GoodsController.php 7.5 KB

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