Browse Source

优惠券返券活动--修改领取接口

master
liangyuyan 5 years ago
parent
commit
1ddf72a15f
  1. 22
      app/Service/CouponRebateService.php

22
app/Service/CouponRebateService.php

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

Loading…
Cancel
Save