|
|
@ -36,7 +36,7 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
$sendUserId = $params["send_user_id"]; |
|
|
$sendUserId = $params["send_user_id"]; |
|
|
$phone = $params["phone"]; |
|
|
$phone = $params["phone"]; |
|
|
$now = time(); |
|
|
$now = time(); |
|
|
$ids = is_array($ids) ? implode(',',$ids) : $ids; |
|
|
|
|
|
|
|
|
$ids = is_array($ids) ? $ids : explode(',',$ids); |
|
|
|
|
|
|
|
|
// status: 0领取成功 >0领取失败
|
|
|
// status: 0领取成功 >0领取失败
|
|
|
$result = [ |
|
|
$result = [ |
|
|
@ -60,6 +60,7 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
|
|
|
|
|
$success = []; |
|
|
$success = []; |
|
|
$fail = []; |
|
|
$fail = []; |
|
|
|
|
|
$isr = []; |
|
|
|
|
|
|
|
|
//读写锁,完全控制,性能低
|
|
|
//读写锁,完全控制,性能低
|
|
|
$coupons = Coupon::whereIn('id', $ids)->lockForUpdate() |
|
|
$coupons = Coupon::whereIn('id', $ids)->lockForUpdate() |
|
|
@ -95,7 +96,7 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
|
|
|
|
|
|
// 判断是否领取过 存在记录则领取过
|
|
|
// 判断是否领取过 存在记录则领取过
|
|
|
$isReceive = CouponRec::select('id') |
|
|
$isReceive = CouponRec::select('id') |
|
|
->where('system_coupon_user_id',$ids) |
|
|
|
|
|
|
|
|
->where('system_coupon_user_id',$coupon->id) |
|
|
->where('user_id',$userId) |
|
|
->where('user_id',$userId) |
|
|
->exists(); |
|
|
->exists(); |
|
|
|
|
|
|
|
|
@ -116,10 +117,10 @@ 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; |
|
|
@ -168,9 +169,14 @@ class CouponRebateService implements CouponRebateServiceInterface |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
if(count($receiveSsdb) > 0){ |
|
|
if(count($receiveSsdb) > 0){ |
|
|
|
|
|
$saveSsdb = []; |
|
|
|
|
|
foreach($receiveSsdb as $kssdb => $vssdb){ |
|
|
|
|
|
$saveSsdb[] = $kssdb; |
|
|
|
|
|
$saveSsdb[] = $vssdb; |
|
|
|
|
|
} |
|
|
// 记录到ssdb
|
|
|
// 记录到ssdb
|
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
|
|
if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$receiveSsdb)){ |
|
|
|
|
|
|
|
|
if(false === $ssdb->exec('hset',SsdbKeysPrefix::COUPON_REBATE_RECEIVE.$userId,$saveSsdb)){ |
|
|
$errorData['msg'] = '记录领取优惠券到ssdb失败'; |
|
|
$errorData['msg'] = '记录领取优惠券到ssdb失败'; |
|
|
$this->log->event( |
|
|
$this->log->event( |
|
|
LogLabel::COUPON_LOG, |
|
|
LogLabel::COUPON_LOG, |
|
|
|