lip 3 months ago
parent
commit
64a8ef05be

+ 17 - 0
app/admin/controller/Kefu.php

@@ -114,6 +114,23 @@ class Kefu extends BaseController
         } catch (\Exception $e) {
             return $this->error($e->getMessage());
         }
+        return $this->success([], '签到成功');
+    }
+
+    //客服状态设置
+    public function setStatus()
+    {
+        try {
+            $admin_id = $this->admin_id;
+            KefuWork::addNum($admin_id, 'sign_num');//客服签到次数更新
+            //签到记录
+            Sign::create([          
+                'admin_id' => $admin_id,
+            ]);
+        } catch (\Exception $e) {
+            return $this->error($e->getMessage());
+        }
+        return $this->success([], '签到成功');
     }
 
 }

+ 3 - 0
app/admin/model/ExpressionCategoryLanguages.php

@@ -7,6 +7,9 @@ use app\BaseModel;
 
 class ExpressionCategoryLanguages  extends BaseModel
 {
+    protected $autoWriteTimestamp = true;
+    protected $createTime = 'created_at';
+    protected $updateTime = 'updated_at';
     
     // 语言表对应分类
     public function category()

+ 3 - 0
app/admin/model/Keyword.php

@@ -6,6 +6,9 @@ use app\BaseModel;
 
 class Keyword extends BaseModel
 {
+    protected $autoWriteTimestamp = true;
+    protected $createTime = 'created_at';
+    protected $updateTime = 'updated_at';
     public function languages()
     {
         return $this->hasMany(KeywordLanguages::class, 'keyword_id')

+ 211 - 0
app/common/controller/User.php

@@ -0,0 +1,211 @@
+<?php
+
+namespace app\common\controller;
+
+use think\App;
+use app\enterprise\model\User as UserModel;
+use app\enterprise\model\Group;
+use app\admin\model\GuessAskLanguages;
+use app\admin\model\QuestionLanguages;
+use think\facade\Session;
+use think\facade\Db;
+use GatewayClient\Gateway;
+use Exception;
+
+/**
+ * 控制器基础类
+ */
+class User
+{
+    /**
+     * Request实例
+     * @var \think\Request
+     */
+    protected $request;
+
+    /**
+     * 应用实例
+     * @var \think\App
+     */
+    protected $app;
+
+    protected $lang;
+
+    /**
+     * 构造方法
+     * @access public
+     * @param  App  $app  应用对象
+     */
+    public function __construct(App $app)
+    {
+        Gateway::$registerAddress = config('gateway.registerAddress');
+        $this->app     = $app;
+        $this->request = $this->app->request;
+        $this->lang = request()->header('Lang', 'en');
+    }
+
+    public function login(){
+        $params=request()->param();
+        $where['role'] = 0;
+        $where['cs_uid'] = 0;
+        if (empty($params['account']) || empty($params['uid']) || empty($params['from'])) {
+            return json(['code' => 400, 'msg' => '参数错误']);
+        }
+        if (!empty($params['account'])) {
+            $where[] = ['account', '=', $params['account']];
+        } 
+        if (!empty($params['phone'])) {
+            $where[] = ['phone', '=', $params['phone']];
+        }
+        if (!empty($params['email'])) {
+            $where[] = ['email', '=', $params['email']];
+        }
+        if (!empty($params['from'])) {
+            $where[] = ['from', '=', $params['from']];
+        }
+        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){
+            $salt = \utils\Str::random(4);
+            $userInfo = UserModel::create([
+                'account'=>$params['account'],
+                'realname'=>$params['realname'],
+                'name_py' => pinyin_sentence($params['realname']),
+                'phone'=>$params['phone'],
+                'email'=>$params['email'],
+                'from'=>$params['from'],
+                'uid'=>$params['uid'],
+                'salt' => $salt,
+                'password' => password_hash_tp(123456,$salt),
+                'cs_uid' => 0,
+                'role' => 0,
+                'status' =>1,
+                'register_ip' => $this->request->ip(),
+                'last_login_ip' => $this->request->ip(),
+                'last_login_time' => time(),
+                'login_count' => 1
+            ]);
+        }
+        if($userInfo['status']==0){
+            return warning(lang('user.forbid'));
+        }  
+        
+        $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;
+        }
+        //如果登录信息中含有client——id则自动进行绑定
+        $client_id=$this->request->param('client_id');
+        if($client_id){
+            $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')
+        ];
+        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');
+        $data=[
+            'sessionId'=>Session::getId(),
+            'authToken'=>$authToken,
+            'userInfo'=>$userInfo
+        ];
+        return success(lang('user.loginOk'),$data);
+   }
+
+   // 执行绑定
+    public function doBindUid($user_id,$client_id,$cid=''){
+        // 如果当前ID在线,将其他地方登陆挤兑下线
+        if(Gateway::isUidOnline($user_id)){
+            wsSendMsg($user_id,'offline',['id'=>$user_id,'client_id'=>$client_id,'isMobile'=>$this->request->isMobile()]);
+        }
+        Gateway::bindUid($client_id, $user_id);
+        // 查询团队,如果有团队则加入团队
+        $group=Group::getMyGroup(['gu.user_id'=>$user_id,'gu.status'=>1]);
+        if($group){
+            $group=$group->toArray();
+            $group_ids=arrayToString($group,'group_id',false);
+            foreach($group_ids as $v){
+                Gateway::joinGroup($client_id, $v); 
+            }
+        }
+        if($cid){
+            bindCid($user_id,$cid);
+        }
+        wsSendMsg(0,'isOnline',['id'=>$user_id,'is_online'=>1]);
+    }
+
+    /**
+     * 猜你想问列表
+     */
+    function guessask()
+    {
+        try {
+            $params = $this->request->param();
+            $page = $params['page'] ?? 1;
+            $limit = $params['limit'] ?? 15;
+            $language_code = $this->lang;
+            $query = GuessAskLanguages::where('language_code', $language_code)->where('status', 1); 
+            if (!empty($params['name'])) {
+                $query = $query->where('name', 'like', '%'.$params['name'].'%');
+            }
+            if (isset($params['type']) && $params['type'] != '') {
+                $query = $query->where('type', $params['type']);
+            }
+            $count = $query->count();
+            $list = $query->order('is_top','desc')
+                        ->order('is_rec','desc')
+                        ->order('click_num','desc')
+                        ->limit($limit)
+                        ->page($page)
+                        ->select();
+            
+        } catch (Exception $e) {
+            return error($e->getMessage());
+        }
+        return success('', [ 'count' => $count, 'list' => $list]);
+    }
+
+    /**
+     * 问题列表
+     */
+    function question()
+    {
+        try {
+            $params = $this->request->param();
+            $page = $params['page'] ?? 1;
+            $limit = $params['limit'] ?? 15;
+            $language_code = $this->lang;
+            $query = QuestionLanguages::where('language_code', $language_code)->where('status', 1); 
+            
+            if (isset($params['question_type']) && $params['question_type'] != '') {
+                $query = $query->where('question_type', $params['question_type']);
+            }
+            $count = $query->count();
+            $list = $query->order('weight','desc')
+                        ->limit($limit)
+                        ->page($page)
+                        ->select();
+            
+        } catch (Exception $e) {
+            return error($e->getMessage());
+        }
+        return success('', [ 'count' => $count, 'list' => $list]);
+    }
+
+}

+ 1 - 0
app/lang/zh.php

@@ -95,4 +95,5 @@ return [
     '一级' => '一级',
     '二级' => '二级',
     '三级' => '三级',
+    '签到成功' => '签到成功',
 ];