|
|
@@ -2,8 +2,11 @@
|
|
|
|
|
|
namespace bizHd\cg\services;
|
|
|
|
|
|
+use biz\pt\classes\PtAssetClass;
|
|
|
+use biz\pt\classes\PtYeChangeClass;
|
|
|
use biz\shop\classes\ShopCapitalClass;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
+use biz\shop\classes\ShopYeChangeClass;
|
|
|
use bizHd\base\services\BaseService;
|
|
|
use bizHd\cg\classes\CgRefundClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
@@ -34,8 +37,12 @@ class CgRefundService extends BaseService
|
|
|
$refundOrderSn = orderSn::getCgRefundSn();
|
|
|
$post['orderSn'] = $refundOrderSn;
|
|
|
$post['cgId'] = $cg->id;
|
|
|
- $refundPrice = $post['refundPrice'] ?? 0.01;
|
|
|
+ $refundPrice = $post['price'] ?? 0;
|
|
|
+ if (is_numeric($refundPrice) == false || $refundPrice < 0) {
|
|
|
+ util::fail('退款金额有问题');
|
|
|
+ }
|
|
|
$post['refundPrice'] = $refundPrice;
|
|
|
+ //创建退款单
|
|
|
$cgRefund = CgRefundClass::add($post, true);
|
|
|
|
|
|
$shopId = $cg->shopId ?? 0;
|
|
|
@@ -48,7 +55,11 @@ class CgRefundService extends BaseService
|
|
|
$shop->totalIncome = $currentTotalIncome;
|
|
|
$shop->save();
|
|
|
|
|
|
+ $ptStyle = $shop->ptStyle;
|
|
|
+ $sjId = $shop->sjId;
|
|
|
+ $shopId = $shop->id;
|
|
|
$payWay = $cg->payWay;
|
|
|
+ $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
|
|
|
|
|
|
if ($payWay == dict::getDict('payWay', 'wxPay')) {
|
|
|
|
|
|
@@ -93,19 +104,91 @@ class CgRefundService extends BaseService
|
|
|
$cgRefund->save();
|
|
|
|
|
|
} elseif ($payWay == dict::getDict('payWay', 'debtPay')) {
|
|
|
+
|
|
|
//客户应付款减少
|
|
|
- //供应商应收款减少
|
|
|
+ $clearId = $cg->clearId ?? 0;
|
|
|
+ if (!empty($clearId)) {
|
|
|
+ util::fail('订单已经结帐,无法再发起退款');
|
|
|
+ }
|
|
|
+ $currentMayPay = bcsub($shop->mayPay, $refundPrice, 2);
|
|
|
+ if ($currentMayPay < 0) {
|
|
|
+ util::fail('应付款有问题');
|
|
|
+ }
|
|
|
+ $shop->mayPay = $currentMayPay;
|
|
|
+ $shop->save();
|
|
|
+
|
|
|
} elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
|
|
|
+
|
|
|
//客户余额增加
|
|
|
- //供应商余额减少
|
|
|
- } else {
|
|
|
+ $currentBalance = bcadd($shop->balance, $refundPrice, 2);
|
|
|
+ $shop->balance = $currentBalance;
|
|
|
+ $shop->save();
|
|
|
+ $currentTxBalance = $shop->txBalance;
|
|
|
+
|
|
|
+ $id = $cgRefund->id;
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $id,
|
|
|
+ 'capitalType' => $currentType,
|
|
|
+ 'amount' => $refundPrice,
|
|
|
+ 'balance' => $currentBalance,
|
|
|
+ 'txBalance' => $currentTxBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'event' => "采购退款",
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'tx' => dict::getDict('yeTx', 'canNot'),
|
|
|
+ 'ptStyle' => $ptStyle,
|
|
|
+ ];
|
|
|
+ ShopYeChangeClass::addChange($change, true);
|
|
|
+
|
|
|
+ $asset = null;
|
|
|
+ if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
|
|
|
+ $asset = PtAssetClass::getHdBalance();
|
|
|
+ } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
|
|
|
+ $asset = PtAssetClass::getGhsBalance();
|
|
|
+ } else {
|
|
|
+ util::fail('没有找到平台');
|
|
|
+ }
|
|
|
+ $currentPtBalance = bcadd($asset->amount, $refundPrice, 2);
|
|
|
+ $asset->amount = $currentPtBalance;
|
|
|
+ $asset->save();
|
|
|
+
|
|
|
+ $txAsset = null;
|
|
|
+ if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
|
|
|
+ $txAsset = PtAssetClass::getHdTxBalance();
|
|
|
+ } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
|
|
|
+ $txAsset = PtAssetClass::getGhsTxBalance();
|
|
|
+ } else {
|
|
|
+ util::fail('没有找到平台');
|
|
|
+ }
|
|
|
+ $currentPtTxBalance = $txAsset->amount;
|
|
|
+
|
|
|
+ $change = [
|
|
|
+ 'relateId' => $id,
|
|
|
+ 'capitalType' => $currentType,
|
|
|
+ 'amount' => $refundPrice,
|
|
|
+ 'balance' => $currentPtBalance,
|
|
|
+ 'txBalance' => $currentPtTxBalance,
|
|
|
+ 'io' => 1,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'event' => "【{$shop->merchantName} {$shop->shopName}】的采购被退款",
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'tx' => dict::getDict('yeTx', 'canNot'),
|
|
|
+ 'ptStyle' => $ptStyle,
|
|
|
+ 'shopName' => $shop->shopName,
|
|
|
+ 'sjName' => $shop->merchantName,
|
|
|
+ ];
|
|
|
+ PtYeChangeClass::addChange($change, true);
|
|
|
|
|
|
+ } else {
|
|
|
+ util::fail('支付方式没有找到哦!');
|
|
|
}
|
|
|
|
|
|
$sjId = $cg->sjId ?? 0;
|
|
|
$shopId = $cg->shopId ?? 0;
|
|
|
$event = '采购退款';
|
|
|
- $currentType = dict::getDict('capitalType', 'cgRefund', 'id');
|
|
|
$capitalData = [
|
|
|
'capitalType' => $currentType,
|
|
|
'io' => 1,
|