GoodsController.php 7.7 KB

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