GoodsController.php 7.2 KB

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