lip пре 3 месеци
родитељ
комит
ec74ac0f9f

+ 5 - 6
app/admin/command/UserQueue.php

@@ -32,11 +32,6 @@ class UserQueue extends Command
         ];
 
         while(true) {
-            //查询当前最少接线数的客服
-            $kefu_chat_max = Config::getKefuChatMax();//单个客服接线上限
-            if ($kefu_chat_max) {
-                $where[] = ['chat_num', '<', $kefu_chat_max];
-            }
 
             //排队用户
             $list = User::where('status', 1)->where('is_online', 1)->where('service_status', 0)
@@ -44,9 +39,13 @@ class UserQueue extends Command
                         ->select()
                         ->toArray();
             if (empty($list)) {
-                sleep(10);
+                sleep(5);
             }
             foreach ($list as $item) {
+                //查询当前最少接线数的客服
+                // $kefu_chat_max = Config::getKefuChatMax();//单个客服接线上限
+                $kefu_chat_max = (int)Config::where('field','kefu_chat_max')->value('val');
+                $where[] = ['chat_num', '<', $kefu_chat_max];
                 $cs_user = User::where($where)->order('chat_num', 'asc')->find();
                 if (!$cs_user) {
                     break;

+ 1 - 1
app/admin/command/UserTimeout.php

@@ -51,7 +51,7 @@ class UserTimeout extends Command
                     ->where('service_start', '<=', time() - $user_timeouted_warning)
                     ->where(function($query) use ($user_timeout_warning){
                         if ($user_timeout_warning > 0) {
-                            $query->where('service_start', '>', time() - $user_timeout_warning);
+                            $query->where('service_start', '<=', time() - $user_timeout_warning);
                         }
                     })
                     ->where('timeout_type', '<',2)

+ 4 - 2
app/admin/controller/Admin.php

@@ -310,8 +310,10 @@ class Admin extends BaseController
             //结束客服服务时间
             KefuTime::endData($this->admin_id, 4);
 
-            //客服离线后自动结束所有客服会话
-            User::KefuOffline($userInfo['user_id'], $this->admin_id);
+            // //客服离线后自动结束所有客服会话
+            // User::KefuOffline($userInfo['user_id'], $this->admin_id);
+
+            wsSendMsg(0,'isOnline',['id'=>$userInfo['user_id'],'is_online'=>0]);
         }
         JWTAuth::invalidate(JWTAuth::token()->get());
         return success(lang('退出成功'));

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

@@ -83,8 +83,9 @@ class Config extends BaseModel
             return $kefu_chat_max;
         }
         
-        $config = Config::whereIn('field',['kefu_chat_max'])->column('val', 'field');
-        cache('config_kefu_chat_max', $config['kefu_chat_max'] ?? 0);
-        return $config['kefu_chat_max'] ?? 0;
+        $kefu_chat_max = (int)Config::where('field','kefu_chat_max')->value('val');
+        $kefu_chat_max = $kefu_chat_max ? $kefu_chat_max : 1;
+        cache('config_kefu_chat_max', $kefu_chat_max);
+        return $kefu_chat_max;
     }
 }

+ 6 - 4
app/enterprise/controller/Im.php

@@ -239,14 +239,16 @@ class Im extends BaseController
                 return $this->error('系统管理员无法转人工');
             }
             if($user->service_status == -1) {
+                
+                //机器人客服
+                $autoTask = Config::autoTask();
+                $auto_cs_uid = !empty($autoTask['user_id']) ? $autoTask['user_id'] : 1;
                 $user->service_status = 0;
                 $user->service_start = time();
                 $user->timeout_type = 0;
-                $user->cs_uid = 0;
+                $user->cs_uid = $auto_cs_uid;
                 $user->save();
 
-                //机器人客服
-                $autoTask = Config::autoTask();
                 $param = [
                     'id' => \utils\Str::getUuid(),
                     'type' => 'text',
@@ -256,7 +258,7 @@ class Im extends BaseController
                     'content' => Config::getFieldValue('transfer_to_human'),
                     'file_id' => 0,
                     'is_group' => 0,
-                    'user_id' => !empty($autoTask['user_id']) ? $autoTask['user_id'] : 1,
+                    'user_id' => $auto_cs_uid,
                 ];
                 Message::sendMsg($param, 0);