| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace addon\blindbox\api\controller;
- use app\api\controller\BaseApi;
- use addon\blindbox\model\BlindboxCategory as BlindboxCategoryModel;
- use addon\blindbox\model\Blindbox as BlindboxModel;
- use addon\blindbox\model\BlindboxGoods as BlindboxGoodsModel;
- use app\model\member\Member;
- use app\model\goods\Goods as GoodsModel;
- /**
- * 盲盒商品
- * Class Goods
- * @package addon\blindbox\api\controller
- */
- class Goods extends BaseApi
- {
- /**
- *获取展示的盲盒分类
- */
- public function categoryList()
- {
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'status', '=', 1 ],
- ];
- $category_model = new BlindboxCategoryModel();
- $data = $category_model->getBlindboxCategoryList($condition);
- return $this->response($data);
- }
- /**
- * 获取盲盒活动列表
- */
- public function page()
- {
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
- $category_id = $this->params[ 'category_id' ] ?? 0;
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'blindbox_status', '=', 1 ],
- ];
- if ($category_id) {
- $condition[] = [ 'category_id', '=', $category_id ];
- }
- $blindbox_model = new BlindboxModel();
- $data = $blindbox_model->getBlindboxPageList($condition, $page, $page_size, 'sort asc,create_time desc');
- return $this->response($data);
- }
- /**
- * 盲盒(系列)详情
- */
- public function info()
- {
- $token = $this->checkToken();
- $blindbox_id = $this->params[ 'blindbox_id' ] ?? 0;
- if (empty($blindbox_id)) return $this->response($this->error('', '缺少参数'));
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'blindbox_status', '=', 1 ],
- [ 'blindbox_id', '=', $blindbox_id ]
- ];
- $blindbox_model = new BlindboxModel();
- $data = $blindbox_model->getBlindboxInfo($condition);
- if ($data[ 'data' ]) {
- $goods_model = new BlindboxGoodsModel();
- $goods_list = $goods_model->getBlindboxGoodsList([ [ 'a.site_id', '=', $this->site_id ], [ 'a.blindbox_id', '=', $blindbox_id ] ])[ 'data' ] ?? [];
- $checked_goods = [];
- #是否新人
- $is_new = 0;
- if ($goods_list) {
- foreach ($goods_list as $k => $v) {
- if (!isset($checked_goods[ $v[ 'goods_id' ] ])) {
- $checked_goods[ $v[ 'goods_id' ] ] = $v;
- }
- }
- $goods_ids = array_column($checked_goods, 'goods_id');
- $goods_model = new GoodsModel();
- $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' ] ?? [];
- $member_arr = array_column($goods_list, 'member_id');
- if ($this->member_id) {
- if (in_array($this->member_id, $member_arr)) {
- #不是新人
- $is_new = 1;
- }
- $member_model = new Member();
- $member_info_result = $member_model->getMemberDetail($this->member_id, $this->site_id)[ 'data' ] ?? [];
- $data[ 'data' ][ 'member_info' ] = $member_info_result;
- }
- }
- #盒子内的商品
- $data[ 'data' ][ 'goods_list' ] = $goods_data;
- $data[ 'data' ][ 'is_new' ] = $is_new;
- }
- return $this->response($data);
- }
- /**
- * 盲盒下的盒子
- * @return false|string
- */
- public function boxPage()
- {
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? 6;
- $blindbox_id = $this->params[ 'blindbox_id' ] ?? 0;
- if (empty($blindbox_id)) return $this->response($this->error('', '缺少参数'));
- #获取盲盒下所有盒子
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'blindbox_status', '=', 1 ],
- [ 'blindbox_id', '=', $blindbox_id ]
- ];
- $blindbox_model = new BlindboxModel();
- $data = $blindbox_model->getBlindboxInfo($condition)[ 'data' ] ?? [];
- if (empty($data)) return $this->response($this->error('', '暂无数据'));
- $box_condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'blindbox_id', '=', $blindbox_id ],
- ];
- if ($data[ 'is_emptybox' ] == 2) {
- $box_condition[] = [ 'a.status', '=', 0 ];
- }
- $goods_model = new BlindboxGoodsModel();
- $box_list = $goods_model->getBlindboxGoodsPageList($box_condition, $page, $page_size, 'sort desc', 'id,blindbox_id,status,create_time');
- $box_list[ 'data' ][ 'page' ] = $page;
- return $this->response($box_list);
- }
- }
|