Goods.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\pintuan\api\controller;
  11. use addon\pintuan\model\Pintuan as PintuanModel;
  12. use addon\pintuan\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 info()
  24. {
  25. $sku_id = $this->params[ 'sku_id' ] ?? 0;
  26. $pintuan_id = $this->params[ 'pintuan_id' ] ?? 0;
  27. $pintuan_num = $this->params[ 'pintuan_num' ] ?? 0;
  28. if (empty($sku_id)) {
  29. return $this->response($this->error('', 'REQUEST_SKU_ID'));
  30. }
  31. if (empty($pintuan_id)) {
  32. return $this->response($this->error('', 'REQUEST_PINTUAN_ID'));
  33. }
  34. $pintuan_model = new PintuanModel();
  35. $condition = [
  36. [ 'ppg.sku_id', '=', $sku_id ],
  37. [ 'ppg.pintuan_id', '=', $pintuan_id ],
  38. [ 'pp.status', '=', 1 ],
  39. [ 'g.goods_state', '=', 1 ],
  40. [ 'g.is_delete', '=', 0 ]
  41. ];
  42. $info = $pintuan_model->getPintuanGoodsDetail($condition, '')[ 'data' ] ?? [];
  43. $params = $info;
  44. if ($params[ 'pintuan_type' ] == 'ladder') {
  45. $params[ 'pintuan_ladder' ] = $pintuan_num;
  46. $price = $pintuan_model->getPintuanPrice($params);
  47. $info[ 'pintuan_price' ] = $price;
  48. }
  49. if (!empty($info)) {
  50. if (!empty($info[ 'goods_spec_format' ])) {
  51. $goods_spec_format = $pintuan_model->getGoodsSpecFormat($pintuan_id, $this->site_id, $info[ 'goods_spec_format' ]);
  52. $info[ 'goods_spec_format' ] = json_encode($goods_spec_format);
  53. }
  54. } else {
  55. $sku_id = $pintuan_model->getGoodsSpecFormat($pintuan_id, $this->site_id, '', $sku_id);
  56. $info = [ 'type' => 'again', 'sku_id' => $sku_id ];
  57. }
  58. return $this->response($this->success($info));
  59. }
  60. /**
  61. * 拼团商品详情信息
  62. */
  63. public function detail()
  64. {
  65. $pintuan_id = isset($this->params[ 'pintuan_id' ]) ? $this->params[ 'pintuan_id' ] : 0;
  66. if (empty($pintuan_id)) {
  67. return $this->response($this->error('', 'REQUEST_ID'));
  68. }
  69. $pintuan_model = new PintuanModel();
  70. $condition = [
  71. [ 'ppg.pintuan_id', '=', $pintuan_id ],
  72. [ 'ppg.site_id', '=', $this->site_id ],
  73. [ 'pp.status', '=', 1 ],
  74. [ 'g.goods_state', '=', 1 ],
  75. [ 'g.is_delete', '=', 0 ]
  76. ];
  77. $goods_sku_detail = $pintuan_model->getPintuanGoodsDetail($condition, '')[ 'data' ];
  78. if (empty($goods_sku_detail)) return $this->response($this->error());
  79. $res[ 'goods_sku_detail' ] = $goods_sku_detail;
  80. if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
  81. //判断商品规格项
  82. $goods_spec_format = $pintuan_model->getGoodsSpecFormat($pintuan_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
  83. $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  84. }
  85. // 处理公共数据
  86. $goods_sku_api = new Goodssku();
  87. $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ]);
  88. return $this->response($this->success($res));
  89. }
  90. /**
  91. * 查询商品SKU集合
  92. * @return false|string
  93. */
  94. public function goodsSku()
  95. {
  96. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  97. $pintuan_id = isset($this->params[ 'pintuan_id' ]) ? $this->params[ 'pintuan_id' ] : 0;
  98. $pintuan_num = $this->params[ 'pintuan_num' ] ?? 0;
  99. if (empty($goods_id)) {
  100. return $this->response($this->error('', 'REQUEST_ID'));
  101. }
  102. if (empty($pintuan_id)) {
  103. return $this->response($this->error('', 'REQUEST_ID'));
  104. }
  105. $pintuan_model = new PintuanModel();
  106. $condition = [
  107. [ 'ppg.pintuan_id', '=', $pintuan_id ],
  108. [ 'ppg.site_id', '=', $this->site_id ],
  109. [ 'pp.status', '=', 1 ],
  110. [ 'g.goods_id', '=', $goods_id ],
  111. [ 'g.goods_state', '=', 1 ],
  112. [ 'g.is_delete', '=', 0 ]
  113. ];
  114. $list = $pintuan_model->getPintuanGoodsSkuList($condition);
  115. foreach ($list[ 'data' ] as $k => $v) {
  116. if ($v[ 'pintuan_type' ] == 'ladder') {
  117. $v[ 'pintuan_ladder' ] = $pintuan_num;
  118. $price = $pintuan_model->getPintuanPrice($v);
  119. $list[ 'data' ][ $k ][ 'pintuan_price' ] = $price;
  120. }
  121. if (!empty($v[ 'goods_spec_format' ])) {
  122. $goods_spec_format = $pintuan_model->getGoodsSpecFormat($pintuan_id, $this->site_id, $v[ 'goods_spec_format' ]);
  123. $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  124. }
  125. }
  126. return $this->response($list);
  127. }
  128. public function page()
  129. {
  130. $site_id = $this->site_id;
  131. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  132. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  133. $goods_id_arr = isset($this->params[ 'goods_id_arr' ]) ? $this->params[ 'goods_id_arr' ] : '';//goods_id数组
  134. $condition = [
  135. [ 'pp.status', '=', 1 ],// 状态(0正常 1活动进行中 2活动已结束 3失效 4删除)
  136. [ 'g.goods_stock', '>', 0 ],
  137. [ 'g.goods_state', '=', 1 ],
  138. [ 'g.is_delete', '=', 0 ],
  139. [ 'g.site_id', '=', $site_id ]
  140. ];
  141. if (!empty($goods_id_arr)) {
  142. $condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
  143. }
  144. $pintuan_model = new PintuanModel();
  145. $list = $pintuan_model->getPintuanGoodsPageList($condition, $page, $page_size, 'pp.pintuan_id desc');
  146. return $this->response($list);
  147. }
  148. public function lists()
  149. {
  150. $site_id = $this->site_id;
  151. $num = isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : null;
  152. $goods_id_arr = isset($this->params[ 'goods_id_arr' ]) ? $this->params[ 'goods_id_arr' ] : '';//goods_id数组
  153. $condition = [
  154. [ 'pp.status', '=', 1 ],// 状态(0正常 1活动进行中 2活动已结束 3失效 4删除)
  155. [ 'g.goods_stock', '>', 0 ],
  156. [ 'g.goods_state', '=', 1 ],
  157. [ 'g.is_delete', '=', 0 ],
  158. [ 'g.site_id', '=', $site_id ]
  159. ];
  160. if (!empty($goods_id_arr)) {
  161. $condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
  162. }
  163. $pintuan_model = new PintuanModel();
  164. $list = $pintuan_model->getPintuanList($condition, '', 'pp.pintuan_id desc', $num);
  165. return $this->response($list);
  166. }
  167. /**
  168. * 获取商品海报
  169. */
  170. public function poster()
  171. {
  172. $this->checkToken();
  173. $promotion_type = 'pintuan';
  174. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  175. $qrcode_param[ 'source_member' ] = $this->member_id;
  176. $poster = new Poster();
  177. $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
  178. return $this->response($res);
  179. }
  180. /**
  181. * 分享图片
  182. * @return false|string
  183. */
  184. public function shareImg()
  185. {
  186. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  187. $poster = new Poster();
  188. $res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
  189. return $this->response($res);
  190. }
  191. }