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.

186 lines
5.1 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. $model->is_default = TakingSite::IS_DEFAULT_NO;
  65. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  66. return $this->redirect('index');
  67. }
  68. return $this->render('create', [
  69. 'model' => $model,
  70. ]);
  71. }
  72. /**
  73. * Updates an existing TakingSite model.
  74. * If update is successful, the browser will be redirected to the 'view' page.
  75. * @param integer $id
  76. * @return mixed
  77. * @throws NotFoundHttpException if the model cannot be found
  78. */
  79. public function actionUpdate($id)
  80. {
  81. $model = $this->findModel($id);
  82. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  83. return $this->redirect('index');
  84. }
  85. return $this->render('update', [
  86. 'model' => $model,
  87. ]);
  88. }
  89. /**
  90. * Deletes an existing TakingSite model.
  91. * If deletion is successful, the browser will be redirected to the 'index' page.
  92. * @param integer $id
  93. * @return mixed
  94. * @throws NotFoundHttpException if the model cannot be found
  95. */
  96. public function actionDelete($id)
  97. {
  98. $this->findModel($id)->delete();
  99. return $this->redirect(['index']);
  100. }
  101. /**
  102. * Finds the TakingSite model based on its primary key value.
  103. * If the model is not found, a 404 HTTP exception will be thrown.
  104. * @param integer $id
  105. * @return TakingSite the loaded model
  106. * @throws NotFoundHttpException if the model cannot be found
  107. */
  108. protected function findModel($id)
  109. {
  110. if (($model = TakingSite::findOne($id)) !== null) {
  111. return $model;
  112. }
  113. throw new NotFoundHttpException('The requested page does not exist.');
  114. }
  115. /**
  116. * @author iron
  117. * 文件导出
  118. */
  119. public function actionExport()
  120. {
  121. $searchModel = new TakingSiteSearch();
  122. $params = Yii::$app->request->queryParams;
  123. if ($params['page-type'] == 'all') {
  124. $dataProvider = $searchModel->allData($params);
  125. } else {
  126. $dataProvider = $searchModel->search($params);
  127. }
  128. \iron\widget\Excel::export([
  129. 'models' => $dataProvider->getModels(),
  130. 'format' => 'Xlsx',
  131. 'asAttachment' => true,
  132. 'fileName' =>'Taking Sites'. "-" .date('Y-m-d H/i/s', time()),
  133. 'columns' => $searchModel->columns()
  134. ]);
  135. }
  136. /**
  137. * @return array
  138. * 根据省获取市数据
  139. */
  140. public function actionCity()
  141. {
  142. Yii::$app->response->format = 'json';
  143. $parents = Yii::$app->request->post('depdrop_parents');
  144. if ($parents != null) {
  145. $provinceId = $parents[0];
  146. $data = City::find()->select('city_id as id,name')->where(['province_id' => $provinceId])->asArray()->all();
  147. return ['output' => $data, 'selected' => '441904'];
  148. } else {
  149. return ['output' => '', 'selected' => ''];
  150. }
  151. }
  152. /**
  153. * @return array
  154. * 根据市数据获取区域数据
  155. */
  156. public function actionArea()
  157. {
  158. Yii::$app->response->format = 'json';
  159. $parents = Yii::$app->request->post('depdrop_parents');
  160. if ($parents != null) {
  161. $cityId = $parents[0];
  162. $data = Area::find()->select('area_id as id,name')->where(['city_id' => $cityId])->asArray()->all();
  163. return ['output' => $data, 'selected' => ''];
  164. } else {
  165. return ['output' => '', 'selected' => ''];
  166. }
  167. }
  168. }