GoodsController.php 7.6 KB

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