Topicgoods.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\topic\api\controller;
  11. use addon\topic\model\Poster;
  12. use addon\topic\model\Topic as TopicModel;
  13. use addon\topic\model\TopicGoods as TopicGoodsModel;
  14. use app\api\controller\BaseApi;
  15. use app\api\controller\Goodssku;
  16. use app\model\system\Promotion as PrmotionModel;
  17. /**
  18. * 专题活动商品
  19. */
  20. class Topicgoods extends BaseApi
  21. {
  22. /**
  23. * 详情信息
  24. */
  25. public function detail()
  26. {
  27. $id = isset($this->params[ 'topic_id' ]) ? $this->params[ 'topic_id' ] : 0;
  28. if (empty($id)) {
  29. return $this->response($this->error('', 'REQUEST_ID'));
  30. }
  31. $topic_goods_model = new TopicGoodsModel();
  32. $condition = [
  33. [ 'ptg.id', '=', $id ],
  34. [ 'pt.status', '=', 2 ]
  35. ];
  36. $goods_sku_detail = $topic_goods_model->getTopicGoodsDetail($condition)[ 'data' ];
  37. if (empty($goods_sku_detail)) return $this->response($this->error());
  38. $res[ 'goods_sku_detail' ] = $goods_sku_detail;
  39. if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
  40. $goods_spec_format = $topic_goods_model->getGoodsSpecFormat($goods_sku_detail[ 'topic_id' ], $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
  41. $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  42. }
  43. // 处理公共数据
  44. $goods_sku_api = new Goodssku();
  45. $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ]);
  46. return $this->response($this->success($res));
  47. }
  48. /**
  49. * 查询商品SKU集合
  50. * @return false|string
  51. */
  52. public function goodsSku()
  53. {
  54. $goods_id = isset($this->params[ 'goods_id' ]) ? $this->params[ 'goods_id' ] : 0;
  55. $topic_id = isset($this->params[ 'topic_id' ]) ? $this->params[ 'topic_id' ] : 0;
  56. if (empty($topic_id)) {
  57. return $this->response($this->error('', 'REQUEST_ID'));
  58. }
  59. if (empty($goods_id)) {
  60. return $this->response($this->error('', 'REQUEST_ID'));
  61. }
  62. $topic_goods_model = new TopicGoodsModel();
  63. $condition = [
  64. [ 'ptg.topic_id', '=', $topic_id ],
  65. [ 'ptg.goods_id', '=', $goods_id ],
  66. [ 'pt.status', '=', 2 ]
  67. ];
  68. $list = $topic_goods_model->getTopicGoodsSkuList($condition);
  69. if (!empty($list[ 'data' ])) {
  70. foreach ($list[ 'data' ] as $k => $v) {
  71. if (!empty($v[ 'goods_spec_format' ])) {
  72. $goods_spec_format = $topic_goods_model->getGoodsSpecFormat($v[ 'topic_id' ], $this->site_id, $v[ 'goods_spec_format' ]);
  73. $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  74. }
  75. }
  76. }
  77. return $this->response($list);
  78. }
  79. /**
  80. * 【废弃】获取商品基本信息
  81. * @return false|string
  82. */
  83. public function info()
  84. {
  85. $sku_id = isset($this->params[ 'sku_id' ]) ? $this->params[ 'sku_id' ] : 0;
  86. $topic_id = isset($this->params[ 'topic_id' ]) ? $this->params[ 'topic_id' ] : 0;
  87. if (empty($sku_id)) {
  88. return $this->response($this->error('', 'REQUEST_SKU_ID'));
  89. }
  90. if (empty($topic_id)) {
  91. return $this->response($this->error('', 'REQUEST_ID'));
  92. }
  93. $topic_goods_model = new TopicGoodsModel();
  94. $condition = [
  95. [ 'ptg.topic_id', '=', $topic_id ],
  96. [ 'ptg.sku_id', '=', $sku_id ],
  97. [ 'pt.status', '=', 2 ]
  98. ];
  99. $goods_sku_detail = $topic_goods_model->getTopicGoodsDetail($condition);
  100. $goods_sku_detail = $goods_sku_detail[ 'data' ];
  101. $res[ 'goods_sku_detail' ] = $goods_sku_detail;
  102. if (!empty($goods_sku_detail)) {
  103. $goods_spec_format = $topic_goods_model->getGoodsSpecFormat($goods_sku_detail[ 'topic_id' ], $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
  104. $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
  105. } else {
  106. $sku_id = $topic_goods_model->getGoodsSpecFormat($topic_id, $this->site_id, '', $sku_id);
  107. $res = [ 'type' => 'again', 'sku_id' => $sku_id ];
  108. }
  109. return $this->response($this->success($res));
  110. }
  111. /**
  112. * 列表信息
  113. */
  114. public function page()
  115. {
  116. $topic_id = isset($this->params[ 'topic_id' ]) ? $this->params[ 'topic_id' ] : 0;
  117. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  118. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  119. if (empty($topic_id)) {
  120. return $this->response($this->error('', 'REQUEST_TOPIC_ID'));
  121. }
  122. $condition = [
  123. [ 'nptg.topic_id', '=', $topic_id ],
  124. [ 'ngs.goods_state', '=', 1 ],
  125. [ 'ngs.is_delete', '=', 0 ],
  126. [ 'nptg.default', '=', 1 ]
  127. ];
  128. $order = 'nptg.id asc';
  129. $topic_goods_model = new TopicGoodsModel();
  130. $topic_model = new TopicModel();
  131. $info = $topic_model->getTopicInfo([ [ "topic_id", "=", $topic_id ] ], 'bg_color,topic_adv,topic_name');
  132. $info = $info[ 'data' ];
  133. $res = $topic_goods_model->getTopicGoodsPageList($condition, $page, $page_size, $order);
  134. // $res[ 'data' ][ 'bg_color' ] = $info[ 'bg_color' ];
  135. $res[ 'data' ][ 'topic_adv' ] = $info[ 'topic_adv' ];
  136. $res[ 'data' ][ 'topic_name' ] = $info[ 'topic_name' ];
  137. $promotion_model = new PrmotionModel();
  138. $zone_config = $promotion_model->getPromotionZoneConfig('topic', $this->site_id)[ 'data' ][ 'value' ];
  139. $res[ 'data' ][ 'bg_color' ] = $zone_config[ 'bg_color' ];
  140. return $this->response($res);
  141. }
  142. /**
  143. * 获取商品海报
  144. */
  145. public function poster()
  146. {
  147. $this->checkToken();
  148. $promotion_type = 'topic';
  149. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  150. $qrcode_param[ 'source_member' ] = $this->member_id;
  151. $poster = new Poster();
  152. $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
  153. return $this->response($res);
  154. }
  155. }