lip 3 mesi fa
parent
commit
f9caa167e8

+ 2 - 5
app/admin/command/UserTimeout.php

@@ -22,11 +22,8 @@ class UserTimeout extends Command
 
     public function execute(Input $input, Output $output)
     {
-        $data = Config::whereIn('field',['kefu_timeout_reminder','kefu_timeout_warning','user_timeouted_warning', 'user_timeout_warning','user_inline_finished'])->field(['field','val'])->select()->toArray();
-        $config = [];
-        foreach($data as $k => $v) {
-            $config[$v['field']] = $v['val'];
-        }
+        $config = Config::whereIn('field',['kefu_timeout_reminder','kefu_timeout_warning','user_timeouted_warning', 'user_timeout_warning','user_inline_finished'])->column('val','field');
+       print_r($config);die;
         $user_timeout_warning = 0;
         if (isset($config['user_timeout_warning']) && $config['user_timeout_warning'] > 0) {
             $user_timeout_warning = $config['user_timeout_warning'];

+ 2 - 1
app/admin/controller/Config.php

@@ -44,12 +44,13 @@ class Config extends BaseController
             }
             $params['language_code'] = $params['language_code'] ?? 'zh';
 
+            $params['val'] = $params['type'] == 'rich_text' ? json_encode($params['val']) : $params['val'];
+            
             if (!empty($id)) {
                 $exist = ConfigModel::where('id', $id)->find();
                 if (!$exist) {
                     return $this->error('配置不存在');
                 }
-                $params['val'] = json_encode($params['val']);
                 ConfigModel::where('id', $id)->update($params);
             } else {
                 ConfigModel::create($params);

+ 4 - 4
app/admin/controller/Kefu.php

@@ -45,12 +45,12 @@ class Kefu extends BaseController
                         ->join('user', 'admin.id = user.uid', 'left')
                         ->where('kefu_work.created_at', '>=', date('Y-m-d 00:00:00'));
 
-            if (isset($params['is_online']) && $params['is_online'] == '') {
+            if (isset($params['is_online']) && $params['is_online'] != '') {
                 $query->where('user.is_online', $params['is_online']);
             }
 
             $count = $query->count();
-            $list = $query->field(['distinct kefu_work.id', 'admin.nickname','user.is_online', 'kefu_work.chat_num','kefu_work.transfer_num','kefu_work.intervention_num','kefu_work.completed_num'])
+            $list = $query->field(['distinct admin.id','admin.id as admin_id', 'admin.nickname','user.is_online', 'kefu_work.chat_num','kefu_work.transfer_num','kefu_work.intervention_num','kefu_work.completed_num'])
                         ->order('admin.id', 'asc')            
                         ->limit($limit)
                         ->page($page)
@@ -345,7 +345,7 @@ class Kefu extends BaseController
                 wsSendMsg(0,'handleChat',['user_id'=>$user_id]);
     
                 //给用户发送客服评分的消息
-                $user_open_comment = Config::where('field', 'user_open_comment')->value('val');
+                $user_open_comment = Config::getFieldValue('user_open_comment');
                 if ($user_open_comment == 1 ) {
                     $param = [
                         'id' => \utils\Str::getUuid(),
@@ -353,7 +353,7 @@ class Kefu extends BaseController
                         'status' => 'going',
                         'sendTime' => time() * 1000,
                         'toContactId' => $user_id,
-                        'content' => Config::where('field','kefu_finished_chat')->value('val'),
+                        'content' => Config::getFieldValue('kefu_finished_chat'),
                         'file_id' => 0,
                         'is_group' => 0,
                         'user_id' => $user->cs_uid,

+ 6 - 0
app/admin/controller/User.php

@@ -14,6 +14,12 @@ class User extends BaseController
      */
     function list()
     {
+        $config = \app\admin\model\Config::getFieldValue('fileUpload');
+        
+        // $chatInfo=\app\admin\model\Config::where(['field'=>'platform_name'])->value('val');
+    //    print_r($chatInfo);die;
+       print_r($config);die;
+
         try {
             $params = $this->request->param();
             $page = $params['page'] ?? 1;

+ 15 - 2
app/admin/model/Config.php

@@ -11,8 +11,8 @@ class Config extends BaseModel
     protected $autoWriteTimestamp = true;
     protected $createTime = 'created_at';
     protected $updateTime = 'updated_at';
-    protected $json = ['val'];
-    protected $jsonAssoc = true;
+    // protected $json = ['val'];
+    // protected $jsonAssoc = true;
     
     public static function getSelect($language_code, $select = true) {
         Lang::setLangSet($language_code);
@@ -46,6 +46,16 @@ class Config extends BaseModel
         return $value ? json_decode($value, true) : '';
     }
 
+    //获取指定配置的数据
+    public static function getFieldValue($field)
+    {
+        $config = self::where('field', $field)->find();
+        if (!empty($config['type']) && $config['type'] == 'rich_text') {
+            return $config['val'] ? json_decode($config['val'], true) : '';
+        }
+        return '';
+    }
+
     //获取配置数据
     public static function getConfigData($fields, $flag = 1) 
     {
@@ -56,6 +66,9 @@ class Config extends BaseModel
         }
         $data = [];
         foreach ($list as $item) {
+            if ($item['type'] == 'rich_text') {
+                $item['val'] = $item['val'] ? json_decode($item['val'], true) : '';
+            }
             $data[$item['field']] = $item['val'];
         }
         return $data;

+ 1 - 1
app/common/controller/Upload.php

@@ -51,7 +51,7 @@ class Upload extends BaseController
             $info['ext']     = $pathInfo['extension'];
             $info['name']    =$message['fileName'] ?? '';
         }
-        $conf=Config::where(['field'=>'fileUpload'])->value('val');
+        $conf=Config::getFieldValue('fileUpload');
         if($conf['size']*1024*1024 < $info['size']){
             return shutdown(lang('file.uploadLimit',['size'=>$conf['size']]));
         }

+ 3 - 4
app/common/listener/UserRegister.php

@@ -11,12 +11,12 @@ class UserRegister
     public function handle(User $user,$data){
         try{
             // 查询相关配置信息
-            $sysInfo=Config::where(['field'=>'sysInfo'])->value('val');
+            $sysInfo=Config::getFieldValue('sysInfo');
             if($sysInfo['runMode']!=2){
                 return true;
             }
             // 获取聊天设置
-            $chatInfo=Config::where(['field'=>'chatInfo'])->value('val');
+            $chatInfo=Config::getFieldValue('chatInfo');
             $autoAdduser=$chatInfo['autoAddUser'] ?? [];
             $autoTask=Config::autoTask();
             // 是否开启自动客服
@@ -39,8 +39,7 @@ class UserRegister
                             $userInfo['dispalayName']=$userInfo['realname'];
                             $userInfo['id']=$userInfo['user_id'];
                             $userInfo['avatar']=avatarUrl($userInfo['avatar'],$userInfo['realname'],$userInfo['user_id']);
-                            $first_auto_reply = Config::where(['field'=>'first_auto_reply'])->value('val');
-                            $first_auto_reply = json_decode($first_auto_reply,true);
+                            $first_auto_reply = Config::getFieldValue('first_auto_reply');
                             $msg=[
                                 'id'=>\utils\Str::getUuid(),
                                 'user_id'=>$autoTask['user_id'],

+ 1 - 1
app/enterprise/controller/Im.php

@@ -248,7 +248,7 @@ class Im extends BaseController
                     'status' => 'going',
                     'sendTime' => time() * 1000,
                     'toContactId' => $user_id,
-                    'content' => Config::where('field','transfer_to_human')->value('val'),
+                    'content' => Config::getFieldValue('transfer_to_human'),
                     'file_id' => 0,
                     'is_group' => 0,
                     'user_id' => !empty($autoTask['user_id']) ? $autoTask['user_id'] : 1,

+ 2 - 2
app/enterprise/model/Message.php

@@ -158,13 +158,13 @@ class Message extends BaseModel
                 if ($question) {
                     $param['type'] = 'list';
                     $content = [
-                        'title' => Config::where('field','reply_keyword')->value('val'),
+                        'title' => Config::getFieldValue('reply_keyword'),
                         'list' => $question,
                     ];
                     $param['content'] = json_encode($content);
                 } else {
                     $param['type'] = 'text';
-                    $param['content'] = Config::where('field','reply_keyword_math_fail')->value('val');
+                    $param['content'] = Config::getFieldValue('reply_keyword_math_fail');
                 }
             }
             

+ 1 - 1
app/index/controller/Index.php

@@ -155,7 +155,7 @@ class Index
         if($downAppUrl){
             return redirect($downAppUrl);
         }
-        $config=Config::where('field','sysInfo')->value('val');
+        $config=Config::getFieldValue('sysInfo');
         $android=getAppDowmUrl('android');
         $winUrl=getAppDowmUrl('windows');
         $macUrl=getAppDowmUrl('mac');

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

@@ -13,7 +13,7 @@ class Config extends BaseModel
     protected $jsonAssoc = true;
     
     public static function autoTask(){
-        $autoTask=Config::where(['field'=>'autoTask'])->value('val');
+        $autoTask=Config::getFieldValue('autoTask');
         if($autoTask){
             return $autoTask;
         }else{
@@ -22,6 +22,7 @@ class Config extends BaseModel
                 'group_num'=>1, //群聊序号
                 'user_id'=>0,  //上一次的客服ID
             ];
+            $autoTask=json_encode($autoTask);
             Config::create(['field'=>'autoTask','val'=>$autoTask]);
             return $autoTask;
         }
@@ -50,6 +51,9 @@ class Config extends BaseModel
             $conf=Config::where([['field','in',$nameFields]])->select()->toArray();
             foreach($conf as $v){
                 $value=[];
+                if ($v['type'] == 'rich_text') {
+                    $v['val'] = json_decode($v['val'], true);
+                }
                 if($v['field']=='fileUpload'){
                     $value['size'] = $v['val']['size'];
                     $value['preview'] = $v['val']['preview'];