GoodsController.php 8.5 KB

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