正在显示
1 个修改的文件
包含
41 行增加
和
1 行删除
@@ -51,26 +51,66 @@ class News extends Api | @@ -51,26 +51,66 @@ 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)){ |
71 | + //不在已领取 | ||
72 | + if(!in_array($value,$gift_id)){ | ||
73 | + //不在分享券 | ||
59 | $arr[$k]['c_id'] = $value; | 74 | $arr[$k]['c_id'] = $value; |
60 | $arr[$k]['uid'] = $this->uid; | 75 | $arr[$k]['uid'] = $this->uid; |
61 | $k++; | 76 | $k++; |
62 | } | 77 | } |
63 | } | 78 | } |
79 | + } | ||
64 | $r_couponModel = new Rcoupon(); | 80 | $r_couponModel = new Rcoupon(); |
65 | $res = $r_couponModel->saveAll($arr); | 81 | $res = $r_couponModel->saveAll($arr); |
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); | 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 | + //无分享券 | ||
70 | $this->success('成功'); | 90 | $this->success('成功'); |
71 | }else{ | 91 | }else{ |
92 | + //有分享券 | ||
93 | + if($coupon_count != 1){ | ||
94 | + //一键领取多张优惠券(新人券) | ||
95 | + $this->success('优惠券中包含分享优惠券,请请分享后领取'); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + }else{ | ||
100 | + if($is_gift == 0){ | ||
101 | + //无分享券 | ||
102 | + $this->error('失败'); | ||
103 | + }else{ | ||
104 | + //有分享券 | ||
105 | + if($coupon_count == 1){ | ||
106 | + //领取单张优惠券 | ||
107 | + $this->error('该优惠券为分享优惠券,请分享后领取'); | ||
108 | + }else{ | ||
109 | + //一键领取多张优惠券(新人券) | ||
72 | $this->error('失败'); | 110 | $this->error('失败'); |
73 | } | 111 | } |
112 | + } | ||
113 | + } | ||
74 | }else{ | 114 | }else{ |
75 | $this->error('请求方式错误'); | 115 | $this->error('请求方式错误'); |
76 | } | 116 | } |
-
请 注册 或 登录 后发表评论