Your Name 5 months ago
parent
commit
2270586235
1 changed files with 46 additions and 4 deletions
  1. 46
    4
      application/api/controller/Ai.php

+ 46
- 4
application/api/controller/Ai.php View File

423
         //12.判断是否合法 同时存在触发词和并发词
423
         //12.判断是否合法 同时存在触发词和并发词
424
         [$is_bh1,$fc1] = $this->isInRule($data['cfc'],$line);
424
         [$is_bh1,$fc1] = $this->isInRule($data['cfc'],$line);
425
         [$is_bh2,$fc2] = $this->isInRule($data['bfc'],$line);
425
         [$is_bh2,$fc2] = $this->isInRule($data['bfc'],$line);
426
+
427
+
428
+        //13.替换指令的变量
429
+        //var_dump($data['zlj']);die;
430
+        if(!empty($data['zlj'])){
431
+            $zlj = json_decode($data['zlj'],true);
432
+            $zlj_new = [];
433
+            foreach ($zlj as $k => $v) {
434
+                $key = ''.(string)$k.'';
435
+                if (strpos($v,'K') !== false) {
436
+                    $v_str = str_replace("K", $line, $v);
437
+                    $zlj_new[$key] = $v_str;
438
+                }else{
439
+                    $zlj_new[$key] = $v;
440
+                }
441
+            }
442
+            $zlj_new_json = json_encode($zlj_new,JSON_UNESCAPED_UNICODE);
443
+            $data['zlj'] = $zlj_new_json;
444
+            //var_dump($zlj_new_json);die;
445
+        }
446
+
426
         if($is_bh1 > 0 && $is_bh2 > 0){
447
         if($is_bh1 > 0 && $is_bh2 > 0){
427
             //同时存在
448
             //同时存在
428
             $desc .= '同时存在并发词['.$fc2.']和触发词['.$fc1.']合法';
449
             $desc .= '同时存在并发词['.$fc2.']和触发词['.$fc1.']合法';
540
             ->order('tb_time desc')
561
             ->order('tb_time desc')
541
             ->limit(1)
562
             ->limit(1)
542
             ->find();
563
             ->find();
543
-        $lasttime = $row['tb_time'];
564
+
565
+        //var_dump($row);
566
+
567
+        if(isset($row['tb_time'])){
568
+            $lasttime = $row['tb_time'];
569
+        }else{
570
+            $lasttime = 0;
571
+        }
544
 
572
 
545
         $list = Db::name('cms_zl')->where([
573
         $list = Db::name('cms_zl')->where([
546
                 'catid'=>18,
574
                 'catid'=>18,
570
 
598
 
571
                 //读取指令集
599
                 //读取指令集
572
                 $zlj = $json['zlj'];
600
                 $zlj = $json['zlj'];
601
+                $zlj_arr = json_decode($zlj,true);
602
+                $zlj_end = end($zlj_arr);
603
+                $key = count($zlj_arr)-1;
604
+                unset($zlj_arr[$key]);
605
+                $zlj = json_encode($zlj_arr,JSON_UNESCAPED_UNICODE);
606
+
573
 
607
 
574
                 //获取创意
608
                 //获取创意
575
                 if((string)$json['is_sj'] === '-1'){
609
                 if((string)$json['is_sj'] === '-1'){
580
                         //既然指定 不管管是否为空
614
                         //既然指定 不管管是否为空
581
                         $cy = $json['cy'.$json['is_sj']];
615
                         $cy = $json['cy'.$json['is_sj']];
582
                     }else{
616
                     }else{
617
+
583
                         //随机
618
                         //随机
619
+
620
+
584
                         $sj_num = [];
621
                         $sj_num = [];
585
                         for($i=1;$i<=6;$i++){
622
                         for($i=1;$i<=6;$i++){
586
                             if(!empty($json['cy'.$i])){
623
                             if(!empty($json['cy'.$i])){
587
                                 $sj_num[] = $i;
624
                                 $sj_num[] = $i;
588
                             }
625
                             }
589
                         }
626
                         }
590
-                        $randomKey = array_rand($sj_num);
591
-                        $num = $sj_num[$randomKey];
592
-                        $cy = $json['cy'.$num];
627
+                        if(!empty($sj_num)){
628
+                            $randomKey = array_rand($sj_num);
629
+                            $num = $sj_num[$randomKey];
630
+                            $cy = $json['cy'.$num];
631
+                        }else{
632
+                            $cy = '0';
633
+                        }
593
                     }
634
                     }
594
                 }
635
                 }
595
 
636
 
610
                     'status' => 0, //默认手动开启
651
                     'status' => 0, //默认手动开启
611
                     'cy' => $cy, //创意
652
                     'cy' => $cy, //创意
612
                     'zlj' => $zlj, //指令集 json字符串
653
                     'zlj' => $zlj, //指令集 json字符串
654
+                    'tpzl' => $zlj_end,
613
                     'sjcy' => $json['is_sj'], //随机创意
655
                     'sjcy' => $json['is_sj'], //随机创意
614
                     'lyjlid' => $row['id'], //来源id
656
                     'lyjlid' => $row['id'], //来源id
615
                     'sblx' => 3,//设别类型 电脑A
657
                     'sblx' => 3,//设别类型 电脑A

Loading…
Cancel
Save