|
|
@@ -0,0 +1,432 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 批发客户来款分配销挂账(对齐零售 RechargeClass::complete + SettleClass::clearSettle)
|
|
|
+ *
|
|
|
+ * 【背景】挂账已并入净 balance 后,不能再走「clearDebtAmountReduce + 整单 remainDebtPrice=0」旧销账,
|
|
|
+ * 也不能「充值后 balance 必须 >0 才 useBalanceClear」。
|
|
|
+ * 【原则】
|
|
|
+ * 1. 写账前:ensureCustomMoneyReady + ensureGhsMoneyReady(见 AccountMoneyClass)
|
|
|
+ * 2. 来款先入账:balance += 本次金额(rechargeBalance / thirdPay)
|
|
|
+ * 3. 仅用「本次来款」作资金池 FIFO 销 debt=1 订单(末单可部分销,见 buildNeedClearMap)
|
|
|
+ * 4. confirmClear(['paymentSettleOnly'=>true]) 只改订单欠款
|
|
|
+ * 5. clearConsumeBalance(实销合计) 扣减净余额,避免余额与订单状态不一致
|
|
|
+ * 6. 回写充值单/流水 clearId、clearSn、clearAmount;列表 becomeBalance = amount - clearAmount
|
|
|
+ *
|
|
|
+ * 搜索关键词:ensure_before_recharge_clear、custom_ghs_recharge、custom_recharge_ghs_clear_action
|
|
|
+ */
|
|
|
+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'];
|
|
|
+
|
|
|
+ // 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 销单,再扣余额(见 applyPoolToDebtOrders)
|
|
|
+ $allocate = self::applyPoolToDebtOrders($custom, $ghs, $shop, $staff, $amount, [
|
|
|
+ 'remark' => $params['remark'] ?? '充值销账',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 4. 回写充值单、余额流水上的 clearId/clearAmount(供 becomeBalance 展示)
|
|
|
+ if (!empty($customRecharge) && !empty($allocate['clear'])) {
|
|
|
+ self::patchRechargeAudit($customRecharge, $respond['ghsRecharge'] ?? null, $allocate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $respond;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】花店线上充值支付成功后的销账(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'];
|
|
|
+
|
|
|
+ self::syncDebtFlags($custom, $ghs);
|
|
|
+
|
|
|
+ // thirdPay 已入账,此处只按「本次支付金额」销挂账,勿在 NoticeController 再调 useBalanceClear
|
|
|
+ $allocate = self::applyPoolToDebtOrders($custom, $ghs, $shop, null, $amount, [
|
|
|
+ 'remark' => '线上充值销账',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!empty($customRecharge) && !empty($allocate['clear'])) {
|
|
|
+ self::patchRechargeAudit($customRecharge, $ghsRecharge, $allocate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $allocate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】待付结账单 — 供货商确认「客户已转账」(OrderClearController::actionConfirmClear)。
|
|
|
+ * 【流程】rechargeBalance(结账单 actPrice) → confirmClear(paymentSettleOnly) → clearConsumeBalance(实销)
|
|
|
+ * 【替代】旧逻辑「充值 + confirmClear(clearDebt) + clearConsumeBalance(整单 actPrice)」会在合并后双计挂账。
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ // 从净余额扣掉实销金额(替代旧逻辑里对整单 actPrice 的 consume + clearDebt 双计)
|
|
|
+ if (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);
|
|
|
+ }
|
|
|
+ $allocate = [
|
|
|
+ 'clear' => $clear,
|
|
|
+ 'realClearAmount' => $realClearAmount,
|
|
|
+ 'clearId' => $clear->id ?? 0,
|
|
|
+ 'clearSn' => $clear->orderSn ?? '',
|
|
|
+ 'clearAmount' => $realClearAmount,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!empty($customRecharge)) {
|
|
|
+ self::patchRechargeAudit($customRecharge, $ghsRecharge ?? null, $allocate);
|
|
|
+ } else {
|
|
|
+ self::patchRechargeAuditByClear($custom, $ghs, $clear, $realClearAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'custom' => $custom,
|
|
|
+ 'ghs' => $ghs,
|
|
|
+ 'customRecharge' => $customRecharge,
|
|
|
+ 'allocate' => $allocate,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】用账户当前正余额 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' => '余额结账',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】加锁客户/供货商并执行挂账并入净余额(幂等)。
|
|
|
+ * 【校验】合并后双方 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];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】按本次来款池 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 【用途】用指定来款池金额销挂账:建结账单 → paymentSettleOnly 确认 → clearConsumeBalance。
|
|
|
+ * 【参数】$poolAmount 本次来款(充值额或正余额),不是账户历史累计余额。
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+
|
|
|
+ // 入账后须把「用于销单」的部分从 balance 扣回,净余额才与订单状态一致
|
|
|
+ if (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);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ $clearId = $allocate['clearId'] ?? 0;
|
|
|
+ $clearSn = $allocate['clearSn'] ?? '';
|
|
|
+ $clearAmount = $allocate['clearAmount'] ?? '0.00';
|
|
|
+
|
|
|
+ if (!empty($customRecharge)) {
|
|
|
+ if (self::modelHasAttr($customRecharge, 'clearId')) {
|
|
|
+ $customRecharge->clearId = $clearId;
|
|
|
+ $customRecharge->clearSn = $clearSn;
|
|
|
+ $customRecharge->clearAmount = $clearAmount;
|
|
|
+ $customRecharge->save(false, ['clearId', 'clearSn', 'clearAmount']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $relateId = $customRecharge->id ?? 0;
|
|
|
+ self::patchBalanceChangeRow(CustomBalanceChangeClass::class, $relateId, $clearId, $clearSn, $clearAmount);
|
|
|
+
|
|
|
+ if (!empty($ghsRecharge)) {
|
|
|
+ $gRelateId = $ghsRecharge->id ?? 0;
|
|
|
+ self::patchBalanceChangeRow(GhsBalanceChangeClass::class, $gRelateId, $clearId, $clearSn, $clearAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 = [])
|
|
|
+ {
|
|
|
+ $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';
|
|
|
+ }
|
|
|
+ $row->save(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected static function modelHasAttr($row, $attr)
|
|
|
+ {
|
|
|
+ return is_object($row) && method_exists($row, 'hasAttribute') && $row->hasAttribute($attr);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|