|
|
@@ -5,6 +5,8 @@ namespace bizGhs\cg\services;
|
|
|
use bizGhs\base\services\BaseService;
|
|
|
use bizGhs\cg\classes\CgRefundClass;
|
|
|
use bizGhs\cg\classes\CgRefundItemClass;
|
|
|
+use bizGhs\ghs\classes\GhsClass;
|
|
|
+use bizGhs\ghs\classes\GhsDebtRecordClass;
|
|
|
use bizGhs\order\classes\PurchaseOrderItemClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use common\components\dict;
|
|
|
@@ -109,6 +111,38 @@ class CgRefundService extends BaseService
|
|
|
$data['refundPrice'] = $refundPrice;
|
|
|
$data['refundType'] = $post['refundType'] ?? 0;
|
|
|
$refund = CgRefundClass::add($data, true);
|
|
|
+
|
|
|
+ //锁定当前增加资产的运作,有多处,请搜索关键词 ghsAddDebtAction
|
|
|
+ $ghsId = $order->ghsId??0;
|
|
|
+ $ghs = GhsClass::getLockById($ghsId);
|
|
|
+ if (empty($ghs)) {
|
|
|
+ util::fail('没有找到供货商');
|
|
|
+ }
|
|
|
+ $ghsAddDebtKey = 'ghs_change_debt_' . $ghsId;
|
|
|
+ $lock = util::lock($ghsAddDebtKey);
|
|
|
+ if (!$lock) {
|
|
|
+ util::fail("系统繁忙,请重试");
|
|
|
+ }
|
|
|
+ $ghs->debtAmount = bcsub($ghs->debtAmount, $refundPrice, 2);
|
|
|
+ $ghs->save();
|
|
|
+
|
|
|
+ //减少欠款变动记录
|
|
|
+ $capitalType = dict::getDict('capitalType', 'ghsCgOrderRefund', 'id');
|
|
|
+ $debtData = [
|
|
|
+ 'ghsId' => $ghsId,
|
|
|
+ 'relateId' => $refund->id,
|
|
|
+ 'ptStyle' => 2,
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $refundPrice,
|
|
|
+ 'balance' => $ghs->debtAmount,
|
|
|
+ 'io' => 0,
|
|
|
+ 'event' => '采购单'.$order->orderSn.'售后 ' .$orderSn ,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ ];
|
|
|
+ GhsDebtRecordClass::add($debtData);
|
|
|
+ util::unlock($ghsAddDebtKey);
|
|
|
+
|
|
|
return $refund;
|
|
|
}
|
|
|
|