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.

151 lines
4.0 KiB

  1. <?php
  2. namespace backend\modules\goods\controllers;
  3. use Yii;
  4. use backend\modules\goods\models\ars\Supplier;
  5. use backend\modules\goods\models\searchs\SupplierSearch;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. /**
  10. * SupplierController implements the CRUD actions for Supplier model.
  11. */
  12. class SupplierController 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 Supplier models.
  30. * @return mixed
  31. */
  32. public function actionIndex()
  33. {
  34. $searchModel = new SupplierSearch();
  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 Supplier 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 Supplier 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 Supplier();
  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 Supplier 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 Supplier 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. $model = $this->findModel($id);
  96. $model->is_delete = Supplier::IS_DELETE_YES;
  97. $model->save();
  98. return $this->redirect(['index']);
  99. }
  100. /**
  101. * Finds the Supplier 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 Supplier the loaded model
  105. * @throws NotFoundHttpException if the model cannot be found
  106. */
  107. protected function findModel($id)
  108. {
  109. if (($model = Supplier::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 SupplierSearch();
  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' =>'Suppliers'. "-" .date('Y-m-d H/i/s', time()),
  132. 'columns' => $searchModel->columns()
  133. ]);
  134. }
  135. }