|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace bizGhs\custom\classes;
|
|
|
|
|
|
+use bizGhs\ghs\classes\GhsRechargeClass;
|
|
|
use bizGhs\order\classes\OrderClearClass;
|
|
|
use bizHd\purchase\classes\PurchaseClearClass;
|
|
|
use common\components\dict;
|
|
|
@@ -63,12 +64,17 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
return self::attachClearMetaFromClearId($row, $relateId);
|
|
|
}
|
|
|
|
|
|
- if (!self::isRechargeCapitalType($row['capitalType'] ?? 0)) {
|
|
|
+ if (!self::isRechargeCapitalType($row['capitalType'] ?? 0)
|
|
|
+ && !self::isGhsSideRechargeCapitalType($row['capitalType'] ?? 0)) {
|
|
|
return $row;
|
|
|
}
|
|
|
|
|
|
- $recharge = CustomRechargeClass::getById($relateId, true);
|
|
|
+ $recharge = self::resolveCustomRechargeForBalanceRow($row);
|
|
|
if (!empty($recharge)) {
|
|
|
+ $customId = intval(is_object($recharge) ? ($recharge->customId ?? 0) : ($recharge['customId'] ?? 0));
|
|
|
+ if ($customId > 0) {
|
|
|
+ $row['customId'] = $customId;
|
|
|
+ }
|
|
|
$clearId = intval(is_object($recharge) ? ($recharge->clearId ?? 0) : ($recharge['clearId'] ?? 0));
|
|
|
if ($clearId > 0) {
|
|
|
$row['clearId'] = $clearId;
|
|
|
@@ -78,10 +84,91 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 选订单销账:充值单未落库 clearId 时,按客户+金额+时间匹配已付结账单
|
|
|
+ // 花店 xhGhsBalanceChange 禁止按金额模糊匹配,避免串到其它结账单
|
|
|
+ if (self::isFloristGhsBalanceChangeRow($row)) {
|
|
|
+ return $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 供货商侧 CustomBalanceChange:充值单未落库 clearId 时再按金额+时间匹配
|
|
|
return self::fillClearAuditByPaidClearMatch($row, $recharge ?? null);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 供货商帮充:CustomBalanceChange.relateId=CustomRecharge.id;
|
|
|
+ * 花店线上/帮充的 GhsBalanceChange.relateId=GhsRecharge.id(capitalType 常为 66 线上充)。
|
|
|
+ */
|
|
|
+ protected static function resolveCustomRechargeForBalanceRow(array $row)
|
|
|
+ {
|
|
|
+ $relateId = intval($row['relateId'] ?? 0);
|
|
|
+ if ($relateId <= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ $capitalType = intval($row['capitalType'] ?? 0);
|
|
|
+
|
|
|
+ if (self::isFloristGhsBalanceChangeRow($row) || self::isGhsSideRechargeCapitalType($capitalType)) {
|
|
|
+ $ghsRecharge = GhsRechargeClass::getById($relateId, true);
|
|
|
+ if (!empty($ghsRecharge)) {
|
|
|
+ return self::findCustomRechargeByGhsRecharge($ghsRecharge);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (self::isRechargeCapitalType($capitalType)) {
|
|
|
+ $customRecharge = CustomRechargeClass::getById($relateId, true);
|
|
|
+ if (!empty($customRecharge)) {
|
|
|
+ $linkedGhsRechargeId = intval(is_object($customRecharge)
|
|
|
+ ? ($customRecharge->ghsRechargeId ?? 0)
|
|
|
+ : ($customRecharge['ghsRechargeId'] ?? 0));
|
|
|
+ if ($linkedGhsRechargeId <= 0 || $linkedGhsRechargeId !== $relateId) {
|
|
|
+ return $customRecharge;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $ghsRecharge = GhsRechargeClass::getById($relateId, true);
|
|
|
+ if (!empty($ghsRecharge)) {
|
|
|
+ return self::findCustomRechargeByGhsRecharge($ghsRecharge);
|
|
|
+ }
|
|
|
+ return $customRecharge ?? null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 花店端 xhGhsBalanceChange:有 ghsId、无 customId */
|
|
|
+ protected static function isFloristGhsBalanceChangeRow(array $row)
|
|
|
+ {
|
|
|
+ return intval($row['ghsId'] ?? 0) > 0 && intval($row['customId'] ?? 0) <= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static function findCustomRechargeByGhsRecharge($ghsRecharge)
|
|
|
+ {
|
|
|
+ if (empty($ghsRecharge)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ $ghsRechargeId = intval(is_object($ghsRecharge) ? ($ghsRecharge->id ?? 0) : ($ghsRecharge['id'] ?? 0));
|
|
|
+ if ($ghsRechargeId > 0) {
|
|
|
+ $probe = new \bizGhs\custom\models\CustomRecharge();
|
|
|
+ if (method_exists($probe, 'hasAttribute') && $probe->hasAttribute('ghsRechargeId')) {
|
|
|
+ $linked = CustomRechargeClass::getByCondition(['ghsRechargeId' => $ghsRechargeId], true, null, 'id DESC');
|
|
|
+ if (!empty($linked)) {
|
|
|
+ return $linked;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $customId = intval(is_object($ghsRecharge) ? ($ghsRecharge->customId ?? 0) : ($ghsRecharge['customId'] ?? 0));
|
|
|
+ $ghsId = intval(is_object($ghsRecharge) ? ($ghsRecharge->ghsId ?? 0) : ($ghsRecharge['ghsId'] ?? 0));
|
|
|
+ $amount = bcadd((string)(is_object($ghsRecharge) ? ($ghsRecharge->amount ?? 0) : ($ghsRecharge['amount'] ?? 0)), '0', 2);
|
|
|
+ if ($customId <= 0 || $ghsId <= 0 || bccomp($amount, '0', 2) <= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ $where = [
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'ghsId' => $ghsId,
|
|
|
+ 'amount' => $amount,
|
|
|
+ ];
|
|
|
+ $payTime = is_object($ghsRecharge) ? ($ghsRecharge->payTime ?? '') : ($ghsRecharge['payTime'] ?? '');
|
|
|
+ if (!empty($payTime) && $payTime !== '0000-00-00 00:00:00') {
|
|
|
+ $where['payTime'] = $payTime;
|
|
|
+ }
|
|
|
+ return CustomRechargeClass::getByCondition($where, true, null, 'id DESC');
|
|
|
+ }
|
|
|
+
|
|
|
/** 写入流水/充值单时带上结账单(有字段才写,对照 hd 充值即带 settleId) */
|
|
|
public static function mergeClearAuditIntoRowData(array $data, array $audit)
|
|
|
{
|
|
|
@@ -141,6 +228,12 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
protected static function fillClearAuditByPaidClearMatch(array $row, $recharge = null)
|
|
|
{
|
|
|
$customId = intval($row['customId'] ?? 0);
|
|
|
+ if ($customId <= 0 && !empty($recharge)) {
|
|
|
+ $customId = intval(is_object($recharge) ? ($recharge->customId ?? 0) : ($recharge['customId'] ?? 0));
|
|
|
+ if ($customId > 0) {
|
|
|
+ $row['customId'] = $customId;
|
|
|
+ }
|
|
|
+ }
|
|
|
if ($customId <= 0) {
|
|
|
return $row;
|
|
|
}
|
|
|
@@ -211,6 +304,17 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
return in_array($capitalType, $ids, true);
|
|
|
}
|
|
|
|
|
|
+ /** 花店侧 xhGhsBalanceChange:relateId 为 GhsRecharge.id */
|
|
|
+ protected static function isGhsSideRechargeCapitalType($capitalType)
|
|
|
+ {
|
|
|
+ $capitalType = intval($capitalType);
|
|
|
+ $ids = [
|
|
|
+ dict::getDict('capitalType', 'customAskGhsRecharge', 'id'),
|
|
|
+ dict::getDict('capitalType', 'customAskGhsRechargeReturn', 'id'),
|
|
|
+ ];
|
|
|
+ return in_array($capitalType, $ids, true);
|
|
|
+ }
|
|
|
+
|
|
|
/** 结账类入账(relateId=结账单 id) */
|
|
|
protected static function isClearIncomeCapitalType($capitalType)
|
|
|
{
|