PriceDifferenceGiftPackageController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace addons\CloudStock\backend\controllers;
  3. use addons\CloudStock\common\models\CloudStockGoods;
  4. use addons\CloudStock\common\services\CloudStockPriceDifferenceGiftPackageService;
  5. use common\enums\StatusEnum;
  6. use common\models\goods\Goods;
  7. use Yii;
  8. /**
  9. * 默认控制器
  10. *
  11. * Class DefaultController
  12. * @package addons\CloudStock\backend\controllers
  13. */
  14. class PriceDifferenceGiftPackageController extends BaseController
  15. {
  16. public $enableCsrfValidation = false;
  17. public function actionIndex()
  18. {
  19. // 查询参数
  20. if (\Yii::$app->request->isAjax) {
  21. if (\Yii::$app->request->isGet) {
  22. $params = \Yii::$app->request->get();
  23. $params['mall_id'] = $this->mall_id;
  24. $data = (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->index($params);
  25. return $this->success('操作成功', $data);
  26. }
  27. }
  28. return $this->render($this->action->id);
  29. }
  30. public function actionEdit()
  31. {
  32. try {
  33. $request = Yii::$app->request;
  34. if ($request->isAjax) {
  35. if ($request->isGet) {
  36. $params = Yii::$app->request->get();
  37. $data = (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->detail($params);
  38. return $this->success('操作成功', $data);
  39. }
  40. if ($request->isPost) {
  41. $params = Yii::$app->request->post();
  42. if (!empty($params['pic_type'])) {
  43. if (empty($params['pic'])) {
  44. return $this->error('请上传图片');
  45. }
  46. }
  47. $params['mall_id'] = $this->mall_id;
  48. $ret = (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->edit($params);
  49. return $this->success('操作成功', $ret);
  50. }
  51. }
  52. } catch (\Exception $e) {
  53. return $this->error($e->getMessage(), []);
  54. }
  55. }
  56. public function actionSwitchStatus()
  57. {
  58. try {
  59. if (\Yii::$app->request->isAjax) {
  60. if (\Yii::$app->request->isPost) {
  61. $params = \Yii::$app->request->post();
  62. $res = Yii::$app->services->validate->validate($params, [
  63. [['id'], 'required'],
  64. [['status'], 'integer']
  65. ]);
  66. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  67. $params['mall_id'] = $this->mall_id;
  68. (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->switchStatus($params);
  69. return $this->success('操作成功');
  70. }
  71. }
  72. return $this->error();
  73. } catch (\Exception $e) {
  74. return $this->error($e->getMessage(), []);
  75. }
  76. }
  77. public function actionDelete()
  78. {
  79. try {
  80. if (\Yii::$app->request->isAjax) {
  81. if (\Yii::$app->request->isPost) {
  82. $params = \Yii::$app->request->post();
  83. $res = Yii::$app->services->validate->validate($params, [
  84. [['id'], 'required'],
  85. ]);
  86. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  87. $params['mall_id'] = $this->mall_id;
  88. $params['status'] = StatusEnum::DELETE;
  89. (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->del($params);
  90. return $this->success('操作成功');
  91. }
  92. }
  93. return $this->error();
  94. } catch (\Exception $e) {
  95. return $this->error($e->getMessage(), []);
  96. }
  97. }
  98. //不用验证权限
  99. public function actionGetCloudStockGoodsList()
  100. {
  101. $where[] = ['=', 'mall_id', $this->mall_id];
  102. $where[] = ['in', 'status', [StatusEnum::DISABLED, StatusEnum::ENABLED]];
  103. $params = [
  104. 'where' => $where, 'order' => 'id desc', 'select' => 'id,goods_id'
  105. ];
  106. $page_data = CloudStockGoods::listPage($params, true, true);
  107. if (!empty($page_data['list'])) {
  108. $goods_id_arr = array_column($page_data['list'], 'goods_id');
  109. $goods_arr = Goods::lists(['where' => [['id' => $goods_id_arr]], 'index' => 'id']);
  110. foreach ($page_data['list'] as &$item) {
  111. $item['goods_name'] = $item['cover_pic'] = '';
  112. if (!empty($goods_arr[$item['goods_id']])) {
  113. $item['goods_name'] = $goods_arr[$item['goods_id']]['goods_name'];
  114. $item['cover_pic'] = $goods_arr[$item['goods_id']]['cover_pic'];
  115. }
  116. }
  117. }
  118. return $this->success('操作成功', $page_data);
  119. }
  120. public function actionGetLevelList()
  121. {
  122. $request = Yii::$app->request;
  123. if ($request->isAjax) {
  124. // 查询参数
  125. if (\Yii::$app->request->isAjax) {
  126. if (\Yii::$app->request->isGet) {
  127. $params = \Yii::$app->request->get();
  128. $params['mall_id'] = $this->mall_id;
  129. $data = (new CloudStockPriceDifferenceGiftPackageService(['mall_id' => $this->mall_id]))->getLevelList($params);
  130. return $this->success('操作成功', $data);
  131. }
  132. }
  133. }
  134. }
  135. }