GoodsController.php 8.2 KB

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