GoodsController.php 7.9 KB

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