作者 lyh

gx创建作者

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogAuthorTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 11:12
  8 + */
  9 +
  10 +namespace App\Console\Commands\AiBlog;
  11 +
  12 +use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
  14 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  15 +use App\Models\Project\ProjectAiSetting;
  16 +use App\Services\AiBlogService;
  17 +use App\Services\ProjectServer;
  18 +use Illuminate\Console\Command;
  19 +use Illuminate\Support\Facades\Cache;
  20 +use Illuminate\Support\Facades\DB;
  21 +
  22 +class AiBlogAuthorTask extends Command
  23 +{
  24 + /**
  25 + * The name and signature of the console command.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $signature = 'save_ai_blog_author';
  30 +
  31 + /**
  32 + * The console command description.
  33 + *
  34 + * @var string
  35 + */
  36 + protected $description = '查询ai_blog_author是否已经生成';
  37 +
  38 +
  39 + /**
  40 + * @remark :获取作者
  41 + * @name :handle
  42 + * @author :lyh
  43 + * @method :post
  44 + * @time :2025/2/21 11:30
  45 + */
  46 + public function handle(){
  47 + $aiBlogTaskModel = new AiBlogTaskModel();
  48 + while (true){
  49 + $info = $aiBlogTaskModel->where('status',1)->where('type',1)->inRandomOrder()->first();
  50 + if(empty($info)){
  51 + sleep(300);
  52 + continue;
  53 + }
  54 + $info = $info->toArray();
  55 + echo '开始->project_id:' . $info['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
  56 + //获取配置
  57 + $aiSettingInfo = $this->getSetting($info['project_id']);
  58 + $aiBlogService = new AiBlogService();
  59 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  60 + $aiBlogService->key = $aiSettingInfo['key'];
  61 + $result = $aiBlogService->getAuthor();
  62 + if(!isset($result['status'])){
  63 + continue;
  64 + }
  65 + if($result['status'] != 200){
  66 + sleep(10);
  67 + continue;
  68 + }
  69 + //修改任务状态
  70 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
  71 + //保存当前项目ai_blog数据
  72 + ProjectServer::useProject($info['project_id']);
  73 + $this->saveAiBlogAuthor($result['data'] ?? []);
  74 + DB::disconnect('custom_mysql');
  75 + echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  76 + }
  77 + return true;
  78 + }
  79 +
  80 +
  81 + /**
  82 + * @remark :获取项目配置
  83 + * @name :getSetting
  84 + * @author :lyh
  85 + * @method :post
  86 + * @time :2025/2/14 11:27
  87 + */
  88 + public function getSetting($project_id){
  89 + $ai_cache = Cache::get('ai_blog_'.$project_id);
  90 + if($ai_cache){
  91 + return $ai_cache;
  92 + }
  93 + $projectAiSettingModel = new ProjectAiSetting();
  94 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
  95 + Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
  96 + return $aiSettingInfo;
  97 + }
  98 +
  99 + /**
  100 + * @remark :保存数据
  101 + * @name :saveAiBlogAuthor
  102 + * @author :lyh
  103 + * @method :post
  104 + * @time :2025/2/21 11:36
  105 + */
  106 + public function saveAiBlogAuthor($data){
  107 + if(empty($data)){
  108 + return true;
  109 + }
  110 + $param = [];
  111 + foreach ($data as $v){
  112 + $param = [
  113 + 'author_id'=>$v['id'],
  114 + 'title'=>$v['title'],
  115 + 'image'=>$v['picture'],
  116 + 'description'=>$v['description'],
  117 + ];
  118 + }
  119 + $aiBlogAuthorModel = new AiBlogAuthor();
  120 + return $aiBlogAuthorModel->insertAll($param);
  121 + }
  122 +}
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Console\Commands\AiBlog; 10 namespace App\Console\Commands\AiBlog;
11 11
12 use App\Models\Ai\AiBlog; 12 use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
13 use App\Models\Project\ProjectAiSetting; 14 use App\Models\Project\ProjectAiSetting;
14 use App\Services\AiBlogService; 15 use App\Services\AiBlogService;
15 use App\Services\ProjectServer; 16 use App\Services\ProjectServer;
@@ -38,7 +39,7 @@ class AiBlogTask extends Command @@ -38,7 +39,7 @@ class AiBlogTask extends Command
38 public function handle(){ 39 public function handle(){
39 $aiBlogTaskModel = new AiBlogTaskModel(); 40 $aiBlogTaskModel = new AiBlogTaskModel();
40 while (true){ 41 while (true){
41 - $info = $aiBlogTaskModel->where('status',1)->inRandomOrder()->first(); 42 + $info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();
42 if(empty($info)){ 43 if(empty($info)){
43 sleep(300); 44 sleep(300);
44 continue; 45 continue;
@@ -53,8 +54,6 @@ class AiBlogTask extends Command @@ -53,8 +54,6 @@ class AiBlogTask extends Command
53 $aiBlogService->task_id = $info['task_id']; 54 $aiBlogService->task_id = $info['task_id'];
54 $result = $aiBlogService->getDetail(); 55 $result = $aiBlogService->getDetail();
55 if(!isset($result['status'])){ 56 if(!isset($result['status'])){
56 - //修改任务状态  
57 - $aiBlogTaskModel->edit(['status'=>3],['id'=>$info['id']]);  
58 continue; 57 continue;
59 } 58 }
60 if($result['status'] != 200){ 59 if($result['status'] != 200){
@@ -67,12 +66,14 @@ class AiBlogTask extends Command @@ -67,12 +66,14 @@ class AiBlogTask extends Command
67 ProjectServer::useProject($info['project_id']); 66 ProjectServer::useProject($info['project_id']);
68 $aiBlogModel = new AiBlog(); 67 $aiBlogModel = new AiBlog();
69 $aiBlogModel->edit(['new_title'=>$result['data']['title'],'image'=>$result['data']['thumb'],'text'=>$result['data']['section'],'status'=>2],['task_id'=>$info['task_id']]); 68 $aiBlogModel->edit(['new_title'=>$result['data']['title'],'image'=>$result['data']['thumb'],'text'=>$result['data']['section'],'status'=>2],['task_id'=>$info['task_id']]);
  69 + $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
70 DB::disconnect('custom_mysql'); 70 DB::disconnect('custom_mysql');
71 echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); 71 echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
72 } 72 }
73 return true; 73 return true;
74 } 74 }
75 75
  76 +
76 /** 77 /**
77 * @remark :获取项目配置 78 * @remark :获取项目配置
78 * @name :getSetting 79 * @name :getSetting
@@ -90,4 +91,30 @@ class AiBlogTask extends Command @@ -90,4 +91,30 @@ class AiBlogTask extends Command
90 Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600); 91 Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
91 return $aiSettingInfo; 92 return $aiSettingInfo;
92 } 93 }
  94 +
  95 + /**
  96 + * @remark :更新作者的页面
  97 + * @name :updateAiBlogAuthor
  98 + * @author :lyh
  99 + * @method :post
  100 + * @time :2025/2/21 11:53
  101 + */
  102 + public function updateAiBlogAuthor($aiSettingInfo,$author_id){
  103 + if(empty($author_id)){
  104 + return true;
  105 + }
  106 + $aiBlogService = new AiBlogService();
  107 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  108 + $aiBlogService->key = $aiSettingInfo['key'];
  109 + $aiBlogService->author_id = $author_id;
  110 + $result = $aiBlogService->getAuthorDetail();
  111 + if(isset($result['status']) && $result['status'] == 200){
  112 + //当前作者的页面
  113 + $aiBlogAuthorModel = new AiBlogAuthor();
  114 + if(!empty($result['data']['section'])){
  115 + $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
  116 + }
  117 + }
  118 + return true;
  119 + }
93 } 120 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :RequestUrlLog.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 9:55
  8 + */
  9 +
  10 +namespace App\Console\Commands\RequestUrlLog;
  11 +
  12 +use Illuminate\Console\Command;
  13 +
  14 +class RequestUrlLog extends Command
  15 +{
  16 + /**
  17 + * The name and signature of the console command.
  18 + *
  19 + * @var string
  20 + */
  21 + protected $signature = 'request_url_log';
  22 +
  23 + /**
  24 + * The console command description.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $description = '统计昨日数据';
  29 +}
@@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\Ai\AiBlogLogic; 7 use App\Http\Logic\Bside\Ai\AiBlogLogic;
8 use App\Http\Requests\Bside\Ai\AiBlogRequest; 8 use App\Http\Requests\Bside\Ai\AiBlogRequest;
9 use App\Models\Ai\AiBlog; 9 use App\Models\Ai\AiBlog;
  10 +use App\Models\Ai\AiBlogAuthor;
10 use App\Services\AiBlogService; 11 use App\Services\AiBlogService;
11 use App\Services\ProjectServer; 12 use App\Services\ProjectServer;
12 use Illuminate\Support\Facades\DB; 13 use Illuminate\Support\Facades\DB;
@@ -102,15 +103,15 @@ class AiBlogController extends BaseController @@ -102,15 +103,15 @@ class AiBlogController extends BaseController
102 } 103 }
103 104
104 /** 105 /**
105 - * @remark :创建作者  
106 - * @name :createAuthor 106 + * @remark :获取作者列表
  107 + * @name :getAiBlogAuthor
107 * @author :lyh 108 * @author :lyh
108 * @method :post 109 * @method :post
109 - * @time :2025/2/20 10:45 110 + * @time :2025/2/21 11:44
110 */ 111 */
111 - public function createAuthor(AiBlogLogic $aiBlogLogic){  
112 - //获取当前项目的ai_blog设置  
113 - $result = $aiBlogLogic->createAuthor();  
114 - $this->response('success',Code::SUCCESS,$result); 112 + public function getAiBlogAuthor(AiBlogAuthor $aiBlogAuthor){
  113 + $field = ['author_id','title','image','description','created_at','updated_at'];
  114 + $lists = $aiBlogAuthor->lists($this->map,$this->page,$this->row,$field);
  115 + $this->response('success',Code::SUCCESS,$lists);
115 } 116 }
116 } 117 }
@@ -12,6 +12,7 @@ use App\Helper\FormGlobalsoApi; @@ -12,6 +12,7 @@ use App\Helper\FormGlobalsoApi;
12 use App\Http\Logic\Aside\BaseLogic; 12 use App\Http\Logic\Aside\BaseLogic;
13 use App\Jobs\CopyImageFileJob; 13 use App\Jobs\CopyImageFileJob;
14 use App\Jobs\CopyProjectJob; 14 use App\Jobs\CopyProjectJob;
  15 +use App\Models\Ai\AiBlogAuthor;
15 use App\Models\Channel\Channel; 16 use App\Models\Channel\Channel;
16 use App\Models\Channel\User; 17 use App\Models\Channel\User;
17 use App\Models\Channel\Zone; 18 use App\Models\Channel\Zone;
@@ -24,6 +25,7 @@ use App\Models\Inquiry\InquiryIP; @@ -24,6 +25,7 @@ use App\Models\Inquiry\InquiryIP;
24 use App\Models\Inquiry\InquirySet; 25 use App\Models\Inquiry\InquirySet;
25 use App\Models\Manage\Manage; 26 use App\Models\Manage\Manage;
26 use App\Models\Project\After; 27 use App\Models\Project\After;
  28 +use App\Models\Project\AiBlogTask;
27 use App\Models\Project\DeployBuild; 29 use App\Models\Project\DeployBuild;
28 use App\Models\Project\DeployOptimize; 30 use App\Models\Project\DeployOptimize;
29 use App\Models\Project\InquiryFilterConfig; 31 use App\Models\Project\InquiryFilterConfig;
@@ -222,6 +224,7 @@ class ProjectLogic extends BaseLogic @@ -222,6 +224,7 @@ class ProjectLogic extends BaseLogic
222 'key'=>$result['data']['key'], 224 'key'=>$result['data']['key'],
223 ]; 225 ];
224 $aiSettingModel->add($resData); 226 $aiSettingModel->add($resData);
  227 + $this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']);
225 } 228 }
226 }else{ 229 }else{
227 //有信息更新 230 //有信息更新
@@ -244,6 +247,30 @@ class ProjectLogic extends BaseLogic @@ -244,6 +247,30 @@ class ProjectLogic extends BaseLogic
244 } 247 }
245 248
246 /** 249 /**
  250 + * @remark :创建作者
  251 + * @name :createAuthor
  252 + * @author :lyh
  253 + * @method :post
  254 + * @time :2025/2/21 11:17
  255 + */
  256 + public function createAuthor($project_id,$mch_id,$key){
  257 + //查看当前项目是否已经创建了作者
  258 + $aiBlogTaskModel = new AiBlogTask();
  259 + $count = $aiBlogTaskModel->counts();
  260 + if($count > 0){
  261 + return true;
  262 + }
  263 + $aiBlogService = new AiBlogService();
  264 + $aiBlogService->mch_id = $mch_id;
  265 + $aiBlogService->key = $key;
  266 + $result = $aiBlogService->createAuthor();
  267 + if($result['status'] == 200){
  268 + $aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]);
  269 + }
  270 + return true;
  271 + }
  272 +
  273 + /**
247 * @remark :选择服务器后双向绑定 274 * @remark :选择服务器后双向绑定
248 * @name :setServers 275 * @name :setServers
249 * @author :lyh 276 * @author :lyh
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogAuthor.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 10:59
  8 + */
  9 +
  10 +namespace App\Models\Ai;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class AiBlogAuthor extends Base
  15 +{
  16 + protected $table = 'gl_ai_blog_author';
  17 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :RequestUrlLog.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 9:38
  8 + */
  9 +
  10 +namespace App\Models\RequestUrlLog;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +/**
  15 + * @remark :url请求日志
  16 + * @name :RequestUrlLog
  17 + * @author :lyh
  18 + * @method :post
  19 + * @time :2025/2/21 9:48
  20 + */
  21 +class RequestUrlLog extends Base
  22 +{
  23 + protected $table = 'gl_request_url_log';
  24 +}
@@ -20,6 +20,8 @@ class AiBlogService @@ -20,6 +20,8 @@ class AiBlogService
20 public $route = '';//回调地址 20 public $route = '';//回调地址
21 21
22 public $task_id = '';//任务id 22 public $task_id = '';//任务id
  23 +
  24 + public $author_id = '';//作者id
23 /** 25 /**
24 * @remark :创建项目 26 * @remark :创建项目
25 * @name :createProject 27 * @name :createProject
@@ -104,6 +106,24 @@ class AiBlogService @@ -104,6 +106,24 @@ class AiBlogService
104 } 106 }
105 107
106 /** 108 /**
  109 + * @remark :获取作者信息
  110 + * @name :getAuthor
  111 + * @author :lyh
  112 + * @method :post
  113 + * @time :2025/2/21 10:57
  114 + */
  115 + public function getAuthor(){
  116 + $request_url = $this->url.'api/author/list';
  117 + $param = [
  118 + 'mch_id'=>$this->mch_id,
  119 + ];
  120 + $this->sign = $this->generateSign($param,$this->key);
  121 + $param['sign'] = $this->sign;
  122 + $result = http_post($request_url,json_encode($param,true));
  123 + return $result;
  124 + }
  125 +
  126 + /**
107 * @remark :计算签名 127 * @remark :计算签名
108 * @name :generateSign 128 * @name :generateSign
109 * @author :lyh 129 * @author :lyh
@@ -143,4 +163,23 @@ class AiBlogService @@ -143,4 +163,23 @@ class AiBlogService
143 $result = http_post($request_url,json_encode($param,true)); 163 $result = http_post($request_url,json_encode($param,true));
144 return $result; 164 return $result;
145 } 165 }
  166 +
  167 + /**
  168 + * @remark :获取作者页面
  169 + * @name :getAuthorDetail
  170 + * @author :lyh
  171 + * @method :post
  172 + * @time :2025/2/21 11:55
  173 + */
  174 + public function getAuthorDetail(){
  175 + $request_url = $this->url.'api/author/detail';
  176 + $param = [
  177 + 'mch_id'=>$this->mch_id,
  178 + 'author_id'=>$this->author_id,
  179 + ];
  180 + $this->sign = $this->generateSign($param,$this->key);
  181 + $param['sign'] = $this->sign;
  182 + $result = http_post($request_url,json_encode($param,true));
  183 + return $result;
  184 + }
146 } 185 }
@@ -157,8 +157,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -157,8 +157,8 @@ Route::middleware(['bloginauth'])->group(function () {
157 Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save'); 157 Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save');
158 Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask'); 158 Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask');
159 Route::any('/blog/del', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'delete'])->name('ai_blog_delete'); 159 Route::any('/blog/del', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'delete'])->name('ai_blog_delete');
  160 + Route::any('/blog/getAiBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlogAuthor'])->name('ai_blog_getAiBlogAuthor');
160 Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo'); 161 Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo');
161 - Route::any('/blog/createAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'createAuthor'])->name('ai_blog_createAuthor');  
162 Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save'); 162 Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save');
163 Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList'); 163 Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList');
164 Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList'); 164 Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList');