'用户名', 'password' => '密码', ]; } public function login($user=null) { $this->cx_mch_id = 0; if(!$this->validate()){ return $this->getModelError(); } if(empty($user)){ $mobile_phone = EncryptHelper::encryptMobilePhone($this->username); $mobile_phone = $mobile_phone ? $mobile_phone : $this->username; $user = User::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'status' => User::STATUS_NORMAL ]) ->andWhere([ 'OR', ['username' => $this->username], ['mobile_phone' => $mobile_phone], ]) ->one(); if($user == null){ return [ 'code' => 1, 'msg' => '用户名或者密码错误1' ]; } } /*if(!$user->validatePassword($this->password)){ $err_msg = "密码错误"; User::lastLogin($user->id, 0, $err_msg, $this->cx_mch_id); return [ 'code' => 1, 'msg' => '用户名或者密码错误' ]; } */ if(\Yii::$app->user->login($user,\Yii::$app->params['loginAuthExpireTime'])){ $args = []; $args['cx_mch_id'] = $this->cx_mch_id; $args['token_type'] = $this->token_type; $atoken = new AToken($args); $data = $atoken->generate_access_token(); if($data['code'] == 0){ $err_msg = "登录成功"; User::lastLogin($user->id, 1, $err_msg, $this->cx_mch_id); //是否需要绑定 $data = User::bindQuery($user, $data); } } else { $data = [ 'code' => 1, 'msg' => '登录失败' ]; } return $data; } }