GoodsController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. $where = [];
  66. if ($status != -1) {
  67. $where['status'] = $status;
  68. }
  69. if (!empty($name)) {
  70. $where['name'] = ['like', $name];
  71. }
  72. if (!empty($cId)) {
  73. $where['cId'] = $cId;
  74. }
  75. $where['mainId'] = $this->mainId;
  76. $where['delStatus'] = 0;
  77. $data = GoodsService::getGoodsList($where);
  78. util::success($data);
  79. }
  80. //获取商品详情 ssh 2019.12.7
  81. public function actionDetail()
  82. {
  83. $id = Yii::$app->request->get('id');
  84. $goods = GoodsClass::getGoodsInfo($id);
  85. GoodsClass::valid($goods, $this->mainId);
  86. util::success($goods);
  87. }
  88. //更新商品 ssh 2019.12.7
  89. public function actionUpdate()
  90. {
  91. $data = Yii::$app->request->post();
  92. $id = isset($data['id']) ? $data['id'] : 0;
  93. $info = GoodsService::getById($id);
  94. GoodsService::valid($info, $this->mainId);
  95. $data['sjId'] = $this->sjId;
  96. $data['mainId'] = $this->mainId;
  97. $data['flower'] = $info['flower'] ?? 0;
  98. GoodsService::updateGoods($id, $data);
  99. util::complete();
  100. }
  101. //商品排序 ssh 2020.3.11
  102. public function actionSort()
  103. {
  104. $id = Yii::$app->request->get('id', 0);
  105. $cId = Yii::$app->request->get('cId', 0);
  106. $inTurn = Yii::$app->request->get('inTurn', 0);
  107. //验证商品
  108. $info = GoodsService::getById($id);
  109. GoodsService::valid($info, $this->mainId);
  110. if ($cId != 0) {
  111. //验证分类
  112. $category = CategoryService::getById($cId);
  113. CategoryService::valid($category, $this->mainId);
  114. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  115. } else {
  116. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  117. GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
  118. }
  119. util::complete('操作成功');
  120. }
  121. //删除商品 ssh 2019.12.7
  122. public function actionDelete()
  123. {
  124. $id = Yii::$app->request->get('id', 0);
  125. $goods = GoodsService::getById($id);
  126. GoodsService::valid($goods, $this->mainId);
  127. GoodsService::deleteGoods($goods);
  128. util::complete();
  129. }
  130. //上下架 ssh 2019.12.8
  131. public function actionChangeStatus()
  132. {
  133. $get = Yii::$app->request->get();
  134. $id = isset($get['id']) ? $get['id'] : 0;
  135. $status = isset($get['status']) ? $get['status'] : 1;
  136. $info = GoodsService::getById($id);
  137. GoodsService::valid($info, $this->mainId);
  138. GoodsService::changeStatus($id, $status);
  139. util::complete();
  140. }
  141. //商品说明 ssh 2019.12.8
  142. public function actionIntroduce()
  143. {
  144. $set = GoodsSettingService::getByCondition(['mainId' => $this->mainId]);
  145. $introduce = $set['goodsIntroduce'];
  146. util::success(['introduce' => $introduce]);
  147. }
  148. //修改商品说明 ssh 2019.12.8
  149. public function actionUpdateIntroduce()
  150. {
  151. $introduce = Yii::$app->request->post('introduce', '');
  152. GoodsSettingService::updateByCondition(['mainId' => $this->mainId], ['goodsIntroduce' => $introduce]);
  153. util::complete('提交成功');
  154. }
  155. //设置 ssh 2019.12.8
  156. public function actionSetting()
  157. {
  158. $return = GoodsSettingService::getSetting($this->mainId);
  159. util::success($return);
  160. }
  161. //更新涨价 ssh 2019.12.9
  162. public function actionUpdateRise()
  163. {
  164. $post = Yii::$app->request->post();
  165. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  166. unset($post['festIdList']);
  167. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  168. if ($riseSwitch == 1) {
  169. if (empty($festIdList)) {
  170. util::fail('请选择节日');
  171. }
  172. FestRiseService::deleteByCondition(['mainId' => $this->mainId]);
  173. $add = [];
  174. foreach ($festIdList as $festId) {
  175. $add[] = ['mainId' => $this->mainId, 'festId' => $festId];
  176. }
  177. FestRiseService::batchAdd($add);
  178. }
  179. GoodsSettingService::updateByCondition(['mainId' => $this->mainId], $post);
  180. util::complete('提交成功');
  181. }
  182. //获取商品详情 ssh 2019.12.3
  183. public function actionMallDetail()
  184. {
  185. $id = Yii::$app->request->get('id', 0);
  186. $info = GoodsClass::getGoodsInfo($id);
  187. GoodsService::valid($info, $this->mainId);
  188. $setting = GoodsSettingService::getByCondition(['mainId' => $this->mainId]);
  189. $commonIntro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
  190. $info['commonIntro'] = $commonIntro;
  191. util::success($info);
  192. }
  193. public function actionIndex()
  194. {
  195. $catWhere = ['mainId' => $this->mainId];
  196. $goodsWhere['mainId'] = $this->mainId;
  197. $goodsWhere['delStatus'] = 0;
  198. $classIds = CategoryService::getCategoryClassAll($catWhere);
  199. $goodsData = GoodsCategoryService::getGoodsAll($goodsWhere);
  200. $goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->mainId);
  201. //组装数据 [{classId:'','className:'',child:[{itemInfoData}]}]
  202. $data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData);
  203. util::success($data);
  204. }
  205. //保存花材组合 ssh 2021.4.10
  206. public function actionSaveItemGroup()
  207. {
  208. $orderSn = Yii::$app->request->post('orderSn', '');
  209. $name = Yii::$app->request->post('name', '');
  210. $classId = Yii::$app->request->post('categoryId', 0);
  211. if (empty($name)) {
  212. util::fail("名称不能为空");
  213. }
  214. $cateExists = CategoryService::exists(['id' => $classId, 'mainId' => $this->mainId]);
  215. if (!$cateExists) {
  216. util::fail("分类不存在");
  217. }
  218. $itemInfo = OrderItemclass::getAllByCondition(['orderSn' => $orderSn], null, "*");
  219. if (empty($itemInfo)) {
  220. util::fail("订单不存在");
  221. }
  222. $order = OrderService::getOrderBySn($orderSn);
  223. OrderService::valid($order, $this->shopId);
  224. $save = GoodsService::saveItemGroup($order, $itemInfo, $classId, $name, $this->adminId);
  225. if ($save) {
  226. util::complete();
  227. }
  228. util::fail("保存失败");
  229. }
  230. }