调整退款金额的错误
This commit is contained in:
parent
a1bf0caf1c
commit
fe05e30fda
@ -37,6 +37,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
protected $store_consumption_user;
|
protected $store_consumption_user;
|
||||||
protected $consumption_money;
|
protected $consumption_money;
|
||||||
protected $balance;
|
protected $balance;
|
||||||
|
protected $payType;
|
||||||
|
|
||||||
public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0)
|
public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0)
|
||||||
{
|
{
|
||||||
@ -597,7 +598,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
} else {
|
} else {
|
||||||
if ($consumption_id > 0) {
|
if ($consumption_id > 0) {
|
||||||
if ($this->store_consumption_user) {
|
if ($this->store_consumption_user) {
|
||||||
if ($this->store_consumption_user['type'] == 2 && $pay_price >= 6) {
|
if ($this->store_consumption_user['type'] == 2 && $pay_price >= 6 && $this->payType != 'balance') {
|
||||||
$a = bcdiv($pay_price, 6);
|
$a = bcdiv($pay_price, 6);
|
||||||
if ($this->balance > $a) {
|
if ($this->balance > $a) {
|
||||||
$pay_price = bcsub($pay_price, $a, 2);
|
$pay_price = bcsub($pay_price, $a, 2);
|
||||||
@ -704,6 +705,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0, $consumption_id = 0)
|
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0, $consumption_id = 0)
|
||||||
{
|
{
|
||||||
$uid = $user->uid;
|
$uid = $user->uid;
|
||||||
|
$this->payType = $pay_type;
|
||||||
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true, $consumption_id);
|
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true, $consumption_id);
|
||||||
$order_model = $orderInfo['order_model'];
|
$order_model = $orderInfo['order_model'];
|
||||||
$order_extend = $orderInfo['order_extend'];
|
$order_extend = $orderInfo['order_extend'];
|
||||||
|
@ -226,6 +226,33 @@ class StoreRefundOrderRepository extends BaseRepository
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按订单实付金额退款
|
||||||
|
* @param $order
|
||||||
|
* @param $products
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getOrderRefundPrice($order, $products)
|
||||||
|
{
|
||||||
|
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
|
||||||
|
$totalPostage = 0;
|
||||||
|
$totalRefundPrice = 0;
|
||||||
|
$realPriceTotal = 0;
|
||||||
|
foreach ($products as $k => $product) {
|
||||||
|
$isLast = count($products->toArray()) == ($k + 1);
|
||||||
|
[$realPrice, $realPriceTotal] = $this->calculate($order['total_price'], $order['pay_price'], $product['product_price'], $realPriceTotal, $isLast);
|
||||||
|
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
|
||||||
|
$postagePrice = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
|
||||||
|
$refundPrice = 0;
|
||||||
|
if ($realPrice > 0) {
|
||||||
|
$refundPrice = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0,$productRefundPrice['refund_postage']??0 ,2), 2);
|
||||||
|
}
|
||||||
|
$totalPostage = bcadd($totalPostage, $postagePrice, 2);
|
||||||
|
$totalRefundPrice = bcadd($totalRefundPrice, $refundPrice, 2);
|
||||||
|
}
|
||||||
|
return bcadd($totalPostage, $totalRefundPrice, 2);
|
||||||
|
}
|
||||||
|
|
||||||
public function getRefundsTotalPrice($order, $products)
|
public function getRefundsTotalPrice($order, $products)
|
||||||
{
|
{
|
||||||
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
|
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
|
||||||
@ -249,12 +276,30 @@ class StoreRefundOrderRepository extends BaseRepository
|
|||||||
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
|
$productRefundPrices = app()->make(StoreRefundProductRepository::class)->userRefundPrice($products->column('order_product_id'));
|
||||||
$product = $products[0];
|
$product = $products[0];
|
||||||
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
|
$productRefundPrice = $productRefundPrices[$product['order_product_id']] ?? [];
|
||||||
$total_refund_price = bcsub($product['product_price'], bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
|
[$realPrice, $realPriceTotal] = $this->calculate($order['total_price'], $order['pay_price'], $product['product_price'], 0);
|
||||||
|
$total_refund_price = bcsub($realPrice, bcsub($productRefundPrice['refund_price'] ?? 0, $productRefundPrice['refund_postage'] ?? 0, 2), 2);
|
||||||
$postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
|
$postage_price = (!$order->status || $order->status == 9) ? bcsub($product['postage_price'], $productRefundPrice['refund_postage'] ?? 0, 2) : 0;
|
||||||
|
|
||||||
return compact('total_refund_price', 'postage_price');
|
return compact('total_refund_price', 'postage_price');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算退款金额
|
||||||
|
* @param float $orderTotalPrice 订单总金额
|
||||||
|
* @param float $orderPayPrice 订单实付金额
|
||||||
|
* @param float $productPrice 商品总金额
|
||||||
|
* @param float $realPriceTotal 实付金额合计
|
||||||
|
* @param bool $isLast 是否最后一条
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function calculate($orderTotalPrice, $orderPayPrice, $productPrice, $realPriceTotal, $isLast = false)
|
||||||
|
{
|
||||||
|
$rate = bcdiv($productPrice, $orderTotalPrice, 5);
|
||||||
|
$realPrice = $isLast ? bcsub($orderPayPrice, $realPriceTotal, 2) : bcmul($orderPayPrice, $rate, 2);
|
||||||
|
$realPriceTotal = bcadd($realPriceTotal, $realPrice, 2);
|
||||||
|
return [$realPrice, $realPriceTotal];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param StoreOrder $order
|
* @param StoreOrder $order
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
|
@ -91,7 +91,7 @@ class StoreRefundOrder extends BaseController
|
|||||||
if (count($product) != count($ids))
|
if (count($product) != count($ids))
|
||||||
return app('json')->fail('请选择正确的退款商品');
|
return app('json')->fail('请选择正确的退款商品');
|
||||||
if ($type == 2) {
|
if ($type == 2) {
|
||||||
$total_refund_price = $this->repository->getRefundsTotalPrice($order, $product);
|
$total_refund_price = $this->repository->getOrderRefundPrice($order, $product);
|
||||||
$postage_price = 0;
|
$postage_price = 0;
|
||||||
} else {
|
} else {
|
||||||
$data = $this->repository->getRefundTotalPrice($order, $product);
|
$data = $this->repository->getRefundTotalPrice($order, $product);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user