作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -15,6 +15,7 @@ use App\Services\ProjectServer; @@ -15,6 +15,7 @@ use App\Services\ProjectServer;
15 use Illuminate\Console\Command; 15 use Illuminate\Console\Command;
16 use Illuminate\Support\Facades\Cache; 16 use Illuminate\Support\Facades\Cache;
17 use Illuminate\Support\Facades\DB; 17 use Illuminate\Support\Facades\DB;
  18 +use Illuminate\Support\Facades\Redis;
18 19
19 /** 20 /**
20 * 初始化项目 21 * 初始化项目
@@ -149,7 +150,7 @@ class UpdateSeoTdk extends Command @@ -149,7 +150,7 @@ class UpdateSeoTdk extends Command
149 echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 150 echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
150 ProjectUpdateTdk::retry($task->id, $e->getMessage()); 151 ProjectUpdateTdk::retry($task->id, $e->getMessage());
151 } 152 }
152 - echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 153 + echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
153 } 154 }
154 } 155 }
155 156
@@ -162,18 +163,25 @@ class UpdateSeoTdk extends Command @@ -162,18 +163,25 @@ class UpdateSeoTdk extends Command
162 $ai_commands = Arr::setValueToKey($ai_commands, 'key'); 163 $ai_commands = Arr::setValueToKey($ai_commands, 'key');
163 foreach ($this->maps as $table => $map) { 164 foreach ($this->maps as $table => $map) {
164 $update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0]; 165 $update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
165 - echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL . json_encode($update[$table]); 166 + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
166 $list = DB::connection('custom_mysql')->table($table)->get(); 167 $list = DB::connection('custom_mysql')->table($table)->get();
167 if (!empty($list)) { 168 if (!empty($list)) {
168 $list = $list->toArray(); 169 $list = $list->toArray();
169 foreach ($list as $v) { 170 foreach ($list as $v) {
170 - echo '打印数据:'.date('Y-m-d H:i:s') . $update[$table]['total_page'].PHP_EOL;  
171 $update[$table]['total_page']++; 171 $update[$table]['total_page']++;
172 $v = (array)$v; 172 $v = (array)$v;
173 - echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL; 173 +
  174 + //缓存 在处理的项目数据 id
  175 + $cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
  176 + if(!Redis::setnx($cache_key, 1)){
  177 + continue;
  178 + }
  179 + Redis::expire($cache_key, 120);
  180 +
  181 + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
  182 +
174 $data = []; 183 $data = [];
175 $json_field = ''; 184 $json_field = '';
176 - echo date('Y-m-d H:i:s') . json_encode($map) . PHP_EOL;  
177 foreach ($map as $ai_key => $field) { 185 foreach ($map as $ai_key => $field) {
178 $field_arr = explode('.', $field); 186 $field_arr = explode('.', $field);
179 if (count($field_arr) > 1) { 187 if (count($field_arr) > 1) {
@@ -188,14 +196,6 @@ class UpdateSeoTdk extends Command @@ -188,14 +196,6 @@ class UpdateSeoTdk extends Command
188 continue; 196 continue;
189 } 197 }
190 198
191 - //缓存 在处理的 项目 数据 id  
192 - $cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";  
193 - if(Cache::get($cache_key)){  
194 - echo '其他进程在处理' . PHP_EOL;  
195 - continue;  
196 - }  
197 - Cache::put($cache_key, 1, 120);  
198 -  
199 //AI生成 199 //AI生成
200 if (!empty($ai_commands[$ai_key]['ai'])) { 200 if (!empty($ai_commands[$ai_key]['ai'])) {
201 $prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v); 201 $prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
@@ -307,8 +307,6 @@ class UpdateSeoTdk extends Command @@ -307,8 +307,6 @@ class UpdateSeoTdk extends Command
307 } 307 }
308 $prompt .= '.Please answer in ' . ($lang ?: 'English'); 308 $prompt .= '.Please answer in ' . ($lang ?: 'English');
309 309
310 - echo $prompt . PHP_EOL;  
311 -  
312 return $prompt; 310 return $prompt;
313 } 311 }
314 312
@@ -375,7 +373,6 @@ class UpdateSeoTdk extends Command @@ -375,7 +373,6 @@ class UpdateSeoTdk extends Command
375 public function ai_send($prompt) 373 public function ai_send($prompt)
376 { 374 {
377 $text = Gpt::instance()->openai_chat_qqs($prompt); 375 $text = Gpt::instance()->openai_chat_qqs($prompt);
378 - echo 'GPT result:' . $text . PHP_EOL;  
379 $text = Common::deal_keywords($text); 376 $text = Common::deal_keywords($text);
380 return Common::deal_str($text); 377 return Common::deal_str($text);
381 } 378 }
@@ -67,6 +67,13 @@ class ProjectLogic extends BaseLogic @@ -67,6 +67,13 @@ class ProjectLogic extends BaseLogic
67 if($info['extend_type'] != 0){ 67 if($info['extend_type'] != 0){
68 $info['type'] = $info['extend_type']; 68 $info['type'] = $info['extend_type'];
69 } 69 }
  70 + //升级项目初始上传配置
  71 + if(empty($info['upload_config'])){
  72 + $info['upload_config'] =["upload_max_num"=>100, "allow_file_type"=>"doc,docx,xls,xlsx,pdf,txt,csv,png,jpg,jpeg", "upload_max_size"=>5];
  73 + }
  74 + if(empty($info['channel'])){
  75 + $info['channel'] = ["user_id"=>"", "zone_id"=>"", "channel_id"=>""];
  76 + }
70 return $this->success($info); 77 return $this->success($info);
71 } 78 }
72 79
@@ -525,9 +532,12 @@ class ProjectLogic extends BaseLogic @@ -525,9 +532,12 @@ class ProjectLogic extends BaseLogic
525 * @time :2023/11/8 14:23 532 * @time :2023/11/8 14:23
526 */ 533 */
527 public function copyProject(){ 534 public function copyProject(){
  535 + DB::beginTransaction();
  536 + try {
528 //复制初始项目 537 //复制初始项目
529 $data = $this->model::where('id', $this->param['project_id'])->first(); 538 $data = $this->model::where('id', $this->param['project_id'])->first();
530 $data = $data->getAttributes(); 539 $data = $data->getAttributes();
  540 + $type = $data['type'];
531 $data['type'] = 0; 541 $data['type'] = 0;
532 $data['title'] = $data['title'].'-copy'; 542 $data['title'] = $data['title'].'-copy';
533 unset($data['id']); 543 unset($data['id']);
@@ -562,6 +572,15 @@ class ProjectLogic extends BaseLogic @@ -562,6 +572,15 @@ class ProjectLogic extends BaseLogic
562 $paymentData['project_id'] = $project_id; 572 $paymentData['project_id'] = $project_id;
563 $paymentModel->insert($paymentData); 573 $paymentModel->insert($paymentData);
564 } 574 }
  575 + //复制售后表
  576 + $afterModel = new After();
  577 + $afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
  578 + if(!empty($afterData)){
  579 + $afterData = $afterData->getAttributes();
  580 + unset($afterData['id']);
  581 + $afterData['project_id'] = $project_id;
  582 + $afterModel->insert($afterData);
  583 + }
565 //复制用户 584 //复制用户
566 $userModel = new UserModel(); 585 $userModel = new UserModel();
567 $userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first(); 586 $userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
@@ -580,7 +599,14 @@ class ProjectLogic extends BaseLogic @@ -580,7 +599,14 @@ class ProjectLogic extends BaseLogic
580 $settingData['project_id'] = $project_id; 599 $settingData['project_id'] = $project_id;
581 $settingTemplateModel->insert($settingData); 600 $settingTemplateModel->insert($settingData);
582 } 601 }
  602 + DB::commit();
  603 + }catch (\Exception $e){
  604 + DB::rollBack();
  605 + $this->fail('error');
  606 + }
  607 + if($type != 0){
583 $this->copyMysql($this->param['project_id'],$project_id); 608 $this->copyMysql($this->param['project_id'],$project_id);
  609 + }
584 return $this->success($data); 610 return $this->success($data);
585 } 611 }
586 612
@@ -13,6 +13,7 @@ use App\Helper\Arr; @@ -13,6 +13,7 @@ use App\Helper\Arr;
13 use App\Models\Base; 13 use App\Models\Base;
14 use Illuminate\Support\Facades\DB; 14 use Illuminate\Support\Facades\DB;
15 use Illuminate\Support\Facades\Log; 15 use Illuminate\Support\Facades\Log;
  16 +use Illuminate\Support\Facades\Redis;
16 17
17 class ProjectUpdateTdk extends Base 18 class ProjectUpdateTdk extends Base
18 { 19 {
@@ -30,6 +31,7 @@ class ProjectUpdateTdk extends Base @@ -30,6 +31,7 @@ class ProjectUpdateTdk extends Base
30 * @date 2023/11/9 31 * @date 2023/11/9
31 */ 32 */
32 public static function add_task($project_id){ 33 public static function add_task($project_id){
  34 + Redis::lpush('updateSeoTdk', $project_id);
33 $model = new self(); 35 $model = new self();
34 $model->project_id = $project_id; 36 $model->project_id = $project_id;
35 $model->save(); 37 $model->save();
@@ -42,6 +44,15 @@ class ProjectUpdateTdk extends Base @@ -42,6 +44,15 @@ class ProjectUpdateTdk extends Base
42 * @date 2023/11/9 44 * @date 2023/11/9
43 */ 45 */
44 public static function getPendingTask(){ 46 public static function getPendingTask(){
  47 + //有其他任务 就取其他任务 没有其他任务运行未结束的任务
  48 + $project_id = Redis::rpop('updateSeoTdk');
  49 + $data = [];
  50 + if($project_id){
  51 + $data = self::find($project_id);
  52 + }
  53 + if($data){
  54 + return $data;
  55 + }
45 return self::where('status', self::STATUS_PENDING)->orderBy('id', 'asc')->first(); 56 return self::where('status', self::STATUS_PENDING)->orderBy('id', 'asc')->first();
46 } 57 }
47 58