作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !1672
@@ -95,7 +95,7 @@ class RemainDay extends Command @@ -95,7 +95,7 @@ class RemainDay extends Command
95 if($item['type'] != Project::TYPE_THREE){ 95 if($item['type'] != Project::TYPE_THREE){
96 $pause_days = $item['pause_days'] + 1; 96 $pause_days = $item['pause_days'] + 1;
97 } 97 }
98 -// $this->project->edit(['pause_days'=>$pause_days],['id'=>$item['id']]); 98 + $this->project->edit(['pause_days'=>$pause_days],['id'=>$item['id']]);
99 continue; 99 continue;
100 } 100 }
101 //白帽版本的系统 101 //白帽版本的系统
@@ -110,11 +110,11 @@ class RemainDay extends Command @@ -110,11 +110,11 @@ class RemainDay extends Command
110 $seo_remain_day = 0; 110 $seo_remain_day = 0;
111 } 111 }
112 if($deploy_build['plan'] == 0 && $seo_remain_day == 0 && $deploy_build['seo_service_duration'] != 0){//只有白帽版本的项目且剩余服务时常未0,放入未续费中 112 if($deploy_build['plan'] == 0 && $seo_remain_day == 0 && $deploy_build['seo_service_duration'] != 0){//只有白帽版本的项目且剩余服务时常未0,放入未续费中
113 -// $this->project->edit(['seo_remain_day'=>$seo_remain_day,'extend_type'=>Project::TYPE_FIVE],['id'=>$item['id']]); 113 + $this->project->edit(['seo_remain_day'=>$seo_remain_day,'extend_type'=>Project::TYPE_FIVE],['id'=>$item['id']]);
114 continue; 114 continue;
115 } 115 }
116 //同时包括白帽版本+默认版本的项目 116 //同时包括白帽版本+默认版本的项目
117 -// $this->project->edit(['seo_remain_day'=>$seo_remain_day],['id'=>$item['id']]); 117 + $this->project->edit(['seo_remain_day'=>$seo_remain_day],['id'=>$item['id']]);
118 } 118 }
119 //默认版本计算剩余服务时常 119 //默认版本计算剩余服务时常
120 if($item['type'] == Project::TYPE_TWO || $item['type'] == Project::TYPE_FOUR){ 120 if($item['type'] == Project::TYPE_TWO || $item['type'] == Project::TYPE_FOUR){
@@ -144,7 +144,7 @@ class RemainDay extends Command @@ -144,7 +144,7 @@ class RemainDay extends Command
144 $remain_day = 0; 144 $remain_day = 0;
145 $extend_type = Project::TYPE_FIVE; 145 $extend_type = Project::TYPE_FIVE;
146 } 146 }
147 -// $this->project->edit(['remain_day'=>$remain_day,'extend_type'=>$extend_type],['id'=>$item['id']]); 147 + $this->project->edit(['remain_day'=>$remain_day,'extend_type'=>$extend_type],['id'=>$item['id']]);
148 echo 'end->项目id:' . $item['id'] . '执行时间:'. date('Y-m-d H:i:s') . PHP_EOL; 148 echo 'end->项目id:' . $item['id'] . '执行时间:'. date('Y-m-d H:i:s') . PHP_EOL;
149 } 149 }
150 return true; 150 return true;
@@ -13,6 +13,7 @@ use App\Enums\Common\Code; @@ -13,6 +13,7 @@ use App\Enums\Common\Code;
13 use App\Helper\FormGlobalsoApi; 13 use App\Helper\FormGlobalsoApi;
14 use App\Helper\PayStripeApi; 14 use App\Helper\PayStripeApi;
15 use App\Helper\Translate; 15 use App\Helper\Translate;
  16 +use App\Http\Logic\Bside\Gpt\ChatLogic;
16 use App\Http\Logic\Bside\News\NewsLogic; 17 use App\Http\Logic\Bside\News\NewsLogic;
17 use App\Models\Ai\AiBlog; 18 use App\Models\Ai\AiBlog;
18 use App\Models\Channel\Channel; 19 use App\Models\Channel\Channel;
@@ -41,9 +42,13 @@ class TestController extends BaseController @@ -41,9 +42,13 @@ class TestController extends BaseController
41 * @method :post 42 * @method :post
42 * @time :2025/2/13 16:34 43 * @time :2025/2/13 16:34
43 */ 44 */
44 - public function ceshi(){  
45 - //获取上一周询盘数量  
46 - $transData = Translate::tran(['heidenhain programming','heidenhain tnc 620'], 'zh');  
47 - $this->response('success',Code::SUCCESS,$transData); 45 + public function ceshi(ChatLogic $logic){
  46 + $this->request->validate([
  47 + 'message'=>['required'],
  48 + ],[
  49 + 'message.required' => '消息内容不能为空',
  50 + ]);
  51 + $data = $logic->sendMessage();
  52 + $this->response('success',Code::SUCCESS,$data);
48 } 53 }
49 } 54 }
@@ -11,6 +11,8 @@ namespace App\Http\Logic\Bside\Gpt; @@ -11,6 +11,8 @@ namespace App\Http\Logic\Bside\Gpt;
11 11
12 use App\Http\Logic\Bside\BaseLogic; 12 use App\Http\Logic\Bside\BaseLogic;
13 use App\Models\Gpt\Chat; 13 use App\Models\Gpt\Chat;
  14 +use App\Models\Gpt\ChatItem;
  15 +use App\Services\GptService;
14 16
15 class ChatLogic extends BaseLogic 17 class ChatLogic extends BaseLogic
16 { 18 {
@@ -18,6 +20,7 @@ class ChatLogic extends BaseLogic @@ -18,6 +20,7 @@ class ChatLogic extends BaseLogic
18 { 20 {
19 parent::__construct(); 21 parent::__construct();
20 $this->model = new Chat(); 22 $this->model = new Chat();
  23 + $this->itemModel = new ChatItem();
21 } 24 }
22 25
23 /** 26 /**
@@ -28,18 +31,37 @@ class ChatLogic extends BaseLogic @@ -28,18 +31,37 @@ class ChatLogic extends BaseLogic
28 * @time :2025/4/2 10:01 31 * @time :2025/4/2 10:01
29 */ 32 */
30 public function sendMessage(){ 33 public function sendMessage(){
  34 + $gptService = new GptService();
31 if(isset($this->param['chat_id'])){ 35 if(isset($this->param['chat_id'])){
32 $chatInfo = $this->model->read(['id'=>$this->param['chat_id']]); 36 $chatInfo = $this->model->read(['id'=>$this->param['chat_id']]);
33 - if($chatInfo === false){  
34 - $id = $this->saveChat($this->param['message']);  
35 - }else{  
36 - $id = $chatInfo['id']; 37 + if($chatInfo !== false){
  38 + $list = $this->itemModel->list(['chat_id'=>$chatInfo['id'],'id',['*'],'desc',2]);
  39 + $message[] = ['role' => 'system', 'content' => "You are now the marketing customer service of 深圳创贸集团"];
  40 + foreach ($list as $val){
  41 + if($val['is_reply'] == 2){
  42 + $message[] = ['role' => 'user', 'content' => $val['content']];
  43 + }else{
  44 + $message[] = ['role' => 'assistant', 'content' => $val['content']];
  45 + }
  46 + }
  47 + $message[] = ['role' => 'user', 'content' => $this->param['message']];
  48 + $data = [
  49 + 'message'=>$message,
  50 + ];
  51 + $result = $gptService->get_ai_chat($data);
37 } 52 }
38 - }else{  
39 - $id = $this->saveChat($this->param['message']);  
40 } 53 }
  54 +// $id = $this->saveChat($this->param['message']);
  55 +// $this->saveChatItem($id,$this->param['message']);
41 56
42 - 57 + $data = [
  58 + 'message'=>[
  59 + ['role' => 'system', 'content' => "You are now the marketing customer service of 深圳创贸集团"],
  60 + ['role' => 'user', 'content' => $this->param['message']]
  61 + ],
  62 + ];
  63 + $result = $gptService->get_ai_chat($data);
  64 + $this->success($result);
43 } 65 }
44 66
45 /** 67 /**
@@ -57,4 +79,22 @@ class ChatLogic extends BaseLogic @@ -57,4 +79,22 @@ class ChatLogic extends BaseLogic
57 ]; 79 ];
58 return $this->model->addReturnId($saveData); 80 return $this->model->addReturnId($saveData);
59 } 81 }
  82 +
  83 + /**
  84 + * @remark :消息详情表保存一条记录
  85 + * @name :saveChatItem
  86 + * @author :lyh
  87 + * @method :post
  88 + * @time :2025/4/2 13:45
  89 + */
  90 + public function saveChatItem($id,$message){
  91 + //创建一个会话
  92 + $saveData = [
  93 + 'user_id'=>$this->user['id'],
  94 + 'is_reply'=>2,
  95 + 'chat_id'=>$id,
  96 + 'content'=>$message,
  97 + ];
  98 + return $this->itemModel->addReturnId($saveData);
  99 + }
60 } 100 }