GoodsController.php 8.6 KB

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