GroupGoods.php 6.2 KB
<?php

namespace app\api\controller;

use app\api\model\TeamGroup;
use app\api\model\TeamGroupInfo;
use app\common\controller\Api;
use think\Config;

/**
 * 团购商品接口
 */
class GroupGoods extends Api
{
    protected $goodsModel;
    protected $categoryModel;
    protected $keywordLogModel;

    public function _initialize()
    {
        parent::_initialize();
        $this->goodsModel = new \app\api\model\Goods;
        $this->categoryModel = new \app\api\model\Category;
        $this->keywordLogModel = new \app\api\model\KeywordLog;
    }


    /**
     * @ApiTitle    (团购商品列表(首页))
     * @ApiSummary  (团购商品列表(首页))
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/group_goods/getGroupGoodsIndex)
     * @ApiReturn({
    "code": 1,
    "msg": "请求成功",
    "time": "1587463117",
    "data": [
    {
    "goods_id": 1, 商品id
    "ch_name": "EMP精选 澳洲白肉油桃  500~540g  4只装", 中文名称
    "en_name": "EMP selected Australian white meat nectarines Australian  meat nectarines", 英文名称
    "image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
    "goods_price": "0.00", 普通售价
    "group_price": "0.00", 拼团售价 拼团售价优先级最高
    "vip_price": "0.00", 会员售价
    "country_ch_name": "意大利",  原产地中文
    "country_en_name": "Ltaly",  原产地英文
    "is_vip_price": "2", 会员特价:1=开启,2=关闭
    "stock_num": 55  库存
    }
    ]
    })
     */
    public function getGroupGoodsIndex()
    {
        $where['g.is_group'] = 1;

        $data = $this->goodsModel->selectData($where, 5,$this->lang);

        $this->success('请求成功', $data);
    }

    /**
     * @ApiTitle    (团购商品列表)
     * @ApiSummary  (团购商品列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/group_goods/getGroupGoodsList)
     * @ApiParams  (name=page, type=string, required=false, description="页数")
     * @ApiReturn({
    "code": 1,
    "msg": "请求成功",
    "time": "1587463117",
    "data": [
    {
    "goods_id": 1, 商品id
    "ch_name": "EMP精选 澳洲白肉油桃  500~540g  4只装", 中文名称
    "en_name": "EMP selected Australian white meat nectarines Australian  meat nectarines", 英文名称
    "image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
    "goods_price": "0.00", 普通售价
    "group_price": "0.00", 拼团售价 拼团售价优先级最高
    "vip_price": "0.00", 会员售价
    "country_ch_name": "意大利",  原产地中文
    "country_en_name": "Ltaly",  原产地英文
    "is_vip_price": "2", 会员特价:1=开启,2=关闭
    "stock_num": 55  库存
    }
    ]
    })
     */
    public function getGroupGoodsList()
    {
        $page = $this->request->param('page');
        $limit = Config::get('paginate.index_rows');
        $where['g.is_group'] = 1;
        $data = $this->goodsModel->selectPageData($where,$page,$limit,$this->lang);
        $this->success('请求成功', $data);
    }

    /**
     * @ApiTitle    (拼团列表)
     * @ApiSummary  (拼团列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/group_goods/getTeamList)
     * @ApiParams  (name=goods_id, type=string, required=true, description="商品id")
     * @ApiParams  (name=limit, type=string, required=false, description="条数 不传查询全部")
     * @ApiReturn({
    "code": 1,
    "msg": "请求成功",
    "time": "1587983117",
    "data":
    "is_end": 1 .剩余库存量<成团人数  开团库存不足立即开团不可选
     "list": [
    {
    "team_group_id": 2, 拼团id
    "user_avatar": "", 用户头像
    "user_nickname": "admin", 用户昵称
    "grouptime": 1588066875, 有效时间
    "group_num": 2, 拼团人数
    "num": 1 还差几人拼团成功
    }
    ]
    })
     */
    public function getTeamList()
    {
        $teamGroupModel = new TeamGroup();
        $teamGroupInfoModel = new TeamGroupInfo();
        $goods_id = $this->request->param('goods_id');
        if (!$goods_id) $this->error('缺少参数 goods_id!');
        $limit = $this->request->param('limit')?$this->request->param('limit'):'';
        $goods = $this->goodsModel->where('id',$goods_id)->field('group_num,stock_num')->find();
        if ($goods['group_num']>$goods['stock_num']) $data['is_end'] = 1;
        $list = $teamGroupModel->selectData(['goods_id'=>$goods_id],$limit);
        foreach ($list as $k=>$v){
            $count = $teamGroupInfoModel->where('team_group_id',$v['team_group_id'])->count();
            $list[$k]['num'] = $v['group_num'] - $count;
        }
        $data['list'] = $list;
        $this->success('请求成功', $data);
    }

    /**
     * @ApiTitle    (拼团详情)
     * @ApiSummary  (拼团详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/group_goods/getTeamInfo)
     * @ApiParams  (name=team_group_id, type=string, required=true, description="拼团id")
     * @ApiReturn({
    "code": 1,
    "msg": "请求成功",
    "time": "1587984522",
    "data": {
    "total": 2, 总人数
    "grouptime": 1588066875,  有效时间
    "num": 1, 目前人数
    "list": [
    {
    "id": 3,
    "team_group_id": 2,
    "user_avatar": "",
    "user_nickname": "admin"
    },
    {
    "user_avatar": "../1.jpg"
    }
    ]
    }
    })
     */
    public function getTeamInfo()
    {
        $teamGroupModel = new TeamGroup();
        $teamGroupInfoModel = new TeamGroupInfo();
        $team_group_id = $this->request->param('team_group_id');
        if (!$team_group_id) $this->error('缺少参数 team_group_id!');
        $team = $teamGroupModel->where('id',$team_group_id)->field('group_num,grouptime')->find();
        $list = $teamGroupInfoModel->selectData(['team_group_id'=>$team_group_id]);
        $newList = [];
        for ($i=0;$i<$team['group_num'];$i++){
            if (!empty($list[$i])) $newList[$i] = $list[$i];
            else $newList[$i]['user_avatar'] = cdnurl(config('site.team_default_avatar')) ; //默认头像
        }
        $data['total'] = $team['group_num'];
        $data['grouptime'] = $team['grouptime'];
        $data['num'] = count($list);
        $data['list'] = $newList;
        $this->success('请求成功', $data);
    }
}