优化数据归属问题
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\admin\controller;
|
||||
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\service\ChannelSettlementService;
|
||||
use support\think\Db;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
@@ -16,7 +17,7 @@ class Channel extends Backend
|
||||
/**
|
||||
* 预览接口与手动结算共用「手动结算」按钮权限(避免额外菜单节点)
|
||||
*/
|
||||
protected array $noNeedPermission = ['manualSettlePreview', 'channelAdminShareList', 'saveChannelAdminShare'];
|
||||
protected array $noNeedPermission = ['manualSettlePreview', 'channelAdminShareList', 'saveChannelAdminShare', 'batchSettlePending', 'settleStats'];
|
||||
|
||||
/**
|
||||
* Channel模型对象
|
||||
@@ -314,7 +315,7 @@ class Channel extends Backend
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
$payload = $this->buildManualSettlePayload($row->toArray());
|
||||
$payload = ChannelSettlementService::buildSettlePayload($row->toArray());
|
||||
if (is_string($payload)) {
|
||||
return $this->error($payload);
|
||||
}
|
||||
@@ -611,63 +612,80 @@ class Channel extends Backend
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
$remark = (string) $request->post('remark', '');
|
||||
$remark = trim((string) $request->post('remark', ''));
|
||||
|
||||
$payload = $this->buildManualSettlePayload($row->toArray());
|
||||
if (is_string($payload)) {
|
||||
return $this->error($payload);
|
||||
}
|
||||
|
||||
$settlementNo = $payload['settlement_no'];
|
||||
if (Db::name('agent_settlement_period')->where('settlement_no', $settlementNo)->value('id')) {
|
||||
return $this->error('结算单号已存在,请稍后重试');
|
||||
}
|
||||
|
||||
$shareRows = $this->resolveCommissionSharesForChannel((int) $row['id']);
|
||||
if ($shareRows === []) {
|
||||
return $this->error('渠道下无可用管理员分配比例,无法生成佣金记录');
|
||||
}
|
||||
|
||||
$now = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$periodId = (int) Db::name('agent_settlement_period')->insertGetId([
|
||||
'settlement_no' => $settlementNo,
|
||||
'period_start_at' => $payload['period_start_ts'],
|
||||
'period_end_at' => $payload['period_end_ts'],
|
||||
'total_bet_amount' => $payload['total_bet_amount'],
|
||||
'total_payout_amount' => $payload['total_payout_amount'],
|
||||
'platform_profit_amount' => $payload['platform_profit_amount'],
|
||||
'status' => 2,
|
||||
'remark' => trim($remark) !== '' ? $remark : ('手动结算-渠道#' . $row['id'] . '-' . $row['name']),
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
|
||||
$commissionRows = $this->buildCommissionRowsForSplit(
|
||||
$shareRows,
|
||||
(int) $row['id'],
|
||||
$periodId,
|
||||
(string) $payload['calc_base_amount'],
|
||||
(string) $payload['commission_amount'],
|
||||
trim($remark) !== '' ? $remark : ('手动结算佣金-CH' . $row['id']),
|
||||
$now
|
||||
);
|
||||
if ($commissionRows === []) {
|
||||
throw new \RuntimeException('分配比例拆分失败,未生成佣金记录');
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
$res = ChannelSettlementService::settleBySuperAdmin((int) $row['id'], intval($this->auth->id), $remark, false);
|
||||
if (($res['ok'] ?? false) !== true) {
|
||||
return $this->error((string) ($res['msg'] ?? '结算失败'));
|
||||
}
|
||||
Db::name('agent_commission_record')->insertAll($commissionRows);
|
||||
|
||||
Db::name('channel')->where('id', $row['id'])->update([
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
return $this->success('超管结算完成,渠道分红余额已入账');
|
||||
}
|
||||
$res = ChannelSettlementService::settleDividendByChannelAdmin((int) $row['id'], intval($this->auth->id), $remark);
|
||||
if (($res['ok'] ?? false) !== true) {
|
||||
return $this->error((string) ($res['msg'] ?? '结算失败'));
|
||||
}
|
||||
return $this->success('渠道分红已结算完成');
|
||||
}
|
||||
|
||||
return $this->success('手动结算已完成,已生成结算周期与佣金记录');
|
||||
/**
|
||||
* 超管批量结算全部待结算渠道(可作为“提前结算”入口)
|
||||
*/
|
||||
public function batchSettlePending(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
$res = ChannelSettlementService::settleAllDueChannels(intval($this->auth->id));
|
||||
return $this->success('批量结算完成', $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道结算统计卡片
|
||||
*/
|
||||
public function settleStats(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$query = Db::name('channel');
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$query->where('id', 'in', $this->currentChannelIds ?: [0]);
|
||||
}
|
||||
$rows = $query->field(['id', 'status', 'carryover_balance'])->select()->toArray();
|
||||
$total = count($rows);
|
||||
$enabled = 0;
|
||||
$disabled = 0;
|
||||
$carryoverPositiveCount = 0;
|
||||
$carryoverTotal = '0.00';
|
||||
$carryoverPositiveTotal = '0.00';
|
||||
foreach ($rows as $row) {
|
||||
$status = intval($row['status'] ?? 0);
|
||||
if ($status === 1) {
|
||||
$enabled++;
|
||||
} else {
|
||||
$disabled++;
|
||||
}
|
||||
$carry = bcadd(strval($row['carryover_balance'] ?? '0'), '0', 2);
|
||||
$carryoverTotal = bcadd($carryoverTotal, $carry, 2);
|
||||
if (bccomp($carry, '0', 2) > 0) {
|
||||
$carryoverPositiveCount++;
|
||||
$carryoverPositiveTotal = bcadd($carryoverPositiveTotal, $carry, 2);
|
||||
}
|
||||
}
|
||||
return $this->success('', [
|
||||
'channel_total' => $total,
|
||||
'enabled_count' => $enabled,
|
||||
'disabled_count' => $disabled,
|
||||
'carryover_positive_count' => $carryoverPositiveCount,
|
||||
'carryover_total' => $carryoverTotal,
|
||||
'carryover_positive_total' => $carryoverPositiveTotal,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -251,9 +251,27 @@ class Rule extends Backend
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($rules as $idx => $rule) {
|
||||
$title = $rule['title'] ?? '';
|
||||
if (is_string($title) && $title !== '') {
|
||||
$rules[$idx]['title'] = $this->menuTitleToZh($title);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->assembleTree ? $this->tree->assembleChild($rules) : $rules;
|
||||
}
|
||||
|
||||
private function menuTitleToZh(string $title): string
|
||||
{
|
||||
static $zhMap = null;
|
||||
if (!is_array($zhMap)) {
|
||||
$mapFile = app_path() . '/common/lang/zh-cn/admin_rule_title.php';
|
||||
$loaded = is_file($mapFile) ? include $mapFile : [];
|
||||
$zhMap = is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
return isset($zhMap[$title]) && is_string($zhMap[$title]) ? $zhMap[$title] : $title;
|
||||
}
|
||||
|
||||
private function autoAssignPermission(int $id, int $pid): void
|
||||
{
|
||||
$groups = AdminGroup::where('rules', '<>', '*')->select();
|
||||
|
||||
@@ -43,7 +43,7 @@ class UserNoticeRead extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -60,4 +60,25 @@ class UserNoticeRead extends Backend
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可见的管理员ID集合(本人 + 下级角色组内管理员)
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function scopedAdminIds(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$groupIds = $this->auth->getAdminChildGroups();
|
||||
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
||||
$adminIds[] = $this->auth->id;
|
||||
$adminIds = array_map(static fn($id) => intval(strval($id)), $adminIds);
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds, static fn($id) => $id > 0)));
|
||||
return $adminIds === [] ? [0] : $adminIds;
|
||||
}
|
||||
}
|
||||
|
||||
268
app/admin/controller/order/AdminWithdrawOrder.php
Normal file
268
app/admin/controller/order/AdminWithdrawOrder.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\order;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\service\AdminWalletService;
|
||||
use support\think\Db;
|
||||
use support\Response;
|
||||
use Throwable;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
/**
|
||||
* 管理员提现记录(审核)
|
||||
*/
|
||||
class AdminWithdrawOrder extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['stats'];
|
||||
|
||||
protected ?object $model = null;
|
||||
|
||||
protected bool $modelValidate = false;
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'order_no', 'receive_account', 'remark'];
|
||||
|
||||
protected string|array $defaultSortField = ['id' => 'desc'];
|
||||
|
||||
protected string|array $orderGuarantee = ['id' => 'desc'];
|
||||
|
||||
protected array $withJoinTable = ['admin', 'channel', 'reviewAdmin'];
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
$this->model = new \app\common\model\AdminWithdrawOrder();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _index(): Response
|
||||
{
|
||||
if ($this->request && $this->request->get('select')) {
|
||||
return $this->select($this->request);
|
||||
}
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = [$mainShort . '.channel_id', 'in', $this->getCurrentAdminTopChannelIds()];
|
||||
}
|
||||
$res = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
->visible([
|
||||
'admin' => ['username'],
|
||||
'channel' => ['name'],
|
||||
'reviewAdmin' => ['username'],
|
||||
])
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function _edit(): Response
|
||||
{
|
||||
$pk = $this->model->getPk();
|
||||
$id = $this->request ? ($this->request->post($pk) ?? $this->request->get($pk)) : null;
|
||||
if ($id === null || $id === '') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
if ($this->request && $this->request->method() === 'POST') {
|
||||
return $this->error('请使用通过/拒绝按钮审核');
|
||||
}
|
||||
$row = $this->loadWithRelations(intval(strval($id)));
|
||||
if (!$row) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
if (!$this->canReviewOrder($row)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
return $this->success('', ['row' => $row]);
|
||||
}
|
||||
|
||||
public function approve(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if ($request->method() !== 'POST') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$id = intval(strval($request->post('id', 0)));
|
||||
if ($id <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$order = Db::name('admin_withdraw_order')->where('id', $id)->find();
|
||||
if (!is_array($order)) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
if (!$this->canReviewOrder($order)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
if (intval($order['status'] ?? 0) !== 0) {
|
||||
return $this->error('该提现订单已审核');
|
||||
}
|
||||
$remark = trim((string) $request->post('remark', ''));
|
||||
Db::startTrans();
|
||||
try {
|
||||
AdminWalletService::approveWithdraw($order, intval($this->auth->id), $remark);
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success('审核通过');
|
||||
}
|
||||
|
||||
public function reject(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if ($request->method() !== 'POST') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$id = intval(strval($request->post('id', 0)));
|
||||
if ($id <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$remark = trim((string) $request->post('remark', ''));
|
||||
if ($remark === '') {
|
||||
return $this->error('请填写拒绝原因');
|
||||
}
|
||||
$order = Db::name('admin_withdraw_order')->where('id', $id)->find();
|
||||
if (!is_array($order)) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
if (!$this->canReviewOrder($order)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
if (intval($order['status'] ?? 0) !== 0) {
|
||||
return $this->error('该提现订单已审核');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
AdminWalletService::rejectWithdraw($order, intval($this->auth->id), $remark);
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success('审核拒绝完成');
|
||||
}
|
||||
|
||||
public function stats(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$query = Db::name('admin_withdraw_order');
|
||||
if ($this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$query->where('channel_id', 'in', $this->getCurrentAdminTopChannelIds());
|
||||
}
|
||||
$rows = $query->field(['status', 'amount', 'actual_amount'])->select()->toArray();
|
||||
$total = count($rows);
|
||||
$pending = 0;
|
||||
$approved = 0;
|
||||
$rejected = 0;
|
||||
$totalAmount = '0.00';
|
||||
$pendingAmount = '0.00';
|
||||
$approvedAmount = '0.00';
|
||||
foreach ($rows as $row) {
|
||||
$status = intval($row['status'] ?? 0);
|
||||
$amount = bcadd(strval($row['amount'] ?? '0'), '0', 2);
|
||||
$actual = bcadd(strval($row['actual_amount'] ?? '0'), '0', 2);
|
||||
$totalAmount = bcadd($totalAmount, $amount, 2);
|
||||
if ($status === 0) {
|
||||
$pending++;
|
||||
$pendingAmount = bcadd($pendingAmount, $amount, 2);
|
||||
} elseif ($status === 1) {
|
||||
$approved++;
|
||||
$approvedAmount = bcadd($approvedAmount, $actual, 2);
|
||||
} elseif ($status === 2) {
|
||||
$rejected++;
|
||||
}
|
||||
}
|
||||
return $this->success('', [
|
||||
'total_count' => $total,
|
||||
'pending_count' => $pending,
|
||||
'approved_count' => $approved,
|
||||
'rejected_count' => $rejected,
|
||||
'total_amount' => $totalAmount,
|
||||
'pending_amount' => $pendingAmount,
|
||||
'approved_amount' => $approvedAmount,
|
||||
]);
|
||||
}
|
||||
|
||||
private function loadWithRelations(int $id): ?array
|
||||
{
|
||||
$row = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
->visible([
|
||||
'admin' => ['username'],
|
||||
'channel' => ['name'],
|
||||
'reviewAdmin' => ['username'],
|
||||
])
|
||||
->where($this->model->getTable() . '.id', $id)
|
||||
->find();
|
||||
return $row ? $row->toArray() : null;
|
||||
}
|
||||
|
||||
private function canReviewOrder(array $order): bool
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return false;
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
$channelId = intval($order['channel_id'] ?? 0);
|
||||
if ($channelId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$allowed = $this->getCurrentAdminTopChannelIds();
|
||||
return in_array($channelId, $allowed, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可审核的“顶级角色组(pid=0)”所属渠道
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function getCurrentAdminTopChannelIds(): array
|
||||
{
|
||||
$uid = intval($this->auth->id ?? 0);
|
||||
if ($uid <= 0) {
|
||||
return [0];
|
||||
}
|
||||
$groupIds = Db::name('admin_group_access')->where('uid', $uid)->column('group_id');
|
||||
if ($groupIds === []) {
|
||||
return [0];
|
||||
}
|
||||
$rows = Db::name('admin_group')
|
||||
->field(['id', 'pid', 'channel_id'])
|
||||
->where('id', 'in', $groupIds)
|
||||
->where('pid', 0)
|
||||
->whereNotNull('channel_id')
|
||||
->select()
|
||||
->toArray();
|
||||
$channelIds = [];
|
||||
foreach ($rows as $row) {
|
||||
$cid = intval($row['channel_id'] ?? 0);
|
||||
if ($cid > 0) {
|
||||
$channelIds[] = $cid;
|
||||
}
|
||||
}
|
||||
return $channelIds === [] ? [0] : array_values(array_unique($channelIds));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class BetOrder extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -101,4 +101,25 @@ class BetOrder extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可见的管理员ID集合(本人 + 下级角色组内管理员)
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function scopedAdminIds(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$groupIds = $this->auth->getAdminChildGroups();
|
||||
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
||||
$adminIds[] = $this->auth->id;
|
||||
$adminIds = array_map(static fn($id) => intval(strval($id)), $adminIds);
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds, static fn($id) => $id > 0)));
|
||||
return $adminIds === [] ? [0] : $adminIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class DepositOrder extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
||||
}
|
||||
$this->appendDepositOrderIndexWhere($where, $mainShort);
|
||||
|
||||
@@ -140,7 +140,28 @@ class DepositOrder extends Backend
|
||||
if (!is_numeric(strval($adminIdRaw))) {
|
||||
return false;
|
||||
}
|
||||
return intval(strval($adminIdRaw)) === intval(strval($this->auth->id));
|
||||
return in_array(intval(strval($adminIdRaw)), $this->scopedAdminIds(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可见的管理员ID集合(本人 + 下级角色组内管理员)
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function scopedAdminIds(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$groupIds = $this->auth->getAdminChildGroups();
|
||||
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
||||
$adminIds[] = $this->auth->id;
|
||||
$adminIds = array_map(static fn($id) => intval(strval($id)), $adminIds);
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds, static fn($id) => $id > 0)));
|
||||
return $adminIds === [] ? [0] : $adminIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class WithdrawOrder extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -395,7 +395,7 @@ class WithdrawOrder extends Backend
|
||||
return false;
|
||||
}
|
||||
$ownerAdminId = $this->intParam($user['admin_id'] ?? 0);
|
||||
return $ownerAdminId > 0 && $ownerAdminId === $this->intParam($this->auth->id ?? 0);
|
||||
return $ownerAdminId > 0 && in_array($ownerAdminId, $this->scopedAdminIds(), true);
|
||||
}
|
||||
|
||||
private function intParam($raw): int
|
||||
@@ -430,6 +430,27 @@ class WithdrawOrder extends Backend
|
||||
return '#' . strval($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可见的管理员ID集合(本人 + 下级角色组内管理员)
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function scopedAdminIds(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$groupIds = $this->auth->getAdminChildGroups();
|
||||
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
||||
$adminIds[] = $this->auth->id;
|
||||
$adminIds = array_map(fn($id) => $this->intParam($id), $adminIds);
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds, fn($id) => $id > 0)));
|
||||
return $adminIds === [] ? [0] : $adminIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把 2 位小数金额压缩成最多 2 位小数用于展示(不影响落库精度)
|
||||
*/
|
||||
|
||||
@@ -5,12 +5,17 @@ declare(strict_types=1);
|
||||
namespace app\admin\controller\routine;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\common\service\AdminWalletService;
|
||||
use app\common\controller\Backend;
|
||||
use support\think\Db;
|
||||
use Webman\Http\Request;
|
||||
use support\Response;
|
||||
use Throwable;
|
||||
|
||||
class AdminInfo extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['walletSummary', 'walletRecords', 'withdrawApply'];
|
||||
|
||||
protected ?object $model = null;
|
||||
|
||||
protected array|string $preExcludeFields = ['username', 'last_login_time', 'password', 'salt', 'status'];
|
||||
@@ -88,4 +93,109 @@ class AdminInfo extends Backend
|
||||
|
||||
return $this->success('', ['row' => $row]);
|
||||
}
|
||||
|
||||
public function walletSummary(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$adminId = intval($this->auth->id ?? 0);
|
||||
if ($adminId <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$wallet = AdminWalletService::ensureWallet($adminId);
|
||||
return $this->success('', [
|
||||
'wallet' => [
|
||||
'balance' => strval($wallet['balance'] ?? '0.00'),
|
||||
'frozen_balance' => strval($wallet['frozen_balance'] ?? '0.00'),
|
||||
'total_income' => strval($wallet['total_income'] ?? '0.00'),
|
||||
'total_withdraw' => strval($wallet['total_withdraw'] ?? '0.00'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function walletRecords(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$adminId = intval($this->auth->id ?? 0);
|
||||
if ($adminId <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$limit = intval((string) $request->get('limit', 10));
|
||||
if ($limit <= 0) {
|
||||
$limit = 10;
|
||||
}
|
||||
$res = Db::name('admin_wallet_record')->alias('awr')
|
||||
->leftJoin('channel c', 'awr.channel_id = c.id')
|
||||
->leftJoin('admin oa', 'awr.operator_admin_id = oa.id')
|
||||
->field([
|
||||
'awr.id', 'awr.biz_type', 'awr.direction', 'awr.amount', 'awr.balance_before', 'awr.balance_after',
|
||||
'awr.ref_type', 'awr.ref_id', 'awr.remark', 'awr.create_time', 'c.name as channel_name', 'oa.username as operator_admin_username',
|
||||
])
|
||||
->where('awr.admin_id', $adminId)
|
||||
->order('awr.id', 'desc')
|
||||
->paginate($limit);
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function withdrawApply(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
if ($request->method() !== 'POST') {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$adminId = intval($this->auth->id ?? 0);
|
||||
if ($adminId <= 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
$withdrawCoinRaw = $request->post('withdraw_coin', '');
|
||||
$withdrawCoin = is_string($withdrawCoinRaw) ? trim($withdrawCoinRaw) : (is_numeric($withdrawCoinRaw) ? strval($withdrawCoinRaw) : '');
|
||||
$receiveAccount = trim(is_string($request->post('receive_account', '')) ? $request->post('receive_account', '') : '');
|
||||
$receiveType = trim(is_string($request->post('receive_type', '')) ? $request->post('receive_type', '') : '');
|
||||
$idempotencyKey = trim(is_string($request->post('idempotency_key', '')) ? $request->post('idempotency_key', '') : '');
|
||||
if ($withdrawCoin === '' || $receiveAccount === '' || $receiveType === '' || $idempotencyKey === '') {
|
||||
return $this->error('参数缺失');
|
||||
}
|
||||
if (mb_strlen($idempotencyKey) > 64) {
|
||||
return $this->error('幂等键过长');
|
||||
}
|
||||
if (!is_numeric($withdrawCoin) || bccomp($withdrawCoin, '0', 2) <= 0) {
|
||||
return $this->error('提现金额必须大于0');
|
||||
}
|
||||
$withdrawCoin = bcadd($withdrawCoin, '0', 2);
|
||||
$allowedReceiveTypes = ['bank', 'ewallet', 'crypto'];
|
||||
if (!in_array($receiveType, $allowedReceiveTypes, true)) {
|
||||
return $this->error('收款类型不合法,仅支持 bank/ewallet/crypto');
|
||||
}
|
||||
$remark = trim((string) $request->post('remark', ''));
|
||||
$admin = Db::name('admin')->field(['id', 'channel_id'])->where('id', $adminId)->find();
|
||||
$channelId = is_array($admin) ? intval($admin['channel_id'] ?? 0) : 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = AdminWalletService::applyWithdraw($adminId, $channelId, $withdrawCoin, $receiveType, $receiveAccount, $idempotencyKey, $remark);
|
||||
if (($res['ok'] ?? false) !== true) {
|
||||
Db::rollback();
|
||||
return $this->error(strval($res['msg'] ?? '提现申请失败'));
|
||||
}
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success('提现申请已提交,待渠道超管审核', [
|
||||
'order_id' => intval($res['order_id'] ?? 0),
|
||||
'order_no' => strval($res['order_no'] ?? ''),
|
||||
'idempotent_hit' => !empty($res['idempotent_hit']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class UserWalletRecord extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -101,4 +101,25 @@ class UserWalletRecord extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可见的管理员ID集合(本人 + 下级角色组内管理员)
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function scopedAdminIds(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$groupIds = $this->auth->getAdminChildGroups();
|
||||
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
||||
$adminIds[] = $this->auth->id;
|
||||
$adminIds = array_map(static fn($id) => intval(strval($id)), $adminIds);
|
||||
$adminIds = array_values(array_unique(array_filter($adminIds, static fn($id) => $id > 0)));
|
||||
return $adminIds === [] ? [0] : $adminIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -278,35 +278,41 @@ class Auth extends \ba\Auth
|
||||
public function getMenus(int $uid = 0): array
|
||||
{
|
||||
$menus = parent::getMenus($uid ?: $this->id);
|
||||
// 库内 title 为中文;仅英文界面走 __()。若对 zh-cn 也 __(),Symfony 在找不到键时会 fallback 到 en,
|
||||
// 命中 admin_rule_title 后会把中文标题误译成英文。
|
||||
$localeNorm = str_replace('_', '-', strtolower(locale()));
|
||||
$toEnglish = ($localeNorm === 'en');
|
||||
|
||||
return $this->translateMenuRuleTitles($menus, $toEnglish);
|
||||
return $this->translateMenuRuleTitles($menus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 admin_rule.title 在英文界面译为英文;中文界面保持库内原文。
|
||||
* 英文映射见 app/common/lang/en/admin_rule_title.php
|
||||
* 菜单标题统一按中文显示(不随语言切换)。
|
||||
* 若 title 为英文动作名/英文菜单名,按中文映射表转换。
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $menus
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function translateMenuRuleTitles(array $menus, bool $toEnglish): array
|
||||
private function translateMenuRuleTitles(array $menus): array
|
||||
{
|
||||
foreach ($menus as $k => $item) {
|
||||
if (isset($item['title']) && is_string($item['title']) && $item['title'] !== '') {
|
||||
$menus[$k]['title'] = $toEnglish ? __($item['title']) : $item['title'];
|
||||
$menus[$k]['title'] = $this->menuTitleToZh($item['title']);
|
||||
}
|
||||
if (!empty($item['children']) && is_array($item['children'])) {
|
||||
$menus[$k]['children'] = $this->translateMenuRuleTitles($item['children'], $toEnglish);
|
||||
$menus[$k]['children'] = $this->translateMenuRuleTitles($item['children']);
|
||||
}
|
||||
}
|
||||
|
||||
return $menus;
|
||||
}
|
||||
|
||||
private function menuTitleToZh(string $title): string
|
||||
{
|
||||
static $zhMap = null;
|
||||
if (!is_array($zhMap)) {
|
||||
$mapFile = app_path() . '/common/lang/zh-cn/admin_rule_title.php';
|
||||
$loaded = is_file($mapFile) ? include $mapFile : [];
|
||||
$zhMap = is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
return isset($zhMap[$title]) && is_string($zhMap[$title]) ? $zhMap[$title] : $title;
|
||||
}
|
||||
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return in_array('*', $this->getRuleIds());
|
||||
|
||||
@@ -62,6 +62,10 @@ class Auth extends MobileBase
|
||||
return $this->mobileError(2002, 'Invite code not bound to channel');
|
||||
}
|
||||
$extend['channel_id'] = (int) $channelId;
|
||||
$channelStatus = Db::name('channel')->where('id', (int) $channelId)->value('status');
|
||||
if (intval($channelStatus) !== 1) {
|
||||
return $this->mobileError(2002, 'Channel disabled');
|
||||
}
|
||||
|
||||
$registered = $this->auth->register($username, $password, $phone, $email, 1, $extend);
|
||||
if (!$registered) {
|
||||
|
||||
@@ -81,11 +81,14 @@ return [
|
||||
'连胜奖励' => 'Win streak rewards',
|
||||
'连胜降低档位' => 'Streak reduction tiers',
|
||||
'钱包加减点' => 'Wallet adjust',
|
||||
'测试' => 'Test',
|
||||
'测试频道监听' => 'Test channel monitoring',
|
||||
'推送-对局公共频道' => 'Push: public game period',
|
||||
'推送-公告广播频道' => 'Push: operation notices',
|
||||
'推送-用户私有频道' => 'Push: user private',
|
||||
'渠道管理' => 'Channel management',
|
||||
'管理员提现记录' => 'Admin withdraw records',
|
||||
'一键批量结算待结算渠道' => 'Batch settle pending channels',
|
||||
'渠道结算统计' => 'Channel settlement statistics',
|
||||
|
||||
// 演示/运营公告标题(若入库为菜单展示)
|
||||
'系统维护通知(演示)' => 'Maintenance notice (demo)',
|
||||
|
||||
@@ -80,6 +80,11 @@ class Auth extends \ba\Auth
|
||||
$this->setError('Account disabled');
|
||||
return false;
|
||||
}
|
||||
$channelId = intval($this->model->channel_id ?? 0);
|
||||
if ($channelId > 0 && !$this->isChannelEnabled($channelId)) {
|
||||
$this->setError('Channel disabled');
|
||||
return false;
|
||||
}
|
||||
$this->token = $token;
|
||||
$this->loginEd = true;
|
||||
return true;
|
||||
@@ -136,6 +141,11 @@ class Auth extends \ba\Auth
|
||||
'remark' => User::formatLoginRemark($time, $ip),
|
||||
];
|
||||
$data = array_merge(compact('username', 'password', 'phone', 'email'), $data, $extend);
|
||||
$channelIdForRegister = isset($data['channel_id']) ? intval($data['channel_id']) : 0;
|
||||
if ($channelIdForRegister > 0 && !$this->isChannelEnabled($channelIdForRegister)) {
|
||||
$this->setError('Channel disabled');
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
@@ -178,6 +188,11 @@ class Auth extends \ba\Auth
|
||||
$this->setError('Account disabled');
|
||||
return false;
|
||||
}
|
||||
$channelId = intval($this->model->channel_id ?? 0);
|
||||
if ($channelId > 0 && !$this->isChannelEnabled($channelId)) {
|
||||
$this->setError('Channel disabled');
|
||||
return false;
|
||||
}
|
||||
|
||||
$userLoginRetry = config('buildadmin.user_login_retry');
|
||||
if ($userLoginRetry && $this->model->last_login_time) {
|
||||
@@ -382,4 +397,13 @@ class Auth extends \ba\Auth
|
||||
$this->setKeepTime((int)config('buildadmin.user_token_keep_time', 86400));
|
||||
return true;
|
||||
}
|
||||
|
||||
private function isChannelEnabled(int $channelId): bool
|
||||
{
|
||||
$status = Db::name('channel')->where('id', $channelId)->value('status');
|
||||
if ($status === null || $status === '') {
|
||||
return false;
|
||||
}
|
||||
return intval($status) === 1;
|
||||
}
|
||||
}
|
||||
|
||||
27
app/common/model/AdminWallet.php
Normal file
27
app/common/model/AdminWallet.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\think\Model;
|
||||
|
||||
class AdminWallet extends Model
|
||||
{
|
||||
protected $name = 'admin_wallet';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
protected $type = [
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
'balance' => 'string',
|
||||
'frozen_balance' => 'string',
|
||||
'total_income' => 'string',
|
||||
'total_withdraw' => 'string',
|
||||
];
|
||||
|
||||
public function admin(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
39
app/common/model/AdminWalletRecord.php
Normal file
39
app/common/model/AdminWalletRecord.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\think\Model;
|
||||
|
||||
class AdminWalletRecord extends Model
|
||||
{
|
||||
protected $name = 'admin_wallet_record';
|
||||
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
protected $createTime = 'create_time';
|
||||
|
||||
protected $updateTime = false;
|
||||
|
||||
protected $type = [
|
||||
'create_time' => 'integer',
|
||||
'amount' => 'string',
|
||||
'balance_before' => 'string',
|
||||
'balance_after' => 'string',
|
||||
];
|
||||
|
||||
public function admin(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||
}
|
||||
|
||||
public function channel(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class, 'channel_id', 'id');
|
||||
}
|
||||
|
||||
public function operatorAdmin(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'operator_admin_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
37
app/common/model/AdminWithdrawOrder.php
Normal file
37
app/common/model/AdminWithdrawOrder.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\think\Model;
|
||||
|
||||
class AdminWithdrawOrder extends Model
|
||||
{
|
||||
protected $name = 'admin_withdraw_order';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
protected $type = [
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
'review_time' => 'integer',
|
||||
'amount' => 'string',
|
||||
'actual_amount' => 'string',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
public function admin(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||
}
|
||||
|
||||
public function channel(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Channel::class, 'channel_id', 'id');
|
||||
}
|
||||
|
||||
public function reviewAdmin(): \think\model\relation\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'review_admin_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
213
app/common/service/AdminWalletService.php
Normal file
213
app/common/service/AdminWalletService.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use support\think\Db;
|
||||
|
||||
class AdminWalletService
|
||||
{
|
||||
public static function ensureWallet(int $adminId): array
|
||||
{
|
||||
$wallet = Db::name('admin_wallet')->where('admin_id', $adminId)->find();
|
||||
if (is_array($wallet)) {
|
||||
return $wallet;
|
||||
}
|
||||
$now = time();
|
||||
Db::name('admin_wallet')->insert([
|
||||
'admin_id' => $adminId,
|
||||
'balance' => '0.00',
|
||||
'frozen_balance' => '0.00',
|
||||
'total_income' => '0.00',
|
||||
'total_withdraw' => '0.00',
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
return Db::name('admin_wallet')->where('admin_id', $adminId)->find() ?: [];
|
||||
}
|
||||
|
||||
public static function creditCommission(int $adminId, ?int $channelId, string $amount, string $refType, int $refId, string $remark): void
|
||||
{
|
||||
$wallet = self::ensureWallet($adminId);
|
||||
$before = strval($wallet['balance'] ?? '0.00');
|
||||
$after = bcadd($before, $amount, 2);
|
||||
$now = time();
|
||||
Db::name('admin_wallet')->where('admin_id', $adminId)->update([
|
||||
'balance' => $after,
|
||||
'total_income' => Db::raw('total_income + ' . $amount),
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_wallet_record')->insert([
|
||||
'admin_id' => $adminId,
|
||||
'channel_id' => $channelId,
|
||||
'biz_type' => 'commission_income',
|
||||
'direction' => 1,
|
||||
'amount' => $amount,
|
||||
'balance_before' => $before,
|
||||
'balance_after' => $after,
|
||||
'ref_type' => $refType,
|
||||
'ref_id' => $refId,
|
||||
'idempotency_key' => 'commission_income_' . $adminId . '_' . $refId,
|
||||
'operator_admin_id' => null,
|
||||
'remark' => $remark,
|
||||
'create_time' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function applyWithdraw(
|
||||
int $adminId,
|
||||
int $channelId,
|
||||
string $withdrawCoin,
|
||||
string $receiveType,
|
||||
string $receiveAccount,
|
||||
string $idempotencyKey,
|
||||
string $remark
|
||||
): array
|
||||
{
|
||||
$existing = Db::name('admin_withdraw_order')->where('idempotency_key', $idempotencyKey)->find();
|
||||
if (is_array($existing)) {
|
||||
$existAdminId = intval($existing['admin_id'] ?? 0);
|
||||
if ($existAdminId !== $adminId) {
|
||||
return ['ok' => false, 'msg' => 'Idempotency key conflict'];
|
||||
}
|
||||
return [
|
||||
'ok' => true,
|
||||
'order_id' => intval($existing['id'] ?? 0),
|
||||
'order_no' => strval($existing['order_no'] ?? ''),
|
||||
'idempotent_hit' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$wallet = self::ensureWallet($adminId);
|
||||
$before = strval($wallet['balance'] ?? '0.00');
|
||||
if (bccomp($before, $withdrawCoin, 2) < 0) {
|
||||
return ['ok' => false, 'msg' => '钱包余额不足'];
|
||||
}
|
||||
$after = bcsub($before, $withdrawCoin, 2);
|
||||
$beforeFrozen = strval($wallet['frozen_balance'] ?? '0.00');
|
||||
$afterFrozen = bcadd($beforeFrozen, $withdrawCoin, 2);
|
||||
$now = time();
|
||||
$orderNo = 'AWD' . date('YmdHis') . str_pad(strval($adminId), 6, '0', STR_PAD_LEFT) . strval(random_int(1000, 9999));
|
||||
|
||||
Db::name('admin_wallet')->where('admin_id', $adminId)->update([
|
||||
'balance' => $after,
|
||||
'frozen_balance' => $afterFrozen,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
$orderId = Db::name('admin_withdraw_order')->insertGetId([
|
||||
'order_no' => $orderNo,
|
||||
'admin_id' => $adminId,
|
||||
'channel_id' => $channelId > 0 ? $channelId : null,
|
||||
'amount' => $withdrawCoin,
|
||||
'actual_amount' => $withdrawCoin,
|
||||
'status' => 0,
|
||||
'receive_type' => $receiveType,
|
||||
'receive_account' => $receiveAccount,
|
||||
'idempotency_key' => $idempotencyKey,
|
||||
'review_admin_id' => null,
|
||||
'review_time' => null,
|
||||
'remark' => $remark,
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_wallet_record')->insert([
|
||||
'admin_id' => $adminId,
|
||||
'channel_id' => $channelId > 0 ? $channelId : null,
|
||||
'biz_type' => 'withdraw_freeze',
|
||||
'direction' => 2,
|
||||
'amount' => $withdrawCoin,
|
||||
'balance_before' => $before,
|
||||
'balance_after' => $after,
|
||||
'ref_type' => 'admin_withdraw_order',
|
||||
'ref_id' => $orderId,
|
||||
'idempotency_key' => 'admin_withdraw_freeze_' . $orderId,
|
||||
'operator_admin_id' => $adminId,
|
||||
'remark' => $remark !== '' ? $remark : '管理员提现申请冻结',
|
||||
'create_time' => $now,
|
||||
]);
|
||||
|
||||
return ['ok' => true, 'order_id' => $orderId, 'order_no' => $orderNo];
|
||||
}
|
||||
|
||||
public static function approveWithdraw(array $order, int $reviewAdminId, string $remark): void
|
||||
{
|
||||
$orderId = intval($order['id'] ?? 0);
|
||||
$adminId = intval($order['admin_id'] ?? 0);
|
||||
$amount = strval($order['amount'] ?? '0.00');
|
||||
$wallet = self::ensureWallet($adminId);
|
||||
$frozen = strval($wallet['frozen_balance'] ?? '0.00');
|
||||
$afterFrozen = bcsub($frozen, $amount, 2);
|
||||
$now = time();
|
||||
|
||||
Db::name('admin_wallet')->where('admin_id', $adminId)->update([
|
||||
'frozen_balance' => $afterFrozen,
|
||||
'total_withdraw' => Db::raw('total_withdraw + ' . $amount),
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_withdraw_order')->where('id', $orderId)->update([
|
||||
'status' => 1,
|
||||
'review_admin_id' => $reviewAdminId,
|
||||
'review_time' => $now,
|
||||
'remark' => $remark,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_wallet_record')->insert([
|
||||
'admin_id' => $adminId,
|
||||
'channel_id' => $order['channel_id'] ?? null,
|
||||
'biz_type' => 'withdraw_success',
|
||||
'direction' => 2,
|
||||
'amount' => $amount,
|
||||
'balance_before' => strval($wallet['balance'] ?? '0.00'),
|
||||
'balance_after' => strval($wallet['balance'] ?? '0.00'),
|
||||
'ref_type' => 'admin_withdraw_order',
|
||||
'ref_id' => $orderId,
|
||||
'idempotency_key' => 'admin_withdraw_success_' . $orderId,
|
||||
'operator_admin_id' => $reviewAdminId,
|
||||
'remark' => $remark !== '' ? $remark : '管理员提现审核通过',
|
||||
'create_time' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function rejectWithdraw(array $order, int $reviewAdminId, string $remark): void
|
||||
{
|
||||
$orderId = intval($order['id'] ?? 0);
|
||||
$adminId = intval($order['admin_id'] ?? 0);
|
||||
$amount = strval($order['amount'] ?? '0.00');
|
||||
$wallet = self::ensureWallet($adminId);
|
||||
$before = strval($wallet['balance'] ?? '0.00');
|
||||
$after = bcadd($before, $amount, 2);
|
||||
$frozen = strval($wallet['frozen_balance'] ?? '0.00');
|
||||
$afterFrozen = bcsub($frozen, $amount, 2);
|
||||
$now = time();
|
||||
|
||||
Db::name('admin_wallet')->where('admin_id', $adminId)->update([
|
||||
'balance' => $after,
|
||||
'frozen_balance' => $afterFrozen,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_withdraw_order')->where('id', $orderId)->update([
|
||||
'status' => 2,
|
||||
'review_admin_id' => $reviewAdminId,
|
||||
'review_time' => $now,
|
||||
'remark' => $remark,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::name('admin_wallet_record')->insert([
|
||||
'admin_id' => $adminId,
|
||||
'channel_id' => $order['channel_id'] ?? null,
|
||||
'biz_type' => 'withdraw_refund',
|
||||
'direction' => 1,
|
||||
'amount' => $amount,
|
||||
'balance_before' => $before,
|
||||
'balance_after' => $after,
|
||||
'ref_type' => 'admin_withdraw_order',
|
||||
'ref_id' => $orderId,
|
||||
'idempotency_key' => 'admin_withdraw_refund_' . $orderId,
|
||||
'operator_admin_id' => $reviewAdminId,
|
||||
'remark' => $remark !== '' ? $remark : '管理员提现审核拒绝退回',
|
||||
'create_time' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
470
app/common/service/ChannelSettlementService.php
Normal file
470
app/common/service/ChannelSettlementService.php
Normal file
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use support\think\Db;
|
||||
use Throwable;
|
||||
|
||||
class ChannelSettlementService
|
||||
{
|
||||
public static function settleBySuperAdmin(int $channelId, int $operatorAdminId, string $remark = '', bool $auto = false): array
|
||||
{
|
||||
$channel = Db::name('channel')->where('id', $channelId)->find();
|
||||
if (!is_array($channel)) {
|
||||
return ['ok' => false, 'msg' => '渠道不存在'];
|
||||
}
|
||||
$payload = self::buildSettlePayload($channel);
|
||||
if (is_string($payload)) {
|
||||
return ['ok' => false, 'msg' => $payload];
|
||||
}
|
||||
$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' => '结算单号冲突,请重试'];
|
||||
}
|
||||
$shareRows = self::resolveCommissionSharesForChannel($channelId);
|
||||
if ($shareRows === []) {
|
||||
return ['ok' => false, 'msg' => '渠道下无可用管理员分配比例,无法结算'];
|
||||
}
|
||||
$now = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$periodId = intval(Db::name('agent_settlement_period')->insertGetId([
|
||||
'settlement_no' => $settlementNo,
|
||||
'period_start_at' => $payload['period_start_ts'],
|
||||
'period_end_at' => $payload['period_end_ts'],
|
||||
'total_bet_amount' => $payload['total_bet_amount'],
|
||||
'total_payout_amount' => $payload['total_payout_amount'],
|
||||
'platform_profit_amount' => $payload['platform_profit_amount'],
|
||||
'status' => 1,
|
||||
'remark' => $remark !== '' ? $remark : (($auto ? '自动' : '手动') . '渠道结算-CH' . $channelId),
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]));
|
||||
$rows = self::buildCommissionRowsForSplit(
|
||||
$shareRows,
|
||||
$channelId,
|
||||
$periodId,
|
||||
strval($payload['calc_base_amount']),
|
||||
strval($payload['commission_amount']),
|
||||
$remark !== '' ? $remark : '渠道待分红记录',
|
||||
$now
|
||||
);
|
||||
if ($rows === []) {
|
||||
throw new \RuntimeException('生成待分红记录失败');
|
||||
}
|
||||
Db::name('agent_commission_record')->insertAll($rows);
|
||||
Db::name('channel')->where('id', $channelId)->update([
|
||||
'carryover_balance' => Db::raw('carryover_balance + ' . strval($payload['commission_amount'])),
|
||||
'update_time' => $now,
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
return ['ok' => false, 'msg' => $e->getMessage()];
|
||||
}
|
||||
return ['ok' => true, 'payload' => $payload];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
public static function settleAllDueChannels(int $operatorAdminId): array
|
||||
{
|
||||
$channels = Db::name('channel')->where('status', 1)->select()->toArray();
|
||||
$ok = 0;
|
||||
$failed = [];
|
||||
$now = time();
|
||||
foreach ($channels as $channel) {
|
||||
$channelId = intval($channel['id'] ?? 0);
|
||||
if ($channelId <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (!self::isChannelDueForAutoSettle($channel, $now)) {
|
||||
continue;
|
||||
}
|
||||
$res = self::settleBySuperAdmin($channelId, $operatorAdminId, '周期自动结算', true);
|
||||
if (($res['ok'] ?? false) === true) {
|
||||
$ok++;
|
||||
continue;
|
||||
}
|
||||
$failed[] = [
|
||||
'channel_id' => $channelId,
|
||||
'msg' => strval($res['msg'] ?? '结算失败'),
|
||||
];
|
||||
}
|
||||
return ['ok_count' => $ok, 'failed' => $failed];
|
||||
}
|
||||
|
||||
private static function isChannelDueForAutoSettle(array $channel, int $now): bool
|
||||
{
|
||||
$channelId = intval($channel['id'] ?? 0);
|
||||
if ($channelId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$lastEnd = self::getLastSettlementEndForChannel($channelId);
|
||||
$cycle = strval($channel['settle_cycle'] ?? 'weekly');
|
||||
$settleTime = strval($channel['settle_time'] ?? '02:00:00');
|
||||
$today = date('Y-m-d', $now);
|
||||
$targetTs = strtotime($today . ' ' . $settleTime);
|
||||
if ($targetTs === false || $now < $targetTs) {
|
||||
return false;
|
||||
}
|
||||
if ($lastEnd !== null && $lastEnd >= $targetTs) {
|
||||
return false;
|
||||
}
|
||||
if ($cycle === 'daily') {
|
||||
return true;
|
||||
}
|
||||
if ($cycle === 'weekly') {
|
||||
$weekday = intval($channel['settle_weekday'] ?? 1);
|
||||
$w = intval(date('N', $now));
|
||||
return $weekday === $w;
|
||||
}
|
||||
if ($cycle === 'monthly') {
|
||||
$monthday = intval($channel['settle_monthday'] ?? 1);
|
||||
$d = intval(date('j', $now));
|
||||
return $monthday === $d;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function buildSettlePayload(array $row): array|string
|
||||
{
|
||||
$channelId = intval($row['id'] ?? 0);
|
||||
if ($channelId <= 0) {
|
||||
return '渠道数据异常';
|
||||
}
|
||||
$endTs = time();
|
||||
$lastEnd = self::getLastSettlementEndForChannel($channelId);
|
||||
$channelCreateTs = intval($row['create_time'] ?? 0);
|
||||
$periodStartTs = $lastEnd === null ? ($channelCreateTs > 0 ? $channelCreateTs : 0) : $lastEnd;
|
||||
if ($periodStartTs >= $endTs) {
|
||||
return '结算区间无效(开始时间不早于当前)';
|
||||
}
|
||||
$stats = self::aggregateBetOrderForChannel($channelId, $periodStartTs, $lastEnd !== null, $endTs);
|
||||
$totalBet = $stats['total_bet'];
|
||||
$totalPayout = $stats['total_payout'];
|
||||
$profit = bcsub($totalBet, $totalPayout, 2);
|
||||
$mode = strval($row['agent_mode'] ?? 'turnover');
|
||||
$commission = self::computeCommissionAmounts($row, $totalBet, $profit, $mode);
|
||||
if (is_string($commission)) {
|
||||
return $commission;
|
||||
}
|
||||
return [
|
||||
'period_start_ts' => $periodStartTs,
|
||||
'period_end_ts' => $endTs,
|
||||
'period_start_at' => date('Y-m-d H:i:s', $periodStartTs),
|
||||
'period_end_at' => date('Y-m-d H:i:s', $endTs),
|
||||
'total_bet_amount' => $totalBet,
|
||||
'total_payout_amount' => $totalPayout,
|
||||
'platform_profit_amount' => $profit,
|
||||
'commission_rate' => $commission['commission_rate'],
|
||||
'calc_base_amount' => $commission['calc_base_amount'],
|
||||
'commission_amount' => $commission['commission_amount'],
|
||||
'agent_mode' => $mode,
|
||||
'commission_split' => self::buildCommissionSplitPreview(self::resolveCommissionSharesForChannel($channelId), $commission['commission_amount']),
|
||||
];
|
||||
}
|
||||
|
||||
private static function getLastSettlementEndForChannel(int $channelId): ?int
|
||||
{
|
||||
$row = Db::name('agent_commission_record')->alias('acr')
|
||||
->join('agent_settlement_period asp', 'acr.settlement_period_id = asp.id')
|
||||
->where('acr.channel_id', $channelId)
|
||||
->field('MAX(asp.period_end_at) AS m')
|
||||
->find();
|
||||
if (!is_array($row)) {
|
||||
return null;
|
||||
}
|
||||
$m = $row['m'] ?? null;
|
||||
if ($m === null || $m === '') {
|
||||
return null;
|
||||
}
|
||||
return intval($m);
|
||||
}
|
||||
|
||||
private static function aggregateBetOrderForChannel(int $channelId, int $periodStartTs, bool $hasPriorSettlement, int $endTs): array
|
||||
{
|
||||
$query = Db::name('bet_order')
|
||||
->where('channel_id', $channelId)
|
||||
->where('status', 2)
|
||||
->where('create_time', '<=', $endTs);
|
||||
if ($hasPriorSettlement) {
|
||||
$query->where('create_time', '>', $periodStartTs);
|
||||
} else {
|
||||
$query->where('create_time', '>=', $periodStartTs);
|
||||
}
|
||||
$row = $query->field('SUM(total_amount) AS tb, SUM(win_amount) AS tw, SUM(jackpot_extra_amount) AS tj')->find();
|
||||
$tb = is_array($row) && $row['tb'] !== null && $row['tb'] !== '' ? strval($row['tb']) : '0.00';
|
||||
$tw = is_array($row) && $row['tw'] !== null && $row['tw'] !== '' ? strval($row['tw']) : '0.00';
|
||||
$tj = is_array($row) && $row['tj'] !== null && $row['tj'] !== '' ? strval($row['tj']) : '0.00';
|
||||
$totalPayout = bcadd($tw, $tj, 2);
|
||||
return ['total_bet' => bcadd($tb, '0', 2), 'total_payout' => bcadd($totalPayout, '0', 2)];
|
||||
}
|
||||
|
||||
private static function computeCommissionAmounts(array $row, string $totalBet, string $platformProfit, string $mode): array|string
|
||||
{
|
||||
if ($mode === 'turnover') {
|
||||
$ratePercent = $row['turnover_share_rate'] ?? null;
|
||||
if ($ratePercent === null || $ratePercent === '') {
|
||||
return '普通返水代理未配置返水分红比例';
|
||||
}
|
||||
$rateDec = bcdiv(strval($ratePercent), '100', 4);
|
||||
return [
|
||||
'commission_rate' => $rateDec,
|
||||
'calc_base_amount' => $totalBet,
|
||||
'commission_amount' => bcmul($totalBet, $rateDec, 2),
|
||||
];
|
||||
}
|
||||
if ($mode === 'affiliate') {
|
||||
$fee = $row['affiliate_fee_rate'] ?? null;
|
||||
$rulesRaw = $row['affiliate_ladder_rules'] ?? null;
|
||||
if ($fee === null || $fee === '') {
|
||||
return '联营代理未配置成本扣除比例';
|
||||
}
|
||||
$rules = self::normalizeLadderRulesForSettlement($rulesRaw);
|
||||
if ($rules === []) {
|
||||
return '联营阶梯规则无效或为空';
|
||||
}
|
||||
if (bccomp($platformProfit, '0', 2) <= 0) {
|
||||
return ['commission_rate' => '0.0000', 'calc_base_amount' => '0.00', 'commission_amount' => '0.00'];
|
||||
}
|
||||
$afterFee = bcmul($platformProfit, bcsub('1', strval($fee), 4), 2);
|
||||
if (bccomp($afterFee, '0', 2) <= 0) {
|
||||
return ['commission_rate' => '0.0000', 'calc_base_amount' => '0.00', 'commission_amount' => '0.00'];
|
||||
}
|
||||
$shareRate = self::pickAffiliateShareRateFromLadder($rules, $platformProfit);
|
||||
$rateDec = number_format($shareRate, 6, '.', '');
|
||||
return [
|
||||
'commission_rate' => $rateDec,
|
||||
'calc_base_amount' => $afterFee,
|
||||
'commission_amount' => bcmul($afterFee, $rateDec, 2),
|
||||
];
|
||||
}
|
||||
return '未知的代理模式';
|
||||
}
|
||||
|
||||
private static function normalizeLadderRulesForSettlement(mixed $rulesRaw): array
|
||||
{
|
||||
if ($rulesRaw === null || $rulesRaw === '') {
|
||||
return [];
|
||||
}
|
||||
if (is_string($rulesRaw)) {
|
||||
$decoded = json_decode($rulesRaw, true);
|
||||
$rulesRaw = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
if (!is_array($rulesRaw)) {
|
||||
return [];
|
||||
}
|
||||
$out = [];
|
||||
foreach ($rulesRaw as $rule) {
|
||||
if (!is_array($rule)) {
|
||||
continue;
|
||||
}
|
||||
$minLoss = $rule['minLoss'] ?? ($rule['min_loss'] ?? null);
|
||||
$shareRate = $rule['shareRate'] ?? ($rule['share_rate'] ?? null);
|
||||
if ($minLoss === null || $shareRate === null || !is_numeric(strval($minLoss)) || !is_numeric(strval($shareRate))) {
|
||||
continue;
|
||||
}
|
||||
$out[] = [
|
||||
'minLoss' => number_format(floatval($minLoss), 4, '.', ''),
|
||||
'shareRate' => number_format(floatval($shareRate), 6, '.', ''),
|
||||
];
|
||||
}
|
||||
usort($out, static function (array $a, array $b): int {
|
||||
return bccomp($a['minLoss'], $b['minLoss'], 4);
|
||||
});
|
||||
return $out;
|
||||
}
|
||||
|
||||
private static function pickAffiliateShareRateFromLadder(array $rules, string $playerLoss): float
|
||||
{
|
||||
$chosen = floatval($rules[0]['shareRate']);
|
||||
foreach ($rules as $rule) {
|
||||
if (bccomp($playerLoss, strval($rule['minLoss']), 2) >= 0) {
|
||||
$chosen = floatval($rule['shareRate']);
|
||||
}
|
||||
}
|
||||
return $chosen;
|
||||
}
|
||||
|
||||
private static function generateAgentSettlementNo(string $sourceFlag, int $channelId, int $endTs): string
|
||||
{
|
||||
$flag = strtoupper(trim($sourceFlag));
|
||||
if ($flag !== 'M' && $flag !== 'A') {
|
||||
$flag = 'M';
|
||||
}
|
||||
$base = $flag . str_pad(strval(max(0, $channelId)), 6, '0', STR_PAD_LEFT) . str_pad(strval(max(0, $endTs)), 10, '0', STR_PAD_LEFT);
|
||||
return $base . strtoupper(substr(bin2hex(random_bytes(4)), 0, 2));
|
||||
}
|
||||
|
||||
private static function resolveCommissionSharesForChannel(int $channelId): array
|
||||
{
|
||||
$rows = Db::name('channel_admin_share')->alias('cas')
|
||||
->join('admin a', 'cas.admin_id = a.id')
|
||||
->field(['cas.admin_id', 'cas.share_rate'])
|
||||
->where('cas.channel_id', $channelId)
|
||||
->where('cas.status', 1)
|
||||
->where('a.status', 'enable')
|
||||
->order('cas.admin_id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
if ($rows === []) {
|
||||
return [];
|
||||
}
|
||||
$sum = '0.00';
|
||||
$out = [];
|
||||
foreach ($rows as $row) {
|
||||
$adminId = intval($row['admin_id'] ?? 0);
|
||||
$shareRate = bcadd(strval($row['share_rate'] ?? '0'), '0', 2);
|
||||
if ($adminId <= 0 || bccomp($shareRate, '0', 2) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$sum = bcadd($sum, $shareRate, 2);
|
||||
$out[] = ['admin_id' => $adminId, 'share_rate' => $shareRate];
|
||||
}
|
||||
if ($out === [] || bccomp($sum, '100.00', 2) !== 0) {
|
||||
return [];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private static function buildCommissionRowsForSplit(array $shareRows, int $channelId, int $periodId, string $calcBaseAmount, string $commissionTotal, string $remark, int $now): array
|
||||
{
|
||||
$sum = '0.00';
|
||||
$rows = [];
|
||||
$lastIndex = count($shareRows) - 1;
|
||||
foreach ($shareRows as $index => $shareRow) {
|
||||
$shareRate = bcadd(strval($shareRow['share_rate'] ?? '0.00'), '0', 2);
|
||||
$shareDec = bcdiv($shareRate, '100', 4);
|
||||
$amount = $index === $lastIndex ? bcsub($commissionTotal, $sum, 2) : bcmul($commissionTotal, $shareDec, 2);
|
||||
if ($index !== $lastIndex) {
|
||||
$sum = bcadd($sum, $amount, 2);
|
||||
}
|
||||
$effectiveRate = bccomp($calcBaseAmount, '0', 2) <= 0 ? '0.0000' : bcdiv($amount, $calcBaseAmount, 6);
|
||||
$rows[] = [
|
||||
'settlement_period_id' => $periodId,
|
||||
'channel_id' => $channelId,
|
||||
'admin_id' => intval($shareRow['admin_id'] ?? 0),
|
||||
'commission_rate' => $effectiveRate,
|
||||
'calc_base_amount' => $calcBaseAmount,
|
||||
'commission_amount' => $amount,
|
||||
'status' => 0,
|
||||
'settled_at' => null,
|
||||
'remark' => $remark . ' | 分配比例=' . $shareRate . '%',
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private static function buildCommissionSplitPreview(array $shareRows, string $commissionTotal): array
|
||||
{
|
||||
if ($shareRows === []) {
|
||||
return [];
|
||||
}
|
||||
$adminIds = array_map(static fn(array $row): int => intval($row['admin_id'] ?? 0), $shareRows);
|
||||
$adminNames = Db::name('admin')->where('id', 'in', $adminIds)->column('username', 'id');
|
||||
$sum = '0.00';
|
||||
$out = [];
|
||||
$lastIndex = count($shareRows) - 1;
|
||||
foreach ($shareRows as $index => $shareRow) {
|
||||
$shareRate = bcadd(strval($shareRow['share_rate'] ?? '0.00'), '0', 2);
|
||||
$shareDec = bcdiv($shareRate, '100', 4);
|
||||
$amount = $index === $lastIndex ? bcsub($commissionTotal, $sum, 2) : bcmul($commissionTotal, $shareDec, 2);
|
||||
if ($index !== $lastIndex) {
|
||||
$sum = bcadd($sum, $amount, 2);
|
||||
}
|
||||
$aid = intval($shareRow['admin_id'] ?? 0);
|
||||
$out[] = [
|
||||
'admin_id' => $aid,
|
||||
'admin_username' => strval($adminNames[$aid] ?? ('#' . $aid)),
|
||||
'share_rate' => $shareRate,
|
||||
'commission_amount' => $amount,
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
22
app/process/ChannelAutoSettleTicker.php
Normal file
22
app/process/ChannelAutoSettleTicker.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\process;
|
||||
|
||||
use app\common\service\ChannelSettlementService;
|
||||
use Workerman\Timer;
|
||||
|
||||
/**
|
||||
* 渠道周期自动结算(每 60 秒扫描一次)
|
||||
*/
|
||||
class ChannelAutoSettleTicker
|
||||
{
|
||||
public function onWorkerStart(): void
|
||||
{
|
||||
Timer::add(60, static function (): void {
|
||||
ChannelSettlementService::settleAllDueChannels(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,12 @@ return [
|
||||
'count' => 1,
|
||||
'reloadable' => false,
|
||||
],
|
||||
// 渠道结算:按渠道周期自动结算(超管逻辑)
|
||||
'channelAutoSettleTicker' => [
|
||||
'handler' => app\process\ChannelAutoSettleTicker::class,
|
||||
'count' => 1,
|
||||
'reloadable' => false,
|
||||
],
|
||||
|
||||
// File update detection and automatic reload
|
||||
'monitor' => [
|
||||
|
||||
@@ -6,6 +6,9 @@ export const actionUrl = new Map([
|
||||
['index', url + 'index'],
|
||||
['edit', url + 'edit'],
|
||||
['log', '/admin/auth.AdminLog/index'],
|
||||
['walletSummary', url + 'walletSummary'],
|
||||
['walletRecords', url + 'walletRecords'],
|
||||
['withdrawApply', url + 'withdrawApply'],
|
||||
])
|
||||
|
||||
export function index() {
|
||||
@@ -35,3 +38,31 @@ export function postData(data: anyObj) {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function walletSummary() {
|
||||
return createAxios({
|
||||
url: actionUrl.get('walletSummary'),
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
export function walletRecords(filter: anyObj = {}) {
|
||||
return createAxios<TableDefaultData>({
|
||||
url: actionUrl.get('walletRecords'),
|
||||
method: 'get',
|
||||
params: filter,
|
||||
})
|
||||
}
|
||||
|
||||
export function withdrawApply(data: anyObj) {
|
||||
return createAxios(
|
||||
{
|
||||
url: actionUrl.get('withdrawApply'),
|
||||
method: 'post',
|
||||
data,
|
||||
},
|
||||
{
|
||||
showSuccessMessage: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,6 +77,16 @@ export default {
|
||||
share_rate_percent: 'Share rate(%)',
|
||||
share_total_enabled: 'Enabled total',
|
||||
share_total_must_100: 'Enabled share total must equal 100%',
|
||||
batch_settle_pending: 'Batch settle pending channels',
|
||||
settle_stats_channel_total: 'Total channels',
|
||||
settle_stats_enabled: 'Enabled channels',
|
||||
settle_stats_pending_dividend: 'Channels pending dividend',
|
||||
settle_stats_pending_amount: 'Pending dividend amount',
|
||||
settle_filter_all: 'All',
|
||||
settle_filter_with_balance: 'With dividend balance',
|
||||
settle_filter_no_balance: 'No dividend balance',
|
||||
settle_filter_enabled: 'Enabled only',
|
||||
settle_filter_disabled: 'Disabled only',
|
||||
admin_id_placeholder: 'Select an admin (within your permission scope)',
|
||||
admin__username: 'Person in charge',
|
||||
admin_group_names: 'Role group',
|
||||
|
||||
37
web/src/lang/backend/en/order/adminWithdrawOrder.ts
Normal file
37
web/src/lang/backend/en/order/adminWithdrawOrder.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
'quick Search Fields': 'Order no., receive account, remark',
|
||||
id: 'ID',
|
||||
order_no: 'Order No.',
|
||||
admin_username: 'Admin',
|
||||
channel_name: 'Channel',
|
||||
amount: 'Apply amount',
|
||||
actual_amount: 'Actual amount',
|
||||
status: 'Status',
|
||||
'status 0': 'Pending review',
|
||||
'status 1': 'Approved',
|
||||
'status 2': 'Rejected',
|
||||
receive_type: 'Receive type',
|
||||
receive_account: 'Receive account',
|
||||
review_admin_username: 'Reviewer',
|
||||
remark: 'Remark',
|
||||
create_time: 'Create time',
|
||||
review_btn_approve: 'Approve',
|
||||
review_btn_reject: 'Reject',
|
||||
review_approve_title: 'Approve order',
|
||||
review_reject_title: 'Reject order',
|
||||
review_remark_optional: 'Optional review remark',
|
||||
reject_reason_required: 'Please enter reject reason',
|
||||
stat_total_count: 'Total orders',
|
||||
stat_pending_count: 'Pending orders',
|
||||
stat_pending_amount: 'Pending amount',
|
||||
stat_approved_amount: 'Approved amount',
|
||||
filter_all: 'All',
|
||||
filter_pending: 'Pending',
|
||||
filter_approved: 'Approved',
|
||||
filter_rejected: 'Rejected',
|
||||
filter_receive_type_all: 'All receive types',
|
||||
receive_type_bank: 'Bank card',
|
||||
receive_type_ewallet: 'E-wallet',
|
||||
receive_type_crypto: 'Crypto address',
|
||||
}
|
||||
|
||||
@@ -11,4 +11,30 @@ export default {
|
||||
'Please leave blank if not modified': 'Please leave blank if you do not modify',
|
||||
'Save changes': 'Save changes',
|
||||
'Operation log': 'Operation log',
|
||||
admin_wallet: 'Admin wallet',
|
||||
withdraw: 'Withdraw',
|
||||
wallet_balance: 'Available balance',
|
||||
wallet_frozen_balance: 'Frozen balance',
|
||||
wallet_total_income: 'Total income',
|
||||
wallet_total_withdraw: 'Total withdraw',
|
||||
wallet_records: 'Wallet records',
|
||||
wallet_records_type: 'Type',
|
||||
wallet_records_direction: 'Direction',
|
||||
wallet_direction_in: 'In',
|
||||
wallet_direction_out: 'Out',
|
||||
wallet_records_amount: 'Amount',
|
||||
wallet_records_balance_after: 'Balance after',
|
||||
wallet_records_remark: 'Remark',
|
||||
wallet_records_time: 'Time',
|
||||
withdraw_apply_title: 'Admin withdraw apply',
|
||||
withdraw_coin: 'Withdraw amount',
|
||||
withdraw_coin_placeholder: 'Please input withdraw_coin (2 decimals)',
|
||||
receive_type: 'Receive type',
|
||||
receive_type_placeholder: 'Please select receive_type',
|
||||
receive_account: 'Receive account',
|
||||
receive_account_placeholder: 'Please input receive_account',
|
||||
idempotency_key: 'Idempotency key',
|
||||
idempotency_key_placeholder: 'Please input idempotency_key (optional, auto-generated if empty)',
|
||||
remark: 'Remark',
|
||||
submit_apply: 'Submit apply',
|
||||
}
|
||||
|
||||
@@ -77,6 +77,16 @@ export default {
|
||||
share_rate_percent: '分配比例(%)',
|
||||
share_total_enabled: '启用项合计',
|
||||
share_total_must_100: '启用项分配比例总和必须等于100%',
|
||||
batch_settle_pending: '一键批量结算待结算渠道',
|
||||
settle_stats_channel_total: '渠道总数',
|
||||
settle_stats_enabled: '启用渠道',
|
||||
settle_stats_pending_dividend: '待分红渠道',
|
||||
settle_stats_pending_amount: '待分红总额',
|
||||
settle_filter_all: '全部',
|
||||
settle_filter_with_balance: '有分红余额',
|
||||
settle_filter_no_balance: '无分红余额',
|
||||
settle_filter_enabled: '仅启用',
|
||||
settle_filter_disabled: '仅停用',
|
||||
admin_id_placeholder: '请选择管理员(仅当前权限范围内)',
|
||||
admin__username: '负责人',
|
||||
admin_group_names: '角色组',
|
||||
|
||||
37
web/src/lang/backend/zh-cn/order/adminWithdrawOrder.ts
Normal file
37
web/src/lang/backend/zh-cn/order/adminWithdrawOrder.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default {
|
||||
'quick Search Fields': '订单号、收款账户、备注',
|
||||
id: 'ID',
|
||||
order_no: '订单号',
|
||||
admin_username: '管理员',
|
||||
channel_name: '渠道',
|
||||
amount: '申请金额',
|
||||
actual_amount: '实际金额',
|
||||
status: '状态',
|
||||
'status 0': '待审核',
|
||||
'status 1': '已通过',
|
||||
'status 2': '已拒绝',
|
||||
receive_type: '收款方式',
|
||||
receive_account: '收款账户',
|
||||
review_admin_username: '审核人',
|
||||
remark: '备注',
|
||||
create_time: '创建时间',
|
||||
review_btn_approve: '通过',
|
||||
review_btn_reject: '拒绝',
|
||||
review_approve_title: '通过审核',
|
||||
review_reject_title: '拒绝审核',
|
||||
review_remark_optional: '可选填写审核备注',
|
||||
reject_reason_required: '请填写拒绝原因',
|
||||
stat_total_count: '提现总单数',
|
||||
stat_pending_count: '待审核单数',
|
||||
stat_pending_amount: '待审核金额',
|
||||
stat_approved_amount: '已通过金额',
|
||||
filter_all: '全部',
|
||||
filter_pending: '待审核',
|
||||
filter_approved: '已通过',
|
||||
filter_rejected: '已拒绝',
|
||||
filter_receive_type_all: '全部收款方式',
|
||||
receive_type_bank: '银行卡',
|
||||
receive_type_ewallet: '电子钱包',
|
||||
receive_type_crypto: '加密地址',
|
||||
}
|
||||
|
||||
@@ -11,4 +11,30 @@ export default {
|
||||
'Please leave blank if not modified': '不修改请留空',
|
||||
'Save changes': '保存修改',
|
||||
'Operation log': '操作日志',
|
||||
admin_wallet: '管理员钱包',
|
||||
withdraw: '提现',
|
||||
wallet_balance: '可用余额',
|
||||
wallet_frozen_balance: '冻结余额',
|
||||
wallet_total_income: '累计入账',
|
||||
wallet_total_withdraw: '累计提现',
|
||||
wallet_records: '钱包流水',
|
||||
wallet_records_type: '类型',
|
||||
wallet_records_direction: '方向',
|
||||
wallet_direction_in: '入账',
|
||||
wallet_direction_out: '出账',
|
||||
wallet_records_amount: '金额',
|
||||
wallet_records_balance_after: '变动后余额',
|
||||
wallet_records_remark: '备注',
|
||||
wallet_records_time: '时间',
|
||||
withdraw_apply_title: '管理员提现申请',
|
||||
withdraw_coin: '提现金额',
|
||||
withdraw_coin_placeholder: '请输入 withdraw_coin(两位小数)',
|
||||
receive_type: '收款方式',
|
||||
receive_type_placeholder: '请选择 receive_type',
|
||||
receive_account: '收款账户',
|
||||
receive_account_placeholder: '请输入 receive_account',
|
||||
idempotency_key: '幂等键',
|
||||
idempotency_key_placeholder: '请输入 idempotency_key(可留空自动生成)',
|
||||
remark: '备注',
|
||||
submit_apply: '提交申请',
|
||||
}
|
||||
|
||||
277
web/src/views/backend/order/adminWithdrawOrder/index.vue
Normal file
277
web/src/views/backend/order/adminWithdrawOrder/index.vue
Normal file
@@ -0,0 +1,277 @@
|
||||
<template>
|
||||
<div class="default-main ba-table-box">
|
||||
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
|
||||
<TableHeader
|
||||
:buttons="['refresh', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||
:quick-search-placeholder="t('Quick search placeholder', { fields: t('order.adminWithdrawOrder.quick Search Fields') })"
|
||||
/>
|
||||
<div class="withdraw-stats-cards">
|
||||
<el-card shadow="never" class="withdraw-stat-card">
|
||||
<div class="label">{{ t('order.adminWithdrawOrder.stat_total_count') }}</div>
|
||||
<div class="value">{{ stats.total_count }}</div>
|
||||
</el-card>
|
||||
<el-card shadow="never" class="withdraw-stat-card">
|
||||
<div class="label">{{ t('order.adminWithdrawOrder.stat_pending_count') }}</div>
|
||||
<div class="value">{{ stats.pending_count }}</div>
|
||||
</el-card>
|
||||
<el-card shadow="never" class="withdraw-stat-card">
|
||||
<div class="label">{{ t('order.adminWithdrawOrder.stat_pending_amount') }}</div>
|
||||
<div class="value">{{ stats.pending_amount }}</div>
|
||||
</el-card>
|
||||
<el-card shadow="never" class="withdraw-stat-card">
|
||||
<div class="label">{{ t('order.adminWithdrawOrder.stat_approved_amount') }}</div>
|
||||
<div class="value">{{ stats.approved_amount }}</div>
|
||||
</el-card>
|
||||
</div>
|
||||
<div class="withdraw-filter-row">
|
||||
<el-radio-group v-model="statusFilterMode" size="small" @change="onStatusFilterChange">
|
||||
<el-radio-button label="all">{{ t('order.adminWithdrawOrder.filter_all') }}</el-radio-button>
|
||||
<el-radio-button label="pending">{{ t('order.adminWithdrawOrder.filter_pending') }}</el-radio-button>
|
||||
<el-radio-button label="approved">{{ t('order.adminWithdrawOrder.filter_approved') }}</el-radio-button>
|
||||
<el-radio-button label="rejected">{{ t('order.adminWithdrawOrder.filter_rejected') }}</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-select v-model="receiveTypeFilterMode" class="receive-type-filter" @change="onStatusFilterChange">
|
||||
<el-option :label="t('order.adminWithdrawOrder.filter_receive_type_all')" value="all" />
|
||||
<el-option :label="t('order.adminWithdrawOrder.receive_type_bank')" value="bank" />
|
||||
<el-option :label="t('order.adminWithdrawOrder.receive_type_ewallet')" value="ewallet" />
|
||||
<el-option :label="t('order.adminWithdrawOrder.receive_type_crypto')" value="crypto" />
|
||||
</el-select>
|
||||
</div>
|
||||
<Table ref="tableRef"></Table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, provide, reactive, ref, useTemplateRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { baTableApi } from '/@/api/common'
|
||||
import TableHeader from '/@/components/table/header/index.vue'
|
||||
import Table from '/@/components/table/index.vue'
|
||||
import baTableClass from '/@/utils/baTable'
|
||||
import createAxios from '/@/utils/axios'
|
||||
|
||||
defineOptions({
|
||||
name: 'order/adminWithdrawOrder',
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const tableRef = useTemplateRef('tableRef')
|
||||
const statusFilterMode = ref<'all' | 'pending' | 'approved' | 'rejected'>('all')
|
||||
const receiveTypeFilterMode = ref<'all' | 'bank' | 'ewallet' | 'crypto'>('all')
|
||||
const stats = reactive({
|
||||
total_count: 0,
|
||||
pending_count: 0,
|
||||
approved_count: 0,
|
||||
rejected_count: 0,
|
||||
total_amount: '0.00',
|
||||
pending_amount: '0.00',
|
||||
approved_amount: '0.00',
|
||||
})
|
||||
|
||||
const onReview = async (row: anyObj, action: 'approve' | 'reject') => {
|
||||
const needReason = action === 'reject'
|
||||
const { value } = await ElMessageBox.prompt(
|
||||
needReason ? t('order.adminWithdrawOrder.reject_reason_required') : t('order.adminWithdrawOrder.review_remark_optional'),
|
||||
action === 'approve' ? t('order.adminWithdrawOrder.review_approve_title') : t('order.adminWithdrawOrder.review_reject_title'),
|
||||
{
|
||||
confirmButtonText: t('Confirm'),
|
||||
cancelButtonText: t('Cancel'),
|
||||
inputPlaceholder: needReason ? t('order.adminWithdrawOrder.reject_reason_required') : t('order.adminWithdrawOrder.review_remark_optional'),
|
||||
inputPattern: needReason ? /.+/ : undefined,
|
||||
inputErrorMessage: needReason ? t('order.adminWithdrawOrder.reject_reason_required') : '',
|
||||
})
|
||||
await createAxios(
|
||||
{
|
||||
url: `/admin/order.AdminWithdrawOrder/${action}`,
|
||||
method: 'post',
|
||||
data: { id: row.id, remark: value || '' },
|
||||
},
|
||||
{ showSuccessMessage: true }
|
||||
)
|
||||
await loadStats()
|
||||
baTable.getData()
|
||||
}
|
||||
|
||||
const optButtons: OptButton[] = [
|
||||
{
|
||||
render: 'tipButton',
|
||||
name: 'approve',
|
||||
title: 'order.adminWithdrawOrder.review_btn_approve',
|
||||
text: '',
|
||||
type: 'success',
|
||||
icon: 'el-icon-Check',
|
||||
display: (row: TableRow) => Number(row.status) === 0,
|
||||
click: (row: TableRow) => void onReview(row as anyObj, 'approve'),
|
||||
},
|
||||
{
|
||||
render: 'tipButton',
|
||||
name: 'reject',
|
||||
title: 'order.adminWithdrawOrder.review_btn_reject',
|
||||
text: '',
|
||||
type: 'danger',
|
||||
icon: 'el-icon-Close',
|
||||
display: (row: TableRow) => Number(row.status) === 0,
|
||||
click: (row: TableRow) => void onReview(row as anyObj, 'reject'),
|
||||
},
|
||||
]
|
||||
|
||||
const baTable = new baTableClass(
|
||||
new baTableApi('/admin/order.AdminWithdrawOrder/'),
|
||||
{
|
||||
pk: 'id',
|
||||
column: [
|
||||
{ type: 'selection', align: 'center', operator: false },
|
||||
{ label: t('order.adminWithdrawOrder.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||
{ label: t('order.adminWithdrawOrder.order_no'), prop: 'order_no', align: 'center', minWidth: 170, operator: 'LIKE' },
|
||||
{ label: t('order.adminWithdrawOrder.admin_username'), prop: 'admin.username', align: 'center', minWidth: 120, operator: 'LIKE' },
|
||||
{ label: t('order.adminWithdrawOrder.channel_name'), prop: 'channel.name', align: 'center', minWidth: 120, operator: 'LIKE' },
|
||||
{ label: t('order.adminWithdrawOrder.amount'), prop: 'amount', align: 'center', minWidth: 100, operator: 'RANGE' },
|
||||
{ label: t('order.adminWithdrawOrder.actual_amount'), prop: 'actual_amount', align: 'center', minWidth: 100, operator: 'RANGE' },
|
||||
{
|
||||
label: t('order.adminWithdrawOrder.status'),
|
||||
prop: 'status',
|
||||
align: 'center',
|
||||
operator: 'eq',
|
||||
render: 'tag',
|
||||
custom: { 0: 'warning', 1: 'success', 2: 'danger' },
|
||||
replaceValue: {
|
||||
0: t('order.adminWithdrawOrder.status 0'),
|
||||
1: t('order.adminWithdrawOrder.status 1'),
|
||||
2: t('order.adminWithdrawOrder.status 2'),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('order.adminWithdrawOrder.receive_type'),
|
||||
prop: 'receive_type',
|
||||
align: 'center',
|
||||
minWidth: 110,
|
||||
operator: 'eq',
|
||||
render: 'tag',
|
||||
custom: { bank: 'primary', ewallet: 'success', crypto: 'warning' },
|
||||
replaceValue: {
|
||||
bank: t('order.adminWithdrawOrder.receive_type_bank'),
|
||||
ewallet: t('order.adminWithdrawOrder.receive_type_ewallet'),
|
||||
crypto: t('order.adminWithdrawOrder.receive_type_crypto'),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('order.adminWithdrawOrder.receive_account'),
|
||||
prop: 'receive_account',
|
||||
align: 'center',
|
||||
minWidth: 160,
|
||||
operator: 'LIKE',
|
||||
showOverflowTooltip: true,
|
||||
},
|
||||
{ label: t('order.adminWithdrawOrder.review_admin_username'), prop: 'reviewAdmin.username', align: 'center', minWidth: 120, operator: 'LIKE' },
|
||||
{ label: t('order.adminWithdrawOrder.remark'), prop: 'remark', align: 'center', minWidth: 180, operator: 'LIKE', showOverflowTooltip: true },
|
||||
{
|
||||
label: t('order.adminWithdrawOrder.create_time'),
|
||||
prop: 'create_time',
|
||||
align: 'center',
|
||||
render: 'datetime',
|
||||
operator: 'RANGE',
|
||||
comSearchRender: 'datetime',
|
||||
sortable: 'custom',
|
||||
width: 160,
|
||||
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||
},
|
||||
{ label: t('Operate'), align: 'center', width: 90, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
|
||||
],
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
const onStatusFilterChange = () => {
|
||||
baTable.getData()
|
||||
}
|
||||
|
||||
const loadStats = async () => {
|
||||
const res = await createAxios({ url: '/admin/order.AdminWithdrawOrder/stats', method: 'get' })
|
||||
if (res.code !== 1 || !res.data) {
|
||||
return
|
||||
}
|
||||
stats.total_count = Number(res.data.total_count ?? 0)
|
||||
stats.pending_count = Number(res.data.pending_count ?? 0)
|
||||
stats.approved_count = Number(res.data.approved_count ?? 0)
|
||||
stats.rejected_count = Number(res.data.rejected_count ?? 0)
|
||||
stats.total_amount = String(res.data.total_amount ?? '0.00')
|
||||
stats.pending_amount = String(res.data.pending_amount ?? '0.00')
|
||||
stats.approved_amount = String(res.data.approved_amount ?? '0.00')
|
||||
}
|
||||
|
||||
baTable.before.getData = () => {
|
||||
const filter = baTable.table.filter || {}
|
||||
const searchRaw = filter.search
|
||||
const search = Array.isArray(searchRaw)
|
||||
? searchRaw.filter((item: any) => item && item.field !== 'status' && item.field !== 'receive_type')
|
||||
: []
|
||||
if (statusFilterMode.value === 'pending') {
|
||||
search.push({ field: 'status', operator: 'eq', val: 0 })
|
||||
} else if (statusFilterMode.value === 'approved') {
|
||||
search.push({ field: 'status', operator: 'eq', val: 1 })
|
||||
} else if (statusFilterMode.value === 'rejected') {
|
||||
search.push({ field: 'status', operator: 'eq', val: 2 })
|
||||
}
|
||||
if (receiveTypeFilterMode.value !== 'all') {
|
||||
search.push({ field: 'receive_type', operator: 'eq', val: receiveTypeFilterMode.value })
|
||||
}
|
||||
filter.search = search
|
||||
baTable.table.filter = filter
|
||||
}
|
||||
|
||||
baTable.after.getData = () => {
|
||||
void loadStats()
|
||||
}
|
||||
|
||||
provide('baTable', baTable)
|
||||
|
||||
onMounted(() => {
|
||||
baTable.table.ref = tableRef.value
|
||||
baTable.mount()
|
||||
baTable.getData()?.then(() => {
|
||||
baTable.initSort()
|
||||
baTable.dragSort()
|
||||
})
|
||||
void loadStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.withdraw-stats-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.withdraw-stat-card .label {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.withdraw-stat-card .value {
|
||||
margin-top: 6px;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.withdraw-filter-row {
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.receive-type-filter {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.withdraw-stats-cards {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -27,6 +27,20 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-info-form">
|
||||
<el-card shadow="never" class="wallet-card">
|
||||
<template #header>
|
||||
<div class="wallet-card-header">
|
||||
<span>{{ t('routine.adminInfo.admin_wallet') }}</span>
|
||||
<el-button type="primary" link @click="state.withdrawDialogVisible = true">{{ t('routine.adminInfo.withdraw') }}</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<div class="wallet-metrics">
|
||||
<div>{{ t('routine.adminInfo.wallet_balance') }}:{{ state.wallet.balance }}</div>
|
||||
<div>{{ t('routine.adminInfo.wallet_frozen_balance') }}:{{ state.wallet.frozen_balance }}</div>
|
||||
<div>{{ t('routine.adminInfo.wallet_total_income') }}:{{ state.wallet.total_income }}</div>
|
||||
<div>{{ t('routine.adminInfo.wallet_total_withdraw') }}:{{ state.wallet.total_withdraw }}</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-form
|
||||
@keyup.enter="onSubmit()"
|
||||
:key="state.formKey"
|
||||
@@ -99,13 +113,40 @@
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-dialog v-model="state.withdrawDialogVisible" :title="t('routine.adminInfo.withdraw_apply_title')" width="520px" :close-on-click-modal="false">
|
||||
<el-form label-width="100px">
|
||||
<el-form-item :label="t('routine.adminInfo.withdraw_coin')">
|
||||
<el-input v-model="state.withdrawForm.withdraw_coin" :placeholder="t('routine.adminInfo.withdraw_coin_placeholder')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.adminInfo.receive_type')">
|
||||
<el-select v-model="state.withdrawForm.receive_type" class="w100" :placeholder="t('routine.adminInfo.receive_type_placeholder')">
|
||||
<el-option label="bank" value="bank" />
|
||||
<el-option label="ewallet" value="ewallet" />
|
||||
<el-option label="crypto" value="crypto" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.adminInfo.receive_account')">
|
||||
<el-input v-model="state.withdrawForm.receive_account" :placeholder="t('routine.adminInfo.receive_account_placeholder')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.adminInfo.idempotency_key')">
|
||||
<el-input v-model="state.withdrawForm.idempotency_key" :placeholder="t('routine.adminInfo.idempotency_key_placeholder')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.adminInfo.remark')">
|
||||
<el-input v-model="state.withdrawForm.remark" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="state.withdrawDialogVisible = false">{{ t('Cancel') }}</el-button>
|
||||
<el-button type="primary" :loading="state.withdrawSubmitting" @click="onWithdrawApply">{{ t('routine.adminInfo.submit_apply') }}</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, useTemplateRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { index, log, postData } from '/@/api/backend/routine/AdminInfo'
|
||||
import { index, log, postData, walletSummary, withdrawApply } from '/@/api/backend/routine/AdminInfo'
|
||||
import type { FormItemRule } from 'element-plus'
|
||||
import { fullUrl, onResetForm, timeFormat } from '/@/utils/common'
|
||||
import { uuid } from '../../../utils/random'
|
||||
@@ -137,6 +178,10 @@ const state: {
|
||||
logPageSize: number
|
||||
logTotal: number
|
||||
logLoading: boolean
|
||||
wallet: { balance: string; frozen_balance: string; total_income: string; total_withdraw: string }
|
||||
withdrawDialogVisible: boolean
|
||||
withdrawSubmitting: boolean
|
||||
withdrawForm: { withdraw_coin: string; receive_type: string; receive_account: string; idempotency_key: string; remark: string }
|
||||
} = reactive({
|
||||
adminInfo: {},
|
||||
formKey: uuid(),
|
||||
@@ -149,6 +194,10 @@ const state: {
|
||||
logPageSize: 12,
|
||||
logTotal: 100,
|
||||
logLoading: true,
|
||||
wallet: { balance: '0.00', frozen_balance: '0.00', total_income: '0.00', total_withdraw: '0.00' },
|
||||
withdrawDialogVisible: false,
|
||||
withdrawSubmitting: false,
|
||||
withdrawForm: { withdraw_coin: '100.00', receive_type: 'bank', receive_account: '', idempotency_key: '', remark: '' },
|
||||
})
|
||||
|
||||
index().then((res) => {
|
||||
@@ -165,8 +214,15 @@ index().then((res) => {
|
||||
},
|
||||
]
|
||||
getLog()
|
||||
loadWalletSummary()
|
||||
})
|
||||
|
||||
const loadWalletSummary = () => {
|
||||
walletSummary().then((res) => {
|
||||
state.wallet = res.data?.wallet || state.wallet
|
||||
})
|
||||
}
|
||||
|
||||
const getLog = () => {
|
||||
log(state.logFilter)
|
||||
.then((res) => {
|
||||
@@ -233,6 +289,26 @@ const onSubmit = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onWithdrawApply = () => {
|
||||
state.withdrawSubmitting = true
|
||||
if (!state.withdrawForm.idempotency_key) {
|
||||
state.withdrawForm.idempotency_key = `admin_withdraw_${Date.now()}_${Math.floor(Math.random() * 100000)}`
|
||||
}
|
||||
withdrawApply({ ...state.withdrawForm })
|
||||
.then(() => {
|
||||
state.withdrawDialogVisible = false
|
||||
state.withdrawForm.withdraw_coin = '100.00'
|
||||
state.withdrawForm.receive_type = 'bank'
|
||||
state.withdrawForm.receive_account = ''
|
||||
state.withdrawForm.idempotency_key = ''
|
||||
state.withdrawForm.remark = ''
|
||||
loadWalletSummary()
|
||||
})
|
||||
.finally(() => {
|
||||
state.withdrawSubmitting = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -286,6 +362,24 @@ const onSubmit = () => {
|
||||
padding: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
.wallet-card {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.wallet-card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.wallet-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.el-card :deep(.el-timeline-item__icon) {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user