93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年9月15日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\controllers\auth;
|
|
|
|
use yii\helpers\VarDumper;
|
|
use app\modules\admin\controllers\Controller;
|
|
use app\modules\admin\behaviors\LoginBehavior;
|
|
use app\models\common\auth\CommonRoleActionForm;
|
|
use app\models\common\auth\CommonRoleEditForm;
|
|
use app\models\common\auth\CommonRoleListForm;
|
|
use app\models\auth\Role;
|
|
use app\modules\admin\models\AdminMenu;
|
|
|
|
|
|
class RoleController extends Controller
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), [
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function actionIndex()
|
|
{
|
|
if(\Yii::$app->request->isAjax){
|
|
$form = new CommonRoleListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
//本人创建的角色
|
|
$form->creator_user_id = \Yii::$app->admin->identity->user_id;
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('index');
|
|
}
|
|
|
|
public function actionEdit($id = 0)
|
|
{
|
|
$model = Role::findOne([
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0,
|
|
'id' => $id,
|
|
]);
|
|
if($model == null)
|
|
$model = new Role();
|
|
$m = new AdminMenu();
|
|
if(\Yii::$app->request->isPost){
|
|
$form = new CommonRoleEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->creator_user_id = \Yii::$app->admin->identity->user_id;
|
|
$form->model = $model;
|
|
$form->allows = $m->getMenuUrls($m->getList(false));
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$permissions = $model->isNewRecord || !$model->permission ? [] : json_decode($model->permission->permissions,true);
|
|
$permission_tree = $m->getPermissionTree($permissions);
|
|
$return_url = \Yii::$app->request->referrer;
|
|
return $this->render('edit', [
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
'permission_tree' => $permission_tree
|
|
]);
|
|
}
|
|
|
|
public function actionDelete()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CommonRoleActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
}
|
|
|