OrderCommentTemplatesController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use common\enums\StatusEnum;
  5. use common\models\goods\Goods;
  6. use common\models\order\OrderComments;
  7. use common\models\order\OrderCommentsTemplates;
  8. use common\models\User;
  9. use Exception;
  10. use Yii;
  11. /**
  12. * 评价模板管理控制器
  13. *
  14. * Class OrderCommentsController
  15. * @Author: hua
  16. * @DateTime: 2021/10/7 15:57
  17. * @Copyright: copyright (c) 2021 广东七件事集团
  18. * @package backend\modules\mall\controllers
  19. */
  20. class OrderCommentTemplatesController extends MallController
  21. {
  22. /**
  23. * 首页
  24. * @Author: hua
  25. * @DateTime: 2021/10/7 15:57
  26. * @Copyright: copyright (c) 2021 广东七件事集团
  27. * @return mixed|string|void
  28. */
  29. public function actionIndex()
  30. {
  31. if (\Yii::$app->request->isAjax) {
  32. if (\Yii::$app->request->isGet) {
  33. $params = Yii::$app->request->get();
  34. $params['where'] = [['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]];
  35. if (isset($params['type']) && $params['type'] != -1) $params['where'][] = ['=', 'type', $params['type']];
  36. if (isset($params['keyword_name']) && !empty($params['keyword'])) {
  37. if ($params['keyword_name'] == 'id') $params['where'][] = ['=', 'id', $params['keyword']];
  38. if ($params['keyword_name'] == 'title') $params['where'][] = ['=', 'title', $params['keyword']];
  39. }
  40. $page_data = OrderCommentsTemplates::listPage($params);
  41. if ($page_data === false) return $this->error(OrderComments::getStaticError());
  42. return $this->success('操作成功', $page_data);
  43. }
  44. }
  45. return $this->render($this->action->id);
  46. }
  47. /**
  48. * 编辑
  49. * @Author: hua
  50. * @DateTime: 2021/10/7 16:27
  51. * @Copyright: copyright (c) 2021 广东七件事集团
  52. */
  53. public function actionEdit()
  54. {
  55. if (\Yii::$app->request->isAjax) {
  56. $params = Yii::$app->request->post();
  57. $rules = [
  58. [['title', 'content', 'type'], 'required'],
  59. [['id'], 'safe']
  60. ];
  61. $res = Yii::$app->services->validate->validate($params, $rules);
  62. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  63. $params['mall_id'] = $this->mall_id;
  64. $res = OrderCommentsTemplates::setData($params);
  65. if ($res === false) return $this->error(OrderComments::getStaticError());
  66. return $this->success();
  67. }
  68. }
  69. /**
  70. * 删除
  71. * @Author: hua
  72. * @DateTime: 2021/10/7 16:53
  73. * @Copyright: copyright (c) 2021 广东七件事集团
  74. * @return mixed|void
  75. * @throws Exception
  76. */
  77. public function actionDestroy()
  78. {
  79. if (\Yii::$app->request->isAjax) {
  80. $params = Yii::$app->request->post();
  81. $rules = [
  82. [['id'], 'required'],
  83. [['id'], 'integer']
  84. ];
  85. $res = Yii::$app->services->validate->validate($params, $rules);
  86. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  87. $params['status'] = StatusEnum::DELETE;
  88. $res = OrderCommentsTemplates::setData($params);
  89. if ($res === false) return $this->error(OrderComments::getStaticError());
  90. return $this->success();
  91. }
  92. }
  93. }