|
|
@@ -121,26 +121,39 @@ class PurchaseClass extends BaseClass
|
|
|
$sendCost = $data['sendCost'] ?? 0.00;
|
|
|
$prePrice = bcadd($prePrice, $sendCost, 2);
|
|
|
$actPrice = $prePrice;
|
|
|
- $realPrice = $actPrice;
|
|
|
-
|
|
|
- //验证优惠券
|
|
|
- $couponId = isset($data['couponId']) ? $data['couponId'] : 0;
|
|
|
- if (!empty($couponId)) {
|
|
|
- $coupon = ShopCouponClass::getLockById($couponId);
|
|
|
- ShopCouponClass::valid($coupon, $data['shopId']);
|
|
|
- if ($coupon->miniCost != 0 && $coupon->miniCost > $prePrice) {
|
|
|
- util::fail('达到最低消费才能使用优惠券');
|
|
|
+ $realPrice = $prePrice;
|
|
|
+ if (isset($data['modifyPrice'])) {
|
|
|
+ //商家打折,修改金额
|
|
|
+ $modifyPrice = $data['modifyPrice'] ?? 0;
|
|
|
+ if ($modifyPrice > $prePrice) {
|
|
|
+ util::fail('实收金额大于订单总金额');
|
|
|
}
|
|
|
- if ($prePrice < $coupon->amount) {
|
|
|
- util::fail('总价应大于优惠金额');
|
|
|
+ if ($modifyPrice < $prePrice) {
|
|
|
+ $data['discountAmount'] = bcsub($prePrice, $modifyPrice, 2);
|
|
|
+ $data['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
+ $actPrice = $modifyPrice;
|
|
|
+ $realPrice = $modifyPrice;
|
|
|
}
|
|
|
- $coupon->take = ShopCouponClass::TAKE_HAS;
|
|
|
- $coupon->save();
|
|
|
- $realPrice = bcsub($actPrice, $coupon->amount, 2);
|
|
|
- $data['discountType'] = dict::getDict('discountType', 'usePtCoupon');
|
|
|
- $data['discountAmount'] = $coupon->amount;
|
|
|
+ } else {
|
|
|
+ //验证优惠券
|
|
|
+ $couponId = isset($data['couponId']) ? $data['couponId'] : 0;
|
|
|
+ if (!empty($couponId)) {
|
|
|
+ $coupon = ShopCouponClass::getLockById($couponId);
|
|
|
+ ShopCouponClass::valid($coupon, $data['shopId']);
|
|
|
+ if ($coupon->miniCost != 0 && $coupon->miniCost > $prePrice) {
|
|
|
+ util::fail('达到最低消费才能使用优惠券');
|
|
|
+ }
|
|
|
+ if ($prePrice < $coupon->amount) {
|
|
|
+ util::fail('总价应大于优惠金额');
|
|
|
+ }
|
|
|
+ $coupon->take = ShopCouponClass::TAKE_HAS;
|
|
|
+ $coupon->save();
|
|
|
+ $realPrice = bcsub($actPrice, $coupon->amount, 2);
|
|
|
+ $data['discountType'] = dict::getDict('discountType', 'usePtCoupon');
|
|
|
+ $data['discountAmount'] = $coupon->amount;
|
|
|
+ }
|
|
|
+ $data['couponId'] = $couponId;
|
|
|
}
|
|
|
- $data['couponId'] = $couponId;
|
|
|
$data['prePrice'] = $prePrice;
|
|
|
$data['actPrice'] = $actPrice;
|
|
|
$data['realPrice'] = $realPrice;
|