From 469cec1e6a8867db4c389ca521ae7e0169e2ae5b Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Thu, 20 Mar 2025 17:59:35 +0800 Subject: [PATCH] feat : coupon --- app/Service/ServiceTrait/Api/OrderTrait.php | 58 ++++++++++----------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/app/Service/ServiceTrait/Api/OrderTrait.php b/app/Service/ServiceTrait/Api/OrderTrait.php index b486fa4..4866f31 100644 --- a/app/Service/ServiceTrait/Api/OrderTrait.php +++ b/app/Service/ServiceTrait/Api/OrderTrait.php @@ -293,33 +293,33 @@ trait OrderTrait $this->orderRes['total_sundry_price'] = bcmul($this->orderRes['sundry_price'],(string)$this->orderRes['sundry_num'],2); } - /** - * 计算优惠 - * @return void - */ - protected function computeFavorable(): void - { - if ($this->couponId <= 0 && $this->isAutoSelectCoupon == 1) { - $this->couponId = $this->getAutoCouponId(); - } - - if ($this->couponId <= 0) { - $this->orderRes['coupon_id'] = 0; - $this->orderRes['coupon'] = []; - $this->orderRes['favorable_good_price'] = '0'; - $this->orderRes['favorable_sundry_price'] = '0'; - return; - } - - $couponInfo = []; // todo 优惠券信息 - - $this->orderRes['coupon_id'] = $this->couponId; - $this->orderRes['coupon'] = $couponInfo; - - //todo 优惠计算 - $this->orderRes['favorable_good_price'] = '1.00'; - $this->orderRes['favorable_sundry_price'] = '1.00'; - } +// /** +// * 计算优惠 +// * @return void +// */ +// protected function computeFavorable(): void +// { +// if ($this->couponId <= 0 && $this->isAutoSelectCoupon == 1) { +// $this->couponId = $this->getAutoCouponId(); +// } +// +// if ($this->couponId <= 0) { +// $this->orderRes['coupon_id'] = 0; +// $this->orderRes['coupon'] = []; +// $this->orderRes['favorable_good_price'] = '0'; +// $this->orderRes['favorable_sundry_price'] = '0'; +// return; +// } +// +// $couponInfo = []; // todo 优惠券信息 +// +// $this->orderRes['coupon_id'] = $this->couponId; +// $this->orderRes['coupon'] = $couponInfo; +// +// //todo 优惠计算 +// $this->orderRes['favorable_good_price'] = '1.00'; +// $this->orderRes['favorable_sundry_price'] = '1.00'; +// } /** * 计算最终价格 @@ -362,7 +362,7 @@ trait OrderTrait $orderMaxPrice = max(array_column($this->orderRes['good'],'price')); $this->orderRes['coupon']['amount'] = match ($this->orderRes['coupon']['coupon_type']) { CouponCode::COUPON_TYPE_INSTANT_REDUCTION => $this->orderRes['coupon']['amount'], - CouponCode::COUPON_TYPE_DISCOUNT => bcmul(bcdiv("100", bcsub("100",$this->orderRes['coupon']['ratio'],2),2),$orderMaxPrice,2), + CouponCode::COUPON_TYPE_DISCOUNT => bcmul(bcdiv("100", bcsub("100",(string)$this->orderRes['coupon']['ratio'],2),2),(string)$orderMaxPrice,2), default => 0 }; } @@ -388,7 +388,7 @@ trait OrderTrait if (empty($couponTemplateInfo)) throw new ErrException('优惠券信息错误'); $this->couponId = $couponInfo->id; - $this->orderRes['coupon_info'] = [ + $this->orderRes['coupon'] = [ 'id' => $couponInfo->id, 'coupon_type' => $couponTemplateInfo->coupon_type, 'amount' => $couponTemplateInfo->amount,