News.php
8.1 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
namespace app\api\controller;
use app\admin\model\Coupon;
use app\admin\model\Rcoupon;
use app\admin\model\Record;
use app\common\controller\Api;
use think\Validate;
/**
* 新人特惠接口
*/
class News extends Api
{
protected $noNeedLogin = ['newsCouponList','newsGoodsList'];
protected $noNeedRight = ['*'];
protected $uid = '';
public function _initialize()
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
}
/**
* @ApiTitle (领取优惠券)
* @ApiSummary (领取优惠券)
* @ApiMethod (POST)
* @ApiRoute (/api/news/receiveAllCoupon)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="coupon_id", type="string", required=true, description="优惠券id(多个以逗号隔开)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575358991",
"data": null
})
*/
public function receiveAllCoupon(){
if($this->request->isPost()){
$coupon_id = $this->request->post('coupon_id');
$rule = config('verify.receive_coupon');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['coupon_id'=>$coupon_id])) {
$this->error($validate->getError());
}
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$coupon_id_s = explode(',',$coupon_id);
$arr = [];
$k = 0;
foreach($coupon_id_s as $value){
$k+=0;
if(!in_array($value,$receive_s)){
$arr[$k]['c_id'] = $value;
$arr[$k]['uid'] = $this->uid;
$k++;
}
}
$r_couponModel = new Rcoupon();
$res = $r_couponModel->saveAll($arr);
if($res){
//减优惠券数量
$couponModel = new Coupon();
$couponModel->whereIn('id',$coupon_id_s)->setDec('coupon_number',1);
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (新人专享礼包)
* @ApiSummary (新人专享礼包)
* @ApiMethod (GET)
* @ApiRoute (/api/news/newsCouponList)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575352892",
"data":[
{
"id": 4,//优惠券id
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_tag": "无门槛",//优惠券(无门槛或满减金额)
"coupon_price": "8.5折"//(折扣或减少金额)
},
{
"id": 2,
"coupon_tag": "无门槛",
"coupon_price": "¥300"
},
{
"id": 1,
"coupon_tag": "满1000可用",
"coupon_price": "¥200"
}
]
})
*/
public function newsCouponList(){
if($this->request->isGet()){
$flag = config('verify.flag');
$where = ['is_new'=>$flag[1],'coupon_number'=>['<>',0],'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$data = Common::selectWhereData('coupon',$where,'id,c_type,coupon_type,full_reduce,reduce,discount','sort desc,id desc');
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
$res[$key]['is_receive'] = 0;//未领取
if(in_array($value['id'],$receive_s)){
$res[$key]['is_receive'] = 1;//已领取
}
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (新人特惠商品列表)
* @ApiSummary (新人特惠商品列表)
* @ApiMethod (GET)
* @ApiRoute (/api/news/newsGoodsList)
*
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
"is_new_tag": 0//新人价格标签(0:不显示,1:显示)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function newsGoodsList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('verify.page');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$flag = config('verify.flag');
$where = ['is_new'=>$flag[1]];
$limit = config('verify.goods_limit');
$arr = Common::goodsList($where,$page,$this->uid,$limit);
$this->success('成功',$arr);
}else{
$this->error('请求方式错误');
}
}
}