|
@@ -3,12 +3,16 @@
|
|
|
namespace bizGhs\order\classes;
|
|
namespace bizGhs\order\classes;
|
|
|
|
|
|
|
|
use biz\shop\classes\ShopAdminClass;
|
|
use biz\shop\classes\ShopAdminClass;
|
|
|
|
|
+use biz\shop\classes\ShopCapitalClass;
|
|
|
use biz\shop\classes\ShopClass;
|
|
use biz\shop\classes\ShopClass;
|
|
|
use biz\shop\classes\ShopExtClass;
|
|
use biz\shop\classes\ShopExtClass;
|
|
|
use biz\shop\models\Shop;
|
|
use biz\shop\models\Shop;
|
|
|
use biz\sj\classes\SjClass;
|
|
use biz\sj\classes\SjClass;
|
|
|
use biz\stat\classes\StatItemClass;
|
|
use biz\stat\classes\StatItemClass;
|
|
|
|
|
+use biz\stat\classes\StatKhCgClass;
|
|
|
use biz\stat\classes\StatOrderCountClass;
|
|
use biz\stat\classes\StatOrderCountClass;
|
|
|
|
|
+use biz\stat\classes\StatOutClass;
|
|
|
|
|
+use biz\stat\classes\StatRefundClass;
|
|
|
use bizGhs\custom\models\Custom;
|
|
use bizGhs\custom\models\Custom;
|
|
|
use bizGhs\express\services\DadaExpressServices;
|
|
use bizGhs\express\services\DadaExpressServices;
|
|
|
use bizGhs\order\models\Order;
|
|
use bizGhs\order\models\Order;
|
|
@@ -153,7 +157,7 @@ class OrderClass extends BaseClass
|
|
|
$currentPrice = bcadd($itemPrice, $sendCost, 2);
|
|
$currentPrice = bcadd($itemPrice, $sendCost, 2);
|
|
|
|
|
|
|
|
$shopId = $order->shopId ?? 0;
|
|
$shopId = $order->shopId ?? 0;
|
|
|
- $shop = ShopClass::getById($shopId, true);
|
|
|
|
|
|
|
+ $shop = ShopClass::getLockById($shopId);
|
|
|
$kiloFee = $shop->kiloFee ?? 0;
|
|
$kiloFee = $shop->kiloFee ?? 0;
|
|
|
$miniKilo = $shop->miniKilo ?? 0;
|
|
$miniKilo = $shop->miniKilo ?? 0;
|
|
|
$calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
|
|
$calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
|
|
@@ -167,22 +171,83 @@ class OrderClass extends BaseClass
|
|
|
$order->save();
|
|
$order->save();
|
|
|
$bookPrice = $order->bookPrice ?? 0;
|
|
$bookPrice = $order->bookPrice ?? 0;
|
|
|
|
|
|
|
|
|
|
+ $mainId = $shop->mainId ?? 0;
|
|
|
|
|
+ $sjId = $shop->sjId ?? 0;
|
|
|
|
|
+ $customId = $order->customId ?? 0;
|
|
|
|
|
+ $relateOrderSn = $order->orderSn ?? '';
|
|
|
|
|
+ $shopAdminId = $data['shopAdminId'] ?? 0;
|
|
|
|
|
+ $shopAdminName = $data['shopAdminName'] ?? '';
|
|
|
|
|
+
|
|
|
$refundId = 0;
|
|
$refundId = 0;
|
|
|
- if ($bookPrice == $currentPrice) {
|
|
|
|
|
- return true;
|
|
|
|
|
- } elseif ($bookPrice > $currentPrice) {
|
|
|
|
|
-// $refundPrice = bcsub($bookPrice, $currentPrice, 2);
|
|
|
|
|
-// //退款
|
|
|
|
|
-// RefundOrderClass::add($data, true);
|
|
|
|
|
-// //门店余额减少
|
|
|
|
|
-// ShopClass::saleRefundReduceBalance($shop, $refund, $refundPrice);
|
|
|
|
|
- } else {
|
|
|
|
|
- //欠款
|
|
|
|
|
- $currentDebt = bcsub($currentPrice, $bookPrice, 2);
|
|
|
|
|
- $order->debtPrice = $currentDebt;
|
|
|
|
|
- $order->remainDebtPrice = $currentDebt;
|
|
|
|
|
- $order->debt = OrderClass::DEBT_YES;
|
|
|
|
|
- $order->save();
|
|
|
|
|
|
|
+ if ($bookPrice != $currentPrice) {
|
|
|
|
|
+ if ($bookPrice > $currentPrice) {
|
|
|
|
|
+ $refundPrice = bcsub($bookPrice, $currentPrice, 2);
|
|
|
|
|
+
|
|
|
|
|
+ $order->refundPrice = $refundPrice;
|
|
|
|
|
+ $order->tkPrice = bcadd($order->tkPrice, $refundPrice, 2);
|
|
|
|
|
+ $order->save();
|
|
|
|
|
+
|
|
|
|
|
+ $orderSn = orderSn::getGhsRefundSn();
|
|
|
|
|
+ $book = 1;
|
|
|
|
|
+ $refundData = [
|
|
|
|
|
+ 'mainId' => $mainId,
|
|
|
|
|
+ 'shopId' => $shopId,
|
|
|
|
|
+ 'sjId' => $sjId,
|
|
|
|
|
+ 'customId' => $customId,
|
|
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
|
|
+ 'relateOrderSn' => $relateOrderSn,
|
|
|
|
|
+ 'book' => $book,
|
|
|
|
|
+ 'status' => 0,
|
|
|
|
|
+ 'shopAdminId' => $shopAdminId,
|
|
|
|
|
+ 'shopAdminName' => $shopAdminName,
|
|
|
|
|
+ 'refundPrice' => $refundPrice,
|
|
|
|
|
+ 'refundType' => RefundOrderClass::REFUND_TYPE_MONEY,
|
|
|
|
|
+ ];
|
|
|
|
|
+ //退款
|
|
|
|
|
+ $refund = RefundOrderClass::add($refundData, true);
|
|
|
|
|
+
|
|
|
|
|
+ //余额减少
|
|
|
|
|
+ ShopClass::ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice);
|
|
|
|
|
+
|
|
|
|
|
+ //总支出增加
|
|
|
|
|
+ $currentTotalExpend = bcadd($shop->totalExpend, $refundPrice, 2);
|
|
|
|
|
+ $shop->totalExpend = $currentTotalExpend;
|
|
|
|
|
+ $totalRefund = bcadd($shop->totalRefund, $refundPrice, 2);
|
|
|
|
|
+ $shop->totalRefund = $totalRefund;
|
|
|
|
|
+ $shop->save();
|
|
|
|
|
+
|
|
|
|
|
+ //支出流水
|
|
|
|
|
+ $customName = $order->customName ?? '';
|
|
|
|
|
+ $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id');
|
|
|
|
|
+ $sjId = $order->sjId ?? 0;
|
|
|
|
|
+ $event = "预订单多付退给{$customName}";
|
|
|
|
|
+ $capitalData = [
|
|
|
|
|
+ 'capitalType' => $thisType,
|
|
|
|
|
+ 'io' => 0,
|
|
|
|
|
+ 'totalExpend' => $currentTotalExpend,
|
|
|
|
|
+ 'payWay' => 0,
|
|
|
|
|
+ 'amount' => $refundPrice,
|
|
|
|
|
+ 'sjId' => $sjId,
|
|
|
|
|
+ 'shopId' => $shopId,
|
|
|
|
|
+ 'event' => $event,
|
|
|
|
|
+ ];
|
|
|
|
|
+ ShopCapitalClass::addCapital($capitalData);
|
|
|
|
|
+ //出统计
|
|
|
|
|
+ StatOutClass::updateOrInsert($shop, $refundPrice);
|
|
|
|
|
+ //退款统计
|
|
|
|
|
+ $payWay = $order->payWay ?? 0;
|
|
|
|
|
+ StatRefundClass::replace($shop, $payWay, $refundPrice);
|
|
|
|
|
+ //客户采购减少统计
|
|
|
|
|
+ StatKhCgClass::refundReplace($refund);
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //欠款
|
|
|
|
|
+ $currentDebt = bcsub($currentPrice, $bookPrice, 2);
|
|
|
|
|
+ $order->debtPrice = $currentDebt;
|
|
|
|
|
+ $order->remainDebtPrice = $currentDebt;
|
|
|
|
|
+ $order->debt = OrderClass::DEBT_YES;
|
|
|
|
|
+ $order->save();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return ['kiloFee' => $kiloFee, 'refundId' => $refundId, 'miniKilo' => $miniKilo];
|
|
return ['kiloFee' => $kiloFee, 'refundId' => $refundId, 'miniKilo' => $miniKilo];
|
|
|
}
|
|
}
|