调试平台手续费分润

This commit is contained in:
luofei 2023-05-26 16:07:11 +08:00
parent d651d826d1
commit fb5af6e716
4 changed files with 73 additions and 1 deletions

View File

@ -1293,6 +1293,9 @@ class StoreRefundOrderRepository extends BaseRepository
'financial_type' => 'refund_charge',
'number' => $refundRate,
], $res->mer_id);
event('refund.after', compact('id', 'res'));
return $res;
}

View File

@ -691,7 +691,7 @@ class MerchantRepository extends BaseRepository
'mer_id' => $this->merId,
'financial_record_sn' => $financeSn . $index
];
Queue::push(AutoMarginJob::class, ['merId' => $this->merId, 'margin' => $margin]);
Queue::push(AutoMarginJob::class, ['merId' => $this->merId, 'margin' => $margin, 'orderId' => $order['order_id']]);
return [$income, $finance, true];
}

View File

@ -0,0 +1,68 @@
<?php
declare (strict_types=1);
namespace app\listener;
use app\common\dao\system\merchant\MerchantDao;
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;
/**
* 订单退款之后,退佣金
*/
class AfterRefund
{
public $refundOrder;
public function handle($event)
{
$this->refundOrder = $event['res'];
$financialRecords = FinancialRecord::getInstance()->where('order_id', $this->refundOrder['order_id'])->select();
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);
$this->saveFinanceRecord($financialRecord);
}
if ($financialRecord['financial_type'] == 'auto_margin') {
//佣金类型的扣除保证金
ServeOrder::getInstance()->where('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);
$merchant->ot_margin = $merchant->paid_margin;
if ($merchant->paid_margin <= 0) {
$merchant->is_margin = MerchantRepository::NeedMargin;
}
$merchant->save();
$this->saveFinanceRecord($financialRecord);
}
}
}
public function subMoney($financialRecord)
{
/** @var MerchantRepository $merchantRepository */
$merchantRepository = app()->make(MerchantRepository::class);
$merchantRepository->subLockMoney($financialRecord['mer_id'], 'order', $this->refundOrder['order_id'], (float)$financialRecord['number']);
}
public function saveFinanceRecord($financialRecord)
{
/** @var FinancialRecordRepository $financialRecordRepository */
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financialRecordRepository->dec([
'order_id' => $this->refundOrder->refund_order_id,
'order_sn' => $this->refundOrder->refund_order_sn,
'user_info' => $this->refundOrder->user->nickname,
'user_id' => $this->refundOrder->uid,
'type' => 1,
'financial_type' => $financialRecord['financial_type'] . '_refund',
'number' => $financialRecord['number'],
], $financialRecord['mer_id']);
}
}

View File

@ -43,6 +43,7 @@ class AutoMarginJob implements JobInterface
'pay_type' => ServeOrderRepository::PAY_TYPE_BALANCE,
'order_info' => json_encode($orderInfo,JSON_UNESCAPED_UNICODE),
'pay_price' => $data['margin'],
'store_order_id' => $data['orderId'],
];
$values['order_sn'] = app()->make(StoreOrderRepository::class)->getNewOrderId('cs');
$values['pay_time'] = date('y_m-d H:i:s', time());