作者 lyh

gx剩余服务时常

1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :AiBlogTask.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2025/2/14 11:14  
8 - */  
9 -  
10 -namespace App\Console\Commands\Ai;  
11 -  
12 -use App\Models\Ai\AiBlog;  
13 -use App\Models\Ai\AiBlogAuthor;  
14 -use App\Models\Ai\AiBlogList;  
15 -use App\Models\Ai\AiVideo;  
16 -use App\Models\Project\ProjectAiSetting;  
17 -use App\Models\RouteMap\RouteMap;  
18 -use App\Services\AiBlogService;  
19 -use App\Services\ProjectServer;  
20 -use Illuminate\Console\Command;  
21 -use App\Models\Project\AiBlogTask as AiBlogTaskModel;  
22 -use Illuminate\Support\Facades\Cache;  
23 -use Illuminate\Support\Facades\DB;  
24 -use function Symfony\Component\String\s;  
25 -  
26 -class AiVideoTask extends Command  
27 -{  
28 - /**  
29 - * The name and signature of the console command.  
30 - *  
31 - * @var string  
32 - */  
33 - protected $signature = 'save_ai_video';  
34 -  
35 - /**  
36 - * The console command description.  
37 - *  
38 - * @var string  
39 - */  
40 - protected $description = '查询ai_video是否已经生成';  
41 -  
42 - public function handle(){  
43 - $aiBlogTaskModel = new AiBlogTaskModel();  
44 - while (true){  
45 - $list = $aiBlogTaskModel->list(['status'=>1,'type'=>3],'id',['*'],'asc',1000);  
46 - if(empty($list)){  
47 - sleep(300);  
48 - continue;  
49 - }  
50 - $updateProject = [];  
51 - foreach ($list as $item){  
52 - echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');  
53 - //获取配置  
54 - $aiSettingInfo = $this->getSetting($item['project_id']);  
55 - $aiBlogService = new AiBlogService();  
56 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
57 - $aiBlogService->key = $aiSettingInfo['key'];  
58 - $aiBlogService->task_id = $item['task_id'];  
59 - $result = $aiBlogService->getDetail();  
60 - if($result['status'] != 200){  
61 - sleep(5);  
62 - continue;  
63 - }  
64 - //保存当前项目ai_blog数据  
65 - ProjectServer::useProject($item['project_id']);  
66 - $aiVideoModel = new AiVideo();  
67 - $aiBlogInfo = $aiVideoModel->read(['task_id'=>$item['task_id']],['id']);  
68 - if($aiBlogInfo === false){  
69 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);  
70 - continue;  
71 - }  
72 - if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {  
73 - $updateProject[$item['project_id']][] = $result['data']['author_id'];  
74 - }  
75 - //拿到返回的路由查看是否重复  
76 - $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_VIDEO, $aiBlogInfo['id'], $item['project_id']);  
77 - if($route != $result['data']['url']){  
78 - $aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);  
79 - }  
80 - $aiVideoModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);  
81 - DB::disconnect('custom_mysql');  
82 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);  
83 - }  
84 - //TODO::更新列表页及作者  
85 - $this->updateProject($updateProject);  
86 - echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');  
87 - }  
88 - return true;  
89 - }  
90 -  
91 - /**  
92 - * @remark :更新项目作者页面及列表页  
93 - * @name :updateProject  
94 - * @author :lyh  
95 - * @method :post  
96 - * @time :2025/3/4 10:25  
97 - */  
98 - public function updateProject($updateProject){  
99 - if(empty($updateProject)){  
100 - return true;  
101 - }  
102 - foreach ($updateProject as $project_id => $author){  
103 - ProjectServer::useProject($project_id);  
104 - $aiSettingInfo = $this->getSetting($project_id);  
105 -// $this->updateBlogList($aiSettingInfo);  
106 - //更新作者  
107 - foreach ($author as $val){  
108 - $this->updateAiBlogAuthor($aiSettingInfo,$val);  
109 - }  
110 - DB::disconnect('custom_mysql');  
111 - }  
112 - return true;  
113 - }  
114 -  
115 - /**  
116 - * @remark :获取项目配置  
117 - * @name :getSetting  
118 - * @author :lyh  
119 - * @method :post  
120 - * @time :2025/2/14 11:27  
121 - */  
122 - public function getSetting($project_id){  
123 - $ai_cache = Cache::get('ai_blog_'.$project_id);  
124 - if($ai_cache){  
125 - return $ai_cache;  
126 - }  
127 - $projectAiSettingModel = new ProjectAiSetting();  
128 - $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);  
129 - Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);  
130 - return $aiSettingInfo;  
131 - }  
132 -  
133 - /**  
134 - * @remark :更新作者的页面  
135 - * @name :updateAiBlogAuthor  
136 - * @author :lyh  
137 - * @method :post  
138 - * @time :2025/2/21 11:53  
139 - */  
140 - public function updateAiBlogAuthor($aiSettingInfo,$author_id){  
141 - if(empty($author_id)){  
142 - return true;  
143 - }  
144 - $aiBlogService = new AiBlogService();  
145 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
146 - $aiBlogService->key = $aiSettingInfo['key'];  
147 - $aiBlogService->author_id = $author_id;  
148 - $result = $aiBlogService->getAuthorDetail();  
149 - if(isset($result['status']) && $result['status'] == 200){  
150 - //当前作者的页面  
151 - $aiBlogAuthorModel = new AiBlogAuthor();  
152 - if(!empty($result['data']['section'])){  
153 - $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);  
154 - }  
155 - }  
156 - return true;  
157 - }  
158 -  
159 - /**  
160 - * @remark :更新列表页  
161 - * @name :updateBlogList  
162 - * @author :lyh  
163 - * @method :post  
164 - * @time :2025/2/26 15:42  
165 - */  
166 - public function updateBlogList($aiSettingInfo){  
167 - $aiBlogService = new AiBlogService();  
168 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
169 - $aiBlogService->key = $aiSettingInfo['key'];  
170 - $page = 1;  
171 - $saveData = [];  
172 - $result = $aiBlogService->getAiBlogList($page,15);  
173 - if(!isset($result['status']) && $result['status'] != 200){  
174 - return true;  
175 - }  
176 - $total_page = $result['data']['total_page'];  
177 - //组装数据保存  
178 - $saveData[] = [  
179 - 'route'=>$page,  
180 - 'text'=>$result['data']['section'],  
181 - ];  
182 - while ($total_page > $page){  
183 - $page++;  
184 - $result = $aiBlogService->getAiBlogList($page,15);  
185 - if(isset($result['status']) && $result['status'] == 200){  
186 - $saveData[] = [  
187 - 'route'=>$page,  
188 - 'text'=>$result['data']['section'],  
189 - ];  
190 - }  
191 - }  
192 - $aiBlogListModel = new AiBlogList();  
193 - if(!empty($saveData)){  
194 - //写一条路由信息  
195 - $aiBlogListModel->truncate();  
196 - $aiBlogListModel->insertAll($saveData);  
197 - }  
198 - return true;  
199 - }  
200 -}  
@@ -44,23 +44,26 @@ class ShareUser extends Command @@ -44,23 +44,26 @@ class ShareUser extends Command
44 //获取所有ayr_share用户 44 //获取所有ayr_share用户
45 $ayr_share_model = new AyrShareModel(); 45 $ayr_share_model = new AyrShareModel();
46 $ayr_release = new AyrReleaseModel(); 46 $ayr_release = new AyrReleaseModel();
47 - $ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=',''],'project_id'=>410]); 47 + $ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
48 foreach ($ayr_share_list as $v){ 48 foreach ($ayr_share_list as $v){
49 $time = Carbon::now()->modify('-1 days')->toDateString(); 49 $time = Carbon::now()->modify('-1 days')->toDateString();
50 //创建时间小于7天前的当前时间 50 //创建时间小于7天前的当前时间
51 if($v['created_at'] > $time){ 51 if($v['created_at'] > $time){
  52 + echo '创建时间小于7天跳过。'.date('Y-m-d H:i:s').PHP_EOL;
52 continue; 53 continue;
53 } 54 }
54 //查询当前用户是否有未推送的博文 55 //查询当前用户是否有未推送的博文
55 $release_info = $this->release_info($ayr_release,$v); 56 $release_info = $this->release_info($ayr_release,$v);
56 //有推文时,直接跳出循环 57 //有推文时,直接跳出循环
57 if($release_info !== false){ 58 if($release_info !== false){
  59 + echo '有推文直接跳过。'.date('Y-m-d H:i:s').PHP_EOL;
58 continue; 60 continue;
59 } 61 }
60 //查询7天是否发送博文 62 //查询7天是否发送博文
61 $release_info = $this->release_seven_info($ayr_release); 63 $release_info = $this->release_seven_info($ayr_release);
62 //有发送博文,则跳出循环 64 //有发送博文,则跳出循环
63 if($release_info !== false){ 65 if($release_info !== false){
  66 + echo '7天内有推文跳过。'.date('Y-m-d H:i:s').PHP_EOL;
64 continue; 67 continue;
65 } 68 }
66 //删除用户第三方配置 69 //删除用户第三方配置
@@ -1148,6 +1148,9 @@ class ProductLogic extends BaseLogic @@ -1148,6 +1148,9 @@ class ProductLogic extends BaseLogic
1148 */ 1148 */
1149 public function batchSetKeyword(){ 1149 public function batchSetKeyword(){
1150 if(isset($this->param['is_cover']) && $this->param['is_cover'] == 1){//覆盖 1150 if(isset($this->param['is_cover']) && $this->param['is_cover'] == 1){//覆盖
  1151 + foreach ($this->param['id'] as $id){
  1152 + KeywordRelated::saveRelated($id,$this->param['keyword_id'] ?? []);//关键字关联
  1153 + }
1151 $this->param['keyword_id'] = ','.implode(',',$this->param['keyword_id']).','; 1154 $this->param['keyword_id'] = ','.implode(',',$this->param['keyword_id']).',';
1152 $this->edit(['keyword_id'=>$this->param['keyword_id']],['id'=>['in',$this->param['id']]]); 1155 $this->edit(['keyword_id'=>$this->param['keyword_id']],['id'=>['in',$this->param['id']]]);
1153 }else{ 1156 }else{
@@ -1155,6 +1158,7 @@ class ProductLogic extends BaseLogic @@ -1155,6 +1158,7 @@ class ProductLogic extends BaseLogic
1155 //获取当前产品的分类 1158 //获取当前产品的分类
1156 $productInfo = $this->model->read(['id'=>$id],['id','keyword_id']); 1159 $productInfo = $this->model->read(['id'=>$id],['id','keyword_id']);
1157 $keyword_ids_arr = array_values(array_unique(array_merge($productInfo['keyword_id'],$this->param['keyword_id']))); 1160 $keyword_ids_arr = array_values(array_unique(array_merge($productInfo['keyword_id'],$this->param['keyword_id'])));
  1161 + KeywordRelated::saveRelated($id,$keyword_ids_arr ?? []);//关键字关联
1158 $keyword_ids = ','.implode(',',$keyword_ids_arr).','; 1162 $keyword_ids = ','.implode(',',$keyword_ids_arr).',';
1159 $this->model->edit(['keyword_id'=>$keyword_ids],['id'=>$id]); 1163 $this->model->edit(['keyword_id'=>$keyword_ids],['id'=>$id]);
1160 } 1164 }