|
|
@@ -716,6 +716,94 @@ class CustomClass extends BaseClass
|
|
|
GhsBalanceChangeClass::add($gbData, true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 后台手动减少客户净余额(只减正余额部分,不增加待结)。
|
|
|
+ * 调用方须已通过 lockAccountPair 锁定 custom/ghs。
|
|
|
+ */
|
|
|
+ public static function manualDeductBalance($shop, $custom, $ghs, $amount, $params = [])
|
|
|
+ {
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('没有找到客户');
|
|
|
+ }
|
|
|
+ AccountMoneyClass::ensureCustomMoneyReady($custom, true);
|
|
|
+ if (!empty($ghs)) {
|
|
|
+ AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
|
|
|
+ self::assertPairBalanceEqual($custom, $ghs);
|
|
|
+ }
|
|
|
+
|
|
|
+ $amount = bcadd((string)$amount, '0', 2);
|
|
|
+ if (bccomp($amount, '0', 2) <= 0) {
|
|
|
+ util::fail('金额要大于0');
|
|
|
+ }
|
|
|
+ $beforeBalance = bcadd((string)($custom->balance ?? '0'), '0', 2);
|
|
|
+ if (bccomp($beforeBalance, '0', 2) <= 0) {
|
|
|
+ util::fail('没有可减余额');
|
|
|
+ }
|
|
|
+ if (bccomp($beforeBalance, $amount, 2) < 0) {
|
|
|
+ util::fail('余额不够扣');
|
|
|
+ }
|
|
|
+
|
|
|
+ $newBalance = bcsub($beforeBalance, $amount, 2);
|
|
|
+ self::savePairBalanceAfterDeduct($custom, $ghs, $newBalance);
|
|
|
+
|
|
|
+ $remark = $params['remark'] ?? '';
|
|
|
+ $staffId = intval($params['staffId'] ?? 0);
|
|
|
+ $staffName = $params['staffName'] ?? '';
|
|
|
+ $mainId = $shop->mainId ?? 0;
|
|
|
+ $shopId = $shop->id ?? 0;
|
|
|
+ $sjId = $shop->sjId ?? 0;
|
|
|
+ $customId = $custom->id ?? 0;
|
|
|
+ $customName = $custom->name ?? '';
|
|
|
+ $capitalType = dict::getDict('capitalType', 'deduct', 'id');
|
|
|
+ $fromType = dict::getDict('fromType', 'shop');
|
|
|
+ $event = '手动减少';
|
|
|
+
|
|
|
+ CustomBalanceChangeClass::add([
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'customName' => $customName,
|
|
|
+ 'relateId' => 0,
|
|
|
+ 'onlinePay' => 1,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $newBalance,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'io' => 0,
|
|
|
+ 'side' => 0,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'fromType' => $fromType,
|
|
|
+ 'event' => $event,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'remark' => $remark,
|
|
|
+ ], true);
|
|
|
+
|
|
|
+ if (!empty($ghs)) {
|
|
|
+ $customShopId = $custom->shopId ?? 0;
|
|
|
+ $customShop = ShopClass::getById($customShopId, true);
|
|
|
+ GhsBalanceChangeClass::add([
|
|
|
+ 'ghsId' => $ghs->id ?? 0,
|
|
|
+ 'relateId' => 0,
|
|
|
+ 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
|
|
|
+ 'capitalType' => $capitalType,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'balance' => $newBalance,
|
|
|
+ 'io' => 0,
|
|
|
+ 'side' => 0,
|
|
|
+ 'onlinePay' => 1,
|
|
|
+ 'payWay' => 0,
|
|
|
+ 'fromType' => $fromType,
|
|
|
+ 'event' => $event,
|
|
|
+ 'sjId' => $customShop->sjId ?? 0,
|
|
|
+ 'mainId' => $customShop->mainId ?? 0,
|
|
|
+ 'shopId' => $customShopId,
|
|
|
+ 'remark' => $remark,
|
|
|
+ ], true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 开单余额支付:扣减净 balance 并记购买流水(须传入 payAfter 已 lockAccountPair 的 custom/ghs)。
|
|
|
*/
|