diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 266c9eb2..68462931 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -351,7 +351,7 @@ class StoreOrderRepository extends BaseRepository $merchantRepo = app()->make(MerchantRepository::class); $merchantRepo->merId = $order->mer_id; $merchantRepo->forceMargin = false; - [$_payPrice, $finance] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); + [$_payPrice, $finance, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); } $finance[] = [ 'order_id' => $order->order_id, diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index b532d111..27492c7b 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -672,7 +672,7 @@ class MerchantRepository extends BaseRepository $merchant = Merchant::find($this->merId); //商户保证金未完全缴纳且设置了自动扣除比例 if ($merchant['margin'] <= $merchant['paid_margin'] || ($this->forceMargin === false && $merchant['auto_margin_rate'] <= 0 && $merchant['auto_margin_rate'] > 100)) { - return [$income, $finance]; + return [$income, $finance, false]; } $rate = $this->forceMargin ? 100 : $merchant['auto_margin_rate']; //商户保证金未完全缴纳且设置了自动扣除比例 @@ -692,7 +692,7 @@ class MerchantRepository extends BaseRepository 'financial_record_sn' => $financeSn . $index ]; Queue::push(AutoMarginJob::class, ['merId' => $this->merId, 'margin' => $margin]); - return [$income, $finance]; + return [$income, $finance, true]; } diff --git a/app/listener/paySuccessOrder.php b/app/listener/paySuccessOrder.php index afb5c0a2..c26a96fe 100644 --- a/app/listener/paySuccessOrder.php +++ b/app/listener/paySuccessOrder.php @@ -55,12 +55,6 @@ class paySuccessOrder if ($entryMerchant['type_id'] == Merchant::TypeStore) { $merchantRate = systemConfig('commission_to_merchant_rate'); $merchantAmount = bcmul($this->totalAmount, (string)($merchantRate / 100), 2); - /** @var MerchantRepository $merchantRepo */ - $merchantRepo = app()->make(MerchantRepository::class); - $merchantRepo->merId = $entryMerId; - $merchantRepo->forceMargin = true; - [$merchantAmount, $this->finance] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index); - $this->index++; if ($merchantAmount > 0) { $this->finance[] = [ 'order_id' => $this->event['order']['order_id'], @@ -75,7 +69,17 @@ class paySuccessOrder 'financial_record_sn' => $this->financeSn . $this->index ]; $this->index++; - app()->make(MerchantRepository::class)->addLockMoney($entryMerId, 'order', $event['order']['order_id'], (float)$merchantAmount); + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo->merId = $entryMerId; + $merchantRepo->forceMargin = true; + [$merchantAmount, $this->finance, $increase] = $merchantRepo->autoMargin($merchantAmount, $event['order'], $this->finance, $this->financeSn, $this->index); + if ($increase) { + $this->index++; + } + if ($merchantAmount > 0) { + app()->make(MerchantRepository::class)->addLockMoney($entryMerId, 'order', $event['order']['order_id'], (float)$merchantAmount); + } } }