|
|
@@ -2,464 +2,42 @@
|
|
|
|
|
|
namespace bizGhs\custom\services;
|
|
|
|
|
|
-use biz\ghs\classes\GhsClass as BizGhsClass;
|
|
|
-use biz\shop\classes\ShopClass;
|
|
|
-use bizGhs\custom\classes\AccountMoneyClass;
|
|
|
-use bizGhs\custom\classes\CustomBalanceChangeClass;
|
|
|
-use bizGhs\custom\classes\CustomClass;
|
|
|
-use bizGhs\custom\classes\CustomRechargeClass;
|
|
|
-use bizGhs\ghs\classes\GhsBalanceChangeClass;
|
|
|
-use bizGhs\order\classes\OrderClearClass;
|
|
|
-use bizGhs\order\classes\OrderClass;
|
|
|
-use bizHd\purchase\classes\PurchaseClearClass;
|
|
|
-use common\components\util;
|
|
|
-
|
|
|
/**
|
|
|
- * 批发来款与销挂账(对齐 hd RechargeClass::complete,非照搬 ghs 旧三件套)
|
|
|
- *
|
|
|
- * ── 账户模型(合并后)──
|
|
|
- * 净 balance:正=有余额,负=待结。订单 remainDebtPrice 仍逐单记录待结。
|
|
|
- * 合并式:balance 已含历史挂账,勿再 clearDebtAmountReduce。
|
|
|
- *
|
|
|
- * ── hd 零售(对照)──
|
|
|
- * balance / balancePay 与订单欠款分开记;充值 balance += 来款;
|
|
|
- * 销单只改订单 remainDebtPrice,不再减 balance;
|
|
|
- * 流水一条:amount=来款,settleAmount=用于销单,balance=充值+销单后的最终值。
|
|
|
- *
|
|
|
- * ── ghs 应对齐的行为 ──
|
|
|
- * A. 来款充值销账(rechargeClear / 线上 thirdPay+allocate):
|
|
|
- * 来款已 rechargeBalance 入账 → FIFO 销单(仅改订单)→ 不再 clearConsumeBalance(否则 +1 又 -1)。
|
|
|
- * B. 用已有正余额销账(allocateFromExistingBalance):
|
|
|
- * 无新来款 → 销单后须 clearConsumeBalance 扣减 balance → 可记一条「结账」流水。
|
|
|
- * C. 待付结账单确认(linkedClearAfterRecharge):
|
|
|
- * 来款入账 + 按结账单销单 → 同 A,不二次扣 balance。
|
|
|
+ * 兼容层:批发充值销账已迁至 GhsRechargeSettleService,本类仅保留旧类名调用。
|
|
|
*
|
|
|
- * 搜索关键词:ensure_before_recharge_clear、custom_ghs_recharge、custom_recharge_ghs_clear_action
|
|
|
+ * @see GhsRechargeSettleService
|
|
|
*/
|
|
|
class CustomPaymentAllocateService
|
|
|
{
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】商家帮客户充值并自动按本次来款销挂账(app-ghs CustomController 充值清账)。
|
|
|
- * 【流程】ensure → rechargeBalance → applyPoolToDebtOrders → patchRechargeAudit
|
|
|
- * 【参数】$params 可含 remark、rechargeType(售后返充)
|
|
|
- */
|
|
|
public static function rechargeClear($custom, $amount, $shop, $staff, $payWay, $params = [])
|
|
|
{
|
|
|
- // 1. 挂账并入净余额(幂等)
|
|
|
- $pair = self::ensurePairReady($custom, null);
|
|
|
- $custom = $pair['custom'];
|
|
|
- $ghs = $pair['ghs'];
|
|
|
-
|
|
|
- // 作废待付结账单,避免充值后误确认旧单(实付130+优惠106 与本次充值100 混在一起)
|
|
|
- OrderClearClass::expireAwaitPayClears($custom->id ?? 0);
|
|
|
-
|
|
|
- // 2. 来款入账(balance += 本次充值额)
|
|
|
- $respond = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params);
|
|
|
- $custom = $respond['custom'] ?? $custom;
|
|
|
- $ghs = $respond['ghs'] ?? $ghs;
|
|
|
- $customRecharge = $respond['customRecharge'] ?? null;
|
|
|
-
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
-
|
|
|
- // 3. 仅用「本次充值额」FIFO 销单(只改订单,不二次扣 balance,对照 hd)
|
|
|
- $allocate = self::applyPoolToDebtOrders($custom, $ghs, $shop, $staff, $amount, [
|
|
|
- 'remark' => $params['remark'] ?? '充值销账',
|
|
|
- 'funding' => 'recharge',
|
|
|
- ]);
|
|
|
-
|
|
|
- // 4. 回写充值单、余额流水上的 clearId/clearAmount(供 becomeBalance 展示)
|
|
|
- if (!empty($customRecharge) && !empty($allocate['clear'])) {
|
|
|
- self::patchRechargeAudit($customRecharge, $respond['ghsRecharge'] ?? null, $allocate, $custom, $ghs);
|
|
|
- }
|
|
|
-
|
|
|
- return $respond;
|
|
|
+ return GhsRechargeSettleService::merchantRechargeWithAutoClear($custom, $amount, $shop, $staff, $payWay, $params);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】花店线上充值支付成功后的销账(CustomRechargeClass::thirdPay 末尾调用)。
|
|
|
- * 【注意】余额已在 thirdPay 写入,此处不再 recharge;NoticeController 勿再调 useBalanceClear。
|
|
|
- * 【参数】$amount 须与回调金额、本次来款池一致(通常为充值单 amount)
|
|
|
- */
|
|
|
public static function allocateAfterOnlinePay($custom, $ghs, $shop, $amount, $customRecharge, $ghsRecharge = null)
|
|
|
{
|
|
|
- $pair = self::ensurePairReady($custom, $ghs);
|
|
|
- $custom = $pair['custom'];
|
|
|
- $ghs = $pair['ghs'];
|
|
|
-
|
|
|
- OrderClearClass::expireAwaitPayClears($custom->id ?? 0);
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
-
|
|
|
- // thirdPay 已入账,此处只按「本次支付金额」销挂账,勿在 NoticeController 再调 useBalanceClear
|
|
|
- $allocate = self::applyPoolToDebtOrders($custom, $ghs, $shop, null, $amount, [
|
|
|
- 'remark' => '线上充值销账',
|
|
|
- 'funding' => 'recharge',
|
|
|
- ]);
|
|
|
-
|
|
|
- if (!empty($customRecharge) && !empty($allocate['clear'])) {
|
|
|
- self::patchRechargeAudit($customRecharge, $ghsRecharge, $allocate, $custom, $ghs);
|
|
|
- }
|
|
|
-
|
|
|
- return $allocate;
|
|
|
+ return GhsRechargeSettleService::onlinePayFifoClear($custom, $ghs, $shop, $amount, $customRecharge, $ghsRecharge);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】待付结账单 — 供货商确认「客户已转账」(OrderClearController::actionConfirmClear)。
|
|
|
- * 【流程】rechargeBalance(来款) → confirmClear(paymentSettleOnly)(不 clearConsumeBalance,对照 hd)
|
|
|
- */
|
|
|
public static function linkedClearAfterRecharge($custom, $ghs, $shop, $staff, $clear, $payWay, $customRecharge = null)
|
|
|
{
|
|
|
- $pair = self::ensurePairReady($custom, $ghs);
|
|
|
- $custom = $pair['custom'];
|
|
|
- $ghs = $pair['ghs'];
|
|
|
-
|
|
|
- $amount = $clear->actPrice ?? 0;
|
|
|
- if (bccomp($amount, '0', 2) <= 0) {
|
|
|
- util::fail('结账单金额有误');
|
|
|
- }
|
|
|
-
|
|
|
- // 来款按结账单实收金额入账
|
|
|
- if (empty($customRecharge)) {
|
|
|
- $respond = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay, [
|
|
|
- 'remark' => $clear->remark ?? '',
|
|
|
- ]);
|
|
|
- $custom = $respond['custom'];
|
|
|
- $ghs = $respond['ghs'];
|
|
|
- $customRecharge = $respond['customRecharge'] ?? null;
|
|
|
- $ghsRecharge = $respond['ghsRecharge'] ?? null;
|
|
|
- } else {
|
|
|
- $ghsRecharge = null;
|
|
|
- }
|
|
|
-
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
-
|
|
|
- // 只改订单 remainDebtPrice,不调 clearDebtAmountReduce(合并后挂账已在 balance 里)
|
|
|
- OrderClearClass::confirmClear($clear, $payWay, [
|
|
|
- 'skipCashMoney' => true,
|
|
|
- 'paymentSettleOnly' => true,
|
|
|
- ]);
|
|
|
-
|
|
|
- $realClearAmount = OrderClearClass::sumClearAmountByClearId($clear->id ?? 0);
|
|
|
- $payCap = bcadd((string)($clear->actPrice ?? '0'), '0', 2);
|
|
|
- if (bccomp($realClearAmount, $payCap, 2) > 0) {
|
|
|
- $realClearAmount = $payCap;
|
|
|
- }
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
- $allocate = [
|
|
|
- 'clear' => $clear,
|
|
|
- 'realClearAmount' => $realClearAmount,
|
|
|
- 'clearId' => $clear->id ?? 0,
|
|
|
- 'clearSn' => $clear->orderSn ?? '',
|
|
|
- 'clearAmount' => $realClearAmount,
|
|
|
- ];
|
|
|
-
|
|
|
- if (!empty($customRecharge)) {
|
|
|
- self::patchRechargeAudit($customRecharge, $ghsRecharge ?? null, $allocate, $custom, $ghs);
|
|
|
- } else {
|
|
|
- self::patchRechargeAuditByClear($custom, $ghs, $clear, $realClearAmount);
|
|
|
- }
|
|
|
-
|
|
|
- return [
|
|
|
- 'custom' => $custom,
|
|
|
- 'ghs' => $ghs,
|
|
|
- 'customRecharge' => $customRecharge,
|
|
|
- 'allocate' => $allocate,
|
|
|
- ];
|
|
|
+ return GhsRechargeSettleService::confirmClearBillWithIncoming($custom, $ghs, $shop, $staff, $clear, $payWay, $customRecharge);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】用账户当前正余额 FIFO 销挂账(原 OrderClearClass::useBalanceClear)。
|
|
|
- * 【区别】资金池 = 当前 balance 正数部分,不是某笔充值单金额;销完后 clearConsumeBalance。
|
|
|
- */
|
|
|
public static function allocateFromExistingBalance($custom, $ghs, $shop, $staff)
|
|
|
{
|
|
|
- $pair = self::ensurePairReady($custom, $ghs);
|
|
|
- $custom = $pair['custom'];
|
|
|
- $ghs = $pair['ghs'];
|
|
|
-
|
|
|
- $pool = $custom->balance ?? '0.00';
|
|
|
- if (bccomp($pool, '0', 2) <= 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- $allocate = self::applyPoolToDebtOrders($custom, $ghs, $shop, $staff, $pool, [
|
|
|
- 'remark' => '余额结账',
|
|
|
- 'funding' => 'existing_balance',
|
|
|
- ]);
|
|
|
-
|
|
|
- $realClearAmount = $allocate['realClearAmount'] ?? '0.00';
|
|
|
- if (bccomp($realClearAmount, '0', 2) > 0 && !empty($allocate['clear'])) {
|
|
|
- // 用已有正余额销账:无充值流水,仍记一条「结账」变动
|
|
|
- CustomClass::clearConsumeBalance($realClearAmount, $custom, $ghs, $shop, $staff, $allocate['clear']);
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
+ return GhsRechargeSettleService::consumePositiveBalanceFifo($custom, $ghs, $shop, $staff);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】加锁客户/供货商并执行挂账并入净余额(幂等)。
|
|
|
- * 【校验】合并后双方 balance 必须一致,否则 fail。
|
|
|
- *
|
|
|
- * @return array{custom: object, ghs: object}
|
|
|
- */
|
|
|
public static function ensurePairReady($custom, $ghs = null)
|
|
|
{
|
|
|
- if (empty($custom)) {
|
|
|
- util::fail('没有客户信息');
|
|
|
- }
|
|
|
- $customId = is_object($custom) ? ($custom->id ?? 0) : ($custom['id'] ?? 0);
|
|
|
- $custom = CustomClass::getLockById($customId);
|
|
|
- if (empty($custom)) {
|
|
|
- util::fail('没有找到客户');
|
|
|
- }
|
|
|
- AccountMoneyClass::ensureCustomMoneyReady($custom, true);
|
|
|
-
|
|
|
- $ghsId = $custom->ghsId ?? 0;
|
|
|
- if (empty($ghs)) {
|
|
|
- $ghs = BizGhsClass::getLockById($ghsId);
|
|
|
- }
|
|
|
- if (empty($ghs)) {
|
|
|
- util::fail('没有找到供货商');
|
|
|
- }
|
|
|
- AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
|
|
|
-
|
|
|
- if (floatval($custom->balance) != floatval($ghs->balance)) {
|
|
|
- util::fail('客户与供货商余额不一致,请联系管理员');
|
|
|
- }
|
|
|
-
|
|
|
- return ['custom' => $custom, 'ghs' => $ghs];
|
|
|
+ return GhsRechargeSettleService::lockAccountPair($custom, $ghs);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 【用途】按本次来款池 FIFO 选出待销订单(逻辑移植自 hd RechargeClass::complete 约 324–364 行)。
|
|
|
- * 【规则】按 id 升序累加 remainDebtPrice;超过池金额时仅末单 partial clear;部分商家 mainId 遇超池即 break。
|
|
|
- *
|
|
|
- * @return array<int, array{orderId:int, clearAmount:string, orderSn:string}>
|
|
|
- */
|
|
|
public static function buildNeedClearMap($customId, $poolAmount, $shop = null)
|
|
|
{
|
|
|
- $poolAmount = bcadd((string)$poolAmount, '0', 2);
|
|
|
- if (bccomp($poolAmount, '0', 2) <= 0) {
|
|
|
- return [];
|
|
|
- }
|
|
|
-
|
|
|
- $orderList = OrderClass::getAllByCondition(['customId' => $customId, 'debt' => 1], 'id asc', '*', null, true);
|
|
|
- if (empty($orderList)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
-
|
|
|
- $lastRemain = '0.00';
|
|
|
- $need = [];
|
|
|
- $hasOver = false;
|
|
|
- $mainId = is_object($shop) ? ($shop->mainId ?? 0) : 0;
|
|
|
-
|
|
|
- foreach ($orderList as $order) {
|
|
|
- $orderId = (int)($order->id ?? 0);
|
|
|
- $orderSn = $order->orderSn ?? '';
|
|
|
- $remainDebtPrice = bcadd((string)($order->remainDebtPrice ?? 0), '0', 2);
|
|
|
- if (bccomp($remainDebtPrice, '0', 2) <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $currentTotal = bcadd($lastRemain, $remainDebtPrice, 2);
|
|
|
- // 累计欠款超过来款池:首单超额时只销「池子剩余」部分(部分销末单)
|
|
|
- if (bccomp($currentTotal, $poolAmount, 2) > 0) {
|
|
|
- if (!$hasOver) {
|
|
|
- $lastClear = bcsub($poolAmount, $lastRemain, 2);
|
|
|
- if (bccomp($lastClear, '0', 2) > 0) {
|
|
|
- $need[] = [
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'clearAmount' => $lastClear,
|
|
|
- 'orderSn' => $orderSn,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- $hasOver = true;
|
|
|
- if (getenv('YII_ENV') == 'production' && in_array($mainId, [23390])) {
|
|
|
- break;
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $lastRemain = $currentTotal;
|
|
|
- $need[] = [
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'clearAmount' => $remainDebtPrice,
|
|
|
- 'orderSn' => $orderSn,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- return $need;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 用资金池 FIFO 销挂账。
|
|
|
- * funding=recharge:来款已入账,只改订单,不 clearConsumeBalance(对照 hd)。
|
|
|
- * funding=existing_balance:用账面正余额,销单后 clearConsumeBalance 扣减。
|
|
|
- */
|
|
|
- protected static function applyPoolToDebtOrders($custom, $ghs, $shop, $staff, $poolAmount, $options = [])
|
|
|
- {
|
|
|
- $customId = $custom->id ?? 0;
|
|
|
- $need = self::buildNeedClearMap($customId, $poolAmount, $shop);
|
|
|
- if (empty($need)) {
|
|
|
- return [
|
|
|
- 'clear' => null,
|
|
|
- 'realClearAmount' => '0.00',
|
|
|
- 'clearId' => 0,
|
|
|
- 'clearSn' => '',
|
|
|
- 'clearAmount' => '0.00',
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $staffId = $staff->id ?? 0;
|
|
|
- $staffName = $staff->name ?? '';
|
|
|
- $sjId = $shop->sjId ?? 0;
|
|
|
- $shopId = $shop->id ?? 0;
|
|
|
-
|
|
|
- $totalClear = '0.00';
|
|
|
- foreach ($need as $row) {
|
|
|
- $totalClear = bcadd($totalClear, $row['clearAmount'], 2);
|
|
|
- }
|
|
|
-
|
|
|
- // 新建销账结账单前,作废该客户其它待付结账单(与零售一致)
|
|
|
- OrderClearClass::expireAwaitPayClears($customId);
|
|
|
-
|
|
|
- $clearData = [
|
|
|
- 'customId' => $customId,
|
|
|
- 'ghsShopAdminId' => $staffId,
|
|
|
- 'ghsShopId' => $shopId,
|
|
|
- 'ghsShopAdminName' => $staffName,
|
|
|
- 'modifyPrice' => $totalClear,
|
|
|
- 'payWay' => 0,
|
|
|
- 'complete' => 0,
|
|
|
- 'remark' => $options['remark'] ?? '充值销账',
|
|
|
- ];
|
|
|
-
|
|
|
- $clear = OrderClearClass::clearWithAmountMap($clearData, $need, $sjId, $shopId);
|
|
|
- // 合并后:只更新订单欠款字段,不 reduce debtAmount
|
|
|
- OrderClearClass::confirmClear($clear, 0, [
|
|
|
- 'skipCashMoney' => true,
|
|
|
- 'paymentSettleOnly' => true,
|
|
|
- ]);
|
|
|
-
|
|
|
- $realClearAmount = OrderClearClass::sumClearAmountByClearId($clear->id ?? 0);
|
|
|
- $poolAmount = bcadd((string)$poolAmount, '0', 2);
|
|
|
- if (bccomp($realClearAmount, $poolAmount, 2) > 0) {
|
|
|
- util::fail('销账金额超过本次来款' . floatval($poolAmount) . '元,请检查订单待结或联系技术员');
|
|
|
- }
|
|
|
-
|
|
|
- $funding = $options['funding'] ?? 'recharge';
|
|
|
- // 仅「用已有正余额」销账时才扣 balance;来款充值销账的来款已在 rechargeBalance 记入 balance
|
|
|
- if ($funding === 'existing_balance' && bccomp($realClearAmount, '0', 2) > 0) {
|
|
|
- $custom = CustomClass::getLockById($custom->id ?? 0);
|
|
|
- $ghs = BizGhsClass::getLockById($ghs->id ?? 0);
|
|
|
- CustomClass::clearConsumeBalance($realClearAmount, $custom, $ghs, $shop, $staff, $clear);
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
- } else {
|
|
|
- self::syncDebtFlags($custom, $ghs);
|
|
|
- }
|
|
|
-
|
|
|
- return [
|
|
|
- 'clear' => $clear,
|
|
|
- 'realClearAmount' => $realClearAmount,
|
|
|
- 'clearId' => $clear->id ?? 0,
|
|
|
- 'clearSn' => $clear->orderSn ?? '',
|
|
|
- 'clearAmount' => $realClearAmount,
|
|
|
- 'custom' => $custom,
|
|
|
- 'ghs' => $ghs,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- /** 按净 balance 刷新 isDebt / ghs.debt 标记(负余额=仍有待结) */
|
|
|
- protected static function syncDebtFlags($custom, $ghs)
|
|
|
- {
|
|
|
- $bal = $custom->balance ?? '0.00';
|
|
|
- $custom->isDebt = bccomp($bal, '0', 2) < 0 ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
|
|
|
- $custom->save(false, ['isDebt']);
|
|
|
-
|
|
|
- if (!empty($ghs)) {
|
|
|
- $ghs->debt = bccomp($bal, '0', 2) < 0 ? 2 : 1;
|
|
|
- $ghs->save(false, ['debt']);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /** 回写 xhCustomRecharge、xhCustomBalanceChange 的 clearId/clearSn/clearAmount(需先执行 add_clear_audit_fields.sql) */
|
|
|
- protected static function patchRechargeAudit($customRecharge, $ghsRecharge, $allocate, $custom = null, $ghs = null)
|
|
|
- {
|
|
|
- $clearId = $allocate['clearId'] ?? 0;
|
|
|
- $clearSn = $allocate['clearSn'] ?? '';
|
|
|
- $clearAmount = $allocate['clearAmount'] ?? '0.00';
|
|
|
- $finalCustomBalance = is_object($custom) ? ($custom->balance ?? null) : null;
|
|
|
- $finalGhsBalance = is_object($ghs) ? ($ghs->balance ?? null) : null;
|
|
|
-
|
|
|
- if (!empty($customRecharge)) {
|
|
|
- if (self::modelHasAttr($customRecharge, 'clearId')) {
|
|
|
- $customRecharge->clearId = $clearId;
|
|
|
- $customRecharge->clearSn = $clearSn;
|
|
|
- $customRecharge->clearAmount = $clearAmount;
|
|
|
- if ($finalCustomBalance !== null) {
|
|
|
- $customRecharge->balance = $finalCustomBalance;
|
|
|
- }
|
|
|
- $customRecharge->save(false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $relateId = $customRecharge->id ?? 0;
|
|
|
- self::patchBalanceChangeRow(CustomBalanceChangeClass::class, $relateId, $clearId, $clearSn, $clearAmount, [], $finalCustomBalance);
|
|
|
-
|
|
|
- if (!empty($ghsRecharge)) {
|
|
|
- $gRelateId = $ghsRecharge->id ?? 0;
|
|
|
- self::patchBalanceChangeRow(GhsBalanceChangeClass::class, $gRelateId, $clearId, $clearSn, $clearAmount, [], $finalGhsBalance);
|
|
|
- if ($finalGhsBalance !== null) {
|
|
|
- $ghsRecharge->balance = $finalGhsBalance;
|
|
|
- $ghsRecharge->save(false, ['balance']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected static function patchRechargeAuditByClear($custom, $ghs, $clear, $clearAmount)
|
|
|
- {
|
|
|
- $clearId = $clear->id ?? 0;
|
|
|
- $clearSn = $clear->orderSn ?? '';
|
|
|
- self::patchBalanceChangeRow(CustomBalanceChangeClass::class, 0, $clearId, $clearSn, $clearAmount, [
|
|
|
- 'customId' => $custom->id ?? 0,
|
|
|
- 'io' => 1,
|
|
|
- 'limit' => 1,
|
|
|
- ]);
|
|
|
- self::patchBalanceChangeRow(GhsBalanceChangeClass::class, 0, $clearId, $clearSn, $clearAmount, [
|
|
|
- 'ghsId' => $ghs->id ?? 0,
|
|
|
- 'io' => 1,
|
|
|
- 'limit' => 1,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- protected static function patchBalanceChangeRow($class, $relateId, $clearId, $clearSn, $clearAmount, $extraWhere = [], $finalBalance = null)
|
|
|
- {
|
|
|
- $where = array_merge(['io' => 1], $extraWhere);
|
|
|
- if ($relateId > 0) {
|
|
|
- $where['relateId'] = $relateId;
|
|
|
- }
|
|
|
- $row = $class::getByCondition($where, true, null, 'id DESC');
|
|
|
- if (empty($row) || !self::modelHasAttr($row, 'clearId')) {
|
|
|
- return;
|
|
|
- }
|
|
|
- $row->clearId = $clearId;
|
|
|
- $row->clearSn = $clearSn;
|
|
|
- $row->clearAmount = $clearAmount;
|
|
|
- if (self::modelHasAttr($row, 'giveAmount')) {
|
|
|
- $row->giveAmount = '0.00';
|
|
|
- }
|
|
|
- // 流水余额列展示充值+销账后的净余额(与 hd 单条充值流水一致)
|
|
|
- if ($finalBalance !== null && self::modelHasAttr($row, 'balance')) {
|
|
|
- $row->balance = $finalBalance;
|
|
|
- }
|
|
|
- $row->save(false);
|
|
|
- }
|
|
|
-
|
|
|
- protected static function modelHasAttr($row, $attr)
|
|
|
- {
|
|
|
- return is_object($row) && method_exists($row, 'hasAttribute') && $row->hasAttribute($attr);
|
|
|
+ return GhsRechargeSettleService::planFifoByPool($customId, $poolAmount);
|
|
|
}
|
|
|
|
|
|
}
|