作者 赵彬吉

tdk ai command

@@ -241,8 +241,16 @@ class UpdateSeoTdk extends Command @@ -241,8 +241,16 @@ class UpdateSeoTdk extends Command
241 $notify_master = $notify_keyword = false; 241 $notify_master = $notify_keyword = false;
242 //更新统计 242 //更新统计
243 $update = []; 243 $update = [];
244 - $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); 244 + //AI指令 是否有定制指令
  245 + $ai_commands = AiCommand::where('is_batch', 1)->where('project_id', 0)->select('key', 'scene', 'ai')->get()->toArray();
  246 + $project_ai_commands = AiCommand::where('is_batch', 1)->where('project_id', $project_id)->select('key', 'scene', 'ai')->get()->toArray();
245 $ai_commands = Arr::setValueToKey($ai_commands, 'key'); 247 $ai_commands = Arr::setValueToKey($ai_commands, 'key');
  248 + $project_ai_commands = Arr::setValueToKey($project_ai_commands, 'key');
  249 + foreach ($ai_commands as $k => $ai_command){
  250 + if(!empty($project_ai_commands[$k])){
  251 + $ai_commands[$k] = $project_ai_commands[$k];
  252 + }
  253 + }
246 foreach ($this->maps as $table => $map) { 254 foreach ($this->maps as $table => $map) {
247 $total_page = DB::connection('custom_mysql')->table($table)->count(); 255 $total_page = DB::connection('custom_mysql')->table($table)->count();
248 $update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0]; 256 $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 @@ -505,7 +513,7 @@ class UpdateSeoTdk extends Command
505 $info = $this->getDeployOptimize($project_id); 513 $info = $this->getDeployOptimize($project_id);
506 if (!empty($info['keyword_' . $type])) { 514 if (!empty($info['keyword_' . $type])) {
507 $fix_keyword = explode(",", $info['keyword_' . $type]); 515 $fix_keyword = explode(",", $info['keyword_' . $type]);
508 - 516 + $fix_keyword = array_filter($fix_keyword);
509 //去掉标题存在的词 517 //去掉标题存在的词
510 if ($topic) { 518 if ($topic) {
511 foreach ($fix_keyword as $k=>$keyword) { 519 foreach ($fix_keyword as $k=>$keyword) {
@@ -1097,6 +1097,7 @@ function getPrefixKeyword($project_id, $type, $num) @@ -1097,6 +1097,7 @@ function getPrefixKeyword($project_id, $type, $num)
1097 $info = getDeployOptimize($project_id); 1097 $info = getDeployOptimize($project_id);
1098 if (!empty($info['keyword_' . $type])) { 1098 if (!empty($info['keyword_' . $type])) {
1099 $fix_keyword = explode(",", $info['keyword_' . $type]); 1099 $fix_keyword = explode(",", $info['keyword_' . $type]);
  1100 + $fix_keyword = array_filter($fix_keyword);
1100 //随机取 1101 //随机取
1101 shuffle($fix_keyword); 1102 shuffle($fix_keyword);
1102 if (count($fix_keyword) < $num) 1103 if (count($fix_keyword) < $num)
@@ -37,12 +37,26 @@ class AiCommandLogic extends BaseLogic @@ -37,12 +37,26 @@ class AiCommandLogic extends BaseLogic
37 */ 37 */
38 public function ai_add(){ 38 public function ai_add(){
39 $condition = [ 39 $condition = [
40 - 'key'=>$this->param['key'] 40 + 'key'=>$this->param['key'],
  41 + 'project_id'=>$this->param['project_id']??0,
41 ]; 42 ];
42 $info = $this->model->read($condition); 43 $info = $this->model->read($condition);
43 if($info !== false){ 44 if($info !== false){
44 $this->fail('当前指令已存在'); 45 $this->fail('当前指令已存在');
45 } 46 }
  47 + if($condition['project_id']){
  48 + $where = [
  49 + 'key'=>$this->param['key'],
  50 + 'project_id'=>0,
  51 + 'is_batch'=>1,
  52 + ];
  53 + $valid_key = $this->model->read($where);
  54 + if(!$valid_key){
  55 + $this->fail('指令字段不正确');
  56 + }
  57 + $this->param['is_batch'] = 1;
  58 + }
  59 +
46 $this->param['operator_id'] = $this->manager['id']; 60 $this->param['operator_id'] = $this->manager['id'];
47 $this->param['create_id'] = $this->manager['id']; 61 $this->param['create_id'] = $this->manager['id'];
48 $rs = $this->model->add($this->param); 62 $rs = $this->model->add($this->param);
@@ -61,12 +75,25 @@ class AiCommandLogic extends BaseLogic @@ -61,12 +75,25 @@ class AiCommandLogic extends BaseLogic
61 public function ai_edit(){ 75 public function ai_edit(){
62 $condition = [ 76 $condition = [
63 'id'=>['!=',$this->param['id']], 77 'id'=>['!=',$this->param['id']],
64 - 'key'=>$this->param['key'] 78 + 'key'=>$this->param['key'],
  79 + 'project_id'=>$this->param['project_id']??0,
65 ]; 80 ];
66 $info = $this->model->read($condition); 81 $info = $this->model->read($condition);
67 if($info !== false){ 82 if($info !== false){
68 $this->fail('当前编辑的指令key已存在'); 83 $this->fail('当前编辑的指令key已存在');
69 } 84 }
  85 + if($condition['project_id']){
  86 + $where = [
  87 + 'key'=>$this->param['key'],
  88 + 'project_id'=>0,
  89 + 'is_batch'=>1,
  90 + ];
  91 + $valid_key = $this->model->read($where);
  92 + if(!$valid_key){
  93 + $this->fail('指令字段不正确');
  94 + }
  95 + $this->param['is_batch'] = 1;
  96 + }
70 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); 97 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
71 if($rs === false){ 98 if($rs === false){
72 $this->fail('error'); 99 $this->fail('error');
@@ -26,7 +26,11 @@ class AiCommandLogic extends BaseLogic @@ -26,7 +26,11 @@ class AiCommandLogic extends BaseLogic
26 * @date 2023/11/22 26 * @date 2023/11/22
27 */ 27 */
28 public function getPrompt($is_batch = 0){ 28 public function getPrompt($is_batch = 0){
29 - $ai_command = $this->model->where('key', $this->param['key'])->first(); 29 + //是否有项目指令
  30 + $ai_command = $this->model->where('key', $this->param['key'])->where('project_id', $this->project['id'])->first();
  31 + if(!$ai_command){
  32 + $ai_command = $this->model->where('key', $this->param['key'])->where('project_id', 0)->first();
  33 + }
30 if(!$ai_command){ 34 if(!$ai_command){
31 $this->fail('指令不存在'); 35 $this->fail('指令不存在');
32 } 36 }