作者 赵彬吉

tdk ai command

... ... @@ -241,8 +241,16 @@ class UpdateSeoTdk extends Command
$notify_master = $notify_keyword = false;
//更新统计
$update = [];
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
//AI指令 是否有定制指令
$ai_commands = AiCommand::where('is_batch', 1)->where('project_id', 0)->select('key', 'scene', 'ai')->get()->toArray();
$project_ai_commands = AiCommand::where('is_batch', 1)->where('project_id', $project_id)->select('key', 'scene', 'ai')->get()->toArray();
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
$project_ai_commands = Arr::setValueToKey($project_ai_commands, 'key');
foreach ($ai_commands as $k => $ai_command){
if(!empty($project_ai_commands[$k])){
$ai_commands[$k] = $project_ai_commands[$k];
}
}
foreach ($this->maps as $table => $map) {
$total_page = DB::connection('custom_mysql')->table($table)->count();
$update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0];
... ... @@ -505,7 +513,7 @@ class UpdateSeoTdk extends Command
$info = $this->getDeployOptimize($project_id);
if (!empty($info['keyword_' . $type])) {
$fix_keyword = explode(",", $info['keyword_' . $type]);
$fix_keyword = array_filter($fix_keyword);
//去掉标题存在的词
if ($topic) {
foreach ($fix_keyword as $k=>$keyword) {
... ...
... ... @@ -1097,6 +1097,7 @@ function getPrefixKeyword($project_id, $type, $num)
$info = getDeployOptimize($project_id);
if (!empty($info['keyword_' . $type])) {
$fix_keyword = explode(",", $info['keyword_' . $type]);
$fix_keyword = array_filter($fix_keyword);
//随机取
shuffle($fix_keyword);
if (count($fix_keyword) < $num)
... ...
... ... @@ -37,12 +37,26 @@ class AiCommandLogic extends BaseLogic
*/
public function ai_add(){
$condition = [
'key'=>$this->param['key']
'key'=>$this->param['key'],
'project_id'=>$this->param['project_id']??0,
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前指令已存在');
}
if($condition['project_id']){
$where = [
'key'=>$this->param['key'],
'project_id'=>0,
'is_batch'=>1,
];
$valid_key = $this->model->read($where);
if(!$valid_key){
$this->fail('指令字段不正确');
}
$this->param['is_batch'] = 1;
}
$this->param['operator_id'] = $this->manager['id'];
$this->param['create_id'] = $this->manager['id'];
$rs = $this->model->add($this->param);
... ... @@ -61,12 +75,25 @@ class AiCommandLogic extends BaseLogic
public function ai_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'key'=>$this->param['key']
'key'=>$this->param['key'],
'project_id'=>$this->param['project_id']??0,
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前编辑的指令key已存在');
}
if($condition['project_id']){
$where = [
'key'=>$this->param['key'],
'project_id'=>0,
'is_batch'=>1,
];
$valid_key = $this->model->read($where);
if(!$valid_key){
$this->fail('指令字段不正确');
}
$this->param['is_batch'] = 1;
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
... ...
... ... @@ -26,7 +26,11 @@ class AiCommandLogic extends BaseLogic
* @date 2023/11/22
*/
public function getPrompt($is_batch = 0){
$ai_command = $this->model->where('key', $this->param['key'])->first();
//是否有项目指令
$ai_command = $this->model->where('key', $this->param['key'])->where('project_id', $this->project['id'])->first();
if(!$ai_command){
$ai_command = $this->model->where('key', $this->param['key'])->where('project_id', 0)->first();
}
if(!$ai_command){
$this->fail('指令不存在');
}
... ...