From a64abab901c167102d08616edd7ecb72709d6e73 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Mon, 5 Feb 2024 17:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E9=93=BE=E4=BF=9D=E8=AF=81?= =?UTF-8?q?=E9=87=91=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/store/order/StoreOrderOtherDao.php | 27 ++++++++++------- .../system/merchant/MerchantRepository.php | 29 +++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/common/dao/store/order/StoreOrderOtherDao.php b/app/common/dao/store/order/StoreOrderOtherDao.php index 2fe9f8b7..c93233db 100755 --- a/app/common/dao/store/order/StoreOrderOtherDao.php +++ b/app/common/dao/store/order/StoreOrderOtherDao.php @@ -836,16 +836,23 @@ class StoreOrderOtherDao extends BaseDao $financeDao->order->order_id = $model->refund_order_id; $financeDao->platformIn($refundTotal, 'supply_chain_refund', $model->mer_id); - // TODO 暂时不退保证金 -// if ($refundOrder->order->status == -1){ -// $margin = FinancialRecord::where('order_id', $refundOrder['order_id']) -// ->where('mer_id', $model->mer_id) -// ->where('financial_type', 'auto_margin') -// ->value('number'); -// if ($margin) { -// $financeDao->platformOut($margin, 'auto_margin_refund', $model->mer_id); -// } -// } + $marginRecord = FinancialRecord::where('order_id', $refundOrder['order_id']) + ->where('mer_id', $model->mer_id) + ->where('financial_type', 'auto_margin') + ->value('number'); + $marginRefunded = FinancialRecord::where('order_id', $refundOrder['order_id']) + ->where('mer_id', $model->mer_id) + ->where('financial_type', 'auto_margin_refund') + ->sum('number'); + if ($marginRecord > $marginRefunded) { + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo->forceMargin = false; + $merchantRepo->merId = $model->mer_id; + [$margin, $financeDao] = $merchantRepo->refundDeposit($refundTotal, $financeDao); + $merchantRepo->addLockMoney($model->mer_id, 'order', $refundOrder['order_id'], $margin); + } + $financeDao->save(); app()->make(MerchantRepository::class)->subLockMoney($model->mer_id, 'order', $refundOrder['order_id'], $refundTotal); diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index aee226c3..7925024d 100755 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -813,4 +813,33 @@ class MerchantRepository extends BaseRepository return [bcsub($income,$margin,2), $financeDao]; } + /** + * 自动扣除押金 + * @param $income + * @param FinancialDao $financeDao + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function refundDeposit($income, FinancialDao $financeDao) + { + $merchant = Merchant::find($this->merId); + $rate = $this->forceMargin ? 100 : $merchant['auto_margin_rate']; + $margin = bcmul($income, bcdiv($rate, 100,2), 2); + $merchant->paid_margin = bcsub($merchant->paid_margin, $margin, 2); + if ($merchant->paid_margin <= 0) { + return [bcsub($income,$margin,2), $financeDao]; + } + if ($merchant->paid_margin < $merchant['margin'] && $merchant->is_margin == 10) { + $merchant->is_margin = 1; + } + $merchant->ot_margin = $merchant->paid_margin; + if ($merchant->save() === false) { + throw new \Exception('merchant 保存出错', 500); + } + $financeDao->platformOut($margin, 'auto_margin_refund', $this->merId); + return [$margin, $financeDao]; + } + }