lip 3 miesięcy temu
rodzic
commit
55f5d371eb

+ 3 - 0
app/admin/controller/Config.php

@@ -7,6 +7,7 @@ use app\admin\model\Config as ConfigModel;
 use app\admin\validate\ConfigValidate;
 use Exception;
 use think\facade\Db;
+use think\facade\Cache;
 
 class Config extends BaseController
 {
@@ -58,6 +59,8 @@ class Config extends BaseController
             Db::rollBack();
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('systemInfo');
         return $this->success();
 
     }

+ 8 - 0
app/admin/controller/GuessAsk.php

@@ -7,6 +7,7 @@ use app\admin\model\GuessAsk as GuessAskModel;
 use app\admin\model\GuessAskLanguages;
 use app\admin\validate\GuessAskValidate;
 use Exception;
+use think\facade\Cache;
 
 /**
  * 猜你想问管理
@@ -97,6 +98,9 @@ class GuessAsk extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        
+        //删除缓存
+        Cache::delete('guessaskList');
         return $this->success([], '操作成功');
     }
 
@@ -117,6 +121,8 @@ class GuessAsk extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('guessaskList');
         return $this->success([],'删除成功');
     }
     
@@ -141,6 +147,8 @@ class GuessAsk extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('guessaskList');
         return $this->success([], '操作成功');
     }
 

+ 7 - 0
app/admin/controller/Keyword.php

@@ -8,6 +8,7 @@ use app\admin\model\KeywordLanguages;
 use app\admin\model\QuestionLanguages;
 use app\admin\validate\KeywordValidate;
 use Exception;
+use think\facade\Cache;
 
 /**
  * 关键词管理
@@ -86,6 +87,8 @@ class Keyword extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('keywordList');
         return $this->success([], '操作成功');
     }
 
@@ -103,6 +106,8 @@ class Keyword extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('keywordList');
         return $this->success([], '操作成功');
     }
 
@@ -123,6 +128,8 @@ class Keyword extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('keywordList');
         return $this->success([],'删除成功');
     }
 

+ 11 - 0
app/admin/controller/Question.php

@@ -7,6 +7,7 @@ use app\admin\model\Question as QuestionModel;
 use app\admin\model\QuestionLanguages;
 use app\admin\validate\QuestionValidate;
 use Exception;
+use think\facade\Cache;
 
 /**
  * 问题管理
@@ -97,6 +98,8 @@ class Question extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('questionList');
         return $this->success([],'保存成功');
     }
 
@@ -114,6 +117,8 @@ class Question extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('questionList');
         return $this->success([], '操作成功');
     }
 
@@ -130,6 +135,8 @@ class Question extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('questionList');
         return $this->success([], '操作成功');
     }
 
@@ -146,6 +153,8 @@ class Question extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('questionList');
         return $this->success([], '操作成功');
     }
 
@@ -163,6 +172,8 @@ class Question extends BaseController
         } catch (Exception $e) {
             return $this->error($e->getMessage());
         }
+        //删除缓存
+        Cache::delete('questionList');
         return $this->success([], '删除成功');
     }
 

+ 13 - 10
app/admin/model/KeywordLanguages.php

@@ -3,6 +3,7 @@
 namespace app\admin\model;
 
 use app\BaseModel;
+use think\facade\Db;
 
 
 class KeywordLanguages  extends BaseModel
@@ -20,31 +21,33 @@ class KeywordLanguages  extends BaseModel
 
     //根据聊天内容匹配关键词
     public static function getKeywordByContent($content){
+        $content = strip_tags($content);
         //缓存关键词列表
         $keywordList = cache('keywordList');
-        if (!$keywordList) {
-            $keywordList = self::where('status', 1)->field(['id','language_code', 'name'])->order('weight','desc')->select();
+        //if (!$keywordList) {
+            $keywordList = self::where('status', 1)->field(['id','language_code', 'name'])->order('weight','desc')->select()->toArray();
             cache('keywordList', $keywordList);
-        }
+        //}
+        //$keyword_ids = KeywordLanguages::getKeywordByContent($param['content']);
         $list = [];
         $all_match = [];//完全匹配的关键词
         $match = []; //模糊匹配的关键词
         foreach ($keywordList as $keyword) {
             //判断content是否包含关键词
-            if (strpos($content, $keyword->name) !== false) {
-                if ($keyword->name == $content) {
-                    $all_match[] = $keyword->id;
+            if (strpos($content, $keyword['name']) !== false) {
+                if ($keyword['name'] == $content) {
+                    $all_match[] = $keyword['id'];
                 } else {
-                    $match[] = $keyword->id;
+                    $match[] = $keyword['id'];
                 }
-                $list[] = $keyword->id;
+                $list[] = $keyword['id'];
             }
         }
         if ($all_match) {
-            return self::whereIn('id', $all_match)->increment('all_match_num', 1);
+            Db::name('keyword_languages')->whereIn('id', $all_match)->inc('all_match_num', 1)->update();
         }
         if ($match) {
-            return self::whereIn('id', $match)->increment('match_num', 1);
+            Db::name('keyword_languages')->whereIn('id', $match)->inc('match_num', 1)->update();
         }
         return $list;
     }

+ 4 - 3
app/admin/model/QuestionLanguages.php

@@ -12,12 +12,13 @@ class QuestionLanguages extends BaseModel
     
     public static function getQuestion($keyword_ids, $content)
     {
+        $content = strip_tags($content);
         //缓存问题列表
         $questionList = cache('questionList');
-        if (!$questionList) {
-            $questionList = self::where('status', 1)->field(['id','category_id','question','answer','keyword_id','language_code', 'name'])->order('weight','desc')->select();
+        //if (!$questionList) {
+            $questionList = self::where('status', 1)->field(['id','category_id','question','answer','keyword_id','language_code'])->order('weight','desc')->select()->toArray();
             cache('questionList', $questionList);
-        }
+        //}
         $list = [];
         foreach ($questionList as $item) {
             //判断content是否包含关键词

+ 7 - 0
app/enterprise/controller/Im.php

@@ -10,6 +10,7 @@ use GatewayClient\Gateway;
 use Exception;
 use League\Flysystem\Util;
 use think\facade\Cache;
+use app\manage\model\{Config};
 
 class Im extends BaseController
 {
@@ -552,6 +553,12 @@ class Im extends BaseController
             // 如果时间超过了2分钟也不能撤回
             $createTime=is_string($message['create_time']) ? strtotime($message['create_time']) : $message['create_time'];
             $redoTime=$this->globalConfig['chatInfo']['redoTime'] ?? 120;
+            if ($this->userInfo['role'] == 0 && $this->globalConfig['user_cancel_message'] && $this->globalConfig['user_cancel_message']) {
+                $redoTime=$this->globalConfig['user_cancel_message_time'] * 60;
+            } elseif ($this->userInfo['role'] != 0 &&  $this->globalConfig['kefu_cancel_message']) {
+                $redoTime=$this->globalConfig['kefu_cancel_message'] * 60;
+            }
+            
             if(time()-$createTime>$redoTime && $message['is_group']==0){
                 return warning(lang('im.redoLimitTime',['time'=>floor($redoTime/60)]));
             }

+ 14 - 0
app/enterprise/listener/AutoReplyMessage.php

@@ -0,0 +1,14 @@
+<?php
+namespace app\enterprise\listener;
+
+use app\enterprise\model\{Message};
+
+// 机器人客服自动回复消息
+class AutoReplyMessage
+{
+    public function handle($param, $globalConfig){
+        $message=new Message();
+        $data = $message->sendMessage($param,$globalConfig);
+        return true;
+    }
+}

+ 25 - 14
app/enterprise/model/Message.php

@@ -137,40 +137,50 @@ class Message extends BaseModel
                 }
             }
         }
-        
         if ($sendInterval) {
             Cache::set('send_' . $uid, time(), $sendInterval);
         }
-        $data = self::sendMsg($param,$is_group);
+        $data = self::sendMsg($param,$is_group, 0, $uid);
 
         // 机器人自动回复问题推送给用户
         if ($is_robot && $param['type'] == 'text') {
             //获取关键词匹配
             $keyword_ids = KeywordLanguages::getKeywordByContent($param['content']);
             $question = QuestionLanguages::getQuestion($keyword_ids, $param['content']);
+            $data['question'] = $question;
             if ($question) {
                 $param['type'] = 'list';
-                $param['content'] = $question;
+                $content = [
+                    'title' => Config::where('field','reply_keyword')->value('val'),
+                    'list' => $question,
+                ];
+                $param['content'] = json_encode($content);
             } else {
                 $param['type'] = 'text';
                 $param['content'] = Config::where('field','reply_keyword_math_fail')->value('val');
             }
-
-            $param['toContactId'] = $uid;
+            
+            $fromUserId = $param['toContactId'];
+            $param['toContactId'] = $param['fromUser']['id'];
+            $param['user_id'] = $fromUserId;
             $param['fromUser'] = [
-                'id' => $data['contactInfo']['id'],
-                'displayName' => $data['contactInfo']['displayName'],
-                'avatar' => $data['contactInfo']['avatar'],
-                'account' => '',
+                'id' => $fromUserId,
+                'displayName' => '88888',
+                'avatar' => '',
+                'account' => 'admin',
             ];
-            self::sendMsg($param,$is_group);
+            $param['content'] = Config::where('field','reply_keyword_math_fail')->value('val');
+            //$data2 = self::sendMsg($param,$is_group, 0, $param['user_id']);
+            
+            //机器人自动回复消息
+            event('AutoReplyMessage', [$param, $globalConfig]);
         }
         return $data;
     }
 
     //实际发送消息
-    public static function sendMsg($param,$is_group=0,$is_sys=0){
-        $uid=self::$uid ?: ($param['user_id'] ?? 1);
+    public static function sendMsg($param,$is_group=0,$is_sys=0, $uid=0){
+        $uid = $uid ?: ($param['user_id'] ?? 1);
         $toContactId=$param['toContactId'];
         $manage=[];
         // 重新建立会话,更新会话删除记录
@@ -208,7 +218,7 @@ class Message extends BaseModel
             'from_user'=>$param['user_id'],
             'to_user'=>$toContactId,
             'id'=>$param['id'],
-            'content'=>str_encipher($param['content'],true),
+            'content'=>$param['type'] != 'list' ? str_encipher($param['content'],true) : $param['content'],
             'chat_identify'=>$chat_identify,
             'create_time'=>time(),
             'type'=>$param['type'],
@@ -242,7 +252,7 @@ class Message extends BaseModel
             // 将团队所有成员的未读状态+1
             GroupUser::editGroupUser([['group_id','=',$toContactId],['user_id','<>',$uid]],['unread'=>Db::raw('unread+1')]);
         }else{
-            $sendData['toContactId']=$uid;
+            $sendData['toContactId']=$toContactId;//$uid;
         }
         $sendData['fromUser']['id']=(int)$sendData['fromUser']['id'];
         $sendData['fileSize']=$fileSzie;
@@ -265,6 +275,7 @@ class Message extends BaseModel
         if($is_group==0){
             $toContactId=[$toContactId,$param['user_id']];
         }
+        
         $sendData['toUser']=$param['toContactId'];
         $user=new User();
         // 将聊天窗口的联系人信息带上,方便临时会话

+ 1 - 0
app/event.php

@@ -13,6 +13,7 @@ return [
         'UserRegister'=>['app\common\listener\UserRegister'],
         'GroupChange'=>['app\enterprise\listener\GroupChange'],
         'GreenText'=>['app\common\listener\GreenText'],
+        'AutoReplyMessage'=>['app\enterprise\listener\AutoReplyMessage'],
     ],
 
     'subscribe' => [

+ 1 - 1
app/manage/model/Config.php

@@ -37,7 +37,7 @@ class Config extends BaseModel
     public static function getSystemInfo($update=false){
         $name='systemInfo';
         // $auth=request()->header('Authorization');
-        $nameFields=['sysInfo','fileUpload','chatInfo','compass'];
+        $nameFields=['sysInfo','fileUpload','chatInfo','compass','kefu_cancel_message','user_open_comment', 'user_open_special_comment', 'user_send_gap_time', 'user_open_speech', 'user_show_kefu_read','user_cancel_message','user_cancel_message_time','platform_head_logo','platform_head_logo_night','pc_title_color','platform_logo','platform_name','platform_logo_night'];
         // 如果是登录状态才会返回chatINfo
         // if($auth){
         //     $name='all'.$name;