25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

155 satır
5.0 KiB

  1. <?php
  2. namespace backend\modules\motorcade\controllers;
  3. use common\models\searchUser;
  4. use common\models\User;
  5. use Yii;
  6. use yii\web\NotFoundHttpException;
  7. /**
  8. * UserController implements the CRUD actions for BaseUserAuth model.
  9. */
  10. class UserController extends BaseController
  11. {
  12. public $accessControl = true;
  13. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  14. /**
  15. * Lists all User models.
  16. * @return mixed
  17. */
  18. public function actionIndex()
  19. {
  20. $searchModel = new searchUser();
  21. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  22. return $this->render('index', [
  23. 'searchModel' => $searchModel,
  24. 'dataProvider' => $dataProvider,
  25. ]);
  26. }
  27. /**
  28. * Creates a new User model.
  29. * If creation is successful, the browser will be redirected to the 'view' page.
  30. * @return mixed
  31. */
  32. public function actionCreate()
  33. {
  34. $model = new User(['scenario' => 'create']);
  35. $title = '添加用户';
  36. if ($model->load(Yii::$app->request->post())) {
  37. $login_user = Yii::$app->user->identity;
  38. $model->syncPermissionFo();
  39. $model->USER_PASSWORD = md5($model->USER_PASSWORD);
  40. //车队系统添加的账号,运营主体都为车队运营主体
  41. /* @var $login_user User */
  42. $model->MAIN_CORP_ID = $login_user->MAIN_CORP_ID2;
  43. $model->MAIN_CORP_ID2 = $login_user->MAIN_CORP_ID2;
  44. $model->ORG_ID = $login_user->ORG_ID;
  45. if ($model->save()) {
  46. return '<script>z.pjaxFinish("success", "添加成功", "#float-div")</script>';
  47. } else {
  48. return $this->renderPartial('_form', [
  49. 'title' => $title,
  50. 'model' => $model,
  51. 'type' => 'create'
  52. ]);
  53. }
  54. } else {
  55. return $this->renderPartial('_form', [
  56. 'title' => $title,
  57. 'model' => $model,
  58. 'type' => 'create'
  59. ]);
  60. }
  61. }
  62. public function actionView($id)
  63. {
  64. return $this->actionUpdate($id, 'view');
  65. }
  66. /**
  67. * Updates an existing User model.
  68. * If update is successful, the browser will be redirected to the 'view' page.
  69. * @param integer $id
  70. * @param string $type 查看和修改页面相同
  71. * @return mixed
  72. */
  73. public function actionUpdate($id, $type = 'update')
  74. {
  75. $title = $type === 'update' ? '修改用户' : '查看用户';
  76. $model = $this->findModel($id);
  77. $model->setScenario('update');
  78. if ($model->load(Yii::$app->request->post())) {
  79. $model->syncPermissionFo();
  80. //密码不为空,
  81. if (trim($model->USER_PASSWORD) != '')
  82. $model->USER_PASSWORD = md5($model->USER_PASSWORD);
  83. else
  84. $model->USER_PASSWORD = $model->getOldAttribute('USER_PASSWORD');
  85. if ($model->save()) {
  86. return '<script>z.pjaxFinish("success", "修改成功", "#float-div");$("#search-btn").trigger(\'click\');</script>';
  87. } else {
  88. if (!is_array($model->USER_ROLE2)) {
  89. $model->USER_ROLE2 = explode(',', $model->USER_ROLE2);
  90. }
  91. return $this->renderPartial('_form', [
  92. 'title' => $title,
  93. 'model' => $model,
  94. 'type' => $type
  95. ]);
  96. }
  97. } else {
  98. if (!is_array($model->USER_ROLE2)) {
  99. $model->USER_ROLE2 = explode(',', $model->USER_ROLE2);
  100. }
  101. $model->USER_PASSWORD = '';
  102. return $this->render('_form', [
  103. 'title' => $title,
  104. 'model' => $model,
  105. 'type' => $type
  106. ]);
  107. }
  108. }
  109. public function actionDisable($id)
  110. {
  111. $model = $this->findModel($id);
  112. if ($model->STATUS == 1) {
  113. $model->STATUS = 0;
  114. if ($model->save(false))
  115. $result = ['code' => 0, 'msg' => "启用成功!"];
  116. else
  117. $result = ['code' => 1, 'msg' => "启用失败!"];
  118. } else {
  119. $model->STATUS = 1;
  120. if ($model->save(false))
  121. $result = ['code' => 0, 'msg' => "停用成功!"];
  122. else
  123. $result = ['code' => 1, 'msg' => "停用失败!"];
  124. }
  125. return \GuzzleHttp\json_encode($result);
  126. }
  127. /**
  128. * Finds the User model based on its primary key value.
  129. * If the model is not found, a 404 HTTP exception will be thrown.
  130. * @param integer $id
  131. * @return User the loaded model
  132. * @throws NotFoundHttpException if the model cannot be found
  133. */
  134. protected function findModel($id)
  135. {
  136. if (($model = User::findOne($id)) !== null) {
  137. return $model;
  138. } else {
  139. throw new NotFoundHttpException('The requested page does not exist.');
  140. }
  141. }
  142. }