getOpenid($code); if(!$status) return [false,$openid]; $user = WxEmployee::where('openid',$openid)->first(); if(empty($user)) { $user = new WxEmployee(); $user->mobile = ''; $user->openid = $openid; $user->appid = $service->appid; $user->save(); $state = 0; }else{ $state = 1; if(empty($user->mobile)) $state = 0; } return [true,['openid'=>$openid, 'state'=> $state]]; } public function setMobile($data){ if(empty($data['code'])) return [false, '用户登录凭证(code)不能为空']; if(empty($data['openid'])) return [false, 'openID不能为空']; $code = $data['code']; $openid = $data['openid']; $service = new WxService(); list($status,$mobile) = $service->getMobile($code); if(!$status) return [false,$mobile]; $user = WxEmployee::where('openid',$openid)->first(); if(empty($user)) return [false,'openID在系统中暂无记录']; $user->mobile = $mobile; $user->save(); return [true, ['mobile' => $mobile]]; } public function login($data){ if(empty($data['account'])) return [false, '账号不能为空']; if(empty($data['password'])) return [false, '密码不能为空']; if(empty($data['openid'])) return [false, 'openID不能为空']; $account = $data['account']; $password = $data['password']; $openid = $data['openid']; list($status,$data) = $this->loginRule([ 'account' => $account, 'password' => $password, ]); if(!$status) return [false,$data]; $user_id = $data['id']; $user = WxEmployee::where('openid',$openid)->first(); if(empty($user)||empty($user->mobile)) return [false,'请先登陆']; $user->employee_id = $user_id; $user->save(); return [true,$data]; } public function loginRule($data){ if($this->isEmpty($data,'account')) return [false,'账号不能为空!']; if($this->isEmpty($data,'password')) return [false,'密码不存在!']; $account = $data['account']; $res = Employee::where('del_time',0) ->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(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!']; if($res['state'] == Employee::NOT_USE) return [false,'账号停用!']; return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]]; } public function checkWxUser($userId){ $res = Employee::where('id', $userId) // ->where('del_time',0) ->where('state',Employee::USE)->get()->first(); if(empty($res)) return [false, '该账号无法登录,请联系管理员!']; return [true, $res]; } public function getTopMessage($data,$user){ $return = EmployeeService::getLoginMessage($user['id']); return [true,$return]; } }