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

修改领取优惠券接口

@@ -51,14 +51,30 @@ class News extends Api @@ -51,14 +51,30 @@ class News extends Api
51 $receive_s = array_column($receive,'c_id'); 51 $receive_s = array_column($receive,'c_id');
52 52
53 $coupon_id_s = explode(',',$coupon_id); 53 $coupon_id_s = explode(',',$coupon_id);
  54 + $coupon_count = count($coupon_id_s);
  55 + $gift = Common::selectWhereData('coupon',['id'=>['in',$coupon_id_s]],'id,gift');
  56 + //判断该优惠券是否属于分享优惠券
  57 + $is_gift = 0;
  58 + $gift_id = [];
  59 + foreach($gift as $g_value){
  60 + if($g_value['gift'] != 0){
  61 + //分享券
  62 + $is_gift = 1;
  63 + array_push($gift_id,$g_value['id']);
  64 + }
  65 + }
54 $arr = []; 66 $arr = [];
55 $k = 0; 67 $k = 0;
56 foreach($coupon_id_s as $value){ 68 foreach($coupon_id_s as $value){
57 $k+=0; 69 $k+=0;
58 if(!in_array($value,$receive_s)){ 70 if(!in_array($value,$receive_s)){
59 - $arr[$k]['c_id'] = $value;  
60 - $arr[$k]['uid'] = $this->uid;  
61 - $k++; 71 + //不在已领取
  72 + if(!in_array($value,$gift_id)){
  73 + //不在分享券
  74 + $arr[$k]['c_id'] = $value;
  75 + $arr[$k]['uid'] = $this->uid;
  76 + $k++;
  77 + }
62 } 78 }
63 } 79 }
64 $r_couponModel = new Rcoupon(); 80 $r_couponModel = new Rcoupon();
@@ -66,10 +82,34 @@ class News extends Api @@ -66,10 +82,34 @@ class News extends Api
66 if($res){ 82 if($res){
67 //减优惠券数量 83 //减优惠券数量
68 $couponModel = new Coupon(); 84 $couponModel = new Coupon();
69 - $couponModel->whereIn('id',$coupon_id_s)->setDec('coupon_number',1);  
70 - $this->success('成功'); 85 + //获取已领取的优惠券id
  86 + $receive_coupon_id = array_column($arr,'c_id');
  87 + $couponModel->whereIn('id',$receive_coupon_id)->setDec('coupon_number',1);
  88 + if($is_gift == 0){
  89 + //无分享券
  90 + $this->success('成功');
  91 + }else{
  92 + //有分享券
  93 + if($coupon_count != 1){
  94 + //一键领取多张优惠券(新人券)
  95 + $this->success('优惠券中包含分享优惠券,请请分享后领取');
  96 + }
  97 + }
  98 +
71 }else{ 99 }else{
72 - $this->error('失败'); 100 + if($is_gift == 0){
  101 + //无分享券
  102 + $this->error('失败');
  103 + }else{
  104 + //有分享券
  105 + if($coupon_count == 1){
  106 + //领取单张优惠券
  107 + $this->error('该优惠券为分享优惠券,请分享后领取');
  108 + }else{
  109 + //一键领取多张优惠券(新人券)
  110 + $this->error('失败');
  111 + }
  112 + }
73 } 113 }
74 }else{ 114 }else{
75 $this->error('请求方式错误'); 115 $this->error('请求方式错误');