作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Helper\Common;
  6 +use App\Services\ProjectServer;
  7 +use Illuminate\Console\Command;
  8 +use Illuminate\Support\Facades\DB;
  9 +use Illuminate\Support\Facades\Redis;
  10 +
  11 +/**
  12 + * 初始化项目
  13 + * Class InitProject
  14 + * @package App\Console\Commands
  15 + * @author zbj
  16 + * @date 2023/10/8
  17 + */
  18 +class UpdateSeoTdk extends Command
  19 +{
  20 + /**
  21 + * The name and signature of the console command.
  22 + *
  23 + * @var string
  24 + */
  25 + protected $signature = 'update_seo_tdk';
  26 +
  27 + /**
  28 + * The console command description.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $description = '';
  33 +
  34 + /**
  35 + * Create a new command instance.
  36 + *
  37 + * @return void
  38 + */
  39 + public function __construct()
  40 + {
  41 + parent::__construct();
  42 + }
  43 +
  44 + /**
  45 + * @return bool
  46 + */
  47 + public function handle()
  48 + {
  49 + while (true){
  50 + $project_id = Redis::rpop('updateSeoTdk');
  51 + if(!$project_id){
  52 + sleep(2);
  53 + continue;
  54 + }
  55 + echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
  56 +
  57 + try {
  58 + ProjectServer::useProject($project_id);
  59 + $this->updateProduct($project_id);
  60 + $this->updateBlogs($project_id);
  61 + $this->updateNews($project_id);
  62 + DB::disconnect('custom_mysql');
  63 + }catch (\Exception $e){
  64 + echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
  65 + }
  66 +
  67 + echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
  68 + }
  69 + }
  70 +
  71 + /**
  72 + * @remark :更新产品tdk
  73 + * @name :updateProduct
  74 + * @author :lyh
  75 + * @method :post
  76 + * @time :2023/8/19 9:25
  77 + */
  78 + public function updateProduct($project_id){
  79 + $list = DB::connection('custom_mysql')->table('gl_product')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  80 + if(!empty($list)){
  81 + foreach ($list as $v){
  82 + $v = (array)$v;
  83 + $seo_arr = json_decode($v['seo_mate'], true) ?: [];
  84 + //更新seo_title
  85 + if(!isset($seo_arr['title'])){
  86 + //生成seo_title
  87 + $seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);
  88 + }
  89 + //更新seo_keyword
  90 + if(!isset($seo_arr['keyword'])){
  91 + $seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);
  92 + }
  93 + //更新seo_keyword
  94 + if(!isset($seo_arr['description'])){
  95 + $seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);
  96 + }
  97 + $ser_str = json_encode($seo_arr,true);
  98 + DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update(['seo_mate'=>$ser_str]);
  99 + }
  100 + }
  101 + return true;
  102 + }
  103 +
  104 + /**
  105 + * @remark :更新新闻Tdk
  106 + * @name :updateNews
  107 + * @author :lyh
  108 + * @method :post
  109 + * @time :2023/8/19 10:06
  110 + */
  111 + public function updateNews($project_id){
  112 + $list = DB::connection('custom_mysql')->table('gl_news')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  113 + if(!empty($list)){
  114 + foreach ($list as $k => $v){
  115 + $v = (array)$v;
  116 + $data = [];
  117 + if(empty($v['seo_title'])){
  118 + $data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);
  119 + }
  120 + if(empty($v['seo_keywords'])){
  121 + $data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);
  122 + }
  123 + if(empty($v['seo_description'])){
  124 + $data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);
  125 + }
  126 + DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
  127 + }
  128 + }
  129 + return true;
  130 + }
  131 +
  132 + /**
  133 + * @remark :更新blogTdk
  134 + * @name :updateBlogs
  135 + * @author :lyh
  136 + * @method :post
  137 + * @time :2023/8/19 10:07
  138 + */
  139 + public function updateBlogs($project_id){
  140 + $list = DB::connection('custom_mysql')->table('gl_blog')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
  141 + if(!empty($list)){
  142 + foreach ($list as $k => $v){
  143 + $v = (array)$v;
  144 + $data = [];
  145 + if(empty($v['seo_title'])){
  146 + $data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);
  147 + }
  148 + if(empty($v['seo_keywords'])){
  149 + $data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);
  150 + }
  151 + if(empty($v['seo_description'])){
  152 + $data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);
  153 + }
  154 + DB::connection('custom_mysql')->table('gl_blog')->where(['id'=>$v['id']])->update($data);
  155 + }
  156 + }
  157 + return true;
  158 + }
  159 +
  160 + /**
  161 + * @remark :AI发送
  162 + * @name :ai_send
  163 + * @author :lyh
  164 + * @method :post
  165 + * @time :2023/8/19 10:40
  166 + */
  167 + public function ai_send($key,$keywords){
  168 + $chat_url = 'v2/openai_chat';
  169 + $param = [
  170 + 'key'=>$key,
  171 + 'keywords'=>$keywords,
  172 + ];
  173 + $data = Common::send_openai_msg($chat_url,$param);
  174 + return $data['text'];
  175 + }
  176 +}
@@ -13,6 +13,7 @@ use App\Helper\Common; @@ -13,6 +13,7 @@ use App\Helper\Common;
13 use App\Http\Controllers\Bside\BaseController; 13 use App\Http\Controllers\Bside\BaseController;
14 use App\Services\ProjectServer; 14 use App\Services\ProjectServer;
15 use Illuminate\Support\Facades\DB; 15 use Illuminate\Support\Facades\DB;
  16 +use Illuminate\Support\Facades\Redis;
16 17
17 /** 18 /**
18 * @remark :b端网站更新相关 19 * @remark :b端网站更新相关
@@ -36,12 +37,13 @@ class UpdateController extends BaseController @@ -36,12 +37,13 @@ class UpdateController extends BaseController
36 ],[ 37 ],[
37 'project_id.required' => 'project_id不能为空', 38 'project_id.required' => 'project_id不能为空',
38 ]); 39 ]);
39 - ProjectServer::useProject($this->param['project_id']);  
40 - $this->updateProduct($this->param['project_id']);  
41 - $this->updateBlogs($this->param['project_id']);  
42 - $this->updateNews($this->param['project_id']);  
43 - DB::disconnect('custom_mysql');  
44 - $this->response('success'); 40 + Redis::lpush('updateSeoTdk', $this->param['project_id']);
  41 +// ProjectServer::useProject($this->param['project_id']);
  42 +// $this->updateProduct($this->param['project_id']);
  43 +// $this->updateBlogs($this->param['project_id']);
  44 +// $this->updateNews($this->param['project_id']);
  45 +// DB::disconnect('custom_mysql');
  46 + $this->response('任务添加成功');
45 } 47 }
46 48
47 /** 49 /**
@@ -25,7 +25,7 @@ class BlogController extends BaseController @@ -25,7 +25,7 @@ class BlogController extends BaseController
25 public function lists(BlogModel $blogModel){ 25 public function lists(BlogModel $blogModel){
26 $filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url']; 26 $filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
27 $this->order = 'sort'; 27 $this->order = 'sort';
28 - $query = $blogModel->orderBy($this->order ,'desc'); 28 + $query = $blogModel->orderBy($this->order ,'desc')->orderBy('id','desc');
29 $query = $this->searchParam($query); 29 $query = $this->searchParam($query);
30 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page); 30 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
31 if(!empty($lists)){ 31 if(!empty($lists)){
@@ -25,7 +25,7 @@ class NewsController extends BaseController @@ -25,7 +25,7 @@ class NewsController extends BaseController
25 public function lists(NewsModel $news){ 25 public function lists(NewsModel $news){
26 $filed = ['id','category_id','operator_id','status','created_at','image','updated_at','name','sort','url']; 26 $filed = ['id','category_id','operator_id','status','created_at','image','updated_at','name','sort','url'];
27 $this->order = 'sort'; 27 $this->order = 'sort';
28 - $query = $news->orderBy($this->order ,'desc'); 28 + $query = $news->orderBy($this->order ,'desc')->orderBy('id','desc');
29 $query = $this->searchParam($query); 29 $query = $this->searchParam($query);
30 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page); 30 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
31 if(!empty($lists)){ 31 if(!empty($lists)){
@@ -43,7 +43,7 @@ class ProductController extends BaseController @@ -43,7 +43,7 @@ class ProductController extends BaseController
43 $filed = ['id', 'project_id', 'title', 'sort' ,'thumb', 'gallery' ,'product_type' , 'route' , 43 $filed = ['id', 'project_id', 'title', 'sort' ,'thumb', 'gallery' ,'product_type' , 'route' ,
44 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']; 44 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
45 $this->order = 'sort'; 45 $this->order = 'sort';
46 - $query = $product->orderBy($this->order ,'desc'); 46 + $query = $product->orderBy($this->order ,'desc')->orderBy('id','desc');
47 $query = $this->searchParam($query); 47 $query = $this->searchParam($query);
48 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page); 48 $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
49 if(!empty($lists)){ 49 if(!empty($lists)){
@@ -142,13 +142,17 @@ class ProjectLogic extends BaseLogic @@ -142,13 +142,17 @@ class ProjectLogic extends BaseLogic
142 } 142 }
143 if(isset($param['notice_file']) && !empty($param['notice_file'])){ 143 if(isset($param['notice_file']) && !empty($param['notice_file'])){
144 foreach ($param['notice_file'] as &$v1) { 144 foreach ($param['notice_file'] as &$v1) {
145 - $v1['url'] = str_replace_url($v1['url']); 145 + if(isset($v1['url']) && !empty($v1['url'])){
  146 + $v1['url'] = str_replace_url($v1['url']);
  147 + }
146 } 148 }
147 $param['notice_file'] = Arr::a2s($param['notice_file']); 149 $param['notice_file'] = Arr::a2s($param['notice_file']);
148 } 150 }
149 if(isset($param['confirm_file']) && !empty($param['confirm_file'])){ 151 if(isset($param['confirm_file']) && !empty($param['confirm_file'])){
150 foreach ($param['confirm_file'] as &$v2) { 152 foreach ($param['confirm_file'] as &$v2) {
151 - $v2['url'] = str_replace_url($v2['url']); 153 + if(isset($v2['url']) && !empty($v2['url'])){
  154 + $v2['url'] = str_replace_url($v2['url']);
  155 + }
152 } 156 }
153 $param['confirm_file'] = Arr::a2s($param['confirm_file']); 157 $param['confirm_file'] = Arr::a2s($param['confirm_file']);
154 } 158 }