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

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

@@ -23,7 +23,7 @@ class UserTimeout extends Command
     public function execute(Input $input, Output $output)
     {
         $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'];

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

@@ -41,10 +41,10 @@ class Config extends BaseModel
     }
 
     //字段val如果是json格式,转换为数组
-    public function getValAttribute($value)
-    {
-        return $value ? json_decode($value, true) : '';
-    }
+    // public function getValAttribute($value)
+    // {
+    //     return $value ? json_decode($value, true) : '';
+    // }
 
     //获取指定配置的数据
     public static function getFieldValue($field)

+ 66 - 61
app/common/controller/User.php

@@ -59,59 +59,75 @@ class User
         if (!empty($params['uid'])) {
             $where[] = ['uid', '=', $params['uid']];
         }
-        $userInfo=UserModel::where($where)->withoutField('register_ip,login_count,update_time,create_time')->find();
-        if($userInfo==null){
-            $cs_uid = 0;
-            $autoTask=Config::autoTask();
-            if($autoTask && $autoTask['user_id']){
-                $cs_uid = $autoTask['user_id'];
+        try {
+            Db::startTrans();
+                
+            $userInfo=UserModel::where($where)->withoutField('register_ip,login_count,update_time,create_time')->find();
+            if($userInfo==null){
+                $cs_uid = 0;
+                $autoTask=Config::autoTask();
+                if($autoTask && $autoTask['user_id']){
+                    $cs_uid = $autoTask['user_id'];
+                }
+                $salt = \utils\Str::random(4);
+                $userInfo = UserModel::create([
+                    'account'=>$params['account'],
+                    'realname'=> !empty($params['realname'])  ? $params['realname'] : $params['account'],
+                    'name_py' => !empty($params['realname']) ? pinyin_sentence($params['realname']) : '',
+                    'phone'=>!empty($params['phone']) ? $params['phone'] : '',
+                    'email'=>!empty($params['email']) ? $params['email'] : '',
+                    'from'=>$params['from'],
+                    'uid'=>$params['uid'],
+                    'salt' => $salt,
+                    'avatar' => !empty($params['avatar']) ? $params['avatar'] : '',
+                    'password' => password_hash_tp(123456,$salt),
+                    'cs_uid' => $cs_uid,
+                    'role' => 0,
+                    'status' =>1,
+                    'register_ip' => $this->request->ip(),
+                    'last_login_ip' => $this->request->ip(),
+                    'last_login_time' => time(),
+                    'login_count' => 1
+                ]);
+                // 监听用户注册后的操作
+                event('UserRegister',['user_id' => $userInfo['user_id'], 'realname' => $userInfo['realname']]);
+
+            } else {
+                //$userInfo['avatar']=avatarUrl($userInfo['avatar'],$userInfo['realname'],$userInfo['user_id']);
+                //    如果用户已经有设置
+                $setting=$userInfo['setting'] ?: '';
+                if($setting){
+                    $setting['hideMessageName']= $setting['hideMessageName']=='true' ? true : false;
+                    $setting['hideMessageTime']= $setting['hideMessageTime']=='true' ? true : false;
+                    $setting['avatarCricle']= $setting['avatarCricle']=='true' ? true : false;
+                    $setting['isVoice']= $setting['isVoice']=='true' ? true : false;
+                    $setting['sendKey']=(int)$setting['sendKey'];
+                    $userInfo['setting']=$setting;
+                }
             }
-            $salt = \utils\Str::random(4);
-            $userInfo = UserModel::create([
-                'account'=>$params['account'],
-                'realname'=> !empty($params['realname'])  ? $params['realname'] : $params['account'],
-                'name_py' => !empty($params['realname']) ? pinyin_sentence($params['realname']) : '',
-                'phone'=>!empty($params['phone']) ? $params['phone'] : '',
-                'email'=>!empty($params['email']) ? $params['email'] : '',
-                'from'=>$params['from'],
-                'uid'=>$params['uid'],
-                'salt' => $salt,
+            if($userInfo['status']==0){
+                return warning(lang('user.forbid'));
+            }  
+            
+            $update=[
+                'last_login_time'=>time(),
+                'last_login_ip'=>$this->request->ip(),
+                'login_count'=>Db::raw('login_count+1'),
                 'avatar' => !empty($params['avatar']) ? $params['avatar'] : '',
-                'password' => password_hash_tp(123456,$salt),
-                'cs_uid' => $cs_uid,
-                'role' => 0,
-                'status' =>1,
-                'register_ip' => $this->request->ip(),
-                'last_login_ip' => $this->request->ip(),
-                'last_login_time' => time(),
-                'login_count' => 1
-            ]);
-            // 监听用户注册后的操作
-            event('UserRegister',['user_id' => $userInfo['user_id'], 'realname' => $userInfo['realname']]);
-
-        } else {
-            //$userInfo['avatar']=avatarUrl($userInfo['avatar'],$userInfo['realname'],$userInfo['user_id']);
-            //    如果用户已经有设置
-            $setting=$userInfo['setting'] ?: '';
-            if($setting){
-                $setting['hideMessageName']= $setting['hideMessageName']=='true' ? true : false;
-                $setting['hideMessageTime']= $setting['hideMessageTime']=='true' ? true : false;
-                $setting['avatarCricle']= $setting['avatarCricle']=='true' ? true : false;
-                $setting['isVoice']= $setting['isVoice']=='true' ? true : false;
-                $setting['sendKey']=(int)$setting['sendKey'];
-                $userInfo['setting']=$setting;
+            ];
+            if (!empty($params['realname'])) {
+                $update['realname'] = $params['realname'];
             }
-            // if ($userInfo['service_status'] == 3 && $userInfo['service_status'] != -1) {
-            //     $userInfo['service_status'] = -1;
-            //     $userInfo['service_start'] = 0;
-            //     $autoTask=Config::autoTask();
-            //     $userInfo['cs_uid'] = isset($autoTask['user_id']) ? $autoTask['user_id'] : 0;
-            //     $userInfo->save();
-            // }
+            UserModel::where('user_id',$userInfo['user_id'])->update($update);
+            
+            //记录用户浏览
+            UserView::addData($userInfo['user_id']);
+        
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return error($e->getMessage());
         }
-        if($userInfo['status']==0){
-            return warning(lang('user.forbid'));
-        }  
         
         //如果登录信息中含有client——id则自动进行绑定
         $client_id=$this->request->param('client_id');
@@ -119,24 +135,13 @@ class User
             $cid=$this->request->header('cid','');
             $this->doBindUid($userInfo['user_id'],$client_id,$cid);
         }
-        $update=[
-            'last_login_time'=>time(),
-            'last_login_ip'=>$this->request->ip(),
-            'login_count'=>Db::raw('login_count+1'),
-            'avatar' => !empty($params['avatar']) ? $params['avatar'] : '',
-        ];
-        if (!empty($params['realname'])) {
-            $update['realname'] = $params['realname'];
-        }
-        UserModel::where('user_id',$userInfo['user_id'])->update($update);
+
         $userInfo['qrUrl']=getMainHost().'/scan/u/'.encryptIds($userInfo['user_id']);
         unset($userInfo['password'],$userInfo['salt']);
         $userInfo['displayName']=$userInfo['realname'];
         $userInfo['id']=$userInfo['user_id'];
         $authToken=UserModel::refreshToken($userInfo,$param['terminal'] ?? 'web');
         
-        //记录用户浏览
-        UserView::addData($userInfo['user_id']);
         $data=[
             'sessionId'=>Session::getId(),
             'authToken'=>$authToken,

+ 1 - 1
app/common/listener/UserRegister.php

@@ -86,7 +86,7 @@ class UserRegister
                     $autoTask['group_id']=$groupInfo['group_id'];
                 }
             }
-            Config::update(['val'=>$autoTask],['field'=>'autoTask']);
+            // Config::update(['val'=>$autoTask],['field'=>'autoTask']);
             return true;
         }catch(\Exception $e){
             return shutdown($e->getMessage().$e->getLine());

+ 2 - 11
app/manage/model/Config.php

@@ -9,22 +9,13 @@ use app\BaseModel;
 use think\facade\Cache;
 class Config extends BaseModel
 {
-    protected $json = ['val'];
-    protected $jsonAssoc = true;
+    // protected $json = ['val'];
+    // protected $jsonAssoc = true;
     
     public static function autoTask(){
         $autoTask=Config::getFieldValue('autoTask');
         if($autoTask){
             return $autoTask;
-        }else{
-            $autoTask=[
-                'group_id'=>0, //群聊ID
-                'group_num'=>1, //群聊序号
-                'user_id'=>0,  //上一次的客服ID
-            ];
-            $autoTask=json_encode($autoTask);
-            Config::create(['field'=>'autoTask','val'=>$autoTask]);
-            return $autoTask;
         }
     }
     public static function changeList($list) {