作者 赵彬吉
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Http\Logic\Aside\Project\ProjectLogic;
  6 +use App\Models\Com\NoticeLog;
  7 +use App\Models\Product\Keyword;
  8 +use App\Models\Project\Project;
  9 +use App\Models\RouteMap\RouteMap;
  10 +use App\Services\ProjectServer;
  11 +use Illuminate\Console\Command;
  12 +use Illuminate\Support\Facades\DB;
  13 +
  14 +/**
  15 + * 初始化项目
  16 + * Class InitProject
  17 + * @package App\Console\Commands
  18 + * @author zbj
  19 + * @date 2023/10/8
  20 + */
  21 +class InitKeyword extends Command
  22 +{
  23 + /**
  24 + * The name and signature of the console command.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $signature = 'init_keyword';
  29 +
  30 + /**
  31 + * The console command description.
  32 + *
  33 + * @var string
  34 + */
  35 + protected $description = '批量导入关键字生成路由';
  36 +
  37 + /**
  38 + * Create a new command instance.
  39 + *
  40 + * @return void
  41 + */
  42 + public function __construct()
  43 + {
  44 + parent::__construct();
  45 + }
  46 +
  47 + /**
  48 + * @return bool
  49 + */
  50 + public function handle()
  51 + {
  52 + while (true){
  53 + $list = NoticeLog::where('type', NoticeLog::TYPE_INIT_KEYWORD)->where('status', NoticeLog::STATUS_PENDING)->get();
  54 + if(!empty($list)){
  55 + foreach ($list as $item){
  56 + echo 'start:' . $item['data']['project_id'] . PHP_EOL;
  57 + ProjectServer::useProject($item['data']['project_id']);
  58 + $keywordModel = new Keyword();
  59 + $list = $keywordModel->list(['route'=>'']);
  60 + echo 'start:' . json_encode($list) . PHP_EOL;
  61 + foreach ($list as $v){
  62 + $route = RouteMap::setRoute($v['title'],RouteMap::SOURCE_PRODUCT_KEYWORD,$v['id'],$item['data']['project_id']);
  63 + if(empty($route)){
  64 + $keywordModel->del(['id'=>$v['id']]);
  65 + continue;
  66 + }
  67 + $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
  68 + }
  69 + $item->status = NoticeLog::STATUS_SUCCESS;
  70 + $item->save();
  71 + DB::disconnect('custom_mysql');
  72 + }
  73 + }
  74 + sleep(2);
  75 + }
  76 + }
  77 +
  78 +}
@@ -37,6 +37,7 @@ class UpgradeProjectCount extends Command @@ -37,6 +37,7 @@ class UpgradeProjectCount extends Command
37 public function handle(){ 37 public function handle(){
38 ProjectServer::useProject(439); 38 ProjectServer::useProject(439);
39 $this->count(); 39 $this->count();
  40 +
40 DB::disconnect('custom_mysql'); 41 DB::disconnect('custom_mysql');
41 } 42 }
42 43
@@ -60,11 +61,15 @@ class UpgradeProjectCount extends Command @@ -60,11 +61,15 @@ class UpgradeProjectCount extends Command
60 // 获取当月结束时间 61 // 获取当月结束时间
61 $end = date('Y-m-t', strtotime($v['month'])); 62 $end = date('Y-m-t', strtotime($v['month']));
62 $arr['project_id'] = 439; 63 $arr['project_id'] = 439;
63 - $inquiry_list = (new FormGlobalsoApi())->getInquiryList('www.cnzyl.com','',1,100000000);  
64 - //总数  
65 - $arr['total'] = $inquiry_list['data']['total'] ?? 0; 64 + $res = $this->inquiry('www.cnzyl.com',$v['month']);
  65 + $arr['month_total'] = 0;
  66 + if(isset($res['data']['count'])){
  67 + $arr['month_total'] = $res['data']['count'];
  68 + }
  69 + if(isset($res['data']['data'])){
  70 + $arr['country'] = $res['data']['data'];
  71 + }
66 $arr['month'] = $v['month']; 72 $arr['month'] = $v['month'];
67 - $arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';  
68 $arr = $this->pv_ip($arr,$start,$end); 73 $arr = $this->pv_ip($arr,$start,$end);
69 $arr = $this->sourceCount($arr,$start,$end); 74 $arr = $this->sourceCount($arr,$start,$end);
70 if($info === false){ 75 if($info === false){
@@ -143,4 +148,13 @@ class UpgradeProjectCount extends Command @@ -143,4 +148,13 @@ class UpgradeProjectCount extends Command
143 return $arr; 148 return $arr;
144 } 149 }
145 150
  151 + public function inquiry($url,$month){
  152 + $url = 'https://'.$url.'/';
  153 + $token = md5($url.date("Y-m-d"));
  154 + $url = 'https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain='.$url.'&token='.$token.'&source=1,2,3,4&model=month&sta_date='.$month;
  155 + $res = http_get($url,['charset=utf-8']);
  156 + echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
  157 + return $res;
  158 + }
  159 +
146 } 160 }
@@ -51,7 +51,7 @@ class UpdateRoute extends Command @@ -51,7 +51,7 @@ class UpdateRoute extends Command
51 */ 51 */
52 public function handle(){ 52 public function handle(){
53 $projectModel = new Project(); 53 $projectModel = new Project();
54 - $list = $projectModel->list(['id'=>290]); 54 + $list = $projectModel->list(['id'=>209]);
55 foreach ($list as $v){ 55 foreach ($list as $v){
56 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 56 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
57 ProjectServer::useProject($v['id']); 57 ProjectServer::useProject($v['id']);
@@ -59,6 +59,7 @@ class UpdateRoute extends Command @@ -59,6 +59,7 @@ class UpdateRoute extends Command
59 $this->setProductKeyword(); 59 $this->setProductKeyword();
60 // $this->getRouteMap(); 60 // $this->getRouteMap();
61 // $this->getProductCategory(); 61 // $this->getProductCategory();
  62 +// $this->delRouteMap();
62 DB::disconnect('custom_mysql'); 63 DB::disconnect('custom_mysql');
63 } 64 }
64 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 65 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
@@ -225,4 +226,11 @@ class UpdateRoute extends Command @@ -225,4 +226,11 @@ class UpdateRoute extends Command
225 return true; 226 return true;
226 } 227 }
227 228
  229 + public function delRouteMap(){
  230 + $productKeywordModel = new Keyword();
  231 + $list = $productKeywordModel->list();
  232 + foreach ($list as $k=>$v){
  233 + RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569);
  234 + }
  235 + }
228 } 236 }
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2024/1/6
  6 + * Time: 17:41
  7 + */
  8 +namespace App\Http\Controllers\Api;
  9 +
  10 +use App\Models\Project\OnlineCheck;
  11 +use App\Models\Project\Project;
  12 +use Illuminate\Http\Request;
  13 +
  14 +/**
  15 + * Class PrivateController
  16 + * @package App\Http\Controllers\Api
  17 + */
  18 +class PrivateController extends BaseController
  19 +{
  20 + /**
  21 + * 优化中项目列表
  22 + * @param Request $request
  23 + * @return false|string
  24 + */
  25 + public function optimizeProjectList(Request $request)
  26 + {
  27 + $page_size = $request->input('page_size', 20);
  28 + $field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain'];
  29 + $result = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
  30 + ->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
  31 + ->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
  32 + ->where('c.qa_status', '=', OnlineCheck::STATUS_ONLINE_TRUE)
  33 + ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
  34 + ->paginate($page_size)
  35 + ->toArray();
  36 + return $this->success($result);
  37 + }
  38 +}
@@ -69,7 +69,7 @@ class OptimizeController extends BaseController @@ -69,7 +69,7 @@ class OptimizeController extends BaseController
69 if(!empty($list)){ 69 if(!empty($list)){
70 foreach ($list as $v) { 70 foreach ($list as $v) {
71 $last = Arr::last($v); 71 $last = Arr::last($v);
72 - if(isset($last['g']) && ($last['g'] == 1)){ 72 + if(isset($last['g']) && ($last['g'] == 1) && ($last['position'] <= 10) && ($last['position'] >= 1)){
73 $num = $num+1; 73 $num = $num+1;
74 } 74 }
75 } 75 }
@@ -63,6 +63,7 @@ class KeywordController extends BaseController @@ -63,6 +63,7 @@ class KeywordController extends BaseController
63 if(!empty($map['keyword_title'])){ 63 if(!empty($map['keyword_title'])){
64 $map['keyword_title'] = ['like','%'.$map['keyword_title'].'%']; 64 $map['keyword_title'] = ['like','%'.$map['keyword_title'].'%'];
65 } 65 }
  66 + $map['route'] = ['<>',''];
66 $map['project_id'] = $this->user['project_id']; 67 $map['project_id'] = $this->user['project_id'];
67 return $this->success($map); 68 return $this->success($map);
68 } 69 }
@@ -7,6 +7,7 @@ use App\Helper\Arr; @@ -7,6 +7,7 @@ use App\Helper\Arr;
7 use App\Helper\Common; 7 use App\Helper\Common;
8 use App\Helper\Translate; 8 use App\Helper\Translate;
9 use App\Http\Logic\Bside\BaseLogic; 9 use App\Http\Logic\Bside\BaseLogic;
  10 +use App\Models\Com\NoticeLog;
10 use App\Models\News\News; 11 use App\Models\News\News;
11 use App\Models\Product\Keyword; 12 use App\Models\Product\Keyword;
12 use App\Models\Product\KeywordRelated; 13 use App\Models\Product\KeywordRelated;
@@ -136,10 +137,6 @@ class KeywordLogic extends BaseLogic @@ -136,10 +137,6 @@ class KeywordLogic extends BaseLogic
136 * @time :2023/8/28 14:03 137 * @time :2023/8/28 14:03
137 */ 138 */
138 public function batchAdd(){ 139 public function batchAdd(){
139 - $route_array = Translate::tran($this->param['title'], 'en');  
140 - if (empty($route_array)) {  
141 - $this->fail('路由生成失败,请稍后重试!');  
142 - }  
143 try { 140 try {
144 foreach ($this->param['title'] as $k=>$v){ 141 foreach ($this->param['title'] as $k=>$v){
145 if(empty($v)){ 142 if(empty($v)){
@@ -152,11 +149,10 @@ class KeywordLogic extends BaseLogic @@ -152,11 +149,10 @@ class KeywordLogic extends BaseLogic
152 $param['created_at'] = date('Y-m-d H:i:s'); 149 $param['created_at'] = date('Y-m-d H:i:s');
153 $param['updated_at'] = $param['created_at']; 150 $param['updated_at'] = $param['created_at'];
154 $param['title'] = $v; 151 $param['title'] = $v;
155 - $id = $this->model->insertGetId($param);  
156 - $route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);  
157 - $this->model->edit(['route'=>$route],['id'=>$id]); 152 + $this->model->insertGetId($param);
158 } 153 }
159 } 154 }
  155 + NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
160 }catch (\Exception $e){ 156 }catch (\Exception $e){
161 $this->fail('error'); 157 $this->fail('error');
162 } 158 }
@@ -9,4 +9,6 @@ class OnlineCheck extends Base @@ -9,4 +9,6 @@ class OnlineCheck extends Base
9 //设置关联表名 9 //设置关联表名
10 protected $table = 'gl_project_online_check'; 10 protected $table = 'gl_project_online_check';
11 11
  12 + const STATUS_ONLINE_FALSE = 0;
  13 + const STATUS_ONLINE_TRUE = 1;
12 } 14 }
@@ -19,3 +19,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { @@ -19,3 +19,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
19 }); 19 });
20 20
21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit'); 21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
  22 +Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController::class, 'optimizeProjectList'])->name('api.optimize_project_list');