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.

149 lines
3.8 KiB

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