|
|
@@ -4260,12 +4260,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
unset($data['session_id']);
|
|
|
// 会话状态:1-开启,0-关闭
|
|
|
- if(isset($data['is_active']) && $aichat_session['is_active'] == $data['is_active']){
|
|
|
- return Result::success('会话状态已为'.$data['is_active'].'!');
|
|
|
- }
|
|
|
- if(isset($data['is_active']) && ($data['is_active'] == 0 || $data['is_active'] == '0')){
|
|
|
- $data['end_time'] = date('Y-m-d H:i:s');
|
|
|
- }
|
|
|
+ // if(isset($data['is_active']) && $aichat_session['is_active'] == $data['is_active']){
|
|
|
+ // return Result::success('会话状态已为'.$data['is_active'].'!');
|
|
|
+ // }
|
|
|
+ // if(isset($data['is_active']) && ($data['is_active'] == 0 || $data['is_active'] == '0')){
|
|
|
+ // $data['end_time'] = date('Y-m-d H:i:s');
|
|
|
+ // }
|
|
|
$result = AichatSession::where($where)->update($data);
|
|
|
if(empty($result)){
|
|
|
return Result::error('修改会话失败!');
|
|
|
@@ -4319,17 +4319,30 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
$where['user_id'] = $data['user_id'];
|
|
|
$where['session_id'] = $data['session_id'];
|
|
|
- $where['is_active'] = 1;
|
|
|
+ // $where['is_active'] = 1;
|
|
|
$aichat_session = AichatSession::where($where)->first();
|
|
|
if(empty($aichat_session)){
|
|
|
return Result::error('会话不存在!');
|
|
|
}
|
|
|
- $data['message_type'] = empty($data['message_type']) ? 'text' : $data['message_type'];
|
|
|
- $result = Aichat::insertGetId($data);
|
|
|
- if(empty($result)){
|
|
|
- return Result::error('发送消息失败!');
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ $data['message_type'] = empty($data['message_type']) ? 'text' : $data['message_type'];
|
|
|
+ $result['aichat'] = Aichat::insertGetId($data);
|
|
|
+ if(empty($result)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('发送消息失败!');
|
|
|
+ }
|
|
|
+ $result['aichat_session'] = AichatSession::where($where)->update(['end_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ if(empty($result['aichat_session'])){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('更新会话截止时间失败!');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 自助建站-ai会话-获取消息列表
|
|
|
@@ -4338,7 +4351,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
// $where['user_id'] = $data['user_id'];
|
|
|
$where['session_id'] = $data['session_id'];
|
|
|
- $where['is_active'] = 1;
|
|
|
+ // $where['is_active'] = 1;
|
|
|
$session = AichatSession::where($where)->first();
|
|
|
if(empty($session)){
|
|
|
return Result::error('会话不存在!');
|