作者 lyh

gx

  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 + foreach ($list as $item){
  55 + echo 'start:' . $item['id'] . PHP_EOL;
  56 + ProjectServer::useProject($item['data']['project_id']);
  57 + $keywordModel = new Keyword();
  58 + $list = $keywordModel->list(['route'=>'']);
  59 + foreach ($list as $v){
  60 + $route = RouteMap::setRoute($v['title'],RouteMap::SOURCE_PRODUCT_KEYWORD,$v['id'],$item['data']['project_id']);
  61 + if(empty($route)){
  62 + $keywordModel->del(['id'=>$v['id']]);
  63 + }
  64 + }
  65 + DB::disconnect('custom_mysql');
  66 + }
  67 + sleep(2);
  68 + }
  69 + }
  70 +
  71 +}
@@ -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 }