Browse Source

登录,公司做员工的附属

lizhen_gitee 1 year ago
parent
commit
98a6dc0ce2

+ 0 - 63
application/api/controller/company/User.php

@@ -24,69 +24,6 @@ class User extends Apic
 
     }
 
-    /**
-     * 手机验证码登录
-     *
-     * @ApiMethod (POST)
-     * @param string $mobile  手机号
-     * @param string $captcha 验证码
-     */
-    public function mobilelogin()
-    {
-        $mobile = $this->request->post('mobile');
-        $captcha = $this->request->post('captcha');
-
-        if (!$mobile || !$captcha) {
-            $this->error(__('Invalid parameters'));
-        }
-        if (!Validate::regex($mobile, "^1\d{10}$")) {
-            $this->error('请填写正确的手机号');
-        }
-        if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
-            $this->error(__('Captcha is incorrect'));
-        }
-
-        //登录与注册
-        $ret = false;
-        $user = \app\common\model\Company::getByMobile($mobile);
-        if ($user) {
-            /*if ($user->status == 0) {
-                $this->error(__('Account is locked'));
-            }
-            if ($user->status == 2) {
-                $this->error('该用户已注销');
-            }*/
-
-            //如果已经有账号则直接登录
-            $ret = $this->auth->direct($user->id);
-        } else {
-
-            //找员工
-            $userstaff = Db::name('company_staff')->where('mobile',$mobile)->find();
-            if($userstaff)
-            {
-                $user = \app\common\model\Company::get($userstaff['company_id']);
-                if($user)
-                {
-                    $ret = $this->auth->direct($user->id);
-                }
-            }
-
-            if($ret === false){
-                // 用户信息不存在时使用
-                $extend = [];
-                $ret = $this->auth->register_mobile($mobile, Random::alnum(), '', $mobile, $extend);
-            }
-        }
-        if ($ret) {
-            Sms::flush($mobile, 'mobilelogin');
-            $data = ['userinfo' => $this->getUserinfo('return')];
-            $this->success('登录成功', $data);
-        } else {
-            $this->error($this->auth->getError());
-        }
-    }
-
     public function accountlogin(){
         $mobile   = $this->request->post('mobile');
         $password = $this->request->post('password');

+ 34 - 31
application/common/library/Authcompany.php

@@ -3,7 +3,7 @@
 namespace app\common\library;
 
 use app\common\model\CompanyStaff;
-use app\common\model\Company as User;
+use app\common\model\Company;
 use app\common\model\UserRule;
 use fast\Random;
 use think\Config;
@@ -27,7 +27,8 @@ class Authcompany
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'name', 'logo','image','contacts', 'mobile','province_name','city_name','area_name','province_id','city_id','area_id','address','full_address','longitude','latitude','aptitude_images','open_hours','staff'];
+    //protected $allowFields = ['id', 'name', 'logo','image','contacts', 'mobile','province_name','city_name','area_name','province_id','city_id','area_id','address','full_address','longitude','latitude','aptitude_images','open_hours','staff'];
+    protected $allowFields = ['id','company_id','type','truename','mobile','company'];
 
 
     public function __construct($options = [])
@@ -112,15 +113,28 @@ class Authcompany
         }
         $user_id = intval($data['user_id']);
         if ($user_id > 0) {
-            $user = User::get($user_id);
+            $user = CompanyStaff::get($user_id);
             if (!$user) {
                 $this->setError('Account not exist');
                 return false;
             }
-            /*if ($user['status'] != 1) {
+            if ($user->status != 1) {
                 $this->setError('Account is locked');
                 return false;
-            }*/
+            }
+
+            if(!$user->company_id){
+                $this->setError('Account not exist');
+                return false;
+            }
+            $companyinfo = Company::get($user->company_id);
+            if(!$companyinfo){
+                $this->setError('Account not exist');
+                return false;
+            }
+
+            $user->company = $companyinfo;
+
             $this->_user = $user;
             $this->_logined = true;
             $this->_token = $token;
@@ -319,9 +333,8 @@ class Authcompany
             return false;
         }
 
-        //直接登录会员
-        return $this->direct($user->company_id,$user);
-
+        //直接登录员工
+        return $this->direct($user->id);
     }
 
     /**
@@ -386,32 +399,22 @@ class Authcompany
      * @param int $user_id
      * @return boolean
      */
-    public function direct($user_id,$staff)
+    public function direct($staff_id)
     {
-        $user = User::get($user_id);
+        $user = CompanyStaff::get($staff_id);
         if ($user) {
+            if(!$user->company_id){
+                return false;
+            }
+            $companyinfo = Company::get($user->company_id);
+            if(!$companyinfo){
+                return false;
+            }
+
             Db::startTrans();
             try {
-                /*
-                $ip = request()->ip();
-                $time = time();
-
-                //判断连续登录和最大连续登录
-                if ($user->logintime < \fast\Date::unixtime('day')) {
-                    $user->successions = $user->logintime < \fast\Date::unixtime('day', -1) ? 1 : $user->successions + 1;
-                    $user->maxsuccessions = max($user->successions, $user->maxsuccessions);
-                }
-
-                $user->prevtime = $user->logintime;
-                //记录本次登录的IP和时间
-                $user->loginip = $ip;
-                $user->logintime = $time;
-                //重置登录失败次数
-                $user->loginfailure = 0;
-
-                $user->save();*/
 
-				$user->staff = $staff;// 追加员工
+				$user->company = $companyinfo;// 追加公司
 
                 $this->_user = $user;
 
@@ -488,8 +491,8 @@ class Authcompany
         $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
 
         //追加
-        $userinfo['image'] = one_domain_image($userinfo['image']);
-        $userinfo['money'] = model('walletcompany')->getWallet($this->id,'money');
+        $userinfo['company']['image'] = one_domain_image($userinfo['company']['image']);
+        $userinfo['money'] = model('walletcompany')->getWallet($this->company_id,'money');
 
         return $userinfo;
     }