GoodsController.php 7.6 KB

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