|
|
@@ -141,6 +141,18 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
return $relateId > 0 && !empty(GhsRechargeClass::getById($relateId, true));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据 xhGhsRecharge.customRechargeId 取成对的 xhCustomRecharge。
|
|
|
+ *
|
|
|
+ * 一次充值应对写两张充值单并互相关联(linkCustomAndGhsRecharge / 花店建单):
|
|
|
+ * - 结账单 clearId 写在 CustomRecharge 上
|
|
|
+ * - 花店 GhsBalanceChange.relateId = GhsRecharge.id,只能通过 customRechargeId 找到 CustomRecharge
|
|
|
+ *
|
|
|
+ * 若 customRechargeId 为空或查无记录,视为写入阶段脏数据,不做金额/时间猜测匹配。
|
|
|
+ *
|
|
|
+ * @param object|array $ghsRecharge
|
|
|
+ * @return object|null
|
|
|
+ */
|
|
|
protected static function findCustomRechargeByGhsRecharge($ghsRecharge)
|
|
|
{
|
|
|
if (empty($ghsRecharge)) {
|
|
|
@@ -149,42 +161,10 @@ class CustomBalanceChangeClass extends BaseClass
|
|
|
$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();
|
|
|
- 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) {
|
|
|
+ if ($customRechargeId <= 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') {
|
|
|
- $withPayTime = array_merge($where, ['payTime' => $payTime]);
|
|
|
- $matched = CustomRechargeClass::getByCondition($withPayTime, true, null, 'id DESC');
|
|
|
- if (!empty($matched)) {
|
|
|
- return $matched;
|
|
|
- }
|
|
|
- }
|
|
|
- return CustomRechargeClass::getByCondition($where, true, null, 'id DESC');
|
|
|
+ return CustomRechargeClass::getById($customRechargeId, true);
|
|
|
}
|
|
|
|
|
|
/** 写入流水/充值单时带上结账单(有字段才写,对照 hd 充值即带 settleId) */
|