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.

155 lines
4.1 KiB

  1. <?php
  2. namespace backend\modules\shop\controllers;
  3. use backend\modules\shop\logic\delivery\DeliveryManager;
  4. use Yii;
  5. use backend\modules\shop\models\ars\Delivery;
  6. use backend\modules\shop\models\searchs\DeliverySearch;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. /**
  11. * DeliveryController implements the CRUD actions for Delivery model.
  12. */
  13. class DeliveryController extends Controller
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function behaviors()
  19. {
  20. return [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. 'delete' => ['POST'],
  25. ],
  26. ],
  27. ];
  28. }
  29. /**
  30. * Lists all Delivery models.
  31. * @return mixed
  32. */
  33. public function actionIndex()
  34. {
  35. $searchModel = new DeliverySearch();
  36. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  37. return $this->render('index', [
  38. 'searchModel' => $searchModel,
  39. 'dataProvider' => $dataProvider,
  40. 'columns' => $searchModel->columns()
  41. ]);
  42. }
  43. /**
  44. * Displays a single Delivery model.
  45. * @param integer $id
  46. * @return mixed
  47. * @throws NotFoundHttpException if the model cannot be found
  48. */
  49. public function actionView($id)
  50. {
  51. $model = $this->findModel($id);
  52. $logistics = DeliveryManager::queryLogistics($model->order_id);
  53. return $this->render('view', [
  54. 'model' => $model,
  55. 'logistics' => $logistics,
  56. ]);
  57. }
  58. /**
  59. * Creates a new Delivery model.
  60. * If creation is successful, the browser will be redirected to the 'view' page.
  61. * @return mixed
  62. */
  63. public function actionCreate()
  64. {
  65. $model = new Delivery();
  66. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  67. return $this->redirect('index');
  68. }
  69. return $this->render('create', [
  70. 'model' => $model,
  71. ]);
  72. }
  73. /**
  74. * Updates an existing Delivery model.
  75. * If update is successful, the browser will be redirected to the 'view' page.
  76. * @param integer $id
  77. * @return mixed
  78. * @throws NotFoundHttpException if the model cannot be found
  79. */
  80. public function actionUpdate($id)
  81. {
  82. $model = $this->findModel($id);
  83. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  84. return $this->redirect('index');
  85. }
  86. return $this->render('update', [
  87. 'model' => $model,
  88. ]);
  89. }
  90. /**
  91. * Deletes an existing Delivery model.
  92. * If deletion is successful, the browser will be redirected to the 'index' page.
  93. * @param integer $id
  94. * @return mixed
  95. * @throws NotFoundHttpException if the model cannot be found
  96. */
  97. public function actionDelete($id)
  98. {
  99. $this->findModel($id)->delete();
  100. return $this->redirect(['index']);
  101. }
  102. /**
  103. * Finds the Delivery model based on its primary key value.
  104. * If the model is not found, a 404 HTTP exception will be thrown.
  105. * @param integer $id
  106. * @return Delivery the loaded model
  107. * @throws NotFoundHttpException if the model cannot be found
  108. */
  109. protected function findModel($id)
  110. {
  111. if (($model = Delivery::findOne($id)) !== null) {
  112. return $model;
  113. }
  114. throw new NotFoundHttpException('The requested page does not exist.');
  115. }
  116. /**
  117. * @author iron
  118. * 文件导出
  119. */
  120. public function actionExport()
  121. {
  122. $searchModel = new DeliverySearch();
  123. $params = Yii::$app->request->queryParams;
  124. if ($params['page-type'] == 'all') {
  125. $dataProvider = $searchModel->allData($params);
  126. } else {
  127. $dataProvider = $searchModel->search($params);
  128. }
  129. \iron\widget\Excel::export([
  130. 'models' => $dataProvider->getModels(),
  131. 'format' => 'Xlsx',
  132. 'asAttachment' => true,
  133. 'fileName' =>'Deliveries'. "-" .date('Y-m-d H/i/s', time()),
  134. 'columns' => $searchModel->columns()
  135. ]);
  136. }
  137. }