调整订单退款的错误
This commit is contained in:
parent
96255e2b0e
commit
f3fbb46b49
@ -17,6 +17,7 @@ namespace app\common\repositories\store\order;
|
||||
use app\common\dao\store\order\StoreRefundOrderDao;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\system\merchant\FinancialRecord;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||
@ -1245,6 +1246,8 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
$refundRate = bcadd($refundRate, $_refundRate, 2);
|
||||
}
|
||||
$refundPriceAll = bcadd($refundPriceAll, $refundPrice, 2);
|
||||
$margin = FinancialRecord::getInstance()->where('mer_id', $res->mer_id)->where('order_sn', $item['sn'])->where('financial_type', 'auto_margin')->value('number');
|
||||
$refundPrice = bcsub($refundPrice, $margin, 2);
|
||||
|
||||
try {
|
||||
$orderType = (isset($item['presell']) && $item['presell']) ? 'presell' : 'order';
|
||||
|
@ -9,6 +9,7 @@ use app\common\model\system\merchant\FinancialRecord;
|
||||
use app\common\model\system\serve\ServeOrder;
|
||||
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
@ -32,12 +33,23 @@ class AfterRefund
|
||||
foreach ($financialRecords as $financialRecord) {
|
||||
if (in_array($financialRecord['financial_type'], ['commission_to_cloud_warehouse', 'commission_to_entry_merchant', 'commission_to_service_team', 'commission_to_village', 'commission_to_town', ])) {
|
||||
//佣金类型的退还佣金
|
||||
$this->subMoney($financialRecord);
|
||||
if ($financialRecord['financial_type'] == 'commission_to_entry_merchant') {
|
||||
//入口店铺的佣金,如果有保证金,不退佣金
|
||||
$isMargin = $this->isMargin($financialRecords, $financialRecord['mer_id']);
|
||||
if (!$isMargin) {
|
||||
$this->subMoney($financialRecord);
|
||||
}
|
||||
} else {
|
||||
$this->subMoney($financialRecord);
|
||||
}
|
||||
$this->saveFinanceRecord($financialRecord);
|
||||
}
|
||||
if (in_array($financialRecord['financial_type'], ['order_true', 'commission_to_cloud_warehouse', 'commission_to_entry_merchant', 'commission_to_service_team', 'commission_to_village', 'commission_to_town',])) {
|
||||
$this->checkBill($financialRecord['mer_id'], $financialRecord['order_id']);
|
||||
}
|
||||
if ($financialRecord['financial_type'] == 'auto_margin') {
|
||||
Log::info("refundMargin, mer_id: {$financialRecord['mer_id']}, money: {$financialRecord['number']}");
|
||||
//佣金类型的扣除保证金
|
||||
//保证金类型的扣除保证金
|
||||
ServeOrder::getInstance()->where('store_order_id', $financialRecord['order_id'])->update(['is_del' => 1]);
|
||||
$merchant = app()->make(MerchantDao::class)->get($financialRecord['mer_id']);
|
||||
$merchant->paid_margin = max(bcsub($merchant['paid_margin'], $financialRecord['number'], 2), 0);
|
||||
@ -46,13 +58,47 @@ class AfterRefund
|
||||
$merchant->is_margin = MerchantRepository::NeedMargin;
|
||||
}
|
||||
$merchant->save();
|
||||
$this->addMoney($financialRecord);
|
||||
$this->saveFinanceRecord($financialRecord);
|
||||
}
|
||||
}
|
||||
Log::info('refundCommissionEnd');
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有保证金
|
||||
* @param $financialRecords
|
||||
* @param $merId
|
||||
* @return bool
|
||||
*/
|
||||
public function isMargin($financialRecords, $merId)
|
||||
{
|
||||
$bool = false;
|
||||
foreach ($financialRecords as $financialRecord) {
|
||||
if ($financialRecord['mer_id'] == $merId && $financialRecord['financial_type'] == 'auto_margin') {
|
||||
$bool = true;
|
||||
}
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单资金在冻结期内产生了退款,需要检查是否有未结算的资金,如果有,需要退还给商家
|
||||
* @param $merId
|
||||
* @param $orderId
|
||||
*/
|
||||
public function checkBill($merId, $orderId)
|
||||
{
|
||||
/** @var UserBillRepository $make */
|
||||
$make = app()->make(UserBillRepository::class);
|
||||
$bill = $make->search(['category' => 'mer_computed_money', 'type' => 'order', 'mer_id' => $merId, 'link_id' => $orderId, 'status' => 0])->find();
|
||||
if ($bill) {
|
||||
$merchant = app()->make(MerchantRepository::class);
|
||||
$merchant->addMoney($bill->mer_id, $bill->number);
|
||||
$bill->status = 1;
|
||||
$bill->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function subMoney($financialRecord)
|
||||
{
|
||||
Log::info("refundCommission, mer_id: {$financialRecord['mer_id']}, money: {$financialRecord['number']}");
|
||||
@ -61,14 +107,6 @@ class AfterRefund
|
||||
$merchantRepository->subLockMoney($financialRecord['mer_id'], 'order', $this->refundOrder['order_id'], (float)$financialRecord['number']);
|
||||
}
|
||||
|
||||
public function addMoney($financialRecord)
|
||||
{
|
||||
Log::info("refundCommission, mer_id: {$financialRecord['mer_id']}, money: {$financialRecord['number']}");
|
||||
/** @var MerchantRepository $merchantRepository */
|
||||
$merchantRepository = app()->make(MerchantRepository::class);
|
||||
$merchantRepository->addMoney($financialRecord['mer_id'], (float)$financialRecord['number']);
|
||||
}
|
||||
|
||||
public function saveFinanceRecord($financialRecord)
|
||||
{
|
||||
/** @var FinancialRecordRepository $financialRecordRepository */
|
||||
|
Loading…
x
Reference in New Issue
Block a user