You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

151 lines
4.4 KiB

  1. <?php
  2. namespace backend\modules\motorcade\controllers;
  3. use common\models\BaseRole;
  4. use common\models\User;
  5. use Yii;
  6. use common\models\BaseUserAuth;
  7. use yii\data\ActiveDataProvider;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. /**
  12. * AuthController implements the CRUD actions for BaseUserAuth model.
  13. */
  14. class AuthController extends Controller
  15. {
  16. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  17. /**
  18. * @inheritdoc
  19. */
  20. public function behaviors()
  21. {
  22. return [
  23. 'verbs' => [
  24. 'class' => VerbFilter::className(),
  25. 'actions' => [
  26. 'delete' => ['POST'],
  27. ],
  28. ],
  29. ];
  30. }
  31. /**
  32. * Lists all BaseUserAuth models.
  33. * @return mixed
  34. */
  35. public function actionIndex()
  36. {
  37. $dataProvider = new ActiveDataProvider([
  38. 'query' => BaseUserAuth::zFind(BaseUserAuth::SYS_FO)->joinWith('mainCorp'),
  39. ]);
  40. return $this->render('index', [
  41. 'dataProvider' => $dataProvider,
  42. ]);
  43. }
  44. /**
  45. * Displays a single BaseUserAuth model.
  46. * @param integer $id
  47. * @return mixed
  48. */
  49. public function actionView($id)
  50. {
  51. return $this->render('view', [
  52. 'model' => $this->findModel($id),
  53. ]);
  54. }
  55. /**
  56. * Creates a new BaseUserAuth model.
  57. * If creation is successful, the browser will be redirected to the 'view' page.
  58. * @return mixed
  59. */
  60. public function actionCreate()
  61. {
  62. $model = new BaseUserAuth();
  63. $roles = BaseRole::find()->where(['and', ['CANCEL_FLAG'=> 0], [ '>=', 'id', '123'], ])->asArray()->all();
  64. if ($model->load(Yii::$app->request->post())) {
  65. /* @var $list array */
  66. $list = $model->role_list;
  67. $model->role_list = implode(',', $list);
  68. $model->sys = $model::SYS_FO;
  69. if($model->save()){
  70. User::updateAll(['MENU_PERMISSION'=> $model->role_list], ['USER_ROLE2'=> $model->id]);
  71. }
  72. return $this->redirect(['view', 'id' => $model->id]);
  73. } else {
  74. $model->role_list = explode(',', $model->role_list);
  75. return $this->render('create', [
  76. 'model' => $model,
  77. 'roles' => $roles,
  78. ]);
  79. }
  80. }
  81. /**
  82. * Updates an existing BaseUserAuth model.
  83. * If update is successful, the browser will be redirected to the 'view' page.
  84. * @param integer $id
  85. * @return mixed
  86. */
  87. public function actionUpdate($id)
  88. {
  89. $model = $this->findModel($id);
  90. $roles = BaseRole::find()->where(['and', ['CANCEL_FLAG'=> 0], [ '>=', 'id', '123'], ])->asArray()->all();
  91. // if(Yii::$app->request->isPost){
  92. // /* @var $model->role_list array */
  93. // $model->role_list = implode(',', $model->role_list);
  94. // }
  95. if ($model->load(Yii::$app->request->post())) {
  96. /* @var $list array */
  97. $list = $model->role_list;
  98. $model->role_list = implode(',', $list);
  99. $model->sys = $model::SYS_FO;
  100. if($model->save()){
  101. User::updateAll(['MENU_PERMISSION'=> $model->role_list], ['USER_ROLE2'=> $model->id]);
  102. }
  103. return $this->redirect(['view', 'id' => $model->id]);
  104. } else {
  105. $model->role_list = explode(',', $model->role_list);
  106. return $this->render('update', [
  107. 'model' => $model,
  108. 'roles' => $roles,
  109. ]);
  110. }
  111. }
  112. /**
  113. * Deletes an existing BaseUserAuth model.
  114. * If deletion is successful, the browser will be redirected to the 'index' page.
  115. * @param integer $id
  116. * @return mixed
  117. */
  118. public function actionDelete($id)
  119. {
  120. $this->findModel($id)->delete();
  121. return $this->redirect(['index']);
  122. }
  123. /**
  124. * Finds the BaseUserAuth model based on its primary key value.
  125. * If the model is not found, a 404 HTTP exception will be thrown.
  126. * @param integer $id
  127. * @return BaseUserAuth the loaded model
  128. * @throws NotFoundHttpException if the model cannot be found
  129. */
  130. protected function findModel($id)
  131. {
  132. if (($model = BaseUserAuth::findOne($id)) !== null) {
  133. return $model;
  134. } else {
  135. throw new NotFoundHttpException('The requested page does not exist.');
  136. }
  137. }
  138. }