作者 刘锟

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

... ... @@ -6,6 +6,7 @@ use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Models\Ai\AiCommand;
use App\Models\Ai\AiTdkErrorLog;
use App\Models\Com\UpdateNotify;
use App\Models\Domain\DomainInfo;
use App\Models\Mail\Mail;
... ... @@ -271,6 +272,14 @@ class UpdateSeoTdk extends Command
}
Redis::expire($cache_key, 120);
//连续3次失败的 不再处理
$error_log = AiTdkErrorLog::getLog($project_id, $table, $v['id']);
if($error_log){
continue;
}
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
$v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first();
$v = (array)$v;
... ... @@ -304,7 +313,7 @@ class UpdateSeoTdk extends Command
}elseif ($field_arr[1] == 'description'){
$update[$table]['des']++;
}
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt);
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt, $project_id, $table, $v['id']);
}else{
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
... ... @@ -321,7 +330,7 @@ class UpdateSeoTdk extends Command
if($field == 'keyword_content'){
$update[$table]['keyword_content']++;
}
$data[$field] = $this->ai_send($prompt);
$data[$field] = $this->ai_send($prompt, $project_id, $table, $v['id']);
}
} else {
//直接使用topic
... ... @@ -499,15 +508,29 @@ class UpdateSeoTdk extends Command
* @method :post
* @time :2023/8/19 10:40
*/
public function ai_send($prompt)
public function ai_send($prompt, $project_id, $table, $id)
{
$text = Gpt::instance()->openai_chat_qqs($prompt);
if (!$text) {
$cache_key = "ai_error_times_{$project_id}_{$table}_{$id}";
if (!Cache::get($cache_key)) {
Cache::put($cache_key, 0, 7 * 24 * 3600);
}
$times = Cache::increment($cache_key);
//3次错误 记录下来 后面不处理了
if ($times > 2) {
AiTdkErrorLog::insertLog($project_id, $table, $id, $prompt);
Cache::forget($cache_key);
}
}
$text = Common::deal_keywords($text);
$text = Common::deal_str($text);
//包含这写字 重新生成
if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){
return $this->ai_send($prompt);
return $this->ai_send($prompt, $project_id, $table, $id);
}
return $text;
... ...
... ... @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Detail;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
... ... @@ -678,7 +679,11 @@ class ProductController extends BaseController
$new_content = htmlentities($contents);
}
if (!empty($new_content)){
$productInfo['content'] = $new_content . $productInfo['content'];
$detailModel = new Detail();
$detailInfo = $detailModel->read(['column_id'=>1]);
if($detailInfo !== false && !empty($detailInfo['content'])){
$productInfo['content'] = $new_content . $detailInfo['content']['content'];
}
}
$this->response('success',Code::SUCCESS,$productInfo);
}
... ...
... ... @@ -133,9 +133,9 @@ class BlogLogic extends BaseLogic
if($info['status'] != 2){
$this->model->edit(['status'=>2],['id'=>$id]);
}else{
$this->delRoute($id);
$this->model->del(['id' => $id]);
}
$this->delRoute($id);
}
DB::commit();
}catch (Exception $e){
... ...
... ... @@ -163,9 +163,9 @@ class NewsLogic extends BaseLogic
if($info['status'] != 2){
$this->model->edit(['status'=>2],['id'=>$id]);
}else{
$this->delRoute($id);
$this->model->del(['id' => $id]);
}
$this->delRoute($id);
}
DB::commit();
} catch (Exception $e) {
... ...
... ... @@ -430,7 +430,6 @@ class ProductLogic extends BaseLogic
foreach ($this->param['ids'] as $id) {
$info = $this->model->read(['id'=>$id],['id','status']);
if($info['status'] == Product::STATUS_RECYCLE){
$this->delRoute($id);
//删除当前产品模版
// $this->delProductModule($id);
$this->model->del(['id'=>$id]);
... ... @@ -441,6 +440,7 @@ class ProductLogic extends BaseLogic
//回收站
$this->model->edit(['status'=>Product::STATUS_RECYCLE],['id'=>$id]);
}
$this->delRoute($id);
}
DB::connection('custom_mysql')->commit();
}catch (\Exception $e){
... ...
<?php
namespace App\Models\Ai;
use App\Models\Base;
class AiTdkErrorLog extends Base
{
//设置关联表名
protected $table = 'gl_ai_tdk_error_log';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
public static function insertLog($project_id, $table, $table_id, $prompt){
$model = new self();
$model->project_id = $project_id;
$model->table_name = $table;
$model->table_id = $table_id;
$model->prompt = $prompt;
$model->save();
}
public static function getLog($project_id, $table, $table_id){
return self::where('project_id', $project_id)->where('table_name', $table)->where('table_id', $table_id)->first();
}
}
... ...