添加支付费率扣除

This commit is contained in:
Dev
2026-10-27 18:10:51 +08:00
parent 20f9113d94
commit f53c142a56
14 changed files with 225 additions and 41 deletions
@@ -91,15 +91,42 @@ class DemandService
}
/**
* 计算扣除平台服务费后开发者实得金额
* @param mixed $amount 订单金额(元)
* 虚拟支付渠道费率。iOS 走苹果,其余终端按安卓费率
* @param string $platform android|ios
* @return string
*/
public static function getDeveloperIncome($amount): string
public static function getPayFeeRate($platform): string
{
$config = config('common.virtual_pay');
if (!is_array($config)) {
$config = [];
}
$isIos = $platform === 'ios';
$raw = $isIos ? ($config['ios_pay_fees'] ?? '0.12') : ($config['android_pay_fees'] ?? '0.01');
if (!is_numeric($raw) || $raw < 0) {
$raw = $isIos ? '0.12' : '0.01';
}
$rate = sprintf('%.4f', (float)$raw);
return bccomp($rate, '1', 4) > 0 ? '1.0000' : $rate;
}
/**
* 开发者实得 = 支付金额 - 平台服务费 - 安卓/iOS 支付费率
* @param mixed $amount 订单金额(元)
* @param string $platform android|ios
* @return string
*/
public static function getDeveloperIncome($amount, $platform = 'android'): string
{
$ratio = self::getPlatformCommissionRatio();
$payFee = self::getPayFeeRate($platform);
$remain = bcsub(bcsub('1', $ratio, 4), $payFee, 4);
if (bccomp($remain, '0', 4) < 0) {
$remain = '0';
}
return bcmul((string)$amount, bcsub('1', $ratio, 4), 2);
return bcmul((string)$amount, $remain, 2);
}
/**
@@ -630,7 +657,8 @@ class DemandService
$userId = $contract->demandBidding->user_id;
//开发者冻结金额增加
$demandOrder = OrderService::getDemandOrder($demand->parent_order_no, OrderService::ORDER_TYPE_FIRST_PAYMENT);
$amount = self::getDeveloperIncome($demandOrder->payment_amount);
$payPlatform = OrderPaymentService::where('order_no', $demandOrder->order_no)->order('id desc')->value('pay_platform');
$amount = self::getDeveloperIncome($demandOrder->payment_amount, $payPlatform ?: 'android');
$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);
@@ -667,7 +695,8 @@ class DemandService
$userId = $demand->winBidding->user_id;
//开发者冻结金额增加
$demandOrder = OrderService::getDemandOrder($demand->parent_order_no, OrderService::ORDER_TYPE_FINAL_PAYMENT);
$amount = self::getDeveloperIncome($demandOrder->payment_amount);
$payPlatform = OrderPaymentService::where('order_no', $demandOrder->order_no)->order('id desc')->value('pay_platform');
$amount = self::getDeveloperIncome($demandOrder->payment_amount, $payPlatform ?: 'android');
$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);
@@ -768,7 +797,15 @@ class DemandService
$demand->status = DemandService::STATUS_FINISHED;
$demand->settle_status = CommonService::SUCCESS;
$demand->save();
$amount = self::getDeveloperIncome($demand->demandContracts->total_amount ?? 0);
$amount = '0';
foreach ([OrderService::ORDER_TYPE_FIRST_PAYMENT, OrderService::ORDER_TYPE_FINAL_PAYMENT] as $orderType) {
$demandOrder = OrderService::getDemandOrder($demand->parent_order_no, $orderType);
if (!$demandOrder) {
continue;
}
$payPlatform = OrderPaymentService::where('order_no', $demandOrder->order_no)->order('id desc')->value('pay_platform');
$amount = bcadd($amount, self::getDeveloperIncome($demandOrder->payment_amount, $payPlatform ?: 'android'), 2);
}
//写入余额日志
$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);