108 lines
2.8 KiB
PHP
108 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-4
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models;
|
|
|
|
use app\models\Admin;
|
|
use app\models\User;
|
|
|
|
class LoginForm extends AdminModel
|
|
{
|
|
public $username;
|
|
public $password;
|
|
public $captcha_code;
|
|
public $remember;
|
|
|
|
public $cx_mch_id;
|
|
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['username', 'password', 'captcha_code', 'remember'], 'trim'],
|
|
[['username', 'password', 'captcha_code', 'cx_mch_id'], 'required'],
|
|
[['captcha_code',],'captcha', 'captchaAction' => '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' => '登录成功'
|
|
];
|
|
}
|
|
|
|
} |