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.
 
 
 
 
 
 

182 lines
5.0 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use backend\modules\zzcs\models\BaseUser;
  4. use Yii;
  5. use common\models\User;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. /**
  11. * UserController implements the CRUD actions for User model.
  12. */
  13. class UserController extends Controller
  14. {
  15. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  16. /**
  17. * @inheritdoc
  18. */
  19. // public function behaviors()
  20. // {
  21. // return [
  22. // 'verbs' => [
  23. // 'class' => VerbFilter::className(),
  24. // 'actions' => [
  25. // 'delete' => ['POST'],
  26. // ],
  27. // ],
  28. // ];
  29. // }
  30. /**
  31. * Lists all User models.
  32. * @return mixed
  33. */
  34. public function actionIndex()
  35. {
  36. $dataProvider = new ActiveDataProvider([
  37. 'query' => User::find(),
  38. ]);
  39. return $this->render('index', [
  40. 'dataProvider' => $dataProvider,
  41. ]);
  42. }
  43. /**
  44. * Displays a single User model.
  45. * @param integer $id
  46. * @return mixed
  47. */
  48. public function actionView($id)
  49. {
  50. return $this->render('view', [
  51. 'model' => $this->findModel($id),
  52. ]);
  53. }
  54. /**
  55. * Creates a new User model.
  56. * If creation is successful, the browser will be redirected to the 'view' page.
  57. * @return mixed
  58. */
  59. public function actionCreate()
  60. {
  61. $model = new User();
  62. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  63. return $this->redirect(['view', 'id' => $model->ID]);
  64. } else {
  65. return $this->render('create', [
  66. 'model' => $model,
  67. ]);
  68. }
  69. }
  70. /**
  71. * Updates an existing User model.
  72. * If update is successful, the browser will be redirected to the 'view' page.
  73. * @param integer $id
  74. * @return mixed
  75. */
  76. public function actionUpdate($id)
  77. {
  78. $model = $this->findModel($id);
  79. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  80. return $this->redirect(['view', 'id' => $model->ID]);
  81. } else {
  82. return $this->render('update', [
  83. 'model' => $model,
  84. ]);
  85. }
  86. }
  87. /**
  88. * Deletes an existing User model.
  89. * If deletion is successful, the browser will be redirected to the 'index' page.
  90. * @param integer $id
  91. * @return mixed
  92. */
  93. public function actionDelete($id)
  94. {
  95. $this->findModel($id)->delete();
  96. return $this->redirect(['index']);
  97. }
  98. /**
  99. * Finds the User model based on its primary key value.
  100. * If the model is not found, a 404 HTTP exception will be thrown.
  101. * @param integer $id
  102. * @return User the loaded model
  103. * @throws NotFoundHttpException if the model cannot be found
  104. */
  105. protected function findModel($id)
  106. {
  107. if (($model = User::findOne($id)) !== null) {
  108. return $model;
  109. } else {
  110. throw new NotFoundHttpException('The requested page does not exist.');
  111. }
  112. }
  113. public function actionModifyPassword()
  114. {
  115. $user_id = Yii::$app->user->id;
  116. $model = $this->findModel($user_id);
  117. $model->setScenario('password');
  118. // $model = new User();
  119. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  120. $model->USER_PASSWORD = md5($model->USER_PASSWORD);
  121. $model->save(false);
  122. Yii::$app->session->setFlash('success', '修改成功');
  123. return $this->redirect('modify-password');
  124. }
  125. $model->USER_PASSWORD = '';
  126. $model->USER_PASSWORD1 = '';
  127. $model->USER_PASSWORD2 = '';
  128. return $this->render('_modifyPW', ['model'=>$model]);
  129. }
  130. public function actionTest(){
  131. $data = BaseUser::find()->all();
  132. foreach ($data as $datum) {
  133. $notes = preg_split('/[\,\|]/', $datum->MENU_PERMISSION);
  134. $arr148 = [134,135,136];
  135. $arr139 = [140,141];
  136. $arr149 = [124,125,126,128];
  137. $arr150 = [142,143,144,129,130,131,132,133];
  138. $arr154 = [137,138];
  139. foreach ($notes as $note) {
  140. if(in_array($note, $arr148) && !in_array(148, $notes)){
  141. $notes[] = 148;
  142. }
  143. if(in_array($note, $arr139) && !in_array(139, $notes)){
  144. $notes[] = 139;
  145. }
  146. if(in_array($note, $arr149) && !in_array(149, $notes)){
  147. $notes[] = 149;
  148. }
  149. if(in_array($note, $arr150) && !in_array(150, $notes)){
  150. $notes[] = 150;
  151. }
  152. if(in_array($note, $arr154) && !in_array(154, $notes)){
  153. $notes[] = 154;
  154. }
  155. }
  156. $str = implode($notes, ',');
  157. if(trim($str) != ''){
  158. $datum->MENU_PERMISSION = $str;
  159. $datum->save();
  160. }
  161. }
  162. echo date('Y-m-d H:i:s');
  163. }
  164. }