|
|
@@ -15,7 +15,9 @@ use Yii;
|
|
|
* 合并(客户/批发关系行):balance = 原 balance - 原 debtAmount,debtAmount 置 0,balanceMerged=1。
|
|
|
* 合并(ghsApp 采购供货商行,ownPtStyle=ghs/kmGhs):按待结采购单 actPrice 合计重算净 balance,debtAmount 置 0。
|
|
|
* 合并(hd 花店侧供货商行,ownPtStyle=hd):balance -= debtAmount 旧逻辑(mergeGhsDebtIntoBalanceIfNeeded);二者不可混用。
|
|
|
- * 写业务前调 ensureCustomMoneyReady / ensureGhsMoneyReady;列表/详情返回前调 formatMoneyForClient。
|
|
|
+ * 写业务前调 ensureCustomMoneyReady / ensureGhsMoneyReady(仅行锁,不触发合并)。
|
|
|
+ * 批量合并仅由控制台脚本调用 mergeCustomMoneyForScript / mergeGhsMoneyForScript 等。
|
|
|
+ * 列表/详情返回前调 formatMoneyForClient。
|
|
|
* 旧 App(appVersion<3)由 formatMoneyForClient 拆回待结+余额双字段;新 App 只读净 balance。
|
|
|
*
|
|
|
* 充值销账(合并后来款 FIFO 销单):bizGhs\custom\services\GhsRechargeSettleService
|
|
|
@@ -195,7 +197,7 @@ class AccountMoneyClass
|
|
|
|
|
|
/**
|
|
|
* 【用途】对 xhGhs(花店↔供货商关系行)执行与上相同的挂账并入余额。
|
|
|
- * 【调用时机】ensureCustomMoneyReady 会顺带处理 custom.ghsId;hd 采购-only 场景用 ensureGhsMoneyReady。
|
|
|
+ * 【调用时机】mergeCustomMoneyForScript 会顺带处理 custom.ghsId;脚本侧 mergeGhsMoneyForScript 处理仅 ghs 行。
|
|
|
* 【说明】充值等场景要求 custom 与 ghs 两边净额一致,故成对合并。
|
|
|
*/
|
|
|
public static function mergeGhsDebtIntoBalanceIfNeeded($ghs, $writeBalanceChange = true)
|
|
|
@@ -317,13 +319,26 @@ class AccountMoneyClass
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 【用途】客户侧金额业务的前置入口(最重要,绝大多数写操作应先调此方法)。
|
|
|
- * 【做什么】行锁客户 → 未合并则合并客户 → 再合并其 ghsId 对应 xhGhs 行。
|
|
|
- * 【调用时机】开单挂账、结账、退款、充值、余额消费结账、清分改客户金额等。
|
|
|
- * 【参数】$writeMergeChange false 可关闭合并说明流水(极少用);默认 true
|
|
|
- * 【返回值】已合并、可安全读写 balance 的客户 AR
|
|
|
+ * 【用途】客户侧金额写操作前置:仅对客户行加锁,不执行挂账并入余额。
|
|
|
+ * 【调用时机】开单、结账、退款、充值等写 balance 前。
|
|
|
*/
|
|
|
public static function ensureCustomMoneyReady($custom, $writeMergeChange = true)
|
|
|
+ {
|
|
|
+ if (empty($custom)) {
|
|
|
+ return $custom;
|
|
|
+ }
|
|
|
+ $customId = is_array($custom) ? ($custom['id'] ?? 0) : ($custom->id ?? 0);
|
|
|
+ if (!is_object($custom) || !self::isMerged($custom)) {
|
|
|
+ $custom = CustomClass::getLockById($customId);
|
|
|
+ }
|
|
|
+ return $custom;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】控制台批量合并:客户行 + 其 ghsId 关系行一次性并入净 balance。
|
|
|
+ * 【调用时机】仅 php yii balance-merge/run 等脚本,禁止在 HTTP 业务里调用。
|
|
|
+ */
|
|
|
+ public static function mergeCustomMoneyForScript($custom, $writeMergeChange = true)
|
|
|
{
|
|
|
if (empty($custom)) {
|
|
|
return $custom;
|
|
|
@@ -374,8 +389,8 @@ class AccountMoneyClass
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 【用途】仅处理 xhGhs 关系行(无 custom 对象时),逻辑同 ensureCustomMoneyReady 的 ghs 部分。
|
|
|
- * 【调用时机】hd 采购挂账/结账/退款、ghs 采购单改供货商金额、CgRefund 等只拿到 $ghs 的场景。
|
|
|
+ * 【用途】供货商关系行写操作前置:仅加行锁,不执行挂账并入余额。
|
|
|
+ * 【调用时机】hd 采购挂账/结账/退款、ghs 采购改金额等写 balance 前。
|
|
|
*/
|
|
|
public static function ensureGhsMoneyReady($ghs, $writeMergeChange = true)
|
|
|
{
|
|
|
@@ -386,30 +401,29 @@ class AccountMoneyClass
|
|
|
if (!is_object($ghs) || !self::isMerged($ghs)) {
|
|
|
$ghs = BizGhsClass::getLockById($ghsId);
|
|
|
}
|
|
|
- if (empty($ghs)) {
|
|
|
- return $ghs;
|
|
|
- }
|
|
|
- if (!self::isMerged($ghs) && self::isGhsAppPurchaseSupplierRow($ghs)) {
|
|
|
- return self::mergeOwnShopGhsBalanceFromPurchaseOrdersIfNeeded($ghs, $writeMergeChange);
|
|
|
- }
|
|
|
- return self::mergeGhsDebtIntoBalanceIfNeeded($ghs, $writeMergeChange);
|
|
|
+ return $ghs;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 【用途】客户列表分页时,对「仍有 debtAmount 未合并」的单户触发懒合并(读路径补刀)。
|
|
|
- * 【调用时机】CustomClass::groupBaseInfo 循环里发现 debtAmount>0 且 balanceMerged=0。
|
|
|
- * 【说明】避免客户长期无交易一直显示旧双字段;合并后会刷新该行再 formatMoneyForClient。
|
|
|
- * 【参数】$customId 客户主键
|
|
|
+ * 【用途】控制台批量合并:单条 xhGhs(hd 走 debtAmount 合并,ghsApp 采购行走采购单重算)。
|
|
|
+ * 【调用时机】仅 php yii balance-merge/run;ghsApp 采购行请用 ghs-purchase-balance-merge/run。
|
|
|
*/
|
|
|
- public static function mergeCustomRowFromListIfNeeded($customId)
|
|
|
+ public static function mergeGhsMoneyForScript($ghs, $writeMergeChange = true)
|
|
|
{
|
|
|
- if (empty($customId)) {
|
|
|
- return;
|
|
|
+ if (empty($ghs)) {
|
|
|
+ return $ghs;
|
|
|
+ }
|
|
|
+ $ghsId = is_array($ghs) ? ($ghs['id'] ?? 0) : ($ghs->id ?? 0);
|
|
|
+ if (!is_object($ghs) || !self::isMerged($ghs)) {
|
|
|
+ $ghs = BizGhsClass::getLockById($ghsId);
|
|
|
+ }
|
|
|
+ if (empty($ghs)) {
|
|
|
+ return $ghs;
|
|
|
}
|
|
|
- $custom = CustomClass::getLockById($customId);
|
|
|
- if (!empty($custom)) {
|
|
|
- self::ensureCustomMoneyReady($custom, true);
|
|
|
+ if (!self::isMerged($ghs) && self::isGhsAppPurchaseSupplierRow($ghs)) {
|
|
|
+ return self::mergeOwnShopGhsBalanceFromPurchaseOrdersIfNeeded($ghs, $writeMergeChange);
|
|
|
}
|
|
|
+ return self::mergeGhsDebtIntoBalanceIfNeeded($ghs, $writeMergeChange);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -630,24 +644,4 @@ class AccountMoneyClass
|
|
|
GhsBalanceChangeClass::add($gbData, true);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 【用途】供货商列表分页时的读路径懒合并:ghsApp 采购行按采购单重算,hd 花店行走 debtAmount 合并。
|
|
|
- * 【调用时机】bizGhs\ghs\classes\GhsClass::groupBaseInfo。
|
|
|
- */
|
|
|
- public static function mergeGhsRowFromListIfNeeded($ghsId)
|
|
|
- {
|
|
|
- if (empty($ghsId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- $ghs = BizGhsClass::getLockById($ghsId);
|
|
|
- if (empty($ghs)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (self::isGhsAppPurchaseSupplierRow($ghs)) {
|
|
|
- self::mergeOwnShopGhsBalanceFromPurchaseOrdersIfNeeded($ghs, true);
|
|
|
- return;
|
|
|
- }
|
|
|
- self::mergeGhsDebtIntoBalanceIfNeeded($ghs, true);
|
|
|
- }
|
|
|
}
|