Goods.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\bargain\api\controller;
  11. use addon\bargain\model\Bargain as BargainModel;
  12. use addon\bargain\model\Poster;
  13. use app\api\controller\BaseApi;
  14. use app\api\controller\Goodssku;
  15. /**
  16. * 砍价商品
  17. */
  18. class Goods extends BaseApi
  19. {
  20. /**
  21. * 获取砍价活动列表
  22. */
  23. public function page()
  24. {
  25. $page = $this->params[ 'page' ] ?? 1;
  26. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  27. $id_arr = isset($this->params[ 'id_arr' ]) ? $this->params[ 'id_arr' ] : '';
  28. $is_exclude_bargaining = $this->params[ 'is_exclude_bargaining' ] ?? 0; // 是否需排除砍价中
  29. $bargain = new BargainModel();
  30. $condition = [
  31. [ 'pb.site_id', '=', $this->site_id ],
  32. [ 'pb.status', '=', 1 ],
  33. [ 'g.goods_state', '=', 1 ],
  34. [ 'g.is_delete', '=', 0 ]
  35. ];
  36. if (!empty($id_arr)) {
  37. $condition[] = [ 'pb.goods_id', 'in', $id_arr ];
  38. }
  39. if ($is_exclude_bargaining) {
  40. $token = $this->checkToken();
  41. if ($token[ 'code' ] == 0) {
  42. $goods_id = $bargain->getBargainingGoodsId($this->member_id);
  43. if (!empty($goods_id)) $condition[] = [ 'g.goods_id', 'not in', $goods_id ];
  44. }
  45. }
  46. $data = $bargain->getBargainPageList($condition, $page, $page_size, 'pb.bargain_id desc', '');
  47. return $this->response($data);
  48. }
  49. /**
  50. * 获取砍价活动列表
  51. */
  52. public function lists()
  53. {
  54. $num = $this->params[ 'num' ] ?? null;
  55. $id_arr = isset($this->params[ 'id_arr' ]) ? $this->params[ 'id_arr' ] : '';
  56. $is_exclude_bargaining = $this->params[ 'is_exclude_bargaining' ] ?? 0; // 是否需排除砍价中
  57. $bargain = new BargainModel();
  58. $condition = [
  59. [ 'pb.site_id', '=', $this->site_id ],
  60. [ 'pb.status', '=', 1 ],
  61. [ 'g.goods_state', '=', 1 ],
  62. [ 'g.is_delete', '=', 0 ]
  63. ];
  64. if (!empty($id_arr)) {
  65. $condition[] = [ 'pb.goods_id', 'in', $id_arr ];
  66. }
  67. if ($is_exclude_bargaining) {
  68. $token = $this->checkToken();
  69. if ($token[ 'code' ] == 0) {
  70. $goods_id = $bargain->getBargainingGoodsId($this->member_id);
  71. if (!empty($goods_id)) $condition[] = [ 'g.goods_id', 'not in', $goods_id ];
  72. }
  73. }
  74. $data = $bargain->getBargainList($condition, '', 'pb.bargain_id desc', $num);
  75. return $this->response($data);
  76. }
  77. /**
  78. * 获取砍价中的商品列表
  79. * @return false|string
  80. */
  81. public function bargainingList()
  82. {
  83. $token = $this->checkToken();
  84. if ($token[ 'code' ] < 0) return $this->response($token);
  85. $condition = [
  86. [ 'pbl.site_id', '=', $this->site_id ],
  87. [ 'pbl.member_id', '=', $this->member_id ],
  88. [ 'pbl.status', '=', 0 ],
  89. [ 'g.goods_state', '=', 1 ],
  90. [ 'g.is_delete', '=', 0 ],
  91. [ 'pb.status', '=', 1 ],
  92. ];
  93. $join = [
  94. ['goods g', 'g.goods_id = pbl.goods_id', 'left'],
  95. ['promotion_bargain pb', 'pb.goods_id = pbl.goods_id', 'left'],
  96. ];
  97. $field = 'pb.sale_num,pb.join_num,pbl.launch_id,pbl.bargain_id,pbl.sku_id,pbl.goods_id,pbl.site_id,pbl.start_time,pbl.end_time,pbl.member_id,pbl.curr_price,pbl.price,g.goods_name,g.goods_image,g.recommend_way,pbl.floor_price';
  98. $bargain = new BargainModel();
  99. $list = $bargain->getBargainLaunchList($condition, $field, 'pbl.start_time desc', 'pbl', $join);
  100. return $this->response($this->success($list));
  101. }
  102. /**
  103. * 商品详情
  104. */
  105. public function detail()
  106. {
  107. $bargain_id = isset($this->params[ 'bargain_id' ]) ? $this->params[ 'bargain_id' ] : 0;
  108. if (empty($bargain_id)) {
  109. return $this->response($this->error('', 'REQUEST_ID'));
  110. }
  111. $bargain = new BargainModel();
  112. $condition = [
  113. [ 'pb.bargain_id', '=', $bargain_id ],
  114. [ 'pbg.site_id', '=', $this->site_id ],
  115. [ 'pbg.status', '=', 1 ],
  116. [ 'g.goods_state', '=', 1 ],
  117. [ 'g.is_delete', '=', 0 ]
  118. ];
  119. $goods_sku_detail = $bargain->getBargainGoodsDetail($condition)[ 'data' ];
  120. if (empty($goods_sku_detail)) return $this->response($this->error());
  121. $res[ 'goods_sku_detail' ] = $goods_sku_detail;
  122. if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
  123. //判断商品规格项
  124. $goods_spec_format = $bargain->getGoodsSpecFormat($bargain_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
  125. $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  126. }
  127. $token = $this->checkToken();
  128. if ($token[ 'code' ] == 0) {
  129. $launch_info = $bargain->getBargainLaunchDetail([
  130. [ 'bargain_id', '=', $goods_sku_detail[ 'bargain_id' ] ],
  131. [ 'sku_id', '=', $goods_sku_detail[ 'sku_id' ] ],
  132. [ 'member_id', '=', $this->member_id ],
  133. [ 'status', '=', 0 ]
  134. ], 'launch_id');
  135. if (!empty($launch_info[ 'data' ])) $res[ 'goods_sku_detail' ][ 'launch_info' ] = $launch_info[ 'data' ];
  136. }
  137. // 处理公共数据
  138. $goods_sku_api = new Goodssku();
  139. $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ]);
  140. return $this->response($this->success($res));
  141. }
  142. /**
  143. * 查询商品SKU集合
  144. * @return false|string
  145. */
  146. public function goodsSku()
  147. {
  148. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  149. $bargain_id = isset($this->params[ 'bargain_id' ]) ? $this->params[ 'bargain_id' ] : 0;
  150. if (empty($goods_id)) {
  151. return $this->response($this->error('', 'REQUEST_ID'));
  152. }
  153. if (empty($bargain_id)) {
  154. return $this->response($this->error('', 'REQUEST_ID'));
  155. }
  156. $condition = [
  157. [ 'pb.bargain_id', '=', $bargain_id ],
  158. [ 'pbg.site_id', '=', $this->site_id ],
  159. // [ 'pbg.status', '=', 1 ],
  160. [ 'g.goods_id', '=', $goods_id ],
  161. [ 'g.goods_state', '=', 1 ],
  162. [ 'g.is_delete', '=', 0 ]
  163. ];
  164. $goods = new BargainModel();
  165. $list = $goods->getBargainGoodsSkuList($condition);
  166. foreach ($list[ 'data' ] as $k => $v) {
  167. if (!empty($v[ 'goods_spec_format' ])) {
  168. $goods_spec_format = $goods->getGoodsSpecFormat($bargain_id, $this->site_id, $v[ 'goods_spec_format' ]);
  169. $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  170. }
  171. }
  172. return $this->response($list);
  173. }
  174. /**
  175. * 【废弃】基础信息
  176. */
  177. public function info()
  178. {
  179. $sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
  180. $bargain_id = isset($this->params[ 'bargain_id' ]) ? $this->params[ 'bargain_id' ] : 0;
  181. if (empty($sku_id)) {
  182. return $this->response($this->error('', 'REQUEST_SKU_ID'));
  183. }
  184. if (empty($bargain_id)) {
  185. return $this->response($this->error('', 'REQUEST_ID'));
  186. }
  187. $goods = new BargainModel();
  188. $condition = [
  189. [ 'pbg.sku_id', '=', $sku_id ],
  190. [ 'pbg.bargain_id', '=', $bargain_id ],
  191. [ 'pbg.status', '=', 1 ],
  192. [ 'g.goods_state', '=', 1 ],
  193. [ 'g.is_delete', '=', 0 ]
  194. ];
  195. $info = $goods->getBargainGoodsDetail($condition, '');
  196. if (!empty($info[ 'data' ])) {
  197. $goods_spec_format = $goods->getGoodsSpecFormat($bargain_id, $this->site_id, $info[ 'data' ][ 'goods_spec_format' ]);
  198. $info[ 'data' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  199. } else {
  200. $sku_id = $goods->getGoodsSpecFormat($bargain_id, $this->site_id, '', $sku_id);
  201. $info = $this->success([ 'type' => 'again', 'sku_id' => $sku_id ]);
  202. }
  203. return $this->response($info);
  204. }
  205. /**
  206. * 商品海报
  207. * @return false|string
  208. */
  209. public function poster()
  210. {
  211. $this->checkToken();
  212. $promotion_type = 'bargain';
  213. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  214. $qrcode_param[ 'source_member' ] = $this->member_id;
  215. $poster = new Poster();
  216. $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
  217. return $this->response($res);
  218. }
  219. /**
  220. * 分享图片
  221. * @return false|string
  222. */
  223. public function shareImg()
  224. {
  225. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  226. $poster = new Poster();
  227. $res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
  228. return $this->response($res);
  229. }
  230. }