'admin/passport/captcha',], [['remember'],'default', 'value' => 'off'], [['cx_mch_id'], 'integer'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'username' => '用户名', 'password' => '密码', 'captcha_code' => '图片验证码', 'remember' => '记住我的登录信息', ]; } public function login() { if(!$this->validate()){ return $this->getModelError(); } $user = User::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'username' => $this->username, 'is_delete' => 0, 'status' => User::STATUS_NORMAL, 'type' => [User::TYPE_ADMIN,User::TYPE_STAFF,User::TYPE_ADMIN_STAFF] ]); if($user == null){ return [ 'code' => 1, 'msg' => '用户名或者密码错误' ]; } if(!$user->validatePassword($this->password)){ $err_msg = "密码错误"; Admin::lastLogin($user->id, 0, $err_msg, $this->cx_mch_id); return [ 'code' => 1, 'msg' => '用户名或者密码错误' ]; } $admin = Admin::findOne([ 'cx_mch_id' => $this->cx_mch_id, "user_id" => $user->id, "is_delete" => 0 ]); if($admin == null){ $err_msg = "没有权限"; Admin::lastLogin($user->id, 0, $err_msg, $this->cx_mch_id); return [ 'code' => 1, 'msg' => '用户名或者密码错误' ]; } $err_msg = "登录成功"; Admin::lastLogin($user->id, 1, $err_msg, $this->cx_mch_id); if($this->remember == "on"){ \Yii::$app->admin->login($admin,\Yii::$app->params['loginAuthExpireTime']); } else { \Yii::$app->admin->login($admin); } return [ 'code' => 0, 'msg' => '登录成功' ]; } }