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