Browse Source

商家员工登录

lizhen_gitee 1 year ago
parent
commit
cf1cf6b4c1

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

@@ -87,6 +87,20 @@ class User extends Apic
         }
     }
 
+    public function accountlogin(){
+        $mobile   = $this->request->post('mobile');
+        $password = $this->request->post('password');
+        if (!$mobile || !$password) {
+            $this->error(__('Invalid parameters'));
+        }
+        $ret = $this->auth->login($mobile, $password);
+        if ($ret) {
+            $data = ['userinfo' => $this->auth->getUserinfo()];
+            $this->success(__('Logged in successful'), $data);
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 
 
     /**

+ 4 - 9
application/common/controller/Apic.php

@@ -368,28 +368,23 @@ class Apic
         $controllername = $this->request->controller();
         $actionname     = $this->request->action();
 
-        if($controllername == 'Notify'){
-            return true;
-        }
-
         $data = [
             'uid'   => $this->auth->id,
             'api'   => $modulename.'/'.$controllername.'/'.$actionname,
-            'params_get' => json_encode($this->request->input()),
-            'params_post' => json_encode($this->request->post()),
-            'params_request' => json_encode($this->request->request()),
-//            'addtime'  => time(),
+            'params' => json_encode($this->request->request()),
+            'addtime'  => time(),
             'adddatetime'  => date('Y-m-d H:i:s'),
             'ip'   => request()->ip(),
         ];
         $request_id = db('api_request_log')->insertGetId($data);
         defined('API_REQUEST_ID') or define('API_REQUEST_ID', $request_id);
+
     }
 
     protected function request_log_update($log_result){
         if(defined('API_REQUEST_ID')) { //记录app正常返回结果
             if(strlen(json_encode($log_result['data'])) > 10000) {
-                // $log_result['data'] = '数据太多,不记录';
+                $log_result['data'] = '数据太多,不记录';
             }
             db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($log_result)]);
         }

+ 10 - 6
application/common/library/Authcompany.php

@@ -2,6 +2,7 @@
 
 namespace app\common\library;
 
+use app\common\model\CompanyStaff;
 use app\common\model\Company as User;
 use app\common\model\UserRule;
 use fast\Random;
@@ -300,10 +301,10 @@ class Authcompany
      * @param string $password 密码
      * @return boolean
      */
-    /*public function login($account, $password)
+    public function login($account, $password)
     {
-        $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
-        $user = User::get([$field => $account]);
+        $field = 'mobile';
+        $user = CompanyStaff::get([$field => $account]);
         if (!$user) {
             $this->setError('Account is incorrect');
             return false;
@@ -319,8 +320,9 @@ class Authcompany
         }
 
         //直接登录会员
-        return $this->direct($user->id);
-    }*/
+        return $this->direct($user->company_id,$user);
+
+    }
 
     /**
      * 退出
@@ -384,7 +386,7 @@ class Authcompany
      * @param int $user_id
      * @return boolean
      */
-    public function direct($user_id)
+    public function direct($user_id,$staff)
     {
         $user = User::get($user_id);
         if ($user) {
@@ -409,6 +411,8 @@ class Authcompany
 
                 $user->save();*/
 
+				$user->staff = $staff;// 追加员工
+
                 $this->_user = $user;
 
                 $this->_token = Random::uuid();

+ 16 - 0
application/common/model/CompanyStaff.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 商家员工
+ */
+class CompanyStaff extends Model
+{
+    // 表名
+    protected $name = 'company_staff';
+
+}