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.

185 lines
5.0 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use common\models\ars\Area;
  4. use common\models\ars\City;
  5. use Yii;
  6. use common\models\ars\TakingSite;
  7. use common\models\searchs\TakingSiteSearch;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11. /**
  12. * TakingSiteController implements the CRUD actions for TakingSite model.
  13. */
  14. class TakingSiteController extends Controller
  15. {
  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 TakingSite models.
  32. * @return mixed
  33. */
  34. public function actionIndex()
  35. {
  36. $searchModel = new TakingSiteSearch();
  37. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  38. return $this->render('index', [
  39. 'searchModel' => $searchModel,
  40. 'dataProvider' => $dataProvider,
  41. 'columns' => $searchModel->columns()
  42. ]);
  43. }
  44. /**
  45. * Displays a single TakingSite model.
  46. * @param integer $id
  47. * @return mixed
  48. * @throws NotFoundHttpException if the model cannot be found
  49. */
  50. public function actionView($id)
  51. {
  52. return $this->render('view', [
  53. 'model' => $this->findModel($id),
  54. ]);
  55. }
  56. /**
  57. * Creates a new TakingSite model.
  58. * If creation is successful, the browser will be redirected to the 'view' page.
  59. * @return mixed
  60. */
  61. public function actionCreate()
  62. {
  63. $model = new TakingSite();
  64. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  65. return $this->redirect('index');
  66. }
  67. return $this->render('create', [
  68. 'model' => $model,
  69. ]);
  70. }
  71. /**
  72. * Updates an existing TakingSite model.
  73. * If update is successful, the browser will be redirected to the 'view' page.
  74. * @param integer $id
  75. * @return mixed
  76. * @throws NotFoundHttpException if the model cannot be found
  77. */
  78. public function actionUpdate($id)
  79. {
  80. $model = $this->findModel($id);
  81. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  82. return $this->redirect('index');
  83. }
  84. return $this->render('update', [
  85. 'model' => $model,
  86. ]);
  87. }
  88. /**
  89. * Deletes an existing TakingSite model.
  90. * If deletion is successful, the browser will be redirected to the 'index' page.
  91. * @param integer $id
  92. * @return mixed
  93. * @throws NotFoundHttpException if the model cannot be found
  94. */
  95. public function actionDelete($id)
  96. {
  97. $this->findModel($id)->delete();
  98. return $this->redirect(['index']);
  99. }
  100. /**
  101. * Finds the TakingSite model based on its primary key value.
  102. * If the model is not found, a 404 HTTP exception will be thrown.
  103. * @param integer $id
  104. * @return TakingSite the loaded model
  105. * @throws NotFoundHttpException if the model cannot be found
  106. */
  107. protected function findModel($id)
  108. {
  109. if (($model = TakingSite::findOne($id)) !== null) {
  110. return $model;
  111. }
  112. throw new NotFoundHttpException('The requested page does not exist.');
  113. }
  114. /**
  115. * @author iron
  116. * 文件导出
  117. */
  118. public function actionExport()
  119. {
  120. $searchModel = new TakingSiteSearch();
  121. $params = Yii::$app->request->queryParams;
  122. if ($params['page-type'] == 'all') {
  123. $dataProvider = $searchModel->allData($params);
  124. } else {
  125. $dataProvider = $searchModel->search($params);
  126. }
  127. \iron\widget\Excel::export([
  128. 'models' => $dataProvider->getModels(),
  129. 'format' => 'Xlsx',
  130. 'asAttachment' => true,
  131. 'fileName' =>'Taking Sites'. "-" .date('Y-m-d H/i/s', time()),
  132. 'columns' => $searchModel->columns()
  133. ]);
  134. }
  135. /**
  136. * @return array
  137. * 根据省获取市数据
  138. */
  139. public function actionCity()
  140. {
  141. Yii::$app->response->format = 'json';
  142. $parents = Yii::$app->request->post('depdrop_parents');
  143. if ($parents != null) {
  144. $provinceId = $parents[0];
  145. $data = City::find()->select('city_id as id,name')->where(['province_id' => $provinceId])->asArray()->all();
  146. return ['output' => $data, 'selected' => ''];
  147. } else {
  148. return ['output' => '', 'selected' => ''];
  149. }
  150. }
  151. /**
  152. * @return array
  153. * 根据市数据获取区域数据
  154. */
  155. public function actionArea()
  156. {
  157. Yii::$app->response->format = 'json';
  158. $parents = Yii::$app->request->post('depdrop_parents');
  159. if ($parents != null) {
  160. $cityId = $parents[0];
  161. $data = Area::find()->select('area_id as id,name')->where(['city_id' => $cityId])->asArray()->all();
  162. return ['output' => $data, 'selected' => ''];
  163. } else {
  164. return ['output' => '', 'selected' => ''];
  165. }
  166. }
  167. }