debtPrice ?? '0'), '0', 2); if (bccomp($amount, '0', 2) <= 0) { $amount = bcadd((string)($order->remainDebtPrice ?? '0'), '0', 2); } if (bccomp($amount, '0', 2) <= 0) { return; } $beforeBalance = $ghs->balance ?? '0.00'; $ghs->debt = 2; $newBalance = bcsub($beforeBalance, $amount, 2); $ghs->balance = $newBalance; $ghs->save(false, ['balance', 'debt']); $relateId = $order->id ?? 0; $orderSn = $order->orderSn ?? ''; $ghsId = $ghs->id ?? 0; $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id'); $event = '购买花材,采购单号:' . $orderSn; if ($bookOrder) { $event = '预订单多退少补,单号' . $orderSn; } $change = [ 'relateId' => $relateId, 'ghsId' => $ghsId, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $newBalance, 'io' => 0, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId ?? 0, 'shopId' => $order->shopId ?? 0, ]; GhsBalanceChangeClass::add($change, true); } /** 采购结账:balance 增加(原 debtAmount 减少) */ public static function clearDebtAmountReduce($ghs, $custom, $amount, $clear) { // hd 采购结账:净 balance 增加 AccountMoneyClass::ensureGhsMoneyReady($ghs, true); $beforeBalance = $ghs->balance ?? '0.00'; $newBalance = bcadd($beforeBalance, $amount, 2); if (bccomp($beforeBalance, '0', 2) < 0 && bccomp($newBalance, '0', 2) > 0) { noticeUtil::push("结账没有成功,账户余额:{$beforeBalance} 本次结账金额:{$amount} 供货商ID:{$ghs->id}", '15280215347'); util::fail('结账没有成功'); } $ghs->balance = $newBalance; $ghs->debt = bccomp($newBalance, '0', 2) < 0 ? 2 : 1; $ghs->save(false, ['balance', 'debt']); $relateId = $clear->id ?? 0; $ghsId = $ghs->id ?? 0; $orderSn = $clear->orderSn ?? ''; $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id'); $change = [ 'relateId' => $relateId, 'ghsId' => $ghsId, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $newBalance, 'io' => 1, 'payWay' => 1, 'event' => "结账,单号:{$orderSn}", 'sjId' => $custom->sjId ?? 0, 'shopId' => $custom->shopId ?? 0, ]; GhsBalanceChangeClass::add($change, true); } /** 采购退款:balance 增加 */ public static function refundDebtAmountReduce($ghs, $refund, $cg) { // hd 采购退款:净 balance 增加 AccountMoneyClass::ensureGhsMoneyReady($ghs, true); $refundPrice = $refund->refundPrice ?? 0; if (bccomp($refundPrice, '0', 2) <= 0) { return; } $newBalance = bcadd($ghs->balance ?? '0.00', $refundPrice, 2); $ghs->balance = $newBalance; $ghs->save(false, ['balance']); $relateId = $refund->id ?? 0; $ghsId = $ghs->id ?? 0; $capitalType = dict::getDict('capitalType', 'cgRefund', 'id'); $cgOrderSn = $cg->orderSn ?? ''; $change = [ 'relateId' => $relateId, 'ghsId' => $ghsId, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'capitalType' => $capitalType, 'amount' => $refundPrice, 'balance' => $newBalance, 'io' => 1, 'payWay' => 0, 'event' => "采购单:{$cgOrderSn} 退款", 'sjId' => $refund->sjId ?? 0, 'shopId' => $refund->shopId ?? 0, ]; GhsBalanceChangeClass::add($change, true); } //验证供货商 ssh 20220307 public static function valid($ghs, $shopId) { if (empty($ghs)) { util::fail('没有找到供货商'); } if ($ghs->ownShopId != $shopId) { util::fail('不是您的供货商'); } return true; } }