|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace bizGhs\custom\classes;
|
|
|
|
|
|
+use bizGhs\ghs\classes\GhsBalanceChangeClass;
|
|
|
use bizGhs\ghs\classes\GhsRechargeClass;
|
|
|
use bizGhs\order\classes\OrderClearClass;
|
|
|
use bizHd\purchase\classes\PurchaseClearClass;
|
|
|
@@ -84,8 +85,20 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 花店 xhGhsBalanceChange 禁止按金额模糊匹配,避免串到其它结账单
|
|
|
+ // 花店 xhGhsBalanceChange:禁止金额模糊匹配;再尝试 GhsRecharge 直连
|
|
|
if (self::isFloristGhsBalanceChangeRow($row)) {
|
|
|
+ if (empty($recharge)) {
|
|
|
+ $ghsRecharge = GhsRechargeClass::getById($relateId, true);
|
|
|
+ if (!empty($ghsRecharge)) {
|
|
|
+ $recharge = self::findCustomRechargeByGhsRecharge($ghsRecharge);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($recharge)) {
|
|
|
+ $clearId = intval(is_object($recharge) ? ($recharge->clearId ?? 0) : ($recharge['clearId'] ?? 0));
|
|
|
+ if ($clearId > 0) {
|
|
|
+ return self::attachClearMetaFromClearId($row, $clearId);
|
|
|
+ }
|
|
|
+ }
|
|
|
return $row;
|
|
|
}
|
|
|
|
|
|
@@ -94,8 +107,8 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 供货商帮充:CustomBalanceChange.relateId=CustomRecharge.id;
|
|
|
- * 花店线上/帮充的 GhsBalanceChange.relateId=GhsRecharge.id(capitalType 常为 66 线上充)。
|
|
|
+ * 供货商帮充:CustomBalanceChange.relateId=CustomRecharge.id(无 ghsId 字段);
|
|
|
+ * 花店 xhGhsBalanceChange.relateId=GhsRecharge.id(有 ghsId)。
|
|
|
*/
|
|
|
protected static function resolveCustomRechargeForBalanceRow(array $row)
|
|
|
{
|
|
|
@@ -103,37 +116,29 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
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;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (self::isFloristGhsBalanceChangeRow($row)) {
|
|
|
$ghsRecharge = GhsRechargeClass::getById($relateId, true);
|
|
|
- if (!empty($ghsRecharge)) {
|
|
|
- return self::findCustomRechargeByGhsRecharge($ghsRecharge);
|
|
|
+ if (empty($ghsRecharge)) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- return $customRecharge ?? null;
|
|
|
+ return self::findCustomRechargeByGhsRecharge($ghsRecharge);
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ return CustomRechargeClass::getById($relateId, true);
|
|
|
}
|
|
|
|
|
|
- /** 花店端 xhGhsBalanceChange:有 ghsId、无 customId */
|
|
|
+ /** 花店端 xhGhsBalanceChange:有 ghsId;relateId 对应 GhsRecharge(非 CustomRecharge.id) */
|
|
|
protected static function isFloristGhsBalanceChangeRow(array $row)
|
|
|
{
|
|
|
- return intval($row['ghsId'] ?? 0) > 0 && intval($row['customId'] ?? 0) <= 0;
|
|
|
+ if (intval($row['ghsId'] ?? 0) <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (intval($row['customId'] ?? 0) <= 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $relateId = intval($row['relateId'] ?? 0);
|
|
|
+ return $relateId > 0 && !empty(GhsRechargeClass::getById($relateId, true));
|
|
|
}
|
|
|
|
|
|
protected static function findCustomRechargeByGhsRecharge($ghsRecharge)
|
|
|
@@ -141,6 +146,15 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
if (empty($ghsRecharge)) {
|
|
|
return null;
|
|
|
}
|
|
|
+ $customRechargeId = intval(is_object($ghsRecharge)
|
|
|
+ ? ($ghsRecharge->customRechargeId ?? 0)
|
|
|
+ : ($ghsRecharge['customRechargeId'] ?? 0));
|
|
|
+ if ($customRechargeId > 0) {
|
|
|
+ $byPair = CustomRechargeClass::getById($customRechargeId, true);
|
|
|
+ if (!empty($byPair)) {
|
|
|
+ return $byPair;
|
|
|
+ }
|
|
|
+ }
|
|
|
$ghsRechargeId = intval(is_object($ghsRecharge) ? ($ghsRecharge->id ?? 0) : ($ghsRecharge['id'] ?? 0));
|
|
|
if ($ghsRechargeId > 0) {
|
|
|
$probe = new \bizGhs\custom\models\CustomRecharge();
|
|
|
@@ -358,6 +372,35 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
$row->save(false);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 花店线上充:回写 xhGhsBalanceChange(relateId=GhsRecharge.id)
|
|
|
+ */
|
|
|
+ public static function patchClearAuditByGhsRechargeId($ghsRechargeId, $clearId, $clearSn, $clearAmount, $finalBalance = null)
|
|
|
+ {
|
|
|
+ $ghsRechargeId = intval($ghsRechargeId);
|
|
|
+ $clearId = intval($clearId);
|
|
|
+ if ($ghsRechargeId <= 0 || $clearId <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $row = GhsBalanceChangeClass::getByCondition([
|
|
|
+ 'relateId' => $ghsRechargeId,
|
|
|
+ 'io' => 1,
|
|
|
+ ], true, null, 'id DESC');
|
|
|
+ if (empty($row) || !method_exists($row, 'hasAttribute') || !$row->hasAttribute('clearId')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $row->clearId = $clearId;
|
|
|
+ $row->clearSn = (string)$clearSn;
|
|
|
+ $row->clearAmount = bcadd((string)$clearAmount, '0', 2);
|
|
|
+ if ($row->hasAttribute('giveAmount')) {
|
|
|
+ $row->giveAmount = '0.00';
|
|
|
+ }
|
|
|
+ if ($finalBalance !== null && $row->hasAttribute('balance')) {
|
|
|
+ $row->balance = $finalBalance;
|
|
|
+ }
|
|
|
+ $row->save(false);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static function exportData($respond, $mainId)
|
|
|
{
|