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.

190 lines
5.2 KiB

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