|
@@ -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']]];
|
|
|
}
|
|
|
}
|