作者 刘锟

update

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Console\Commands; 3 namespace App\Console\Commands;
4 4
  5 +use App\Repositories\BtRepository;
5 use Illuminate\Console\Command; 6 use Illuminate\Console\Command;
6 use Illuminate\Support\Facades\Log; 7 use Illuminate\Support\Facades\Log;
7 use Illuminate\Support\Facades\Redis; 8 use Illuminate\Support\Facades\Redis;
@@ -23,12 +24,17 @@ public function handle() @@ -23,12 +24,17 @@ public function handle()
23 try { 24 try {
24 //拉取代码 25 //拉取代码
25 $this->pullCode(); 26 $this->pullCode();
  27 +
  28 + if ($is_pull > 1) {
  29 + //重启进程
  30 + $this->resetProcess();
  31 + }
26 } catch (\Exception $e) { 32 } catch (\Exception $e) {
27 Log::error('pull_code | error:' . $e->getMessage()); 33 Log::error('pull_code | error:' . $e->getMessage());
28 $this->output($e->getMessage()); 34 $this->output($e->getMessage());
29 } 35 }
30 36
31 - Redis::set('pull_code', false); 37 + Redis::set('pull_code', 0);
32 return true; 38 return true;
33 } 39 }
34 40
@@ -52,6 +58,35 @@ public function pullCode() @@ -52,6 +58,35 @@ public function pullCode()
52 } 58 }
53 59
54 /** 60 /**
  61 + * 重启进程
  62 + * @author Akun
  63 + * @date 2025/06/13 16:56
  64 + */
  65 + public function resetProcess()
  66 + {
  67 + $this->output('重启进程: start.');
  68 +
  69 + $bt_repository = new BtRepository();
  70 + $bt = $bt_repository->getBtObject();
  71 +
  72 + $list = $bt->getProcessList();
  73 + foreach ($list as $value) {
  74 + $process_name = $value['program'];
  75 + $process_num = $value['numprocs'];
  76 +
  77 + $re_stop = $bt->stopProcess($process_name, $process_num);
  78 + $re_stop_msg = $re_stop['msg'] ?? '';
  79 + $this->output($value['ps'] . '-' . $re_stop_msg);
  80 +
  81 + $re_start = $bt->startProcess($process_name, $process_num);
  82 + $re_start_msg = $re_start['msg'] ?? '';
  83 + $this->output($value['ps'] . '-' . $re_start_msg);
  84 + }
  85 +
  86 + $this->output('重启进程: end.');
  87 + }
  88 +
  89 + /**
55 * 输出处理日志 90 * 输出处理日志
56 * @param $message 91 * @param $message
57 */ 92 */
@@ -285,13 +285,18 @@ public function getRandInquiryText(Request $request) @@ -285,13 +285,18 @@ public function getRandInquiryText(Request $request)
285 285
286 /** 286 /**
287 * 通知拉代码 287 * 通知拉代码
  288 + * @param Request $request
288 * @return string 289 * @return string
289 * @author Akun 290 * @author Akun
290 * @date 2025/06/13 15:30 291 * @date 2025/06/13 15:30
291 */ 292 */
292 - public function pullCode() 293 + public function pullCode(Request $request)
293 { 294 {
294 - Redis::set('pull_code', true); 295 + $is_update_process = $request->get('is_update_process');
  296 +
  297 + $pull_code = $is_update_process ? 2 : 1;
  298 +
  299 + Redis::set('pull_code', $pull_code);
295 300
296 return $this->success(); 301 return $this->success();
297 } 302 }
@@ -497,11 +502,11 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA @@ -497,11 +502,11 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA
497 $this->response(); 502 $this->response();
498 } 503 }
499 504
500 - if($type == self::TYPEINQUIRY){ 505 + if ($type == self::TYPEINQUIRY) {
501 //询盘 506 //询盘
502 $ip = $data['submit_ip'] ?? $request->getClientIp(); 507 $ip = $data['submit_ip'] ?? $request->getClientIp();
503 $referrer_url = $data['refer'] ?? $request->header('Referer'); 508 $referrer_url = $data['refer'] ?? $request->header('Referer');
504 - }else{ 509 + } else {
505 //访问 510 //访问
506 $ip = $data['ip'] ?? $request->getClientIp(); 511 $ip = $data['ip'] ?? $request->getClientIp();
507 $referrer_url = $data['referrer_url'] ?? $request->header('Referer'); 512 $referrer_url = $data['referrer_url'] ?? $request->header('Referer');
@@ -538,9 +543,9 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA @@ -538,9 +543,9 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA
538 @file_put_contents(storage_path('logs/fail_req/' . date('Y-m-d') . '.log'), var_export($dataJson, true) . PHP_EOL, FILE_APPEND); 543 @file_put_contents(storage_path('logs/fail_req/' . date('Y-m-d') . '.log'), var_export($dataJson, true) . PHP_EOL, FILE_APPEND);
539 } 544 }
540 545
541 - if($type == self::TYPEINQUIRY){ 546 + if ($type == self::TYPEINQUIRY) {
542 $this->response("success", self::SUCCESS, $resp["data"] ?? []); 547 $this->response("success", self::SUCCESS, $resp["data"] ?? []);
543 - }else{ 548 + } else {
544 $this->responseNew("success", self::SUCCESS, $resp["data"] ?? []); 549 $this->responseNew("success", self::SUCCESS, $resp["data"] ?? []);
545 } 550 }
546 } 551 }
@@ -729,7 +734,7 @@ public function inquiryOtherInfo(Request $request) @@ -729,7 +734,7 @@ public function inquiryOtherInfo(Request $request)
729 */ 734 */
730 public function inquiryQd(Request $request) 735 public function inquiryQd(Request $request)
731 { 736 {
732 - return $this->transmit($request, self::TYPEINQUIRY,self::TRAFFICONE); 737 + return $this->transmit($request, self::TYPEINQUIRY, self::TRAFFICONE);
733 } 738 }
734 739
735 /** 740 /**
@@ -764,14 +769,15 @@ public function search(Request $request) @@ -764,14 +769,15 @@ public function search(Request $request)
764 * 生成robots.txt 769 * 生成robots.txt
765 * @param Request $request 770 * @param Request $request
766 */ 771 */
767 - public function updateRobots(Request $request){ 772 + public function updateRobots(Request $request)
  773 + {
768 $req["domain"] = $request->getHost(); 774 $req["domain"] = $request->getHost();
769 //转发data 775 //转发data
770 $transmitUrl = env("API_URL"); 776 $transmitUrl = env("API_URL");
771 $resp = $this->httpPost($transmitUrl . "api/get_robots_content/", json_encode($req)); 777 $resp = $this->httpPost($transmitUrl . "api/get_robots_content/", json_encode($req));
772 $robotsContent = $resp["data"]["content"]; 778 $robotsContent = $resp["data"]["content"];
773 - $robotTxtPath = public_path($req["domain"]."/robots.txt");  
774 - $this->putSitemapFile($robotTxtPath,$robotsContent); 779 + $robotTxtPath = public_path($req["domain"] . "/robots.txt");
  780 + $this->putSitemapFile($robotTxtPath, $robotsContent);
775 $this->response("success", self::SUCCESS, $resp["data"] ?? []); 781 $this->response("success", self::SUCCESS, $resp["data"] ?? []);
776 } 782 }
777 783