ChatLogic.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @remark :
* @name :ChatLogic.php
* @author :lyh
* @method :post
* @time :2025/4/1 14:37
*/
namespace App\Http\Logic\Bside\Gpt;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Gpt\Chat;
class ChatLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Chat();
}
/**
* @remark :发送消息
* @name :sendMessage
* @author :lyh
* @method :post
* @time :2025/4/2 10:01
*/
public function sendMessage(){
if(isset($this->param['chat_id'])){
$chatInfo = $this->model->read(['id'=>$this->param['chat_id']]);
if($chatInfo === false){
$id = $this->saveChat($this->param['message']);
}else{
$id = $chatInfo['id'];
}
}else{
$id = $this->saveChat($this->param['message']);
}
}
/**
* @remark :创建一条新会话
* @name :saveChat
* @author :lyh
* @method :post
* @time :2025/4/2 10:06
*/
public function saveChat($message){
//创建一个会话
$saveData = [
'user_id'=>$this->user['id'],
'input_content'=>$message,
];
return $this->model->addReturnId($saveData);
}
}