|
|
@ -64,14 +64,13 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
}else{ |
|
|
}else{ |
|
|
$ids = $idsData; |
|
|
$ids = $idsData; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(count($ids) > 0){ |
|
|
if(count($ids) > 0){ |
|
|
try{ |
|
|
try{ |
|
|
Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { |
|
|
Db::transaction( function() use ($ids,$receiveType,$userId,$sendUserId,$phone,$now,&$result,&$errorData,&$receiveSsdb) { |
|
|
|
|
|
|
|
|
$success = []; |
|
|
$success = []; |
|
|
$fail = []; |
|
|
$fail = []; |
|
|
$isr = []; |
|
|
|
|
|
|
|
|
|
|
|
//读写锁,完全控制,性能低
|
|
|
//读写锁,完全控制,性能低
|
|
|
$coupons = Coupon::whereIn('id', $ids)->lockForUpdate() |
|
|
$coupons = Coupon::whereIn('id', $ids)->lockForUpdate() |
|
|
@ -128,14 +127,14 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
$couponReceive->send_user_id = $sendUserId; |
|
|
$couponReceive->send_user_id = $sendUserId; |
|
|
$couponReceive->phone = $phone; |
|
|
$couponReceive->phone = $phone; |
|
|
|
|
|
|
|
|
// if ( $couponReceive->save() && $coupon->save() ) {
|
|
|
|
|
|
// $success[] = $coupon;
|
|
|
|
|
|
// $receiveSsdb[] = $coupon->id;;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
if ( $couponReceive->save() && $coupon->save() ) { |
|
|
|
|
|
$success[] = $coupon; |
|
|
|
|
|
$receiveSsdb[] = $coupon->id;; |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
$fail[] = $coupon; |
|
|
$fail[] = $coupon; |
|
|
$receiveSsdb[] = $coupon->id; |
|
|
$receiveSsdb[] = $coupon->id; |
|
|
$result['status'] = 2; |
|
|
|
|
|
|
|
|
$result['status'] = 3; |
|
|
$result['coupon_text'] = '您已领取!赶快去下单吧~'; |
|
|
$result['coupon_text'] = '您已领取!赶快去下单吧~'; |
|
|
|
|
|
|
|
|
$errorData['msg'] = '用户已经领取了优惠券'; |
|
|
$errorData['msg'] = '用户已经领取了优惠券'; |
|
|
|