|
|
@@ -49,7 +49,10 @@ use App\Model\TemplateRule;
|
|
|
use App\Model\SectorType;
|
|
|
use App\Model\Level;
|
|
|
use App\Model\StyleCode;
|
|
|
-
|
|
|
+use think\controller\Rest;
|
|
|
+use App\Model\Aichat;
|
|
|
+use App\Model\AichatSession;
|
|
|
+use App\Model\TemplateDraftbox;
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
|
@@ -1192,10 +1195,13 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (empty($template)) {
|
|
|
return Result::error('皮肤不存在!');
|
|
|
}
|
|
|
- $sector_id = Sector::where('sector_id', $data['sector_id'])->where('template_id', $data['template_id'])->first();
|
|
|
- if (!empty($sector_id)) {
|
|
|
+ $sector_query = Sector::where('template_id', $data['template_id']);
|
|
|
+ if (!empty($sector_query->where('sector_id', $data['sector_id'])->first())) {
|
|
|
return Result::error('通栏编号已存在!');
|
|
|
}
|
|
|
+ if(!empty($sector_query->where('sector_type', $data['place_type'])->where('component_code',$data['component_code'])->first())){
|
|
|
+ return Result::error('通栏位置已存在!');
|
|
|
+ }
|
|
|
$sector_place = SectorPlace::where('sector_type', $data['place_type'])->get();
|
|
|
if (empty($sector_place)) {
|
|
|
return Result::error('位置不存在!');
|
|
|
@@ -4160,8 +4166,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
|
|
|
$com_key = 0;
|
|
|
// }
|
|
|
- // // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
|
|
|
- // // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
|
|
|
+ // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
|
|
|
+ // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
|
|
|
// 19:选项卡-推荐图类;20:选项卡-最新资讯类;21:选项卡-推荐资讯类;22:选项卡-热点资讯类;23:选项卡-栏目资讯类;24:选项卡-栏目广告混合类;
|
|
|
if (is_scalar($sectorId) && is_scalar($sort_id)) {
|
|
|
if (!in_array($component_type, [10, 12, 16])) {
|
|
|
@@ -4210,4 +4216,232 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$groupedResults = array_values($groupedResults);
|
|
|
return Result::success($groupedResults);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-获取会话列表
|
|
|
+ */
|
|
|
+ public function getAiSessionList(array $data): array
|
|
|
+ {
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
+ $where['website_id'] = $data['website_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['template_id']) && !empty($data['template_id'])){
|
|
|
+ $where['template_id'] = $data['template_id'];
|
|
|
+ }
|
|
|
+ $result = AichatSession::where($where)->get()->all();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('会话不存在!');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-创建会话
|
|
|
+ */
|
|
|
+ public function addAiSession(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error('网站不存在!');
|
|
|
+ }
|
|
|
+ $template = Template::where('template_id',$data['template_id'])->first();
|
|
|
+ if(empty($template)){
|
|
|
+ return Result::error('皮肤不存在!');
|
|
|
+ }
|
|
|
+ $date = date('Hisms');
|
|
|
+ // $date = 1631191019
|
|
|
+ $rand_num = rand(1000,9999);
|
|
|
+ $data['session_id'] = $date.$rand_num;
|
|
|
+ // $data['session_id'] = 16320610069512
|
|
|
+ $ai_sessions = AichatSession::where('user_id',$data['user_id'])->pluck('session_id')->all();
|
|
|
+ if(!empty($data['session_id']) && in_array($data['session_id'],$ai_sessions)){
|
|
|
+ $rand_num = rand(1000,9999);
|
|
|
+ $data['session_id'] = $date.$rand_num;
|
|
|
+ }
|
|
|
+ $result = AichatSession::insert($data);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('创建会话失败!');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-修改会话
|
|
|
+ */
|
|
|
+ public function upAiSession(array $data): array
|
|
|
+ {
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ // return Result::success($where);
|
|
|
+ $aichat_session = AichatSession::where($where)->first();
|
|
|
+ if(empty($aichat_session)){
|
|
|
+ return Result::error('会话不存在!');
|
|
|
+ }
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+ $result = AichatSession::where($where)->update($data);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('修改会话失败!');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-删除会话
|
|
|
+ */
|
|
|
+ public function delAiSession(array $data): array
|
|
|
+ {
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ // 删除会话
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ $result['ai_chat_session'] = AichatSession::where($where)->delete();
|
|
|
+ if(empty($result['ai_chat_session'])){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('删除会话消息失败!');
|
|
|
+ }
|
|
|
+ // 删除会话消息
|
|
|
+ $aichat = Aichat::where($where)->get()->all();
|
|
|
+ if(!empty($aichat)){
|
|
|
+ $result['ai_chat_message'] = Aichat::where($where)->delete();
|
|
|
+ if(empty($result['ai_chat_message'])){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('删除会话消息失败!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除草稿模板
|
|
|
+ $template_draftbox = TemplateDraftbox::where($where)->get()->all();
|
|
|
+ if(!empty($template_draftbox)){
|
|
|
+ $result['template_draftbox'] = TemplateDraftbox::where($where)->delete();
|
|
|
+ if(empty($result['template_draftbox'])){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('删除草稿模板失败!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-发送消息
|
|
|
+ */
|
|
|
+ public function sendAiMessage(array $data): array
|
|
|
+ {
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-获取消息列表
|
|
|
+ */
|
|
|
+ public function getAiMessageList(array $data): array
|
|
|
+ {
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ $where['is_active'] = 1;
|
|
|
+ $session = AichatSession::where($where)->first();
|
|
|
+ if(empty($session)){
|
|
|
+ return Result::error('会话不存在!');
|
|
|
+ }
|
|
|
+ $aichat = Aichat::where($where)->orderBy('send_time','asc')->get()->all();
|
|
|
+ if(empty($aichat)){
|
|
|
+ return Result::error('消息不存在!');
|
|
|
+ }
|
|
|
+ return Result::success($aichat);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-添加模板草稿
|
|
|
+ */
|
|
|
+ public function addTemplateDraftbox(array $data): array
|
|
|
+ {
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ // 后续若是用来对应会话记录,则此项需要修改
|
|
|
+ $session = AichatSession::where($where)->first();
|
|
|
+ if(empty($session)){
|
|
|
+ return Result::error('会话不存在!');
|
|
|
+ }
|
|
|
+ $data['website_id'] = $session['website_id'];
|
|
|
+ $data['template_id'] = $session['template_id'];
|
|
|
+ $template_draftbox = TemplateDraftbox::where($where)->first();
|
|
|
+ if(!empty($template_draftbox)){
|
|
|
+ return Result::error('草稿模板已存在!');
|
|
|
+ }
|
|
|
+ $result = TemplateDraftbox::insert($data);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('添加草稿模板失败!');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-修改模板草稿
|
|
|
+ */
|
|
|
+ public function upTemplateDraftbox(array $data): array
|
|
|
+ {
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ $session = AichatSession::where($where)->first();
|
|
|
+ if(empty($session)){
|
|
|
+ return Result::error('会话不存在!');
|
|
|
+ }
|
|
|
+ if(isset($data['chat_id']) && !empty($data['chat_id'])){
|
|
|
+ $chat = Aichat::where($where)->where('chat_id',$data['chat_id'])->first();
|
|
|
+ if(empty($chat)){
|
|
|
+ return Result::error('消息不存在!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 后续若是用来对应会话记录,则此项需要修改
|
|
|
+ $template_draftbox = TemplateDraftbox::where($where)->first();
|
|
|
+ if(empty($template_draftbox)){
|
|
|
+ return Result::error('草稿模板不存在!');
|
|
|
+ }
|
|
|
+ unset($data['session_id']);
|
|
|
+ $result = TemplateDraftbox::where($where)->update($data);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('修改草稿模板失败!');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 自助建站-ai会话-获取模板草稿列表
|
|
|
+ */
|
|
|
+ public function getTemplateDraftboxList(array $data): array
|
|
|
+ {
|
|
|
+ $where['session_id'] = $data['session_id'];
|
|
|
+ $where['user_id'] = $data['user_id'];
|
|
|
+ if(isset($data['website_id']) && !empty($data['website_id'])){
|
|
|
+ $where['website_id'] = $data['website_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['template_id']) && !empty($data['template_id'])){
|
|
|
+ $where['template_id'] = $data['template_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['status'])){
|
|
|
+ $where['status'] = $data['status'];
|
|
|
+ }
|
|
|
+ if(isset($data['chat_id']) && !empty($data['chat_id'])){
|
|
|
+ $where['chat_id'] = $data['chat_id'];
|
|
|
+ }
|
|
|
+ $template_draftbox = TemplateDraftbox::where($where)->get()->all();
|
|
|
+ if(empty($template_draftbox)){
|
|
|
+ return Result::error('草稿模板不存在!');
|
|
|
+ }
|
|
|
+ return Result::success($template_draftbox);
|
|
|
+ }
|
|
|
}
|