logic = $logic; } //数据报表 public function index($siteId) { $site = Site::query()->where(['id' => $siteId])->select(['old_id'])->first(); if (empty($site->old_id)) { return view('admin/site/tips', [ 'siteId' => $siteId, 'tips' => '关联站点信息不存在' ]); } return view('admin/report/index_for_site', [ 'site' => $site, 'siteId' => $siteId //admin/site/side_layout 需要此字段 ] ); } //客户界面的数据报表 public function customerReport() { $site = $this->hasUserOneSite(); if (!$site) { return view('admin/errors/tips'); } if (empty($site->old_id)) { return view('admin/errors/tips', [ 'tips' => '关联站点信息不存在' ]); } return view('admin/report/customer_report', [ 'site' => $site, ] ); } //月报扩展 public function extend($siteId) { $sixMonth = []; for ($count = 1; $count <= 6; $count++) { $sixMonth[] = date('Ym', strtotime('first day of -' . $count . ' month')); } $site = Site::query()->where(['id' => $siteId])->first(); if (empty($site->old_id)) { return view('admin/site/tips', [ 'siteId' => $siteId, 'tips' => '关联站点信息不存在' ]); } $rankConnection = DB::connection('rank'); $reportExtendList = $rankConnection->table('report_extend') ->where(['project_id' => $site->old_id])->limit(6)->orderBy('ym', 'desc')->get(); $reportSummaryList = $rankConnection->table('report_summary') ->where(['project_id' => $site->old_id])->get()->map(function ($item) { return (array)$item; })->groupBy('ym')->toArray(); $customList = $rankConnection->table('webmaster_custom')->whereIn('ym', $sixMonth)->where([ 'project_id' => $site->old_id ])->get()->toArray(); $ym = date('Ym', strtotime('-1 month')); $reportExtend = $rankConnection->table('report_extend') ->where(['project_id' => $site->old_id, 'ym' => $ym])->first(); $summaryList = $rankConnection->table('report_summary') ->where(['project_id' => $site->old_id, 'ym' => $ym])->get()->toArray(); $keyCustomList = array_column($customList, null, 'ym'); $contract = $rankConnection->table('report_contract')->where(['project_id' => $site->old_id, 'ym' => $ym])->first(); return view('admin/report/extend', [ 'data' => $site, 'siteId' => $siteId, 'sixMonth' => $sixMonth, 'keyCustomList' => $keyCustomList, 'reportExtend' => $reportExtend, 'reportExtendList' => $reportExtendList, 'reportSummaryList' => $reportSummaryList, 'summaryList' => $summaryList, 'contractList' => $contract ]); } //月报扩展下的 外链文章同步 public function syncCustomer(Request $request, $oldId) { $ymMapData = $request->input('ymMapData'); if (!is_array($ymMapData)) { return response()->json(['message' => '参数错误'], 422); } foreach ($ymMapData as $key => $item) { $condition = ['project_id' => $oldId, 'ym' => $key]; DB::connection('rank')->table('webmaster_custom') ->updateOrInsert($condition, [ 'link_count' => $item['linkCount'], 'article_count' => $item['articleCount'], 'create_time' => time() ]); } return response()->json(['message' => '操作成功']); } //月报扩展下的 月度总结同步 public function syncSummary(SummaryRequest $request, $oldId) { $validated = $request->validated(); $validated['dataList'] = $validated['dataList'] ?? []; $validated['fileList'] = $validated['fileList'] ?? []; $ym = date('Ym', strtotime('-1 month')); $this->logic->syncSummary($ym, $oldId, $validated); $this->logic->syncFileExtend($ym, $oldId, $validated); return response()->json(['message' => '操作成功']); } //月报扩展下的 合同同步 public function syncContract(ContractRequest $request, $oldId) { $rankConnection = DB::connection('rank'); $ym = date('Ym', strtotime('-1 month')); $validated = $request->validated(); $validated['create_time'] = time(); $rankConnection->table('report_contract')->updateOrInsert(['ym' => $ym, 'project_id' => $oldId], $validated); return response()->json(['message' => '操作成功']); } //清除上一个月数据 public function clearLastMonthData($siteId) { $lstMonth = date('Ym', strtotime('-1 month', strtotime(date('Y-m-01')))); $projectId = Site::query()->where('id', $siteId)->value('old_id'); if (!empty($projectId)) { $rankConnection = DB::connection('rank'); $rankConnection->table('webmaster_country')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_custom')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_effect')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_flow')->where([['project_id', '=', $projectId], ['flow_ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_include')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_keyword')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); $rankConnection->table('webmaster_keyword_info')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete(); } return response()->json(['message' => '操作成功']); } //推送消息至app public function pushMessage($siteId) { DB::table('report_notice')->insert(['site_id' => $siteId]); $info = DB::table('report_notice_task')->where([['site_id', '=', $siteId], ['status', '=', 0]])->first(); if (empty($info)) { DB::table('report_notice_task')->insert(['site_id' => $siteId]); } return response()->json(['message' => '操作成功']); } }