需求列表状态刷新优化

This commit is contained in:
Dev
2026-10-14 15:46:49 +08:00
parent a0149f5f93
commit 8eb253784a
7 changed files with 111 additions and 15 deletions
@@ -72,6 +72,36 @@ class DemandService
const BUTTON_CONFIRM_RECEIPT = 'confirmReceipt'; //确认收货
const BUTTON_DELIVER_GOODS = 'deliverGoods'; //开发者发货
/**
* 获取平台服务费比例(0~1),后台填写大于 1 时按百分比处理,如 10 表示 10%
* @return string
*/
public static function getPlatformCommissionRatio(): string
{
$ratio = config('site.platform_commission_ratio');
if (!is_numeric($ratio) || $ratio <= 0) {
return '0';
}
$ratio = (string)$ratio;
if (bccomp($ratio, '1', 4) > 0) {
$ratio = bcdiv($ratio, '100', 4);
}
return bccomp($ratio, '1', 4) > 0 ? '1' : bcadd($ratio, '0', 4);
}
/**
* 计算扣除平台服务费后开发者实得金额
* @param mixed $amount 订单金额(元)
* @return string
*/
public static function getDeveloperIncome($amount): string
{
$ratio = self::getPlatformCommissionRatio();
return bcmul((string)$amount, bcsub('1', $ratio, 4), 2);
}
/**
* 创建需求
*
@@ -600,8 +630,7 @@ class DemandService
$userId = $contract->demandBidding->user_id;
//开发者冻结金额增加
$demandOrder = OrderService::getDemandOrder($demand->parent_order_no, OrderService::ORDER_TYPE_FIRST_PAYMENT);
$ratio = (float)config('site.platform_commission_ratio');
$amount = $demandOrder->payment_amount * (1 - $ratio);
$amount = self::getDeveloperIncome($demandOrder->payment_amount);
$title = OrderService::ORDER_TYPE_MAP[$demandOrder->order_type] ?? '需求收益';
$log_res = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_FREEZE, $userId, $amount, $title . '-冻结金额增加', AccountLogService::TYPE_FREEZE, 0, AccountLogService::INC_EXP_INCREASE, $demandOrder->id);
AccountService::updateData($userId, 0, $amount, 0, 0, $log_res->id);
@@ -638,8 +667,7 @@ class DemandService
$userId = $demand->winBidding->user_id;
//开发者冻结金额增加
$demandOrder = OrderService::getDemandOrder($demand->parent_order_no, OrderService::ORDER_TYPE_FINAL_PAYMENT);
$ratio = (float)config('site.platform_commission_ratio');
$amount = $demandOrder->payment_amount * (1 - $ratio);
$amount = self::getDeveloperIncome($demandOrder->payment_amount);
$title = OrderService::ORDER_TYPE_MAP[$demandOrder->order_type] ?? '需求收益';
$log_res = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_FREEZE, $userId, $amount, $title . '-冻结金额增加', AccountLogService::TYPE_FREEZE, 0, AccountLogService::INC_EXP_INCREASE, $demandOrder->id);
AccountService::updateData($userId, 0, $amount, 0, 0, $log_res->id);
@@ -728,12 +756,11 @@ class DemandService
'order_status' => DemandService::STATUS_CONFIRM_RECEIPT,
'settle_status' => CommonService::ONGOING,
];
$ratio = (float)config('site.platform_commission_ratio');
Demands::with(['demandContracts', 'winBidding'])->where($where)->chunk(100, function ($demands) use ($ratio) {
Demands::with(['demandContracts', 'winBidding'])->where($where)->chunk(100, function ($demands) {
foreach ($demands as $demand) {
try {
//开启事务 抛出异常时自动回滚
DB::transaction(function () use ($demand, $ratio) {
DB::transaction(function () use ($demand) {
$userId = $demand->merchant->user_id;
$show_time = $demand->goodsInfo->show_time ? $demand->goodsInfo->show_time : $demand->goodsInfo->created_at;
Log::info('订单收益解冻:', ['show_time' => $show_time, 'unfreeze_time' => strtotime(date('Y-m-d', strtotime($show_time) + 3 * 3600) . ' 09:00')]);
@@ -741,7 +768,7 @@ class DemandService
$demand->status = DemandService::STATUS_FINISHED;
$demand->settle_status = CommonService::SUCCESS;
$demand->save();
$amount = ($demand->demandContracts->total_amount ?? 0) * (1 - $ratio);
$amount = self::getDeveloperIncome($demand->demandContracts->total_amount ?? 0);
//写入余额日志
$log_res = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_FREEZE, -$amount, '需求收益解冻-冻结扣除', AccountLogService::TYPE_UNFREEZE, 0, $demand->id, $demand->order_amount);
$log_res = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_AMOUNT, +$amount, '需求收益解冻-余额增加', AccountLogService::TYPE_UNFREEZE, 0, $demand->id, $demand->order_amount);