作者 刘锟

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

@@ -6,6 +6,7 @@ use App\Helper\Arr; @@ -6,6 +6,7 @@ use App\Helper\Arr;
6 use App\Helper\Common; 6 use App\Helper\Common;
7 use App\Helper\Gpt; 7 use App\Helper\Gpt;
8 use App\Models\Ai\AiCommand; 8 use App\Models\Ai\AiCommand;
  9 +use App\Models\Ai\AiTdkErrorLog;
9 use App\Models\Com\UpdateNotify; 10 use App\Models\Com\UpdateNotify;
10 use App\Models\Domain\DomainInfo; 11 use App\Models\Domain\DomainInfo;
11 use App\Models\Mail\Mail; 12 use App\Models\Mail\Mail;
@@ -271,6 +272,14 @@ class UpdateSeoTdk extends Command @@ -271,6 +272,14 @@ class UpdateSeoTdk extends Command
271 } 272 }
272 Redis::expire($cache_key, 120); 273 Redis::expire($cache_key, 120);
273 274
  275 +
  276 + //连续3次失败的 不再处理
  277 + $error_log = AiTdkErrorLog::getLog($project_id, $table, $v['id']);
  278 + if($error_log){
  279 + continue;
  280 + }
  281 +
  282 +
274 echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL; 283 echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
275 $v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first(); 284 $v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first();
276 $v = (array)$v; 285 $v = (array)$v;
@@ -304,7 +313,7 @@ class UpdateSeoTdk extends Command @@ -304,7 +313,7 @@ class UpdateSeoTdk extends Command
304 }elseif ($field_arr[1] == 'description'){ 313 }elseif ($field_arr[1] == 'description'){
305 $update[$table]['des']++; 314 $update[$table]['des']++;
306 } 315 }
307 - $data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt); 316 + $data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt, $project_id, $table, $v['id']);
308 }else{ 317 }else{
309 if($field == 'title' || $field == 'seo_title'){ 318 if($field == 'title' || $field == 'seo_title'){
310 $update[$table]['title']++; 319 $update[$table]['title']++;
@@ -321,7 +330,7 @@ class UpdateSeoTdk extends Command @@ -321,7 +330,7 @@ class UpdateSeoTdk extends Command
321 if($field == 'keyword_content'){ 330 if($field == 'keyword_content'){
322 $update[$table]['keyword_content']++; 331 $update[$table]['keyword_content']++;
323 } 332 }
324 - $data[$field] = $this->ai_send($prompt); 333 + $data[$field] = $this->ai_send($prompt, $project_id, $table, $v['id']);
325 } 334 }
326 } else { 335 } else {
327 //直接使用topic 336 //直接使用topic
@@ -499,15 +508,29 @@ class UpdateSeoTdk extends Command @@ -499,15 +508,29 @@ class UpdateSeoTdk extends Command
499 * @method :post 508 * @method :post
500 * @time :2023/8/19 10:40 509 * @time :2023/8/19 10:40
501 */ 510 */
502 - public function ai_send($prompt) 511 + public function ai_send($prompt, $project_id, $table, $id)
503 { 512 {
504 $text = Gpt::instance()->openai_chat_qqs($prompt); 513 $text = Gpt::instance()->openai_chat_qqs($prompt);
  514 +
  515 + if (!$text) {
  516 + $cache_key = "ai_error_times_{$project_id}_{$table}_{$id}";
  517 + if (!Cache::get($cache_key)) {
  518 + Cache::put($cache_key, 0, 7 * 24 * 3600);
  519 + }
  520 + $times = Cache::increment($cache_key);
  521 + //3次错误 记录下来 后面不处理了
  522 + if ($times > 2) {
  523 + AiTdkErrorLog::insertLog($project_id, $table, $id, $prompt);
  524 + Cache::forget($cache_key);
  525 + }
  526 + }
  527 +
505 $text = Common::deal_keywords($text); 528 $text = Common::deal_keywords($text);
506 $text = Common::deal_str($text); 529 $text = Common::deal_str($text);
507 530
508 //包含这写字 重新生成 531 //包含这写字 重新生成
509 if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){ 532 if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){
510 - return $this->ai_send($prompt); 533 + return $this->ai_send($prompt, $project_id, $table, $id);
511 } 534 }
512 535
513 return $text; 536 return $text;
@@ -12,6 +12,7 @@ use App\Http\Logic\Bside\Product\ProductLogic; @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
12 use App\Http\Requests\Bside\Product\ProductRequest; 12 use App\Http\Requests\Bside\Product\ProductRequest;
13 use App\Models\Product\Category; 13 use App\Models\Product\Category;
14 use App\Models\Product\CategoryRelated; 14 use App\Models\Product\CategoryRelated;
  15 +use App\Models\Product\Detail;
15 use App\Models\Product\Extend; 16 use App\Models\Product\Extend;
16 use App\Models\Product\ExtendInfo; 17 use App\Models\Product\ExtendInfo;
17 use App\Models\Product\Keyword; 18 use App\Models\Product\Keyword;
@@ -678,7 +679,11 @@ class ProductController extends BaseController @@ -678,7 +679,11 @@ class ProductController extends BaseController
678 $new_content = htmlentities($contents); 679 $new_content = htmlentities($contents);
679 } 680 }
680 if (!empty($new_content)){ 681 if (!empty($new_content)){
681 - $productInfo['content'] = $new_content . $productInfo['content']; 682 + $detailModel = new Detail();
  683 + $detailInfo = $detailModel->read(['column_id'=>1]);
  684 + if($detailInfo !== false && !empty($detailInfo['content'])){
  685 + $productInfo['content'] = $new_content . $detailInfo['content']['content'];
  686 + }
682 } 687 }
683 $this->response('success',Code::SUCCESS,$productInfo); 688 $this->response('success',Code::SUCCESS,$productInfo);
684 } 689 }
@@ -133,9 +133,9 @@ class BlogLogic extends BaseLogic @@ -133,9 +133,9 @@ class BlogLogic extends BaseLogic
133 if($info['status'] != 2){ 133 if($info['status'] != 2){
134 $this->model->edit(['status'=>2],['id'=>$id]); 134 $this->model->edit(['status'=>2],['id'=>$id]);
135 }else{ 135 }else{
136 - $this->delRoute($id);  
137 $this->model->del(['id' => $id]); 136 $this->model->del(['id' => $id]);
138 } 137 }
  138 + $this->delRoute($id);
139 } 139 }
140 DB::commit(); 140 DB::commit();
141 }catch (Exception $e){ 141 }catch (Exception $e){
@@ -163,9 +163,9 @@ class NewsLogic extends BaseLogic @@ -163,9 +163,9 @@ class NewsLogic extends BaseLogic
163 if($info['status'] != 2){ 163 if($info['status'] != 2){
164 $this->model->edit(['status'=>2],['id'=>$id]); 164 $this->model->edit(['status'=>2],['id'=>$id]);
165 }else{ 165 }else{
166 - $this->delRoute($id);  
167 $this->model->del(['id' => $id]); 166 $this->model->del(['id' => $id]);
168 } 167 }
  168 + $this->delRoute($id);
169 } 169 }
170 DB::commit(); 170 DB::commit();
171 } catch (Exception $e) { 171 } catch (Exception $e) {
@@ -430,7 +430,6 @@ class ProductLogic extends BaseLogic @@ -430,7 +430,6 @@ class ProductLogic extends BaseLogic
430 foreach ($this->param['ids'] as $id) { 430 foreach ($this->param['ids'] as $id) {
431 $info = $this->model->read(['id'=>$id],['id','status']); 431 $info = $this->model->read(['id'=>$id],['id','status']);
432 if($info['status'] == Product::STATUS_RECYCLE){ 432 if($info['status'] == Product::STATUS_RECYCLE){
433 - $this->delRoute($id);  
434 //删除当前产品模版 433 //删除当前产品模版
435 // $this->delProductModule($id); 434 // $this->delProductModule($id);
436 $this->model->del(['id'=>$id]); 435 $this->model->del(['id'=>$id]);
@@ -441,6 +440,7 @@ class ProductLogic extends BaseLogic @@ -441,6 +440,7 @@ class ProductLogic extends BaseLogic
441 //回收站 440 //回收站
442 $this->model->edit(['status'=>Product::STATUS_RECYCLE],['id'=>$id]); 441 $this->model->edit(['status'=>Product::STATUS_RECYCLE],['id'=>$id]);
443 } 442 }
  443 + $this->delRoute($id);
444 } 444 }
445 DB::connection('custom_mysql')->commit(); 445 DB::connection('custom_mysql')->commit();
446 }catch (\Exception $e){ 446 }catch (\Exception $e){
  1 +<?php
  2 +
  3 +namespace App\Models\Ai;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class AiTdkErrorLog extends Base
  8 +{
  9 + //设置关联表名
  10 + protected $table = 'gl_ai_tdk_error_log';
  11 + //自动维护create_at创建时间 updated_at修改时间
  12 + public $timestamps = true;
  13 +
  14 + public static function insertLog($project_id, $table, $table_id, $prompt){
  15 + $model = new self();
  16 + $model->project_id = $project_id;
  17 + $model->table_name = $table;
  18 + $model->table_id = $table_id;
  19 + $model->prompt = $prompt;
  20 + $model->save();
  21 + }
  22 +
  23 + public static function getLog($project_id, $table, $table_id){
  24 + return self::where('project_id', $project_id)->where('table_name', $table)->where('table_id', $table_id)->first();
  25 + }
  26 +}