GoodsController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace addons\ScoreExpansion\backend\controllers;
  3. use addons\ScoreExpansion\backend\services\ScoreExpansionRecommendRewardGoodsService;
  4. use addons\ScoreExpansion\common\models\ScoreExpansionRecommendRewardGoods;
  5. use Yii;
  6. use yii\db\Exception;
  7. class GoodsController extends BaseController
  8. {
  9. public $enableCsrfValidation = false;
  10. /**
  11. * 商品页面
  12. *
  13. * @return string
  14. */
  15. public function actionIndex()
  16. {
  17. return $this->render($this->action->id);
  18. }
  19. /**
  20. * 商品列表
  21. *
  22. * @return void
  23. */
  24. public function actionList()
  25. {
  26. $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
  27. $this->success('success', $scoreExpansionRecommendRewardGoodsService->list($this->request->get()));
  28. }
  29. /**
  30. * 设置独立奖励
  31. *
  32. * @return void
  33. */
  34. public function actionEdit()
  35. {
  36. $post = $this->request->post();
  37. $res = Yii::$app->services->validate->validate($post, [
  38. [['id', 'is_alone', 'setting'], 'required'],
  39. [['id', 'is_alone'], 'integer'],
  40. ]);
  41. if ($res === false) {
  42. $this->error(Yii::$app->services->validate->getErrorMessage());
  43. return;
  44. }
  45. $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
  46. if (!$scoreExpansionRecommendRewardGoodsService->edit($post)) {
  47. $this->error($scoreExpansionRecommendRewardGoodsService->getError());
  48. return;
  49. }
  50. $this->success();
  51. }
  52. /**
  53. * 删除商品
  54. *
  55. * @return void
  56. */
  57. public function actionDel()
  58. {
  59. $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
  60. if (!$scoreExpansionRecommendRewardGoodsService->del($this->request->post('id'))) {
  61. $this->error($scoreExpansionRecommendRewardGoodsService->getError());
  62. return;
  63. }
  64. $this->success();
  65. }
  66. /**
  67. * 添加商品
  68. *
  69. * @return void
  70. * @throws Exception
  71. */
  72. public function actionSave()
  73. {
  74. $post = $this->request->post();
  75. $res = Yii::$app->services->validate->validate($post, [
  76. [['goods_ids'], 'required'],
  77. ]);
  78. if ($res === false) {
  79. $this->error(Yii::$app->services->validate->getErrorMessage());
  80. return;
  81. }
  82. $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
  83. if (!$scoreExpansionRecommendRewardGoodsService->save($post['goods_ids'])) {
  84. $this->error($scoreExpansionRecommendRewardGoodsService->getError() ?: '添加失败');
  85. return;
  86. }
  87. $this->success();
  88. }
  89. }