作者 jinglong
1 个管道 的构建 通过 耗费 3 秒

修改优惠券接口

... ... @@ -386,7 +386,7 @@ class Cars extends Api
$goods_id_s = explode(',',$goods_id);
//查询商品所属品牌id
$res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1],],'id,t_id');
$res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1]],'id,t_id');
$b_id_s = array_unique(array_values(array_column($res1,'t_id')));
//包含品牌中的商品
... ... @@ -402,7 +402,6 @@ class Cars extends Api
$time = time();
$where['id'] = ['in',$receive_s];
$where['is_use'] = $flag[0];
$where['end_time'] = ['>',$time];
$data = Common::selectWhereOrData('coupon',$where,$where1,$where2,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
... ...
... ... @@ -67,7 +67,7 @@ class Coupons extends Api
}
$flag = config('verify.flag');
$where = ['is_new'=>$flag[0],'coupon_number'=>['<>',0],'end_time'=>['>',time()]];
$where = ['is_new'=>$flag[0],'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
... ... @@ -240,7 +240,6 @@ class Coupons extends Api
* @ApiRoute (/api/coupons/goodsCouponList)
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
* @ApiParams (name="is_flag", type="inter", required=true, description="优惠券标识(0:未使用,1:已使用,2:已过期)")
*
* @ApiReturn({
"code": 1,
... ... @@ -252,18 +251,20 @@ class Coupons extends Api
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_name": "全场优惠券",//优惠券名称
"end_time": "2020.1.31",//优惠券有效期
"coupon_number": 100,//优惠券剩余数量(0:领光了)
"type": "全场通用"//优惠券用途
},
{
"id": 10,
"coupon_tag": "折扣券",
"coupon_price": "9.5折",
"coupon_tag1": "满2000可用",
"coupon_name": "商品优惠券",
"end_time": "2020.1.31",
"type": "商品可用"
"id": 2,//优惠券id
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_name": "全场优惠券",//优惠券名称
"coupon_number": 100,//优惠券剩余数量(0:领光了)
"type": "全场通用"//优惠券用途
}
]
})
... ... @@ -271,35 +272,21 @@ class Coupons extends Api
public function goodsCouponList(){
if($this->request->isGet()){
$goods_id = $this->request->get('goods_id');
$is_flag = $this->request->get('is_flag');
$rule = config('verify.goods_coupon');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id,'is_flag'=>$is_flag])) {
if (!$validate->check(['goods_id'=>$goods_id])) {
$this->error($validate->getError());
}
$type = config('verify.type');
$where = ['type'=>$type[2],'bg_id'=>$goods_id,'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$type = config('verify.type');
$flag = config('verify.flag');
//不显示没有库存的优惠券
$where = ['is_new'=>$flag[0],'type'=>$type[2],'bg_id'=>$goods_id,'coupon_number'=>['<>',0]];
if($is_flag == 0){
//未使用
$where['id'] = ['not in',$receive_s];
$where['end_time'] = ['>',time()];
}else if($is_flag == 1){
//已使用
$where['id'] = ['in',$receive_s];
$where['end_time'] = ['>',time()];
}else{
//已过期
$where['end_time'] = ['<',time()];
}
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number','c_type asc,coupon_type desc');
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
... ... @@ -338,9 +325,23 @@ class Coupons extends Api
}
}
$res[$key]['is_receive'] = 0;//未领取
if(in_array($value['id'],$receive_s)){
$res[$key]['is_receive'] = 1;//已领取
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
$res[$key]['type'] = '商品可用';
$res[$key]['coupon_number'] = $value['coupon_number'];//优惠券剩余数量
//全场,品牌,商品
if($value['type'] == 0){
$res[$key]['type'] = '全场通用';
}else if($value['type'] == 1){
$res[$key]['type'] = '部分品牌可用';
}else{
$res[$key]['type'] = '部分商品可用';
}
}
$this->success('成功',$res);
}else{
... ...
... ... @@ -333,7 +333,8 @@ class User extends Api
* @ApiSummary (我的优惠券)
* @ApiMethod (GET)
* @ApiRoute (/api/user/myCouponList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="is_flag", type="inter", required=true, description="优惠券标识(0:未使用,1:已使用,2:已过期)")
*
* @ApiReturn({
"code": 1,
... ... @@ -363,14 +364,33 @@ class User extends Api
*/
public function myCouponList(){
if($this->request->isGet()){
//查询已经领取过
$is_flag = $this->request->get('is_flag');
$rule = config('verify.my_coupon');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['is_flag'=>$is_flag])) {
$this->error($validate->getError());
}
$flag = config('verify.flag');
$where['uid'] = $this->uid;
if($is_flag == 0){
//未使用
$where['is_use'] = $flag[0];
$where1['end_time'] = ['>',time()];
}else if($is_flag == 1){
//已使用
$where['is_use'] = $flag[1];
$where1['end_time'] = ['>',time()];
}else{
//已过期
$where1['end_time'] = ['<',time()];
}
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid,'is_use'=>$flag[0]],'id,c_id');
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',$where,'id,c_id');
$receive_s = array_column($receive,'c_id');
$where['id'] = ['in',$receive_s];
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
$where1['id'] = ['in',$receive_s];
$data = Common::selectWhereData('coupon',$where1,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
$res = [];
foreach($data as $key=>$value){
... ...
... ... @@ -221,11 +221,18 @@ return [
'goods_coupon' => [
'rule' => [
'goods_id' => 'require|number',
'is_flag' => 'require|number',
],
'msg' => [
'goods_id.require' => '商品id不能为空',
'goods_id.number' => '商品id必须为数字',
]
],
//我的优惠券
'my_coupon' => [
'rule' => [
'is_flag' => 'require|number',
],
'msg' => [
'is_flag.require' => '优惠券标识不能为空',
'is_flag.number' => '优惠券标识必须为数字',
]
... ...
... ... @@ -1892,12 +1892,6 @@
<td></td>
<td>商品id</td>
</tr>
<tr>
<td>is_flag</td>
<td>inter</td>
<td></td>
<td>优惠券标识(0:未使用,1:已使用,2:已过期)</td>
</tr>
</tbody>
</table>
</div>
... ... @@ -1921,10 +1915,6 @@
<input type="inter" class="form-control input-sm" id="goods_id" required placeholder="商品id" name="goods_id">
</div>
<div class="form-group">
<label class="control-label" for="is_flag">is_flag</label>
<input type="inter" class="form-control input-sm" id="is_flag" required placeholder="优惠券标识(0:未使用,1:已使用,2:已过期)" name="is_flag">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="11">提交</button>
<button type="reset" class="btn btn-info" rel="11">重置</button>
</div>
... ... @@ -1965,18 +1955,20 @@
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_name": "全场优惠券",//优惠券名称
"end_time": "2020.1.31",//优惠券有效期
"coupon_number": 100,//优惠券剩余数量(0:领光了)
"type": "全场通用"//优惠券用途
},
{
"id": 10,
"coupon_tag": "折扣券",
"coupon_price": "9.5折",
"coupon_tag1": "满2000可用",
"coupon_name": "商品优惠券",
"end_time": "2020.1.31",
"type": "商品可用"
"id": 2,//优惠券id
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_name": "全场优惠券",//优惠券名称
"coupon_number": 100,//优惠券剩余数量(0:领光了)
"type": "全场通用"//优惠券用途
}
]
}</pre>
... ... @@ -5444,6 +5436,12 @@
<div class="panel panel-default">
<div class="panel-heading"><strong>Headers</strong></div>
<div class="panel-body">
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
... ... @@ -5455,22 +5453,16 @@
</thead>
<tbody>
<tr>
<td>token</td>
<td>string</td>
<td>is_flag</td>
<td>inter</td>
<td></td>
<td>请求的Token</td>
<td>优惠券标识(0:未使用,1:已使用,2:已过期)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>正文</strong></div>
<div class="panel-body">
</div>
... ... @@ -5481,22 +5473,12 @@
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading"><strong>Headers</strong></div>
<div class="panel-body">
<div class="headers">
<div class="form-group">
<label class="control-label" for="token">token</label>
<input type="string" class="form-control input-sm" id="token" required placeholder="请求的Token - Ex: " name="token">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
<form enctype="application/x-www-form-urlencoded" role="form" action="/api/user/myCouponList" method="GET" name="form34" id="form34">
<div class="form-group">
<label class="control-label" for="is_flag">is_flag</label>
<input type="inter" class="form-control input-sm" id="is_flag" required placeholder="优惠券标识(0:未使用,1:已使用,2:已过期)" name="is_flag">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="34">提交</button>
... ... @@ -5568,7 +5550,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2019-12-04 16:13:54 </div>
Generated on 2019-12-04 18:04:40 </div>
<div class="col-md-6" align="right">
<a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>
</div>
... ...
... ... @@ -26,7 +26,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'order_sn', title: __('Order_sn')},
{field: 'status', title: __('Status')},
{field: 'status', title: __('Status'),searchList: {0: __('待付款'), 1: __('已取消'),2: __('待发货'), 3: __('退款申请中'),4: __('已退款'), 5: __('待收货'),6: __('已退换货'), 7: __('已完成')},formatter:Table.api.formatter.label},
{field: 'receive_name', title: __('Receive_name')},
{field: 'receive_mobile', title: __('Receive_mobile')},
{field: 'receive_address', title: __('Receive_address')},
... ...