1.压注记录修改为游玩记录
2.测试结算并测试 3.备份数据库
This commit is contained in:
@@ -37,7 +37,7 @@ class ChannelSettlementService
|
||||
'total_bet_amount' => $payload['total_bet_amount'],
|
||||
'total_payout_amount' => $payload['total_payout_amount'],
|
||||
'platform_profit_amount' => $payload['platform_profit_amount'],
|
||||
'status' => 1,
|
||||
'status' => 2,
|
||||
'remark' => $remark !== '' ? $remark : (($auto ? '自动' : '手动') . '渠道结算-CH' . $channelId),
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
@@ -54,9 +54,32 @@ class ChannelSettlementService
|
||||
if ($rows === []) {
|
||||
throw new \RuntimeException('生成待分红记录失败');
|
||||
}
|
||||
Db::name('agent_commission_record')->insertAll($rows);
|
||||
foreach ($rows as $row) {
|
||||
$adminId = intval($row['admin_id'] ?? 0);
|
||||
$amount = strval($row['commission_amount'] ?? '0.00');
|
||||
if ($adminId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$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) {
|
||||
AdminWalletService::creditCommission(
|
||||
$adminId,
|
||||
$channelId,
|
||||
$amount,
|
||||
'agent_commission_record',
|
||||
$commissionRecordId,
|
||||
$remark !== '' ? $remark : '超管结算自动发放分红',
|
||||
$operatorAdminId
|
||||
);
|
||||
}
|
||||
}
|
||||
// 已改为超管结算即发放,结算后不再保留渠道待分红余额。
|
||||
Db::name('channel')->where('id', $channelId)->update([
|
||||
'carryover_balance' => Db::raw('carryover_balance + ' . strval($payload['commission_amount'])),
|
||||
'carryover_balance' => '0.00',
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::commit();
|
||||
@@ -69,83 +92,7 @@ class ChannelSettlementService
|
||||
|
||||
public static function settleDividendByChannelAdmin(int $channelId, int $operatorAdminId, string $remark = ''): array
|
||||
{
|
||||
$channel = Db::name('channel')->where('id', $channelId)->find();
|
||||
if (!is_array($channel)) {
|
||||
return ['ok' => false, 'msg' => '渠道不存在'];
|
||||
}
|
||||
$carryover = strval($channel['carryover_balance'] ?? '0.00');
|
||||
if (bccomp($carryover, '0', 2) <= 0) {
|
||||
return ['ok' => false, 'msg' => '当前渠道没有分红余额,待下周期结算'];
|
||||
}
|
||||
$pendingRows = Db::name('agent_commission_record')
|
||||
->where('channel_id', $channelId)
|
||||
->where('status', 0)
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
if ($pendingRows === []) {
|
||||
return ['ok' => false, 'msg' => '当前渠道没有待分红记录,待下周期结算'];
|
||||
}
|
||||
$totalPending = '0.00';
|
||||
foreach ($pendingRows as $pendingRow) {
|
||||
$totalPending = bcadd($totalPending, strval($pendingRow['commission_amount'] ?? '0.00'), 2);
|
||||
}
|
||||
if (bccomp($carryover, $totalPending, 2) < 0) {
|
||||
return ['ok' => false, 'msg' => '渠道可分红余额不足,请联系超管核对结算'];
|
||||
}
|
||||
$now = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($pendingRows as $pendingRow) {
|
||||
$amount = strval($pendingRow['commission_amount'] ?? '0.00');
|
||||
$adminId = intval($pendingRow['admin_id'] ?? 0);
|
||||
if ($adminId <= 0 || bccomp($amount, '0', 2) <= 0) {
|
||||
continue;
|
||||
}
|
||||
AdminWalletService::creditCommission(
|
||||
$adminId,
|
||||
$channelId,
|
||||
$amount,
|
||||
'agent_commission_record',
|
||||
intval($pendingRow['id'] ?? 0),
|
||||
$remark !== '' ? $remark : '渠道分红结算入账'
|
||||
);
|
||||
}
|
||||
Db::name('agent_commission_record')
|
||||
->where('channel_id', $channelId)
|
||||
->where('status', 0)
|
||||
->update([
|
||||
'status' => 1,
|
||||
'settled_at' => $now,
|
||||
'update_time' => $now,
|
||||
'remark' => Db::raw("CONCAT(remark, ' | 渠道结算确认')"),
|
||||
]);
|
||||
Db::name('channel')->where('id', $channelId)->update([
|
||||
'carryover_balance' => bcsub($carryover, $totalPending, 2),
|
||||
'update_time' => $now,
|
||||
]);
|
||||
$periodIds = Db::name('agent_commission_record')->where('channel_id', $channelId)->where('status', 1)->column('settlement_period_id');
|
||||
if ($periodIds !== []) {
|
||||
foreach ($periodIds as $periodIdRaw) {
|
||||
$periodId = intval($periodIdRaw);
|
||||
if ($periodId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$left = intval(Db::name('agent_commission_record')->where('settlement_period_id', $periodId)->where('status', 0)->count());
|
||||
if ($left === 0) {
|
||||
Db::name('agent_settlement_period')->where('id', $periodId)->update([
|
||||
'status' => 2,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return ['ok' => false, 'msg' => $e->getMessage()];
|
||||
}
|
||||
return ['ok' => true, 'settled_amount' => $totalPending];
|
||||
return ['ok' => false, 'msg' => '当前流程为超管结算后自动发放,渠道管理员无需二次结算'];
|
||||
}
|
||||
|
||||
public static function settleAllDueChannels(int $operatorAdminId): array
|
||||
|
||||
Reference in New Issue
Block a user