input('start_time', date('Y-m-d')); $end_time = $request->input('end_time', date('Y-m-d', time() + 86400)); $distribution_channel_id = $this->getChannelId(); $official = $this->getOfficialAccount($distribution_channel_id); if (!$official) return response()->success(); if ($request->input('export')) { $data = OfficialAccountBillsService::getBillsByOfficialAcount($distribution_channel_id, $start_time, $end_time, true); // $data = OrderService::OfficialAccountOrderStat($distribution_channel_id,$start_time,$end_time,500); } else { // $data = OrderService::OfficialAccountOrderStat($distribution_channel_id,$start_time,$end_time); $data = OfficialAccountBillsService::getBillsByOfficialAcount($distribution_channel_id, $start_time, $end_time, false); } // if ($data) { // foreach ($data as &$v) { // $v->nickname = isset($official[$v->appid]) ? $official[$v->appid] : '未知'; // $amount = OrderService::OfficialAccountOrderSum($distribution_channel_id, $start_time, $end_time, $v->appid); // $v->total_amount = $amount; // } // } if ($request->input('export')) { $filename = date('YmdHis') . '.csv'; Storage::append($filename, mb_convert_encoding("日期,服务号,充值金额,总额,新关粉丝数,30天内充值,60天内充值,90天内充值", 'gbk')); $str = ''; if ($data) { foreach ($data as $val) { $val->new_fans_num = $val->new_fans_num ? $val->new_fans_num : 0; $val->recharge_amount_in_30_days = $val->recharge_amount_in_30_days ? $val->recharge_amount_in_30_days : 0; $val->recharge_amount_in_60_days = $val->recharge_amount_in_60_days ? $val->recharge_amount_in_60_days : 0; $val->recharge_amount_in_90_days = $val->recharge_amount_in_90_days ? $val->recharge_amount_in_90_days : 0; $str .= "{$val->date},{$val->nickname},{$val->recharge_amount},{$val->channel_recharge_amount},{$val->new_fans_num},{$val->recharge_amount_in_30_days},{$val->recharge_amount_in_60_days},{$val->recharge_amount_in_90_days}\r\n"; } } Storage::append($filename, mb_convert_encoding($str, 'gbk')); return response()->download(storage_path('app/' . $filename))->deleteFileAfterSend(true); } return response()->pagination(new OfficialAccountBillsTransformer(), $data); } private function getOfficialAccount($distribution_channel_id) { if (empty($distribution_channel_id)) return []; $res = DB::table('official_accounts')->select('nickname', 'appid')->where('distribution_channel_id', $distribution_channel_id)->get(); if ($res) { $data = []; foreach ($res as $v) { $data[$v->appid] = $v->nickname; } return $data; } return []; } }