Goods.php 7.2 KB

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