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.

173 lines
4.6 KiB

  1. <?php
  2. namespace backend\modules\shop\controllers;
  3. use Yii;
  4. use backend\modules\shop\models\ars\AfterSale;
  5. use backend\modules\shop\models\searchs\AfterSaleSearch;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. /**
  10. * AfterSaleController implements the CRUD actions for AfterSale model.
  11. */
  12. class AfterSaleController 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 AfterSale models.
  30. * @return mixed
  31. */
  32. public function actionIndex()
  33. {
  34. $searchModel = new AfterSaleSearch();
  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 AfterSale 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 AfterSale 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 AfterSale();
  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 AfterSale 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 AfterSale 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 AfterSale 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 AfterSale the loaded model
  103. * @throws NotFoundHttpException if the model cannot be found
  104. */
  105. protected function findModel($id)
  106. {
  107. if (($model = AfterSale::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 AfterSaleSearch();
  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' =>'After Sales'. "-" .date('Y-m-d H/i/s', time()),
  130. 'columns' => $searchModel->columns()
  131. ]);
  132. }
  133. /**
  134. * @param $status
  135. * @param $id
  136. * @return \yii\web\Response
  137. * 处理售后申请
  138. */
  139. public function actionHandle($status, $id)
  140. {
  141. $url = Yii::$app->request->referrer;
  142. $model = AfterSale::findOne($id);
  143. if ($status == AfterSale::STATUS_ACCEPT) {
  144. $model->status = AfterSale::STATUS_ACCEPT;
  145. } else {
  146. $model->status = AfterSale::STATUS_REJECT;
  147. }
  148. $model->dealt_at = time();
  149. $model->operator_id = Yii::$app->user->id;
  150. if ($model->save()) {
  151. return $this->redirect('index');
  152. } else {
  153. return $this->redirect($url);
  154. }
  155. }
  156. }