GoodsController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\OrderItemClass;
  4. use bizHd\goods\classes\GoodsClass;
  5. use bizHd\goods\services\CategoryService;
  6. use bizHd\goods\services\GoodsCategoryService;
  7. use bizHd\goods\services\GoodsSettingService;
  8. use biz\sj\services\MerchantAssetService;
  9. use bizHd\saas\services\FestRiseService;
  10. use common\components\noticeUtil;
  11. use Yii;
  12. use common\components\util;
  13. use bizHd\goods\services\GoodsService;
  14. use yii\web\Controller;
  15. use bizHd\order\services\OrderService;
  16. class GoodsController extends BaseController
  17. {
  18. public $guestAccess = ['detail'];
  19. //商品列表 ssh 2019.12.7
  20. public function actionList()
  21. {
  22. $get = Yii::$app->request->get();
  23. $status = isset($get['status']) && is_numeric($get['status']) ? $get['status'] : -1;
  24. $cId = isset($get['cId']) && !empty($get['cId']) ? $get['cId'] : 0;
  25. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  26. $where = [];
  27. if ($status != -1) {
  28. $where['status'] = $status;
  29. }
  30. if (!empty($name)) {
  31. $where['name'] = ['like', $name];
  32. }
  33. if (!empty($cId)) {
  34. $where['cId'] = $cId;
  35. }
  36. $where['mainId'] = $this->mainId;
  37. $where['delStatus'] = 0;
  38. $data = GoodsService::getGoodsList($where);
  39. util::success($data);
  40. }
  41. //获取商品详情 ssh 2019.12.7
  42. public function actionDetail()
  43. {
  44. $id = Yii::$app->request->get('id');
  45. $goods = GoodsService::getGoodsInfo($id);
  46. GoodsClass::valid($goods, $this->sjId);
  47. util::success($goods);
  48. }
  49. //更新商品 ssh 2019.12.7
  50. public function actionUpdate()
  51. {
  52. $data = Yii::$app->request->post();
  53. $id = isset($data['id']) ? $data['id'] : 0;
  54. $info = GoodsService::getById($id);
  55. GoodsService::valid($info, $this->sjId);
  56. $data['sjId'] = $this->sjId;
  57. $data['mainId'] = $this->mainId;
  58. GoodsService::updateGoods($id, $data);
  59. util::complete();
  60. }
  61. //商品排序 ssh 2020.3.11
  62. public function actionSort()
  63. {
  64. $id = Yii::$app->request->get('id', 0);
  65. $cId = Yii::$app->request->get('cId', 0);
  66. $inTurn = Yii::$app->request->get('inTurn', 0);
  67. //验证商品
  68. $info = GoodsService::getById($id);
  69. GoodsService::valid($info, $this->sjId);
  70. if ($cId != 0) {
  71. //验证分类
  72. $category = CategoryService::getById($cId);
  73. CategoryService::valid($category, $this->sjId);
  74. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  75. } else {
  76. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  77. GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
  78. }
  79. util::complete('操作成功');
  80. }
  81. //删除商品 ssh 2019.12.7
  82. public function actionDelete()
  83. {
  84. $id = Yii::$app->request->get('id', 0);
  85. $goods = GoodsService::getById($id);
  86. GoodsService::valid($goods, $this->sjId);
  87. GoodsService::deleteGoods($goods);
  88. util::complete();
  89. }
  90. //上下架 ssh 2019.12.8
  91. public function actionChangeStatus()
  92. {
  93. $get = Yii::$app->request->get();
  94. $id = isset($get['id']) ? $get['id'] : 0;
  95. $status = isset($get['status']) ? $get['status'] : 1;
  96. $info = GoodsService::getById($id);
  97. GoodsService::valid($info, $this->sjId);
  98. GoodsService::changeStatus($id, $status);
  99. util::complete();
  100. }
  101. //商品说明 ssh 2019.12.8
  102. public function actionIntroduce()
  103. {
  104. $set = GoodsSettingService::getByCondition(['sjId' => $this->sjId]);
  105. $introduce = $set['goodsIntroduce'];
  106. util::success(['introduce' => $introduce]);
  107. }
  108. //修改商品说明 ssh 2019.12.8
  109. public function actionUpdateIntroduce()
  110. {
  111. $introduce = Yii::$app->request->post('introduce', '');
  112. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], ['goodsIntroduce' => $introduce]);
  113. util::complete('提交成功');
  114. }
  115. //设置 ssh 2019.12.8
  116. public function actionSetting()
  117. {
  118. $return = GoodsSettingService::getSetting($this->sjId);
  119. util::success($return);
  120. }
  121. //更新涨价 ssh 2019.12.9
  122. public function actionUpdateRise()
  123. {
  124. $post = Yii::$app->request->post();
  125. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  126. unset($post['festIdList']);
  127. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  128. if ($riseSwitch == 1) {
  129. if (empty($festIdList)) {
  130. util::fail('请选择节日');
  131. }
  132. FestRiseService::deleteByCondition(['sjId' => $this->sjId]);
  133. $add = [];
  134. foreach ($festIdList as $festId) {
  135. $add[] = ['sjId' => $this->sjId, 'festId' => $festId];
  136. }
  137. FestRiseService::batchAdd($add);
  138. }
  139. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], $post);
  140. util::complete('提交成功');
  141. }
  142. //获取商品详情 ssh 2019.12.3
  143. public function actionMallDetail()
  144. {
  145. $id = Yii::$app->request->get('id', 0);
  146. $info = GoodsService::getGoodsInfo($id);
  147. GoodsService::valid($info, $this->sjId);
  148. $setting = GoodsSettingService::getByCondition(['sjId' => $this->sjId]);
  149. $commonIntro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
  150. $info['commonIntro'] = $commonIntro;
  151. util::success($info);
  152. }
  153. public function actionIndex()
  154. {
  155. $classIds = CategoryService::getCategoryClassAll($this->mainId);
  156. $where['sjId'] = $this->sjId;
  157. $where['delStatus'] = 0;
  158. $goodsData = GoodsCategoryService::getGoodsAll($where);
  159. //常用的GoodsId
  160. $oftenIds = GoodsCategoryService::getOftenIds($this->mainId);
  161. $goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->mainId);
  162. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  163. $data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData, $oftenIds);
  164. util::success($data);
  165. }
  166. //保存花材组合 shish 2021.4.10
  167. public function actionSaveItemGroup()
  168. {
  169. $orderSn = Yii::$app->request->post('orderSn', '');
  170. $name = Yii::$app->request->post('name', '');
  171. $classId = Yii::$app->request->post('categoryId', 0);
  172. if (empty($name)) {
  173. util::fail("名称不能为空");
  174. }
  175. $cateExists = CategoryService::exists(['id' => $classId, 'sjId' => $this->sjId]);
  176. if (!$cateExists) {
  177. util::fail("分类不存在");
  178. }
  179. $itemInfo = OrderItemclass::getAllByCondition(['orderSn' => $orderSn], null, "*");
  180. if (empty($itemInfo)) {
  181. util::fail("订单不存在");
  182. }
  183. $order = OrderService::getOrderBySn($orderSn);
  184. OrderService::valid($order, $this->shopId);
  185. $save = GoodsService::saveItemGroup($order, $itemInfo, $classId, $name, $this->adminId);
  186. if ($save) {
  187. util::complete();
  188. }
  189. util::fail("保存失败");
  190. }
  191. }