GroupGoods.php
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?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);
}
}