|
@@ -71,6 +71,8 @@ class CouponService extends BaseService
|
|
|
if($time){
|
|
|
$query->where('start_time','<=', time())
|
|
|
->where('end_time','>=', time());
|
|
|
+
|
|
|
+ $query->whereRaw('received_num < num');
|
|
|
}
|
|
|
|
|
|
$merchId = isset($params['merch_id'])? $params['merch_id'] : 0;
|
|
@@ -202,9 +204,11 @@ class CouponService extends BaseService
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ $query->whereRaw('received_num < num');
|
|
|
+
|
|
|
$query->where('start_time','<=', time())
|
|
|
->where('end_time','>=', time());
|
|
|
- })->count('id');
|
|
|
+ })->count('sid');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -241,7 +245,7 @@ class CouponService extends BaseService
|
|
|
$info = $this->model->where(['id'=> $id,'mark'=>1,'status'=>1])
|
|
|
->where('start_time','<=', time())
|
|
|
->where('end_time','>=', time())
|
|
|
- ->select(['id as coupon_id','name','coupon_type','reduce_price','discount','min_price','expire_day','start_time','end_time','apply_merch_ids'])
|
|
|
+ ->select(['id as coupon_id','name','num','received_num','coupon_type','reduce_price','discount','min_price','expire_day','start_time','end_time','apply_merch_ids'])
|
|
|
->first();
|
|
|
$info = $info? $info->toArray() : [];
|
|
|
if(empty($info)){
|
|
@@ -249,6 +253,12 @@ class CouponService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if($info['received_num'] >= $info['num']){
|
|
|
+ $this->error = 2909;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
$userInfo = MemberModel::where(['id'=> $userId,'mark'=>1,'status'=>1])
|
|
|
->select(['id','status'])
|
|
|
->first();
|
|
@@ -264,11 +274,20 @@ class CouponService extends BaseService
|
|
|
$info['update_time'] = time();
|
|
|
$info['status'] = 1;
|
|
|
$info['mark'] = 1;
|
|
|
+ DB::beginTransaction();
|
|
|
if(!MemberCouponModel::insertGetId($info)){
|
|
|
$this->error = 2907;
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$this->model->where(['id'=> $id])->setInc('received_num', 1)){
|
|
|
+ $this->error = 2907;
|
|
|
+ DB::rollBack();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ DB::commit();
|
|
|
$this->error = 2908;
|
|
|
return true;
|
|
|
}
|