Browse Source

增加获取客服信息

Panda 2 months ago
parent
commit
ef77cac771
1 changed files with 16 additions and 2 deletions
  1. 16 2
      application/api/controller/Baseconfig.php

+ 16 - 2
application/api/controller/Baseconfig.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\utils\Service\Tencent\TencentIm;
 use think\Db;
 /**
  * 基础配置接口
@@ -14,9 +15,22 @@ class Baseconfig extends Api
 
    
     public function index(){
-
+        $im   = new TencentIm();
+        $kefu = Db::name('admin')->field(['id', 'nickname', 'avatar', 'is_im'])->where('is_kefu', 1)->where('status', 'normal')->select();
+        foreach ($kefu as $key => $item) {
+            $chat_id               = im_prefix('_kefu_' . $item['id']);
+            $avatar                = !empty($item['avatar']) ? cdnurl($item['avatar']) : '';
+            $kefu[$key]['chat_id'] = $chat_id;
+            $kefu[$key]['avatar']  = $avatar;
+            // 注册IM
+            if ($item['is_im'] == 0) {
+                if ($im->register($chat_id, $item['nickname'], $avatar)) {
+                    Db::name('admin')->where('id', $item['id'])->update(['is_im' => 1]);
+                }
+            }
+        }
         $config = [
-            'kefu_user_ids'            => config('site.kefu_user_ids'),//在线客服人员
+            'kefu_user_ids'    => $kefu,//在线客服人员
             'examine_bg_image' => cdnurl(config('site.examine_bg_image')),
 
         ];