...
|
...
|
@@ -51,14 +51,30 @@ class News extends Api |
|
|
$receive_s = array_column($receive,'c_id');
|
|
|
|
|
|
$coupon_id_s = explode(',',$coupon_id);
|
|
|
$coupon_count = count($coupon_id_s);
|
|
|
$gift = Common::selectWhereData('coupon',['id'=>['in',$coupon_id_s]],'id,gift');
|
|
|
//判断该优惠券是否属于分享优惠券
|
|
|
$is_gift = 0;
|
|
|
$gift_id = [];
|
|
|
foreach($gift as $g_value){
|
|
|
if($g_value['gift'] != 0){
|
|
|
//分享券
|
|
|
$is_gift = 1;
|
|
|
array_push($gift_id,$g_value['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++;
|
|
|
//不在已领取
|
|
|
if(!in_array($value,$gift_id)){
|
|
|
//不在分享券
|
|
|
$arr[$k]['c_id'] = $value;
|
|
|
$arr[$k]['uid'] = $this->uid;
|
|
|
$k++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$r_couponModel = new Rcoupon();
|
...
|
...
|
@@ -66,10 +82,34 @@ class News extends Api |
|
|
if($res){
|
|
|
//减优惠券数量
|
|
|
$couponModel = new Coupon();
|
|
|
$couponModel->whereIn('id',$coupon_id_s)->setDec('coupon_number',1);
|
|
|
$this->success('成功');
|
|
|
//获取已领取的优惠券id
|
|
|
$receive_coupon_id = array_column($arr,'c_id');
|
|
|
$couponModel->whereIn('id',$receive_coupon_id)->setDec('coupon_number',1);
|
|
|
if($is_gift == 0){
|
|
|
//无分享券
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
//有分享券
|
|
|
if($coupon_count != 1){
|
|
|
//一键领取多张优惠券(新人券)
|
|
|
$this->success('优惠券中包含分享优惠券,请请分享后领取');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
$this->error('失败');
|
|
|
if($is_gift == 0){
|
|
|
//无分享券
|
|
|
$this->error('失败');
|
|
|
}else{
|
|
|
//有分享券
|
|
|
if($coupon_count == 1){
|
|
|
//领取单张优惠券
|
|
|
$this->error('该优惠券为分享优惠券,请分享后领取');
|
|
|
}else{
|
|
|
//一键领取多张优惠券(新人券)
|
|
|
$this->error('失败');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
...
|
...
|
|