|
@@ -84,7 +84,7 @@ class Index extends Api
|
|
|
public function get_coupon(){
|
|
|
$coupon_id = input('coupon_id',0);
|
|
|
|
|
|
- $coupon = Db::name('unishop_coupon')->field('id,title,least,value')
|
|
|
+ $coupon = Db::name('unishop_coupon')->field('id,title,least,value,number')
|
|
|
->where('id',$coupon_id)
|
|
|
->where('deletetime',NULL)
|
|
|
->where('switch',1)
|
|
@@ -92,15 +92,17 @@ class Index extends Api
|
|
|
->where('endtime','>',time())
|
|
|
->find();
|
|
|
|
|
|
- if($coupon){
|
|
|
- $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->where('coupon_id',$coupon_id)->find();
|
|
|
- if(empty($user_coupon)){
|
|
|
- $data = [
|
|
|
+ $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->where('coupon_id',$coupon_id)->find();
|
|
|
+
|
|
|
+ if($coupon && empty($user_coupon)){
|
|
|
+ $data = [];
|
|
|
+ for($i=1;$i<=$coupon['number'];$i++){
|
|
|
+ $data[] = [
|
|
|
'coupon_id' => $coupon_id,
|
|
|
'user_id' => $this->auth->id,
|
|
|
];
|
|
|
- Db::name('unishop_coupon_user')->insertGetId($data);
|
|
|
}
|
|
|
+ Db::name('unishop_coupon_user')->insertAll($data);
|
|
|
}
|
|
|
|
|
|
$this->success('领取成功');
|