GoodsController.php 8.8 KB

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