Goods.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\blindbox\api\controller;
  11. use app\api\controller\BaseApi;
  12. use addon\blindbox\model\BlindboxCategory as BlindboxCategoryModel;
  13. use addon\blindbox\model\Blindbox as BlindboxModel;
  14. use addon\blindbox\model\BlindboxGoods as BlindboxGoodsModel;
  15. use app\model\member\Member;
  16. use app\model\goods\Goods as GoodsModel;
  17. /**
  18. * 盲盒商品
  19. * Class Goods
  20. * @package addon\blindbox\api\controller
  21. */
  22. class Goods extends BaseApi
  23. {
  24. /**
  25. *获取展示的盲盒分类
  26. */
  27. public function categoryList()
  28. {
  29. $condition = [
  30. [ 'site_id', '=', $this->site_id ],
  31. [ 'status', '=', 1 ],
  32. ];
  33. $category_model = new BlindboxCategoryModel();
  34. $data = $category_model->getBlindboxCategoryList($condition);
  35. return $this->response($data);
  36. }
  37. /**
  38. * 获取盲盒活动列表
  39. */
  40. public function page()
  41. {
  42. $page = $this->params[ 'page' ] ?? 1;
  43. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  44. $category_id = $this->params[ 'category_id' ] ?? 0;
  45. $condition = [
  46. [ 'site_id', '=', $this->site_id ],
  47. [ 'blindbox_status', '=', 1 ],
  48. ];
  49. if ($category_id) {
  50. $condition[] = [ 'category_id', '=', $category_id ];
  51. }
  52. $blindbox_model = new BlindboxModel();
  53. $data = $blindbox_model->getBlindboxPageList($condition, $page, $page_size, 'sort asc,create_time desc');
  54. return $this->response($data);
  55. }
  56. /**
  57. * 盲盒(系列)详情
  58. */
  59. public function info()
  60. {
  61. $token = $this->checkToken();
  62. $blindbox_id = $this->params[ 'blindbox_id' ] ?? 0;
  63. if (empty($blindbox_id)) return $this->response($this->error('', '缺少参数'));
  64. $condition = [
  65. [ 'site_id', '=', $this->site_id ],
  66. [ 'blindbox_status', '=', 1 ],
  67. [ 'blindbox_id', '=', $blindbox_id ]
  68. ];
  69. $blindbox_model = new BlindboxModel();
  70. $data = $blindbox_model->getBlindboxInfo($condition);
  71. if ($data[ 'data' ]) {
  72. $goods_model = new BlindboxGoodsModel();
  73. $goods_list = $goods_model->getBlindboxGoodsList([ [ 'a.site_id', '=', $this->site_id ], [ 'a.blindbox_id', '=', $blindbox_id ] ])[ 'data' ] ?? [];
  74. $checked_goods = [];
  75. #是否新人
  76. $is_new = 0;
  77. if ($goods_list) {
  78. foreach ($goods_list as $k => $v) {
  79. if (!isset($checked_goods[ $v[ 'goods_id' ] ])) {
  80. $checked_goods[ $v[ 'goods_id' ] ] = $v;
  81. }
  82. }
  83. $goods_ids = array_column($checked_goods, 'goods_id');
  84. $goods_model = new GoodsModel();
  85. $goods_data = $goods_model->getGoodsList([ [ 'goods_id', 'in', $goods_ids ], [ 'site_id', '=', $this->site_id ] ], 'goods_id,goods_name,goods_image,price,market_price,sku_id')[ 'data' ] ?? [];
  86. $member_arr = array_column($goods_list, 'member_id');
  87. if ($this->member_id) {
  88. if (in_array($this->member_id, $member_arr)) {
  89. #不是新人
  90. $is_new = 1;
  91. }
  92. $member_model = new Member();
  93. $member_info_result = $member_model->getMemberDetail($this->member_id, $this->site_id)[ 'data' ] ?? [];
  94. $data[ 'data' ][ 'member_info' ] = $member_info_result;
  95. }
  96. }
  97. #盒子内的商品
  98. $data[ 'data' ][ 'goods_list' ] = $goods_data;
  99. $data[ 'data' ][ 'is_new' ] = $is_new;
  100. }
  101. return $this->response($data);
  102. }
  103. /**
  104. * 盲盒下的盒子
  105. * @return false|string
  106. */
  107. public function boxPage()
  108. {
  109. $page = $this->params[ 'page' ] ?? 1;
  110. $page_size = $this->params[ 'page_size' ] ?? 6;
  111. $blindbox_id = $this->params[ 'blindbox_id' ] ?? 0;
  112. if (empty($blindbox_id)) return $this->response($this->error('', '缺少参数'));
  113. #获取盲盒下所有盒子
  114. $condition = [
  115. [ 'site_id', '=', $this->site_id ],
  116. [ 'blindbox_status', '=', 1 ],
  117. [ 'blindbox_id', '=', $blindbox_id ]
  118. ];
  119. $blindbox_model = new BlindboxModel();
  120. $data = $blindbox_model->getBlindboxInfo($condition)[ 'data' ] ?? [];
  121. if (empty($data)) return $this->response($this->error('', '暂无数据'));
  122. $box_condition = [
  123. [ 'site_id', '=', $this->site_id ],
  124. [ 'blindbox_id', '=', $blindbox_id ],
  125. ];
  126. if ($data[ 'is_emptybox' ] == 2) {
  127. $box_condition[] = [ 'a.status', '=', 0 ];
  128. }
  129. $goods_model = new BlindboxGoodsModel();
  130. $box_list = $goods_model->getBlindboxGoodsPageList($box_condition, $page, $page_size, 'sort desc', 'id,blindbox_id,status,create_time');
  131. $box_list[ 'data' ][ 'page' ] = $page;
  132. return $this->response($box_list);
  133. }
  134. }