where(['id' => $id])->first(); if (!$site) { return view('admin/site/tips', [ 'tips' => '报告不存在', 'siteId' => $id, ]); } try { $rankConnection = DB::connection('rank'); $old = $rankConnection->table('project')->where(['id' => $site->old_id])->select(['allow_googlerank', 'number', 'interval_time'])->first(); $keywordCount = $rankConnection->table('project_keyword')->where(['project_id' => $site->old_id])->count(); $keywordCountNotRun = $rankConnection->table('project_keyword')->where(['project_id' => $site->old_id])->where(['allow_googlerank' => '0'])->count(); return view('admin/rank/keyword_for_site', [ 'siteId' => $id, 'site' => $site, 'old' => $old, 'keywordCount' => $keywordCount, 'keywordCountNotRun' => $keywordCountNotRun ]); } catch (\Throwable $exception) { return view('admin/site/tips', [ 'tips' => '数据库连接超时,error:' . $exception->getMessage().'http://test.build.yinqingli.net/admin', 'siteId' => $id, ]); } } //客户界面关键词 public function customerKeyword() { $site = $this->hasUserOneSite(); if (!$site) { return view('admin/errors/tips'); } $rankConnection = DB::connection('rank'); $old = $rankConnection->table('project')->where(['id' => $site->old_id])->select(['allow_googlerank', 'number'])->first(); $keywordCount = $rankConnection->table('project_keyword')->where(['project_id' => $site->old_id])->count(); return view('admin/rank/keyword', [ 'siteId' => $site->id, 'site' => $site, 'old' => $old, 'keywordCount' => $keywordCount ]); } //关键词保存 public function keywordSave(KeywordRequest $request, $id) { if (!$request->ajax()) { return view('admin/rank/keyword_save', [ 'siteId' => $id ]); } $site = Site::query()->where(['id' => $id])->first(); if (!$site) { return response()->json(['message' => '站点信息不存在'], 400); } if (!$site->old_id) { return response()->json(['message' => '请先与rank项目关联'], 400); } $rankConnection = DB::connection('rank'); $maxSn = $rankConnection->table('project_keyword')->where(['project_id' => $site->old_id])->max('sn') ?? 0; $validated = $request->validated(); $validated['sn'] = $maxSn; $validated['project_id'] = $site->old_id; $validated['google_rank'] = 9999; $validated['target_url'] = ' '; $validated['resules'] = 0; $validated['allintitle'] = -1; $validated['sync_time'] = strtotime('today'); $rankConnection->table('project_keyword')->insert($validated); return response()->json(['message' => '操作成功']); } //导入关键词 public function importKeyword(Request $request) { set_time_limit(0); $siteId = $request->input('siteId'); if (!$request->input('excel_path') || !$siteId) { return response()->json(['message' => '请先上传excel文件'], 422); } $site = Site::query()->where(['id' => $siteId])->first(); if (!$site) { return response()->json(['message' => '站点信息不存在'], 400); } if (!$site->old_id) { return response()->json(['message' => '请先与rank项目关联'], 400); } try { Excel::import(new Keyword($site->old_id), $request->input('excel_path'), 'public'); } catch (\Throwable $throwable) { Log::error(var_export($throwable->getMessage(), 1)); return response()->json(['message' => $throwable->getMessage()], 400); } return response()->json(['message' => '操作成功']); } public function keywordTpl($siteId) { } //清空关键词 public function clearKeyword($siteId) { $site = Site::query()->where(['id' => $siteId])->first(); if (!$site) { return response()->json(['message' => '站点信息不存在'], 400); } if (!$site->old_id) { return response()->json(['message' => '请先与rank项目关联'], 400); } DB::connection('rank')->table('project_keyword')->where(['project_id' => $site->old_id])->delete(); return response()->json(['message' => '操作成功']); } //允许排名 public function allowRank(Request $request, $oldId) { if ($oldId < 1) { return response()->json(['message' => '请先与rank项目关联'], 400); } $isAllow = $request->input('isAllow'); $number = $request->input('number'); $intervalTime = $request->input('interval_time'); if (!in_array($isAllow, [1, 0])) { return response()->json(['message' => '参数错误'], 400); } if (!in_array($number, [1, 2, 3, 4])) { return response()->json(['message' => '请选择排名服务器'], 400); } if (!in_array($intervalTime, [0, 5, 7, 15, 30])) { return response()->json(['message' => '请选择排名服务器'], 400); } DB::connection('rank')->table('project')->where(['id' => $oldId])->update([ 'allow_googlerank' => $isAllow, 'number' => $number, 'interval_time' => $intervalTime, ]); return response()->json(['message' => '操作成功']); } }