瀏覽代碼

Merge remote-tracking branch 'origin/master'

gogs 1 年之前
父節點
當前提交
f13e6ac1fd
共有 3 個文件被更改,包括 41 次插入24 次删除
  1. 2 2
      app/Service/EmployeeService.php
  2. 6 11
      app/Service/OaService.php
  3. 33 11
      app/Service/Weixin/WxEmployeeService.php

+ 2 - 2
app/Service/EmployeeService.php

@@ -85,8 +85,8 @@ class EmployeeService extends Service
             $model->entry_time = $data['entry_time'] ?? '';
             $model->state = empty($data['leave_time']) ? Employee::USE : Employee::NOT_USE;
             $model->is_admin = $data['is_admin'];
+            $model->account = $data['number'];
             if($model->is_admin == 1){
-                $model->account = $data['number'];
                 if($data['password'] !== '******'){
                     $model->password   = Hash::make($data['password']);
                 }
@@ -152,8 +152,8 @@ class EmployeeService extends Service
             $model->state = empty($data['leave_time']) ? Employee::USE : Employee::NOT_USE;
             $model->crt_id = $user['id'];
             $model->is_admin = $data['is_admin'];
+            $model->account = $data['number'];
             if($model->is_admin == 1){
-                $model->account = $data['number'];
                 if($data['password'] !== '********'){
                     $model->password = Hash::make($data['password']);
                 }

+ 6 - 11
app/Service/OaService.php

@@ -718,17 +718,12 @@ class OaService extends Service
 
         $api = SysMenu::where('id', $menu_id)->value('api');
         $param =  SysMenu::where('id', $menu_id)->value('api_params');
-        if(!empty($param)){
-            $param =  json_decode($param,true);
-            $param['state'] = null;
-            $param['menu_id'] = $menu_id;
-            $param['id'] = null;
-            $request->userData = $user;
-            $request->merge($param);
-//            foreach ($param as $k=>$v){
-//                $request->set($k,$v);
-//            }
-        }
+        $param =  json_decode($param,true);
+        $param['state'] = null;
+        $param['menu_id'] = $menu_id;
+        $param['id'] = null;
+        $request->merge($param);
+
         $path = $this->getMenu();
         $control = '\\' . $path[$api]["controller"];
         $act = $path[$api]["act"];

+ 33 - 11
app/Service/Weixin/WxEmployeeService.php

@@ -29,30 +29,37 @@ class WxEmployeeService extends Service
     }
 
     public function login($data,$openid){
+        if(empty($data['account'])) return [false, '账号不能为空'];
+        if(empty($data['password'])) return [false, '密码不能为空'];
+        if(empty($openid) || $openid == null) return [false, 'ciphertext不能为空'];
+
         $account = $data['account'];
         $password = $data['password'];
-
-        file_put_contents('111.txt',json_encode([$account,$password,$openid]));
-
         list($status,$data) = $this->loginRule([
             'account' => $account,
             'password' => $password,
         ]);
-        if(!$status) return [false,$data];
-//        var_dump($data);
+        if(! $status) return [false, $data];
+
         $user_id = $data['id'];
         $user = WxEmployeeOfficial::where('openid',$openid)->first();
-//        var_dump($user);die;
-        if(!empty($user)) {
+
+        if(empty($user)) {
             $bool = WxEmployeeOfficial::where('employee_id',$user_id)->exists();
             if($bool) return [false,'该账号已经与其他微信用户绑定!'];
 
-//            $user = new WxEmployeeOfficial();
+            $user = new WxEmployeeOfficial();
             $user->openid = $openid;
             $user->appid = WeixinService::APPID;
             $user->employee_id = $user_id;
             $user->save();
         }else{
+            if(empty($user->employee_id)){
+                $bool = WxEmployeeOfficial::where('employee_id',$user_id)->exists();
+                if($bool) return [false,'该账号已经与其他微信用户绑定!'];
+                $user->employee_id = $user_id;
+                $user->save();
+            }
             if(! empty($user->employee_id) && $user->employee_id != $user_id) return [false,'该账号已经与其他微信用户绑定!'];
         }
 
@@ -63,15 +70,30 @@ class WxEmployeeService extends Service
         if($this->isEmpty($data,'account')) return [false,'账号不能为空!'];
         if($this->isEmpty($data,'password')) return [false,'密码不存在!'];
 
+        $account = $data['account'];
         $res = Employee::where('del_time',0)
-            ->where('number', $data['account'])
+            ->where(function ($query)use($account) {
+                $query->where('account', $account)
+                    ->orWhere('mobile', $account);
+            })
             ->get()->toArray();
+
         if(empty($res)) return [false,'账号不存在或已被删除!'];
+        if(count($res) > 1) return [false,'手机号绑定多个账户!'];
 
         $res = reset($res);
         if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
-        if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
+        if(empty($res['password'])){
+            if(empty($res['mobile'])) return [false, '用户手机号码信息不能为空'];
+            $lastFour = substr($res['mobile'], -4);
+            if($lastFour != $data['password']) return [false,'密码错误!'];
+
+            Employee::where('id', $res['id'])
+                ->update(['password' => Hash::make($data['password'])]);
+        }else{
+            if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
+        }
 
-        return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['number']]];
+        return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]];
     }
 }