1.优化充值跳转链接的问题
2.优化后台渠道管理页面的显示样式
This commit is contained in:
@@ -9,8 +9,16 @@ use Throwable;
|
||||
|
||||
class ChannelSettlementService
|
||||
{
|
||||
public static function settleBySuperAdmin(int $channelId, int $operatorAdminId, string $remark = '', bool $auto = false): array
|
||||
{
|
||||
/**
|
||||
* @param array<int, string>|null $handlingFeeByAdmin admin_id => handling fee
|
||||
*/
|
||||
public static function settleBySuperAdmin(
|
||||
int $channelId,
|
||||
int $operatorAdminId,
|
||||
string $remark = '',
|
||||
bool $auto = false,
|
||||
?array $handlingFeeByAdmin = null
|
||||
): array {
|
||||
$channel = Db::name('channel')->where('id', $channelId)->find();
|
||||
if (!is_array($channel)) {
|
||||
return ['ok' => false, 'msg' => __('Channel not found')];
|
||||
@@ -19,6 +27,7 @@ class ChannelSettlementService
|
||||
if (is_string($payload)) {
|
||||
return ['ok' => false, 'msg' => $payload];
|
||||
}
|
||||
$defaultFee = bcadd(strval($channel['settlement_handling_fee'] ?? '0'), '0', 2);
|
||||
$settlementNo = self::generateAgentSettlementNo($auto ? 'A' : 'M', $channelId, intval($payload['period_end_ts']));
|
||||
if (Db::name('agent_settlement_period')->where('settlement_no', $settlementNo)->value('id')) {
|
||||
return ['ok' => false, 'msg' => __('Settlement number conflict, please retry')];
|
||||
@@ -26,7 +35,9 @@ class ChannelSettlementService
|
||||
$distributions = AdminCommissionDistributionService::distributeChannelCommission(
|
||||
$channelId,
|
||||
strval($payload['commission_amount']),
|
||||
strval($payload['calc_base_amount'])
|
||||
strval($payload['calc_base_amount']),
|
||||
$defaultFee,
|
||||
$handlingFeeByAdmin
|
||||
);
|
||||
if ($distributions === []) {
|
||||
return ['ok' => false, 'msg' => __('No channel root agent configured for commission distribution')];
|
||||
@@ -58,20 +69,21 @@ class ChannelSettlementService
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$adminId = intval($row['admin_id'] ?? 0);
|
||||
$amount = strval($row['commission_amount'] ?? '0.00');
|
||||
$netAmount = strval($row['net_commission_amount'] ?? '0.00');
|
||||
if ($adminId <= 0) {
|
||||
continue;
|
||||
}
|
||||
unset($row['net_commission_amount']);
|
||||
$row['status'] = 1;
|
||||
$row['settled_at'] = $now;
|
||||
$row['remark'] = strval($row['remark'] ?? '') . ' | 超管结算直接发放';
|
||||
$row['update_time'] = $now;
|
||||
$commissionRecordId = intval(Db::name('agent_commission_record')->insertGetId($row));
|
||||
if (bccomp($amount, '0.00', 2) > 0) {
|
||||
if (bccomp($netAmount, '0.00', 2) > 0) {
|
||||
AdminWalletService::creditCommission(
|
||||
$adminId,
|
||||
$channelId,
|
||||
$amount,
|
||||
$netAmount,
|
||||
'agent_commission_record',
|
||||
$commissionRecordId,
|
||||
$remark !== '' ? $remark : '超管结算自动发放分红',
|
||||
@@ -97,9 +109,16 @@ class ChannelSettlementService
|
||||
return ['ok' => false, 'msg' => __('This flow pays commissions automatically after super admin settlement; channel admin does not need to settle again')];
|
||||
}
|
||||
|
||||
public static function settleAllDueChannels(int $operatorAdminId, bool $respectCycle = true): array
|
||||
public static function settleAllDueChannels(int $operatorAdminId, bool $respectCycle = true, ?array $channelIds = null): array
|
||||
{
|
||||
$channels = Db::name('channel')->where('status', 1)->select()->toArray();
|
||||
$query = Db::name('channel')->where('status', 1);
|
||||
if ($channelIds !== null) {
|
||||
if ($channelIds === []) {
|
||||
return ['ok_count' => 0, 'failed' => []];
|
||||
}
|
||||
$query->whereIn('id', $channelIds);
|
||||
}
|
||||
$channels = $query->select()->toArray();
|
||||
$ok = 0;
|
||||
$failed = [];
|
||||
$now = time();
|
||||
@@ -191,10 +210,12 @@ class ChannelSettlementService
|
||||
'calc_base_amount' => $commission['calc_base_amount'],
|
||||
'commission_amount' => $commission['commission_amount'],
|
||||
'agent_mode' => $mode,
|
||||
'settlement_handling_fee' => bcadd(strval($row['settlement_handling_fee'] ?? '0'), '0', 2),
|
||||
'commission_split' => AdminCommissionDistributionService::buildSplitPreview(
|
||||
$channelId,
|
||||
$commission['commission_amount'],
|
||||
$commission['calc_base_amount']
|
||||
$commission['calc_base_amount'],
|
||||
bcadd(strval($row['settlement_handling_fee'] ?? '0'), '0', 2)
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -332,7 +353,8 @@ class ChannelSettlementService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{admin_id:int,commission_amount:string,commission_rate:string,calc_base_amount:string}> $distributions
|
||||
* @param array<int, array{admin_id:int,commission_amount:string,commission_rate:string,calc_base_amount:string,handling_fee:string,net_commission_amount:string}> $distributions
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private static function buildCommissionRowsFromDistribution(array $distributions, int $channelId, int $periodId, string $remark, int $now): array
|
||||
{
|
||||
@@ -350,6 +372,8 @@ class ChannelSettlementService
|
||||
'commission_rate' => strval($dist['commission_rate'] ?? '0.0000'),
|
||||
'calc_base_amount' => strval($dist['calc_base_amount'] ?? '0.00'),
|
||||
'commission_amount' => $amount,
|
||||
'handling_fee' => strval($dist['handling_fee'] ?? '0.00'),
|
||||
'net_commission_amount' => strval($dist['net_commission_amount'] ?? '0.00'),
|
||||
'status' => 0,
|
||||
'settled_at' => null,
|
||||
'remark' => $remark . ' | 树形分红实发',
|
||||
|
||||
Reference in New Issue
Block a user