release
parent
2724be081a
commit
cdcbb0256b
|
|
@ -88,13 +88,14 @@ class WalletController extends Controller
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'pay_sn' => ['bail', 'required'],
|
'pay_sn' => ['bail', 'required'],
|
||||||
|
'pay_way' => ['bail', 'required'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB::transaction(function () use ($user, $validated) {
|
DB::transaction(function () use ($user, $validated) {
|
||||||
$payLog = PayLog::where('pay_sn', $validated['pay_sn'])->lockForUpdate()->firstOrFail();
|
$payLog = PayLog::where('pay_sn', $validated['pay_sn'])->where('pay_way', $validated['pay_way'])->lockForUpdate()->firstOrFail();
|
||||||
|
|
||||||
$payable = $payLog->payable;
|
$payable = $payLog->payable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Helpers;
|
|
||||||
|
|
||||||
class Numeric
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 去除数字字符串小数点后多余的 0
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function trimTrailingZero($value)
|
|
||||||
{
|
|
||||||
if (is_numeric($value) && strpos($value, '.') !== false) {
|
|
||||||
$value = rtrim(rtrim($value, '0'), '.') ?: '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Constants\OrderStatus;
|
use App\Constants\OrderStatus;
|
||||||
use App\Helpers\Numeric;
|
|
||||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
@ -263,7 +262,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getCouponDiscountAmountFormatAttribute()
|
public function getCouponDiscountAmountFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['coupon_discount_amount'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['coupon_discount_amount'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -273,7 +272,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getVipDiscountAmountFormatAttribute()
|
public function getVipDiscountAmountFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['vip_discount_amount'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['vip_discount_amount'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -283,7 +282,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getReducedAmountFormatAttribute()
|
public function getReducedAmountFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['reduced_amount'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['reduced_amount'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -293,7 +292,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getShippingFeeFormatAttribute()
|
public function getShippingFeeFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['shipping_fee'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['shipping_fee'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -303,7 +302,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getTotalAmountFormatAttribute()
|
public function getTotalAmountFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['total_amount'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['total_amount'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -313,7 +312,7 @@ class Order extends Model
|
||||||
*/
|
*/
|
||||||
public function getProductsTotalAmountFormatAttribute()
|
public function getProductsTotalAmountFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['products_total_amount'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['products_total_amount'], 100, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Helpers\Numeric as NumericHelper;
|
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
@ -142,10 +141,12 @@ class UserCoupon extends Model
|
||||||
|
|
||||||
// 如果是折扣券
|
// 如果是折扣券
|
||||||
if ($this->isDiscountCoupon()) {
|
if ($this->isDiscountCoupon()) {
|
||||||
return NumericHelper::trimTrailingZero(bcdiv($value, 10, 1));
|
$value = bcdiv($value, 10, 1);
|
||||||
|
} else {
|
||||||
|
$value = bcdiv($value, 100, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NumericHelper::trimTrailingZero(bcdiv($value, 100, 2));
|
return trim_trailing_zeros($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -155,7 +156,7 @@ class UserCoupon extends Model
|
||||||
*/
|
*/
|
||||||
public function getCouponThresholdFormatAttribute(): string
|
public function getCouponThresholdFormatAttribute(): string
|
||||||
{
|
{
|
||||||
return NumericHelper::trimTrailingZero(
|
return trim_trailing_zeros(
|
||||||
bcdiv($this->attributes['coupon_threshold'], 100, 2)
|
bcdiv($this->attributes['coupon_threshold'], 100, 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Helpers\Numeric;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class WalletLog extends Model
|
class WalletLog extends Model
|
||||||
|
|
@ -29,6 +28,6 @@ class WalletLog extends Model
|
||||||
*/
|
*/
|
||||||
public function getChangeBalanceFormatAttribute()
|
public function getChangeBalanceFormatAttribute()
|
||||||
{
|
{
|
||||||
return Numeric::trimTrailingZero(bcdiv($this->attributes['change_balance'], 100, 2));
|
return trim_trailing_zeros(bcdiv($this->attributes['change_balance'], 100, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use App\Endpoint\Api\Http\Resources\ShippingAddressResource;
|
||||||
use App\Endpoint\Api\Http\Resources\UserCouponResource;
|
use App\Endpoint\Api\Http\Resources\UserCouponResource;
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use App\Exceptions\ShippingNotSupportedException;
|
use App\Exceptions\ShippingNotSupportedException;
|
||||||
use App\Helpers\Numeric;
|
|
||||||
use App\Models\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Models\DistributionPreIncomeJob;
|
use App\Models\DistributionPreIncomeJob;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
|
|
@ -467,11 +466,11 @@ class OrderService
|
||||||
'coupons' => UserCouponResource::collection((new CouponService())->getAvailableCoupons($user, $products)),
|
'coupons' => UserCouponResource::collection((new CouponService())->getAvailableCoupons($user, $products)),
|
||||||
'shipping_address' => $shippingAddress ? ShippingAddressResource::make($shippingAddress) : null, // 收货地址
|
'shipping_address' => $shippingAddress ? ShippingAddressResource::make($shippingAddress) : null, // 收货地址
|
||||||
'shipping_supported' => $shippingSupported,
|
'shipping_supported' => $shippingSupported,
|
||||||
'shipping_fee' => Numeric::trimTrailingZero(bcdiv($shippingFee, 100, 2)), // 运费
|
'shipping_fee' => trim_trailing_zeros(bcdiv($shippingFee, 100, 2)), // 运费
|
||||||
'products_total_amount' => Numeric::trimTrailingZero(bcdiv($productsTotalAmount, 100, 2)), // 商品总额
|
'products_total_amount' => trim_trailing_zeros(bcdiv($productsTotalAmount, 100, 2)), // 商品总额
|
||||||
'vip_discount_amount' => Numeric::trimTrailingZero(bcdiv($vipDiscountAmount, 100, 2)), // 会员折扣金额
|
'vip_discount_amount' => trim_trailing_zeros(bcdiv($vipDiscountAmount, 100, 2)), // 会员折扣金额
|
||||||
'coupon_discount_amount' => Numeric::trimTrailingZero(bcdiv($couponDiscountAmount, 100, 2)), // 优惠券折扣金额
|
'coupon_discount_amount' => trim_trailing_zeros(bcdiv($couponDiscountAmount, 100, 2)), // 优惠券折扣金额
|
||||||
'total_amount' => Numeric::trimTrailingZero(bcdiv($totalAmount, 100, 2)), // 实付金额
|
'total_amount' => trim_trailing_zeros(bcdiv($totalAmount, 100, 2)), // 实付金额
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue