2024-09-19 11:32:39 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace admin\controllers;
|
|
|
|
|
|
|
|
|
|
|
|
use admin\models\Admin;
|
|
|
|
|
|
use admin\models\forms\LoginForm;
|
|
|
|
|
|
use admin\models\RegisterForm;
|
|
|
|
|
|
use common\enums\UserRoleEnum;
|
|
|
|
|
|
use common\helpers\ArrayHelper;
|
|
|
|
|
|
use common\models\AdminAccessToken;
|
|
|
|
|
|
use common\models\Role;
|
|
|
|
|
|
use common\models\Store;
|
|
|
|
|
|
use Yii;
|
|
|
|
|
|
use yii\base\Exception;
|
|
|
|
|
|
use common\core\BaseAdminController;
|
|
|
|
|
|
|
|
|
|
|
|
class LoginController extends BaseAdminController
|
|
|
|
|
|
{
|
|
|
|
|
|
public $modelClass = Admin::class;
|
|
|
|
|
|
public $enableCsrfValidation = false;
|
|
|
|
|
|
public $defaultAction = 'register';
|
|
|
|
|
|
public $optional = ['register', 'logout', 'login'];
|
|
|
|
|
|
|
|
|
|
|
|
public $mallId;
|
|
|
|
|
|
|
|
|
|
|
|
public function actionLogin()
|
|
|
|
|
|
{
|
|
|
|
|
|
$model = new LoginForm();
|
|
|
|
|
|
// $model->attributes=Yii::$app->request->post();
|
|
|
|
|
|
|
|
|
|
|
|
if (Yii::$app->request->isPost) {
|
|
|
|
|
|
/** @var $adminAccessToken AdminAccessToken */
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post(), '') && $adminAccessToken = $model->login()) {
|
|
|
|
|
|
$admin = Admin::find()->where(['uid' => $adminAccessToken->admin_id])->one();
|
|
|
|
|
|
$admin = ArrayHelper::toArray($admin, [
|
|
|
|
|
|
Admin::class => ['uid', 'username', 'role', 'mobile', 'store_id','code','city_id','province_id'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
$title = '萧康管理后台';
|
|
|
|
|
|
switch ($admin['role']) {
|
|
|
|
|
|
case UserRoleEnum::SUPER_ADMIN:
|
|
|
|
|
|
$title = '萧康管理后台';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UserRoleEnum::STORE_ADMIN:
|
|
|
|
|
|
$name = Store::find()->select(['name'])->where(['id' => $admin['store_id']])->one();
|
|
|
|
|
|
$title = $name->name . '管理后台';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UserRoleEnum::PROVINCE_DAI :
|
|
|
|
|
|
case UserRoleEnum::CITY_DAI:
|
|
|
|
|
|
case UserRoleEnum::SUPPLY:
|
|
|
|
|
|
$title = $admin['username'].'的管理后台';
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
$title = $admin['username'].'的管理后台';
|
|
|
|
|
|
}
|
2024-09-23 13:48:02 +08:00
|
|
|
|
$admin['title'] = $title;
|
2024-09-19 11:32:39 +08:00
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
'userInfo' => $admin,
|
|
|
|
|
|
'token' => $adminAccessToken->access_token
|
|
|
|
|
|
];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Exception("登陆失败,帐号或者密码错误");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function actionLogout()
|
|
|
|
|
|
{
|
|
|
|
|
|
Yii::$app->user->logout();
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 后台注册
|
|
|
|
|
|
* @doc-param string mobile 手机号
|
|
|
|
|
|
* @doc-param string password 密码
|
|
|
|
|
|
* @doc-param string username 用户名
|
|
|
|
|
|
* @doc-param int role 角色id
|
|
|
|
|
|
* @doc-param int store_id 门店id / optional
|
|
|
|
|
|
* @doc-param int province_id 省份 / optional
|
|
|
|
|
|
* @doc-param int city_id 城市 / optional
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionRegister()
|
|
|
|
|
|
{
|
|
|
|
|
|
$post = Yii::$app->request->post();
|
|
|
|
|
|
|
|
|
|
|
|
$model = new RegisterForm();
|
|
|
|
|
|
$model->attributes = $post;
|
|
|
|
|
|
return $model->register();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 重置密码或忘记密码
|
|
|
|
|
|
* @doc-param string mobile 手机号
|
|
|
|
|
|
* @doc-param string password 密码
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionResetPassword()
|
|
|
|
|
|
{
|
|
|
|
|
|
$post = Yii::$app->request->post();
|
|
|
|
|
|
$this->requestValidate($post, [
|
|
|
|
|
|
[['mobile', 'password'], 'required']
|
|
|
|
|
|
]);
|
|
|
|
|
|
$LoginForm = new LoginForm();
|
|
|
|
|
|
$LoginForm->attributes = $post;
|
|
|
|
|
|
return $LoginForm->ResetPassword();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 所有角色
|
|
|
|
|
|
* @doc-return mixed @List{id,name-string-名字,role_code-string-role_code,description-string-描述} 医生列表
|
|
|
|
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionAllRole()
|
|
|
|
|
|
{
|
|
|
|
|
|
$post = Yii::$app->request->get();
|
|
|
|
|
|
$query = Role::find();
|
|
|
|
|
|
|
|
|
|
|
|
$this->field = [
|
|
|
|
|
|
Role::class => [
|
|
|
|
|
|
'id', 'name', 'role_code', 'description'
|
|
|
|
|
|
]
|
|
|
|
|
|
];
|
|
|
|
|
|
return $this->create($query, $post);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @doc-name 编辑管理员信息
|
|
|
|
|
|
* @doc-param string bank_user_name 开户人姓名 / optional
|
|
|
|
|
|
* @doc-param string bank_card 银行卡号 / optional
|
|
|
|
|
|
* @doc-param string bank_name 开户行 / optional
|
|
|
|
|
|
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折 / optional
|
|
|
|
|
|
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function actionEditSuperInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
$post = Yii::$app->request->post();
|
|
|
|
|
|
|
|
|
|
|
|
$admin = \Yii::$app->user->identity;
|
|
|
|
|
|
if ($admin->role!=UserRoleEnum::SUPER_ADMIN){
|
|
|
|
|
|
throw new \yii\db\Exception('您不是超管,不能编辑信息');
|
|
|
|
|
|
}
|
|
|
|
|
|
$model = new RegisterForm();
|
|
|
|
|
|
$model->attributes = $post;
|
|
|
|
|
|
return $model->EditSuper();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|