|
|
|
@ -276,15 +276,15 @@ class OrderService implements OrderServiceInterface |
|
|
|
// 处理红包的使用
|
|
|
|
$canUseCoupons = CouponUserRec::select(['id', 'user_id', 'number', 'number_remain', 'system_coupon_user_id']) |
|
|
|
->whereIn('id', $receiveCouponIds) |
|
|
|
->get(); |
|
|
|
->get()->toArray(); |
|
|
|
if (is_array($canUseCoupons)&&!empty($canUseCoupons)) { |
|
|
|
# 使用记录、更新当前优惠券
|
|
|
|
foreach ($canUseCoupons as $key => &$coupon) { |
|
|
|
|
|
|
|
$couponUse = [ |
|
|
|
'user_id' => $coupon->user_id, |
|
|
|
'user_receive_id' => $coupon->id, |
|
|
|
'system_coupon_id' => $coupon->system_coupon_user_id, |
|
|
|
'user_id' => $coupon['user_id'], |
|
|
|
'user_receive_id' => $coupon['id'], |
|
|
|
'system_coupon_id' => $coupon['system_coupon_user_id'], |
|
|
|
'order_main_id' => $orderMainId, |
|
|
|
'use_time' => $currentTime, |
|
|
|
'return_time' => 0, |
|
|
|
@ -292,20 +292,21 @@ class OrderService implements OrderServiceInterface |
|
|
|
'status' => 1, |
|
|
|
'update_time' => 0, |
|
|
|
]; |
|
|
|
var_dump('$couponUse',$couponUse); |
|
|
|
|
|
|
|
$insertRes = CouponUserUse::query()->insert($couponUse); |
|
|
|
|
|
|
|
if ($insertRes) { |
|
|
|
$numberRemain = $coupon->number_remain - 1; |
|
|
|
$numberRemain = $coupon['number_remain'] - 1; |
|
|
|
if ($numberRemain == 0) { |
|
|
|
$status = 2; |
|
|
|
} elseif ($numberRemain > 0 && $numberRemain < $coupon->number) { |
|
|
|
} elseif ($numberRemain > 0 && $numberRemain < $coupon['number']) { |
|
|
|
$status = 1; |
|
|
|
} elseif ($numberRemain == $coupon->number) { |
|
|
|
} elseif ($numberRemain == $coupon['number']) { |
|
|
|
$status = 0; |
|
|
|
} |
|
|
|
|
|
|
|
$upRes = CouponUserRec::query()->where(['id' => $coupon->id])->update(['number_remain' => $numberRemain, 'status' => $status]); |
|
|
|
$upRes = CouponUserRec::query()->where(['id' => $coupon['id']])->update(['number_remain' => $numberRemain, 'status' => $status]); |
|
|
|
|
|
|
|
if (!$upRes) { |
|
|
|
Db::rollBack(); |
|
|
|
@ -313,7 +314,7 @@ class OrderService implements OrderServiceInterface |
|
|
|
} |
|
|
|
|
|
|
|
// 缓存使用记录
|
|
|
|
$usedRes = $this->couponService->cacheTodayCouponUsed($coupon->user_id, $coupon->system_coupon_user_id, $coupon->id); |
|
|
|
$usedRes = $this->couponService->cacheTodayCouponUsed($coupon['user_id'], $coupon['system_coupon_user_id'], $coupon['id']); |
|
|
|
if (!$usedRes) { |
|
|
|
Db::rollBack(); |
|
|
|
return '优惠券使用失败'; |
|
|
|
|