Compare commits
74 Commits
master
...
8e51ca8930
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e51ca8930 | |||
| 425e9feb56 | |||
| e5543ae6e4 | |||
| 0b2f4a026e | |||
| 1213f8e58a | |||
| 27e9de0ac9 | |||
| 502404af17 | |||
| 76aa9bde8b | |||
| 72b43759f1 | |||
| ed46f18415 | |||
| 05d592dcbc | |||
| 2419f81955 | |||
| 2de54e17c3 | |||
| 0b26afde70 | |||
| f5eaf8da30 | |||
| b79904f75e | |||
| 6b21626878 | |||
| 7445dc4cb0 | |||
| e8620998ae | |||
| 3182d04956 | |||
| cc7e2d9a1a | |||
| 7e4ba86afa | |||
| 064ce06393 | |||
| 2af7fedcce | |||
| bb166350fd | |||
| 84d499145d | |||
| 54aa0bd34f | |||
| 1a748745cb | |||
| bc034727b0 | |||
| e56c3ada34 | |||
| 296991f53a | |||
| 1f8d76e80b | |||
| 5afaa9fcb2 | |||
| 6f56574aac | |||
| fdd8f6dffa | |||
| b1efeb8b31 | |||
| 275f94f96d | |||
| 9452fd28e2 | |||
| 7716929447 | |||
| a6d87d5c0d | |||
| e94ebd3fe6 | |||
| 99a0b63f0e | |||
| fbf8f9d39d | |||
| e726fc3041 | |||
| a37da0b6f5 | |||
| 1de9af703a | |||
| 4cf0da8092 | |||
| 6632923213 | |||
| 316506b597 | |||
| 282d73a203 | |||
| 4b6bbab9d1 | |||
| e312154b0f | |||
| fe1ceeb4fb | |||
| 7e5585aee0 | |||
| e087f89df5 | |||
| 1cb2e26a77 | |||
| 330bd3b525 | |||
| dc86d0ae86 | |||
| 8cd7de9f1b | |||
| 27f95a303a | |||
| 931af70c36 | |||
| f7d9b18f02 | |||
| c1b4790f04 | |||
| 943d8f7b5f | |||
| 01f71a4871 | |||
| 02549f4feb | |||
| 7a4d89d216 | |||
| cfe026b5eb | |||
| 768cf5137c | |||
| 7e8867ed12 | |||
| 005f261e03 | |||
| effdaaa38b | |||
| aef404548d | |||
| 39955a17a8 |
@@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SaiAdmin</title>
|
||||
<title>Dafuweng-Dice</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
"eslint-plugin-vue": "^9.27.0",
|
||||
"globals": "^15.9.0",
|
||||
"husky": "^9.1.5",
|
||||
"iconv-lite": "^0.7.2",
|
||||
"lint-staged": "^15.5.2",
|
||||
"prettier": "^3.5.3",
|
||||
"rollup-plugin-visualizer": "^5.12.0",
|
||||
|
||||
11
saiadmin-artd/pnpm-lock.yaml
generated
11
saiadmin-artd/pnpm-lock.yaml
generated
@@ -144,6 +144,9 @@ importers:
|
||||
husky:
|
||||
specifier: ^9.1.5
|
||||
version: 9.1.7
|
||||
iconv-lite:
|
||||
specifier: ^0.7.2
|
||||
version: 0.7.2
|
||||
lint-staged:
|
||||
specifier: ^15.5.2
|
||||
version: 15.5.2
|
||||
@@ -2549,6 +2552,10 @@ packages:
|
||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
iconv-lite@0.7.2:
|
||||
resolution: {integrity: sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
ieee754@1.2.1:
|
||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||
|
||||
@@ -6767,6 +6774,10 @@ snapshots:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
|
||||
iconv-lite@0.7.2:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
|
||||
ieee754@1.2.1: {}
|
||||
|
||||
ignore@5.3.2: {}
|
||||
|
||||
@@ -1,31 +1,66 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 基础数据统计
|
||||
* 大富翁工作台卡片统计(玩家注册、充值、提现、游玩次数,含较上周对比)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchStatistics() {
|
||||
return request.get<any>({
|
||||
url: '/core/system/statistics'
|
||||
url: '/core/dice/dashboard/statistics'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录统计图表数据
|
||||
* 近期玩家充值统计(近10天每日充值金额)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchLoginChart() {
|
||||
export function fetchRechargeChart() {
|
||||
return request.get<any>({
|
||||
url: '/core/system/loginChart'
|
||||
url: '/core/dice/dashboard/rechargeChart'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录统计图表数据
|
||||
* 月度玩家充值汇总(当年1-12月每月充值金额)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchLoginBarChart() {
|
||||
export function fetchRechargeBarChart() {
|
||||
return request.get<any>({
|
||||
url: '/core/system/loginBarChart'
|
||||
url: '/core/dice/dashboard/rechargeBarChart'
|
||||
})
|
||||
}
|
||||
|
||||
/** 玩家充值记录项 */
|
||||
export interface WalletRecordItem {
|
||||
player_name: string
|
||||
coin: number
|
||||
create_time: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作台-玩家充值记录(最新50条)
|
||||
* @returns 列表
|
||||
*/
|
||||
export function fetchWalletRecordList() {
|
||||
return request.get<WalletRecordItem[]>({
|
||||
url: '/core/dice/dashboard/walletRecordList'
|
||||
})
|
||||
}
|
||||
|
||||
/** 新增玩家记录项 */
|
||||
export interface NewPlayerItem {
|
||||
name: string
|
||||
coin: number
|
||||
total_ticket_count: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作台-新增玩家记录(最新50条)
|
||||
* @returns 列表
|
||||
*/
|
||||
export function fetchNewPlayerList() {
|
||||
return request.get<NewPlayerItem[]>({
|
||||
url: '/core/dice/dashboard/newPlayerList'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
// 数据配置
|
||||
data: () => [0, 0, 0, 0, 0, 0, 0],
|
||||
xAxisData: () => [],
|
||||
xAxisName: '',
|
||||
barWidth: '40%',
|
||||
stack: false,
|
||||
|
||||
@@ -124,24 +125,30 @@
|
||||
} = useChartComponent({
|
||||
props,
|
||||
checkEmpty: () => {
|
||||
// 检查单数据情况
|
||||
if (Array.isArray(props.data) && typeof props.data[0] === 'number') {
|
||||
if (!Array.isArray(props.data) || !props.data.length) return true
|
||||
|
||||
const first = props.data[0]
|
||||
// 单数据情况:number[] 或可转为数字的数组(兼容后端 int 返回为 string)
|
||||
if (typeof first === 'number' && !Number.isNaN(first)) {
|
||||
const singleData = props.data as number[]
|
||||
return !singleData.length || singleData.every((val) => val === 0)
|
||||
return singleData.every((val) => val === 0 || Number.isNaN(Number(val)))
|
||||
}
|
||||
if (typeof first === 'string' && !Number.isNaN(Number(first))) {
|
||||
const singleData = props.data.map((v) => Number(v))
|
||||
return singleData.every((val) => val === 0 || Number.isNaN(val))
|
||||
}
|
||||
|
||||
// 检查多数据情况
|
||||
if (Array.isArray(props.data) && typeof props.data[0] === 'object') {
|
||||
// 多数据情况
|
||||
if (typeof first === 'object' && first !== null && 'name' in first) {
|
||||
const multiData = props.data as BarDataItem[]
|
||||
return (
|
||||
!multiData.length ||
|
||||
multiData.every((item) => !item.data?.length || item.data.every((val) => val === 0))
|
||||
return multiData.every(
|
||||
(item) => !item.data?.length || item.data.every((val) => val === 0 || Number.isNaN(Number(val)))
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
watchSources: [() => props.data, () => props.xAxisData, () => props.colors],
|
||||
watchSources: [() => props.data, () => props.xAxisData, () => props.xAxisName, () => props.colors],
|
||||
generateOptions: (): EChartsOption => {
|
||||
const options: EChartsOption = {
|
||||
grid: getGridWithLegend(props.showLegend && isMultipleData.value, props.legendPosition, {
|
||||
@@ -152,6 +159,9 @@
|
||||
tooltip: props.showTooltip ? getTooltipStyle() : undefined,
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
name: props.xAxisName || undefined,
|
||||
nameLocation: 'middle',
|
||||
nameGap: 25,
|
||||
data: props.xAxisData,
|
||||
axisTick: getAxisTickStyle(),
|
||||
axisLine: getAxisLineStyle(props.showAxisLine),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
>
|
||||
<span
|
||||
class="block max-w-46 overflow-hidden text-ellipsis whitespace-nowrap px-1.5 text-sm text-g-600 dark:text-g-800"
|
||||
>{{ formatMenuTitle(item.meta?.title as string) }}</span
|
||||
>{{ formatMenuTitle(item.meta?.title as string, item.path) }}</span
|
||||
>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
@click="searchGoPage(item)"
|
||||
@mouseenter="highlightOnHover(index)"
|
||||
>
|
||||
{{ formatMenuTitle(item.meta.title) }}
|
||||
{{ formatMenuTitle(item.meta.title, item.path) }}
|
||||
<ArtSvgIcon v-show="isHighlighted(index)" icon="fluent:arrow-enter-left-20-filled" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,7 +60,7 @@
|
||||
@click="searchGoPage(item)"
|
||||
@mouseenter="highlightOnHoverHistory(index)"
|
||||
>
|
||||
{{ formatMenuTitle(item.meta.title) }}
|
||||
{{ formatMenuTitle(item.meta.title, item.path) }}
|
||||
<div
|
||||
class="size-5 selected-icon select-none rounded-full text-g-500 flex-cc c-p"
|
||||
@click.stop="deleteHistory(index)"
|
||||
@@ -182,7 +182,7 @@
|
||||
const flattenAndMatch = (item: AppRouteRecord) => {
|
||||
if (item.meta?.isHide) return
|
||||
|
||||
const lowerItemTitle = formatMenuTitle(item.meta.title).toLowerCase()
|
||||
const lowerItemTitle = formatMenuTitle(item.meta.title, item.path).toLowerCase()
|
||||
|
||||
if (item.children && item.children.length > 0) {
|
||||
item.children.forEach(flattenAndMatch)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<ElSubMenu v-if="hasChildren" :index="item.path || item.meta.title" class="!p-0">
|
||||
<template #title>
|
||||
<ArtSvgIcon :icon="item.meta.icon" :color="theme?.iconColor" class="mr-1 text-lg" />
|
||||
<span class="text-md">{{ formatMenuTitle(item.meta.title) }}</span>
|
||||
<span class="text-md">{{ formatMenuTitle(item.meta.title, item.path) }}</span>
|
||||
<div v-if="item.meta.showBadge" class="art-badge art-badge-horizontal" />
|
||||
<div v-if="item.meta.showTextBadge" class="art-text-badge">
|
||||
{{ item.meta.showTextBadge }}
|
||||
@@ -32,7 +32,7 @@
|
||||
class="mr-1 text-lg"
|
||||
:style="{ color: theme.iconColor }"
|
||||
/>
|
||||
<span class="text-md">{{ formatMenuTitle(item.meta.title) }}</span>
|
||||
<span class="text-md">{{ formatMenuTitle(item.meta.title, item.path) }}</span>
|
||||
<div
|
||||
v-if="item.meta.showBadge"
|
||||
class="art-badge"
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
return props.list.map((item) => ({
|
||||
...item,
|
||||
isActive: isMenuItemActive(item),
|
||||
formattedTitle: formatMenuTitle(item.meta.title)
|
||||
formattedTitle: formatMenuTitle(item.meta.title, item.path)
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<ElTooltip
|
||||
class="box-item"
|
||||
effect="dark"
|
||||
:content="$t(menu.meta.title)"
|
||||
:content="formatMenuTitle(menu.meta.title, menu.path)"
|
||||
placement="right"
|
||||
:offset="15"
|
||||
:hide-after="0"
|
||||
@@ -43,7 +43,7 @@
|
||||
}"
|
||||
/>
|
||||
<span v-if="dualMenuShowText" class="text-md text-g-700">
|
||||
{{ $t(menu.meta.title) }}
|
||||
{{ formatMenuTitle(menu.meta.title, menu.path) }}
|
||||
</span>
|
||||
<div v-if="menu.meta.showBadge" class="art-badge art-badge-dual" />
|
||||
</div>
|
||||
@@ -136,6 +136,7 @@
|
||||
import { useMenuStore } from '@/store/modules/menu'
|
||||
import { isIframe } from '@/utils/navigation'
|
||||
import { handleMenuJump } from '@/utils/navigation'
|
||||
import { formatMenuTitle } from '@/utils/router'
|
||||
import SidebarSubmenu from './widget/SidebarSubmenu.vue'
|
||||
import { useCommon } from '@/hooks/core/useCommon'
|
||||
import { useWindowSize, useTimeoutFn } from '@vueuse/core'
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/>
|
||||
</div>
|
||||
<span class="menu-name">
|
||||
{{ formatMenuTitle(item.meta.title) }}
|
||||
{{ formatMenuTitle(item.meta.title, item.path) }}
|
||||
</span>
|
||||
<div v-if="item.meta.showBadge" class="art-badge" style="right: 10px" />
|
||||
</template>
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
<template #title>
|
||||
<span class="menu-name">
|
||||
{{ formatMenuTitle(item.meta.title) }}
|
||||
{{ formatMenuTitle(item.meta.title, item.path) }}
|
||||
</span>
|
||||
<div v-if="item.meta.showBadge" class="art-badge" />
|
||||
<div v-if="item.meta.showTextBadge && (level > 0 || menuOpen)" class="art-text-badge">
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
class="text-base mr-1 group-hover:text-theme"
|
||||
:class="item.path === activeTab ? 'text-theme' : 'text-g-600'"
|
||||
/>
|
||||
{{ item.customTitle || formatMenuTitle(item.title) }}
|
||||
{{ item.customTitle || formatMenuTitle(item.title, item.path) }}
|
||||
<span
|
||||
v-if="list.length > 1 && !item.fixedTab"
|
||||
class="inline-flex flex-cc relative ml-0.5 p-1 rounded-full tad-200 hover:bg-g-200"
|
||||
|
||||
@@ -38,7 +38,7 @@ import { headerBarConfig } from './modules/headerBar'
|
||||
const appConfig: SystemConfig = {
|
||||
// 系统信息
|
||||
systemInfo: {
|
||||
name: 'SaiAdmin' // 系统名称
|
||||
name: 'Dafuweng-Dice' // 系统名称
|
||||
},
|
||||
// 系统主题
|
||||
systemThemeStyles: {
|
||||
|
||||
@@ -150,8 +150,8 @@
|
||||
},
|
||||
"login": {
|
||||
"leftView": {
|
||||
"title": "A backend system of beauty and efficiency",
|
||||
"subTitle": "A sleek and practical interface for a great user experience"
|
||||
"title": "Monopoly Game Management",
|
||||
"subTitle": "Monopoly Game Management"
|
||||
},
|
||||
"title": "Welcome back",
|
||||
"subTitle": "Please enter your account and password to login",
|
||||
@@ -245,7 +245,11 @@
|
||||
},
|
||||
"dashboard": {
|
||||
"title": "Dashboard",
|
||||
"console": "Console"
|
||||
"console": "Console",
|
||||
"userCenter": "User Center"
|
||||
},
|
||||
"userCenter": {
|
||||
"title": "User Center"
|
||||
},
|
||||
"result": {
|
||||
"title": "Result Page",
|
||||
@@ -259,11 +263,43 @@
|
||||
"serverError": "500"
|
||||
},
|
||||
"system": {
|
||||
"title": "System Settings",
|
||||
"user": "User Manage",
|
||||
"role": "Role Manage",
|
||||
"title": "System Management",
|
||||
"user": "User Management",
|
||||
"role": "Role Management",
|
||||
"userCenter": "User Center",
|
||||
"menu": "Menu Manage"
|
||||
"menu": "Menu Management",
|
||||
"dept": "Department Management",
|
||||
"post": "Post Management",
|
||||
"config": "System Config"
|
||||
},
|
||||
"safeguard": {
|
||||
"title": "Operations Management",
|
||||
"dict": "Data Dictionary",
|
||||
"server": "Server Monitor",
|
||||
"operLog": "Operation Log",
|
||||
"loginLog": "Login Log",
|
||||
"emailLog": "Email Log",
|
||||
"database": "Database",
|
||||
"cache": "Cache Management",
|
||||
"attachment": "Attachment"
|
||||
},
|
||||
"tool": {
|
||||
"title": "Development Tools",
|
||||
"crontab": "Crontab",
|
||||
"code": "Code Generator"
|
||||
},
|
||||
"dice": {
|
||||
"title": "Dice Game",
|
||||
"lotteryPoolConfig": "Lottery Tier Weight Config",
|
||||
"player": "Player Management",
|
||||
"playerWalletRecord": "Player Wallet Records",
|
||||
"playRecord": "Player Draw Records",
|
||||
"playerTicketRecord": "Player Ticket Records",
|
||||
"rewardConfig": "Reward Config",
|
||||
"reward": "Dice Point Weight Config",
|
||||
"rewardConfigRecord": "Dice Weight Test Records",
|
||||
"playRecordTest": "Draw Records (Test Weight)",
|
||||
"config": "Game Config"
|
||||
}
|
||||
},
|
||||
"table": {
|
||||
|
||||
@@ -150,8 +150,8 @@
|
||||
},
|
||||
"login": {
|
||||
"leftView": {
|
||||
"title": "一款兼具设计美学与高效开发的后台系统",
|
||||
"subTitle": "美观实用的界面,经过视觉优化,确保卓越的用户体验"
|
||||
"title": "大富翁游戏管理",
|
||||
"subTitle": "大富翁游戏管理"
|
||||
},
|
||||
"title": "欢迎回来",
|
||||
"subTitle": "输入您的账号和密码登录",
|
||||
|
||||
@@ -117,6 +117,8 @@ export interface BarChartProps extends BaseChartProps, AxisDisplayProps, Interac
|
||||
data: number[] | BarDataItem[]
|
||||
/** X轴标签数据 */
|
||||
xAxisData?: string[]
|
||||
/** X轴名称(如:色子点数) */
|
||||
xAxisName?: string
|
||||
/** 柱状图宽度 */
|
||||
barWidth?: string | number
|
||||
/** 是否堆叠显示 */
|
||||
|
||||
@@ -21,8 +21,8 @@ import { HttpError, handleError, showError, showSuccess } from './error'
|
||||
import { $t } from '@/locales'
|
||||
import { BaseResponse } from '@/types'
|
||||
|
||||
/** 请求配置常量 */
|
||||
const REQUEST_TIMEOUT = 15000
|
||||
/** 请求配置常量(超时时间 30s) */
|
||||
const REQUEST_TIMEOUT = 30000
|
||||
const LOGOUT_DELAY = 500
|
||||
const MAX_RETRIES = 0
|
||||
const RETRY_DELAY = 1000
|
||||
|
||||
@@ -11,6 +11,62 @@ import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import i18n, { $t } from '@/locales'
|
||||
|
||||
/**
|
||||
* 路径到菜单 i18n key 的映射
|
||||
* 当后端返回的菜单名为中文或非 i18n key 时,根据 path 仍可显示多语言
|
||||
*/
|
||||
export const MAP_PATH_TO_MENU_I18N_KEY: Record<string, string> = {
|
||||
'/dashboard': 'menus.dashboard.title',
|
||||
'/dashboard/console': 'menus.dashboard.console',
|
||||
'/dashboard/user-center': 'menus.userCenter.title',
|
||||
'/system': 'menus.system.title',
|
||||
'/system/user': 'menus.system.user',
|
||||
'/system/role': 'menus.system.role',
|
||||
'/system/user-center': 'menus.system.userCenter',
|
||||
'/system/menu': 'menus.system.menu',
|
||||
'/system/dept': 'menus.system.dept',
|
||||
'/system/post': 'menus.system.post',
|
||||
'/system/config': 'menus.system.config',
|
||||
'/safeguard': 'menus.safeguard.title',
|
||||
'/safeguard/dict': 'menus.safeguard.dict',
|
||||
'/safeguard/server': 'menus.safeguard.server',
|
||||
'/safeguard/oper-log': 'menus.safeguard.operLog',
|
||||
'/safeguard/login-log': 'menus.safeguard.loginLog',
|
||||
'/safeguard/email-log': 'menus.safeguard.emailLog',
|
||||
'/safeguard/database': 'menus.safeguard.database',
|
||||
'/safeguard/cache': 'menus.safeguard.cache',
|
||||
'/safeguard/attachment': 'menus.safeguard.attachment',
|
||||
'/tool': 'menus.tool.title',
|
||||
'/tool/crontab': 'menus.tool.crontab',
|
||||
'/tool/code': 'menus.tool.code',
|
||||
'/dice': 'menus.dice.title',
|
||||
'/dice/lottery_pool_config': 'menus.dice.lotteryPoolConfig',
|
||||
'/dice/lottery_pool_config/index': 'menus.dice.lotteryPoolConfig',
|
||||
'/dice/player': 'menus.dice.player',
|
||||
'/dice/player/index': 'menus.dice.player',
|
||||
'/dice/player_wallet_record': 'menus.dice.playerWalletRecord',
|
||||
'/dice/player_wallet_record/index': 'menus.dice.playerWalletRecord',
|
||||
'/dice/play_record': 'menus.dice.playRecord',
|
||||
'/dice/play_record/index': 'menus.dice.playRecord',
|
||||
'/dice/player_ticket_record': 'menus.dice.playerTicketRecord',
|
||||
'/dice/player_ticket_record/index': 'menus.dice.playerTicketRecord',
|
||||
'/dice/reward_config': 'menus.dice.rewardConfig',
|
||||
'/dice/reward_config/index': 'menus.dice.rewardConfig',
|
||||
'/dice/reward': 'menus.dice.reward',
|
||||
'/dice/reward/index': 'menus.dice.reward',
|
||||
'/dice/reward_config_record': 'menus.dice.rewardConfigRecord',
|
||||
'/dice/reward_config_record/index': 'menus.dice.rewardConfigRecord',
|
||||
'/dice/play_record_test': 'menus.dice.playRecordTest',
|
||||
'/dice/play_record_test/index': 'menus.dice.playRecordTest',
|
||||
'/dice/config': 'menus.dice.config',
|
||||
'/dice/config/index': 'menus.dice.config',
|
||||
'/result/success': 'menus.result.success',
|
||||
'/result/fail': 'menus.result.fail',
|
||||
'/exception/403': 'menus.exception.forbidden',
|
||||
'/exception/404': 'menus.exception.notFound',
|
||||
'/exception/500': 'menus.exception.serverError'
|
||||
}
|
||||
|
||||
/** 扩展的路由配置类型 */
|
||||
export type AppRouteRecordRaw = RouteRecordRaw & {
|
||||
hidden?: boolean
|
||||
@@ -34,28 +90,42 @@ export const setPageTitle = (to: RouteLocationNormalized): void => {
|
||||
const { title } = to.meta
|
||||
if (title) {
|
||||
setTimeout(() => {
|
||||
document.title = `${formatMenuTitle(String(title))} - ${AppConfig.systemInfo.name}`
|
||||
document.title = `${formatMenuTitle(String(title), to.path)} - ${AppConfig.systemInfo.name}`
|
||||
}, 150)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径获取对应的菜单 i18n key(若有)
|
||||
*/
|
||||
export const getMenuI18nKeyByPath = (path: string): string | undefined => {
|
||||
if (!path) return undefined
|
||||
const normalized = path.replace(/\?.*$/, '').replace(/#.*$/, '').replace(/\/$/, '') || '/'
|
||||
return MAP_PATH_TO_MENU_I18N_KEY[normalized]
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化菜单标题
|
||||
* @param title 菜单标题,可以是 i18n 的 key,也可以是字符串
|
||||
* @param title 菜单标题,可以是 i18n 的 key(如 menus.dashboard.title),也可以是中文等纯文本
|
||||
* @param path 可选,当前菜单路由 path;当 title 非 i18n key 时,用 path 查表得到 key 再翻译,以实现多语言切换
|
||||
* @returns 格式化后的菜单标题
|
||||
*/
|
||||
export const formatMenuTitle = (title: string): string => {
|
||||
if (title) {
|
||||
if (title.startsWith('menus.')) {
|
||||
// 使用 te() 方法检查翻译键值是否存在,避免控制台警告
|
||||
if (i18n.global.te(title)) {
|
||||
return $t(title)
|
||||
} else {
|
||||
// 如果翻译不存在,返回键值的最后部分作为fallback
|
||||
return title.split('.').pop() || title
|
||||
}
|
||||
export const formatMenuTitle = (title: string, path?: string): string => {
|
||||
if (!title) return ''
|
||||
|
||||
if (title.startsWith('menus.')) {
|
||||
if (i18n.global.te(title)) {
|
||||
return $t(title)
|
||||
}
|
||||
return title
|
||||
return title.split('.').pop() || title
|
||||
}
|
||||
return ''
|
||||
|
||||
if (path) {
|
||||
const i18nKey = getMenuI18nKeyByPath(path)
|
||||
if (i18nKey && i18n.global.te(i18nKey)) {
|
||||
return $t(i18nKey)
|
||||
}
|
||||
}
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// ANSI 转义码生成网站 https://patorjk.com/software/taag/#p=display&f=Big&t=ABB%0A
|
||||
const asciiArt = `
|
||||
\x1b[32m欢迎使用 SaiAdmin 6.x
|
||||
\x1b[0m
|
||||
\x1b[36mSaiAdmin 官网: https://saithink.top
|
||||
\x1b[0m
|
||||
`
|
||||
console.log(asciiArt)
|
||||
|
||||
@@ -40,9 +40,9 @@ export const tableConfig = {
|
||||
// 总条数
|
||||
totalFields: ['total', 'count'],
|
||||
// 当前页码
|
||||
currentFields: ['current', 'page', 'pageNum'],
|
||||
currentFields: ['current', 'page', 'pageNum', 'current_page'],
|
||||
// 每页大小
|
||||
sizeFields: ['size', 'pageSize', 'limit'],
|
||||
sizeFields: ['size', 'pageSize', 'limit', 'per_page'],
|
||||
|
||||
// 请求参数映射配置,前端发送请求时使用的分页参数名
|
||||
// useTable 组合式函数传递分页参数的时候 用 current 跟 size
|
||||
|
||||
@@ -143,10 +143,10 @@ export const defaultResponseAdapter = <T>(response: unknown): ApiResponse<T> =>
|
||||
total = extractTotal(res, records, tableConfig.totalFields)
|
||||
pagination = extractPagination(res)
|
||||
|
||||
// 如果没有找到,检查嵌套data
|
||||
// 如果没有找到,检查嵌套 data(如 ThinkPHP paginate: { data: { total, per_page, current_page, data: [] } })
|
||||
if (records.length === 0 && 'data' in res && typeof res.data === 'object') {
|
||||
const data = res.data as Record<string, unknown>
|
||||
records = extractRecords(data, ['list', 'records', 'items'])
|
||||
records = extractRecords(data, ['list', 'data', 'records', 'items'])
|
||||
total = extractTotal(data, records, tableConfig.totalFields)
|
||||
pagination = extractPagination(res, data)
|
||||
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
<SalesOverview />
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
|
||||
<ElRow :gutter="20">
|
||||
<ElCol :sm="24" :md="12" :lg="12">
|
||||
<WalletRecordList />
|
||||
</ElCol>
|
||||
<ElCol :sm="24" :md="12" :lg="12">
|
||||
<NewPlayerList />
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
</template>
|
||||
|
||||
<template v-if="userInfo.dashboard === 'work'">
|
||||
@@ -27,8 +36,6 @@
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
</template>
|
||||
|
||||
<AboutProject />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -36,7 +43,8 @@
|
||||
import CardList from './modules/card-list.vue'
|
||||
import ActiveUser from './modules/active-user.vue'
|
||||
import SalesOverview from './modules/sales-overview.vue'
|
||||
import AboutProject from './modules/about-project.vue'
|
||||
import WalletRecordList from './modules/wallet-record-list.vue'
|
||||
import NewPlayerList from './modules/new-player-list.vue'
|
||||
import NewUser from './modules/new-user.vue'
|
||||
import Dynamic from './modules/dynamic-stats.vue'
|
||||
import TodoList from './modules/todo-list.vue'
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<template>
|
||||
<div class="art-card p-5 flex-b mb-5 max-sm:mb-4">
|
||||
<div>
|
||||
<h2 class="text-2xl font-medium">关于项目</h2>
|
||||
<p class="text-g-700 mt-1">{{ systemName }} 是一款兼具设计美学与高效开发的后台系统</p>
|
||||
<p class="text-g-700 mt-1">使用了 webman + Vue3 + Element Plus 高性能、高颜值技术栈</p>
|
||||
|
||||
<div class="flex flex-wrap gap-3.5 max-w-150 mt-9">
|
||||
<div
|
||||
class="w-60 flex-cb h-12.5 px-3.5 border border-g-300 c-p rounded-lg text-sm bg-g-100 duration-300 hover:-translate-y-1 max-sm:w-full"
|
||||
v-for="link in linkList"
|
||||
:key="link.label"
|
||||
@click="goPage(link.url)"
|
||||
>
|
||||
<span class="text-g-700">{{ link.label }}</span>
|
||||
<ArtSvgIcon icon="ri:arrow-right-s-line" class="text-lg text-g-600" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<img class="w-75 max-md:!hidden" src="@imgs/draw/draw1.png" alt="draw1" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import AppConfig from '@/config'
|
||||
|
||||
const systemName = AppConfig.systemInfo.name
|
||||
|
||||
const linkList = [
|
||||
{ label: '项目官网', url: 'https://saithink.top/' },
|
||||
{ label: '文档', url: 'https://saithink.top/documents/' },
|
||||
{ label: 'Github', url: 'https://github.com/saithink/saiadmin' },
|
||||
{ label: '插件市场', url: 'https://saas.saithink.top/' }
|
||||
]
|
||||
|
||||
/**
|
||||
* 在新标签页中打开指定 URL
|
||||
* @param url 要打开的网页地址
|
||||
*/
|
||||
const goPage = (url: string): void => {
|
||||
window.open(url, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
</script>
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="art-card h-105 p-4 box-border mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>月度登录汇总</h4>
|
||||
<h4>月度玩家充值汇总</h4>
|
||||
</div>
|
||||
</div>
|
||||
<ArtBarChart
|
||||
@@ -17,22 +17,22 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchLoginBarChart } from '@/api/dashboard'
|
||||
import { fetchRechargeBarChart } from '@/api/dashboard'
|
||||
|
||||
/**
|
||||
* 登录数据
|
||||
* 充值金额数据
|
||||
*/
|
||||
const yData = ref<number[]>([])
|
||||
|
||||
/**
|
||||
* 时间数据
|
||||
* 月份数据
|
||||
*/
|
||||
const xData = ref<string[]>([])
|
||||
|
||||
onMounted(async () => {
|
||||
fetchLoginBarChart().then((data) => {
|
||||
yData.value = data.login_count
|
||||
xData.value = data.login_month
|
||||
fetchRechargeBarChart().then((data: any) => {
|
||||
yData.value = data?.recharge_amount ?? []
|
||||
xData.value = data?.recharge_month ?? []
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -2,73 +2,95 @@
|
||||
<ElRow :gutter="20" class="flex">
|
||||
<ElCol :sm="12" :md="6" :lg="6">
|
||||
<div class="art-card relative flex flex-col justify-center h-35 px-5 mb-5 max-sm:mb-4">
|
||||
<span class="text-g-700 text-sm">用户统计</span>
|
||||
<ArtCountTo class="text-[26px] font-medium mt-2" :target="statData.user" :duration="1300" />
|
||||
<span class="text-g-700 text-sm">玩家注册</span>
|
||||
<ArtCountTo class="text-[26px] font-medium mt-2" :target="statData.player_count" :duration="1300" />
|
||||
<div class="flex-c mt-1">
|
||||
<span class="text-xs text-g-600">较上周</span>
|
||||
<span class="ml-1 text-xs font-semibold text-success">+10%</span>
|
||||
<span
|
||||
class="ml-1 text-xs font-semibold"
|
||||
:class="changeClass(statData.player_count_change)"
|
||||
>
|
||||
{{ formatChange(statData.player_count_change) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 bottom-0 right-5 m-auto size-12.5 rounded-xl flex-cc bg-theme/10"
|
||||
>
|
||||
<ArtSvgIcon icon="ri:group-line" class="text-xl text-theme" />
|
||||
<ArtSvgIcon icon="ri:user-add-line" class="text-xl text-theme" />
|
||||
</div>
|
||||
</div>
|
||||
</ElCol>
|
||||
<ElCol :sm="12" :md="6" :lg="6">
|
||||
<div class="art-card relative flex flex-col justify-center h-35 px-5 mb-5 max-sm:mb-4">
|
||||
<span class="text-g-700 text-sm">附件统计</span>
|
||||
<span class="text-g-700 text-sm">玩家充值</span>
|
||||
<ArtCountTo
|
||||
class="text-[26px] font-medium mt-2"
|
||||
:target="statData.attach"
|
||||
:target="statData.charge_amount"
|
||||
:duration="1300"
|
||||
:decimals="2"
|
||||
/>
|
||||
<div class="flex-c mt-1">
|
||||
<span class="text-xs text-g-600">较上周</span>
|
||||
<span class="ml-1 text-xs font-semibold text-success">+10%</span>
|
||||
<span
|
||||
class="ml-1 text-xs font-semibold"
|
||||
:class="changeClass(statData.charge_amount_change)"
|
||||
>
|
||||
{{ formatChange(statData.charge_amount_change) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 bottom-0 right-5 m-auto size-12.5 rounded-xl flex-cc bg-theme/10"
|
||||
>
|
||||
<ArtSvgIcon icon="ri:attachment-line" class="text-xl text-theme" />
|
||||
<ArtSvgIcon icon="ri:money-dollar-circle-line" class="text-xl text-theme" />
|
||||
</div>
|
||||
</div>
|
||||
</ElCol>
|
||||
<ElCol :sm="12" :md="6" :lg="6">
|
||||
<div class="art-card relative flex flex-col justify-center h-35 px-5 mb-5 max-sm:mb-4">
|
||||
<span class="text-g-700 text-sm">登录统计</span>
|
||||
<span class="text-g-700 text-sm">玩家提现</span>
|
||||
<ArtCountTo
|
||||
class="text-[26px] font-medium mt-2"
|
||||
:target="statData.login"
|
||||
:target="statData.withdraw_amount"
|
||||
:duration="1300"
|
||||
:decimals="2"
|
||||
/>
|
||||
<div class="flex-c mt-1">
|
||||
<span class="text-xs text-g-600">较上周</span>
|
||||
<span class="ml-1 text-xs font-semibold text-success">+12%</span>
|
||||
<span
|
||||
class="ml-1 text-xs font-semibold"
|
||||
:class="changeClass(statData.withdraw_amount_change)"
|
||||
>
|
||||
{{ formatChange(statData.withdraw_amount_change) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 bottom-0 right-5 m-auto size-12.5 rounded-xl flex-cc bg-theme/10"
|
||||
>
|
||||
<ArtSvgIcon icon="ri:fire-line" class="text-xl text-theme" />
|
||||
<ArtSvgIcon icon="ri:bank-card-line" class="text-xl text-theme" />
|
||||
</div>
|
||||
</div>
|
||||
</ElCol>
|
||||
<ElCol :sm="12" :md="6" :lg="6">
|
||||
<div class="art-card relative flex flex-col justify-center h-35 px-5 mb-5 max-sm:mb-4">
|
||||
<span class="text-g-700 text-sm">操作统计</span>
|
||||
<span class="text-g-700 text-sm">玩家游玩次数</span>
|
||||
<ArtCountTo
|
||||
class="text-[26px] font-medium mt-2"
|
||||
:target="statData.operate"
|
||||
:target="statData.play_count"
|
||||
:duration="1300"
|
||||
/>
|
||||
<div class="flex-c mt-1">
|
||||
<span class="text-xs text-g-600">较上周</span>
|
||||
<span class="ml-1 text-xs font-semibold text-danger">-5%</span>
|
||||
<span
|
||||
class="ml-1 text-xs font-semibold"
|
||||
:class="changeClass(statData.play_count_change)"
|
||||
>
|
||||
{{ formatChange(statData.play_count_change) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 bottom-0 right-5 m-auto size-12.5 rounded-xl flex-cc bg-theme/10"
|
||||
>
|
||||
<ArtSvgIcon icon="ri:pie-chart-line" class="text-xl text-theme" />
|
||||
<ArtSvgIcon icon="ri:gamepad-line" class="text-xl text-theme" />
|
||||
</div>
|
||||
</div>
|
||||
</ElCol>
|
||||
@@ -79,15 +101,40 @@
|
||||
import { fetchStatistics } from '@/api/dashboard'
|
||||
|
||||
const statData = ref({
|
||||
user: 0,
|
||||
attach: 0,
|
||||
login: 0,
|
||||
operate: 0
|
||||
player_count: 0,
|
||||
player_count_change: 0,
|
||||
charge_amount: 0,
|
||||
charge_amount_change: 0,
|
||||
withdraw_amount: 0,
|
||||
withdraw_amount_change: 0,
|
||||
play_count: 0,
|
||||
play_count_change: 0
|
||||
})
|
||||
|
||||
function formatChange(val: number): string {
|
||||
if (val > 0) return `+${val}%`
|
||||
if (val < 0) return `${val}%`
|
||||
return '0%'
|
||||
}
|
||||
|
||||
function changeClass(val: number): string {
|
||||
if (val > 0) return 'text-success'
|
||||
if (val < 0) return 'text-danger'
|
||||
return 'text-g-600'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchStatistics().then((data) => {
|
||||
statData.value = data
|
||||
fetchStatistics().then((data: any) => {
|
||||
statData.value = {
|
||||
player_count: data?.player_count ?? 0,
|
||||
player_count_change: data?.player_count_change ?? 0,
|
||||
charge_amount: data?.charge_amount ?? 0,
|
||||
charge_amount_change: data?.charge_amount_change ?? 0,
|
||||
withdraw_amount: data?.withdraw_amount ?? 0,
|
||||
withdraw_amount_change: data?.withdraw_amount_change ?? 0,
|
||||
play_count: data?.play_count ?? 0,
|
||||
play_count_change: data?.play_count_change ?? 0
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div class="art-card p-5 overflow-hidden mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header mb-4">
|
||||
<div class="title">
|
||||
<h4>新增玩家</h4>
|
||||
<p class="text-g-600 text-sm mt-1">最新50条新增玩家记录</p>
|
||||
</div>
|
||||
</div>
|
||||
<ArtTable
|
||||
class="w-full"
|
||||
:data="tableData"
|
||||
style="width: 100%"
|
||||
size="default"
|
||||
:border="false"
|
||||
:stripe="true"
|
||||
:header-cell-style="{ background: 'transparent' }"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn label="玩家" prop="name" min-width="120" />
|
||||
<ElTableColumn label="余额" prop="coin" min-width="120" align="right">
|
||||
<template #default="scope">
|
||||
{{ formatCoin(scope.row.coin) }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="抽奖券" prop="total_ticket_count" min-width="100" align="right" />
|
||||
</template>
|
||||
</ArtTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchNewPlayerList, type NewPlayerItem } from '@/api/dashboard'
|
||||
|
||||
const tableData = ref<NewPlayerItem[]>([])
|
||||
|
||||
function formatCoin(val: number | undefined): string {
|
||||
if (val === undefined || val === null) return '0.00'
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchNewPlayerList().then((data) => {
|
||||
tableData.value = Array.isArray(data) ? data : []
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="art-card h-105 p-5 mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header">
|
||||
<div class="title">
|
||||
<h4>近期登录统计</h4>
|
||||
<h4>近期玩家充值统计</h4>
|
||||
</div>
|
||||
</div>
|
||||
<ArtLineChart
|
||||
@@ -16,22 +16,22 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchLoginChart } from '@/api/dashboard'
|
||||
import { fetchRechargeChart } from '@/api/dashboard'
|
||||
|
||||
/**
|
||||
* 登录数据
|
||||
* 充值金额数据
|
||||
*/
|
||||
const yData = ref<number[]>([])
|
||||
|
||||
/**
|
||||
* 时间数据
|
||||
* 日期数据
|
||||
*/
|
||||
const xData = ref<string[]>([])
|
||||
|
||||
onMounted(async () => {
|
||||
fetchLoginChart().then((data) => {
|
||||
yData.value = data.login_count
|
||||
xData.value = data.login_date
|
||||
fetchRechargeChart().then((data: any) => {
|
||||
yData.value = data?.recharge_amount ?? []
|
||||
xData.value = data?.recharge_date ?? []
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div class="art-card p-5 overflow-hidden mb-5 max-sm:mb-4">
|
||||
<div class="art-card-header mb-4">
|
||||
<div class="title">
|
||||
<h4>玩家充值记录</h4>
|
||||
<p class="text-g-600 text-sm mt-1">最新50条充值记录</p>
|
||||
</div>
|
||||
</div>
|
||||
<ArtTable
|
||||
class="w-full"
|
||||
:data="tableData"
|
||||
style="width: 100%"
|
||||
size="default"
|
||||
:border="false"
|
||||
:stripe="true"
|
||||
:header-cell-style="{ background: 'transparent' }"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn label="玩家" prop="player_name" min-width="120" />
|
||||
<ElTableColumn label="充值金额" prop="coin" min-width="120" align="right">
|
||||
<template #default="scope">
|
||||
{{ formatCoin(scope.row.coin) }}
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="充值时间" prop="create_time" min-width="170" />
|
||||
</template>
|
||||
</ArtTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchWalletRecordList, type WalletRecordItem } from '@/api/dashboard'
|
||||
|
||||
const tableData = ref<WalletRecordItem[]>([])
|
||||
|
||||
function formatCoin(val: number | undefined): string {
|
||||
if (val === undefined || val === null) return '0.00'
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWalletRecordList().then((data) => {
|
||||
tableData.value = Array.isArray(data) ? data : []
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@@ -1,7 +1,7 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 色子奖池配置 API接口
|
||||
* 摇色子配置 API接口
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/index',
|
||||
url: '/dice/config/DiceConfig/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/read?id=' + id
|
||||
url: '/dice/config/DiceConfig/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
@@ -34,7 +34,7 @@ export default {
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/save',
|
||||
url: '/dice/config/DiceConfig/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -46,7 +46,7 @@ export default {
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/update',
|
||||
url: '/dice/config/DiceConfig/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -58,7 +58,7 @@ export default {
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/destroy',
|
||||
url: '/dice/config/DiceConfig/destroy',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 色子奖池配置 API 接口
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取数据列表(DiceLotteryPoolConfig)
|
||||
* @param params 搜索参数
|
||||
* @returns 数据列表
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取 DiceLotteryPoolConfig 列表数据,含 id、name、type、t1_weight~t5_weight,用于一键测试权重档位类型下拉
|
||||
* type:0=付费抽奖券,1=免费抽奖券;付费默认选 type=0,免费默认选 type=1
|
||||
*/
|
||||
async getOptions(): Promise<
|
||||
Array<{
|
||||
id: number
|
||||
name: string
|
||||
type: number
|
||||
t1_weight: number
|
||||
t2_weight: number
|
||||
t3_weight: number
|
||||
t4_weight: number
|
||||
t5_weight: number
|
||||
}>
|
||||
> {
|
||||
const res = await request.get<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions'
|
||||
})
|
||||
const rows = Array.isArray(res) ? res : (Array.isArray((res as any)?.data) ? (res as any).data : [])
|
||||
if (!Array.isArray(rows)) return []
|
||||
return rows.map((r: any) => ({
|
||||
id: Number(r.id),
|
||||
name: String(r.name ?? r.id ?? ''),
|
||||
type: Number(r.type ?? 0),
|
||||
t1_weight: Number(r.t1_weight ?? 0),
|
||||
t2_weight: Number(r.t2_weight ?? 0),
|
||||
t3_weight: Number(r.t3_weight ?? 0),
|
||||
t4_weight: Number(r.t4_weight ?? 0),
|
||||
t5_weight: Number(r.t5_weight ?? 0)
|
||||
}))
|
||||
},
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param id 数据ID
|
||||
* @returns 数据详情
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param id 数据ID
|
||||
* @returns 执行结果
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取当前彩金池(Redis 实例化,无则按 type=0 创建),含玩家累计盈利 profit_amount 实时值
|
||||
*/
|
||||
getCurrentPool() {
|
||||
return request.get<{
|
||||
id: number
|
||||
name: string
|
||||
safety_line: number
|
||||
t1_weight: number
|
||||
t2_weight: number
|
||||
t3_weight: number
|
||||
t4_weight: number
|
||||
t5_weight: number
|
||||
profit_amount: number
|
||||
}>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新当前彩金池:仅 safety_line、t1_weight~t5_weight,不可改 profit_amount
|
||||
*/
|
||||
updateCurrentPool(params: {
|
||||
safety_line?: number
|
||||
t1_weight?: number
|
||||
t2_weight?: number
|
||||
t3_weight?: number
|
||||
t4_weight?: number
|
||||
t5_weight?: number
|
||||
}) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利(profit_amount 置为 0)
|
||||
*/
|
||||
resetProfitAmount() {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据) API接口
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取数据列表
|
||||
* @param params 搜索参数
|
||||
* @returns 数据列表
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param id 数据ID
|
||||
* @returns 数据详情
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param id 数据ID
|
||||
* @returns 执行结果
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 一键删除所有测试数据
|
||||
*/
|
||||
clearAll() {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/clearAll'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -71,5 +71,41 @@ export default {
|
||||
url: '/dice/player/DicePlayer/updateStatus',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取彩金池配置选项(DiceLotteryPoolConfig.id、name),供 lottery_config_id 下拉使用
|
||||
* @returns [ { id, name } ]
|
||||
*/
|
||||
async getLotteryConfigOptions(): Promise<Array<{ id: number; name: string }>> {
|
||||
const res = await request.get<any>({
|
||||
url: '/dice/player/DicePlayer/getLotteryConfigOptions'
|
||||
})
|
||||
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }>
|
||||
return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取后台管理员选项(SystemUser),供 admin_id 下拉使用
|
||||
* @returns [ { id, username, realname, label } ]
|
||||
*/
|
||||
async getSystemUserOptions(): Promise<
|
||||
Array<{ id: number; username: string; realname: string; label: string }>
|
||||
> {
|
||||
const res = await request.get<any>({
|
||||
url: '/dice/player/DicePlayer/getSystemUserOptions'
|
||||
})
|
||||
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
|
||||
id: number
|
||||
username: string
|
||||
realname: string
|
||||
label: string
|
||||
}>
|
||||
return rows.map((r) => ({
|
||||
id: Number(r.id),
|
||||
username: String(r.username ?? ''),
|
||||
realname: String(r.realname ?? ''),
|
||||
label: String(r.label ?? r.username ?? r.id ?? '')
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/index',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/read?id=' + id
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
@@ -34,7 +34,7 @@ export default {
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/save',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -46,7 +46,7 @@ export default {
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/update',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -58,7 +58,7 @@ export default {
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/destroy',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -68,7 +68,7 @@ export default {
|
||||
*/
|
||||
getPlayerOptions() {
|
||||
return request.get<{ id: number; username: string }[]>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions'
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions'
|
||||
})
|
||||
},
|
||||
|
||||
@@ -77,7 +77,7 @@ export default {
|
||||
*/
|
||||
getPlayerWalletBefore(playerId: number | string) {
|
||||
return request.get<{ wallet_before: number }>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore',
|
||||
params: { player_id: playerId }
|
||||
})
|
||||
},
|
||||
@@ -93,7 +93,7 @@ export default {
|
||||
remark?: string
|
||||
}) {
|
||||
return request.post<any>({
|
||||
url: '/dice/player_wallet_record/DicePlayerWalletRecord/adminOperate',
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/adminOperate',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
98
saiadmin-artd/src/views/plugin/dice/api/reward/index.ts
Normal file
98
saiadmin-artd/src/views/plugin/dice/api/reward/index.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 奖励对照(dice_reward)API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 分页列表,按 direction 区分顺时针(0)/逆时针(1)
|
||||
* @param params direction(必), tier(选), page, limit, orderField, orderType
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/core/dice/reward/DiceReward/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向)
|
||||
* @param direction 0=顺时针 1=逆时针
|
||||
*/
|
||||
weightRatioList(direction: 0 | 1) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/reward/DiceReward/weightRatioList',
|
||||
params: { direction }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重(dice_reward 双方向)
|
||||
*/
|
||||
weightRatioListWithDirection() {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/reward/DiceReward/weightRatioListWithDirection'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按 DiceReward 主键 id 批量更新 weight
|
||||
* @param items [{ id: DiceReward.id, weight: 1-10000 }, ...]
|
||||
*/
|
||||
batchUpdateWeights(items: Array<{ id: number; weight: number }>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward/DiceReward/batchUpdateWeights',
|
||||
data: { items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:批量更新当前方向的权重(单方向)
|
||||
*/
|
||||
batchUpdateWeightsByDirection(direction: 0 | 1, items: Array<{ id: number; weight: number }>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward/DiceReward/batchUpdateWeightsByDirection',
|
||||
data: { direction, items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 一键测试权重:创建测试记录并启动后台执行,按付费/免费、顺逆方向交替抽奖
|
||||
* 可选 lottery_config_id;不选则传 paid_tier_weights / free_tier_weights(T1-T5)
|
||||
*/
|
||||
startWeightTest(params: {
|
||||
lottery_config_id?: number
|
||||
paid_lottery_config_id?: number
|
||||
free_lottery_config_id?: number
|
||||
s_count?: number
|
||||
n_count?: number
|
||||
paid_s_count?: number
|
||||
paid_n_count?: number
|
||||
free_s_count?: number
|
||||
free_n_count?: number
|
||||
paid_tier_weights?: Record<string, number>
|
||||
free_tier_weights?: Record<string, number>
|
||||
}) {
|
||||
return request.post<{ record_id: number }>({
|
||||
url: '/core/dice/reward/DiceReward/startWeightTest',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询一键测试进度
|
||||
*/
|
||||
getTestProgress(recordId: number) {
|
||||
return request.get<{
|
||||
total_play_count: number
|
||||
over_play_count: number
|
||||
status: number
|
||||
remark: string | null
|
||||
result_counts: Record<number, number> | null
|
||||
tier_counts: Record<string, number> | null
|
||||
}>({
|
||||
url: '/core/dice/reward/DiceReward/getTestProgress',
|
||||
params: { record_id: recordId }
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/dice/reward_config/DiceRewardConfig/index',
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/dice/reward_config/DiceRewardConfig/read?id=' + id
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
@@ -34,7 +34,7 @@ export default {
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/dice/reward_config/DiceRewardConfig/save',
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -46,7 +46,7 @@ export default {
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/dice/reward_config/DiceRewardConfig/update',
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
@@ -58,8 +58,62 @@ export default {
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/dice/reward_config/DiceRewardConfig/destroy',
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量更新奖励索引配置(第一页:id、grid_number、ui_text、real_ev、tier、remark)
|
||||
*/
|
||||
batchUpdate(items: Array<{ id: number; grid_number?: number; ui_text?: string; real_ev?: number; tier?: string; remark?: string }>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdate',
|
||||
data: { items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* T1-T5、BIGWIN 权重配比:按档位分组获取配置列表
|
||||
*/
|
||||
weightRatioList() {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/weightRatioList'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* T1-T5、BIGWIN 权重配比:批量更新顺时针/逆时针权重(写入 dice_reward)
|
||||
*/
|
||||
/** 按 DiceReward 主键 id 批量更新 weight;items: [{ id, weight }, ...] */
|
||||
batchUpdateWeights(items: Array<{ id: number; weight: number }>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdateWeights',
|
||||
data: { items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 大奖权重:按 grid_number 批量保存 BIGWIN 权重(无需 reward id,不存在则自动创建)
|
||||
*/
|
||||
saveBigwinWeightsByGrid(items: Array<{ grid_number: number; weight: number }>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid',
|
||||
data: { items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建奖励对照:按当前奖励配置为顺时针(0)、逆时针(1)生成所有色子可能对应的 dice_reward 记录,权重默认 1,可在奖励对照页权重编辑中调整
|
||||
*/
|
||||
createRewardReference() {
|
||||
return request.post<{
|
||||
created_clockwise: number
|
||||
created_counterclockwise: number
|
||||
updated_clockwise: number
|
||||
updated_counterclockwise: number
|
||||
}>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录 API接口
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取数据列表
|
||||
* @param params 搜索参数
|
||||
* @returns 数据列表
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param id 数据ID
|
||||
* @returns 数据详情
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param id 数据ID
|
||||
* @returns 执行结果
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 导入:测试记录 → DiceReward、DiceRewardConfig(BIGWIN)、DiceLotteryPoolConfig(付费/免费 T1-T5)
|
||||
* @param record_id 测试记录 ID
|
||||
* @param paid_lottery_config_id 可选,导入付费档位概率到的奖池(type=0)
|
||||
* @param free_lottery_config_id 可选,导入免费档位概率到的奖池(type=1)
|
||||
* @param lottery_config_id 兼容旧版,不传 paid/free 时用作统一奖池
|
||||
*/
|
||||
importFromRecord(params: {
|
||||
record_id: number
|
||||
paid_lottery_config_id?: number | null
|
||||
free_lottery_config_id?: number | null
|
||||
lottery_config_id?: number | null
|
||||
}) {
|
||||
return request.post<any>({
|
||||
url: '/dice/reward_config_record/DiceRewardConfigRecord/importFromRecord',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
}
|
||||
141
saiadmin-artd/src/views/plugin/dice/config/index/index.vue
Normal file
141
saiadmin-artd/src/views/plugin/dice/config/index/index.vue
Normal file
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<!-- <ElButton v-permission="'dice:config:index:save'" @click="showDialog('add')" v-ripple>-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:add-fill" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 新增-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:config:index:destroy'"-->
|
||||
<!-- :disabled="selectedRows.length === 0"-->
|
||||
<!-- @click="deleteSelectedRows(api.delete, refreshData)"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:delete-bin-5-line" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 删除-->
|
||||
<!-- </ElButton>-->
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:config:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<!-- <SaButton-->
|
||||
<!-- v-permission="'dice:config:index:destroy'"-->
|
||||
<!-- type="error"-->
|
||||
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
|
||||
<!-- />-->
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/config/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
group: undefined,
|
||||
title: undefined,
|
||||
name: undefined
|
||||
})
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
columnsFactory: () => [
|
||||
// { type: 'selection' },
|
||||
{ prop: 'group', label: '分组', minWidth: 140, align: 'center' },
|
||||
{ prop: 'title', label: '标题', minWidth: 160, align: 'center' },
|
||||
{ prop: 'title_en', label: '标题(英文)', minWidth: 160, align: 'center' },
|
||||
{ prop: 'name', label: '配置名称', align: 'center' },
|
||||
{ prop: 'value', label: '值', minWidth: 240, align: 'center' },
|
||||
{ prop: 'value_en', label: '值(英文)', minWidth: 240, align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
// deleteRow,
|
||||
// deleteSelectedRows,
|
||||
handleSelectionChange
|
||||
// selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
@@ -0,0 +1,174 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? '新增摇色子配置' : '编辑摇色子配置'"
|
||||
width="600px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="分组" prop="group">
|
||||
<el-input
|
||||
v-model="formData.group"
|
||||
placeholder="请输入分组"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="标题" prop="title">
|
||||
<el-input v-model="formData.title" placeholder="请输入标题(中文)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="标题(英文)" prop="title_en">
|
||||
<el-input v-model="formData.title_en" placeholder="请输入标题(英文)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="配置名称" prop="name">
|
||||
<el-input
|
||||
v-model="formData.name"
|
||||
placeholder="请输入配置名称"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="值" prop="value">
|
||||
<el-input v-model="formData.value" type="textarea" :rows="5" placeholder="请输入值(中文)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="值(英文)" prop="value_en">
|
||||
<el-input v-model="formData.value_en" type="textarea" :rows="5" placeholder="请输入值(英文)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
data?: Record<string, any>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
dialogType: 'add',
|
||||
data: undefined
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
/**
|
||||
* 弹窗显示状态双向绑定
|
||||
*/
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
group: [{ required: true, message: '分组必需填写', trigger: 'blur' }],
|
||||
title: [{ required: true, message: '标题必需填写', trigger: 'blur' }],
|
||||
title_en: [{ max: 255, message: '英文标题长度需小于 255 字符', trigger: 'blur' }],
|
||||
name: [{ required: true, message: '配置名称必需填写', trigger: 'blur' }],
|
||||
value: [{ required: true, message: '值必需填写', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null,
|
||||
value: '',
|
||||
value_en: '',
|
||||
name: '',
|
||||
group: '',
|
||||
title: '',
|
||||
title_en: ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据
|
||||
*/
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/**
|
||||
* 监听弹窗打开,初始化表单数据
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
initPage()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
Object.assign(formData, initialFormData)
|
||||
// 如果有数据,则填充数据
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
if (props.data[key] != null && props.data[key] != undefined) {
|
||||
;(formData as any)[key] = props.data[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置表单
|
||||
*/
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(formData)
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.log('表单验证失败:', error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,77 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="100px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="分组" prop="group">
|
||||
<el-input v-model="formData.group" placeholder="请输入分组" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="标题" prop="title">
|
||||
<el-input v-model="formData.title" placeholder="请输入标题" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="配置名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入配置名称" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, any>): void
|
||||
(e: 'search', params: Record<string, any>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
// 展开/收起
|
||||
const isExpanded = ref<boolean>(false)
|
||||
|
||||
// 表单数据双向绑定
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
// 重置
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref.resetFields()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
// 搜索
|
||||
async function handleSearch() {
|
||||
emit('search', formData.value)
|
||||
}
|
||||
|
||||
// 展开/收起
|
||||
function handleExpand(expanded: boolean) {
|
||||
isExpanded.value = expanded
|
||||
}
|
||||
|
||||
// 栅格占据的列数
|
||||
const setSpan = (span: number) => {
|
||||
return {
|
||||
span: span,
|
||||
xs: 24, // 手机:满宽显示
|
||||
sm: span >= 12 ? span : 12, // 平板:大于等于12保持,否则用半宽
|
||||
md: span >= 8 ? span : 8, // 中等屏幕:大于等于8保持,否则用三分之一宽
|
||||
lg: span,
|
||||
xl: span
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -7,29 +7,13 @@
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:lottery_config:index:save'"
|
||||
@click="showDialog('add')"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:lottery_config:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
<ElButton
|
||||
v-permission="'dice:lottery_pool_config:index:index'"
|
||||
type="primary"
|
||||
@click="showCurrentPoolDialog"
|
||||
>
|
||||
查看当前彩金池
|
||||
</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
@@ -50,15 +34,15 @@
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:lottery_config:index:update'"
|
||||
v-permission="'dice:lottery_pool_config:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:lottery_config:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
<!-- <SaButton-->
|
||||
<!-- v-permission="'dice:lottery_pool_config:index:destroy'"-->
|
||||
<!-- type="error"-->
|
||||
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
|
||||
<!-- />-->
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
@@ -71,15 +55,18 @@
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
<!-- 当前彩金池弹窗 -->
|
||||
<CurrentPoolDialog v-model="currentPoolVisible" @success="refreshData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/lottery_config/index'
|
||||
import api from '../../api/lottery_pool_config/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
import CurrentPoolDialog from './modules/current-pool-dialog.vue'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
@@ -121,29 +108,61 @@
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'name', label: '名称' },
|
||||
{ prop: 'type', label: '奖池类型', width: 100, formatter: typeFormatter },
|
||||
{ prop: 'safety_line', label: '安全线' },
|
||||
{ prop: 't1_wight', label: 'T1池权重', width: 100, formatter: weightFormatter('t1_wight') },
|
||||
{ prop: 't2_wight', label: 'T2池权重', width: 100, formatter: weightFormatter('t2_wight') },
|
||||
{ prop: 't3_wight', label: 'T3池权重', width: 100, formatter: weightFormatter('t3_wight') },
|
||||
{ prop: 't4_wight', label: 'T4池权重', width: 100, formatter: weightFormatter('t4_wight') },
|
||||
{ prop: 't5_wight', label: 'T5池权重', width: 100, formatter: weightFormatter('t5_wight') },
|
||||
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||
{ prop: 'name', label: '名称', align: 'center' },
|
||||
{ prop: 'type', label: '奖池类型', width: 100, align: 'center', formatter: typeFormatter },
|
||||
{ prop: 'safety_line', label: '安全线', align: 'center' },
|
||||
{
|
||||
prop: 't1_weight',
|
||||
label: 'T1池权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t1_weight')
|
||||
},
|
||||
{
|
||||
prop: 't2_weight',
|
||||
label: 'T2池权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t2_weight')
|
||||
},
|
||||
{
|
||||
prop: 't3_weight',
|
||||
label: 'T3池权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t3_weight')
|
||||
},
|
||||
{
|
||||
prop: 't4_weight',
|
||||
label: 'T4池权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t4_weight')
|
||||
},
|
||||
{
|
||||
prop: 't5_weight',
|
||||
label: 'T5池权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t5_weight')
|
||||
},
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange } = useSaiAdmin()
|
||||
|
||||
const currentPoolVisible = ref(false)
|
||||
function showCurrentPoolDialog() {
|
||||
currentPoolVisible.value = true
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,313 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="当前彩金池"
|
||||
width="560px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<div v-if="loading && !pool" class="flex justify-center py-8">加载中...</div>
|
||||
<template v-else-if="pool">
|
||||
<div class="pool-info mb-4">
|
||||
<div class="flex items-center gap-2 mb-3">
|
||||
<span class="text-gray-500">池子名称:</span>
|
||||
<span>{{ pool.name }}</span>
|
||||
</div>
|
||||
<div class="profit-row mb-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-gray-500">玩家累计盈利(profit_amount):</span>
|
||||
<span class="font-mono text-lg" :class="profitAmountClass">{{
|
||||
displayProfitAmount
|
||||
}}</span>
|
||||
<span class="realtime-badge">实时</span>
|
||||
</div>
|
||||
<div class="profit-calc-hint">
|
||||
计算方式:每局按“当前中奖金额(含超级大奖 BIGWIN)减去抽奖券费用 100”累加,弹窗打开期间每 2 秒自动刷新
|
||||
</div>
|
||||
</div>
|
||||
<div class="tip-block">
|
||||
<div class="tip-title">抽奖档位规则</div>
|
||||
<div class="tip-content">
|
||||
当玩家在当前彩金池的累计盈利 <strong>低于安全线</strong> 时,按<strong>玩家</strong>的 T*_weight 权重抽取档位;
|
||||
当累计盈利 <strong>高于或等于安全线</strong> 时,按<strong>当前彩金池</strong>的 T*_weight 权重抽取档位(杀分)。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="安全线" prop="safety_line">
|
||||
<el-input-number
|
||||
v-model="formData.safety_line"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="T1池权重(%)" prop="t1_weight">
|
||||
<el-slider v-model="formData.t1_weight" :min="0" :max="100" :step="1" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T2池权重(%)" prop="t2_weight">
|
||||
<el-slider v-model="formData.t2_weight" :min="0" :max="100" :step="1" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T3池权重(%)" prop="t3_weight">
|
||||
<el-slider v-model="formData.t3_weight" :min="0" :max="100" :step="1" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T4池权重(%)" prop="t4_weight">
|
||||
<el-slider v-model="formData.t4_weight" :min="0" :max="100" :step="1" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T5池权重(%)" prop="t5_weight">
|
||||
<el-slider v-model="formData.t5_weight" :min="0" :max="100" :step="1" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<div class="text-gray-500 text-sm">
|
||||
五个池权重总和:<span :class="weightsSum !== 100 ? 'text-red-500' : ''">{{
|
||||
weightsSum
|
||||
}}</span
|
||||
>% / 100%(须为100%)
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">关闭</el-button>
|
||||
<el-button :loading="resetting" :disabled="!pool" @click="handleResetProfit">
|
||||
重置玩家累计盈利
|
||||
</el-button>
|
||||
<el-button type="primary" :loading="saving" :disabled="!pool" @click="handleSubmit">
|
||||
保存权重与安全线
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/lottery_pool_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface PoolData {
|
||||
id: number
|
||||
name: string
|
||||
safety_line: number
|
||||
t1_weight: number
|
||||
t2_weight: number
|
||||
t3_weight: number
|
||||
t4_weight: number
|
||||
t5_weight: number
|
||||
profit_amount: number
|
||||
}
|
||||
|
||||
const props = defineProps<{ modelValue: boolean }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'success'): void }>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const resetting = ref(false)
|
||||
const pool = ref<PoolData | null>(null)
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const formData = reactive({
|
||||
safety_line: 0,
|
||||
t1_weight: 0,
|
||||
t2_weight: 0,
|
||||
t3_weight: 0,
|
||||
t4_weight: 0,
|
||||
t5_weight: 0
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
safety_line: [{ required: true, message: '请输入安全线', trigger: 'blur' }],
|
||||
t1_weight: [{ required: true, message: '请输入T1权重', trigger: 'blur' }],
|
||||
t2_weight: [{ required: true, message: '请输入T2权重', trigger: 'blur' }],
|
||||
t3_weight: [{ required: true, message: '请输入T3权重', trigger: 'blur' }],
|
||||
t4_weight: [{ required: true, message: '请输入T4权重', trigger: 'blur' }],
|
||||
t5_weight: [{ required: true, message: '请输入T5权重', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const weightsSum = computed(
|
||||
() =>
|
||||
formData.t1_weight +
|
||||
formData.t2_weight +
|
||||
formData.t3_weight +
|
||||
formData.t4_weight +
|
||||
formData.t5_weight
|
||||
)
|
||||
|
||||
const displayProfitAmount = computed(() => {
|
||||
const v = pool.value?.profit_amount
|
||||
if (v == null || Number.isNaN(v)) return '-'
|
||||
return Number(v).toFixed(2)
|
||||
})
|
||||
|
||||
const profitAmountClass = computed(() => {
|
||||
const v = pool.value?.profit_amount
|
||||
if (v == null) return ''
|
||||
if (v > 0) return 'text-green-600'
|
||||
if (v < 0) return 'text-red-600'
|
||||
return ''
|
||||
})
|
||||
|
||||
let pollTimer: ReturnType<typeof setInterval> | null = null
|
||||
const POLL_INTERVAL = 2000
|
||||
|
||||
async function loadPool() {
|
||||
if (!visible.value) return
|
||||
try {
|
||||
loading.value = true
|
||||
const res = await api.getCurrentPool()
|
||||
const data = res as unknown as PoolData
|
||||
if (data && typeof data === 'object') {
|
||||
pool.value = data
|
||||
formData.safety_line = data.safety_line ?? 0
|
||||
formData.t1_weight = data.t1_weight ?? 0
|
||||
formData.t2_weight = data.t2_weight ?? 0
|
||||
formData.t3_weight = data.t3_weight ?? 0
|
||||
formData.t4_weight = data.t4_weight ?? 0
|
||||
formData.t5_weight = data.t5_weight ?? 0
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '获取彩金池失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
stopPolling()
|
||||
pollTimer = setInterval(() => {
|
||||
if (!visible.value) {
|
||||
stopPolling()
|
||||
return
|
||||
}
|
||||
api.getCurrentPool().then((res) => {
|
||||
const data = res as unknown as PoolData
|
||||
if (pool.value && data && typeof data === 'object' && data.profit_amount != null) {
|
||||
pool.value.profit_amount = data.profit_amount
|
||||
}
|
||||
})
|
||||
}, POLL_INTERVAL)
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer)
|
||||
pollTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value || !pool.value) return
|
||||
if (weightsSum.value !== 100) {
|
||||
ElMessage.warning('T1~T5 权重合计须为 100%')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
saving.value = true
|
||||
await api.updateCurrentPool({
|
||||
safety_line: formData.safety_line,
|
||||
t1_weight: formData.t1_weight,
|
||||
t2_weight: formData.t2_weight,
|
||||
t3_weight: formData.t3_weight,
|
||||
t4_weight: formData.t4_weight,
|
||||
t5_weight: formData.t5_weight
|
||||
})
|
||||
ElMessage.success('保存成功')
|
||||
await loadPool()
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
if (e?.message) ElMessage.error(e.message)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResetProfit() {
|
||||
if (!pool.value) return
|
||||
try {
|
||||
resetting.value = true
|
||||
await api.resetProfitAmount()
|
||||
ElMessage.success('玩家累计盈利已重置为 0')
|
||||
await loadPool()
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '重置失败')
|
||||
} finally {
|
||||
resetting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
stopPolling()
|
||||
visible.value = false
|
||||
pool.value = null
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) {
|
||||
loadPool().then(() => startPolling())
|
||||
} else {
|
||||
stopPolling()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
onUnmounted(() => stopPolling())
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.pool-info {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.profit-row {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.profit-calc-hint {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.realtime-badge {
|
||||
font-size: 11px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
background: var(--el-color-success-light-9);
|
||||
color: var(--el-color-success);
|
||||
}
|
||||
|
||||
.tip-block {
|
||||
margin-top: 12px;
|
||||
padding: 10px 12px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid var(--el-color-primary);
|
||||
}
|
||||
|
||||
.tip-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.tip-content {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-regular);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.tip-content strong {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
</style>
|
||||
@@ -9,7 +9,11 @@
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入名称" />
|
||||
<el-input
|
||||
v-model="formData.name"
|
||||
placeholder="请输入名称"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
@@ -27,6 +31,7 @@
|
||||
placeholder="请选择奖池类型"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
>
|
||||
<el-option label="正常" :value="0" />
|
||||
<el-option label="强制杀猪" :value="1" />
|
||||
@@ -41,20 +46,20 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="T1池权重(%)" prop="t1_wight">
|
||||
<el-slider v-model="formData.t1_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T1池权重(%)" prop="t1_weight">
|
||||
<el-slider v-model="formData.t1_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T2池权重(%)" prop="t2_wight">
|
||||
<el-slider v-model="formData.t2_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T2池权重(%)" prop="t2_weight">
|
||||
<el-slider v-model="formData.t2_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T3池权重(%)" prop="t3_wight">
|
||||
<el-slider v-model="formData.t3_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T3池权重(%)" prop="t3_weight">
|
||||
<el-slider v-model="formData.t3_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T4池权重(%)" prop="t4_wight">
|
||||
<el-slider v-model="formData.t4_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T4池权重(%)" prop="t4_weight">
|
||||
<el-slider v-model="formData.t4_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T5池权重(%)" prop="t5_wight">
|
||||
<el-slider v-model="formData.t5_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T5池权重(%)" prop="t5_weight">
|
||||
<el-slider v-model="formData.t5_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<div class="text-gray-500 text-sm">
|
||||
@@ -73,7 +78,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/lottery_config/index'
|
||||
import api from '../../../api/lottery_pool_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
@@ -107,7 +112,7 @@
|
||||
})
|
||||
|
||||
/** 五个权重字段名,用于总和校验 */
|
||||
const WEIGHT_KEYS = ['t1_wight', 't2_wight', 't3_wight', 't4_wight', 't5_wight'] as const
|
||||
const WEIGHT_KEYS = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'] as const
|
||||
|
||||
/** 五个池权重总和(用于展示与校验) */
|
||||
const weightsSum = computed(() => {
|
||||
@@ -120,11 +125,11 @@
|
||||
const rules = reactive<FormRules>({
|
||||
name: [{ required: true, message: '名称必需填写', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择奖池类型', trigger: 'change' }],
|
||||
t1_wight: [{ required: true, message: 'T1池权重必需填写', trigger: 'blur' }],
|
||||
t2_wight: [{ required: true, message: 'T2池权重必需填写', trigger: 'blur' }],
|
||||
t3_wight: [{ required: true, message: 'T3池权重必需填写', trigger: 'blur' }],
|
||||
t4_wight: [{ required: true, message: 'T4池权重必需填写', trigger: 'blur' }],
|
||||
t5_wight: [{ required: true, message: 'T5池权重必需填写', trigger: 'blur' }]
|
||||
t1_weight: [{ required: true, message: 'T1池权重必需填写', trigger: 'blur' }],
|
||||
t2_weight: [{ required: true, message: 'T2池权重必需填写', trigger: 'blur' }],
|
||||
t3_weight: [{ required: true, message: 'T3池权重必需填写', trigger: 'blur' }],
|
||||
t4_weight: [{ required: true, message: 'T4池权重必需填写', trigger: 'blur' }],
|
||||
t5_weight: [{ required: true, message: 'T5池权重必需填写', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -136,11 +141,11 @@
|
||||
remark: '',
|
||||
type: null as number | null,
|
||||
safety_line: 0 as number,
|
||||
t1_wight: 0 as number,
|
||||
t2_wight: 0 as number,
|
||||
t3_wight: 0 as number,
|
||||
t4_wight: 0 as number,
|
||||
t5_wight: 0 as number
|
||||
t1_weight: 0 as number,
|
||||
t2_weight: 0 as number,
|
||||
t3_weight: 0 as number,
|
||||
t4_weight: 0 as number,
|
||||
t5_weight: 0 as number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,11 +187,11 @@
|
||||
'id',
|
||||
'type',
|
||||
'safety_line',
|
||||
't1_wight',
|
||||
't2_wight',
|
||||
't3_wight',
|
||||
't4_wight',
|
||||
't5_wight'
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
't4_weight',
|
||||
't5_weight'
|
||||
]
|
||||
for (const key of Object.keys(formData)) {
|
||||
if (!(key in props.data)) continue
|
||||
@@ -7,29 +7,29 @@
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:play_record:index:save'"
|
||||
@click="showDialog('add')"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:play_record:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
<!-- <ElSpace wrap>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:play_record:index:save'"-->
|
||||
<!-- @click="showDialog('add')"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:add-fill" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 新增-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:play_record:index:destroy'"-->
|
||||
<!-- :disabled="selectedRows.length === 0"-->
|
||||
<!-- @click="deleteSelectedRows(api.delete, refreshData)"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:delete-bin-5-line" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 删除-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- </ElSpace>-->
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
{{ row.lottery_type === 0 ? '付费' : row.lottery_type === 1 ? '赠送' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 中奖 tag -->
|
||||
<!-- 是否中大奖 tag -->
|
||||
<template #is_win="{ row }">
|
||||
<ElTag size="small" :type="row.is_win === 1 ? 'success' : 'info'">
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中奖' : '-' }}
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中大奖' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 方向 tag -->
|
||||
@@ -82,11 +82,11 @@
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:play_record:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
<!-- <SaButton-->
|
||||
<!-- v-permission="'dice:play_record:index:destroy'"-->
|
||||
<!-- type="error"-->
|
||||
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
|
||||
<!-- />-->
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
@@ -117,6 +117,8 @@
|
||||
is_win: undefined,
|
||||
win_coin_min: undefined,
|
||||
win_coin_max: undefined,
|
||||
roll_number_min: undefined,
|
||||
roll_number_max: undefined,
|
||||
reward_ui_text: undefined,
|
||||
reward_tier: undefined,
|
||||
direction: undefined
|
||||
@@ -131,7 +133,7 @@
|
||||
const usernameFormatter = (row: Record<string, any>) =>
|
||||
row?.dicePlayer?.username ?? row?.player_id ?? '-'
|
||||
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
|
||||
row?.diceLotteryConfig?.name ?? row?.lottery_config_id ?? '-'
|
||||
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
|
||||
const rewardTierFormatter = (row: Record<string, any>) =>
|
||||
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'
|
||||
|
||||
@@ -168,7 +170,7 @@
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
// { type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{
|
||||
prop: 'player_id',
|
||||
@@ -182,12 +184,15 @@
|
||||
useSlot: true
|
||||
},
|
||||
{ prop: 'lottery_type', label: '抽奖类型', width: 100, useSlot: true },
|
||||
{ prop: 'is_win', label: '中奖', width: 80, useSlot: true },
|
||||
{ prop: 'win_coin', label: '赢取平台币' },
|
||||
{ prop: 'is_win', label: '是否中大奖', width: 100, useSlot: true },
|
||||
{ prop: 'win_coin', label: '赢取平台币', width: 110 },
|
||||
{ prop: 'super_win_coin', label: '中大奖平台币', width: 120 },
|
||||
{ prop: 'reward_win_coin', label: '摇色子中奖平台币', width: 140 },
|
||||
{ prop: 'direction', label: '方向', width: 90, useSlot: true },
|
||||
{ prop: 'start_index', label: '起始索引', width: 90 },
|
||||
{ prop: 'target_index', label: '终点索引', width: 90 },
|
||||
{ prop: 'roll_array', label: '摇取点数', width: 140, useSlot: true },
|
||||
{ prop: 'roll_number', label: '摇取点数和', width: 110, sortable: true },
|
||||
{
|
||||
prop: 'reward_config_id',
|
||||
label: '奖励配置',
|
||||
@@ -206,9 +211,9 @@
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
// deleteRow,
|
||||
// deleteSelectedRows,
|
||||
handleSelectionChange
|
||||
// selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="中奖" prop="is_win">
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select
|
||||
v-model="formData.is_win"
|
||||
placeholder="请选择"
|
||||
@@ -63,18 +63,38 @@
|
||||
:disabled="dialogType === 'edit'"
|
||||
>
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中奖" :value="1" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="赢取平台币" prop="win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.win_coin"
|
||||
placeholder="请输入赢取平台币"
|
||||
placeholder="= 中大奖 + 摇色子中奖"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="中大奖平台币" prop="super_win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.super_win_coin"
|
||||
placeholder="豹子时发放"
|
||||
:precision="2"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="摇色子中奖平台币" prop="reward_win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.reward_win_coin"
|
||||
placeholder="摇色子中奖"
|
||||
:precision="2"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select
|
||||
v-model="formData.direction"
|
||||
@@ -122,6 +142,17 @@
|
||||
</div>
|
||||
<div class="roll-array-hint">固定 5 个数,每个 1~6</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="摇取点数和" prop="roll_number">
|
||||
<el-input-number
|
||||
v-model="formData.roll_number"
|
||||
placeholder="5 个色子点数之和(5~30)"
|
||||
:min="5"
|
||||
:max="30"
|
||||
:precision="0"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="奖励配置" prop="reward_config_id">
|
||||
<el-select
|
||||
v-model="formData.reward_config_id"
|
||||
@@ -186,7 +217,7 @@
|
||||
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
|
||||
lottery_config_id: [{ required: true, message: '请选择彩金池配置', trigger: 'change' }],
|
||||
lottery_type: [{ required: true, message: '请选择抽奖类型', trigger: 'change' }],
|
||||
is_win: [{ required: true, message: '请选择中奖', trigger: 'change' }],
|
||||
is_win: [{ required: true, message: '请选择是否中大奖', trigger: 'change' }],
|
||||
win_coin: [{ required: true, message: '赢取平台币必填', trigger: 'blur' }],
|
||||
rollArrayItems: [
|
||||
{
|
||||
@@ -219,10 +250,13 @@
|
||||
lottery_type: null as number | null,
|
||||
is_win: null as number | null,
|
||||
win_coin: null as number | null,
|
||||
super_win_coin: null as number | null,
|
||||
reward_win_coin: null as number | null,
|
||||
direction: null as number | null,
|
||||
start_index: null as number | null,
|
||||
target_index: null as number | null,
|
||||
roll_array: null as string | number[] | null,
|
||||
roll_number: null as number | null,
|
||||
reward_config_id: null as number | null
|
||||
}
|
||||
|
||||
@@ -278,10 +312,13 @@
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'super_win_coin',
|
||||
'reward_win_coin',
|
||||
'direction',
|
||||
'start_index',
|
||||
'target_index',
|
||||
'roll_array',
|
||||
'roll_number',
|
||||
'reward_config_id'
|
||||
]
|
||||
keys.forEach((key) => {
|
||||
@@ -295,6 +332,17 @@
|
||||
}
|
||||
}
|
||||
})
|
||||
// 若后端未返回 roll_number,根据摇取点数计算
|
||||
if (formData.roll_number == null && formData.rollArrayItems.length === 5) {
|
||||
formData.roll_number = formData.rollArrayItems.reduce((s, n) => (s ?? 0) + (n ?? 0), 0) || null
|
||||
}
|
||||
// 点数和有值但五个点数为空或无效时,根据 roll_number 补全显示(兼容历史错误数据)
|
||||
const sum = formData.roll_number != null ? Number(formData.roll_number) : 0
|
||||
const hasNull = formData.rollArrayItems.some((n) => n == null)
|
||||
const itemsSum = formData.rollArrayItems.reduce((s, n) => (s ?? 0) + (n ?? 0), 0) ?? 0
|
||||
if (sum >= 5 && sum <= 30 && (hasNull || itemsSum !== sum)) {
|
||||
formData.rollArrayItems = defaultRollArrayItems(sum)
|
||||
}
|
||||
}
|
||||
|
||||
/** 将接口的 roll_array 转为固定 5 项数组,不足补 null */
|
||||
@@ -319,6 +367,16 @@
|
||||
return items.slice(0, 5)
|
||||
}
|
||||
|
||||
/** 点数和有值但五个点数缺失时,根据点数和生成默认 5 个数(与后端 defaultRollArrayForSum 一致) */
|
||||
function defaultRollArrayItems(sum: number): (number | null)[] {
|
||||
const s = Math.max(5, Math.min(30, Math.floor(Number(sum))))
|
||||
const base = Math.floor(s / 5)
|
||||
const rem = s - 5 * base
|
||||
const arr: number[] = Array(5).fill(base)
|
||||
for (let i = 0; i < rem; i++) arr[i]++
|
||||
return arr.map((v) => Math.max(1, Math.min(6, v)))
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
@@ -331,10 +389,12 @@
|
||||
const payload = { ...formData } as Record<string, unknown>
|
||||
// 将 5 个输入值拼成 [1,2,3,4,5] 格式,确保每项为 1~6 的整数
|
||||
const items = formData.rollArrayItems
|
||||
payload.roll_array = items.map((n) => {
|
||||
const rollArray = items.map((n) => {
|
||||
const v = n != null ? Number(n) : 1
|
||||
return Math.min(6, Math.max(1, Number.isNaN(v) ? 1 : Math.floor(v)))
|
||||
})
|
||||
payload.roll_array = rollArray
|
||||
payload.roll_number = formData.roll_number ?? rollArray.reduce((s, n) => s + n, 0)
|
||||
delete payload.rollArrayItems
|
||||
if (props.dialogType === 'add') {
|
||||
delete payload.id
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="中奖" prop="is_win">
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select v-model="formData.is_win" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中奖" :value="1" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -63,6 +63,31 @@
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="摇取点数和" prop="roll_number_min">
|
||||
<div class="range-wrap">
|
||||
<el-input-number
|
||||
v-model="formData.roll_number_min"
|
||||
placeholder="最小"
|
||||
:min="5"
|
||||
:max="30"
|
||||
:precision="0"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
<span class="range-sep">至</span>
|
||||
<el-input-number
|
||||
v-model="formData.roll_number_max"
|
||||
placeholder="最大"
|
||||
:min="5"
|
||||
:max="30"
|
||||
:precision="0"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="奖励配置" prop="reward_ui_text">
|
||||
<el-input v-model="formData.reward_ui_text" placeholder="前端显示文本模糊" clearable />
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<!-- 表格头部:汇总与操作按钮同一行,避免占用表格高度导致无法翻页 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<span v-if="totalWinCoin !== null" class="table-summary-inline">
|
||||
平台总盈利:<strong>{{ totalWinCoin }}</strong>
|
||||
</span>
|
||||
<ElSpace wrap class="table-toolbar-buttons">
|
||||
<ElButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
type="danger"
|
||||
plain
|
||||
@click="handleClearAll"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-2-line" />
|
||||
</template>
|
||||
一键删除所有数据
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 彩金池配置:显示 DiceLotteryPoolConfig.name -->
|
||||
<template #lottery_config_id="{ row }">
|
||||
<ElTag size="small">{{ lotteryConfigNameFormatter(row) }}</ElTag>
|
||||
</template>
|
||||
<!-- 抽奖类型 -->
|
||||
<template #lottery_type="{ row }">
|
||||
<ElTag size="small" :type="row.lottery_type === 0 ? 'warning' : 'success'">
|
||||
{{ row.lottery_type === 0 ? '付费' : row.lottery_type === 1 ? '赠送' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 是否中大奖 -->
|
||||
<template #is_win="{ row }">
|
||||
<ElTag size="small" :type="row.is_win === 1 ? 'success' : 'info'">
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中大奖' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 方向 -->
|
||||
<template #direction="{ row }">
|
||||
<ElTag size="small" :type="row.direction === 0 ? 'primary' : 'warning'">
|
||||
{{ row.direction === 0 ? '顺时针' : row.direction === 1 ? '逆时针' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 摇取点数 -->
|
||||
<template #roll_array="{ row }">
|
||||
<ElTag size="small">
|
||||
{{ formatRollArray(row.roll_array) }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 奖励档位:显示 DiceRewardConfig.tier -->
|
||||
<template #reward_config_id="{ row }">
|
||||
<ElTag size="small">{{ rewardTierFormatter(row) }}</ElTag>
|
||||
</template>
|
||||
<!-- 状态 -->
|
||||
<template #status="{ row }">
|
||||
<ElTag size="small" :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '成功' : '失败' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:play_record_test:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/play_record_test/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单(与 play_record 对齐:方向、赢取平台币范围、是否中大奖、中奖档位、点数和)
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
lottery_type: undefined,
|
||||
direction: undefined,
|
||||
is_win: undefined,
|
||||
win_coin_min: undefined,
|
||||
win_coin_max: undefined,
|
||||
reward_tier: undefined,
|
||||
roll_number: undefined
|
||||
})
|
||||
|
||||
// 当前筛选下平台总盈利(付费抽奖次数×100 - 玩家总收益)
|
||||
const totalWinCoin = ref<number | null>(null)
|
||||
|
||||
const listApi = async (params: Record<string, any>) => {
|
||||
const res = await api.list(params)
|
||||
totalWinCoin.value = (res as any)?.total_win_coin ?? null
|
||||
return res
|
||||
}
|
||||
|
||||
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
|
||||
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
|
||||
const rewardTierFormatter = (row: Record<string, any>) =>
|
||||
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'
|
||||
|
||||
/** 摇取点数格式化为 1,3,4,5,6 */
|
||||
function formatRollArray(val: unknown): string {
|
||||
if (val == null || val === '') return '-'
|
||||
if (Array.isArray(val)) return val.join(',')
|
||||
if (typeof val === 'string') {
|
||||
try {
|
||||
const arr = JSON.parse(val)
|
||||
return Array.isArray(arr) ? arr.join(',') : val
|
||||
} catch {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return String(val)
|
||||
}
|
||||
|
||||
const handleClearAll = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定清空所有玩家抽奖测试数据?', '提示', {
|
||||
type: 'warning'
|
||||
})
|
||||
await api.clearAll()
|
||||
ElMessage.success('已清空所有测试数据')
|
||||
getData()
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel') {
|
||||
ElMessage.error(e?.message || '清空失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: listApi,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{ prop: 'lottery_config_id', label: '彩金池配置', width: 120, useSlot: true },
|
||||
{ prop: 'lottery_type', label: '抽奖类型', width: 100, useSlot: true },
|
||||
{ prop: 'is_win', label: '是否中大奖', width: 100, useSlot: true },
|
||||
{ prop: 'win_coin', label: '赢取平台币', width: 110 },
|
||||
{ prop: 'super_win_coin', label: '中大奖平台币', width: 120 },
|
||||
{ prop: 'reward_win_coin', label: '摇色子中奖平台币', width: 140 },
|
||||
{ prop: 'direction', label: '方向', width: 90, useSlot: true },
|
||||
{ prop: 'start_index', label: '起始索引', width: 90 },
|
||||
{ prop: 'target_index', label: '终点索引', width: 90 },
|
||||
{ prop: 'roll_array', label: '摇取点数', width: 140, useSlot: true },
|
||||
{ prop: 'roll_number', label: '摇取点数和', width: 110, sortable: true },
|
||||
{ prop: 'reward_config_id', label: '奖励档位', width: 100, useSlot: true },
|
||||
{ prop: 'status', label: '状态', width: 80, useSlot: true },
|
||||
{ prop: 'create_time', label: '创建时间', width: 170 },
|
||||
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.table-summary-inline {
|
||||
margin-right: 12px;
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-regular);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-summary-inline strong {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.table-toolbar-buttons {
|
||||
display: inline-flex;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,270 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? '新增玩家抽奖记录(测试数据)' : '编辑玩家抽奖记录(测试数据)'"
|
||||
width="600px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="彩金池配置id" prop="lottery_config_id">
|
||||
<el-input v-model="formData.lottery_config_id" placeholder="请输入彩金池配置id" />
|
||||
</el-form-item>
|
||||
<el-form-item label="抽奖类型" prop="lottery_type">
|
||||
<el-select
|
||||
v-model="formData.lottery_type"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option label="付费" :value="0" />
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select v-model="formData.direction" placeholder="请选择" clearable style="width: 100%">
|
||||
<el-option label="顺时针" :value="0" />
|
||||
<el-option label="逆时针" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select v-model="formData.is_win" placeholder="请选择" clearable style="width: 100%">
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="赢取平台币" prop="win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.win_coin"
|
||||
placeholder="赢取平台币"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="中奖档位" prop="reward_tier">
|
||||
<el-select
|
||||
v-model="formData.reward_tier"
|
||||
placeholder="请选择档位(选后自动带出奖励配置ID)"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
@change="onRewardTierChange"
|
||||
>
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="奖励配置id" prop="reward_config_id">
|
||||
<el-input
|
||||
v-model="formData.reward_config_id"
|
||||
placeholder="可选中奖档位自动带出或手动输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="起始索引" prop="start_index">
|
||||
<el-input v-model="formData.start_index" placeholder="请输入起始索引" />
|
||||
</el-form-item>
|
||||
<el-form-item label="结束索引" prop="target_index">
|
||||
<el-input v-model="formData.target_index" placeholder="请输入结束索引" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇取点数和" prop="roll_number">
|
||||
<el-input v-model="formData.roll_number" placeholder="请输入摇取点数和" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇取点数:[1,2,3,4,5,6]" prop="roll_array">
|
||||
<el-input v-model="formData.roll_array" placeholder="请输入摇取点数:[1,2,3,4,5,6]" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态:0=失败,1=成功" prop="status">
|
||||
<sa-radio v-model="formData.status" dict="data_status" />
|
||||
</el-form-item>
|
||||
<el-form-item label="中大奖平台币" prop="super_win_coin">
|
||||
<el-input v-model="formData.super_win_coin" placeholder="请输入中大奖平台币" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇色子中奖平台币" prop="reward_win_coin">
|
||||
<el-input v-model="formData.reward_win_coin" placeholder="请输入摇色子中奖平台币" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属管理员" prop="admin_id">
|
||||
<el-input v-model="formData.admin_id" placeholder="请输入所属管理员" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/play_record_test/index'
|
||||
import rewardConfigApi from '../../../api/reward_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
data?: Record<string, any>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
dialogType: 'add',
|
||||
data: undefined
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
/**
|
||||
* 弹窗显示状态双向绑定
|
||||
*/
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
lottery_config_id: [{ required: true, message: '彩金池配置id必需填写', trigger: 'blur' }],
|
||||
lottery_type: [{ required: true, message: '抽奖类型:0=付费,1=赠送必需填写', trigger: 'blur' }],
|
||||
is_win: [{ required: true, message: '中大奖:0=无,1=中奖必需填写', trigger: 'blur' }],
|
||||
direction: [{ required: true, message: '方向:0=顺时针,1=逆时针必需填写', trigger: 'blur' }],
|
||||
reward_config_id: [{ required: true, message: '奖励配置id必需填写', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '状态:0=失败,1=成功必需填写', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null,
|
||||
lottery_config_id: null,
|
||||
lottery_type: null,
|
||||
is_win: null,
|
||||
win_coin: 0,
|
||||
direction: null,
|
||||
reward_tier: undefined as string | undefined,
|
||||
reward_config_id: null,
|
||||
start_index: null,
|
||||
target_index: null,
|
||||
roll_number: null,
|
||||
roll_array: '',
|
||||
status: 1,
|
||||
super_win_coin: '0.00',
|
||||
reward_win_coin: '0.00',
|
||||
admin_id: null
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据
|
||||
*/
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/**
|
||||
* 监听弹窗打开,初始化表单数据
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
initPage()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
Object.assign(formData, initialFormData)
|
||||
// 如果有数据,则填充数据
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
if (key === 'reward_tier') continue
|
||||
if (props.data[key] != null && props.data[key] !== undefined) {
|
||||
;(formData as Record<string, unknown>)[key] = props.data[key]
|
||||
}
|
||||
}
|
||||
if (typeof formData.win_coin === 'string') {
|
||||
formData.win_coin = parseFloat(formData.win_coin) || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 中奖档位变更:按档位拉取奖励配置并取第一条的 id 填入 reward_config_id
|
||||
*/
|
||||
async function onRewardTierChange(tier: string) {
|
||||
if (!tier) {
|
||||
formData.reward_config_id = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await rewardConfigApi.list({
|
||||
saiType: 'all',
|
||||
tier: tier
|
||||
})
|
||||
const list = (res as any)?.data ?? (Array.isArray(res) ? res : [])
|
||||
const first = Array.isArray(list) ? list[0] : (list?.data?.[0] ?? list?.[0])
|
||||
if (first && first.id != null) {
|
||||
formData.reward_config_id = first.id
|
||||
} else {
|
||||
formData.reward_config_id = null
|
||||
}
|
||||
} catch {
|
||||
formData.reward_config_id = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置表单
|
||||
*/
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
const payload = { ...formData }
|
||||
delete (payload as Record<string, unknown>).reward_tier
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(payload)
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.log('表单验证失败:', error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,146 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="120px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="抽奖类型" prop="lottery_type">
|
||||
<el-select v-model="formData.lottery_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="付费" :value="0" />
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select v-model="formData.direction" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="顺时针" :value="0" />
|
||||
<el-option label="逆时针" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select v-model="formData.is_win" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="赢取平台币" prop="win_coin_min">
|
||||
<div class="range-wrap">
|
||||
<el-input-number
|
||||
v-model="formData.win_coin_min"
|
||||
placeholder="最小"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
<span class="range-sep">至</span>
|
||||
<el-input-number
|
||||
v-model="formData.win_coin_max"
|
||||
placeholder="最大"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="中奖档位" prop="reward_tier">
|
||||
<el-select v-model="formData.reward_tier" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="点数和" prop="roll_number">
|
||||
<el-select
|
||||
v-model="formData.roll_number"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="n in 26"
|
||||
:key="n + 4"
|
||||
:label="String(n + 4)"
|
||||
:value="n + 4"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, any>): void
|
||||
(e: 'search', params: Record<string, any>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
const isExpanded = ref<boolean>(false)
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref.resetFields()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
async function handleSearch() {
|
||||
emit('search', formData.value)
|
||||
}
|
||||
|
||||
function handleExpand(expanded: boolean) {
|
||||
isExpanded.value = expanded
|
||||
}
|
||||
|
||||
const setSpan = (span: number) => ({
|
||||
span,
|
||||
xs: 24,
|
||||
sm: span >= 12 ? span : 12,
|
||||
md: span >= 8 ? span : 8,
|
||||
lg: span,
|
||||
xl: span
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.range-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.range-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.range-sep {
|
||||
color: var(--el-text-color-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<!-- 搜索条件 -->
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<!-- 表格头部 -->
|
||||
<!-- 表格操作 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
@@ -42,7 +42,7 @@
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 状态:开关直接修改 -->
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }">
|
||||
<ElSwitch
|
||||
v-permission="'dice:player:index:update'"
|
||||
@@ -51,7 +51,7 @@
|
||||
@change="(v: string | number | boolean) => handleStatusChange(row, v ? 1 : 0)"
|
||||
/>
|
||||
</template>
|
||||
<!-- 平台币:tag 可点击打开钱包操作弹窗 -->
|
||||
<!-- 平台币,点击可操作 -->
|
||||
<template #coin="{ row }">
|
||||
<ElTag
|
||||
type="info"
|
||||
@@ -62,7 +62,7 @@
|
||||
{{ row.coin ?? 0 }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 操作列 -->
|
||||
<!-- 操作 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
@@ -88,7 +88,7 @@
|
||||
@success="refreshData"
|
||||
/>
|
||||
|
||||
<!-- 钱包操作弹窗(加点/扣点) -->
|
||||
<!-- 钱包操作弹窗 -->
|
||||
<WalletOperateDialog
|
||||
v-model="walletDialogVisible"
|
||||
:player="walletOperatePlayer"
|
||||
@@ -112,34 +112,26 @@
|
||||
phone: undefined,
|
||||
status: undefined,
|
||||
coin: undefined,
|
||||
is_up: undefined
|
||||
lottery_config_id: undefined
|
||||
})
|
||||
|
||||
// 搜索处理
|
||||
// 搜索
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 权重列带 % 的 formatter(ColumnOption.formatter 仅接收 row)
|
||||
// 权重列显示为百分比
|
||||
const weightFormatter = (prop: string) => (row: any) => {
|
||||
const cellValue = row[prop]
|
||||
return cellValue != null && cellValue !== '' ? `${cellValue}%` : '-'
|
||||
}
|
||||
|
||||
// 倍率列展示:0=正常 1=强制杀猪 2=T1高倍率
|
||||
const isUpFormatter = (row: any) => {
|
||||
const cellValue = row.is_up
|
||||
return cellValue === 0
|
||||
? '正常'
|
||||
: cellValue === 1
|
||||
? '强制杀猪'
|
||||
: cellValue === 2
|
||||
? 'T1高倍率'
|
||||
: '-'
|
||||
}
|
||||
// 根据 lottery_config_id 显示彩金池配置名称
|
||||
const lotteryConfigNameFormatter = (row: any) =>
|
||||
row?.diceLotteryPoolConfig?.name ?? (row?.lottery_config_id ? `#${row.lottery_config_id}` : '未知')
|
||||
|
||||
// 表格配置
|
||||
// 表格
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
@@ -158,28 +150,83 @@
|
||||
apiFn: api.list,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'username', label: '用户名' },
|
||||
{ prop: 'phone', label: '手机号' },
|
||||
{ prop: 'name', label: '昵称' },
|
||||
{ prop: 'status', label: '状态', width: 88, useSlot: true },
|
||||
{ prop: 'coin', label: '平台币', width: 100, useSlot: true },
|
||||
{ prop: 'is_up', label: '倍率', width: 80, formatter: isUpFormatter },
|
||||
{ prop: 't1_wight', label: 'T1池权重', width: 100, formatter: weightFormatter('t1_wight') },
|
||||
{ prop: 't2_wight', label: 'T2池权重', width: 100, formatter: weightFormatter('t2_wight') },
|
||||
{ prop: 't3_wight', label: 'T3池权重', width: 100, formatter: weightFormatter('t3_wight') },
|
||||
{ prop: 't4_wight', label: 'T4池权重', width: 100, formatter: weightFormatter('t4_wight') },
|
||||
{ prop: 't5_wight', label: 'T5池权重', width: 100, formatter: weightFormatter('t5_wight') },
|
||||
{ prop: 'total_ticket_count', label: '总抽奖次数' },
|
||||
{ prop: 'paid_ticket_count', label: '购买抽奖次数' },
|
||||
{ prop: 'free_ticket_count', label: '赠送抽奖次数' },
|
||||
{ prop: 'created_at', label: '创建时间' },
|
||||
{ prop: 'updated_at', label: '更新时间' },
|
||||
{ prop: 'operation', label: '操作', width: 120, fixed: 'right', useSlot: true }
|
||||
{ prop: 'username', label: '用户名', align: 'center' },
|
||||
{ prop: 'phone', label: '手机号', align: 'center' },
|
||||
{ prop: 'name', label: '昵称', align: 'center' },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
width: 88,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'coin',
|
||||
label: '平台币',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'lottery_config_id',
|
||||
label: '彩金池配置',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
formatter: (row: any) => lotteryConfigNameFormatter(row)
|
||||
},
|
||||
{
|
||||
prop: 't1_weight',
|
||||
label: 'T1权重',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t1_weight')
|
||||
},
|
||||
{
|
||||
prop: 't2_weight',
|
||||
label: 'T2权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t2_weight')
|
||||
},
|
||||
{
|
||||
prop: 't3_weight',
|
||||
label: 'T3权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t3_weight')
|
||||
},
|
||||
{
|
||||
prop: 't4_weight',
|
||||
label: 'T4权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t4_weight')
|
||||
},
|
||||
{
|
||||
prop: 't5_weight',
|
||||
label: 'T5权重',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
formatter: weightFormatter('t5_weight')
|
||||
},
|
||||
{ prop: 'total_ticket_count', label: '总抽奖次数', align: 'center' },
|
||||
{ prop: 'paid_ticket_count', label: '购买抽奖次数', align: 'center' },
|
||||
{ prop: 'free_ticket_count', label: '赠送抽奖次数', align: 'center' },
|
||||
{ prop: 'create_time', label: '创建时间', align: 'center' },
|
||||
{ prop: 'update_time', label: '更新时间', align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 状态开关切换(列表内直接修改)
|
||||
// 状态切换
|
||||
const handleStatusChange = async (row: Record<string, any>, status: number) => {
|
||||
row._statusLoading = true
|
||||
try {
|
||||
@@ -192,7 +239,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑配置
|
||||
// 弹窗与删除
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
@@ -204,7 +251,7 @@
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
|
||||
// 钱包操作弹窗(从平台币 tag 点击打开)
|
||||
// 钱包操作弹窗
|
||||
const walletDialogVisible = ref(false)
|
||||
type WalletPlayer = { id: number; username?: string; coin?: number }
|
||||
const walletOperatePlayer = ref<WalletPlayer | null>(null)
|
||||
|
||||
@@ -15,7 +15,13 @@
|
||||
<el-input v-model="formData.name" placeholder="请输入昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="formData.phone" placeholder="请输入手机号" clearable maxlength="20" show-word-limit />
|
||||
<el-input
|
||||
v-model="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
clearable
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password" :rules="passwordRules">
|
||||
<el-input
|
||||
@@ -28,6 +34,23 @@
|
||||
<el-form-item label="状态" prop="status">
|
||||
<sa-switch v-model="formData.status" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属管理员" prop="admin_id">
|
||||
<el-select
|
||||
v-model="formData.admin_id"
|
||||
placeholder="选择后台管理员(可选)"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
:loading="systemUserOptionsLoading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in systemUserOptions"
|
||||
:key="item.id"
|
||||
:label="item.label || item.username || `#${item.id}`"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="平台币" prop="coin">
|
||||
<el-input-number
|
||||
v-model="formData.coin"
|
||||
@@ -38,29 +61,98 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="倍率" prop="is_up">
|
||||
<el-select v-model="formData.is_up" placeholder="请选择倍率" clearable style="width: 100%">
|
||||
<el-option label="正常" :value="0" />
|
||||
<el-option label="强制杀猪" :value="1" />
|
||||
<el-option label="T1高倍率" :value="2" />
|
||||
<!-- lottery_config_id:空 = 自定义权重,否则 = DiceLotteryConfig.id;选择后该配置的五个 weight 会写入下方 player.*_weight -->
|
||||
<el-form-item label="彩金池配置" prop="lottery_config_id">
|
||||
<el-select
|
||||
v-model="formData.lottery_config_id"
|
||||
placeholder="留空则使用下方自定义权重,或选择彩金池"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
:loading="lotteryConfigLoading"
|
||||
@change="onLotteryConfigChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in lotteryConfigOptions"
|
||||
:key="item.id"
|
||||
:label="(item.name && String(item.name).trim()) || `#${item.id}`"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="T1池权重(%)" prop="t1_wight">
|
||||
<el-slider v-model="formData.t1_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<!-- 当前选中的 DiceLotteryConfig 数据展示 -->
|
||||
<el-form-item v-if="currentLotteryConfig" label="当前配置" class="current-config-block">
|
||||
<div class="current-lottery-config">
|
||||
<div class="config-row">
|
||||
<span class="config-label">名称:</span>
|
||||
<span>{{ currentLotteryConfig.name ?? '-' }}</span>
|
||||
</div>
|
||||
<div class="config-row">
|
||||
<span class="config-label">类型:</span>
|
||||
<span>{{ lotteryConfigTypeText(currentLotteryConfig.type) }}</span>
|
||||
</div>
|
||||
<div class="config-row">
|
||||
<span class="config-label">T1~T5 权重:</span>
|
||||
<span>{{ currentLotteryConfigWeightsText }}</span>
|
||||
</div>
|
||||
<div v-if="currentLotteryConfig.remark" class="config-row">
|
||||
<span class="config-label">备注:</span>
|
||||
<span>{{ currentLotteryConfig.remark }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="T2池权重(%)" prop="t2_wight">
|
||||
<el-slider v-model="formData.t2_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<!-- lottery_config_id 为空时自定义权重可编辑;有值时来自所选 DiceLotteryConfig,仅展示不可编辑 -->
|
||||
<el-form-item label="T1池权重(%)" prop="t1_weight">
|
||||
<el-slider
|
||||
v-model="formData.t1_weight"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
show-input
|
||||
:disabled="!isLotteryConfigEmpty()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="T3池权重(%)" prop="t3_wight">
|
||||
<el-slider v-model="formData.t3_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T2池权重(%)" prop="t2_weight">
|
||||
<el-slider
|
||||
v-model="formData.t2_weight"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
show-input
|
||||
:disabled="!isLotteryConfigEmpty()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="T4池权重(%)" prop="t4_wight">
|
||||
<el-slider v-model="formData.t4_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T3池权重(%)" prop="t3_weight">
|
||||
<el-slider
|
||||
v-model="formData.t3_weight"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
show-input
|
||||
:disabled="!isLotteryConfigEmpty()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="T5池权重(%)" prop="t5_wight">
|
||||
<el-slider v-model="formData.t5_wight" :min="0" :max="100" :step="0.01" show-input />
|
||||
<el-form-item label="T4池权重(%)" prop="t4_weight">
|
||||
<el-slider
|
||||
v-model="formData.t4_weight"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
show-input
|
||||
:disabled="!isLotteryConfigEmpty()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-form-item label="T5池权重(%)" prop="t5_weight">
|
||||
<el-slider
|
||||
v-model="formData.t5_weight"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:step="0.01"
|
||||
show-input
|
||||
:disabled="!isLotteryConfigEmpty()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="isLotteryConfigEmpty()">
|
||||
<div class="text-gray-500 text-sm">
|
||||
五个池权重总和:<span :class="Math.abs(weightsSum - 100) > 0.01 ? 'text-red-500' : ''">{{
|
||||
weightsSum
|
||||
@@ -78,9 +170,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/player/index'
|
||||
import lotteryConfigApi from '../../../api/lottery_pool_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
const WEIGHT_FIELDS = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'] as const
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
@@ -107,9 +202,20 @@
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
const WEIGHT_KEYS = ['t1_wight', 't2_wight', 't3_wight', 't4_wight', 't5_wight'] as const
|
||||
const weightsSum = computed(() => {
|
||||
return WEIGHT_KEYS.reduce((sum, key) => sum + Number(formData[key] ?? 0), 0)
|
||||
return WEIGHT_FIELDS.reduce((sum, key) => sum + Number(formData[key] ?? 0), 0)
|
||||
})
|
||||
|
||||
/** 当前彩金池配置的 T1~T5 权重展示文案 */
|
||||
const currentLotteryConfigWeightsText = computed(() => {
|
||||
const c = currentLotteryConfig.value
|
||||
if (!c) return '-'
|
||||
const t1 = c.t1_weight ?? 0
|
||||
const t2 = c.t2_weight ?? 0
|
||||
const t3 = c.t3_weight ?? 0
|
||||
const t4 = c.t4_weight ?? 0
|
||||
const t5 = c.t5_weight ?? 0
|
||||
return `${t1}% / ${t2}% / ${t3}% / ${t4}% / ${t5}%`
|
||||
})
|
||||
|
||||
/** 新增时密码必填,编辑时选填 */
|
||||
@@ -132,17 +238,69 @@
|
||||
phone: '',
|
||||
password: '',
|
||||
status: 1 as number,
|
||||
/** 所属后台管理员 ID(SystemUser.id) */
|
||||
admin_id: null as number | null,
|
||||
coin: 0 as number,
|
||||
is_up: null as number | null,
|
||||
t1_wight: 0 as number,
|
||||
t2_wight: 0 as number,
|
||||
t3_wight: 0 as number,
|
||||
t4_wight: 0 as number,
|
||||
t5_wight: 0 as number
|
||||
/** 彩金池配置 ID:空 = 自定义权重,否则 = DiceLotteryConfig.id */
|
||||
lottery_config_id: null as number | null,
|
||||
t1_weight: 0 as number,
|
||||
t2_weight: 0 as number,
|
||||
t3_weight: 0 as number,
|
||||
t4_weight: 0 as number,
|
||||
t5_weight: 0 as number
|
||||
}
|
||||
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/** 彩金池配置下拉选项(DiceLotteryConfig id、name) */
|
||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
/** 彩金池选项加载中 */
|
||||
const lotteryConfigLoading = ref(false)
|
||||
/** 后台管理员下拉选项(SystemUser) */
|
||||
const systemUserOptions = ref<
|
||||
Array<{ id: number; username: string; realname: string; label: string }>
|
||||
>([])
|
||||
/** 管理员选项加载中 */
|
||||
const systemUserOptionsLoading = ref(false)
|
||||
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
|
||||
const currentLotteryConfig = ref<Record<string, any> | null>(null)
|
||||
|
||||
function lotteryConfigTypeText(type: unknown): string {
|
||||
const t = Number(type)
|
||||
if (t === 0) return '付费'
|
||||
if (t === 1) return '赠送'
|
||||
return t ? `类型${t}` : '-'
|
||||
}
|
||||
|
||||
/** 是否为空/自定义权重(未选彩金池或选 0) */
|
||||
function isLotteryConfigEmpty(): boolean {
|
||||
const v = formData.lottery_config_id
|
||||
return v == null || v === 0
|
||||
}
|
||||
|
||||
/** 根据当前 lottery_config_id 加载 DiceLotteryConfig,并将五个权重写入当前 player.*_weight */
|
||||
async function loadCurrentLotteryConfig() {
|
||||
const id = formData.lottery_config_id
|
||||
if (id == null || id === 0) {
|
||||
currentLotteryConfig.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await lotteryConfigApi.read(id)
|
||||
const row = (res as any)?.data ?? (res as any)
|
||||
if (row && typeof row === 'object') {
|
||||
currentLotteryConfig.value = row
|
||||
WEIGHT_FIELDS.forEach((key) => {
|
||||
;(formData as any)[key] = Number(row[key] ?? 0)
|
||||
})
|
||||
} else {
|
||||
currentLotteryConfig.value = null
|
||||
}
|
||||
} catch {
|
||||
currentLotteryConfig.value = null
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
@@ -150,11 +308,63 @@
|
||||
}
|
||||
)
|
||||
|
||||
/** 选择彩金池后,拉取该配置的五个权重并写入当前 player.*_weight,并更新当前配置展示 */
|
||||
async function onLotteryConfigChange(lotteryConfigId: number | null | undefined) {
|
||||
if (lotteryConfigId == null || lotteryConfigId === 0) {
|
||||
currentLotteryConfig.value = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await lotteryConfigApi.read(lotteryConfigId)
|
||||
const row = (res as any)?.data ?? (res as any)
|
||||
if (row && typeof row === 'object') {
|
||||
WEIGHT_FIELDS.forEach((key) => {
|
||||
;(formData as any)[key] = Number(row[key] ?? 0)
|
||||
})
|
||||
currentLotteryConfig.value = row
|
||||
} else {
|
||||
currentLotteryConfig.value = null
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('拉取彩金池配置失败', err)
|
||||
currentLotteryConfig.value = null
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载后台管理员选项 */
|
||||
async function loadSystemUserOptions() {
|
||||
systemUserOptionsLoading.value = true
|
||||
try {
|
||||
systemUserOptions.value = await api.getSystemUserOptions()
|
||||
} catch {
|
||||
systemUserOptions.value = []
|
||||
} finally {
|
||||
systemUserOptionsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const initPage = async () => {
|
||||
currentLotteryConfig.value = null
|
||||
Object.assign(formData, initialFormData)
|
||||
await Promise.all([loadLotteryConfigOptions(), loadSystemUserOptions()])
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
if (!isLotteryConfigEmpty()) {
|
||||
await loadCurrentLotteryConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 从玩家控制器获取 DiceLotteryConfig id/name 列表,供 lottery_config_id 下拉使用 */
|
||||
async function loadLotteryConfigOptions() {
|
||||
lotteryConfigLoading.value = true
|
||||
try {
|
||||
lotteryConfigOptions.value = await api.getLotteryConfigOptions()
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
} finally {
|
||||
lotteryConfigLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,12 +372,12 @@
|
||||
'id',
|
||||
'status',
|
||||
'coin',
|
||||
'is_up',
|
||||
't1_wight',
|
||||
't2_wight',
|
||||
't3_wight',
|
||||
't4_wight',
|
||||
't5_wight'
|
||||
'lottery_config_id',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
't4_weight',
|
||||
't5_weight'
|
||||
]
|
||||
|
||||
const initForm = () => {
|
||||
@@ -180,8 +390,14 @@
|
||||
}
|
||||
const val = props.data[key]
|
||||
if (numKeys.includes(key)) {
|
||||
;(formData as any)[key] =
|
||||
key === 'id' ? (val != null ? Number(val) || null : null) : Number(val) || 0
|
||||
if (key === 'id') {
|
||||
;(formData as any)[key] = val != null ? Number(val) || null : null
|
||||
} else if (key === 'lottery_config_id' || key === 'admin_id') {
|
||||
const num = Number(val)
|
||||
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null
|
||||
} else {
|
||||
;(formData as any)[key] = Number(val) || 0
|
||||
}
|
||||
} else {
|
||||
;(formData as any)[key] = val ?? ''
|
||||
}
|
||||
@@ -197,11 +413,15 @@
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (Math.abs(weightsSum.value - 100) > 0.01) {
|
||||
const useCustomWeights = isLotteryConfigEmpty()
|
||||
if (useCustomWeights && Math.abs(weightsSum.value - 100) > 0.01) {
|
||||
ElMessage.warning('五个池权重总和必须为100%')
|
||||
return
|
||||
}
|
||||
const payload = { ...formData }
|
||||
if (isLotteryConfigEmpty()) {
|
||||
;(payload as any).lottery_config_id = null
|
||||
}
|
||||
if (props.dialogType === 'edit' && !payload.password) {
|
||||
delete (payload as any).password
|
||||
}
|
||||
@@ -219,3 +439,31 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.current-config-block {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.current-lottery-config {
|
||||
padding: 10px 12px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
|
||||
.config-row {
|
||||
margin-bottom: 6px;
|
||||
line-height: 1.5;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.config-label {
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -44,11 +44,19 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="倍率" prop="is_up">
|
||||
<el-select v-model="formData.is_up" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="正常" :value="0" />
|
||||
<el-option label="强制杀猪" :value="1" />
|
||||
<el-option label="T1高倍率" :value="2" />
|
||||
<el-form-item label="彩金池配置" prop="lottery_config_id">
|
||||
<el-select
|
||||
v-model="formData.lottery_config_id"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in lotteryConfigOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -56,6 +64,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/player/index'
|
||||
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
@@ -67,6 +77,16 @@
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
const isExpanded = ref<boolean>(false)
|
||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
|
||||
/** 从玩家控制器获取 DiceLotteryPoolConfig id/name 列表,用于 lottery_config_id 筛选 */
|
||||
onMounted(async () => {
|
||||
try {
|
||||
lotteryConfigOptions.value = await api.getLotteryConfigOptions()
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
}
|
||||
})
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
|
||||
@@ -8,23 +8,23 @@
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton v-permission="'dice:player_ticket_record:index:save'" @click="showDialog('add')" v-ripple>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:player_ticket_record:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
<!-- <ElButton v-permission="'dice:player_ticket_record:index:save'" @click="showDialog('add')" v-ripple>-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:add-fill" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 新增-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:player_ticket_record:index:destroy'"-->
|
||||
<!-- :disabled="selectedRows.length === 0"-->
|
||||
<!-- @click="deleteSelectedRows(api.delete, refreshData)"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:delete-bin-5-line" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 删除-->
|
||||
<!-- </ElButton>-->
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
@@ -50,11 +50,11 @@
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:player_ticket_record:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
<!-- <SaButton-->
|
||||
<!-- v-permission="'dice:player_ticket_record:index:destroy'"-->
|
||||
<!-- type="error"-->
|
||||
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
|
||||
<!-- />-->
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
@@ -77,7 +77,6 @@
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
username: undefined,
|
||||
@@ -127,16 +126,28 @@
|
||||
const usernameFormatter = (row: Record<string, any>) =>
|
||||
row?.dicePlayer?.username ?? row?.player_id ?? '-'
|
||||
return [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{ prop: 'player_id', label: '玩家用户名', formatter: (row: Record<string, any>) => usernameFormatter(row) },
|
||||
{ prop: 'use_coins', label: '消耗硬币' },
|
||||
{ prop: 'total_ticket_count', label: '总抽奖次数' },
|
||||
{ prop: 'paid_ticket_count', label: '购买抽奖次数' },
|
||||
{ prop: 'free_ticket_count', label: '赠送抽奖次数' },
|
||||
{ prop: 'remark', label: '备注', width: 100, showOverflowTooltip: true },
|
||||
{ prop: 'create_time', label: '创建时间', width: 170 },
|
||||
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||
// { type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80, align: 'center' },
|
||||
{
|
||||
prop: 'player_id',
|
||||
label: '玩家用户名',
|
||||
align: 'center',
|
||||
formatter: (row: Record<string, any>) => usernameFormatter(row)
|
||||
},
|
||||
{ prop: 'use_coins', label: '消耗硬币', align: 'center' },
|
||||
{ prop: 'total_ticket_count', label: '总抽奖次数', align: 'center' },
|
||||
{ prop: 'paid_ticket_count', label: '购买抽奖次数', align: 'center' },
|
||||
{ prop: 'free_ticket_count', label: '赠送抽奖次数', align: 'center' },
|
||||
{ prop: 'remark', label: '备注', width: 100, align: 'center', showOverflowTooltip: true },
|
||||
{ prop: 'create_time', label: '创建时间', width: 170, align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 60,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -148,10 +159,9 @@
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
// deleteRow,
|
||||
// deleteSelectedRows,
|
||||
handleSelectionChange
|
||||
// selectedRows
|
||||
} = useSaiAdmin()
|
||||
|
||||
</script>
|
||||
|
||||
@@ -26,7 +26,12 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="消耗硬币" prop="use_coins">
|
||||
<el-input-number v-model="formData.use_coins" placeholder="请输入消耗硬币" :min="0" />
|
||||
<el-input-number
|
||||
v-model="formData.use_coins"
|
||||
placeholder="请输入消耗硬币"
|
||||
:min="0"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="购买抽奖次数" prop="paid_ticket_count">
|
||||
<el-input-number
|
||||
@@ -34,6 +39,7 @@
|
||||
placeholder="请输入购买抽奖次数"
|
||||
:min="0"
|
||||
@change="onTicketCountChange"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="赠送抽奖次数" prop="free_ticket_count">
|
||||
@@ -42,6 +48,7 @@
|
||||
placeholder="请输入赠送抽奖次数"
|
||||
:min="0"
|
||||
@change="onTicketCountChange"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="总抽奖次数" prop="total_ticket_count">
|
||||
@@ -60,6 +67,8 @@
|
||||
placeholder="请输入备注(必填)"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
@@ -7,29 +7,29 @@
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:player_wallet_record:index:save'"
|
||||
@click="showDialog('add')"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:player_wallet_record:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
<!-- <ElSpace wrap>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:player_wallet_record:index:save'"-->
|
||||
<!-- @click="showDialog('add')"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:add-fill" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 新增-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:player_wallet_record:index:destroy'"-->
|
||||
<!-- :disabled="selectedRows.length === 0"-->
|
||||
<!-- @click="deleteSelectedRows(api.delete, refreshData)"-->
|
||||
<!-- v-ripple-->
|
||||
<!-- >-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <ArtSvgIcon icon="ri:delete-bin-5-line" />-->
|
||||
<!-- </template>-->
|
||||
<!-- 删除-->
|
||||
<!-- </ElButton>-->
|
||||
<!-- </ElSpace>-->
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
@@ -60,11 +60,11 @@
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:player_wallet_record:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
<!-- <SaButton-->
|
||||
<!-- v-permission="'dice:player_wallet_record:index:destroy'"-->
|
||||
<!-- type="error"-->
|
||||
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
|
||||
<!-- />-->
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
@@ -203,7 +203,7 @@
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 100,
|
||||
width: 60,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
@@ -218,10 +218,10 @@
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
// deleteRow,
|
||||
// deleteSelectedRows,
|
||||
handleSelectionChange
|
||||
// selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -27,7 +27,13 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="formData.type" placeholder="请选择类型" clearable style="width: 100%">
|
||||
<el-select
|
||||
v-model="formData.type"
|
||||
placeholder="请选择类型"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
>
|
||||
<el-option label="充值" :value="0" />
|
||||
<el-option label="提现" :value="1" />
|
||||
<el-option label="购买抽奖次数" :value="2" />
|
||||
@@ -42,6 +48,7 @@
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
@change="onCoinChange"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="钱包操作前" prop="wallet_before">
|
||||
@@ -70,6 +77,7 @@
|
||||
placeholder="选填"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
137
saiadmin-artd/src/views/plugin/dice/reward/index/index.vue
Normal file
137
saiadmin-artd/src/views/plugin/dice/reward/index/index.vue
Normal file
@@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 方向切换 + 搜索 -->
|
||||
<div class="direction-bar">
|
||||
<el-radio-group v-model="currentDirection" size="default" @change="onDirectionChange">
|
||||
<el-radio-button :value="0">顺时针</el-radio-button>
|
||||
<el-radio-button :value="1">逆时针</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:reward:index:update'"
|
||||
type="primary"
|
||||
@click="weightRatioVisible = true"
|
||||
v-ripple
|
||||
>
|
||||
权重配比
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:reward:index:index'"
|
||||
@click="weightTestVisible = true"
|
||||
v-ripple
|
||||
>
|
||||
一键测试权重
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
/>
|
||||
</ElCard>
|
||||
|
||||
<WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" />
|
||||
<WeightTestDialog v-model="weightTestVisible" @success="refreshData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import api from '../../api/reward/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import WeightRatioDialog from './modules/weight-ratio-dialog.vue'
|
||||
import WeightTestDialog from './modules/weight-test-dialog.vue'
|
||||
|
||||
const currentDirection = ref<0 | 1>(0)
|
||||
const weightRatioVisible = ref(false)
|
||||
const weightTestVisible = ref(false)
|
||||
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
direction: 0,
|
||||
tier: undefined
|
||||
})
|
||||
|
||||
const listApi = (params: Record<string, any>) => {
|
||||
return api.list({ ...params, direction: currentDirection.value })
|
||||
}
|
||||
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, { ...params, direction: currentDirection.value })
|
||||
getData()
|
||||
}
|
||||
|
||||
const onDirectionChange = () => {
|
||||
searchForm.value.direction = currentDirection.value
|
||||
Object.assign(searchParams, { direction: currentDirection.value, tier: searchForm.value.tier })
|
||||
getData()
|
||||
}
|
||||
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: listApi,
|
||||
apiParams: { direction: 0, limit: 100 },
|
||||
columnsFactory: () => [
|
||||
{ prop: 'start_index', label: '起始索引', width: 100, align: 'center' },
|
||||
{ prop: 'end_index', label: '结束索引(end_index)', width: 110, align: 'center' },
|
||||
{ prop: 'tier', label: '档位', width: 90, align: 'center', sortable: true },
|
||||
{
|
||||
prop: 'grid_number',
|
||||
label: '色子点数(摇取5-30)',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
sortable: true,
|
||||
showOverflowTooltip: true
|
||||
},
|
||||
{
|
||||
prop: 'ui_text',
|
||||
label: '显示文本',
|
||||
minWidth: 100,
|
||||
align: 'center',
|
||||
showOverflowTooltip: true
|
||||
},
|
||||
{ prop: 'real_ev', label: '实际中奖金额', width: 110, align: 'center' },
|
||||
{ prop: 'remark', label: '备注', minWidth: 80, align: 'center', showOverflowTooltip: true },
|
||||
{ prop: 'weight', label: '权重(1-10000)', width: 110, align: 'center' }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
searchParams.direction = currentDirection.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.direction-bar {
|
||||
margin-bottom: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="100px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
>
|
||||
<el-col v-bind="setSpan(8)">
|
||||
<el-form-item label="档位" prop="tier">
|
||||
<el-select v-model="formData.tier" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
<el-option label="BIGWIN" value="BIGWIN" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, any>): void
|
||||
(e: 'search', params: Record<string, any>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref?.resetFields?.()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
emit('search', { ...formData.value })
|
||||
}
|
||||
|
||||
const setSpan = (span: number) => ({
|
||||
span,
|
||||
xs: 24,
|
||||
sm: 12,
|
||||
md: 8,
|
||||
lg: span,
|
||||
xl: span
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,552 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="奖励对照表(dice_reward)权重配比"
|
||||
width="900px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<div class="global-tip">
|
||||
编辑的是<strong>奖励对照表(dice_reward / DiceReward 模型)</strong
|
||||
>的权重,按<strong>结束索引(end_index)</strong>区分
|
||||
<strong>顺时针</strong>与<strong>逆时针</strong>两套权重;抽奖时按当前方向取对应权重。
|
||||
</div>
|
||||
<div v-loading="loading" class="dialog-body">
|
||||
<el-tabs v-model="activeTier" type="card">
|
||||
<el-tab-pane v-for="t in tierKeys" :key="t" :label="t" :name="t">
|
||||
<div v-if="getTierItems(t).length === 0" class="empty-tip">该档位暂无配置数据</div>
|
||||
<template v-else>
|
||||
<div class="chart-wrap" v-if="t !== 'T4' && t !== 'T5'">
|
||||
<div class="chart-row">
|
||||
<ArtBarChart
|
||||
x-axis-name="结束索引"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartData(t, 'clockwise')"
|
||||
height="180px"
|
||||
/>
|
||||
<ArtBarChart
|
||||
x-axis-name="结束索引"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartData(t, 'counterclockwise')"
|
||||
height="180px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="weight-sum" v-if="t !== 'T4' && t !== 'T5'">
|
||||
当前档位权重合计(顺时针):<strong>{{ getTierSum(t, 'clockwise') }}</strong>
|
||||
;逆时针:<strong>{{ getTierSum(t, 'counterclockwise') }}</strong>
|
||||
(各条 1-10000,和不限制)
|
||||
</div>
|
||||
<div class="weight-sum weight-sum-t4t5" v-else>T4、T5 仅单一结果,无需配置权重。</div>
|
||||
<el-table :data="getTierItems(t)" border size="small" class="weight-table">
|
||||
<el-table-column
|
||||
label="结束索引(id)"
|
||||
prop="id"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column label="色子点数" prop="grid_number" width="80" align="center" />
|
||||
<el-table-column
|
||||
label="实际中奖金额"
|
||||
prop="real_ev"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="显示文本"
|
||||
prop="ui_text"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="备注"
|
||||
prop="remark"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column label="顺时针权重(direction=0)" min-width="160" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeight(row, 'clockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="
|
||||
(v: number | number[]) =>
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'clockwise',
|
||||
Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1)
|
||||
)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isWeightDisabled(row, t) || getItemWeight(row, 'clockwise') <= 1"
|
||||
@click="
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'clockwise',
|
||||
Math.max(1, getItemWeight(row, 'clockwise') - 1)
|
||||
)
|
||||
"
|
||||
>-</el-button
|
||||
>
|
||||
<el-input-number
|
||||
:model-value="getItemWeight(row, 'clockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="
|
||||
(v: number | string | undefined) =>
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'clockwise',
|
||||
typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1
|
||||
)
|
||||
"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) || getItemWeight(row, 'clockwise') >= 10000
|
||||
"
|
||||
@click="
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'clockwise',
|
||||
Math.min(10000, getItemWeight(row, 'clockwise') + 1)
|
||||
)
|
||||
"
|
||||
>+</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="逆时针权重(direction=1)" min-width="160" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeight(row, 'counterclockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="
|
||||
(v: number | number[]) =>
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'counterclockwise',
|
||||
Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1)
|
||||
)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) || getItemWeight(row, 'counterclockwise') <= 1
|
||||
"
|
||||
@click="
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'counterclockwise',
|
||||
Math.max(1, getItemWeight(row, 'counterclockwise') - 1)
|
||||
)
|
||||
"
|
||||
>-</el-button
|
||||
>
|
||||
<el-input-number
|
||||
:model-value="getItemWeight(row, 'counterclockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="
|
||||
(v: number | string | undefined) =>
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'counterclockwise',
|
||||
typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1
|
||||
)
|
||||
"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) ||
|
||||
getItemWeight(row, 'counterclockwise') >= 10000
|
||||
"
|
||||
@click="
|
||||
setItemWeightByRow(
|
||||
t,
|
||||
row,
|
||||
'counterclockwise',
|
||||
Math.min(10000, getItemWeight(row, 'counterclockwise') + 1)
|
||||
)
|
||||
"
|
||||
>+</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward/index'
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const TIER_KEYS = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
|
||||
/** 供模板 v-for 使用 */
|
||||
const tierKeys = TIER_KEYS
|
||||
type DirectionKey = 'clockwise' | 'counterclockwise'
|
||||
|
||||
interface WeightRow {
|
||||
reward_id_clockwise?: number
|
||||
reward_id_counterclockwise?: number
|
||||
id?: number
|
||||
grid_number?: number
|
||||
real_ev?: number
|
||||
ui_text?: string
|
||||
remark?: string
|
||||
tier?: string
|
||||
weight_clockwise: number
|
||||
weight_counterclockwise: number
|
||||
}
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
const activeTier = ref('T1')
|
||||
const submitting = ref(false)
|
||||
const loading = ref(false)
|
||||
const grouped = ref<Record<string, WeightRow[]>>({
|
||||
T1: [],
|
||||
T2: [],
|
||||
T3: [],
|
||||
T4: [],
|
||||
T5: []
|
||||
})
|
||||
|
||||
function getTierItems(tier: string): WeightRow[] {
|
||||
return grouped.value[tier] ?? []
|
||||
}
|
||||
|
||||
function getTierChartLabels(tier: string): string[] {
|
||||
return getTierItems(tier).map((r) => String(r.grid_number ?? ''))
|
||||
}
|
||||
|
||||
function getTierChartData(tier: string, dir: DirectionKey): number[] {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
return getTierItems(tier).map((r) => toWeightPrecision(r[key] ?? 1))
|
||||
}
|
||||
|
||||
function getTierSum(tier: string, dir: DirectionKey): number {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
return getTierItems(tier).reduce((s, r) => s + toWeightPrecision(r[key] ?? 1), 0)
|
||||
}
|
||||
|
||||
function getItemWeight(row: WeightRow, dir: DirectionKey): number {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
const w = row[key]
|
||||
const num = typeof w === 'number' && !Number.isNaN(w) ? w : Number(w)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return toWeightPrecision(num)
|
||||
}
|
||||
|
||||
function toWeightPrecision(value: number): number {
|
||||
return Math.max(1, Math.min(10000, Math.floor(value)))
|
||||
}
|
||||
|
||||
function setItemWeightByRow(tier: string, row: WeightRow, dir: DirectionKey, value: number) {
|
||||
const v = toWeightPrecision(typeof value === 'number' && !Number.isNaN(value) ? value : 1)
|
||||
const list = grouped.value[tier]
|
||||
if (!list) return
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
const rid = dir === 'clockwise' ? row.reward_id_clockwise : row.reward_id_counterclockwise
|
||||
const idx = list.findIndex(
|
||||
(r) =>
|
||||
r === row ||
|
||||
(rid != null &&
|
||||
(dir === 'clockwise' ? r.reward_id_clockwise : r.reward_id_counterclockwise) === rid)
|
||||
)
|
||||
if (idx >= 0) list[idx][key] = v
|
||||
else row[key] = v
|
||||
}
|
||||
|
||||
function isWeightDisabled(row: WeightRow, tier: string): boolean {
|
||||
if (tier === 'T4' || tier === 'T5') return true
|
||||
return false
|
||||
}
|
||||
|
||||
function normalizeWeightValue(v: unknown): number {
|
||||
const num = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return Math.max(1, Math.min(10000, Math.floor(num)))
|
||||
}
|
||||
|
||||
/** 兼容接口返回 tier -> { 0: [], 1: [] },按 grid_number 合并为每档位一行,含 reward_id 与双方向权重 */
|
||||
function parsePayload(res: any): Record<string, WeightRow[]> {
|
||||
const empty: Record<string, WeightRow[]> = {
|
||||
T1: [],
|
||||
T2: [],
|
||||
T3: [],
|
||||
T4: [],
|
||||
T5: []
|
||||
}
|
||||
if (!res || typeof res !== 'object') return empty
|
||||
const raw = res?.data ?? res
|
||||
if (!raw || typeof raw !== 'object') return empty
|
||||
const out = { ...empty }
|
||||
for (const t of TIER_KEYS) {
|
||||
const tierData = raw[t]
|
||||
if (!tierData || typeof tierData !== 'object') continue
|
||||
const list0 = Array.isArray(tierData[0]) ? tierData[0] : []
|
||||
const list1 = Array.isArray(tierData[1]) ? tierData[1] : []
|
||||
const byGrid = new Map<
|
||||
number,
|
||||
{
|
||||
reward_id_clockwise?: number
|
||||
reward_id_counterclockwise?: number
|
||||
id?: number
|
||||
grid_number?: number
|
||||
real_ev?: number
|
||||
ui_text?: string
|
||||
remark?: string
|
||||
weight_clockwise: number
|
||||
weight_counterclockwise: number
|
||||
}
|
||||
>()
|
||||
for (const r of list0) {
|
||||
const gn = r.grid_number != null ? Number(r.grid_number) : NaN
|
||||
if (!Number.isNaN(gn)) {
|
||||
byGrid.set(gn, {
|
||||
reward_id_clockwise: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
id: r.id != null ? Number(r.id) : undefined,
|
||||
grid_number: gn,
|
||||
real_ev: r.real_ev,
|
||||
ui_text: r.ui_text,
|
||||
remark: r.remark,
|
||||
weight_clockwise: normalizeWeightValue(r.weight),
|
||||
weight_counterclockwise: 1
|
||||
})
|
||||
}
|
||||
}
|
||||
for (const r of list1) {
|
||||
const gn = r.grid_number != null ? Number(r.grid_number) : NaN
|
||||
if (!Number.isNaN(gn)) {
|
||||
const cur = byGrid.get(gn)
|
||||
if (cur) {
|
||||
cur.reward_id_counterclockwise = r.reward_id != null ? Number(r.reward_id) : undefined
|
||||
cur.weight_counterclockwise = normalizeWeightValue(r.weight)
|
||||
} else {
|
||||
byGrid.set(gn, {
|
||||
reward_id_counterclockwise: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
id: r.id != null ? Number(r.id) : undefined,
|
||||
grid_number: gn,
|
||||
real_ev: r.real_ev,
|
||||
ui_text: r.ui_text,
|
||||
remark: r.remark,
|
||||
weight_clockwise: 1,
|
||||
weight_counterclockwise: normalizeWeightValue(r.weight)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
out[t] = Array.from(byGrid.values())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function loadData() {
|
||||
loading.value = true
|
||||
api
|
||||
.weightRatioListWithDirection()
|
||||
.then((res: any) => {
|
||||
grouped.value = parsePayload(res)
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error('获取权重数据失败')
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
/** 按 DiceReward 主键 id 收集:每条记录一条 { id, weight } */
|
||||
function collectItems(): Array<{ id: number; weight: number }> {
|
||||
const items: Array<{ id: number; weight: number }> = []
|
||||
for (const t of TIER_KEYS) {
|
||||
for (const row of getTierItems(t)) {
|
||||
const w0 = isWeightDisabled(row, t) ? 10000 : getItemWeight(row, 'clockwise')
|
||||
const w1 = isWeightDisabled(row, t) ? 10000 : getItemWeight(row, 'counterclockwise')
|
||||
const rid0 = row.reward_id_clockwise != null ? row.reward_id_clockwise : 0
|
||||
const rid1 = row.reward_id_counterclockwise != null ? row.reward_id_counterclockwise : 0
|
||||
if (rid0 > 0) items.push({ id: rid0, weight: w0 })
|
||||
if (rid1 > 0) items.push({ id: rid1, weight: w1 })
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
const items = collectItems()
|
||||
if (items.length === 0) {
|
||||
ElMessage.info('没有可提交的配置')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.then(() => {
|
||||
ElMessage.success('保存成功')
|
||||
emit('success')
|
||||
handleClose()
|
||||
})
|
||||
.catch((e: { message?: string }) => {
|
||||
ElMessage.error(e?.message ?? '保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) {
|
||||
loadData()
|
||||
activeTier.value = 'T1'
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.chart-wrap {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.chart-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
> * {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
}
|
||||
.weight-sum {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.weight-sum-t4t5 {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.global-tip {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.weight-table {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.weight-cell-vertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.weight-slider-wrap {
|
||||
width: 100%;
|
||||
min-width: 80px;
|
||||
padding: 0 8px;
|
||||
:deep(.weight-slider) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.weight-input-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.dialog-body {
|
||||
min-height: 320px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,589 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="权重配比"
|
||||
width="900px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<div class="global-tip">
|
||||
配置<strong>奖励对照表(dice_reward)</strong>的权重,一级按<strong>方向</strong>(顺时针/逆时针),二级按<strong>档位</strong>(T1-T5);各条权重
|
||||
1-10000,档位内按权重比抽取。
|
||||
</div>
|
||||
<div v-loading="loading" class="dialog-body">
|
||||
<!-- 一级:方向(懒加载避免逆时针柱状图在隐藏容器内初始化导致不显示);二级档位 -->
|
||||
<el-tabs v-model="activeDirection" type="card" class="direction-tabs" :lazy="true">
|
||||
<el-tab-pane label="顺时针" name="0">
|
||||
<el-tabs v-model="activeTier" type="card" class="tier-tabs">
|
||||
<el-tab-pane v-for="t in tierKeys" :key="'cw-' + t" :label="t" :name="t">
|
||||
<div v-if="getTierItems(t).length === 0" class="empty-tip">该档位暂无配置数据</div>
|
||||
<template v-else>
|
||||
<div class="chart-wrap" v-if="t !== 'T4' && t !== 'T5'">
|
||||
<ArtBarChart
|
||||
:key="'cw-' + activeDirection + '-' + t"
|
||||
x-axis-name="点数"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartDataForCurrentDirection(t)"
|
||||
height="180px"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-sum" v-if="t !== 'T4' && t !== 'T5'">
|
||||
当前档位权重合计:<strong>{{ getTierSumForCurrentDirection(t) }}</strong>
|
||||
(各条 1-10000,档位内按权重比抽取,和不限制)
|
||||
</div>
|
||||
<div class="weight-sum weight-sum-t4t5" v-else
|
||||
>T4、T5 仅单一结果,无需配置权重。</div
|
||||
>
|
||||
<el-table :data="getTierItems(t)" border size="small" class="weight-table">
|
||||
<el-table-column
|
||||
label="点数(grid_number)"
|
||||
prop="grid_number"
|
||||
width="110"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="结束索引(id)"
|
||||
prop="id"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="实际中奖金额"
|
||||
prop="real_ev"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="显示文本"
|
||||
prop="ui_text"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="备注"
|
||||
prop="remark"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
:label="currentDirectionLabel + ' 权重(1-10000)'"
|
||||
min-width="200"
|
||||
align="center"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeightForCurrentDirection(row)"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="
|
||||
(v: number | number[]) =>
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1)
|
||||
)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) || getItemWeightForCurrentDirection(row) <= 1
|
||||
"
|
||||
@click="
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Math.max(1, getItemWeightForCurrentDirection(row) - 1)
|
||||
)
|
||||
"
|
||||
>-</el-button
|
||||
>
|
||||
<el-input-number
|
||||
:model-value="getItemWeightForCurrentDirection(row)"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="
|
||||
(v: number | string | undefined) =>
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1
|
||||
)
|
||||
"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) ||
|
||||
getItemWeightForCurrentDirection(row) >= 10000
|
||||
"
|
||||
@click="
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Math.min(10000, getItemWeightForCurrentDirection(row) + 1)
|
||||
)
|
||||
"
|
||||
>+</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="逆时针" name="1">
|
||||
<el-tabs v-model="activeTier" type="card" class="tier-tabs">
|
||||
<el-tab-pane v-for="t in tierKeys" :key="'ccw-' + t" :label="t" :name="t">
|
||||
<div v-if="getTierItems(t).length === 0" class="empty-tip">该档位暂无配置数据</div>
|
||||
<template v-else>
|
||||
<div class="chart-wrap" v-if="t !== 'T4' && t !== 'T5'">
|
||||
<ArtBarChart
|
||||
:key="'ccw-' + activeDirection + '-' + t"
|
||||
x-axis-name="点数"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartDataForCurrentDirection(t)"
|
||||
height="180px"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-sum" v-if="t !== 'T4' && t !== 'T5'">
|
||||
当前档位权重合计:<strong>{{ getTierSumForCurrentDirection(t) }}</strong>
|
||||
(各条 1-10000,档位内按权重比抽取,和不限制)
|
||||
</div>
|
||||
<div class="weight-sum weight-sum-t4t5" v-else
|
||||
>T4、T5 仅单一结果,无需配置权重。</div
|
||||
>
|
||||
<el-table :data="getTierItems(t)" border size="small" class="weight-table">
|
||||
<el-table-column
|
||||
label="点数(grid_number)"
|
||||
prop="grid_number"
|
||||
width="110"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="结束索引(id)"
|
||||
prop="id"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="实际中奖金额"
|
||||
prop="real_ev"
|
||||
width="90"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="显示文本"
|
||||
prop="ui_text"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
label="备注"
|
||||
prop="remark"
|
||||
min-width="70"
|
||||
align="center"
|
||||
show-overflow-tooltip
|
||||
/>
|
||||
<el-table-column
|
||||
:label="currentDirectionLabel + ' 权重(1-10000)'"
|
||||
min-width="200"
|
||||
align="center"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeightForCurrentDirection(row)"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="
|
||||
(v: number | number[]) =>
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1)
|
||||
)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) || getItemWeightForCurrentDirection(row) <= 1
|
||||
"
|
||||
@click="
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Math.max(1, getItemWeightForCurrentDirection(row) - 1)
|
||||
)
|
||||
"
|
||||
>-</el-button
|
||||
>
|
||||
<el-input-number
|
||||
:model-value="getItemWeightForCurrentDirection(row)"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="
|
||||
(v: number | string | undefined) =>
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1
|
||||
)
|
||||
"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="
|
||||
isWeightDisabled(row, t) ||
|
||||
getItemWeightForCurrentDirection(row) >= 10000
|
||||
"
|
||||
@click="
|
||||
setItemWeightForCurrentDirection(
|
||||
t,
|
||||
row,
|
||||
Math.min(10000, getItemWeightForCurrentDirection(row) + 1)
|
||||
)
|
||||
"
|
||||
>+</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward/index'
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const TIER_KEYS = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
|
||||
type DirectionKey = 'clockwise' | 'counterclockwise'
|
||||
|
||||
/** 当前方向下的行:reward_id=DiceReward 主键(用于提交更新),id=end_index 展示用,weight 为当前方向权重 */
|
||||
interface WeightRow {
|
||||
reward_id?: number
|
||||
id?: number
|
||||
grid_number?: number
|
||||
real_ev?: number
|
||||
ui_text?: string
|
||||
remark?: string
|
||||
weight: number
|
||||
}
|
||||
|
||||
/** 按档位、方向分组:tier -> { '0': 顺时针行列表, '1': 逆时针行列表 } */
|
||||
type GroupedByTierDirection = Record<string, { '0': WeightRow[]; '1': WeightRow[] }>
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
const activeDirection = ref<'0' | '1'>('0')
|
||||
const activeTier = ref('T1')
|
||||
const submitting = ref(false)
|
||||
const loading = ref(false)
|
||||
const grouped = ref<GroupedByTierDirection>({
|
||||
T1: { '0': [], '1': [] },
|
||||
T2: { '0': [], '1': [] },
|
||||
T3: { '0': [], '1': [] },
|
||||
T4: { '0': [], '1': [] },
|
||||
T5: { '0': [], '1': [] }
|
||||
})
|
||||
|
||||
const currentDirectionLabel = computed(() =>
|
||||
activeDirection.value === '0' ? '顺时针' : '逆时针'
|
||||
)
|
||||
|
||||
const tierKeys = TIER_KEYS
|
||||
|
||||
function getTierItems(tier: string): WeightRow[] {
|
||||
const dir = activeDirection.value
|
||||
const tierData = grouped.value[tier]
|
||||
if (!tierData || !tierData[dir]) return []
|
||||
return tierData[dir]
|
||||
}
|
||||
|
||||
function getTierChartLabels(tier: string): string[] {
|
||||
return getTierItems(tier).map((r) => String(r.grid_number ?? ''))
|
||||
}
|
||||
|
||||
function getTierChartDataForCurrentDirection(tier: string): number[] {
|
||||
return getTierItems(tier).map((r) => toWeightPrecision(r.weight ?? 1))
|
||||
}
|
||||
|
||||
function getTierSumForCurrentDirection(tier: string): number {
|
||||
return getTierItems(tier).reduce((s, r) => s + toWeightPrecision(r.weight ?? 1), 0)
|
||||
}
|
||||
|
||||
function getItemWeightForCurrentDirection(row: WeightRow): number {
|
||||
const w = row.weight
|
||||
const num = typeof w === 'number' && !Number.isNaN(w) ? w : Number(w)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return toWeightPrecision(num)
|
||||
}
|
||||
|
||||
function toWeightPrecision(value: number): number {
|
||||
return Math.max(1, Math.min(10000, Math.floor(value)))
|
||||
}
|
||||
|
||||
function setItemWeightForCurrentDirection(tier: string, row: WeightRow, value: number) {
|
||||
const v = toWeightPrecision(value)
|
||||
const dir = activeDirection.value
|
||||
const tierData = grouped.value[tier]
|
||||
if (!tierData || !tierData[dir]) return
|
||||
const list = tierData[dir]
|
||||
const rid = row.reward_id != null ? row.reward_id : undefined
|
||||
list.forEach((r) => {
|
||||
if (r === row || (rid != null && r.reward_id != null && r.reward_id === rid)) r.weight = v
|
||||
})
|
||||
grouped.value[tier][dir] = [...list]
|
||||
}
|
||||
|
||||
function isWeightDisabled(row: WeightRow, tier: string): boolean {
|
||||
if (tier === 'T4' || tier === 'T5') return true
|
||||
return false
|
||||
}
|
||||
|
||||
function normalizeWeightValue(v: unknown): number {
|
||||
const num = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return Math.max(1, Math.min(10000, Math.floor(num)))
|
||||
}
|
||||
|
||||
/** 兼容后端返回 tier -> { 0: [], 1: [] },每行含 reward_id, id(end_index), grid_number, ui_text, real_ev, remark, weight */
|
||||
function parsePayload(res: any): GroupedByTierDirection {
|
||||
const empty: GroupedByTierDirection = {
|
||||
T1: { '0': [], '1': [] },
|
||||
T2: { '0': [], '1': [] },
|
||||
T3: { '0': [], '1': [] },
|
||||
T4: { '0': [], '1': [] },
|
||||
T5: { '0': [], '1': [] }
|
||||
}
|
||||
if (!res || typeof res !== 'object') return empty
|
||||
const raw = res?.data ?? res
|
||||
if (!raw || typeof raw !== 'object') return empty
|
||||
const out = { ...empty }
|
||||
for (const t of TIER_KEYS) {
|
||||
const tierData = raw[t]
|
||||
if (!tierData || typeof tierData !== 'object') continue
|
||||
out[t] = {
|
||||
'0': Array.isArray(tierData[0])
|
||||
? tierData[0].map((r: any) => ({
|
||||
...r,
|
||||
reward_id: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
weight: normalizeWeightValue(r.weight)
|
||||
}))
|
||||
: [],
|
||||
'1': Array.isArray(tierData[1])
|
||||
? tierData[1].map((r: any) => ({
|
||||
...r,
|
||||
reward_id: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
weight: normalizeWeightValue(r.weight)
|
||||
}))
|
||||
: []
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function loadData() {
|
||||
loading.value = true
|
||||
api
|
||||
.weightRatioListWithDirection()
|
||||
.then((res: any) => {
|
||||
grouped.value = parsePayload(res)
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error('获取权重数据失败')
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
/** 按 DiceReward 主键 id 收集:每条记录一条 { id, reward_id, weight },后端按 id 更新(reward_id 作回退) */
|
||||
function collectItems(): Array<{ id: number; reward_id: number; weight: number }> {
|
||||
const items: Array<{ id: number; reward_id: number; weight: number }> = []
|
||||
for (const t of TIER_KEYS) {
|
||||
const tierData = grouped.value[t]
|
||||
if (!tierData) continue
|
||||
for (const dir of ['0', '1'] as const) {
|
||||
const list = tierData[dir] ?? []
|
||||
for (const row of list) {
|
||||
const rid = row.reward_id != null ? Number(row.reward_id) : 0
|
||||
if (rid <= 0) continue
|
||||
const w = isWeightDisabled(row, t) ? 10000 : toWeightPrecision(row.weight ?? 1)
|
||||
items.push({ id: rid, reward_id: rid, weight: w })
|
||||
}
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
const items = collectItems()
|
||||
if (items.length === 0) {
|
||||
ElMessage.info('没有可提交的配置')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.then(() => {
|
||||
ElMessage.success('保存成功')
|
||||
emit('success')
|
||||
handleClose()
|
||||
})
|
||||
.catch((e: { message?: string }) => {
|
||||
ElMessage.error(e?.message ?? '保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) {
|
||||
loadData()
|
||||
activeDirection.value = '0'
|
||||
activeTier.value = 'T1'
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.direction-tabs {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.tier-tabs {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.chart-wrap {
|
||||
margin-bottom: 12px;
|
||||
min-height: 200px;
|
||||
}
|
||||
.weight-sum {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.weight-sum-t4t5 {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.global-tip {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.weight-table {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.weight-cell-vertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.weight-slider-wrap {
|
||||
width: 100%;
|
||||
min-width: 80px;
|
||||
padding: 0 8px;
|
||||
.weight-slider {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.weight-input-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.dialog-body {
|
||||
min-height: 320px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,381 @@
|
||||
<template>
|
||||
<ElDialog
|
||||
v-model="visible"
|
||||
title="一键测试权重"
|
||||
width="560px"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@close="onClose"
|
||||
>
|
||||
<ElForm ref="formRef" :model="form" label-width="140px">
|
||||
<ElSteps :active="currentStep" finish-status="success" simple class="steps-wrap">
|
||||
<ElStep title="付费抽奖券" />
|
||||
<ElStep title="免费抽奖券" />
|
||||
</ElSteps>
|
||||
|
||||
<!-- 第一页:付费抽奖券 -->
|
||||
<div v-show="currentStep === 0" class="step-panel">
|
||||
<ElFormItem label="测试数据档位类型" prop="paid_lottery_config_id">
|
||||
<ElSelect
|
||||
v-model="form.paid_lottery_config_id"
|
||||
placeholder="不选则下方自定义档位概率(默认 type=0)"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in paidLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.paid_lottery_config_id == null">
|
||||
<div class="tier-label">自定义档位概率(T1~T5),每档 0-100%,五档之和不能超过 100%</div>
|
||||
<ElRow :gutter="12" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">档位 {{ t }}(%)</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getPaidTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setPaidTier(t, $event)"
|
||||
/>
|
||||
</div>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="paidTierSum > 100" class="tier-error"
|
||||
>当前五档之和为 {{ paidTierSum }}%,不能超过 100%</div
|
||||
>
|
||||
</template>
|
||||
<ElFormItem label="顺时针次数" prop="paid_s_count" required>
|
||||
<ElSelect v-model="form.paid_s_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="逆时针次数" prop="paid_n_count" required>
|
||||
<ElSelect v-model="form.paid_n_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
|
||||
<!-- 第二页:免费抽奖券 -->
|
||||
<div v-show="currentStep === 1" class="step-panel">
|
||||
<ElFormItem label="测试数据档位类型" prop="free_lottery_config_id">
|
||||
<ElSelect
|
||||
v-model="form.free_lottery_config_id"
|
||||
placeholder="不选则下方自定义档位概率(默认 type=1)"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in freeLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.free_lottery_config_id == null">
|
||||
<div class="tier-label">自定义档位概率(T1~T5),每档 0-100%,五档之和不能超过 100%</div>
|
||||
<ElRow :gutter="12" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">档位 {{ t }}(%)</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getFreeTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setFreeTier(t, $event)"
|
||||
/>
|
||||
</div>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="freeTierSum > 100" class="tier-error"
|
||||
>当前五档之和为 {{ freeTierSum }}%,不能超过 100%</div
|
||||
>
|
||||
</template>
|
||||
<ElFormItem label="顺时针次数" prop="free_s_count" required>
|
||||
<ElSelect v-model="form.free_s_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="逆时针次数" prop="free_n_count" required>
|
||||
<ElSelect v-model="form.free_n_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</ElForm>
|
||||
|
||||
<template #footer>
|
||||
<ElButton v-if="currentStep > 0" :disabled="running" @click="currentStep--">上一步</ElButton>
|
||||
<ElButton v-if="currentStep < 1" type="primary" :disabled="running" @click="currentStep++"
|
||||
>下一步</ElButton
|
||||
>
|
||||
<ElButton v-if="currentStep === 1" type="primary" :loading="running" @click="handleStart"
|
||||
>开始测试</ElButton
|
||||
>
|
||||
<ElButton :disabled="running" @click="visible = false">取消</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward/index'
|
||||
import lotteryPoolApi from '../../../api/lottery_pool_config/index'
|
||||
|
||||
const countOptions = [0, 100, 500, 1000, 5000]
|
||||
const tierKeys = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
|
||||
|
||||
const visible = defineModel<boolean>({ default: false })
|
||||
const emit = defineEmits<{ (e: 'success'): void }>()
|
||||
|
||||
const formRef = ref()
|
||||
const currentStep = ref(0)
|
||||
const form = reactive({
|
||||
paid_lottery_config_id: undefined as number | undefined,
|
||||
free_lottery_config_id: undefined as number | undefined,
|
||||
paid_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
|
||||
free_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
|
||||
paid_s_count: 100,
|
||||
paid_n_count: 100,
|
||||
free_s_count: 100,
|
||||
free_n_count: 100
|
||||
})
|
||||
const lotteryOptions = ref<Array<{ id: number; name: string; type: number }>>([])
|
||||
/** 将 type 转为数字(接口可能返回字符串 "0"/"1") */
|
||||
function tierTypeNum(r: { type?: number | string }): number {
|
||||
const t = r.type ?? 0
|
||||
return typeof t === 'number' ? t : Number(t) || 0
|
||||
}
|
||||
/** 付费抽奖券可选档位:type=0 */
|
||||
const paidLotteryOptions = computed(() =>
|
||||
lotteryOptions.value.filter((r) => tierTypeNum(r) === 0)
|
||||
)
|
||||
/**
|
||||
* 免费抽奖券可选档位:优先 type=1(DiceLotteryPoolConfig.type=1),若无则显示全部以便下拉有选项
|
||||
*/
|
||||
const freeLotteryOptions = computed(() => {
|
||||
const type1List = lotteryOptions.value.filter((r) => tierTypeNum(r) === 1)
|
||||
return type1List.length > 0 ? type1List : lotteryOptions.value
|
||||
})
|
||||
const running = ref(false)
|
||||
|
||||
function onClose() {
|
||||
running.value = false
|
||||
currentStep.value = 0
|
||||
}
|
||||
|
||||
function getPaidTier(t: string): string {
|
||||
const v = form.paid_tier_weights[t]
|
||||
return v !== undefined && v !== null ? String(v) : ''
|
||||
}
|
||||
function setPaidTier(t: string, val: string | Event) {
|
||||
const raw =
|
||||
typeof val === 'string'
|
||||
? val
|
||||
: ((val as Event & { target: HTMLInputElement }).target?.value ?? '')
|
||||
const num = raw === '' ? 0 : Math.max(0, Math.min(100, Number(raw) || 0))
|
||||
form.paid_tier_weights[t] = num
|
||||
}
|
||||
const paidTierSum = computed(() =>
|
||||
tierKeys.reduce((s, t) => s + (form.paid_tier_weights[t] ?? 0), 0)
|
||||
)
|
||||
function getFreeTier(t: string): string {
|
||||
const v = form.free_tier_weights[t]
|
||||
return v !== undefined && v !== null ? String(v) : ''
|
||||
}
|
||||
function setFreeTier(t: string, val: string | Event) {
|
||||
const raw =
|
||||
typeof val === 'string'
|
||||
? val
|
||||
: ((val as Event & { target: HTMLInputElement }).target?.value ?? '')
|
||||
const num = raw === '' ? 0 : Math.max(0, Math.min(100, Number(raw) || 0))
|
||||
form.free_tier_weights[t] = num
|
||||
}
|
||||
const freeTierSum = computed(() =>
|
||||
tierKeys.reduce((s, t) => s + (form.free_tier_weights[t] ?? 0), 0)
|
||||
)
|
||||
|
||||
async function loadLotteryOptions() {
|
||||
try {
|
||||
const list = await lotteryPoolApi.getOptions()
|
||||
lotteryOptions.value = list.map(
|
||||
(r: { id: number; name: string; type?: number | string }) => ({
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
type: tierTypeNum(r)
|
||||
})
|
||||
)
|
||||
// 付费抽奖券默认使用 type=0 的档位类型
|
||||
const type0 = list.find((r: { type?: number | string }) => tierTypeNum(r) === 0)
|
||||
if (type0) {
|
||||
form.paid_lottery_config_id = type0.id
|
||||
}
|
||||
// 免费抽奖券默认使用 type=1 的档位类型(DiceLotteryPoolConfig.type=1);若无 type=1 则默认选第一项
|
||||
const type1 = list.find((r: { type?: number | string }) => tierTypeNum(r) === 1)
|
||||
if (type1) {
|
||||
form.free_lottery_config_id = type1.id
|
||||
} else if (list.length > 0) {
|
||||
form.free_lottery_config_id = list[0].id
|
||||
}
|
||||
} catch (_) {
|
||||
lotteryOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function buildPayload() {
|
||||
const payload: Record<string, unknown> = {
|
||||
paid_s_count: form.paid_s_count,
|
||||
paid_n_count: form.paid_n_count,
|
||||
free_s_count: form.free_s_count,
|
||||
free_n_count: form.free_n_count
|
||||
}
|
||||
if (form.paid_lottery_config_id != null) {
|
||||
payload.paid_lottery_config_id = form.paid_lottery_config_id
|
||||
} else {
|
||||
payload.paid_tier_weights = { ...form.paid_tier_weights }
|
||||
}
|
||||
if (form.free_lottery_config_id != null) {
|
||||
payload.free_lottery_config_id = form.free_lottery_config_id
|
||||
} else {
|
||||
payload.free_tier_weights = { ...form.free_tier_weights }
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
function validateForm(): boolean {
|
||||
if (form.paid_s_count + form.paid_n_count + form.free_s_count + form.free_n_count <= 0) {
|
||||
ElMessage.warning('付费或免费至少一种方向次数之和大于 0')
|
||||
return false
|
||||
}
|
||||
const needPaidTier = form.paid_lottery_config_id == null
|
||||
const needFreeTier = form.free_lottery_config_id == null
|
||||
if (needPaidTier) {
|
||||
const sum = paidTierSum.value
|
||||
if (sum <= 0) {
|
||||
ElMessage.warning('付费未选奖池时,T1~T5 档位概率之和需大于 0')
|
||||
return false
|
||||
}
|
||||
if (sum > 100) {
|
||||
ElMessage.warning('付费档位概率 T1~T5 之和不能超过 100%')
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (needFreeTier) {
|
||||
const sum = freeTierSum.value
|
||||
if (sum <= 0) {
|
||||
ElMessage.warning('免费未选奖池时,T1~T5 档位概率之和需大于 0')
|
||||
return false
|
||||
}
|
||||
if (sum > 100) {
|
||||
ElMessage.warning('免费档位概率 T1~T5 之和不能超过 100%')
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function handleStart() {
|
||||
if (!validateForm()) return
|
||||
running.value = true
|
||||
try {
|
||||
await api.startWeightTest(buildPayload())
|
||||
ElMessage.success(
|
||||
'测试任务已创建,后台将自动执行。请在【玩家抽奖记录(测试数据)】中查看生成的测试数据'
|
||||
)
|
||||
visible.value = false
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '创建测试任务失败')
|
||||
} finally {
|
||||
running.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(visible, (v) => {
|
||||
if (v) {
|
||||
loadLotteryOptions()
|
||||
} else {
|
||||
onClose()
|
||||
}
|
||||
})
|
||||
|
||||
// 切换到免费步骤时,若当前选中 id 不在免费档位列表中,则重置为第一个 type=1 的选项,避免显示错误
|
||||
watch(currentStep, (step) => {
|
||||
if (step === 1) {
|
||||
const freeOpts = freeLotteryOptions.value
|
||||
const id = form.free_lottery_config_id
|
||||
if (freeOpts.length && (id == null || !freeOpts.some((o) => o.id === id))) {
|
||||
form.free_lottery_config_id = freeOpts[0].id
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.steps-wrap {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.step-panel {
|
||||
min-height: 200px;
|
||||
}
|
||||
.tier-label {
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.tier-row {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.tier-field {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.tier-field-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-regular);
|
||||
margin-bottom: 4px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.tier-input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: var(--el-text-color-regular);
|
||||
background-color: var(--el-fill-color-blank);
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.tier-input:hover {
|
||||
border-color: var(--el-border-color-hover);
|
||||
}
|
||||
.tier-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--el-color-primary);
|
||||
box-shadow: 0 0 0 2px var(--el-color-primary-light-7);
|
||||
}
|
||||
.tier-input::placeholder {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
.tier-error {
|
||||
font-size: 12px;
|
||||
color: var(--el-color-danger);
|
||||
margin-top: 4px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,142 +1,543 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
<div class="art-full-height reward-config-form">
|
||||
<ElCard shadow="never" class="form-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>游戏奖励配置</span>
|
||||
<ElButton
|
||||
v-permission="'dice:reward_config:index:update'"
|
||||
type="warning"
|
||||
:loading="createRewardLoading"
|
||||
@click="handleCreateRewardReference"
|
||||
v-ripple
|
||||
title="按规则:start_index=config(grid_number).id;顺时针 end_index=(start_index+grid_number)%26;逆时针 end_index=start_index-grid_number≥0?start_index-grid_number:26+start_index-grid_number"
|
||||
>
|
||||
创建奖励对照
|
||||
</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:reward_config:index:save'"
|
||||
@click="showDialog('add')"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:reward_config:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:reward_config:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:reward_config:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
<ElTabs v-model="activeTab" type="card" class="top-tabs">
|
||||
<ElTabPane label="奖励索引" name="index">
|
||||
<div class="tab-panel">
|
||||
<div class="panel-tip">色子点数须在 5~30 之间且本表内不重复。</div>
|
||||
<div class="table-scroll-wrap">
|
||||
<ElTable
|
||||
v-loading="loading"
|
||||
:data="indexRowsExcludeBigwin"
|
||||
border
|
||||
size="default"
|
||||
class="config-table"
|
||||
>
|
||||
<ElTableColumn label="索引(id)" prop="id" width="60" align="center">
|
||||
<template #default="{ row }">
|
||||
<span>{{ row.id }}</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="色子点数" min-width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInputNumber
|
||||
v-model="row.grid_number"
|
||||
:min="5"
|
||||
:max="30"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="full-width"
|
||||
/>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="显示文本" min-width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.ui_text" size="small" placeholder="显示文本(中文)" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="显示文本(英文)" min-width="120" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.ui_text_en" size="small" placeholder="显示文本(英文)" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="真实结算" min-width="110" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInputNumber
|
||||
v-model="row.real_ev"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="full-width"
|
||||
/>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="所属档位" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElSelect
|
||||
v-model="row.tier"
|
||||
placeholder="档位"
|
||||
clearable
|
||||
size="small"
|
||||
class="full-width"
|
||||
>
|
||||
<ElOption label="T1" value="T1" />
|
||||
<ElOption label="T2" value="T2" />
|
||||
<ElOption label="T3" value="T3" />
|
||||
<ElOption label="T4" value="T4" />
|
||||
<ElOption label="T5" value="T5" />
|
||||
</ElSelect>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="备注" min-width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.remark" size="small" placeholder="备注" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
<div class="tab-footer">
|
||||
<ElButton type="primary" :loading="savingIndex" @click="handleSaveIndex"
|
||||
>保存</ElButton
|
||||
>
|
||||
<ElButton @click="handleResetIndex">重置</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElTabPane>
|
||||
<ElTabPane label="大奖权重" name="bigwin">
|
||||
<div class="tab-panel">
|
||||
<div class="panel-tip"
|
||||
>从左至右:中大奖点数(不可改)、显示信息、实际中奖、备注、权重(0~10000)。点数 5、30
|
||||
权重固定 100%。本表单独立提交,仅提交大奖权重。</div
|
||||
>
|
||||
<div class="table-scroll-wrap">
|
||||
<ElTable
|
||||
v-loading="loading"
|
||||
:data="bigwinRows"
|
||||
border
|
||||
size="default"
|
||||
class="config-table bigwin-table"
|
||||
>
|
||||
<ElTableColumn label="中大奖点数" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<span class="readonly-value">{{ row.grid_number }}</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="显示信息" min-width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.ui_text" size="small" placeholder="显示信息(中文)" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="显示信息(英文)" min-width="160" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.ui_text_en" size="small" placeholder="显示信息(英文)" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="实际中奖" min-width="120" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInputNumber
|
||||
v-model="row.real_ev"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="full-width"
|
||||
/>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="备注" min-width="140" align="center">
|
||||
<template #default="{ row }">
|
||||
<ElInput v-model="row.remark" size="small" placeholder="备注" />
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="权重(0-10000)" min-width="220" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell">
|
||||
<ElSlider
|
||||
v-model="row.weight"
|
||||
:min="0"
|
||||
:max="10000"
|
||||
:step="100"
|
||||
:disabled="isBigwinWeightDisabled(row)"
|
||||
/>
|
||||
<ElInputNumber
|
||||
v-model="row.weight"
|
||||
:min="0"
|
||||
:max="10000"
|
||||
:step="100"
|
||||
:disabled="isBigwinWeightDisabled(row)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
/>
|
||||
</div>
|
||||
<span v-if="isBigwinWeightDisabled(row)" class="weight-tip"
|
||||
>点数 5、30 固定 100%</span
|
||||
>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
</div>
|
||||
<div v-if="bigwinRows.length === 0 && !loading" class="empty-tip">
|
||||
暂无 BIGWIN 档位配置,请在「奖励索引」中设置 tier 为 BIGWIN。
|
||||
</div>
|
||||
<div class="tab-footer">
|
||||
<ElButton type="primary" :loading="savingBigwin" @click="handleSaveBigwin"
|
||||
>保存</ElButton
|
||||
>
|
||||
<ElButton @click="handleResetBigwin">重置</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</ElTabPane>
|
||||
</ElTabs>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import api from '../../api/reward_config/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
grid_number_min: undefined,
|
||||
grid_number_max: undefined,
|
||||
ui_text: undefined,
|
||||
real_ev_min: undefined,
|
||||
real_ev_max: undefined,
|
||||
tier: undefined
|
||||
})
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
/** 第一页:奖励索引行(来自 DiceRewardConfig 表) */
|
||||
interface IndexRow {
|
||||
id: number
|
||||
grid_number: number
|
||||
ui_text: string
|
||||
ui_text_en: string
|
||||
real_ev: number
|
||||
tier: string
|
||||
remark: string
|
||||
weight: number
|
||||
}
|
||||
|
||||
// 表格配置(默认 100 条/页)
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiParams: { limit: 100 },
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID(索引)', width: 80 },
|
||||
{ prop: 'grid_number', label: '色子点数' },
|
||||
{ prop: 'ui_text', label: '前端显示文本' },
|
||||
{ prop: 'real_ev', label: '真实资金结算' },
|
||||
{ prop: 'tier', label: '所属档位', sortable: true },
|
||||
// { prop: 'create_time', label: '创建时间', sortable: true },
|
||||
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||
]
|
||||
}
|
||||
})
|
||||
const activeTab = ref<'index' | 'bigwin'>('index')
|
||||
const loading = ref(false)
|
||||
const savingIndex = ref(false)
|
||||
const savingBigwin = ref(false)
|
||||
const createRewardLoading = ref(false)
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
/** 第一页数据(来自 api.list,即 DiceRewardConfig 表) */
|
||||
const indexRows = ref<IndexRow[]>([])
|
||||
/** 奖励索引 Tab:排除 tier=BIGWIN,仅显示 T1~T5 */
|
||||
const indexRowsExcludeBigwin = computed(() => indexRows.value.filter((r) => r.tier !== 'BIGWIN'))
|
||||
/** 第二页 BIGWIN 数据:来自同一张表 DiceRewardConfig,过滤 tier===BIGWIN */
|
||||
const bigwinRows = computed(() => indexRows.value.filter((r) => r.tier === 'BIGWIN'))
|
||||
/** 原始 list 快照,用于重置 */
|
||||
let indexRowsSnapshot: IndexRow[] = []
|
||||
|
||||
function toWeight(v: unknown): number {
|
||||
const n = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
|
||||
if (Number.isNaN(n)) return 0
|
||||
return Math.max(0, Math.min(10000, Math.floor(n)))
|
||||
}
|
||||
|
||||
function normalizeIndexRow(raw: Record<string, unknown>): IndexRow {
|
||||
return {
|
||||
id: Number(raw.id) ?? 0,
|
||||
grid_number: Number(raw.grid_number) ?? 0,
|
||||
ui_text: String(raw.ui_text ?? ''),
|
||||
ui_text_en: String((raw as any).ui_text_en ?? ''),
|
||||
real_ev: Number(raw.real_ev) ?? 0,
|
||||
tier: String(raw.tier ?? ''),
|
||||
remark: String(raw.remark ?? ''),
|
||||
weight: toWeight((raw as any).weight)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateRewardReference() {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'按规则创建奖励对照:起始索引 start_index=奖励配置中 grid_number 对应格位的 id;顺时针 end_index=(start_index+摇取点数)%26;逆时针 end_index=start_index-摇取点数≥0 则取该值,否则 26+start_index-摇取点数。先清空现有数据再为 5-30 共 26 个点数、顺/逆时针分别生成。是否继续?',
|
||||
'创建奖励对照',
|
||||
{
|
||||
confirmButtonText: '确定创建',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
createRewardLoading.value = true
|
||||
try {
|
||||
const res: any = await api.createRewardReference()
|
||||
const data = res?.data ?? res
|
||||
const msg =
|
||||
typeof data === 'object' && data !== null
|
||||
? `已按 5-30 共26个点数、顺时针+逆时针创建:顺时针新增 ${data.created_clockwise ?? 0} 条、逆时针新增 ${data.created_counterclockwise ?? 0} 条;顺时针更新 ${data.updated_clockwise ?? 0} 条、逆时针更新 ${data.updated_counterclockwise ?? 0} 条${(data.skipped ?? 0) > 0 ? `;${data.skipped} 个点数使用兜底起始索引` : ''}`
|
||||
: '创建成功'
|
||||
ElMessage.success(msg)
|
||||
loadIndexList()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '创建奖励对照失败')
|
||||
} finally {
|
||||
createRewardLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function loadIndexList() {
|
||||
loading.value = true
|
||||
return api
|
||||
.list({ limit: 200 })
|
||||
.then((res: any) => {
|
||||
const list = res?.data?.records ?? res?.records ?? res?.data ?? []
|
||||
const rows = Array.isArray(list)
|
||||
? list.map((r: Record<string, unknown>) => normalizeIndexRow(r))
|
||||
: []
|
||||
indexRows.value = rows
|
||||
indexRowsSnapshot = rows.map((r) => ({ ...r }))
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error('获取奖励索引配置失败')
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function isBigwinWeightDisabled(row: IndexRow): boolean {
|
||||
return row.grid_number === 5 || row.grid_number === 30
|
||||
}
|
||||
|
||||
const GRID_NUMBER_MIN = 5
|
||||
const GRID_NUMBER_MAX = 30
|
||||
|
||||
/** 找出数组中出现多于一次的值 */
|
||||
function findDuplicateValues(arr: number[]): number[] {
|
||||
const count = new Map<number, number>()
|
||||
for (const v of arr) {
|
||||
count.set(v, (count.get(v) ?? 0) + 1)
|
||||
}
|
||||
const duplicates: number[] = []
|
||||
count.forEach((c, v) => {
|
||||
if (c > 1) duplicates.push(v)
|
||||
})
|
||||
return duplicates.sort((a, b) => a - b)
|
||||
}
|
||||
|
||||
/** 奖励索引表单校验:仅对本表内的行(不含 BIGWIN)校验,点数 5~30 且本批内不重复 */
|
||||
function validateIndexFormForSave(): string | null {
|
||||
const toSave = indexRows.value.filter((r) => r.tier !== 'BIGWIN')
|
||||
if (toSave.length === 0) {
|
||||
return '暂无奖励索引数据可保存'
|
||||
}
|
||||
const nums = toSave.map((r) => Number(r.grid_number))
|
||||
const outOfRange = nums.filter(
|
||||
(n) => Number.isNaN(n) || n < GRID_NUMBER_MIN || n > GRID_NUMBER_MAX
|
||||
)
|
||||
if (outOfRange.length > 0) {
|
||||
return `色子点数必须在 ${GRID_NUMBER_MIN}~${GRID_NUMBER_MAX} 之间`
|
||||
}
|
||||
const duplicates = findDuplicateValues(nums)
|
||||
if (duplicates.length > 0) {
|
||||
return `色子点数在本表内不能重复,重复的点数为:${duplicates.join('、')}`
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** 奖励索引表单:仅提交本表数据(T1~T5),不包含大奖权重 */
|
||||
async function handleSaveIndex() {
|
||||
const err = validateIndexFormForSave()
|
||||
if (err) {
|
||||
ElMessage.warning(err)
|
||||
return
|
||||
}
|
||||
const toSave = indexRows.value.filter((r) => r.tier !== 'BIGWIN')
|
||||
savingIndex.value = true
|
||||
try {
|
||||
const indexPayload = toSave.map((r) => ({
|
||||
id: r.id,
|
||||
grid_number: r.grid_number,
|
||||
ui_text: r.ui_text,
|
||||
ui_text_en: r.ui_text_en,
|
||||
real_ev: r.real_ev,
|
||||
tier: r.tier,
|
||||
remark: r.remark
|
||||
}))
|
||||
await api.batchUpdate(indexPayload)
|
||||
ElMessage.success('保存成功')
|
||||
indexRowsSnapshot = indexRows.value.map((r) => ({ ...r }))
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '保存失败')
|
||||
} finally {
|
||||
savingIndex.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 奖励索引页:重置为本页数据(重新拉取列表) */
|
||||
function handleResetIndex() {
|
||||
loadIndexList()
|
||||
ElMessage.info('已重新加载奖励索引,恢复为服务器最新数据')
|
||||
}
|
||||
|
||||
/** 大奖权重表单校验:点数在本表内不重复 */
|
||||
function validateBigwinFormForSave(): string | null {
|
||||
const rows = bigwinRows.value
|
||||
if (rows.length === 0) {
|
||||
return '暂无 BIGWIN 档位配置可保存'
|
||||
}
|
||||
const nums = rows.map((r) => Number(r.grid_number))
|
||||
const outOfRange = nums.filter(
|
||||
(n) => Number.isNaN(n) || n < GRID_NUMBER_MIN || n > GRID_NUMBER_MAX
|
||||
)
|
||||
if (outOfRange.length > 0) {
|
||||
return `色子点数必须在 ${GRID_NUMBER_MIN}~${GRID_NUMBER_MAX} 之间`
|
||||
}
|
||||
const duplicates = findDuplicateValues(nums)
|
||||
if (duplicates.length > 0) {
|
||||
return `大奖权重本表内点数不能重复,重复的点数为:${duplicates.join('、')}`
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** 大奖权重表单:提交 BIGWIN 的显示信息、英文、实际中奖、备注 + 权重(保存后后端会刷新缓存) */
|
||||
async function handleSaveBigwin() {
|
||||
const rows = bigwinRows.value
|
||||
if (rows.length === 0) {
|
||||
ElMessage.info('暂无 BIGWIN 档位配置,请先在「奖励索引」中设置 tier 为 BIGWIN')
|
||||
return
|
||||
}
|
||||
const err = validateBigwinFormForSave()
|
||||
if (err) {
|
||||
ElMessage.warning(err)
|
||||
return
|
||||
}
|
||||
savingBigwin.value = true
|
||||
try {
|
||||
const batchPayload = rows.map((r) => ({
|
||||
id: r.id,
|
||||
grid_number: r.grid_number,
|
||||
ui_text: r.ui_text,
|
||||
ui_text_en: r.ui_text_en,
|
||||
real_ev: r.real_ev,
|
||||
tier: r.tier,
|
||||
remark: r.remark
|
||||
}))
|
||||
await api.batchUpdate(batchPayload)
|
||||
const weightItems = rows.map((r) => ({
|
||||
grid_number: r.grid_number,
|
||||
weight: isBigwinWeightDisabled(r)
|
||||
? 10000
|
||||
: Math.max(0, Math.min(10000, Math.floor(r.weight)))
|
||||
}))
|
||||
await api.saveBigwinWeightsByGrid(weightItems)
|
||||
ElMessage.success('保存成功')
|
||||
loadIndexList()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '保存失败')
|
||||
} finally {
|
||||
savingBigwin.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 大奖权重页:重置(重新拉取列表,BIGWIN 数据随之更新) */
|
||||
function handleResetBigwin() {
|
||||
loadIndexList()
|
||||
ElMessage.info('已重新加载,大奖权重恢复为服务器最新数据')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadIndexList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.reward-config-form {
|
||||
padding: 16px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.form-card {
|
||||
margin-bottom: 16px;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
:deep(.el-card__body) {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.top-tabs {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
:deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
:deep(.el-tab-pane) {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
.tab-panel {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.table-scroll-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.tab-footer {
|
||||
flex-shrink: 0;
|
||||
margin-top: 12px;
|
||||
padding: 12px 0;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
background: var(--el-bg-color);
|
||||
}
|
||||
.panel-tip {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-bottom: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.config-table {
|
||||
width: 100%;
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.weight-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 0 8px;
|
||||
.el-slider {
|
||||
flex: 1;
|
||||
}
|
||||
.weight-input {
|
||||
width: 120px;
|
||||
}
|
||||
}
|
||||
.weight-tip {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.readonly-value {
|
||||
font-weight: 500;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
.bigwin-table .full-width {
|
||||
width: 100%;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -9,10 +9,17 @@
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="色子点数" prop="grid_number">
|
||||
<el-input-number v-model="formData.grid_number" placeholder="请输入色子点数" />
|
||||
<el-input-number
|
||||
v-model="formData.grid_number"
|
||||
placeholder="请输入色子点数"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="前端显示文本" prop="ui_text">
|
||||
<el-input v-model="formData.ui_text" placeholder="请输入前端显示文本" />
|
||||
<el-input v-model="formData.ui_text" placeholder="请输入前端显示文本(中文)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="前端显示文本(英文)" prop="ui_text_en">
|
||||
<el-input v-model="formData.ui_text_en" placeholder="请输入前端显示文本(英文)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="真实资金结算" prop="real_ev">
|
||||
<el-input-number v-model="formData.real_ev" placeholder="请输入真实资金结算" />
|
||||
@@ -23,14 +30,32 @@
|
||||
placeholder="请选择所属档位"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
>
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
<el-option label="BIGWIN(超级大奖)" value="BIGWIN" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- BIGWIN 时可编辑权重:10000=100% 中奖,0=0% 中奖;点数 5、30 固定 100% 不可改 -->
|
||||
<el-form-item v-if="formData.tier === 'BIGWIN'" label="大奖权重" prop="weight">
|
||||
<el-input-number
|
||||
v-model="formData.weight"
|
||||
:min="0"
|
||||
:max="10000"
|
||||
:step="100"
|
||||
placeholder="0~10000,10000=100%中奖"
|
||||
:disabled="isBigwinWeightDisabled"
|
||||
/>
|
||||
<div v-if="isBigwinWeightDisabled" class="form-tip">
|
||||
点数 5、30 摇到必中大奖,权重固定 10000
|
||||
</div>
|
||||
<div v-else class="form-tip">10000=100% 中奖,0=0% 中奖;仅对点数 10/15/20/25 生效</div>
|
||||
</el-form-item>
|
||||
<!-- 权重已迁移至「T1-T5 与 BIGWIN 权重配比」弹窗(dice_reward 表);BIGWIN 时本弹窗可编辑 weight;起始索引已迁移至 dice_reward.start_index -->
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
v-model="formData.remark"
|
||||
@@ -84,15 +109,22 @@
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
* 表单验证规则(权重已迁移至权重配比弹窗)
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
grid_number: [{ required: true, message: '色子点数必需填写', trigger: 'blur' }],
|
||||
ui_text: [{ required: true, message: '前端显示文本必需填写', trigger: 'blur' }],
|
||||
ui_text_en: [{ max: 255, message: '前端显示文本(英文)长度需小于 255 字符', trigger: 'blur' }],
|
||||
real_ev: [{ required: true, message: '真实资金结算必需填写', trigger: 'blur' }],
|
||||
tier: [{ required: true, message: '所属档位必需填写', trigger: 'blur' }]
|
||||
tier: [{ required: true, message: '所属档位必需填写', trigger: 'blur' }],
|
||||
weight: [{ type: 'number', min: 0, max: 10000, message: '大奖权重 0~10000', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/** 点数 5、30 固定 100% 中大奖,权重不可改 */
|
||||
const isBigwinWeightDisabled = computed(
|
||||
() => formData.tier === 'BIGWIN' && [5, 30].includes(Number(formData.grid_number))
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
@@ -100,9 +132,11 @@
|
||||
id: null,
|
||||
grid_number: null,
|
||||
ui_text: '',
|
||||
ui_text_en: '',
|
||||
real_ev: '',
|
||||
tier: '',
|
||||
remark: ''
|
||||
remark: '',
|
||||
weight: 10000 as number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,16 +170,32 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
* 初始化表单数据(数值字段转为 number,便于滑块/输入框正确回显)
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
if (props.data[key] != null && props.data[key] != undefined) {
|
||||
;(formData as any)[key] = props.data[key]
|
||||
}
|
||||
if (!props.data) return
|
||||
const numKeys = ['id', 'grid_number', 'real_ev', 'weight']
|
||||
for (const key of Object.keys(formData)) {
|
||||
if (!(key in props.data)) continue
|
||||
const val = props.data[key]
|
||||
if (val == null || val === undefined) continue
|
||||
if (numKeys.includes(key)) {
|
||||
const numVal = Number(val)
|
||||
;(formData as Record<string, unknown>)[key] =
|
||||
key === 'id'
|
||||
? numVal || null
|
||||
: Number.isNaN(numVal)
|
||||
? key === 'weight'
|
||||
? 10000
|
||||
: 0
|
||||
: numVal
|
||||
} else {
|
||||
;(formData as Record<string, unknown>)[key] = val ?? ''
|
||||
}
|
||||
}
|
||||
if (formData.tier === 'BIGWIN' && (formData.weight === undefined || formData.weight === null)) {
|
||||
formData.weight = [5, 30].includes(Number(formData.grid_number)) ? 10000 : 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,11 +213,18 @@
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
const payload = { ...formData } as Record<string, unknown>
|
||||
if (formData.tier === 'BIGWIN') {
|
||||
const w = Number(formData.weight)
|
||||
payload.weight = isBigwinWeightDisabled.value ? 10000 : Number.isNaN(w) ? 10000 : w
|
||||
} else {
|
||||
delete payload.weight
|
||||
}
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(payload)
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
emit('success')
|
||||
@@ -177,3 +234,11 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="T1-T5 权重配比(顺时针/逆时针)"
|
||||
width="900px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<div class="global-tip">
|
||||
权重来自<strong>奖励对照表(dice_reward)</strong>,按<strong>结束索引(DiceRewardConfig.id)</strong>区分<strong>顺时针</strong>与<strong>逆时针</strong>两套权重;抽奖时按当前方向取对应权重。
|
||||
</div>
|
||||
<el-tabs v-model="activeTier" type="card">
|
||||
<el-tab-pane v-for="t in tierKeys" :key="t" :label="t" :name="t">
|
||||
<div v-if="getTierItems(t).length === 0" class="empty-tip"> 该档位暂无配置数据 </div>
|
||||
<template v-else>
|
||||
<div class="chart-wrap" v-if="t !== 'T4' && t !== 'T5'">
|
||||
<div class="chart-row">
|
||||
<ArtBarChart
|
||||
x-axis-name="结束索引"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartData(t, 'clockwise')"
|
||||
height="180px"
|
||||
/>
|
||||
<ArtBarChart
|
||||
x-axis-name="结束索引"
|
||||
:x-axis-data="getTierChartLabels(t)"
|
||||
:data="getTierChartData(t, 'counterclockwise')"
|
||||
height="180px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="weight-sum" v-if="t !== 'T4' && t !== 'T5'">
|
||||
当前档位权重合计(顺时针):<strong>{{ getTierSumForValidation(t, 'clockwise') }}</strong>
|
||||
;逆时针:<strong>{{ getTierSumForValidation(t, 'counterclockwise') }}</strong>
|
||||
(各条 1-10000,档位内按权重比抽取,和不限制)
|
||||
</div>
|
||||
<div class="weight-sum weight-sum-t4t5" v-else>
|
||||
T4、T5 档位抽中时仅有一个结果,无需配置权重。
|
||||
</div>
|
||||
<el-table :data="getTierItems(t)" border size="small" class="weight-table">
|
||||
<el-table-column label="结束索引(id)" prop="id" width="90" align="center" show-overflow-tooltip />
|
||||
<el-table-column label="色子点数" prop="grid_number" width="80" align="center" />
|
||||
<el-table-column label="实际中奖金额" prop="real_ev" width="90" align="center" show-overflow-tooltip />
|
||||
<el-table-column label="显示文本" prop="ui_text" min-width="70" align="center" show-overflow-tooltip />
|
||||
<el-table-column label="备注" prop="remark" min-width="70" align="center" show-overflow-tooltip />
|
||||
<el-table-column label="顺时针权重(1-10000)" min-width="160" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeight(row, 'clockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="(v: number | number[]) => setItemWeightByRow(t, row, 'clockwise', Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1))"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isWeightDisabled(row, t) || getItemWeight(row, 'clockwise') <= 1"
|
||||
@click="setItemWeightByRow(t, row, 'clockwise', Math.max(1, getItemWeight(row, 'clockwise') - 1))"
|
||||
>-</el-button>
|
||||
<el-input-number
|
||||
:model-value="getItemWeight(row, 'clockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="(v: number | string | undefined) => setItemWeightByRow(t, row, 'clockwise', typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1)"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isWeightDisabled(row, t) || getItemWeight(row, 'clockwise') >= 10000"
|
||||
@click="setItemWeightByRow(t, row, 'clockwise', Math.min(10000, getItemWeight(row, 'clockwise') + 1))"
|
||||
>+</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="逆时针权重(1-10000)" min-width="160" align="center">
|
||||
<template #default="{ row }">
|
||||
<div class="weight-cell-vertical">
|
||||
<div class="weight-slider-wrap">
|
||||
<el-slider
|
||||
:model-value="getItemWeight(row, 'counterclockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
size="small"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
class="weight-slider"
|
||||
@update:model-value="(v: number | number[]) => setItemWeightByRow(t, row, 'counterclockwise', Array.isArray(v) ? (v[0] ?? 1) : (v ?? 1))"
|
||||
/>
|
||||
</div>
|
||||
<div class="weight-input-wrap">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isWeightDisabled(row, t) || getItemWeight(row, 'counterclockwise') <= 1"
|
||||
@click="setItemWeightByRow(t, row, 'counterclockwise', Math.max(1, getItemWeight(row, 'counterclockwise') - 1))"
|
||||
>-</el-button>
|
||||
<el-input-number
|
||||
:model-value="getItemWeight(row, 'counterclockwise')"
|
||||
:min="1"
|
||||
:max="10000"
|
||||
:step="1"
|
||||
:disabled="isWeightDisabled(row, t)"
|
||||
controls-position="right"
|
||||
size="small"
|
||||
class="weight-input"
|
||||
@update:model-value="(v: number | string | undefined) => setItemWeightByRow(t, row, 'counterclockwise', typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) || 1)"
|
||||
/>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isWeightDisabled(row, t) || getItemWeight(row, 'counterclockwise') >= 10000"
|
||||
@click="setItemWeightByRow(t, row, 'counterclockwise', Math.min(10000, getItemWeight(row, 'counterclockwise') + 1))"
|
||||
>+</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward_config/index'
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const TIER_KEYS = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
|
||||
type DirectionKey = 'clockwise' | 'counterclockwise'
|
||||
|
||||
interface WeightRow {
|
||||
reward_id_clockwise?: number
|
||||
reward_id_counterclockwise?: number
|
||||
id?: number
|
||||
grid_number?: number
|
||||
real_ev?: number
|
||||
ui_text?: string
|
||||
remark?: string
|
||||
tier?: string
|
||||
weight_clockwise: number
|
||||
weight_counterclockwise: number
|
||||
}
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
const tierKeys = TIER_KEYS
|
||||
const activeTier = ref('T1')
|
||||
const submitting = ref(false)
|
||||
|
||||
const grouped = ref<Record<string, WeightRow[]>>({
|
||||
T1: [],
|
||||
T2: [],
|
||||
T3: [],
|
||||
T4: [],
|
||||
T5: []
|
||||
})
|
||||
|
||||
function getTierItems(tier: string): WeightRow[] {
|
||||
return grouped.value[tier] ?? []
|
||||
}
|
||||
|
||||
function getTierChartLabels(tier: string): string[] {
|
||||
return getTierItems(tier).map((r) => String(r.grid_number ?? ''))
|
||||
}
|
||||
|
||||
function getTierChartData(tier: string, dir: DirectionKey): number[] {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
return getTierItems(tier).map((r) => toWeightPrecision(r[key] ?? 1))
|
||||
}
|
||||
|
||||
function getTierSumForValidation(tier: string, dir: DirectionKey): number {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
return getTierItems(tier).reduce((s, r) => s + toWeightPrecision(r[key] ?? 1), 0)
|
||||
}
|
||||
|
||||
function getItemWeight(row: WeightRow, dir: DirectionKey): number {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
const w = row[key]
|
||||
const num = typeof w === 'number' && !Number.isNaN(w) ? w : Number(w)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return toWeightPrecision(num)
|
||||
}
|
||||
|
||||
function toWeightPrecision(value: number): number {
|
||||
const n = Math.max(1, Math.min(10000, Math.floor(value)))
|
||||
return n
|
||||
}
|
||||
|
||||
function setItemWeightByRow(tier: string, row: WeightRow, dir: DirectionKey, value: number) {
|
||||
const v = toWeightPrecision(value)
|
||||
const list = grouped.value[tier]
|
||||
if (!list) return
|
||||
const rid = dir === 'clockwise' ? row.reward_id_clockwise : row.reward_id_counterclockwise
|
||||
const idx = list.findIndex(
|
||||
(r) =>
|
||||
r === row ||
|
||||
(rid != null && (dir === 'clockwise' ? r.reward_id_clockwise : r.reward_id_counterclockwise) === rid)
|
||||
)
|
||||
if (idx >= 0) {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
list[idx][key] = v
|
||||
} else {
|
||||
const key = dir === 'clockwise' ? 'weight_clockwise' : 'weight_counterclockwise'
|
||||
row[key] = v
|
||||
}
|
||||
}
|
||||
|
||||
function isWeightDisabled(row: WeightRow, tier: string): boolean {
|
||||
if (tier === 'T4' || tier === 'T5') return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 解析 tier -> { 0: [], 1: [] },按 grid_number 合并为每档位一行,含 reward_id 与双方向权重 */
|
||||
function parseWeightRatioPayload(res: any): Record<string, WeightRow[]> {
|
||||
const empty: Record<string, WeightRow[]> = {
|
||||
T1: [],
|
||||
T2: [],
|
||||
T3: [],
|
||||
T4: [],
|
||||
T5: []
|
||||
}
|
||||
if (!res || typeof res !== 'object') return empty
|
||||
const raw = res?.data ?? res
|
||||
if (!raw || typeof raw !== 'object') return empty
|
||||
const out = { ...empty }
|
||||
for (const t of TIER_KEYS) {
|
||||
const tierData = raw[t]
|
||||
if (!tierData || typeof tierData !== 'object') continue
|
||||
const list0 = Array.isArray(tierData[0]) ? tierData[0] : []
|
||||
const list1 = Array.isArray(tierData[1]) ? tierData[1] : []
|
||||
const byGrid = new Map<
|
||||
number,
|
||||
{
|
||||
reward_id_clockwise?: number
|
||||
reward_id_counterclockwise?: number
|
||||
id?: number
|
||||
grid_number?: number
|
||||
real_ev?: number
|
||||
ui_text?: string
|
||||
remark?: string
|
||||
weight_clockwise: number
|
||||
weight_counterclockwise: number
|
||||
}
|
||||
>()
|
||||
for (const r of list0) {
|
||||
const gn = r.grid_number != null ? Number(r.grid_number) : NaN
|
||||
if (!Number.isNaN(gn)) {
|
||||
byGrid.set(gn, {
|
||||
reward_id_clockwise: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
id: r.id != null ? Number(r.id) : undefined,
|
||||
grid_number: gn,
|
||||
real_ev: r.real_ev != null ? Number(r.real_ev) : undefined,
|
||||
ui_text: r.ui_text,
|
||||
remark: r.remark,
|
||||
weight_clockwise: normalizeWeightValue(r.weight),
|
||||
weight_counterclockwise: 1
|
||||
})
|
||||
}
|
||||
}
|
||||
for (const r of list1) {
|
||||
const gn = r.grid_number != null ? Number(r.grid_number) : NaN
|
||||
if (!Number.isNaN(gn)) {
|
||||
const cur = byGrid.get(gn)
|
||||
if (cur) {
|
||||
cur.reward_id_counterclockwise = r.reward_id != null ? Number(r.reward_id) : undefined
|
||||
cur.weight_counterclockwise = normalizeWeightValue(r.weight)
|
||||
} else {
|
||||
byGrid.set(gn, {
|
||||
reward_id_counterclockwise: r.reward_id != null ? Number(r.reward_id) : undefined,
|
||||
id: r.id != null ? Number(r.id) : undefined,
|
||||
grid_number: gn,
|
||||
real_ev: r.real_ev != null ? Number(r.real_ev) : undefined,
|
||||
ui_text: r.ui_text,
|
||||
remark: r.remark,
|
||||
weight_clockwise: 1,
|
||||
weight_counterclockwise: normalizeWeightValue(r.weight)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
out[t] = Array.from(byGrid.values())
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function normalizeWeightValue(v: unknown): number {
|
||||
const num = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
|
||||
if (Number.isNaN(num)) return 1
|
||||
return Math.max(1, Math.min(10000, Math.floor(num)))
|
||||
}
|
||||
|
||||
function loadData() {
|
||||
api
|
||||
.weightRatioList()
|
||||
.then((res: any) => {
|
||||
grouped.value = parseWeightRatioPayload(res)
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error('获取权重配比数据失败')
|
||||
})
|
||||
}
|
||||
|
||||
/** 按 DiceReward 主键 id 收集:每条记录一条 { id, weight } */
|
||||
function collectItems(): Array<{ id: number; weight: number }> {
|
||||
const items: Array<{ id: number; weight: number }> = []
|
||||
for (const t of TIER_KEYS) {
|
||||
for (const row of getTierItems(t)) {
|
||||
const w0 = isWeightDisabled(row, t) ? 10000 : getItemWeight(row, 'clockwise')
|
||||
const w1 = isWeightDisabled(row, t) ? 10000 : getItemWeight(row, 'counterclockwise')
|
||||
const rid0 = row.reward_id_clockwise != null ? row.reward_id_clockwise : 0
|
||||
const rid1 = row.reward_id_counterclockwise != null ? row.reward_id_counterclockwise : 0
|
||||
if (rid0 > 0) items.push({ id: rid0, weight: w0 })
|
||||
if (rid1 > 0) items.push({ id: rid1, weight: w1 })
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
const items = collectItems()
|
||||
if (items.length === 0) {
|
||||
ElMessage.info('没有可提交的配置')
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.then(() => {
|
||||
ElMessage.success('保存成功')
|
||||
emit('success')
|
||||
handleClose()
|
||||
})
|
||||
.catch((e: { message?: string }) => {
|
||||
ElMessage.error(e?.message ?? '保存失败')
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) {
|
||||
loadData()
|
||||
activeTier.value = 'T1'
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.chart-wrap {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.chart-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
> * {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
}
|
||||
.weight-sum {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.weight-sum-t4t5 {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.global-tip {
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-regular);
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 6px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.weight-table {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.weight-cell-vertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.weight-slider-wrap {
|
||||
width: 100%;
|
||||
min-width: 80px;
|
||||
padding: 0 8px;
|
||||
.weight-slider {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.weight-input-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,231 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<ElSpace wrap>
|
||||
<ElButton
|
||||
v-permission="'dice:reward_config_record:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 状态:-1失败 0测试中 1完成 -->
|
||||
<template #status="{ row }">
|
||||
<span>{{ formatStatus(row.status) }}</span>
|
||||
</template>
|
||||
<!-- 付费抽取:顺时针、逆时针抽取次数(兼容旧数据用 s_count/n_count) -->
|
||||
<template #paid_draw="{ row }">
|
||||
<span>顺 {{ getPaidS(row) }} / 逆 {{ getPaidN(row) }}</span>
|
||||
</template>
|
||||
<!-- 免费抽取:顺时针、逆时针抽取次数 -->
|
||||
<template #free_draw="{ row }">
|
||||
<span>顺 {{ row.free_s_count ?? 0 }} / 逆 {{ row.free_n_count ?? 0 }}</span>
|
||||
</template>
|
||||
<!-- 平台赚取金额 -->
|
||||
<template #platform_profit="{ row }">
|
||||
<span>{{ formatPlatformProfit(row.platform_profit) }}</span>
|
||||
</template>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:reward_config_record:index:read'"
|
||||
type="success"
|
||||
toolTip="查看详情"
|
||||
@click="openDetail(row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:reward_config_record:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
<!-- 详情抽屉:导入成功后刷新列表 -->
|
||||
<DetailDrawer v-model="detailVisible" :record="detailRecord" @import-done="refreshData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/reward_config_record/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
import DetailDrawer from './modules/detail-drawer.vue'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({})
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 详情抽屉:打开时拉取完整记录(含 paid_tier_weights、free_tier_weights 等)
|
||||
const detailVisible = ref(false)
|
||||
const detailRecord = ref<Record<string, any> | null>(null)
|
||||
async function openDetail(row: Record<string, any>) {
|
||||
const id = row?.id
|
||||
if (id == null) return
|
||||
detailRecord.value = { ...row }
|
||||
detailVisible.value = true
|
||||
try {
|
||||
const res = await api.read(id)
|
||||
const data = res?.data ?? res
|
||||
if (data && typeof data === 'object') {
|
||||
detailRecord.value = data
|
||||
}
|
||||
} catch {
|
||||
// 读取失败时保留列表行数据
|
||||
}
|
||||
}
|
||||
|
||||
// 状态文案:-1失败 0测试中 1完成(2=执行中也显示测试中)
|
||||
function formatStatus(status: unknown): string {
|
||||
const s = Number(status)
|
||||
if (s === -1) return '失败'
|
||||
if (s === 1) return '完成'
|
||||
if (s === 0 || s === 2) return '测试中'
|
||||
return '—'
|
||||
}
|
||||
|
||||
// 付费抽取次数(兼容旧数据:无 paid_s_count 时用 s_count)
|
||||
function getPaidS(row: Record<string, any>): number {
|
||||
const v = row.paid_s_count
|
||||
if (v !== undefined && v !== null && (Number(v) || 0) > 0) return Number(v)
|
||||
return Number(row.s_count ?? 0)
|
||||
}
|
||||
function getPaidN(row: Record<string, any>): number {
|
||||
const v = row.paid_n_count
|
||||
if (v !== undefined && v !== null && (Number(v) || 0) > 0) return Number(v)
|
||||
return Number(row.n_count ?? 0)
|
||||
}
|
||||
|
||||
// 平台赚取金额展示(未完成或空显示 —)
|
||||
function formatPlatformProfit(v: unknown): string {
|
||||
if (v === null || v === undefined || v === '') return '—'
|
||||
const n = Number(v)
|
||||
if (Number.isNaN(n)) return '—'
|
||||
return String(n)
|
||||
}
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiParams: { limit: 100 },
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80, align: 'center' },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
width: 90,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'paid_draw',
|
||||
label: '付费抽取',
|
||||
width: 160,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'free_draw',
|
||||
label: '免费抽取',
|
||||
width: 160,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'platform_profit',
|
||||
label: '平台赚取金额',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{ prop: 'total_play_count', label: '总抽奖次数', width: 110, align: 'center' },
|
||||
{
|
||||
prop: 'admin_name',
|
||||
label: '创建管理员',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
showOverflowTooltip: true
|
||||
},
|
||||
{ prop: 'create_time', label: '创建时间', width: 170, align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
@@ -0,0 +1,531 @@
|
||||
<template>
|
||||
<el-drawer
|
||||
v-model="visible"
|
||||
title="测试记录详情"
|
||||
:size="drawerSize"
|
||||
direction="rtl"
|
||||
destroy-on-close
|
||||
@close="handleClose"
|
||||
>
|
||||
<template v-if="record">
|
||||
<div class="detail-section">
|
||||
<div class="section-title">基本信息</div>
|
||||
<el-descriptions :column="2" border size="small">
|
||||
<el-descriptions-item label="记录ID">
|
||||
{{ record.id }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="测试次数">{{ record.test_count }} 次</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">
|
||||
{{ record.create_time || '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="执行管理员">
|
||||
{{ record.admin_name ?? record.admin_id ?? '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="付费奖池配置ID">
|
||||
{{ record.paid_lottery_config_id ?? record.lottery_config_id ?? '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="免费奖池配置ID">
|
||||
{{ record.free_lottery_config_id ?? '—' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="BIGWIN 权重快照">
|
||||
<template v-if="bigwinWeightDisplay.length">
|
||||
<span v-for="item in bigwinWeightDisplay" :key="item.grid" class="mr-2">
|
||||
{{ item.grid }}:{{ item.weight }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>—</template>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<div class="section-title">付费抽奖档位概率(T1-T5,测试时使用)</div>
|
||||
<el-table
|
||||
v-if="paidTierTableData.length"
|
||||
:data="paidTierTableData"
|
||||
border
|
||||
size="small"
|
||||
class="tier-weights-table"
|
||||
max-height="160"
|
||||
>
|
||||
<el-table-column prop="tier" label="档位" width="80" align="center" />
|
||||
<el-table-column prop="weight" label="权重" width="100" align="center" />
|
||||
<el-table-column prop="percent" label="占比" width="100" align="center" />
|
||||
</el-table>
|
||||
<div v-else class="empty-tip">
|
||||
暂无付费档位数据(旧记录可能仅保存 tier_weights_snapshot)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<div class="section-title">免费抽奖档位概率(T1-T5,测试时使用)</div>
|
||||
<el-table
|
||||
v-if="freeTierTableData.length"
|
||||
:data="freeTierTableData"
|
||||
border
|
||||
size="small"
|
||||
class="tier-weights-table"
|
||||
max-height="160"
|
||||
>
|
||||
<el-table-column prop="tier" label="档位" width="80" align="center" />
|
||||
<el-table-column prop="weight" label="权重" width="100" align="center" />
|
||||
<el-table-column prop="percent" label="占比" width="100" align="center" />
|
||||
</el-table>
|
||||
<div v-else class="empty-tip">暂无免费档位数据</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<div class="section-title">权重配比快照(测试时使用的 T1-T5/BIGWIN 配置)</div>
|
||||
|
||||
<div class="snapshot-group">
|
||||
<div class="snapshot-subtitle">顺时针(非 BIGWIN)</div>
|
||||
<el-table
|
||||
:data="snapshotClockwise"
|
||||
border
|
||||
size="small"
|
||||
max-height="180"
|
||||
class="snapshot-table"
|
||||
>
|
||||
<el-table-column prop="tier" label="档位" width="80" align="center" />
|
||||
<el-table-column prop="grid_number" label="色子点数" width="100" align="center" />
|
||||
<el-table-column prop="weight" label="权重" width="90" align="center" />
|
||||
</el-table>
|
||||
<div v-if="!snapshotClockwise.length" class="empty-tip">暂无顺时针数据</div>
|
||||
</div>
|
||||
|
||||
<div class="snapshot-group">
|
||||
<div class="snapshot-subtitle">逆时针(非 BIGWIN)</div>
|
||||
<el-table
|
||||
:data="snapshotCounterclockwise"
|
||||
border
|
||||
size="small"
|
||||
max-height="180"
|
||||
class="snapshot-table"
|
||||
>
|
||||
<el-table-column prop="tier" label="档位" width="80" align="center" />
|
||||
<el-table-column prop="grid_number" label="色子点数" width="100" align="center" />
|
||||
<el-table-column prop="weight" label="权重" width="90" align="center" />
|
||||
</el-table>
|
||||
<div v-if="!snapshotCounterclockwise.length" class="empty-tip">暂无逆时针数据</div>
|
||||
</div>
|
||||
|
||||
<div class="snapshot-group">
|
||||
<div class="snapshot-subtitle">BIGWIN(按 DiceRewardConfig 配置快照)</div>
|
||||
<el-table
|
||||
:data="bigwinTableData"
|
||||
border
|
||||
size="small"
|
||||
max-height="180"
|
||||
class="snapshot-table"
|
||||
>
|
||||
<el-table-column prop="grid_number" label="色子点数" width="100" align="center" />
|
||||
<el-table-column prop="weight" label="权重" width="90" align="center" />
|
||||
</el-table>
|
||||
<div v-if="!bigwinTableData.length" class="empty-tip">暂无 BIGWIN 数据</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section">
|
||||
<div class="section-title">落点统计(各 grid_number 出现次数)</div>
|
||||
<div class="chart-wrap">
|
||||
<ArtBarChart
|
||||
x-axis-name="色子点数 (grid_number)"
|
||||
:x-axis-data="chartLabels"
|
||||
:data="chartData"
|
||||
height="280px"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="resultTotal === 0" class="empty-tip">暂无落点数据</div>
|
||||
<div v-else class="result-summary">总落点次数:{{ resultTotal }}</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-section footer-actions">
|
||||
<el-button type="primary" :loading="importing" @click="openImport">
|
||||
导入到当前配置
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 导入弹窗 -->
|
||||
<el-dialog
|
||||
v-model="importVisible"
|
||||
title="导入到正式配置"
|
||||
width="520px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<p class="import-desc">
|
||||
将本测试记录导入:<strong>DiceReward</strong>(格子权重)、
|
||||
<strong>DiceRewardConfig</strong>(BIGWIN weight)、
|
||||
<strong>DiceLotteryPoolConfig</strong>(付费/免费 T1-T5 档位概率)。请选择要写入的奖池。
|
||||
</p>
|
||||
<el-form label-width="160px">
|
||||
<el-form-item label="导入付费档位概率到奖池">
|
||||
<el-select
|
||||
v-model="importPaidLotteryConfigId"
|
||||
placeholder="选择任意奖池(建议付费池)"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in paidLotteryOptions"
|
||||
:key="opt.id"
|
||||
:label="opt.name"
|
||||
:value="opt.id"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">不选则使用本记录保存时的付费奖池配置 ID</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="导入免费档位概率到奖池">
|
||||
<el-select
|
||||
v-model="importFreeLotteryConfigId"
|
||||
placeholder="选择任意奖池(建议免费池)"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in freeLotteryOptions"
|
||||
:key="opt.id"
|
||||
:label="opt.name"
|
||||
:value="opt.id"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">不选则使用本记录保存时的免费奖池配置 ID</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="importVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="importing" @click="confirmImport">确认导入</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import recordApi from '../../../api/reward_config_record/index'
|
||||
import lotteryConfigApi from '../../../api/lottery_pool_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const GRID_NUMBERS = [
|
||||
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
||||
30
|
||||
]
|
||||
|
||||
interface RecordRow {
|
||||
id?: number
|
||||
test_count?: number
|
||||
create_time?: string
|
||||
admin_id?: number | null
|
||||
admin_name?: string
|
||||
lottery_config_id?: number | null
|
||||
paid_lottery_config_id?: number | null
|
||||
free_lottery_config_id?: number | null
|
||||
bigwin_weight?: Record<string, number> | Array<[number, number]> | null
|
||||
// 新结构:{ paid: {T1..T5}, free: {T1..T5} },兼容旧结构直接是 {T1..T5}
|
||||
tier_weights_snapshot?:
|
||||
| {
|
||||
paid?: Record<string, number>
|
||||
free?: Record<string, number>
|
||||
[key: string]: any
|
||||
}
|
||||
| Record<string, number>
|
||||
paid_tier_weights?: Record<string, number>
|
||||
free_tier_weights?: Record<string, number>
|
||||
weight_config_snapshot?: Array<{
|
||||
id?: number
|
||||
grid_number?: number
|
||||
tier?: string
|
||||
weight?: number
|
||||
}>
|
||||
result_counts?: Record<string, number>
|
||||
}
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
record: RecordRow | null
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'import-done'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
record: null
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const drawerSize = ref('720px')
|
||||
|
||||
const importVisible = ref(false)
|
||||
const importing = ref(false)
|
||||
const importPaidLotteryConfigId = ref<number | null>(null)
|
||||
const importFreeLotteryConfigId = ref<number | null>(null)
|
||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string; type: number }>>([])
|
||||
|
||||
function tierWeightsToTableData(t: Record<string, number> | null | undefined) {
|
||||
if (!t || typeof t !== 'object') return []
|
||||
const tiers = ['T1', 'T2', 'T3', 'T4', 'T5']
|
||||
const rows = tiers.map((tier) => {
|
||||
const w = t[tier] ?? t[tier.toLowerCase()] ?? 0
|
||||
return { tier, weight: w }
|
||||
})
|
||||
const total = rows.reduce((sum, r) => sum + r.weight, 0)
|
||||
return rows.map((r) => ({
|
||||
tier: r.tier,
|
||||
weight: r.weight,
|
||||
percent: total > 0 ? `${((r.weight / total) * 100).toFixed(1)}%` : '—'
|
||||
}))
|
||||
}
|
||||
|
||||
const paidTierTableData = computed(() => {
|
||||
const r = props.record
|
||||
const paidFromRecord = r?.paid_tier_weights
|
||||
const snapshot = r?.tier_weights_snapshot
|
||||
let snapshotPaid: Record<string, number> | null = null
|
||||
if (snapshot && typeof snapshot === 'object') {
|
||||
if ('paid' in snapshot || 'free' in snapshot) {
|
||||
const s: any = snapshot
|
||||
if (s.paid && typeof s.paid === 'object') {
|
||||
snapshotPaid = s.paid
|
||||
}
|
||||
} else {
|
||||
// 兼容旧结构:直接是 T1-T5
|
||||
snapshotPaid = snapshot as Record<string, number>
|
||||
}
|
||||
}
|
||||
const source =
|
||||
paidFromRecord && Object.keys(paidFromRecord).length ? paidFromRecord : snapshotPaid
|
||||
return tierWeightsToTableData(source || undefined)
|
||||
})
|
||||
|
||||
const freeTierTableData = computed(() => {
|
||||
const r = props.record
|
||||
const freeFromRecord = r?.free_tier_weights
|
||||
const snapshot = r?.tier_weights_snapshot
|
||||
let snapshotFree: Record<string, number> | null = null
|
||||
if (snapshot && typeof snapshot === 'object') {
|
||||
if ('paid' in snapshot || 'free' in snapshot) {
|
||||
const s: any = snapshot
|
||||
if (s.free && typeof s.free === 'object') {
|
||||
snapshotFree = s.free
|
||||
}
|
||||
}
|
||||
}
|
||||
const source =
|
||||
freeFromRecord && Object.keys(freeFromRecord).length ? freeFromRecord : snapshotFree
|
||||
return tierWeightsToTableData(source || undefined)
|
||||
})
|
||||
|
||||
const bigwinWeightDisplay = computed(() => {
|
||||
const raw = props.record?.bigwin_weight
|
||||
if (!raw) return []
|
||||
const entries: Array<{ grid: number; weight: number }> = []
|
||||
if (Array.isArray(raw)) {
|
||||
raw.forEach(([grid, weight]) => {
|
||||
entries.push({ grid: Number(grid), weight: Number(weight) })
|
||||
})
|
||||
} else if (typeof raw === 'object') {
|
||||
Object.keys(raw).forEach((k) => {
|
||||
const grid = Number(k)
|
||||
const w = Number((raw as Record<string, number>)[k])
|
||||
if (!Number.isNaN(grid) && !Number.isNaN(w)) {
|
||||
entries.push({ grid, weight: w })
|
||||
}
|
||||
})
|
||||
}
|
||||
return entries.sort((a, b) => a.grid - b.grid)
|
||||
})
|
||||
|
||||
// 导入不限制奖池类型,两个下拉都可选任意 DiceLotteryPoolConfig
|
||||
const paidLotteryOptions = computed(() => lotteryConfigOptions.value)
|
||||
const freeLotteryOptions = computed(() => lotteryConfigOptions.value)
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (v) => emit('update:modelValue', v)
|
||||
})
|
||||
|
||||
const snapshotTableData = computed(() => {
|
||||
const snapshot = props.record?.weight_config_snapshot as
|
||||
| Array<{
|
||||
tier?: string
|
||||
direction?: number
|
||||
grid_number?: number
|
||||
weight?: number
|
||||
}>
|
||||
| undefined
|
||||
if (!Array.isArray(snapshot)) return []
|
||||
return snapshot.map((item) => {
|
||||
const dir = item.direction
|
||||
return {
|
||||
tier: item.tier ?? '—',
|
||||
direction: dir,
|
||||
direction_label: dir === 0 ? '顺时针' : dir === 1 ? '逆时针' : '—',
|
||||
grid_number: item.grid_number ?? '—',
|
||||
weight: item.weight ?? '—'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const snapshotClockwise = computed(() =>
|
||||
snapshotTableData.value.filter((row) => row.direction === 0 && row.tier !== 'BIGWIN')
|
||||
)
|
||||
const snapshotCounterclockwise = computed(() =>
|
||||
snapshotTableData.value.filter((row) => row.direction === 1 && row.tier !== 'BIGWIN')
|
||||
)
|
||||
const bigwinTableData = computed(() =>
|
||||
bigwinWeightDisplay.value.map((item) => ({
|
||||
grid_number: item.grid,
|
||||
weight: item.weight
|
||||
}))
|
||||
)
|
||||
|
||||
const chartLabels = computed(() => GRID_NUMBERS.map((n) => String(n)))
|
||||
|
||||
const chartData = computed(() => {
|
||||
const counts = props.record?.result_counts
|
||||
if (!counts) return GRID_NUMBERS.map(() => 0)
|
||||
|
||||
// 兼容两种结构:对象 {5:10,...} 或数组 [10, ...]
|
||||
if (Array.isArray(counts)) {
|
||||
// 如果是数组,按顺序映射到 GRID_NUMBERS
|
||||
return GRID_NUMBERS.map((_, idx) => {
|
||||
const v = counts[idx]
|
||||
return typeof v === 'number' && !Number.isNaN(v) ? v : 0
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof counts === 'object') {
|
||||
return GRID_NUMBERS.map((n) => {
|
||||
const byString = (counts as Record<string, number>)[String(n)]
|
||||
const byNumber = (counts as Record<number, number>)[n]
|
||||
const v = byString ?? byNumber
|
||||
return typeof v === 'number' && !Number.isNaN(v) ? v : 0
|
||||
})
|
||||
}
|
||||
|
||||
return GRID_NUMBERS.map(() => 0)
|
||||
})
|
||||
|
||||
const resultTotal = computed(() => {
|
||||
const data = chartData.value
|
||||
return data.reduce((sum, n) => sum + n, 0)
|
||||
})
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false
|
||||
importVisible.value = false
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const updateDrawerSize = () => {
|
||||
drawerSize.value = window.innerWidth <= 768 ? '100%' : '720px'
|
||||
}
|
||||
updateDrawerSize()
|
||||
window.addEventListener('resize', updateDrawerSize)
|
||||
}
|
||||
|
||||
async function loadLotteryOptions() {
|
||||
try {
|
||||
const list = await lotteryConfigApi.getOptions()
|
||||
lotteryConfigOptions.value = Array.isArray(list) ? list : []
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function openImport() {
|
||||
importPaidLotteryConfigId.value =
|
||||
props.record?.paid_lottery_config_id ?? props.record?.lottery_config_id ?? null
|
||||
importFreeLotteryConfigId.value = props.record?.free_lottery_config_id ?? null
|
||||
importVisible.value = true
|
||||
loadLotteryOptions()
|
||||
}
|
||||
|
||||
async function confirmImport() {
|
||||
const id = props.record?.id
|
||||
if (!id) return
|
||||
importing.value = true
|
||||
try {
|
||||
await recordApi.importFromRecord({
|
||||
record_id: id,
|
||||
paid_lottery_config_id: importPaidLotteryConfigId.value ?? undefined,
|
||||
free_lottery_config_id: importFreeLotteryConfigId.value ?? undefined
|
||||
})
|
||||
ElMessage.success('导入成功,已刷新 DiceReward、DiceRewardConfig(BIGWIN)、奖池配置')
|
||||
importVisible.value = false
|
||||
emit('import-done')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message ?? '导入失败')
|
||||
} finally {
|
||||
importing.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-drawer__body) {
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
max-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.detail-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
.snapshot-table {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.snapshot-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.snapshot-subtitle {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
margin: 4px 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.chart-wrap {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.empty-tip {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.result-summary {
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.tier-weights-table {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.footer-actions {
|
||||
margin-top: 16px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.import-desc {
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? '新增奖励配置权重测试记录' : '编辑奖励配置权重测试记录'"
|
||||
width="600px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="测试次数:100/500/1000" prop="test_count">
|
||||
<el-input v-model="formData.test_count" placeholder="请输入测试次数:100/500/1000" />
|
||||
</el-form-item>
|
||||
<el-form-item label="测试时权重配比快照:按档位保存 id,grid_number,tier,weight" prop="weight_config_snapshot">
|
||||
<el-input v-model="formData.weight_config_snapshot" placeholder="请输入测试时权重配比快照:按档位保存 id,grid_number,tier,weight" />
|
||||
</el-form-item>
|
||||
<el-form-item label="落点统计:grid_number=>出现次数" prop="result_counts">
|
||||
<el-input v-model="formData.result_counts" placeholder="请输入落点统计:grid_number=>出现次数" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward_config_record/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
data?: Record<string, any>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
dialogType: 'add',
|
||||
data: undefined
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
/**
|
||||
* 弹窗显示状态双向绑定
|
||||
*/
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
test_count: [{ required: true, message: '测试次数:100/500/1000必需填写', trigger: 'blur' }],
|
||||
})
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null,
|
||||
test_count: 100,
|
||||
weight_config_snapshot: '',
|
||||
result_counts: '',
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据
|
||||
*/
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/**
|
||||
* 监听弹窗打开,初始化表单数据
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
initPage()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
Object.assign(formData, initialFormData)
|
||||
// 如果有数据,则填充数据
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
if (props.data[key] != null && props.data[key] != undefined) {
|
||||
;(formData as any)[key] = props.data[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置表单
|
||||
*/
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(formData)
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.log('表单验证失败:', error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="100px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, any>): void
|
||||
(e: 'search', params: Record<string, any>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
// 展开/收起
|
||||
const isExpanded = ref<boolean>(false)
|
||||
|
||||
// 表单数据双向绑定
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
// 重置
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref.resetFields()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
// 搜索
|
||||
async function handleSearch() {
|
||||
emit('search', formData.value)
|
||||
}
|
||||
|
||||
// 展开/收起
|
||||
function handleExpand(expanded: boolean) {
|
||||
isExpanded.value = expanded
|
||||
}
|
||||
|
||||
// 栅格占据的列数
|
||||
const setSpan = (span: number) => {
|
||||
return {
|
||||
span: span,
|
||||
xs: 24, // 手机:满宽显示
|
||||
sm: span >= 12 ? span : 12, // 平板:大于等于12保持,否则用半宽
|
||||
md: span >= 8 ? span : 8, // 中等屏幕:大于等于8保持,否则用三分之一宽
|
||||
lg: span,
|
||||
xl: span
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -190,8 +190,15 @@
|
||||
saiSecond: 'email'
|
||||
},
|
||||
{ prop: 'phone', label: '手机号', width: 120 },
|
||||
{ prop: 'depts.name', label: '部门', minWidth: 150 },
|
||||
{
|
||||
prop: 'dept_id',
|
||||
label: '部门',
|
||||
minWidth: 150,
|
||||
sortable: true,
|
||||
formatter: (row: any) => row.depts?.name ?? ''
|
||||
},
|
||||
{ prop: 'status', label: '状态', width: 80, saiType: 'dict', saiDict: 'data_status' },
|
||||
{ prop: 'agent_id', label: '代理ID', width: 120, showOverflowTooltip: true },
|
||||
{ prop: 'dashboard', label: '首页', width: 100, saiType: 'dict', saiDict: 'dashboard' },
|
||||
{ prop: 'login_time', label: '上次登录', width: 170, sortable: true },
|
||||
{
|
||||
|
||||
@@ -1,34 +1,43 @@
|
||||
# 数据库配置
|
||||
DB_TYPE = mysql
|
||||
DB_HOST = 127.0.0.1
|
||||
DB_PORT = 3306
|
||||
DB_NAME = saiadmin
|
||||
DB_USER = root
|
||||
DB_PASSWORD = 123456
|
||||
DB_PREFIX =
|
||||
DB_TYPE=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_NAME=saiadmin
|
||||
DB_USER=root
|
||||
DB_PASSWORD=123456
|
||||
DB_PREFIX=
|
||||
DB_POOL_MAX=32
|
||||
DB_POOL_MIN=4
|
||||
|
||||
# 缓存方式,支持file|redis(API 用户登录缓存需使用 redis)
|
||||
CACHE_MODE = redis
|
||||
CACHE_MODE=redis
|
||||
REDIS_POOL_MAX=32
|
||||
|
||||
# Redis配置
|
||||
REDIS_HOST = 127.0.0.1
|
||||
REDIS_PORT = 6379
|
||||
REDIS_PASSWORD = ''
|
||||
REDIS_DB = 0
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=''
|
||||
REDIS_DB=0
|
||||
|
||||
# 游戏地址,用于 /api/v1/getGameUrl 返回
|
||||
GAME_URL=dice-game.yuliao666.top
|
||||
|
||||
# API 鉴权与用户(可选,不填则用默认值)
|
||||
# authToken 签名密钥(必填,与客户端约定,用于 signature 校验)
|
||||
API_AUTH_TOKEN_SECRET = xF75oK91TQj13s0UmNIr1NBWMWGfflNO
|
||||
API_AUTH_TOKEN_SECRET=xF75oK91TQj13s0UmNIr1NBWMWGfflNO
|
||||
# authToken 时间戳允许误差秒数,防重放,默认 300
|
||||
API_AUTH_TOKEN_TIME_TOLERANCE = 300
|
||||
API_AUTH_TOKEN_EXP = 86400
|
||||
# API_USER_TOKEN_EXP = 604800
|
||||
API_USER_CACHE_EXPIRE = 86400
|
||||
API_USER_ENCRYPT_KEY = Wj818SK8dhKBKNOY3PUTmZfhQDMCXEZi
|
||||
API_AUTH_TOKEN_TIME_TOLERANCE=300
|
||||
API_AUTH_TOKEN_EXP=86400
|
||||
# API_USER_TOKEN_EXP=604800
|
||||
API_USER_CACHE_EXPIRE=86400
|
||||
API_USER_ENCRYPT_KEY=Wj818SK8dhKBKNOY3PUTmZfhQDMCXEZi
|
||||
|
||||
# 验证码配置,支持cache|session
|
||||
CAPTCHA_MODE = cache
|
||||
LOGIN_CAPTCHA_ENABLE = false
|
||||
CAPTCHA_MODE=cache
|
||||
LOGIN_CAPTCHA_ENABLE=false
|
||||
|
||||
#前端目录
|
||||
FRONTEND_DIR = saiadmin-vue
|
||||
FRONTEND_DIR=saiadmin-vue
|
||||
|
||||
#生成环境
|
||||
APP_DEBUG=false
|
||||
73
server/app/api/cache/AuthTokenCache.php
vendored
73
server/app/api/cache/AuthTokenCache.php
vendored
@@ -6,49 +6,78 @@ namespace app\api\cache;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 按设备标识存储当前有效的 auth-token,同一设备只保留最新一个,旧 token 自动失效
|
||||
* 平台 auth-token Redis 缓存
|
||||
* 用于 /api/v1/authToken 鉴权接口颁发的 token 存储与校验
|
||||
*/
|
||||
class AuthTokenCache
|
||||
{
|
||||
private static function prefix(): string
|
||||
private static function devicePrefix(): string
|
||||
{
|
||||
return config('api.auth_token_device_prefix', 'api:auth_token:');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置该设备当前有效的 auth-token(会覆盖同设备之前的 token,使旧 token 失效)
|
||||
* @param string $device 设备标识,如 dice
|
||||
* @param string $token 完整 auth-token 字符串
|
||||
* @param int $ttl 过期时间(秒),应与 auth_token_exp 一致
|
||||
*/
|
||||
public static function setDeviceToken(string $device, string $token, int $ttl): bool
|
||||
private static function tokenPrefix(): string
|
||||
{
|
||||
if ($device === '' || $ttl <= 0) {
|
||||
return config('api.auth_token_prefix', 'api:auth_token:t:');
|
||||
}
|
||||
|
||||
private static function expire(): int
|
||||
{
|
||||
return (int) config('api.auth_token_exp', 86400);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储 auth-token(同一 agent_id 只保留最新一个)
|
||||
* @param string $agentId 代理 ID
|
||||
* @param string $token 生成的 auth-token
|
||||
*/
|
||||
public static function setToken(string $agentId, string $token): bool
|
||||
{
|
||||
if ($agentId === '' || $token === '') {
|
||||
return false;
|
||||
}
|
||||
$key = self::prefix() . $device;
|
||||
return Cache::set($key, $token, $ttl);
|
||||
$exp = self::expire();
|
||||
if ($exp <= 0) {
|
||||
return false;
|
||||
}
|
||||
$oldToken = Cache::get(self::devicePrefix() . $agentId);
|
||||
if ($oldToken !== null && $oldToken !== '') {
|
||||
Cache::delete(self::tokenPrefix() . $oldToken);
|
||||
}
|
||||
Cache::set(self::tokenPrefix() . $token, $agentId, $exp);
|
||||
Cache::set(self::devicePrefix() . $agentId, $token, $exp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该设备当前有效的 auth-token,不存在或已过期返回 null
|
||||
* 根据 agent_id 获取当前有效的 token,不存在或已过期返回 null
|
||||
*/
|
||||
public static function getDeviceToken(string $device): ?string
|
||||
public static function getTokenByAgentId(string $agentId): ?string
|
||||
{
|
||||
if ($device === '') {
|
||||
if ($agentId === '') {
|
||||
return null;
|
||||
}
|
||||
$key = self::prefix() . $device;
|
||||
$value = Cache::get($key);
|
||||
return $value !== null && $value !== '' ? (string) $value : null;
|
||||
$val = Cache::get(self::devicePrefix() . $agentId);
|
||||
return $val !== null && $val !== '' ? (string) $val : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验请求中的 token 是否为该设备当前唯一有效 token
|
||||
* 根据 auth-token 获取 agent_id,不存在或已过期返回 null
|
||||
*/
|
||||
public static function isCurrentToken(string $device, string $token): bool
|
||||
public static function getAgentIdByToken(string $token): ?string
|
||||
{
|
||||
$current = self::getDeviceToken($device);
|
||||
return $current !== null && $current === $token;
|
||||
if ($token === '') {
|
||||
return null;
|
||||
}
|
||||
$val = Cache::get(self::tokenPrefix() . $token);
|
||||
return $val !== null && $val !== '' ? (string) $val : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 auth-token 是否有效
|
||||
*/
|
||||
public static function isValidToken(string $token): bool
|
||||
{
|
||||
return self::getAgentIdByToken($token) !== null;
|
||||
}
|
||||
}
|
||||
|
||||
104
server/app/api/cache/UserCache.php
vendored
104
server/app/api/cache/UserCache.php
vendored
@@ -178,4 +178,108 @@ class UserCache
|
||||
$current = self::getCurrentUserToken($userId);
|
||||
return $current !== null && $current === $token;
|
||||
}
|
||||
|
||||
/** 按 username 的登录会话 key 前缀(token 中间件:存在即视为已登录) */
|
||||
private static function sessionUsernamePrefix(): string
|
||||
{
|
||||
return config('api.session_username_prefix', 'api:user:session:');
|
||||
}
|
||||
|
||||
private static function sessionExpire(): int
|
||||
{
|
||||
return (int) config('api.session_expire', 604800);
|
||||
}
|
||||
|
||||
/** 设置 username 当前有效 token(JWT),重新登录会覆盖,实现单点登录 */
|
||||
public static function setSessionByUsername(string $username, string $token): bool
|
||||
{
|
||||
if ($username === '' || $token === '') {
|
||||
return false;
|
||||
}
|
||||
$key = self::sessionUsernamePrefix() . $username;
|
||||
return Cache::set($key, $token, self::sessionExpire());
|
||||
}
|
||||
|
||||
/** 获取 username 当前在服务端登记的有效 token(JWT),不存在返回 null */
|
||||
public static function getSessionTokenByUsername(string $username): ?string
|
||||
{
|
||||
if ($username === '') {
|
||||
return null;
|
||||
}
|
||||
$key = self::sessionUsernamePrefix() . $username;
|
||||
$val = Cache::get($key);
|
||||
return $val !== null && $val !== '' ? (string) $val : null;
|
||||
}
|
||||
|
||||
/** 检查 username 是否已有登录会话(Redis 中是否存在当前 token) */
|
||||
public static function hasSessionByUsername(string $username): bool
|
||||
{
|
||||
return self::getSessionTokenByUsername($username) !== null;
|
||||
}
|
||||
|
||||
/** 删除 username 登录会话(退出登录时调用) */
|
||||
public static function deleteSessionByUsername(string $username): bool
|
||||
{
|
||||
if ($username === '') {
|
||||
return false;
|
||||
}
|
||||
$key = self::sessionUsernamePrefix() . $username;
|
||||
return Cache::delete($key);
|
||||
}
|
||||
|
||||
/** 玩家缓存 key 前缀(Token 中间件用,减少重复查库) */
|
||||
private static function playerCachePrefix(): string
|
||||
{
|
||||
return config('api.player_cache_prefix', 'api:player:');
|
||||
}
|
||||
|
||||
private static function playerCacheTtl(): int
|
||||
{
|
||||
return (int) config('api.player_cache_ttl', 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 username 缓存玩家信息(仅 id + username,供中间件注入 request->player 后使用)
|
||||
* 登录/信息变更时需调用 deletePlayerByUsername 失效
|
||||
*/
|
||||
public static function setPlayerByUsername(string $username, array $playerRow): bool
|
||||
{
|
||||
if ($username === '' || empty($playerRow)) {
|
||||
return false;
|
||||
}
|
||||
$ttl = self::playerCacheTtl();
|
||||
if ($ttl <= 0) {
|
||||
return true;
|
||||
}
|
||||
$key = self::playerCachePrefix() . $username;
|
||||
return Cache::set($key, json_encode($playerRow), $ttl);
|
||||
}
|
||||
|
||||
/** 按 username 取缓存玩家,未命中返回 null */
|
||||
public static function getPlayerByUsername(string $username): ?array
|
||||
{
|
||||
if ($username === '') {
|
||||
return null;
|
||||
}
|
||||
if (self::playerCacheTtl() <= 0) {
|
||||
return null;
|
||||
}
|
||||
$key = self::playerCachePrefix() . $username;
|
||||
$val = Cache::get($key);
|
||||
if ($val === null || $val === '') {
|
||||
return null;
|
||||
}
|
||||
$data = json_decode((string) $val, true);
|
||||
return is_array($data) ? $data : null;
|
||||
}
|
||||
|
||||
/** 退出登录或玩家信息变更时删除玩家缓存 */
|
||||
public static function deletePlayerByUsername(string $username): bool
|
||||
{
|
||||
if ($username === '') {
|
||||
return false;
|
||||
}
|
||||
$key = self::playerCachePrefix() . $username;
|
||||
return Cache::delete($key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\api\cache\AuthTokenCache;
|
||||
|
||||
/**
|
||||
* API 鉴权 Token 接口
|
||||
* 仅支持 GET,必传参数:signature、secret、device、time,签名规则:signature = md5(device . secret . time)
|
||||
* 后续所有 /api 接口调用均需在请求头携带此接口返回的 auth-token
|
||||
*/
|
||||
class AuthTokenController extends OpenController
|
||||
{
|
||||
/**
|
||||
* 获取 auth-token
|
||||
* GET /api/authToken
|
||||
* 参数:signature(签名)、secret(密钥)、device(设备标识)、time(时间戳,秒),四者均为必传且非空
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
if (strtoupper($request->method()) !== 'GET') {
|
||||
return $this->fail('仅支持 GET 请求', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$param = $request->get();
|
||||
$signature = trim((string) ($param['signature'] ?? ''));
|
||||
$secret = trim((string) ($param['secret'] ?? ''));
|
||||
$device = trim((string) ($param['device'] ?? ''));
|
||||
$time = trim((string) ($param['time'] ?? ''));
|
||||
|
||||
if ($signature === '' || $secret === '' || $device === '' || $time === '') {
|
||||
return $this->fail('signature、secret、device、time 均为必传且不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$serverSecret = trim((string) config('api.auth_token_secret', ''));
|
||||
if ($serverSecret === '') {
|
||||
return $this->fail('服务未配置 API_AUTH_TOKEN_SECRET', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
if ($secret !== $serverSecret) {
|
||||
return $this->fail('密钥错误', ReturnCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
$tolerance = (int) config('api.auth_token_time_tolerance', 300);
|
||||
$now = time();
|
||||
$ts = is_numeric($time) ? (int) $time : 0;
|
||||
if ($ts <= 0 || abs($now - $ts) > $tolerance) {
|
||||
return $this->fail('时间戳无效或已过期', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$sign = $this->getAuthToken($device, $serverSecret, $time);
|
||||
if ($sign !== $signature) {
|
||||
return $this->fail('签名验证失败', ReturnCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
$exp = (int) config('api.auth_token_exp', 86400);
|
||||
$tokenResult = JwtToken::generateToken([
|
||||
'id' => 0,
|
||||
'plat' => 'api',
|
||||
'device' => $device,
|
||||
'access_exp' => $exp,
|
||||
]);
|
||||
|
||||
// 同一设备只保留最新 token,覆盖后旧 token 失效
|
||||
AuthTokenCache::setDeviceToken($device, $tokenResult['access_token'], $exp);
|
||||
|
||||
return $this->success([
|
||||
'auth-token' => $tokenResult['access_token'],
|
||||
'expires_in' => $tokenResult['expires_in'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名:signature = md5(device . secret . time)
|
||||
*
|
||||
* @param string $device 设备标识
|
||||
* @param string $secret 密钥(来自配置)
|
||||
* @param string $time 时间戳
|
||||
* @return string
|
||||
*/
|
||||
private function getAuthToken(string $device, string $secret, string $time): string
|
||||
{
|
||||
return md5($device . $secret . $time);
|
||||
}
|
||||
}
|
||||
36
server/app/api/controller/BaseController.php
Normal file
36
server/app/api/controller/BaseController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\util\ApiLang;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* API 控制器基类:根据请求头 lang(en=英文,zh=中文)对返回 message 做双语适配
|
||||
*/
|
||||
class BaseController extends OpenController
|
||||
{
|
||||
/**
|
||||
* 成功返回,message 按请求头 lang(en/zh)翻译
|
||||
*/
|
||||
public function success(array|string $data = [], string $msg = 'success', int $option = JSON_UNESCAPED_UNICODE): Response
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$msg = $data;
|
||||
$data = [];
|
||||
}
|
||||
$msg = ApiLang::translate((string) $msg);
|
||||
return parent::success($data, $msg, $option);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回,message 按 lang 翻译
|
||||
*/
|
||||
public function fail(string $msg = 'fail', int $code = 400): Response
|
||||
{
|
||||
$msg = ApiLang::translate($msg);
|
||||
return parent::fail($msg, $code);
|
||||
}
|
||||
}
|
||||
@@ -3,32 +3,80 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\api\logic\GameLogic;
|
||||
use app\api\logic\PlayStartLogic;
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\config\DiceConfig;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\api\controller\BaseController;
|
||||
use app\api\util\ApiLang;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
|
||||
/**
|
||||
* 游戏相关接口(购买抽奖券等)
|
||||
*/
|
||||
class GameController extends OpenController
|
||||
class GameController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取游戏配置(按 group 分组)
|
||||
* GET /api/game/config
|
||||
* header: lang = zh | en
|
||||
* 返回 data[group] = [ { name, title, value, create_time, update_time }, ... ]
|
||||
* - lang=zh 或默认:title/value = 中文
|
||||
* - lang=en:若存在英文配置则返回 title_en/value_en,否则回退到中文
|
||||
*/
|
||||
public function config(Request $request): Response
|
||||
{
|
||||
$rows = DiceConfig::select('name', 'group', 'title', 'title_en', 'value', 'value_en', 'create_time', 'update_time')->get();
|
||||
$lang = $request->header('lang', 'zh');
|
||||
if (!is_string($lang) || $lang === '') {
|
||||
$lang = 'zh';
|
||||
}
|
||||
$langLower = strtolower($lang);
|
||||
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$group = $row->group ?? '';
|
||||
if (!isset($data[$group])) {
|
||||
$data[$group] = [];
|
||||
}
|
||||
$title = $row->title;
|
||||
$value = $row->value;
|
||||
if ($isEn) {
|
||||
$titleEn = $row->title_en ?? '';
|
||||
$valueEn = $row->value_en ?? '';
|
||||
if ($titleEn !== '') {
|
||||
$title = $titleEn;
|
||||
}
|
||||
if ($valueEn !== '') {
|
||||
$value = $valueEn;
|
||||
}
|
||||
}
|
||||
$data[$group][] = [
|
||||
'name' => $row->name,
|
||||
'title' => $title,
|
||||
'value' => $value,
|
||||
'create_time' => $row->create_time,
|
||||
'update_time' => $row->update_time,
|
||||
];
|
||||
}
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买抽奖券
|
||||
* POST /api/game/buyLotteryTickets
|
||||
* header: auth-token, user-token(由 CheckUserTokenMiddleware 注入 request->user_id)
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
* body: count = 1 | 5 | 10(1次/100coin, 5次/500coin, 10次/1000coin)
|
||||
*/
|
||||
public function buyLotteryTickets(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$count = (int) $request->post('count', 0);
|
||||
if (!in_array($count, [1, 5, 10], true)) {
|
||||
return $this->fail('购买抽奖券错误', ReturnCode::PARAMS_ERROR);
|
||||
@@ -52,69 +100,151 @@ class GameController extends OpenController
|
||||
/**
|
||||
* 获取彩金池(中奖配置表)
|
||||
* GET /api/game/lotteryPool
|
||||
* header: auth-token
|
||||
* 返回 DiceRewardConfig 列表(彩金池/中奖配置)
|
||||
* header: token
|
||||
* 返回 DiceRewardConfig 列表(彩金池/中奖配置),不包含 tier=BIGWIN
|
||||
*/
|
||||
public function lotteryPool(Request $request): Response
|
||||
{
|
||||
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray();
|
||||
$list = DiceRewardConfig::getCachedList();
|
||||
$list = array_values(array_filter($list, function ($row) {
|
||||
return (string) ($row['tier'] ?? '') !== 'BIGWIN';
|
||||
}));
|
||||
|
||||
$lang = $request->header('lang', 'zh');
|
||||
if (!is_string($lang) || $lang === '') {
|
||||
$lang = 'zh';
|
||||
}
|
||||
$langLower = strtolower($lang);
|
||||
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
|
||||
|
||||
if ($isEn) {
|
||||
foreach ($list as $index => $row) {
|
||||
$uiEn = '';
|
||||
if (is_array($row) && array_key_exists('ui_text_en', $row) && $row['ui_text_en'] !== null) {
|
||||
$uiEn = (string) $row['ui_text_en'];
|
||||
}
|
||||
if ($uiEn !== '') {
|
||||
$row['ui_text'] = $uiEn;
|
||||
}
|
||||
$list[$index] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始游戏(抽奖一局)
|
||||
* POST /api/game/playStart
|
||||
* header: auth-token, user-token(由 CheckUserTokenMiddleware 注入 request->user_id)
|
||||
* body: rediction 必传,0=无 1=中奖
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
* body: direction 必传,0=无 1=中奖
|
||||
*/
|
||||
public function playStart(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$rediction = $request->post('rediction');
|
||||
if ($rediction === '' || $rediction === null) {
|
||||
return $this->fail('请传递 rediction 参数', ReturnCode::PARAMS_ERROR);
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$direction = $request->post('direction');
|
||||
if ($direction !== null) {
|
||||
$direction = (int) $direction;
|
||||
}
|
||||
$direction = (int) $rediction;
|
||||
if (!in_array($direction, [0, 1], true)) {
|
||||
return $this->fail('rediction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
||||
return $this->fail('direction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$player = DicePlayer::find($userId);
|
||||
if (!$player) {
|
||||
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
|
||||
}
|
||||
$minEv = (float) DiceRewardConfig::min('real_ev');
|
||||
$minEv = DiceRewardConfig::getCachedMinRealEv();
|
||||
$minCoin = abs($minEv + 100);
|
||||
$coin = (float) $player->coin;
|
||||
if ($coin < $minCoin) {
|
||||
return $this->success([], '当前玩家余额小于DiceRewardConfigMin.real_ev+100无法继续游戏');
|
||||
$msg = ApiLang::translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin], $request);
|
||||
return $this->success([], $msg);
|
||||
}
|
||||
|
||||
try {
|
||||
$logic = new PlayStartLogic();
|
||||
$data = $logic->run($userId, $direction);
|
||||
$data = $logic->run($userId, (int)$direction);
|
||||
|
||||
$lang = $request->header('lang', 'zh');
|
||||
if (!is_string($lang) || $lang === '') {
|
||||
$lang = 'zh';
|
||||
}
|
||||
$langLower = strtolower($lang);
|
||||
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
|
||||
|
||||
if (is_array($data) && array_key_exists('reward_config_id', $data)) {
|
||||
$rewardConfigId = (int) $data['reward_config_id'];
|
||||
if ($rewardConfigId > 0) {
|
||||
$configRow = DiceRewardConfig::getCachedById($rewardConfigId);
|
||||
if ($configRow !== null) {
|
||||
$uiText = '';
|
||||
$uiTextEn = '';
|
||||
if (array_key_exists('ui_text', $configRow) && $configRow['ui_text'] !== null) {
|
||||
$uiText = (string) $configRow['ui_text'];
|
||||
}
|
||||
if (array_key_exists('ui_text_en', $configRow) && $configRow['ui_text_en'] !== null) {
|
||||
$uiTextEn = (string) $configRow['ui_text_en'];
|
||||
}
|
||||
if ($isEn && $uiTextEn !== '') {
|
||||
$data['ui_text'] = $uiTextEn;
|
||||
} else {
|
||||
$data['ui_text'] = $uiText;
|
||||
}
|
||||
$data['ui_text_en'] = $uiTextEn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
} catch (ApiException $e) {
|
||||
return $this->fail($e->getMessage(), ReturnCode::BUSINESS_ERROR);
|
||||
} catch (\Throwable $e) {
|
||||
// 记录抽奖逻辑抛出的真实异常,便于排查“服务超时,没有原因”
|
||||
Log::error('playStart 异常: ' . $e->getMessage(), [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
'player_id' => $userId,
|
||||
'direction' => $direction,
|
||||
]);
|
||||
$timeoutRecord = null;
|
||||
$timeout_message = '';
|
||||
$adminId = null;
|
||||
try {
|
||||
$timeoutPlayer = DicePlayer::find($userId);
|
||||
$adminId = ($timeoutPlayer && ($timeoutPlayer->admin_id ?? null)) ? (int) $timeoutPlayer->admin_id : null;
|
||||
} catch (\Throwable $_) {
|
||||
}
|
||||
try {
|
||||
$timeoutRecord = DicePlayRecord::create([
|
||||
'player_id' => $userId,
|
||||
'admin_id' => $adminId,
|
||||
'lottery_config_id' => 0,
|
||||
'lottery_type' => 0,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
'start_index' => 0,
|
||||
'target_index' => 0,
|
||||
'roll_array' => '[]',
|
||||
'roll_number' => 0,
|
||||
'status' => PlayStartLogic::RECORD_STATUS_TIMEOUT,
|
||||
]);
|
||||
} catch (\Throwable $_) {
|
||||
} catch (\Exception $inner) {
|
||||
$timeout_message = $inner->getMessage();
|
||||
Log::error('游玩记录写入超时: ' . $inner->getMessage());
|
||||
}
|
||||
$payload = $timeoutRecord ? ['record' => $timeoutRecord->toArray()] : [];
|
||||
return $this->success($payload, '服务超时');
|
||||
$msg = $timeout_message !== '' ? $timeout_message : $e->getMessage();
|
||||
if ($msg === '') {
|
||||
$msg = '没有原因';
|
||||
}
|
||||
return $this->fail('服务超时,' . $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,80 +10,83 @@ use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
use app\api\controller\BaseController;
|
||||
|
||||
/**
|
||||
* API 用户登录/注册
|
||||
* 需先携带 auth-token,登录/注册成功后返回 user-token 与用户信息,用户信息已写入 Redis(key=base64(user_id),value=加密)
|
||||
* API 用户登录等
|
||||
* 登录接口 /api/user/Login 无需 token;其余接口需在请求头携带 token(base64(username.-.time)),由 TokenMiddleware 鉴权并注入 request->player_id / request->player
|
||||
*/
|
||||
class UserController extends OpenController
|
||||
class UserController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 登录
|
||||
* POST /api/user/login
|
||||
* body: phone (+60), password
|
||||
* 登录(form-data 参数)
|
||||
* POST /api/user/Login
|
||||
* body: username, password, lang(可选), coin(可选), time(可选)
|
||||
* 根据 username 查找或创建 DicePlayer,按 coin 增减平台币,会话写 Redis,返回带 token 的连接地址
|
||||
*/
|
||||
public function login(Request $request): Response
|
||||
public function Login(Request $request): Response
|
||||
{
|
||||
$phone = $request->post('phone', '');
|
||||
$password = $request->post('password', '');
|
||||
if ($phone === '' || $password === '') {
|
||||
return $this->fail('请填写手机号和密码', ReturnCode::PARAMS_ERROR);
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$password = trim((string) ($request->post('password', '')));
|
||||
$lang = trim((string) ($request->post('lang', 'chs')));
|
||||
$coin = $request->post('coin');
|
||||
$coin = $coin !== null && $coin !== '' ? (float) $coin : 0.0;
|
||||
$time = $request->post('time');
|
||||
$time = $time !== null && $time !== '' ? (string) $time : (string) time();
|
||||
if ($username === '' || $password === '') {
|
||||
return $this->fail('username、password 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
$logic = new UserLogic();
|
||||
$data = $logic->login($phone, $password);
|
||||
return $this->success([
|
||||
'user' => $data['user'],
|
||||
'user-token' => $data['user-token'],
|
||||
'user_id' => $data['user_id'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* POST /api/user/register
|
||||
* body: phone (+60), password, nickname(可选)
|
||||
*/
|
||||
public function register(Request $request): Response
|
||||
{
|
||||
$phone = $request->post('phone', '');
|
||||
$password = $request->post('password', '');
|
||||
$nickname = $request->post('nickname');
|
||||
if ($phone === '' || $password === '') {
|
||||
return $this->fail('请填写手机号和密码', ReturnCode::PARAMS_ERROR);
|
||||
try {
|
||||
$logic = new UserLogic();
|
||||
$result = $logic->loginByUsername($username, $password, $lang, $coin, $time);
|
||||
return $this->success([
|
||||
'url' => $result['url'],
|
||||
'token' => $result['token'],
|
||||
'lang' => $result['lang'],
|
||||
'user_id' => $result['user_id'],
|
||||
'user' => $result['user'],
|
||||
]);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
$logic = new UserLogic();
|
||||
$data = $logic->register($phone, $password, $nickname ? (string) $nickname : null);
|
||||
return $this->success([
|
||||
'user' => $data['user'],
|
||||
'user-token' => $data['user-token'],
|
||||
'user_id' => $data['user_id'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* POST /api/user/logout
|
||||
* header: user-token(由 CheckUserTokenMiddleware 校验并注入 request->userToken)
|
||||
* header: token(JWT),清除该 username 的 Redis 会话
|
||||
*/
|
||||
public function logout(Request $request): Response
|
||||
{
|
||||
$token = $request->userToken ?? UserLogic::getTokenFromRequest($request);
|
||||
if ($token === '' || !UserLogic::logout($token)) {
|
||||
return $this->fail('退出失败或 token 已失效', ReturnCode::TOKEN_INVALID);
|
||||
$token = $request->header('token');
|
||||
if ($token === null || $token === '') {
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
$token = trim(substr($auth, 7));
|
||||
}
|
||||
}
|
||||
$token = $token !== null ? trim((string) $token) : '';
|
||||
if ($token === '') {
|
||||
return $this->fail('请携带 token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
$username = UserLogic::getUsernameFromJwtPayload($token);
|
||||
if ($username === null || $username === '') {
|
||||
return $this->fail('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
UserCache::deleteSessionByUsername($username);
|
||||
UserCache::deletePlayerByUsername($username);
|
||||
return $this->success('已退出登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* GET /api/user/info
|
||||
* header: user-token(由 CheckUserTokenMiddleware 校验并注入 request->user_id)
|
||||
* 返回:id, username, phone, uid, name, coin, total_ticket_count
|
||||
* header: token(由 TokenMiddleware 校验并注入 request->player_id)
|
||||
*/
|
||||
public function info(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$user = UserLogic::getCachedUser($userId);
|
||||
if (empty($user)) {
|
||||
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
|
||||
@@ -99,13 +102,13 @@ class UserController extends OpenController
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取钱包余额(优先读缓存,缓存未命中时从库拉取并回写缓存)
|
||||
* 获取钱包余额(优先读缓存)
|
||||
* GET /api/user/balance
|
||||
* header: user-token(由 CheckUserTokenMiddleware 校验并注入 request->user_id)
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
*/
|
||||
public function balance(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$user = UserLogic::getCachedUser($userId);
|
||||
if (empty($user)) {
|
||||
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
|
||||
@@ -124,12 +127,12 @@ class UserController extends OpenController
|
||||
/**
|
||||
* 玩家钱包流水
|
||||
* GET /api/user/walletRecord
|
||||
* header: user-token(由 CheckUserTokenMiddleware 校验并注入 request->user_id)
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
* 参数: page 页码(默认1), limit 每页条数(默认10), create_time_min/create_time_max 创建时间范围(可选)
|
||||
*/
|
||||
public function walletRecord(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 10);
|
||||
if ($page < 1) {
|
||||
@@ -166,12 +169,12 @@ class UserController extends OpenController
|
||||
/**
|
||||
* 游玩记录
|
||||
* GET /api/user/playGameRecord
|
||||
* header: user-token(由 CheckUserTokenMiddleware 校验并注入 request->user_id)
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
* 参数: page 页码(默认1), limit 每页条数(默认10), create_time_min/create_time_max 创建时间范围(可选)
|
||||
*/
|
||||
public function playGameRecord(Request $request): Response
|
||||
{
|
||||
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 10);
|
||||
if ($page < 1) {
|
||||
|
||||
73
server/app/api/controller/v1/AuthTokenController.php
Normal file
73
server/app/api/controller/v1/AuthTokenController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\cache\AuthTokenCache;
|
||||
use app\api\controller\BaseController;
|
||||
use app\api\util\ReturnCode;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
|
||||
/**
|
||||
* 平台鉴权接口
|
||||
* 鉴权接口:/api/v1/authtoken
|
||||
* GET 参数:signature, secret, time, agent_id
|
||||
* 签名:signature = md5(agent_id.secret.time)
|
||||
*/
|
||||
class AuthTokenController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取 auth-token
|
||||
* GET 参数:signature, secret, time, agent_id
|
||||
* 返回 authtoken,后续 /api/v1/* 接口需在请求头携带 auth-token
|
||||
*/
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$agentId = trim((string) ($request->get('agent_id', '')));
|
||||
$secret = trim((string) ($request->get('secret', '')));
|
||||
$time = trim((string) ($request->get('time', '')));
|
||||
$signature = trim((string) ($request->get('signature', '')));
|
||||
|
||||
if ($agentId === '' || $secret === '' || $time === '' || $signature === '') {
|
||||
return $this->fail('缺少参数:agent_id、secret、time、signature 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$expectedSecret = config('api.auth_token_secret', '');
|
||||
if ($expectedSecret === '') {
|
||||
return $this->fail('服务端未配置 API_AUTH_TOKEN_SECRET', ReturnCode::SERVER_ERROR);
|
||||
}
|
||||
if ($secret !== $expectedSecret) {
|
||||
return $this->fail('密钥错误', ReturnCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
$timeVal = (int) $time;
|
||||
$tolerance = (int) config('api.auth_token_time_tolerance', 300);
|
||||
$now = time();
|
||||
if ($timeVal < $now - $tolerance || $timeVal > $now + $tolerance) {
|
||||
return $this->fail('时间戳已过期或无效,请同步时间', ReturnCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
$expectedSignature = md5($agentId . $secret . $time);
|
||||
if ($signature !== $expectedSignature) {
|
||||
return $this->fail('签名验证失败', ReturnCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
$exp = (int) config('api.auth_token_exp', 86400);
|
||||
$tokenResult = JwtToken::generateToken([
|
||||
'id' => 0,
|
||||
'agent_id' => $agentId,
|
||||
'plat' => 'api_auth_token',
|
||||
'access_exp' => $exp,
|
||||
]);
|
||||
$token = $tokenResult['access_token'];
|
||||
if (!AuthTokenCache::setToken($agentId, $token)) {
|
||||
return $this->fail('生成 token 失败', ReturnCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'authtoken' => $token,
|
||||
]);
|
||||
}
|
||||
}
|
||||
311
server/app/api/controller/v1/GameController.php
Normal file
311
server/app/api/controller/v1/GameController.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
|
||||
use support\think\Db;
|
||||
use app\api\controller\BaseController;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\api\cache\UserCache;
|
||||
|
||||
/**
|
||||
* 平台 v1 游戏接口
|
||||
* 请求头:auth-token
|
||||
*/
|
||||
class GameController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取游戏地址
|
||||
* 根据 username 创建登录 token(JWT),拼接游戏地址返回
|
||||
*/
|
||||
public function getGameUrl(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$password = trim((string) ($request->post('password', '123456')));
|
||||
$time = trim((string) ($request->post('time', '')));
|
||||
|
||||
if ($username === '') {
|
||||
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
if ($password === '') {
|
||||
$password = '123456';
|
||||
}
|
||||
if ($time === '') {
|
||||
$time = (string) time();
|
||||
}
|
||||
|
||||
$adminId = null;
|
||||
$agentId = trim((string) ($request->agent_id ?? ''));
|
||||
if ($agentId !== '') {
|
||||
$systemUser = SystemUser::where('agent_id', $agentId)->find();
|
||||
if ($systemUser) {
|
||||
$adminId = (int) $systemUser->id;
|
||||
}
|
||||
}
|
||||
|
||||
$lang = trim((string) ($request->post('lang', 'zh')));
|
||||
$lang = in_array($lang, ['en', 'zh'], true) ? $lang : 'zh';
|
||||
|
||||
try {
|
||||
$logic = new UserLogic();
|
||||
$result = $logic->loginByUsername($username, $password, $lang === 'en' ? 'en' : 'chs', 0.0, $time, $adminId);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$gameUrlBase = rtrim(config('api.game_url', 'dice-game.yuliao666.top'), '/');
|
||||
$tokenInUrl = str_replace('%3D', '=', urlencode($result['token']));
|
||||
$url = $gameUrlBase . '/?token=' . $tokenInUrl . '&lang=' . $lang;
|
||||
|
||||
return $this->success([
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* POST 参数:username
|
||||
* 返回 DicePlayer 中非敏感信息
|
||||
*/
|
||||
public function getPlayerInfo(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
|
||||
if ($username === '') {
|
||||
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
$hidden = ['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight', 'delete_time'];
|
||||
$info = $player->hidden($hidden)->toArray();
|
||||
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取游戏记录
|
||||
* POST 参数:username(非必填,没填则不按用户筛选), start_create_time, end_create_time(非必填,没填则不筛选时间)
|
||||
* 返回 DicePlayRecord 中非敏感信息
|
||||
*/
|
||||
public function getPlayerGameRecord(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
|
||||
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 20);
|
||||
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
if ($limit < 1 || $limit > 100) {
|
||||
$limit = 20;
|
||||
}
|
||||
|
||||
$query = DicePlayRecord::order('id', 'desc');
|
||||
|
||||
if ($username !== '') {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
return $this->success([]);
|
||||
}
|
||||
$query->where('player_id', (int) $player->id);
|
||||
}
|
||||
|
||||
if ($startCreateTime !== '') {
|
||||
$query->where('create_time', '>=', $startCreateTime);
|
||||
}
|
||||
if ($endCreateTime !== '') {
|
||||
$query->where('create_time', '<=', $endCreateTime);
|
||||
}
|
||||
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
$playerIds = array_unique(array_column($list, 'player_id'));
|
||||
if (!empty($playerIds)) {
|
||||
$players = DicePlayer::whereIn('id', $playerIds)->field('id,username,phone')->select()->toArray();
|
||||
$playerMap = [];
|
||||
foreach ($players as $p) {
|
||||
$playerMap[(int) ($p['id'] ?? 0)] = $p;
|
||||
}
|
||||
foreach ($list as &$item) {
|
||||
$item['dice_player'] = $playerMap[(int) ($item['player_id'] ?? 0)] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取钱包流水
|
||||
* POST 参数:username(非必填,没填则不按用户筛选), start_create_time, end_create_time(非必填,没填则不筛选时间)
|
||||
* 返回 DicePlayerWalletRecord 中非敏感信息
|
||||
*/
|
||||
public function getPlayerWalletRecord(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
|
||||
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 20);
|
||||
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
if ($limit < 1 || $limit > 100) {
|
||||
$limit = 20;
|
||||
}
|
||||
|
||||
$query = DicePlayerWalletRecord::order('id', 'desc');
|
||||
|
||||
if ($username !== '') {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
return $this->success([]);
|
||||
}
|
||||
$query->where('player_id', (int) $player->id);
|
||||
}
|
||||
|
||||
if ($startCreateTime !== '') {
|
||||
$query->where('create_time', '>=', $startCreateTime);
|
||||
}
|
||||
if ($endCreateTime !== '') {
|
||||
$query->where('create_time', '<=', $endCreateTime);
|
||||
}
|
||||
|
||||
$list = $query->with(['dicePlayer' => function ($q) {
|
||||
$q->field('id,username,phone');
|
||||
}])->page($page, $limit)->select()->toArray();
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户中奖券获取记录
|
||||
* POST 参数:username(非必填,没填则不按用户筛选), start_create_time, end_create_time(非必填,没填则不筛选时间)
|
||||
* 返回 DicePlayerTicketRecord 中非敏感信息
|
||||
*/
|
||||
public function getPlayerTicketRecord(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
|
||||
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
|
||||
$page = (int) $request->post('page', 1);
|
||||
$limit = (int) $request->post('limit', 20);
|
||||
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
if ($limit < 1 || $limit > 100) {
|
||||
$limit = 20;
|
||||
}
|
||||
|
||||
$query = DicePlayerTicketRecord::order('id', 'desc');
|
||||
|
||||
if ($username !== '') {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
return $this->success([]);
|
||||
}
|
||||
$query->where('player_id', (int) $player->id);
|
||||
}
|
||||
|
||||
if ($startCreateTime !== '') {
|
||||
$query->where('create_time', '>=', $startCreateTime);
|
||||
}
|
||||
if ($endCreateTime !== '') {
|
||||
$query->where('create_time', '<=', $endCreateTime);
|
||||
}
|
||||
|
||||
$list = $query->with(['dicePlayer' => function ($q) {
|
||||
$q->field('id,username,phone');
|
||||
}])->page($page, $limit)->select()->toArray();
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 钱包转入转出
|
||||
* POST 参数:username(必填), coin(转入>0 或 转出<0)
|
||||
* 创建 DicePlayerWalletRecord,type: 0=充值(coin>0), 1=提现(coin<0)
|
||||
* 返回创建的记录
|
||||
*/
|
||||
public function setPlayerWallet(Request $request): Response
|
||||
{
|
||||
$username = trim((string) ($request->post('username', '')));
|
||||
$coin = $request->post('coin');
|
||||
|
||||
if ($username === '') {
|
||||
return $this->fail('username 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
if ($coin === null || $coin === '') {
|
||||
return $this->fail('coin 不能为空', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$coinVal = (float) $coin;
|
||||
if ($coinVal === 0.0) {
|
||||
return $this->fail('coin 不能为 0', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
$walletBefore = (float) ($player->coin ?? 0);
|
||||
$walletAfter = $walletBefore + $coinVal;
|
||||
|
||||
if ($coinVal < 0 && $walletBefore < -$coinVal) {
|
||||
return $this->fail('余额不足,无法转出', ReturnCode::BUSINESS_ERROR);
|
||||
}
|
||||
|
||||
$type = $coinVal > 0 ? 0 : 1;
|
||||
$remark = $coinVal > 0 ? '充值' : '提现';
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
$player->coin = $walletAfter;
|
||||
$player->save();
|
||||
|
||||
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||
$record = DicePlayerWalletRecord::create([
|
||||
'player_id' => (int) $player->id,
|
||||
'admin_id' => $adminId,
|
||||
'coin' => $coinVal,
|
||||
'type' => $type,
|
||||
'wallet_before' => $walletBefore,
|
||||
'wallet_after' => $walletAfter,
|
||||
'total_ticket_count' => 0,
|
||||
'paid_ticket_count' => 0,
|
||||
'free_ticket_count' => 0,
|
||||
'remark' => $remark,
|
||||
'user_id' => 0,
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return $this->fail('操作失败:' . $e->getMessage(), ReturnCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 出于安全:删除该玩家相关缓存,后续 API 调用按需重建
|
||||
UserCache::deleteUser($player->id);
|
||||
if ($player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
|
||||
$recordArr = $record->toArray();
|
||||
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
|
||||
return $this->success($recordArr);
|
||||
}
|
||||
}
|
||||
53
server/app/api/lang/en.php
Normal file
53
server/app/api/lang/en.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* API 英文文案(请求头 lang=en 时使用)
|
||||
* key 为中文原文,value 为英文
|
||||
*/
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'fail' => 'Fail',
|
||||
'username、password 不能为空' => 'username and password are required',
|
||||
'请携带 token' => 'Please provide token',
|
||||
'token 无效' => 'Invalid or expired token',
|
||||
'已退出登录' => 'Logged out successfully',
|
||||
'用户不存在' => 'User not found',
|
||||
'username 不能为空' => 'username is required',
|
||||
'密码错误' => 'Wrong password',
|
||||
'账号已被禁用,无法登录' => 'Account is disabled and cannot log in',
|
||||
'购买抽奖券错误' => 'Invalid lottery ticket purchase',
|
||||
'平台币不足' => 'Insufficient balance',
|
||||
'direction 必须为 0 或 1' => 'direction must be 0 or 1',
|
||||
'当前玩家余额%s小于%s无法继续游戏' => 'Balance %s is less than %s, cannot continue',
|
||||
'服务超时,' => 'Service timeout: ',
|
||||
'没有原因' => 'Unknown reason',
|
||||
'缺少参数:agent_id、secret、time、signature 不能为空' => 'Missing parameters: agent_id, secret, time, signature are required',
|
||||
'服务端未配置 API_AUTH_TOKEN_SECRET' => 'API_AUTH_TOKEN_SECRET is not configured',
|
||||
'密钥错误' => 'Invalid secret',
|
||||
'时间戳已过期或无效,请同步时间' => 'Timestamp expired or invalid, please sync time',
|
||||
'签名验证失败' => 'Signature verification failed',
|
||||
'生成 token 失败' => 'Failed to generate token',
|
||||
'coin 不能为空' => 'coin is required',
|
||||
'coin 不能为 0' => 'coin cannot be 0',
|
||||
'余额不足,无法转出' => 'Insufficient balance to transfer',
|
||||
'操作失败:' => 'Operation failed: ',
|
||||
'服务超时,没有原因' => 'Service timeout: Unknown reason',
|
||||
// PlayStartLogic / GameLogic
|
||||
'抽奖券不足' => 'Insufficient lottery tickets',
|
||||
'奖池配置不存在' => 'Lottery config not found',
|
||||
'该方向下暂无可用路径配置' => 'No path config available for this direction',
|
||||
// UserLogic
|
||||
'手机号格式错误,仅支持 +60 开头的马来西亚号码(如 +60123456789)' => 'Invalid phone format, only +60 Malaysia numbers supported (e.g. +60123456789)',
|
||||
// TokenMiddleware / Auth (api/user/*, api/game/*)
|
||||
'请携带 auth-token' => 'Please provide auth-token',
|
||||
'auth-token 已过期' => 'auth-token expired',
|
||||
'auth-token 无效' => 'auth-token invalid',
|
||||
'auth-token 格式无效' => 'auth-token format invalid',
|
||||
'auth-token 无效或已失效' => 'auth-token invalid or expired',
|
||||
'token 已过期,请重新登录' => 'Token expired, please login again',
|
||||
'token 格式无效' => 'Token format invalid',
|
||||
'请注册' => 'Please register',
|
||||
'请重新登录' => 'Please login again',
|
||||
'请重新登录(当前账号已在其他处登录)' => 'Please login again (account logged in elsewhere)',
|
||||
];
|
||||
@@ -27,7 +27,8 @@ class GameLogic
|
||||
|
||||
/**
|
||||
* 购买抽奖券
|
||||
* @param int $playerId 玩家ID(即 user_id)
|
||||
* 先更新 Redis 玩家信息(后续游玩从 Redis 读),再用事务更新数据库;事务失败则回滚 Redis
|
||||
* @param int $playerId 玩家ID
|
||||
* @param int $count 购买档位:1 / 5 / 10
|
||||
* @return array 更新后的 coin, total_ticket_count, paid_ticket_count, free_ticket_count
|
||||
*/
|
||||
@@ -55,59 +56,74 @@ class GameLogic
|
||||
$totalBefore = (int) ($player->total_ticket_count ?? 0);
|
||||
$paidBefore = (int) ($player->paid_ticket_count ?? 0);
|
||||
$freeBefore = (int) ($player->free_ticket_count ?? 0);
|
||||
$totalAfter = $totalBefore + $addTotal;
|
||||
$paidAfter = $paidBefore + $addPaid;
|
||||
$freeAfter = $freeBefore + $addFree;
|
||||
|
||||
Db::transaction(function () use (
|
||||
$player,
|
||||
$playerId,
|
||||
$cost,
|
||||
$coinBefore,
|
||||
$coinAfter,
|
||||
$addTotal,
|
||||
$addPaid,
|
||||
$addFree,
|
||||
$totalBefore,
|
||||
$paidBefore,
|
||||
$freeBefore
|
||||
) {
|
||||
$player->coin = $coinAfter;
|
||||
$player->total_ticket_count = $totalBefore + $addTotal;
|
||||
$player->paid_ticket_count = $paidBefore + $addPaid;
|
||||
$player->free_ticket_count = $freeBefore + $addFree;
|
||||
$player->save();
|
||||
$oldUserArr = $player->hidden(['password'])->toArray();
|
||||
$updatedUserArr = $oldUserArr;
|
||||
$updatedUserArr['coin'] = $coinAfter;
|
||||
$updatedUserArr['total_ticket_count'] = $totalAfter;
|
||||
$updatedUserArr['paid_ticket_count'] = $paidAfter;
|
||||
$updatedUserArr['free_ticket_count'] = $freeAfter;
|
||||
|
||||
// 钱包流水记录
|
||||
DicePlayerWalletRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'coin' => -$cost,
|
||||
'type' => self::WALLET_TYPE_BUY_DRAW,
|
||||
'wallet_before' => $coinBefore,
|
||||
'wallet_after' => $coinAfter,
|
||||
'total_ticket_count' => $addTotal,
|
||||
'paid_ticket_count' => $addPaid,
|
||||
'free_ticket_count' => $addFree,
|
||||
'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)",
|
||||
]);
|
||||
UserCache::setUser($playerId, $updatedUserArr);
|
||||
|
||||
// 抽奖券获取记录
|
||||
DicePlayerTicketRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'use_coins' => $cost,
|
||||
'total_ticket_count' => $addTotal,
|
||||
'paid_ticket_count' => $addPaid,
|
||||
'free_ticket_count' => $addFree,
|
||||
'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)",
|
||||
]);
|
||||
});
|
||||
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||
try {
|
||||
Db::transaction(function () use (
|
||||
$player,
|
||||
$playerId,
|
||||
$adminId,
|
||||
$cost,
|
||||
$coinBefore,
|
||||
$coinAfter,
|
||||
$addTotal,
|
||||
$addPaid,
|
||||
$addFree,
|
||||
$totalAfter,
|
||||
$paidAfter,
|
||||
$freeAfter
|
||||
) {
|
||||
$player->coin = $coinAfter;
|
||||
$player->total_ticket_count = $totalAfter;
|
||||
$player->paid_ticket_count = $paidAfter;
|
||||
$player->free_ticket_count = $freeAfter;
|
||||
$player->save();
|
||||
|
||||
$updated = DicePlayer::find($playerId);
|
||||
$userArr = $updated->hidden(['password'])->toArray();
|
||||
UserCache::setUser($playerId, $userArr);
|
||||
DicePlayerWalletRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId,
|
||||
'coin' => -$cost,
|
||||
'type' => self::WALLET_TYPE_BUY_DRAW,
|
||||
'wallet_before' => $coinBefore,
|
||||
'wallet_after' => $coinAfter,
|
||||
'total_ticket_count' => $addTotal,
|
||||
'paid_ticket_count' => $addPaid,
|
||||
'free_ticket_count' => $addFree,
|
||||
'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)",
|
||||
]);
|
||||
|
||||
DicePlayerTicketRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId,
|
||||
'use_coins' => $cost,
|
||||
'total_ticket_count' => $addTotal,
|
||||
'paid_ticket_count' => $addPaid,
|
||||
'free_ticket_count' => $addFree,
|
||||
'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)",
|
||||
]);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
UserCache::setUser($playerId, $oldUserArr);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return [
|
||||
'coin' => (float) $updated->coin,
|
||||
'total_ticket_count' => (int) $updated->total_ticket_count,
|
||||
'paid_ticket_count' => (int) $updated->paid_ticket_count,
|
||||
'free_ticket_count' => (int) $updated->free_ticket_count,
|
||||
'coin' => (float) $coinAfter,
|
||||
'total_ticket_count' => (int) $totalAfter,
|
||||
'paid_ticket_count' => (int) $paidAfter,
|
||||
'free_ticket_count' => (int) $freeAfter,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,15 @@ namespace app\api\logic;
|
||||
|
||||
use app\api\cache\UserCache;
|
||||
use app\api\service\LotteryService;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use support\Log;
|
||||
use support\think\Cache;
|
||||
use support\think\Db;
|
||||
|
||||
@@ -33,11 +35,17 @@ class PlayStartLogic
|
||||
|
||||
/** 开启对局最低余额 = |DiceRewardConfig 最小 real_ev + 100| */
|
||||
private const MIN_COIN_EXTRA = 100;
|
||||
/** 豹子号中大奖额外平台币(无 BIGWIN 配置时兜底) */
|
||||
private const SUPER_WIN_BONUS = 500;
|
||||
/** 可触发超级大奖的 grid_number(5=全1 10=全2 15=全3 20=全4 25=全5 30=全6) */
|
||||
private const SUPER_WIN_GRID_NUMBERS = [5, 10, 15, 20, 25, 30];
|
||||
/** 5 和 30 抽到即豹子,不参与 BIGWIN 权重判定;10/15/20/25 按 BIGWIN weight 判定是否豹子 */
|
||||
private const SUPER_WIN_ALWAYS_GRID_NUMBERS = [5, 30];
|
||||
|
||||
/**
|
||||
* 执行一局游戏
|
||||
* @param int $playerId 玩家ID
|
||||
* @param int $direction 方向 0=无/顺时针 1=中奖/逆时针(前端 rediction)
|
||||
* @param int $direction 方向 0=无/顺时针 1=中奖/逆时针(前端 direction)
|
||||
* @return array 成功返回 DicePlayRecord 数据;余额不足时抛 ApiException,message 为约定文案
|
||||
*/
|
||||
public function run(int $playerId, int $direction): array
|
||||
@@ -47,11 +55,11 @@ class PlayStartLogic
|
||||
throw new ApiException('用户不存在');
|
||||
}
|
||||
|
||||
$minEv = (float) DiceRewardConfig::min('real_ev');
|
||||
$minEv = DiceRewardConfig::getCachedMinRealEv();
|
||||
$minCoin = abs($minEv + self::MIN_COIN_EXTRA);
|
||||
$coin = (float) $player->coin;
|
||||
if ($coin < $minCoin) {
|
||||
throw new ApiException('当前玩家余额小于DiceRewardConfigMin.real_ev+100无法继续游戏');
|
||||
throw new ApiException('当前玩家余额'.$coin.'小于'.$minCoin.'无法继续游戏');
|
||||
}
|
||||
|
||||
$paid = (int) ($player->paid_ticket_count ?? 0);
|
||||
@@ -63,40 +71,129 @@ class PlayStartLogic
|
||||
$lotteryService = LotteryService::getOrCreate($playerId);
|
||||
$ticketType = LotteryService::drawTicketType($paid, $free);
|
||||
$config = $ticketType === self::LOTTERY_TYPE_PAID
|
||||
? ($lotteryService->getConfigType0Id() ? DiceLotteryConfig::find($lotteryService->getConfigType0Id()) : null)
|
||||
: ($lotteryService->getConfigType1Id() ? DiceLotteryConfig::find($lotteryService->getConfigType1Id()) : null);
|
||||
? ($lotteryService->getConfigType0Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType0Id()) : null)
|
||||
: ($lotteryService->getConfigType1Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType1Id()) : null);
|
||||
// 未找到付费/免费对应配置时,统一回退到 type=0 的彩金池
|
||||
if (!$config) {
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
}
|
||||
if (!$config) {
|
||||
throw new ApiException('奖池配置不存在');
|
||||
}
|
||||
|
||||
$tier = LotteryService::drawTierByWeights($config);
|
||||
$rewards = DiceRewardConfig::where('tier', $tier)->select();
|
||||
if ($rewards->isEmpty()) {
|
||||
throw new ApiException('该档位暂无奖励配置');
|
||||
// 计算当前玩家在该彩金池中的累计盈利金额:当前中奖金额(含 BIGWIN)减去抽奖券费用 100
|
||||
$playerQuery = DicePlayRecord::where('player_id', $playerId)
|
||||
->where('lottery_config_id', $config->id)
|
||||
->where('status', self::RECORD_STATUS_SUCCESS);
|
||||
$playerWinSum = (float) $playerQuery->sum('win_coin');
|
||||
$playerPlayCount = (int) $playerQuery->count();
|
||||
$playerProfitTotal = $playerWinSum - 100.0 * $playerPlayCount;
|
||||
$safetyLine = (int) ($config->safety_line ?? 0);
|
||||
// 玩家累计盈利金额达到或超过安全线时,按奖池 T*_weight 杀分;否则按玩家 T*_weight 抽档位
|
||||
$usePoolWeights = $playerProfitTotal >= $safetyLine;
|
||||
|
||||
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
$maxTierRetry = 10;
|
||||
$chosen = null;
|
||||
$tier = null;
|
||||
for ($tierAttempt = 0; $tierAttempt < $maxTierRetry; $tierAttempt++) {
|
||||
$tier = $usePoolWeights
|
||||
? LotteryService::drawTierByWeights($config)
|
||||
: LotteryService::drawTierByPlayerWeights($player);
|
||||
$tierRewards = $byTierDirection[$tier][$direction] ?? [];
|
||||
if (empty($tierRewards)) {
|
||||
Log::warning("档位 {$tier} 方向 {$direction} 无任何 DiceReward,重新摇取档位");
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$chosen = self::drawRewardByWeight($tierRewards);
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === self::EXCEPTION_WEIGHT_ALL_ZERO) {
|
||||
Log::warning("档位 {$tier} 下所有奖励权重均为 0,重新摇取档位");
|
||||
continue;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$rewardList = $rewards->all();
|
||||
$reward = $rewardList[array_rand($rewardList)];
|
||||
$realEv = (float) $reward->real_ev;
|
||||
$winCoin = 100 + $realEv; // 赢取平台币 = 100 + DiceRewardConfig.real_ev
|
||||
$gridNumber = (int) $reward->grid_number;
|
||||
$startIndex = (int) Cache::get(LotteryService::getStartIndexKey($playerId), 0);
|
||||
$targetIndex = (int) $reward->id;
|
||||
$rollArray = $this->generateRollArray($gridNumber);
|
||||
if ($chosen === null) {
|
||||
Log::error("多次摇取档位后仍无有效 DiceReward");
|
||||
throw new ApiException('暂无可用奖励配置');
|
||||
}
|
||||
|
||||
$startIndex = (int) ($chosen['start_index'] ?? 0);
|
||||
$targetIndex = (int) ($chosen['end_index'] ?? 0);
|
||||
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
|
||||
$realEv = (float) ($chosen['real_ev'] ?? 0);
|
||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
|
||||
|
||||
// 豹子判定:5/30 必豹子;10/15/20/25 按 DiceRewardConfig 中 BIGWIN 该点数的 weight 判定(0-10000,10000=100%)
|
||||
$superWinCoin = 0;
|
||||
$isWin = 0;
|
||||
$bigWinRealEv = 0.0;
|
||||
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
$doSuperWin = $alwaysSuperWin;
|
||||
if (!$doSuperWin) {
|
||||
$bigWinWeight = 10000;
|
||||
if ($bigWinConfig !== null && isset($bigWinConfig['weight'])) {
|
||||
$bigWinWeight = min(10000, max(0, (int) $bigWinConfig['weight']));
|
||||
$bigWinRealEv = (float) ($bigWinConfig['real_ev'] ?? 0);
|
||||
}
|
||||
$roll = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX);
|
||||
$doSuperWin = $bigWinWeight > 0 && $roll < ($bigWinWeight / 10000.0);
|
||||
} else {
|
||||
if ($bigWinConfig !== null) {
|
||||
$bigWinRealEv = (float) ($bigWinConfig['real_ev'] ?? 0);
|
||||
}
|
||||
}
|
||||
if ($doSuperWin) {
|
||||
$rollArray = $this->getSuperWinRollArray($rollNumber);
|
||||
$isWin = 1;
|
||||
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
|
||||
// 中 BIGWIN 豹子:不走原奖励流程,不记录原奖励,不触发 T5 再来一次,仅发放豹子奖金
|
||||
$rewardWinCoin = 0;
|
||||
$realEv = 0;
|
||||
$isTierT5 = false;
|
||||
} else {
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
}
|
||||
} else {
|
||||
$rollArray = $this->generateRollArrayFromSum($rollNumber);
|
||||
}
|
||||
|
||||
Log::info(sprintf(
|
||||
'摇取点数 roll_number=%d, 方向=%d, start_index=%d, target_index=%d',
|
||||
$rollNumber,
|
||||
$direction,
|
||||
$startIndex,
|
||||
$targetIndex
|
||||
));
|
||||
$winCoin = $superWinCoin + $rewardWinCoin; // 赢取平台币 = 中大奖 + 摇色子中奖(豹子时 rewardWinCoin 已为 0)
|
||||
|
||||
$record = null;
|
||||
$configId = (int) $config->id;
|
||||
$rewardId = (int) $reward->id;
|
||||
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex; // 中豹子不记录原奖励配置 id
|
||||
$configName = (string) ($config->name ?? '');
|
||||
$isTierT5 = (string) ($reward->tier ?? '') === 'T5';
|
||||
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||
try {
|
||||
Db::transaction(function () use (
|
||||
$playerId,
|
||||
$adminId,
|
||||
$configId,
|
||||
$rewardId,
|
||||
$configName,
|
||||
$ticketType,
|
||||
$winCoin,
|
||||
$superWinCoin,
|
||||
$rewardWinCoin,
|
||||
$isWin,
|
||||
$realEv,
|
||||
$bigWinRealEv,
|
||||
$direction,
|
||||
$startIndex,
|
||||
$targetIndex,
|
||||
@@ -106,14 +203,20 @@ class PlayStartLogic
|
||||
) {
|
||||
$record = DicePlayRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
'reward_win_coin' => $rewardWinCoin,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => $rewardId,
|
||||
'start_index' => $startIndex,
|
||||
'target_index' => $targetIndex,
|
||||
'roll_array' => is_array($rollArray) ? json_encode($rollArray) : $rollArray,
|
||||
'roll_number' => is_array($rollArray) ? array_sum($rollArray) : 0,
|
||||
'lottery_name' => $configName,
|
||||
'status' => self::RECORD_STATUS_SUCCESS,
|
||||
]);
|
||||
@@ -138,46 +241,62 @@ class PlayStartLogic
|
||||
$p->total_ticket_count = (int) $p->total_ticket_count + 1;
|
||||
|
||||
DicePlayerTicketRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId,
|
||||
'free_ticket_count' => 1,
|
||||
'remark' => '中奖结果为T5',
|
||||
'remark' => '中奖结果为T5',
|
||||
]);
|
||||
}
|
||||
|
||||
$p->save();
|
||||
|
||||
// 累加彩金池盈利额度(累加值为 -real_ev)。若 dice_lottery_config 表有 ev 字段则执行
|
||||
// 玩家累计盈利底层仍使用 profit_amount 字段存储:每局按“当前中奖金额(含 BIGWIN) - 抽奖券费用 100”累加
|
||||
// 需确保表有 profit_amount 字段(见 db/dice_lottery_config_add_profit_amount.sql)
|
||||
$perPlayProfit = $winCoin - 100.0;
|
||||
$addProfit = $perPlayProfit;
|
||||
try {
|
||||
DiceLotteryConfig::where('id', $configId)->update([
|
||||
'ev' => Db::raw('IFNULL(ev,0) - ' . (float) $realEv),
|
||||
DiceLotteryPoolConfig::where('id', $configId)->update([
|
||||
'profit_amount' => Db::raw('IFNULL(profit_amount,0) + ' . (float) $addProfit),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('彩金池盈利累加失败,请确认表 dice_lottery_config 已存在 profit_amount 字段并执行 db/dice_lottery_config_add_profit_amount.sql', [
|
||||
'config_id' => $configId,
|
||||
'add_profit' => $addProfit,
|
||||
'real_ev' => $realEv,
|
||||
'bigwin_ev' => $bigWinRealEv,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
} catch (\Throwable $_) {
|
||||
}
|
||||
|
||||
DicePlayerWalletRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId,
|
||||
'coin' => $winCoin,
|
||||
'type' => self::WALLET_TYPE_DRAW,
|
||||
'wallet_before' => $coinBefore,
|
||||
'wallet_after' => $coinAfter,
|
||||
'remark' => '抽奖|play_record_id=' . $record->id,
|
||||
]);
|
||||
|
||||
Cache::set(LotteryService::getStartIndexKey($playerId), $targetIndex, 86400 * 30);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
if ($record === null) {
|
||||
try {
|
||||
$record = DicePlayRecord::create([
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $adminId ?? null,
|
||||
'lottery_config_id' => $configId ?? 0,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
'start_index' => $startIndex,
|
||||
'target_index' => 0,
|
||||
'roll_array' => '[]',
|
||||
'roll_number' => 0,
|
||||
'status' => self::RECORD_STATUS_TIMEOUT,
|
||||
]);
|
||||
} catch (\Throwable $_) {
|
||||
@@ -199,26 +318,230 @@ class PlayStartLogic
|
||||
if (isset($arr['roll_array']) && is_string($arr['roll_array'])) {
|
||||
$arr['roll_array'] = json_decode($arr['roll_array'], true) ?? [];
|
||||
}
|
||||
$arr['roll_number'] = is_array($arr['roll_array'] ?? null) ? array_sum($arr['roll_array']) : 0;
|
||||
$arr['tier'] = $tier ?? '';
|
||||
// 记录完数据后返回当前玩家余额与抽奖次数
|
||||
$arr['coin'] = $updated ? (float) $updated->coin : 0;
|
||||
$arr['total_ticket_count'] = $updated ? (int) $updated->total_ticket_count : 0;
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/** 生成 5 个 1-6 的点数,和为 grid_number(5~30),严格不超范围 */
|
||||
private function generateRollArray(int $gridNumber): array
|
||||
/** 该组配置权重均为 0 时抛出,供调用方重试 */
|
||||
private const EXCEPTION_WEIGHT_ALL_ZERO = 'REWARD_WEIGHT_ALL_ZERO';
|
||||
|
||||
/**
|
||||
* 按权重抽取一条配置:仅 weight>0 参与抽取(weight=0 不会被摇到)
|
||||
* 使用 [0, total) 浮点随机,支持最小权重 0.1%(如 weight=0.1),避免整数随机导致小权重失真
|
||||
* 全部 weight 为 0 时抛出 RuntimeException(EXCEPTION_WEIGHT_ALL_ZERO)
|
||||
*/
|
||||
private static function drawRewardByWeight(array $rewards): array
|
||||
{
|
||||
$minSum = 5;
|
||||
$maxSum = 30;
|
||||
$n = max($minSum, min($maxSum, $gridNumber));
|
||||
$dice = [1, 1, 1, 1, 1];
|
||||
$remain = $n - 5;
|
||||
while ($remain > 0) {
|
||||
$i = array_rand($dice);
|
||||
if ($dice[$i] < 6) {
|
||||
$add = min($remain, 6 - $dice[$i]);
|
||||
$dice[$i] += $add;
|
||||
$remain -= $add;
|
||||
if (empty($rewards)) {
|
||||
throw new \InvalidArgumentException('rewards 不能为空');
|
||||
}
|
||||
$candidateWeights = [];
|
||||
foreach ($rewards as $i => $row) {
|
||||
$w = isset($row['weight']) ? (float) $row['weight'] : 0.0;
|
||||
if ($w > 0) {
|
||||
$candidateWeights[$i] = $w;
|
||||
}
|
||||
}
|
||||
shuffle($dice);
|
||||
return $dice;
|
||||
$total = (float) array_sum($candidateWeights);
|
||||
if ($total > 0) {
|
||||
$r = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX) * $total;
|
||||
$acc = 0.0;
|
||||
foreach ($candidateWeights as $i => $w) {
|
||||
$acc += $w;
|
||||
if ($r < $acc) {
|
||||
return $rewards[$i];
|
||||
}
|
||||
}
|
||||
return $rewards[array_key_last($candidateWeights)];
|
||||
}
|
||||
throw new \RuntimeException(self::EXCEPTION_WEIGHT_ALL_ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据摇取点数(5-30)生成 5 个色子数组,每个 1-6,总和为 $sum
|
||||
* @return int[] 如 [1,2,3,4,5]
|
||||
*/
|
||||
private function generateRollArrayFromSum(int $sum): array
|
||||
{
|
||||
$sum = max(5, min(30, $sum));
|
||||
$arr = [1, 1, 1, 1, 1];
|
||||
$remain = $sum - 5;
|
||||
for ($i = 0; $i < $remain; $i++) {
|
||||
$candidates = array_keys(array_filter($arr, function ($v) {
|
||||
return $v < 6;
|
||||
}));
|
||||
if (empty($candidates)) {
|
||||
break;
|
||||
}
|
||||
$idx = $candidates[random_int(0, count($candidates) - 1)];
|
||||
$arr[$idx]++;
|
||||
}
|
||||
shuffle($arr);
|
||||
return array_values($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 豹子组合:5->[1,1,1,1,1],10->[2,2,2,2,2],15->[3,3,3,3,3],20->[4,4,4,4,4],25->[5,5,5,5,5],30->[6,6,6,6,6]
|
||||
* @return int[]
|
||||
*/
|
||||
private function getSuperWinRollArray(int $gridNumber): array
|
||||
{
|
||||
if ($gridNumber === 30) {
|
||||
return array_fill(0, 5, 6);
|
||||
}
|
||||
$n = (int) ($gridNumber / 5);
|
||||
$n = max(1, min(5, $n));
|
||||
return array_fill(0, 5, $n);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成总和为 $sum 且非豹子的 5 个色子(1-6);sum=5 时仅 [1,1,1,1,1] 可能,仍返回该组合
|
||||
* @return int[]
|
||||
*/
|
||||
private function generateNonSuperWinRollArrayWithSum(int $sum): array
|
||||
{
|
||||
$sum = max(5, min(30, $sum));
|
||||
$super = $this->getSuperWinRollArray($sum);
|
||||
if ($sum === 5) {
|
||||
return $super;
|
||||
}
|
||||
$arr = $super;
|
||||
$maxAttempts = 20;
|
||||
for ($a = 0; $a < $maxAttempts; $a++) {
|
||||
$idx = random_int(0, count($arr) - 1);
|
||||
$j = random_int(0, count($arr) - 1);
|
||||
if ($idx === $j) {
|
||||
$j = ($j + 1) % 5;
|
||||
}
|
||||
$i = $idx;
|
||||
if ($arr[$i] >= 2 && $arr[$j] <= 5) {
|
||||
$arr[$i]--;
|
||||
$arr[$j]++;
|
||||
shuffle($arr);
|
||||
return array_values($arr);
|
||||
}
|
||||
if ($arr[$i] <= 5 && $arr[$j] >= 2) {
|
||||
$arr[$i]++;
|
||||
$arr[$j]--;
|
||||
shuffle($arr);
|
||||
return array_values($arr);
|
||||
}
|
||||
}
|
||||
return $this->generateRollArrayFromSum($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟一局抽奖(不写库、不扣玩家),用于权重测试写入 dice_play_record_test
|
||||
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig|null $config 奖池配置,自定义档位时可为 null
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @param int $lotteryType 0=付费 1=免费
|
||||
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
|
||||
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier(用于统计档位概率)
|
||||
*/
|
||||
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, ?array $customTierWeights = null): array
|
||||
{
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
$maxTierRetry = 10;
|
||||
$chosen = null;
|
||||
$tier = null;
|
||||
for ($tierAttempt = 0; $tierAttempt < $maxTierRetry; $tierAttempt++) {
|
||||
if ($customTierWeights !== null && $customTierWeights !== []) {
|
||||
$tier = LotteryService::drawTierByWeightsFromArray($customTierWeights);
|
||||
} else {
|
||||
if ($config === null) {
|
||||
throw new \RuntimeException('模拟抽奖:未提供奖池配置或自定义档位权重');
|
||||
}
|
||||
$tier = LotteryService::drawTierByWeights($config);
|
||||
}
|
||||
$tierRewards = $byTierDirection[$tier][$direction] ?? [];
|
||||
if (empty($tierRewards)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$chosen = self::drawRewardByWeight($tierRewards);
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === self::EXCEPTION_WEIGHT_ALL_ZERO) {
|
||||
continue;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($chosen === null) {
|
||||
throw new \RuntimeException('模拟抽奖:无可用奖励配置');
|
||||
}
|
||||
|
||||
$startIndex = (int) ($chosen['start_index'] ?? 0);
|
||||
$targetIndex = (int) ($chosen['end_index'] ?? 0);
|
||||
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
|
||||
$realEv = (float) ($chosen['real_ev'] ?? 0);
|
||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
|
||||
|
||||
$superWinCoin = 0;
|
||||
$isWin = 0;
|
||||
$bigWinRealEv = 0.0;
|
||||
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
$doSuperWin = $alwaysSuperWin;
|
||||
if (!$doSuperWin) {
|
||||
$bigWinWeight = 10000;
|
||||
if ($bigWinConfig !== null && isset($bigWinConfig['weight'])) {
|
||||
$bigWinWeight = min(10000, max(0, (int) $bigWinConfig['weight']));
|
||||
}
|
||||
$roll = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX);
|
||||
$doSuperWin = $bigWinWeight > 0 && $roll < ($bigWinWeight / 10000.0);
|
||||
}
|
||||
if ($bigWinConfig !== null && isset($bigWinConfig['real_ev'])) {
|
||||
$bigWinRealEv = (float) $bigWinConfig['real_ev'];
|
||||
}
|
||||
if ($doSuperWin) {
|
||||
$rollArray = $this->getSuperWinRollArray($rollNumber);
|
||||
$isWin = 1;
|
||||
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
|
||||
$rewardWinCoin = 0;
|
||||
} else {
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
}
|
||||
} else {
|
||||
$rollArray = $this->generateRollArrayFromSum($rollNumber);
|
||||
}
|
||||
|
||||
$winCoin = $superWinCoin + $rewardWinCoin;
|
||||
$configId = $config !== null ? (int) $config->id : 0;
|
||||
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
|
||||
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
|
||||
$costRealEv = $realEv + ($isWin === 1 ? $bigWinRealEv : 0.0);
|
||||
|
||||
return [
|
||||
'player_id' => 0,
|
||||
'admin_id' => 0,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => $lotteryType,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
'reward_win_coin' => $rewardWinCoin,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => $rewardId,
|
||||
'start_index' => $startIndex,
|
||||
'target_index' => $targetIndex,
|
||||
'roll_array' => json_encode($rollArray),
|
||||
'roll_number' => array_sum($rollArray),
|
||||
'lottery_name' => $configName,
|
||||
'status' => self::RECORD_STATUS_SUCCESS,
|
||||
'tier' => $tier,
|
||||
'roll_number_for_count' => $rollNumber,
|
||||
'real_ev' => $realEv,
|
||||
'bigwin_real_ev' => $isWin === 1 ? $bigWinRealEv : 0.0,
|
||||
'cost_ev' => $costRealEv,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,78 +33,6 @@ class UserLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录:手机号 + 密码,返回用户信息与 user-token,并写入 Redis 缓存
|
||||
*/
|
||||
public function login(string $phone, string $password): array
|
||||
{
|
||||
self::validatePhone($phone);
|
||||
|
||||
$user = DicePlayer::where('phone', $phone)->find();
|
||||
if (!$user) {
|
||||
throw new ApiException('手机号未注册');
|
||||
}
|
||||
if ((int) $user->status !== self::STATUS_NORMAL) {
|
||||
throw new ApiException('账号已被禁用');
|
||||
}
|
||||
$hashed = $this->hashPassword($password);
|
||||
if ($user->password !== $hashed) {
|
||||
throw new ApiException('密码错误');
|
||||
}
|
||||
|
||||
$userArr = $user->hidden(['password'])->toArray();
|
||||
UserCache::setUser((int) $user->id, $userArr);
|
||||
|
||||
$userToken = $this->generateUserToken((int) $user->id);
|
||||
// 同一用户只保留最新一次登录的 token,旧 token 自动失效
|
||||
UserCache::setCurrentUserToken((int) $user->id, $userToken);
|
||||
return [
|
||||
'user' => $userArr,
|
||||
'user-token' => $userToken,
|
||||
'user_id' => (int) $user->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册:手机号 + 密码(+60),创建玩家并返回用户信息与 user-token,写入 Redis
|
||||
*/
|
||||
public function register(string $phone, string $password, ?string $nickname = null): array
|
||||
{
|
||||
self::validatePhone($phone);
|
||||
|
||||
if (strlen($password) < 6) {
|
||||
throw new ApiException('密码至少 6 位');
|
||||
}
|
||||
|
||||
$exists = DicePlayer::where('phone', $phone)->find();
|
||||
if ($exists) {
|
||||
throw new ApiException('该手机号已注册');
|
||||
}
|
||||
|
||||
$user = new DicePlayer();
|
||||
$user->phone = $phone;
|
||||
$user->username = $phone;
|
||||
if ($nickname !== null && $nickname !== '') {
|
||||
$user->name = $nickname;
|
||||
}
|
||||
// name 未传时由 DicePlayer::onBeforeInsert 默认设为 uid
|
||||
$user->password = $this->hashPassword($password);
|
||||
$user->status = self::STATUS_NORMAL;
|
||||
$user->save();
|
||||
|
||||
$userArr = $user->hidden(['password'])->toArray();
|
||||
UserCache::setUser((int) $user->id, $userArr);
|
||||
|
||||
$userToken = $this->generateUserToken((int) $user->id);
|
||||
// 同一用户只保留最新一次登录的 token,旧 token 自动失效
|
||||
UserCache::setCurrentUserToken((int) $user->id, $userToken);
|
||||
return [
|
||||
'user' => $userArr,
|
||||
'user-token' => $userToken,
|
||||
'user_id' => (int) $user->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 DicePlayerLogic 一致的密码加密:md5(salt . password)
|
||||
*/
|
||||
@@ -114,97 +42,92 @@ class UserLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 user-token(JWT,plat=api_user,id=user_id)
|
||||
* 登录(JSON:username, password, lang, coin, time)
|
||||
* 存在则校验密码并更新 coin(累加);不存在则创建用户并写入 coin。
|
||||
* 将会话写入 Redis,返回 token 与前端连接地址。
|
||||
*
|
||||
* @param int|null $adminId 创建新用户时关联的后台管理员ID(sa_system_user.id),可选
|
||||
*/
|
||||
private function generateUserToken(int $userId): string
|
||||
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null): array
|
||||
{
|
||||
$exp = config('api.user_token_exp', 604800);
|
||||
$result = JwtToken::generateToken([
|
||||
'id' => $userId,
|
||||
'plat' => 'api_user',
|
||||
$username = trim($username);
|
||||
if ($username === '') {
|
||||
throw new ApiException('username 不能为空');
|
||||
}
|
||||
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if ($player) {
|
||||
if ((int) ($player->status ?? 1) === 0) {
|
||||
throw new ApiException('账号已被禁用,无法登录');
|
||||
}
|
||||
$hashed = $this->hashPassword($password);
|
||||
if ($player->password !== $hashed) {
|
||||
throw new ApiException('密码错误');
|
||||
}
|
||||
$currentCoin = (float) $player->coin;
|
||||
$player->coin = $currentCoin + $coin;
|
||||
$player->save();
|
||||
} else {
|
||||
$player = new DicePlayer();
|
||||
$player->username = $username;
|
||||
$player->phone = $username;
|
||||
$player->password = $this->hashPassword($password);
|
||||
$player->status = self::STATUS_NORMAL;
|
||||
$player->coin = $coin;
|
||||
if ($adminId !== null && $adminId > 0) {
|
||||
$player->admin_id = $adminId;
|
||||
}
|
||||
$player->save();
|
||||
}
|
||||
|
||||
$exp = (int) config('api.session_expire', 604800);
|
||||
$tokenResult = JwtToken::generateToken([
|
||||
'id' => (int) $player->id,
|
||||
'username' => $username,
|
||||
'plat' => 'api_login',
|
||||
'access_exp' => $exp,
|
||||
]);
|
||||
return $result['access_token'];
|
||||
$token = $tokenResult['access_token'];
|
||||
UserCache::setSessionByUsername($username, $token);
|
||||
|
||||
$userArr = $player->hidden(['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
|
||||
UserCache::setUser((int) $player->id, $userArr);
|
||||
UserCache::setPlayerByUsername($username, $userArr);
|
||||
|
||||
$baseUrl = rtrim(config('api.login_url_base', 'https://127.0.0.1:6777'), '/');
|
||||
$lang = in_array($lang, ['chs', 'en'], true) ? $lang : 'chs';
|
||||
$tokenInUrl = str_replace('%3D', '=', urlencode($token));
|
||||
$url = $baseUrl . '?token=' . $tokenInUrl . '&lang=' . $lang;
|
||||
|
||||
return [
|
||||
'url' => $url,
|
||||
'token' => $token,
|
||||
'lang' => $lang,
|
||||
'user_id' => (int) $player->id,
|
||||
'user' => $userArr,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求中解析 user-token(header: user-token 或 Authorization: Bearer)
|
||||
* @param object $request 需有 header(string $name) 方法
|
||||
* 从 JWT 中解析 username(仅解码 payload,不校验签名与过期,用于退出时清除会话)
|
||||
*/
|
||||
public static function getTokenFromRequest(object $request): string
|
||||
public static function getUsernameFromJwtPayload(string $token): ?string
|
||||
{
|
||||
$token = $request->header('user-token') ?? '';
|
||||
if ($token !== '') {
|
||||
return trim((string) $token);
|
||||
}
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
return trim(substr($auth, 7));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求获取当前用户 ID:优先 request->user_id,否则从 header 的 user-token 解析
|
||||
* 中间件未正确注入时仍可兜底解析
|
||||
* @param object $request 需有 user_id 属性及 header() 方法
|
||||
*/
|
||||
public static function getUserIdFromRequest(object $request): ?int
|
||||
{
|
||||
$id = $request->user_id ?? null;
|
||||
if ($id !== null && (int) $id > 0) {
|
||||
return (int) $id;
|
||||
}
|
||||
$token = self::getTokenFromRequest($request);
|
||||
if ($token === '') {
|
||||
$parts = explode('.', $token);
|
||||
if (count($parts) !== 3) {
|
||||
return null;
|
||||
}
|
||||
return self::getUserIdFromToken($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 user-token 获取 user_id(不写缓存,仅解析 JWT)
|
||||
* 若 token 已通过退出接口加入黑名单,返回 null
|
||||
*/
|
||||
public static function getUserIdFromToken(string $userToken): ?int
|
||||
{
|
||||
if (UserCache::isTokenBlacklisted($userToken)) {
|
||||
$payload = base64_decode(strtr($parts[1], '-_', '+/'), true);
|
||||
if ($payload === false) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $userToken);
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if (($extend['plat'] ?? '') !== 'api_user') {
|
||||
return null;
|
||||
}
|
||||
$id = $extend['id'] ?? null;
|
||||
if ($id === null) {
|
||||
return null;
|
||||
}
|
||||
$userId = (int) $id;
|
||||
// 同一用户只允许当前登记的 token 生效,重新登录/注册后旧 token 失效
|
||||
if (!UserCache::isCurrentUserToken($userId, $userToken)) {
|
||||
return null;
|
||||
}
|
||||
return $userId;
|
||||
} catch (\Throwable $e) {
|
||||
$data = json_decode($payload, true);
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录:将当前 user-token 加入黑名单,使该 token 失效
|
||||
*/
|
||||
public static function logout(string $userToken): bool
|
||||
{
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $userToken);
|
||||
$exp = (int) ($decoded['exp'] ?? 0);
|
||||
$ttl = $exp > time() ? $exp - time() : 86400;
|
||||
return UserCache::addTokenToBlacklist($userToken, $ttl);
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
$extend = $data['extend'] ?? $data;
|
||||
$username = $extend['username'] ?? null;
|
||||
return $username !== null ? trim((string) $username) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
58
server/app/api/middleware/AuthTokenMiddleware.php
Normal file
58
server/app/api/middleware/AuthTokenMiddleware.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\middleware;
|
||||
|
||||
use app\api\cache\AuthTokenCache;
|
||||
use app\api\util\ReturnCode;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
use Tinywan\Jwt\Exception\JwtTokenException;
|
||||
use Tinywan\Jwt\Exception\JwtTokenExpiredException;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
|
||||
/**
|
||||
* 校验 auth-token 请求头(JWT)
|
||||
* 用于 /api/v1/* 接口(除 /api/v1/authtoken 外)
|
||||
* 请求头需携带 auth-token,通过后注入 request->agent_id
|
||||
*/
|
||||
class AuthTokenMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$token = $request->header('auth-token');
|
||||
$token = $token !== null ? trim((string) $token) : '';
|
||||
if ($token === '') {
|
||||
throw new ApiException('请携带 auth-token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $token);
|
||||
} catch (JwtTokenExpiredException $e) {
|
||||
throw new ApiException('auth-token 已过期', ReturnCode::TOKEN_INVALID);
|
||||
} catch (JwtTokenException $e) {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
} catch (\Throwable $e) {
|
||||
throw new ApiException('auth-token 格式无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if ((string) ($extend['plat'] ?? '') !== 'api_auth_token') {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
$agentId = trim((string) ($extend['agent_id'] ?? ''));
|
||||
if ($agentId === '') {
|
||||
throw new ApiException('auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$currentToken = AuthTokenCache::getTokenByAgentId($agentId);
|
||||
if ($currentToken === null || $currentToken !== $token) {
|
||||
throw new ApiException('auth-token 无效或已失效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$request->agent_id = $agentId;
|
||||
return $handler($request);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\middleware;
|
||||
|
||||
use support\Log;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
use Tinywan\Jwt\Exception\JwtTokenException;
|
||||
use Tinywan\Jwt\Exception\JwtTokenExpiredException;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\api\cache\AuthTokenCache;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
|
||||
/**
|
||||
* 仅校验 auth-token 请求头
|
||||
* 白名单路径(如 /api/authToken)不校验,其它接口必须携带有效 auth-token 或 Authorization: Bearer <token>,且必须通过 JWT 签名与 plat=api 校验
|
||||
*/
|
||||
class CheckAuthTokenMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/** 不需要 auth-token 的路径 */
|
||||
private const WHITELIST = [
|
||||
'api/authToken',
|
||||
];
|
||||
|
||||
/** JWT 至少为 xxx.yyy.zzz 三段 */
|
||||
private const JWT_PARTS_MIN = 3;
|
||||
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$path = trim((string) $request->path(), '/');
|
||||
if ($this->isWhitelist($path)) {
|
||||
return $handler($request);
|
||||
}
|
||||
|
||||
$token = $this->getAuthTokenFromRequest($request);
|
||||
if ($token === '') {
|
||||
throw new ApiException('请携带 auth-token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!$this->looksLikeJwt($token)) {
|
||||
throw new ApiException('auth-token 格式无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$decoded = $this->verifyAuthToken($token);
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if (($extend['plat'] ?? '') !== 'api') {
|
||||
throw new ApiException('auth-token 无效(非 API 凭证)', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
// 同一设备只允许一个 auth-token 生效,非当前 token 视为已失效
|
||||
$device = (string) ($extend['device'] ?? '');
|
||||
if ($device !== '' && !AuthTokenCache::isCurrentToken($device, $token)) {
|
||||
throw new ApiException('auth-token 已失效(该设备已签发新凭证,请使用新 auth-token)', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
return $handler($request);
|
||||
}
|
||||
|
||||
private function getAuthTokenFromRequest(Request $request): string
|
||||
{
|
||||
$token = $request->header('auth-token');
|
||||
if ($token !== null && $token !== '') {
|
||||
return trim((string) $token);
|
||||
}
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
return trim(substr($auth, 7));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
private function looksLikeJwt(string $token): bool
|
||||
{
|
||||
$parts = explode('.', $token);
|
||||
return count($parts) >= self::JWT_PARTS_MIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 auth-token 有效性(签名、过期、iss 等),无效或过期必抛 ApiException
|
||||
*/
|
||||
private function verifyAuthToken(string $token): array
|
||||
{
|
||||
try {
|
||||
return JwtToken::verify(1, $token);
|
||||
} catch (JwtTokenExpiredException $e) {
|
||||
Log::error('auth-token 已过期, 报错信息' . $e);
|
||||
throw new ApiException('auth-token 已过期', ReturnCode::TOKEN_INVALID);
|
||||
} catch (JwtTokenException $e) {
|
||||
Log::error('auth-token 无效, 报错信息' . $e);
|
||||
throw new ApiException($e->getMessage() ?: 'auth-token 无效', ReturnCode::TOKEN_INVALID);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('auth-token 校验失败, 报错信息' . $e);
|
||||
throw new ApiException('auth-token 校验失败', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
private function isWhitelist(string $path): bool
|
||||
{
|
||||
foreach (self::WHITELIST as $prefix) {
|
||||
if ($path === $prefix || str_starts_with($path, $prefix . '/')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\middleware;
|
||||
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
|
||||
/**
|
||||
* 校验 user-token 请求头
|
||||
* 从 header 读取 user-token 或 Authorization: Bearer <user-token>,校验通过后将 user_id、userToken 写入 request 供控制器使用
|
||||
*/
|
||||
class CheckUserTokenMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$token = $request->header('user-token');
|
||||
if (empty($token)) {
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
$token = trim(substr($auth, 7));
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
throw new ApiException('请携带 user-token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
$userId = UserLogic::getUserIdFromToken($token);
|
||||
if ($userId === null) {
|
||||
throw new ApiException('user-token 无效或已过期', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$request->user_id = $userId;
|
||||
$request->userToken = $token;
|
||||
|
||||
return $handler($request);
|
||||
}
|
||||
}
|
||||
87
server/app/api/middleware/TokenMiddleware.php
Normal file
87
server/app/api/middleware/TokenMiddleware.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\middleware;
|
||||
|
||||
use app\api\cache\UserCache;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
use Tinywan\Jwt\Exception\JwtTokenException;
|
||||
use Tinywan\Jwt\Exception\JwtTokenExpiredException;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
|
||||
/**
|
||||
* 校验 token 请求头(JWT)
|
||||
* 解码 JWT 取 username,与 Redis 中当前有效 token 比对;不一致则旧 token 已失效,请重新登录
|
||||
* 通过后注入 request->player_id、request->player
|
||||
*/
|
||||
class TokenMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$token = $request->header('token');
|
||||
if ($token === null || $token === '') {
|
||||
$auth = $request->header('authorization');
|
||||
if ($auth && stripos($auth, 'Bearer ') === 0) {
|
||||
$token = trim(substr($auth, 7));
|
||||
}
|
||||
}
|
||||
$token = $token !== null ? trim((string) $token) : '';
|
||||
if ($token === '') {
|
||||
throw new ApiException('请携带 token', ReturnCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = JwtToken::verify(1, $token);
|
||||
} catch (JwtTokenExpiredException $e) {
|
||||
throw new ApiException('token 已过期,请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
} catch (JwtTokenException $e) {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
} catch (\Throwable $e) {
|
||||
throw new ApiException('token 格式无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$extend = $decoded['extend'] ?? [];
|
||||
if ((string) ($extend['plat'] ?? '') !== 'api_login') {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
$username = trim((string) ($extend['username'] ?? ''));
|
||||
if ($username === '') {
|
||||
throw new ApiException('token 无效', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
$currentToken = UserCache::getSessionTokenByUsername($username);
|
||||
if ($currentToken === null || $currentToken === '') {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
throw new ApiException('请注册', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
throw new ApiException('请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
if ($currentToken !== $token) {
|
||||
throw new ApiException('请重新登录(当前账号已在其他处登录)', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
|
||||
// 优先从 Redis 缓存取玩家,避免每次请求都查库
|
||||
$player = null;
|
||||
$cached = UserCache::getPlayerByUsername($username);
|
||||
if ($cached !== null && isset($cached['id'])) {
|
||||
$player = (new DicePlayer())->data($cached, true);
|
||||
}
|
||||
if ($player === null) {
|
||||
$player = DicePlayer::where('username', $username)->find();
|
||||
if (!$player) {
|
||||
UserCache::deleteSessionByUsername($username);
|
||||
throw new ApiException('请重新登录', ReturnCode::TOKEN_INVALID);
|
||||
}
|
||||
UserCache::setPlayerByUsername($username, $player->hidden(['password'])->toArray());
|
||||
}
|
||||
$request->player_id = (int) $player->id;
|
||||
$request->player = $player;
|
||||
return $handler($request);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\api\service;
|
||||
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use support\think\Cache;
|
||||
|
||||
@@ -19,7 +19,7 @@ class LotteryService
|
||||
private int $playerId;
|
||||
private ?int $configType0Id = null;
|
||||
private ?int $configType1Id = null;
|
||||
/** @var array{t1_wight?:int,t2_wight?:int,t3_wight?:int,t4_wight?:int,t5_wight?:int} */
|
||||
/** @var array{t1_weight?:int,t2_weight?:int,t3_weight?:int,t4_weight?:int,t5_weight?:int} */
|
||||
private array $playerWeights = [];
|
||||
|
||||
public function __construct(int $playerId)
|
||||
@@ -37,7 +37,7 @@ class LotteryService
|
||||
return self::REDIS_KEY_START_INDEX . $playerId;
|
||||
}
|
||||
|
||||
/** 从 Redis 加载或根据玩家与 DiceLotteryConfig 创建并保存 */
|
||||
/** 从 Redis 加载或根据玩家与 DiceLotteryPoolConfig 创建并保存 */
|
||||
public static function getOrCreate(int $playerId): self
|
||||
{
|
||||
$key = self::getRedisKey($playerId);
|
||||
@@ -56,17 +56,17 @@ class LotteryService
|
||||
if (!$player) {
|
||||
throw new \RuntimeException('玩家不存在');
|
||||
}
|
||||
$config0 = DiceLotteryConfig::where('type', 0)->find();
|
||||
$config1 = DiceLotteryConfig::where('type', 1)->find();
|
||||
$config0 = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
$config1 = DiceLotteryPoolConfig::where('type', 1)->find();
|
||||
$s = new self($playerId);
|
||||
$s->configType0Id = $config0 ? (int) $config0->id : null;
|
||||
$s->configType1Id = $config1 ? (int) $config1->id : null;
|
||||
$s->playerWeights = [
|
||||
't1_wight' => (int) ($player->t1_wight ?? 0),
|
||||
't2_wight' => (int) ($player->t2_wight ?? 0),
|
||||
't3_wight' => (int) ($player->t3_wight ?? 0),
|
||||
't4_wight' => (int) ($player->t4_wight ?? 0),
|
||||
't5_wight' => (int) ($player->t5_wight ?? 0),
|
||||
't1_weight' => (int) ($player->t1_weight ?? 0),
|
||||
't2_weight' => (int) ($player->t2_weight ?? 0),
|
||||
't3_weight' => (int) ($player->t3_weight ?? 0),
|
||||
't4_weight' => (int) ($player->t4_weight ?? 0),
|
||||
't5_weight' => (int) ($player->t5_weight ?? 0),
|
||||
];
|
||||
$s->save();
|
||||
return $s;
|
||||
@@ -83,22 +83,59 @@ class LotteryService
|
||||
Cache::set($key, json_encode($data), self::EXPIRE);
|
||||
}
|
||||
|
||||
/** 根据奖池配置的 t1_wight..t5_wight 权重随机抽取档位 T1-T5 */
|
||||
public static function drawTierByWeights(DiceLotteryConfig $config): string
|
||||
/** 根据奖池配置的 t1_weight..t5_weight 权重随机抽取档位 T1-T5 */
|
||||
public static function drawTierByWeights(DiceLotteryPoolConfig $config): string
|
||||
{
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$weights = [
|
||||
(int) ($config->t1_wight ?? 0),
|
||||
(int) ($config->t2_wight ?? 0),
|
||||
(int) ($config->t3_wight ?? 0),
|
||||
(int) ($config->t4_wight ?? 0),
|
||||
(int) ($config->t5_wight ?? 0),
|
||||
(int) ($config->t1_weight ?? 0),
|
||||
(int) ($config->t2_weight ?? 0),
|
||||
(int) ($config->t3_weight ?? 0),
|
||||
(int) ($config->t4_weight ?? 0),
|
||||
(int) ($config->t5_weight ?? 0),
|
||||
];
|
||||
return self::drawTierByWeightArray($tiers, $weights);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据玩家 t1_weight~t5_weight 权重随机抽取中奖档位 T1-T5
|
||||
* t1_weight=T1, t2_weight=T2, t3_weight=T3, t4_weight=T4, t5_weight=T5
|
||||
*/
|
||||
public static function drawTierByPlayerWeights(DicePlayer $player): string
|
||||
{
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$weights = [
|
||||
(int) ($player->t1_weight ?? 0),
|
||||
(int) ($player->t2_weight ?? 0),
|
||||
(int) ($player->t3_weight ?? 0),
|
||||
(int) ($player->t4_weight ?? 0),
|
||||
(int) ($player->t5_weight ?? 0),
|
||||
];
|
||||
return self::drawTierByWeightArray($tiers, $weights);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 T1-T5 权重数组抽取档位(用于测试自定义档位概率)
|
||||
* @param array $tierWeights 如 ['T1'=>100, 'T2'=>200, ...] 或 [100,200,300,400,500]
|
||||
*/
|
||||
public static function drawTierByWeightsFromArray(array $tierWeights): string
|
||||
{
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$weights = [];
|
||||
foreach ($tiers as $i => $t) {
|
||||
$weights[] = (int) ($tierWeights[$t] ?? $tierWeights[$i] ?? 0);
|
||||
}
|
||||
return self::drawTierByWeightArray($tiers, $weights);
|
||||
}
|
||||
|
||||
/** 按档位权重数组抽取 T1-T5 */
|
||||
private static function drawTierByWeightArray(array $tiers, array $weights): string
|
||||
{
|
||||
$total = array_sum($weights);
|
||||
if ($total <= 0) {
|
||||
return $tiers[array_rand($tiers)];
|
||||
return $tiers[random_int(0, count($tiers) - 1)];
|
||||
}
|
||||
$r = mt_rand(1, $total);
|
||||
$r = random_int(1, $total);
|
||||
$acc = 0;
|
||||
foreach ($weights as $i => $w) {
|
||||
$acc += $w;
|
||||
@@ -122,7 +159,7 @@ class LotteryService
|
||||
return 0;
|
||||
}
|
||||
$total = $paid + $free;
|
||||
$r = mt_rand(1, $total);
|
||||
$r = random_int(1, $total);
|
||||
return $r <= $paid ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
72
server/app/api/util/ApiLang.php
Normal file
72
server/app/api/util/ApiLang.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\api\util;
|
||||
|
||||
use support\Request;
|
||||
|
||||
/**
|
||||
* API 多语言:根据请求头 lang(en=英文,zh=中文)翻译返回文案
|
||||
*/
|
||||
class ApiLang
|
||||
{
|
||||
private const LANG_HEADER = 'lang';
|
||||
private const LANG_EN = 'en';
|
||||
private const LANG_ZH = 'zh';
|
||||
|
||||
/** @var array<string, string>|null */
|
||||
private static ?array $enMap = null;
|
||||
|
||||
/**
|
||||
* 从请求中获取语言:lang 请求头 en=英文,zh=中文,默认 zh
|
||||
*/
|
||||
public static function getLang(?Request $request = null): string
|
||||
{
|
||||
$request = $request ?? (function_exists('request') ? request() : null);
|
||||
if ($request === null) {
|
||||
return self::LANG_ZH;
|
||||
}
|
||||
$lang = $request->header(self::LANG_HEADER);
|
||||
if ($lang !== null && $lang !== '') {
|
||||
$lang = strtolower(trim((string) $lang));
|
||||
if ($lang === self::LANG_EN) {
|
||||
return self::LANG_EN;
|
||||
}
|
||||
if ($lang === self::LANG_ZH || $lang === 'chs') {
|
||||
return self::LANG_ZH;
|
||||
}
|
||||
}
|
||||
return self::LANG_ZH;
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译文案:当前请求语言为 en 时返回英文,否则返回原文(中文)
|
||||
* @param string $message 中文或原文
|
||||
* @param Request|null $request 当前请求,不传则自动取 request()
|
||||
*/
|
||||
public static function translate(string $message, ?Request $request = null): string
|
||||
{
|
||||
$lang = self::getLang($request);
|
||||
if ($lang !== self::LANG_EN) {
|
||||
return $message;
|
||||
}
|
||||
if (self::$enMap === null) {
|
||||
$path = dirname(__DIR__) . '/lang/en.php';
|
||||
self::$enMap = is_file($path) ? (require $path) : [];
|
||||
}
|
||||
return self::$enMap[$message] ?? $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 带占位符的翻译,如 translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin])
|
||||
* 先翻译再替换(en 文案使用 %s 占位)
|
||||
*/
|
||||
public static function translateParams(string $message, array $params = [], ?Request $request = null): string
|
||||
{
|
||||
$translated = self::translate($message, $request);
|
||||
if ($params !== []) {
|
||||
$translated = sprintf($translated, ...$params);
|
||||
}
|
||||
return $translated;
|
||||
}
|
||||
}
|
||||
237
server/app/dice/controller/DiceDashboardController.php
Normal file
237
server/app/dice/controller/DiceDashboardController.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\dice\controller;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Response;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 大富翁工作台数据统计
|
||||
*/
|
||||
class DiceDashboardController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function statistics(): Response
|
||||
{
|
||||
$thisWeekStart = date('Y-m-d 00:00:00', strtotime('monday this week'));
|
||||
$thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week'));
|
||||
$lastWeekStart = date('Y-m-d 00:00:00', strtotime('monday last week'));
|
||||
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
|
||||
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
|
||||
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo);
|
||||
$playerThis = $playerQueryThis->count();
|
||||
$playerLast = $playerQueryLast->count();
|
||||
|
||||
$chargeQueryThis = DicePlayerWalletRecord::where('type', 0)
|
||||
->where('coin', '>', 0)
|
||||
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
|
||||
->where('coin', '>', 0)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo);
|
||||
$chargeThis = $chargeQueryThis->sum('coin');
|
||||
$chargeLast = $chargeQueryLast->sum('coin');
|
||||
|
||||
$withdrawQueryThis = DicePlayerWalletRecord::where('type', 1)
|
||||
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo);
|
||||
$withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)'));
|
||||
$withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)'));
|
||||
|
||||
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo);
|
||||
$playThis = $playQueryThis->count();
|
||||
$playLast = $playQueryLast->count();
|
||||
|
||||
$playerChange = $this->calcWeekChange($playerThis, $playerLast);
|
||||
$chargeChange = $this->calcWeekChange((float) $chargeThis, (float) $chargeLast);
|
||||
$withdrawChange = $this->calcWeekChange((float) $withdrawThis, (float) $withdrawLast);
|
||||
$playChange = $this->calcWeekChange($playThis, $playLast);
|
||||
|
||||
return $this->success([
|
||||
'player_count' => $playerThis,
|
||||
'player_count_change' => $playerChange,
|
||||
'charge_amount' => (float) $chargeThis,
|
||||
'charge_amount_change' => $chargeChange,
|
||||
'withdraw_amount' => (float) $withdrawThis,
|
||||
'withdraw_amount_change' => $withdrawChange,
|
||||
'play_count' => $playThis,
|
||||
'play_count_change' => $playChange,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 近期玩家充值统计(近10天每日充值金额)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function rechargeChart(): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
|
||||
$adminCondition = '';
|
||||
if ($allowedIds !== null) {
|
||||
if (empty($allowedIds)) {
|
||||
$data = [];
|
||||
foreach (range(0, 9) as $n) {
|
||||
$data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0];
|
||||
}
|
||||
$data = array_reverse($data);
|
||||
return $this->success([
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_date' => array_column($data, 'recharge_date'),
|
||||
]);
|
||||
}
|
||||
$idsStr = implode(',', array_map('intval', $allowedIds));
|
||||
$adminCondition = " AND w.admin_id IN ({$idsStr})";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
d.date AS recharge_date,
|
||||
IFNULL(SUM(w.coin), 0) AS recharge_amount
|
||||
FROM
|
||||
(SELECT CURDATE() - INTERVAL (a.N) DAY AS date
|
||||
FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3
|
||||
UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6
|
||||
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
|
||||
) d
|
||||
LEFT JOIN dice_player_wallet_record w
|
||||
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$adminCondition}
|
||||
GROUP BY d.date
|
||||
ORDER BY d.date ASC
|
||||
";
|
||||
$data = Db::query($sql);
|
||||
return $this->success([
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_date' => array_column($data, 'recharge_date'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 月度玩家充值汇总(当年1-12月每月充值金额)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function rechargeBarChart(): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
|
||||
$adminCondition = '';
|
||||
if ($allowedIds !== null) {
|
||||
if (empty($allowedIds)) {
|
||||
$data = [];
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0];
|
||||
}
|
||||
return $this->success([
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_month' => array_column($data, 'recharge_month'),
|
||||
]);
|
||||
}
|
||||
$idsStr = implode(',', array_map('intval', $allowedIds));
|
||||
$adminCondition = " AND w.admin_id IN ({$idsStr})";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
CONCAT(LPAD(m.month_num, 2, '0'), '月') AS recharge_month,
|
||||
IFNULL(SUM(w.coin), 0) AS recharge_amount
|
||||
FROM
|
||||
(SELECT 1 AS month_num UNION ALL SELECT 2 UNION ALL SELECT 3
|
||||
UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6
|
||||
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
|
||||
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12) m
|
||||
LEFT JOIN dice_player_wallet_record w
|
||||
ON YEAR(w.create_time) = YEAR(CURDATE())
|
||||
AND MONTH(w.create_time) = m.month_num
|
||||
AND w.type = 0 AND w.coin > 0 {$adminCondition}
|
||||
GROUP BY m.month_num
|
||||
ORDER BY m.month_num ASC
|
||||
";
|
||||
$data = Db::query($sql);
|
||||
return $this->success([
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_month' => array_column($data, 'recharge_month'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作台-玩家充值记录:最新50条(admin_id=当前管理员及子管理员,type=0)
|
||||
* 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function walletRecordList(): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayerWalletRecord::with([
|
||||
'dicePlayer' => function ($q) {
|
||||
$q->field('id,username');
|
||||
},
|
||||
])
|
||||
->where('type', 0)
|
||||
->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo);
|
||||
$list = $query->select();
|
||||
$rows = [];
|
||||
foreach ($list as $row) {
|
||||
$player = $row->dicePlayer;
|
||||
$rows[] = [
|
||||
'player_name' => $player ? $player->getAttr('username') : '',
|
||||
'coin' => $row->getAttr('coin'),
|
||||
'create_time' => $row->getAttr('create_time'),
|
||||
];
|
||||
}
|
||||
return $this->success($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作台-新增玩家记录:最新50条(admin_id=当前管理员及子管理员)
|
||||
* 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function newPlayerList(): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayer::field('username,coin,total_ticket_count,create_time')
|
||||
->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo);
|
||||
$list = $query->select();
|
||||
$rows = [];
|
||||
foreach ($list as $row) {
|
||||
$rows[] = [
|
||||
'name' => $row->getAttr('username'),
|
||||
'coin' => $row->getAttr('coin'),
|
||||
'total_ticket_count' => $row->getAttr('total_ticket_count'),
|
||||
];
|
||||
}
|
||||
return $this->success($rows);
|
||||
}
|
||||
|
||||
private function calcWeekChange($current, $last): float
|
||||
{
|
||||
if ($last == 0) {
|
||||
return $current > 0 ? 100.0 : 0.0;
|
||||
}
|
||||
return round((($current - $last) / $last) * 100, 1);
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,27 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\lottery_config;
|
||||
namespace app\dice\controller\config;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\lottery_config\DiceLotteryConfigLogic;
|
||||
use app\dice\validate\lottery_config\DiceLotteryConfigValidate;
|
||||
use app\dice\logic\config\DiceConfigLogic;
|
||||
use app\dice\validate\config\DiceConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 色子奖池配置控制器
|
||||
* 摇色子配置控制器
|
||||
*/
|
||||
class DiceLotteryConfigController extends BaseController
|
||||
class DiceConfigController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DiceLotteryConfigLogic();
|
||||
$this->validate = new DiceLotteryConfigValidate;
|
||||
$this->logic = new DiceConfigLogic();
|
||||
$this->validate = new DiceConfigValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -33,12 +33,13 @@ class DiceLotteryConfigController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_config:index:index')]
|
||||
#[Permission('摇色子配置列表', 'dice:config:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['type', ''],
|
||||
['group', ''],
|
||||
['title', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
@@ -50,7 +51,7 @@ class DiceLotteryConfigController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置读取', 'dice:lottery_config:index:read')]
|
||||
#[Permission('摇色子配置读取', 'dice:config:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
@@ -68,7 +69,7 @@ class DiceLotteryConfigController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置添加', 'dice:lottery_config:index:save')]
|
||||
#[Permission('摇色子配置添加', 'dice:config:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
@@ -86,7 +87,7 @@ class DiceLotteryConfigController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_config:index:update')]
|
||||
#[Permission('摇色子配置修改', 'dice:config:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
@@ -104,7 +105,7 @@ class DiceLotteryConfigController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置删除', 'dice:lottery_config:index:destroy')]
|
||||
#[Permission('摇色子配置删除', 'dice:config:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\lottery_pool_config;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
|
||||
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 色子奖池配置控制器
|
||||
*/
|
||||
class DiceLotteryPoolConfigController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DiceLotteryPoolConfigLogic();
|
||||
$this->validate = new DiceLotteryPoolConfigValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 DiceLotteryPoolConfig 列表数据,用于 lottery_config_id 下拉(值为 id,显示为 name),并附带 type、T1-T5 档位权重
|
||||
* type:0=付费抽奖券,1=免费抽奖券;一键测试权重中付费默认选 type=0,免费默认选 type=1
|
||||
* @param Request $request
|
||||
* @return Response 返回 [ ['id' => int, 'name' => string, 'type' => int, 't1_weight' => int, ... 't5_weight' => int], ... ]
|
||||
*/
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
public function getOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name,type,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return [
|
||||
'id' => (int) $item['id'],
|
||||
'name' => (string) ($item['name'] ?? ''),
|
||||
'type' => (int) ($item['type'] ?? 0),
|
||||
't1_weight' => (int) ($item['t1_weight'] ?? 0),
|
||||
't2_weight' => (int) ($item['t2_weight'] ?? 0),
|
||||
't3_weight' => (int) ($item['t3_weight'] ?? 0),
|
||||
't4_weight' => (int) ($item['t4_weight'] ?? 0),
|
||||
't5_weight' => (int) ($item['t5_weight'] ?? 0),
|
||||
];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['type', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置读取', 'dice:lottery_pool_config:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置添加', 'dice:lottery_pool_config:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('色子奖池配置删除', 'dice:lottery_pool_config:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前彩金池(Redis 实例化,无则按 type=0 创建)
|
||||
* 返回含玩家累计盈利 profit_amount 实时值,供前端轮询展示
|
||||
*/
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
public function getCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $this->logic->getCurrentPool();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前彩金池:仅可修改 safety_line、t1_weight~t5_weight,不可修改 profit_amount
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
|
||||
public function updateCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->logic->updateCurrentPool($data);
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0
|
||||
*/
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
|
||||
public function resetProfitAmount(Request $request): Response
|
||||
{
|
||||
$this->logic->resetProfitAmount();
|
||||
return $this->success('重置成功');
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\play_record;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\play_record\DicePlayRecordLogic;
|
||||
use app\dice\validate\play_record\DicePlayRecordValidate;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -46,15 +47,18 @@ class DicePlayRecordController extends BaseController
|
||||
['is_win', ''],
|
||||
['win_coin_min', ''],
|
||||
['win_coin_max', ''],
|
||||
['roll_number_min', ''],
|
||||
['roll_number_max', ''],
|
||||
['reward_ui_text', ''],
|
||||
['reward_tier', ''],
|
||||
['direction', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'diceRewardConfig',
|
||||
'diceLotteryConfig',
|
||||
'diceLotteryPoolConfig',
|
||||
]);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
@@ -66,7 +70,9 @@ class DicePlayRecordController extends BaseController
|
||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$list = DicePlayer::field('id,username')->select();
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
})->toArray();
|
||||
@@ -79,7 +85,7 @@ class DicePlayRecordController extends BaseController
|
||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||
public function getLotteryConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryConfig::field('id,name')->select();
|
||||
$list = DiceLotteryPoolConfig::field('id,name')->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'name' => $item['name'] ?? ''];
|
||||
})->toArray();
|
||||
@@ -113,12 +119,15 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
|
||||
use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)控制器
|
||||
*/
|
||||
class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DicePlayRecordTestLogic();
|
||||
$this->validate = new DicePlayRecordTestValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表,并在结果中附带当前筛选条件下测试数据的平台总盈利 total_win_coin(付费抽奖次数×100 - 玩家总收益)
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)列表', 'dice:play_record_test:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['lottery_type', ''],
|
||||
['direction', ''],
|
||||
['is_win', ''],
|
||||
['win_coin_min', ''],
|
||||
['win_coin_max', ''],
|
||||
['reward_tier', ''],
|
||||
['roll_number', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with(['diceLotteryPoolConfig', 'diceRewardConfig']);
|
||||
|
||||
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(lottery_type=0)次数×100 - 玩家总收益(win_coin 求和)
|
||||
$sumQuery = clone $query;
|
||||
$playerTotalWin = (float) $sumQuery->sum('win_coin');
|
||||
$paidCountQuery = clone $query;
|
||||
$paidCount = (int) $paidCountQuery->where('lottery_type', 0)->count();
|
||||
$totalWinCoin = $paidCount * 100 - $playerTotalWin;
|
||||
|
||||
$data = $this->logic->getList($query);
|
||||
$data['total_win_coin'] = $totalWinCoin;
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)读取', 'dice:play_record_test:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)添加', 'dice:play_record_test:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)修改', 'dice:play_record_test:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)删除', 'dice:play_record_test:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键删除所有测试数据:清空 dice_play_record_test 表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)删除', 'dice:play_record_test:index:destroy')]
|
||||
public function clearAll(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$table = (new \app\dice\model\play_record_test\DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空所有测试数据');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,20 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player\DicePlayerLogic;
|
||||
use app\dice\validate\player\DicePlayerValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\api\cache\UserCache;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家控制器
|
||||
* 玩家控制器
|
||||
*/
|
||||
class DicePlayerController extends BaseController
|
||||
{
|
||||
@@ -28,12 +33,55 @@ class DicePlayerController extends BaseController
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取彩金池配置选项(id、name)
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getLotteryConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后台管理员选项(id、username、realname)
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getSystemUserOptions(Request $request): Response
|
||||
{
|
||||
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
|
||||
$deptList = $this->adminInfo['deptList'] ?? [];
|
||||
if (!empty($deptList)) {
|
||||
$query->auth($deptList);
|
||||
}
|
||||
}
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
$label = trim((string) ($item['realname'] ?? '')) ?: (string) ($item['username'] ?? '');
|
||||
return [
|
||||
'id' => (int) $item['id'],
|
||||
'username' => (string) ($item['username'] ?? ''),
|
||||
'realname' => (string) ($item['realname'] ?? ''),
|
||||
'label' => $label ?: (string) $item['id'],
|
||||
];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
@@ -42,9 +90,11 @@ class DicePlayerController extends BaseController
|
||||
['phone', ''],
|
||||
['status', ''],
|
||||
['coin', ''],
|
||||
['is_up', ''],
|
||||
['lottery_config_id', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -54,17 +104,20 @@ class DicePlayerController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家读取', 'dice:player:index:read')]
|
||||
#[Permission('玩家读取', 'dice:player:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,17 +125,26 @@ class DicePlayerController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家添加', 'dice:player:index:save')]
|
||||
#[Permission('玩家添加', 'dice:player:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
// 类型转化
|
||||
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
||||
$data['admin_id'] = (int) $this->adminInfo['id'];
|
||||
}
|
||||
$result = $this->logic->add($data);
|
||||
if ($result && isset($result['id'])) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($result['id']);
|
||||
$player = DicePlayer::find($result['id']);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('添加成功');
|
||||
}
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,36 +152,61 @@ class DicePlayerController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家修改', 'dice:player:index:update')]
|
||||
#[Permission('玩家修改', 'dice:player:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限修改该记录');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($data['id']);
|
||||
$player = DicePlayer::find($data['id']);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅更新状态(列表内开关用)
|
||||
* 更新状态
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家修改', 'dice:player:index:update')]
|
||||
#[Permission('玩家状态修改', 'dice:player:index:update')]
|
||||
public function updateStatus(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id');
|
||||
$status = $request->input('status');
|
||||
if ($id === null || $id === '') {
|
||||
return $this->fail('缺少 id');
|
||||
return $this->fail('缺少参数 id');
|
||||
}
|
||||
if ($status === null || $status === '') {
|
||||
return $this->fail('缺少 status');
|
||||
return $this->fail('缺少参数 status');
|
||||
}
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限修改该记录');
|
||||
}
|
||||
}
|
||||
$this->logic->edit($id, ['status' => (int) $status]);
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($id);
|
||||
$player = DicePlayer::find($id);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
|
||||
@@ -128,19 +215,42 @@ class DicePlayerController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家删除', 'dice:player:index:destroy')]
|
||||
#[Permission('玩家删除', 'dice:player:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null) {
|
||||
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id');
|
||||
$validIds = [];
|
||||
foreach ($ids as $id) {
|
||||
$adminId = (int) ($models[$id] ?? 0);
|
||||
if (in_array($adminId, $allowedIds, true)) {
|
||||
$validIds[] = $id;
|
||||
}
|
||||
}
|
||||
$ids = $validIds;
|
||||
if (empty($ids)) {
|
||||
return $this->fail('无权限删除所选数据');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
// 出于安全:删除相关玩家缓存,后续 API 按需重建
|
||||
foreach ($ids as $id) {
|
||||
UserCache::deleteUser($id);
|
||||
$player = DicePlayer::find($id);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\player_ticket_record;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player_ticket_record\DicePlayerTicketRecordLogic;
|
||||
use app\dice\validate\player_ticket_record\DicePlayerTicketRecordValidate;
|
||||
@@ -51,6 +52,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
]);
|
||||
@@ -66,7 +68,9 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
#[Permission('抽奖券获取记录列表', 'dice:player_ticket_record:index:index')]
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$list = DicePlayer::field('id,username')->select();
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
})->toArray();
|
||||
@@ -83,12 +87,15 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\player_wallet_record;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player_wallet_record\DicePlayerWalletRecordLogic;
|
||||
use app\dice\validate\player_wallet_record\DicePlayerWalletRecordValidate;
|
||||
@@ -47,6 +48,7 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'operator',
|
||||
@@ -63,7 +65,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
#[Permission('玩家钱包流水列表', 'dice:player_wallet_record:index:index')]
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$list = DicePlayer::field('id,username')->select();
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
})->toArray();
|
||||
@@ -83,10 +87,14 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
if ($playerId === null || $playerId === '') {
|
||||
return $this->fail('缺少 player_id');
|
||||
}
|
||||
$player = DicePlayer::field('coin')->where('id', $playerId)->find();
|
||||
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('玩家不存在');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限操作该玩家');
|
||||
}
|
||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||
}
|
||||
|
||||
@@ -100,12 +108,15 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
if (!$model) {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限查看该记录');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,6 +166,14 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
|
||||
if ($player) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限操作该玩家');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$this->logic->adminOperate($data, $adminId);
|
||||
return $this->success('操作成功');
|
||||
|
||||
199
server/app/dice/controller/reward/DiceRewardController.php
Normal file
199
server/app/dice/controller/reward/DiceRewardController.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward;
|
||||
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use support\think\Db;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 奖励对照控制器(dice_reward,按方向分页列表 + 权重编辑)
|
||||
*/
|
||||
class DiceRewardController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 分页列表,按 direction 区分顺时针(0)/逆时针(1)
|
||||
* 参数:direction(必), tier(选), page, limit, orderField, orderType
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$direction = $request->input('direction', null);
|
||||
if ($direction === null || $direction === '') {
|
||||
return $this->fail('请传入 direction(0=顺时针 1=逆时针)');
|
||||
}
|
||||
$direction = (int) $direction;
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
return $this->fail('direction 必须为 0(顺时针)或 1(逆时针)');
|
||||
}
|
||||
$tier = $request->input('tier', '');
|
||||
$page = (int) $request->input('page', 1);
|
||||
$limit = (int) $request->input('limit', 10);
|
||||
$orderField = $request->input('orderField', 'r.tier');
|
||||
$orderType = $request->input('orderType', 'asc');
|
||||
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListWithConfig($direction, [
|
||||
'tier' => $tier,
|
||||
'orderField' => $orderField,
|
||||
'orderType' => $orderType,
|
||||
], $page, $limit);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向,用于兼容)
|
||||
* 参数:direction 0=顺时针 1=逆时针
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function weightRatioList(Request $request): Response
|
||||
{
|
||||
$direction = (int) $request->input('direction', 0);
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
$direction = DiceReward::DIRECTION_CLOCKWISE;
|
||||
}
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierForDirection($direction);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重(dice_reward 双方向)
|
||||
* 返回与 reward_config 权重配比一致结构,供奖励对照页弹窗同时编辑 direction=0/1
|
||||
* 拉取前先刷新缓存,保证与列表页(直查 DB)数据一致,避免表格与弹窗权重不一致
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function weightRatioListWithDirection(Request $request): Response
|
||||
{
|
||||
DiceReward::refreshCache();
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierWithDirection();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键测试权重:创建测试记录并启动单进程后台执行,按付费/免费、顺逆方向交替写入 dice_play_record_test
|
||||
* 参数:lottery_config_id 可选,不选则传 paid_tier_weights / free_tier_weights 自定义档位;
|
||||
* paid_s_count, paid_n_count, free_s_count, free_n_count;或兼容旧版 s_count, n_count
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function startWeightTest(Request $request): Response
|
||||
{
|
||||
$post = is_array($request->post()) ? $request->post() : [];
|
||||
$params = [
|
||||
'lottery_config_id' => $post['lottery_config_id'] ?? null,
|
||||
'paid_lottery_config_id' => $post['paid_lottery_config_id'] ?? null,
|
||||
'free_lottery_config_id' => $post['free_lottery_config_id'] ?? null,
|
||||
's_count' => $post['s_count'] ?? null,
|
||||
'n_count' => $post['n_count'] ?? null,
|
||||
'paid_s_count' => $post['paid_s_count'] ?? null,
|
||||
'paid_n_count' => $post['paid_n_count'] ?? null,
|
||||
'free_s_count' => $post['free_s_count'] ?? null,
|
||||
'free_n_count' => $post['free_n_count'] ?? null,
|
||||
'paid_tier_weights' => $post['paid_tier_weights'] ?? null,
|
||||
'free_tier_weights' => $post['free_tier_weights'] ?? null,
|
||||
];
|
||||
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
|
||||
try {
|
||||
$logic = new DiceRewardConfigRecordLogic();
|
||||
$recordId = $logic->createWeightTestRecord($params, $adminId);
|
||||
return $this->success(['record_id' => $recordId]);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一键测试进度:total_play_count、over_play_count、status、remark
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function getTestProgress(Request $request): Response
|
||||
{
|
||||
$recordId = (int) $request->input('record_id', 0);
|
||||
if ($recordId <= 0) {
|
||||
return $this->fail('请传入 record_id');
|
||||
}
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if (!$record) {
|
||||
return $this->fail('记录不存在');
|
||||
}
|
||||
$arr = $record->toArray();
|
||||
$data = [
|
||||
'total_play_count' => (int) ($arr['total_play_count'] ?? 0),
|
||||
'over_play_count' => (int) ($arr['over_play_count'] ?? 0),
|
||||
'status' => (int) ($arr['status'] ?? 0),
|
||||
'remark' => $arr['remark'] ?? null,
|
||||
'result_counts' => $arr['result_counts'] ?? null,
|
||||
'tier_counts' => $arr['tier_counts'] ?? null,
|
||||
];
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键清空测试数据:清空 dice_play_record_test 表
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function clearPlayRecordTest(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$table = (new DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空测试数据');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按方向+点数批量更新权重(写入 dice_reward)
|
||||
* 参数:items: [{ grid_number, weight_clockwise, weight_counterclockwise }, ...]
|
||||
*/
|
||||
#[Permission('奖励对照修改', 'dice:reward:index:update')]
|
||||
public function batchUpdateWeights(Request $request): Response
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
}
|
||||
try {
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeights($items);
|
||||
return $this->success('保存成功');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:批量更新当前方向的权重(单方向,用于兼容)
|
||||
* 参数:direction(必), items: [{ id, weight }, ...]
|
||||
*/
|
||||
#[Permission('奖励对照修改', 'dice:reward:index:update')]
|
||||
public function batchUpdateWeightsByDirection(Request $request): Response
|
||||
{
|
||||
$direction = (int) $request->post('direction', 0);
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
return $this->fail('direction 必须为 0(顺时针)或 1(逆时针)');
|
||||
}
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
}
|
||||
try {
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items);
|
||||
return $this->success('保存成功');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace app\dice\controller\reward_config;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\reward_config\DiceRewardConfigLogic;
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\validate\reward_config\DiceRewardConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
@@ -103,6 +104,29 @@ class DiceRewardConfigController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新奖励索引配置(第一页:id、grid_number、ui_text、real_ev、tier、remark)
|
||||
* @param Request $request items: [{ id, grid_number?, ui_text?, real_ev?, tier?, remark? }, ...]
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置修改', 'dice:reward_config:index:update')]
|
||||
public function batchUpdate(Request $request): Response
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (! is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
}
|
||||
$err = $this->logic->validateBatchUpdateItems($items);
|
||||
if ($err !== null) {
|
||||
return $this->fail($err);
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
$this->validate('batch_update', array_merge($item, ['id' => $item['id']]));
|
||||
}
|
||||
$this->logic->batchUpdate($items);
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
@@ -123,4 +147,102 @@ class DiceRewardConfigController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-T5、BIGWIN 权重配比:按档位分组返回配置列表(含顺时针/逆时针权重,来自 dice_reward)
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置列表', 'dice:reward_config:index:index')]
|
||||
public function weightRatioList(Request $request): Response
|
||||
{
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$data = $rewardLogic->getListGroupedByTierWithDirection();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* T1-T5、BIGWIN 权重配比:按 DiceReward 主键 id 批量更新 weight(写入 dice_reward,修改后刷新缓存)
|
||||
* items: [ { id: DiceReward.id, weight: 1-10000 }, ... ]
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置修改', 'dice:reward_config:index:update')]
|
||||
public function batchUpdateWeights(Request $request): Response
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (!is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
}
|
||||
try {
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$rewardLogic->batchUpdateWeights($items);
|
||||
return $this->success('保存成功');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 大奖权重:按 grid_number 批量保存 BIGWIN 权重(仅更新 dice_reward_config 表,不操作 dice_reward)
|
||||
* items: [ { grid_number: 5-30, weight: 0-10000 }, ... ]
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置修改', 'dice:reward_config:index:update')]
|
||||
public function saveBigwinWeightsByGrid(Request $request): Response
|
||||
{
|
||||
$items = $request->post('items', []);
|
||||
if (! is_array($items)) {
|
||||
return $this->fail('参数 items 必须为数组');
|
||||
}
|
||||
$err = $this->logic->validateBigwinWeightItems($items);
|
||||
if ($err !== null) {
|
||||
return $this->fail($err);
|
||||
}
|
||||
$this->logic->batchUpdateBigwinWeight($items);
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建奖励对照:按当前 dice_reward_config 为两种方向(顺时针0、逆时针1)生成所有色子可能对应的 dice_reward 记录
|
||||
* 权重默认 1,可在「奖励对照」页的权重编辑弹窗中调整
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置修改', 'dice:reward_config:index:update')]
|
||||
public function createRewardReference(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$result = $rewardLogic->createRewardReferenceFromConfig();
|
||||
return $this->success($result, '创建奖励对照成功');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重配比测试:仅模拟落点统计,不创建游玩记录。按当前配置在内存中模拟 N 次抽奖,返回各 grid_number 落点次数,可选保存到 dice_reward_config_record。
|
||||
* @param Request $request test_count: 100|500|1000, save_record: bool, lottery_config_id: int|null 奖池配置ID,用于设定 T1-T5 概率
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置列表', 'dice:reward_config:index:index')]
|
||||
public function runWeightTest(Request $request): Response
|
||||
{
|
||||
$testCount = (int) $request->post('test_count', 100);
|
||||
$saveRecord = (bool) $request->post('save_record', true);
|
||||
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
|
||||
$lotteryConfigId = $request->post('lottery_config_id', null);
|
||||
if ($lotteryConfigId !== null && $lotteryConfigId !== '') {
|
||||
$lotteryConfigId = (int) $lotteryConfigId;
|
||||
} else {
|
||||
$lotteryConfigId = null;
|
||||
}
|
||||
try {
|
||||
$result = $this->logic->runWeightTest($testCount, $saveRecord, $adminId, $lotteryConfigId);
|
||||
return $this->success($result);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward_config_record;
|
||||
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录控制器
|
||||
*/
|
||||
class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DiceRewardConfigRecordLogic();
|
||||
$this->validate = new DiceRewardConfigRecordValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录列表', 'dice:reward_config_record:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录读取', 'dice:reward_config_record:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
$data['admin_name'] = $this->getAdminName((int) ($data['admin_id'] ?? 0));
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据管理员 ID 获取姓名(realname 优先,否则 username)
|
||||
*/
|
||||
private function getAdminName(int $adminId): string
|
||||
{
|
||||
if ($adminId <= 0) {
|
||||
return '—';
|
||||
}
|
||||
$user = SystemUser::where('id', $adminId)->field('id,realname,username')->find();
|
||||
if (!$user) {
|
||||
return '';
|
||||
}
|
||||
$user = is_array($user) ? $user : $user->toArray();
|
||||
$name = trim((string) ($user['realname'] ?? ''));
|
||||
if ($name !== '') {
|
||||
return $name;
|
||||
}
|
||||
$name = trim((string) ($user['username'] ?? ''));
|
||||
return $name !== '' ? $name : (string) $adminId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录添加', 'dice:reward_config_record:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录修改', 'dice:reward_config_record:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录删除', 'dice:reward_config_record:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入:测试记录 → DiceReward、DiceRewardConfig(BIGWIN)、DiceLotteryPoolConfig(付费/免费 T1-T5)
|
||||
* @param Request $request record_id, paid_lottery_config_id(可选), free_lottery_config_id(可选), lottery_config_id(兼容旧版)
|
||||
*/
|
||||
#[Permission('奖励配置权重测试记录列表', 'dice:reward_config_record:index:index')]
|
||||
public function importFromRecord(Request $request): Response
|
||||
{
|
||||
$recordId = (int) $request->post('record_id', 0);
|
||||
if ($recordId <= 0) {
|
||||
return $this->fail('请指定测试记录');
|
||||
}
|
||||
$paidId = $request->post('paid_lottery_config_id', null);
|
||||
$freeId = $request->post('free_lottery_config_id', null);
|
||||
$legacyId = $request->post('lottery_config_id', null);
|
||||
$paidLotteryConfigId = $paidId !== null && $paidId !== '' ? (int) $paidId : null;
|
||||
$freeLotteryConfigId = $freeId !== null && $freeId !== '' ? (int) $freeId : null;
|
||||
$lotteryConfigId = $legacyId !== null && $legacyId !== '' ? (int) $legacyId : null;
|
||||
try {
|
||||
$this->logic->importFromRecord($recordId, $paidLotteryConfigId, $freeLotteryConfigId, $lotteryConfigId);
|
||||
return $this->success('导入成功,已刷新 DiceReward、DiceRewardConfig(BIGWIN)、奖池配置');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
60
server/app/dice/helper/AdminScopeHelper.php
Normal file
60
server/app/dice/helper/AdminScopeHelper.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\dice\helper;
|
||||
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
|
||||
/**
|
||||
* 管理员数据范围辅助类
|
||||
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
|
||||
*/
|
||||
class AdminScopeHelper
|
||||
{
|
||||
/**
|
||||
* 获取当前管理员可访问的 admin_id 列表
|
||||
* 超级管理员(id=1) 返回 null 表示不限制
|
||||
* 普通管理员返回其本人及部门下属管理员的 id 列表
|
||||
*
|
||||
* @param array|null $adminInfo 当前登录管理员信息(含 id、deptList)
|
||||
* @return int[]|null null=不限制(超级管理员),否则为可访问的 admin_id 数组
|
||||
*/
|
||||
public static function getAllowedAdminIds(?array $adminInfo): ?array
|
||||
{
|
||||
if (empty($adminInfo) || !isset($adminInfo['id'])) {
|
||||
return [];
|
||||
}
|
||||
$adminId = (int) $adminInfo['id'];
|
||||
if ($adminId <= 1) {
|
||||
return null;
|
||||
}
|
||||
$deptList = $adminInfo['deptList'] ?? [];
|
||||
if (empty($deptList) || !isset($deptList['id'])) {
|
||||
return [$adminId];
|
||||
}
|
||||
$query = SystemUser::field('id');
|
||||
$query->auth($deptList);
|
||||
$ids = $query->column('id');
|
||||
return array_map('intval', $ids ?: []);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对查询应用 admin_id 范围过滤
|
||||
*
|
||||
* @param object $query ThinkORM 查询对象
|
||||
* @param array|null $adminInfo 当前登录管理员信息
|
||||
* @return void
|
||||
*/
|
||||
public static function applyAdminScope($query, ?array $adminInfo): void
|
||||
{
|
||||
$allowedIds = self::getAllowedAdminIds($adminInfo);
|
||||
if ($allowedIds === null) {
|
||||
return;
|
||||
}
|
||||
if (empty($allowedIds)) {
|
||||
$query->whereRaw('1=0');
|
||||
return;
|
||||
}
|
||||
$query->whereIn('admin_id', $allowedIds);
|
||||
}
|
||||
}
|
||||
27
server/app/dice/logic/config/DiceConfigLogic.php
Normal file
27
server/app/dice/logic/config/DiceConfigLogic.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\config;
|
||||
|
||||
use plugin\saiadmin\basic\eloquent\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use app\dice\model\config\DiceConfig;
|
||||
|
||||
/**
|
||||
* 摇色子配置逻辑层
|
||||
*/
|
||||
class DiceConfigLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceConfig();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\lottery_pool_config;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 色子奖池配置逻辑层
|
||||
*/
|
||||
class DiceLotteryPoolConfigLogic extends BaseLogic
|
||||
{
|
||||
/** Redis 当前彩金池(type=0 实例)key,无则按 type=0 创建 */
|
||||
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
|
||||
|
||||
private const EXPIRE = 86400 * 7;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceLotteryPoolConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前彩金池:从 Redis 读取实例,profit_amount 每次从 DB 实时读取(表示玩家在该池子的累计盈利)
|
||||
*
|
||||
* @return array{id:int,name:string,safety_line:int,t1_weight:int,t2_weight:int,t3_weight:int,t4_weight:int,t5_weight:int,profit_amount:float}
|
||||
*/
|
||||
public function getCurrentPool(): array
|
||||
{
|
||||
$cached = Cache::get(self::REDIS_KEY_CURRENT_POOL);
|
||||
if ($cached && is_string($cached)) {
|
||||
$data = json_decode($cached, true);
|
||||
if (is_array($data)) {
|
||||
$config = DiceLotteryPoolConfig::find($data['id'] ?? 0);
|
||||
$profit = 0.0;
|
||||
if ($config) {
|
||||
$profit = isset($config->profit_amount) ? (float) $config->profit_amount : (isset($config->ev) ? (float) $config->ev : 0.0);
|
||||
} else {
|
||||
$profit = (float) ($data['profit_amount'] ?? 0);
|
||||
}
|
||||
$data['profit_amount'] = $profit;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
if (!$config) {
|
||||
throw new ApiException('未找到 type=0 的奖池配置,请先创建');
|
||||
}
|
||||
$row = $config->toArray();
|
||||
$profitAmount = isset($row['profit_amount']) ? (float) $row['profit_amount'] : (isset($row['ev']) ? (float) $row['ev'] : 0.0);
|
||||
$pool = [
|
||||
'id' => (int) $row['id'],
|
||||
'name' => (string) ($row['name'] ?? ''),
|
||||
'safety_line' => (int) ($row['safety_line'] ?? 0),
|
||||
't1_weight' => (int) ($row['t1_weight'] ?? 0),
|
||||
't2_weight' => (int) ($row['t2_weight'] ?? 0),
|
||||
't3_weight' => (int) ($row['t3_weight'] ?? 0),
|
||||
't4_weight' => (int) ($row['t4_weight'] ?? 0),
|
||||
't5_weight' => (int) ($row['t5_weight'] ?? 0),
|
||||
'profit_amount' => $profitAmount,
|
||||
];
|
||||
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
|
||||
return $pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前彩金池:仅允许修改 safety_line、t1_weight~t5_weight,不修改 profit_amount
|
||||
* 同时更新 Redis 与 DB 中 type=0 的记录
|
||||
*
|
||||
* @param array{safety_line?:int,t1_weight?:int,t2_weight?:int,t3_weight?:int,t4_weight?:int,t5_weight?:int} $data
|
||||
*/
|
||||
public function updateCurrentPool(array $data): void
|
||||
{
|
||||
$pool = $this->getCurrentPool();
|
||||
$id = (int) $pool['id'];
|
||||
$config = DiceLotteryPoolConfig::find($id);
|
||||
if (!$config) {
|
||||
throw new ApiException('奖池配置不存在');
|
||||
}
|
||||
$allow = ['safety_line', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'];
|
||||
$update = [];
|
||||
foreach ($allow as $k) {
|
||||
if (array_key_exists($k, $data)) {
|
||||
if ($k === 'safety_line') {
|
||||
$update[$k] = (int) $data[$k];
|
||||
} else {
|
||||
$update[$k] = max(0, min(100, (int) $data[$k]));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($update)) {
|
||||
return;
|
||||
}
|
||||
DiceLotteryPoolConfig::where('id', $id)->update($update);
|
||||
$pool = array_merge($pool, $update);
|
||||
$refreshed = DiceLotteryPoolConfig::find($id);
|
||||
$pool['profit_amount'] = $refreshed && (isset($refreshed->profit_amount) || isset($refreshed->ev))
|
||||
? (float) ($refreshed->profit_amount ?? $refreshed->ev)
|
||||
: (float) ($pool['profit_amount'] ?? 0);
|
||||
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0,并刷新 Redis 缓存
|
||||
*/
|
||||
public function resetProfitAmount(): void
|
||||
{
|
||||
$pool = $this->getCurrentPool();
|
||||
$id = (int) $pool['id'];
|
||||
DiceLotteryPoolConfig::where('id', $id)->update(['profit_amount' => 0]);
|
||||
$pool['profit_amount'] = 0.0;
|
||||
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
|
||||
}
|
||||
}
|
||||
@@ -43,16 +43,18 @@ class DicePlayRecordLogic extends BaseLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 roll_array 从数组转为 JSON 字符串
|
||||
* 将 roll_array 转为 JSON 字符串,并确保 roll_number 与摇取点数一致
|
||||
*/
|
||||
private function normalizeRollArray(array $data): array
|
||||
{
|
||||
if (!array_key_exists('roll_array', $data)) {
|
||||
return $data;
|
||||
}
|
||||
$val = $data['roll_array'];
|
||||
if (is_array($val)) {
|
||||
$data['roll_array'] = json_encode($val, JSON_UNESCAPED_UNICODE);
|
||||
if (array_key_exists('roll_array', $data)) {
|
||||
$val = $data['roll_array'];
|
||||
if (is_array($val)) {
|
||||
$data['roll_array'] = json_encode($val, JSON_UNESCAPED_UNICODE);
|
||||
if (!isset($data['roll_number'])) {
|
||||
$data['roll_number'] = array_sum($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -4,24 +4,24 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\lottery_config;
|
||||
namespace app\dice\logic\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
|
||||
/**
|
||||
* 色子奖池配置逻辑层
|
||||
* 玩家抽奖记录(测试数据)逻辑层
|
||||
*/
|
||||
class DiceLotteryConfigLogic extends BaseLogic
|
||||
class DicePlayRecordTestLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceLotteryConfig();
|
||||
$this->model = new DicePlayRecordTest();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\api\cache\UserCache;
|
||||
|
||||
/**
|
||||
* 玩家钱包流水逻辑层
|
||||
@@ -73,8 +74,16 @@ class DicePlayerWalletRecordLogic extends BaseLogic
|
||||
|
||||
DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]);
|
||||
|
||||
// 出于安全:删除该玩家相关缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($playerId);
|
||||
if (isset($player->username) && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
|
||||
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||
$record = [
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $playerAdminId,
|
||||
'coin' => $type === 3 ? $coin : -$coin,
|
||||
'type' => $type,
|
||||
'wallet_before' => $walletBefore,
|
||||
|
||||
451
server/app/dice/logic/reward/DiceRewardLogic.php
Normal file
451
server/app/dice/logic/reward/DiceRewardLogic.php
Normal file
@@ -0,0 +1,451 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\reward;
|
||||
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 奖励对照逻辑层(DiceReward)
|
||||
* 权重 1-10000,区分顺时针/逆时针,修改后刷新 DiceReward 缓存
|
||||
*/
|
||||
class DiceRewardLogic
|
||||
{
|
||||
private const WEIGHT_MIN = 1;
|
||||
private const WEIGHT_MAX = 10000;
|
||||
|
||||
/** 档位键 */
|
||||
private const TIER_KEYS = ['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'];
|
||||
|
||||
/**
|
||||
* 分页列表(按方向筛选,关联 dice_reward_config 展示 grid_number、ui_text、real_ev、remark)
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @param array{tier?: string, orderField?: string, orderType?: string} $where tier 档位筛选
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return array{total: int, per_page: int, current_page: int, data: array}
|
||||
*/
|
||||
public function getListWithConfig(int $direction, array $where, int $page = 1, int $limit = 10): array
|
||||
{
|
||||
$tier = isset($where['tier']) ? trim((string) $where['tier']) : '';
|
||||
$orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier';
|
||||
$orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc';
|
||||
|
||||
$query = DiceReward::alias('r')
|
||||
->where('r.direction', $direction)
|
||||
->field('r.id,r.tier,r.direction,r.end_index,r.weight,r.grid_number,r.start_index,r.ui_text,r.real_ev,r.remark,r.type,r.create_time,r.update_time')
|
||||
->order($orderField, $orderType)
|
||||
->order('r.end_index', 'asc');
|
||||
|
||||
if ($tier !== '') {
|
||||
$query->where('r.tier', $tier);
|
||||
}
|
||||
|
||||
$paginator = $query->paginate($limit, false, ['page' => $page]);
|
||||
$arr = $paginator->toArray();
|
||||
$data = isset($arr['data']) ? $arr['data'] : $arr['records'] ?? [];
|
||||
$total = (int) ($arr['total'] ?? 0);
|
||||
$perPage = (int) ($arr['per_page'] ?? $limit);
|
||||
$currentPage = (int) ($arr['current_page'] ?? $page);
|
||||
foreach ($data as $i => $row) {
|
||||
if (isset($row['id']) && $row['id'] !== '' && $row['id'] !== null) {
|
||||
$data[$i]['id'] = (int) $row['id'];
|
||||
} else {
|
||||
$data[$i]['id'] = isset($row['end_index']) ? (int) $row['end_index'] : 0;
|
||||
}
|
||||
$data[$i]['start_index'] = isset($row['start_index']) && $row['start_index'] !== '' && $row['start_index'] !== null
|
||||
? (int) $row['start_index']
|
||||
: 0;
|
||||
}
|
||||
return [
|
||||
'total' => $total,
|
||||
'per_page' => $perPage,
|
||||
'current_page' => $currentPage,
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单方向批量更新权重(仅更新当前方向的 weight,并刷新缓存)
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @param array<int, array{id: int, weight: int}> $items id 为 end_index(DiceRewardConfig.id)
|
||||
*/
|
||||
public function batchUpdateWeightsByDirection(int $direction, array $items): void
|
||||
{
|
||||
if (empty($items)) {
|
||||
return;
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
$id = isset($item['id']) ? (int) $item['id'] : 0;
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
if ($id <= 0) {
|
||||
throw new ApiException('存在无效的配置ID');
|
||||
}
|
||||
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
|
||||
|
||||
$tier = DiceRewardConfig::where('id', $id)->value('tier');
|
||||
if ($tier === null || $tier === '') {
|
||||
throw new ApiException('配置ID ' . $id . ' 不存在或档位为空');
|
||||
}
|
||||
$tier = (string) $tier;
|
||||
|
||||
$affected = DiceReward::where('tier', $tier)->where('direction', $direction)->where('end_index', $id)->update(['weight' => $weight]);
|
||||
if ($affected === 0) {
|
||||
$m = new DiceReward();
|
||||
$m->tier = $tier;
|
||||
$m->direction = $direction;
|
||||
$m->end_index = $id;
|
||||
$m->weight = $weight;
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位+单方向返回列表(用于权重编辑弹窗:当前方向下按档位分组的配置+权重)
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @return array<string, array> 键 T1|T2|...|BIGWIN,值为该档位下带 weight 的行数组
|
||||
*/
|
||||
public function getListGroupedByTierForDirection(int $direction): array
|
||||
{
|
||||
$configInstance = DiceRewardConfig::getCachedInstance();
|
||||
$byTier = $configInstance['by_tier'] ?? [];
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
|
||||
$result = [];
|
||||
foreach (self::TIER_KEYS as $tier) {
|
||||
$result[$tier] = [];
|
||||
$rows = $byTier[$tier] ?? [];
|
||||
$dirRows = $byTierDirection[$tier][$direction] ?? [];
|
||||
$weightMap = [];
|
||||
foreach ($dirRows as $r) {
|
||||
$eid = isset($r['end_index']) ? (int) $r['end_index'] : 0;
|
||||
$weightMap[$eid] = isset($r['weight']) ? max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, (int) $r['weight'])) : 1;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$id = isset($row['id']) ? (int) $row['id'] : 0;
|
||||
$result[$tier][] = [
|
||||
'id' => $id,
|
||||
'grid_number' => $row['grid_number'] ?? 0,
|
||||
'ui_text' => $row['ui_text'] ?? '',
|
||||
'real_ev' => $row['real_ev'] ?? 0,
|
||||
'remark' => $row['remark'] ?? '',
|
||||
'tier' => $tier,
|
||||
'weight' => $weightMap[$id] ?? 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位+方向返回 DiceReward 列表(用于权重配比弹窗),直接读 dice_reward 表,不依赖 config
|
||||
* 每行含 reward_id(DiceReward 主键,用于按 id 更新权重)、id(end_index 展示用)、grid_number、ui_text、real_ev、remark、weight
|
||||
*
|
||||
* @return array<string, array{0: array, 1: array}>
|
||||
*/
|
||||
public function getListGroupedByTierWithDirection(): array
|
||||
{
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
|
||||
$result = [];
|
||||
foreach (self::TIER_KEYS as $tier) {
|
||||
$result[$tier] = [0 => [], 1 => []];
|
||||
foreach ([0, 1] as $direction) {
|
||||
$rows = $byTierDirection[$tier][$direction] ?? [];
|
||||
foreach ($rows as $r) {
|
||||
$result[$tier][$direction][] = [
|
||||
'reward_id' => isset($r['id']) ? (int) $r['id'] : 0,
|
||||
'id' => isset($r['end_index']) ? (int) $r['end_index'] : 0,
|
||||
'grid_number' => isset($r['grid_number']) ? (int) $r['grid_number'] : 0,
|
||||
'ui_text' => (string) ($r['ui_text'] ?? ''),
|
||||
'real_ev' => $r['real_ev'] ?? 0,
|
||||
'remark' => (string) ($r['remark'] ?? ''),
|
||||
'weight' => isset($r['weight']) ? max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, (int) $r['weight'])) : self::WEIGHT_MIN,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新权重:直接按 DiceReward 主键 id 更新 weight,不依赖 direction/grid_number
|
||||
*
|
||||
* @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键,weight 为 1-10000
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function batchUpdateWeights(array $items): void
|
||||
{
|
||||
if (empty($items)) {
|
||||
return;
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
$id = isset($item['id']) ? (int) $item['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
$id = isset($item['reward_id']) ? (int) $item['reward_id'] : 0;
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new ApiException('存在无效的 DiceReward id');
|
||||
}
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
|
||||
$model = DiceReward::find($id);
|
||||
if ($model !== null) {
|
||||
$model->weight = $weight;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
/** BIGWIN 权重范围:0=0% 中奖,10000=100% 中奖;grid_number=5/30 固定 100% 不可改 */
|
||||
private const BIGWIN_WEIGHT_MAX = 10000;
|
||||
|
||||
/**
|
||||
* 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示)
|
||||
* 若 DiceReward 无该点数则 5/30 返回 10000,其余返回 0
|
||||
*/
|
||||
public function getBigwinWeightByGridNumber(int $gridNumber): int
|
||||
{
|
||||
$inst = DiceReward::getCachedInstance();
|
||||
$rows = $inst['by_tier_direction']['BIGWIN'][DiceReward::DIRECTION_CLOCKWISE] ?? [];
|
||||
foreach ($rows as $row) {
|
||||
if ((int) ($row['grid_number'] ?? 0) === $gridNumber) {
|
||||
return min(self::BIGWIN_WEIGHT_MAX, (int) ($row['weight'] ?? self::BIGWIN_WEIGHT_MAX));
|
||||
}
|
||||
}
|
||||
return in_array($gridNumber, [5, 30], true) ? self::BIGWIN_WEIGHT_MAX : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新);0=0% 中奖,10000=100% 中奖
|
||||
* 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入
|
||||
*/
|
||||
public function updateBigwinWeight(int $gridNumber, int $weight): void
|
||||
{
|
||||
$weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight));
|
||||
$config = DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if (! $config) {
|
||||
return;
|
||||
}
|
||||
$configArr = $config->toArray();
|
||||
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
|
||||
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
|
||||
$row = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if ($row) {
|
||||
$row->tier = 'BIGWIN';
|
||||
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
$row->start_index = (int) ($configArr['id'] ?? $row->start_index);
|
||||
$row->end_index = (int) ($configArr['id'] ?? $row->end_index);
|
||||
$row->ui_text = (string) ($configArr['ui_text'] ?? $row->ui_text);
|
||||
$row->real_ev = (float) ($configArr['real_ev'] ?? $row->real_ev);
|
||||
$row->remark = (string) ($configArr['remark'] ?? $row->remark);
|
||||
$row->type = $configArr['type'] ?? $row->type;
|
||||
$row->save();
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
$m->tier = 'BIGWIN';
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = (int) $gridNumber;
|
||||
$m->start_index = (int) ($configArr['id'] ?? 0);
|
||||
$m->end_index = (int) ($configArr['id'] ?? 0);
|
||||
$m->ui_text = (string) ($configArr['ui_text'] ?? '');
|
||||
$m->real_ev = (float) ($configArr['real_ev'] ?? 0);
|
||||
$m->remark = (string) ($configArr['remark'] ?? '');
|
||||
$m->type = $configArr['type'] ?? null;
|
||||
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
/** 盘面格数(用于顺时针/逆时针计算 end_index) */
|
||||
private const BOARD_SIZE = 26;
|
||||
|
||||
/** 点数摇取范围:5-30,顺时针与逆时针均需创建 */
|
||||
private const GRID_NUMBER_MIN = 5;
|
||||
private const GRID_NUMBER_MAX = 30;
|
||||
|
||||
/**
|
||||
* 创建奖励对照:先清空 dice_reward 表,再按两种方向为点数 5-30 生成记录。
|
||||
*
|
||||
* DiceReward 记录数据规则(与 config 通过 end_index 关联):
|
||||
* - 方向:direction = 0(顺时针)/ 1(逆时针)
|
||||
* - 摇取点数:grid_number
|
||||
* - 起始索引:start_index = DiceRewardConfig::where('grid_number', $grid_number)->first()->id
|
||||
* - 结束索引(顺时针):end_index = ($start_index + $grid_number) % 26(对 26 取余)
|
||||
* - 结束索引(逆时针):end_index = ($start_index - $grid_number >= 0) ? ($start_index - $grid_number) : (26 + $start_index - $grid_number)
|
||||
* - 奖励档位:tier = DiceRewardConfig::where('id', $end_index)->first()->tier
|
||||
* - 显示ui:ui_text = DiceRewardConfig::where('id', $end_index)->first()->ui_text
|
||||
* - 实际中奖:real_ev = DiceRewardConfig::where('id', $end_index)->first()->real_ev
|
||||
* - 备注:remark = DiceRewardConfig::where('id', $end_index)->first()->remark
|
||||
* - 类型:type = DiceRewardConfig::where('id', $end_index)->first()->type(-2=唯一惩罚,-1=抽水,0=回本,1=再来一次,2=小赚,3=大奖格)
|
||||
* - weight 默认 1,后续在权重编辑弹窗设置
|
||||
*
|
||||
* 例如顺时针摇取点数为 5 时:start_index = 配置中 grid_number=5 对应格位的 id,
|
||||
* 结束位置 = (起始位置 + grid_number) % 26,再取该位置的 config 的 id 作为 end_index。
|
||||
* 使用「按 id 排序后的盘面位置 0-25」做环形计算,避免 config.id 非连续时取模结果找不到;
|
||||
* 唯一键为 (direction, grid_number),保证每个点数、每个方向各一条记录,不因 end_index 相同而覆盖。
|
||||
*
|
||||
* @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int}
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function createRewardReferenceFromConfig(): array
|
||||
{
|
||||
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
throw new ApiException('奖励配置为空,请先维护 dice_reward_config');
|
||||
}
|
||||
$configCount = count($list);
|
||||
if ($configCount < self::BOARD_SIZE) {
|
||||
throw new ApiException(
|
||||
'奖励配置需覆盖 26 个格位(id 0-25 或 1-26),当前仅 ' . $configCount . ' 条,无法完整生成 5-30 共26个点数、顺时针与逆时针的奖励对照'
|
||||
);
|
||||
}
|
||||
|
||||
$table = (new DiceReward())->getTable();
|
||||
Db::execute('DELETE FROM `' . $table . '`');
|
||||
DiceReward::refreshCache();
|
||||
|
||||
// 按 id 排序后,盘面位置 0..25 对应 $list[$pos],避免 config.id 非 0-25/1-26 时取模结果找不到
|
||||
$gridToPosition = [];
|
||||
foreach ($list as $pos => $row) {
|
||||
$gn = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
if ($gn >= self::GRID_NUMBER_MIN && $gn <= self::GRID_NUMBER_MAX && !isset($gridToPosition[$gn])) {
|
||||
$gridToPosition[$gn] = $pos;
|
||||
}
|
||||
}
|
||||
|
||||
$createdCw = 0;
|
||||
$createdCcw = 0;
|
||||
$updatedCw = 0;
|
||||
$updatedCcw = 0;
|
||||
$skipped = 0;
|
||||
|
||||
for ($gridNumber = self::GRID_NUMBER_MIN; $gridNumber <= self::GRID_NUMBER_MAX; $gridNumber++) {
|
||||
if (!isset($gridToPosition[$gridNumber])) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
$startPos = $gridToPosition[$gridNumber];
|
||||
$startRow = $list[$startPos];
|
||||
$startId = isset($startRow['id']) ? (int) $startRow['id'] : 0;
|
||||
|
||||
$endPosCw = ($startPos + $gridNumber) % self::BOARD_SIZE;
|
||||
$endPosCcw = $startPos - $gridNumber >= 0 ? $startPos - $gridNumber : self::BOARD_SIZE + $startPos - $gridNumber;
|
||||
|
||||
$configCw = $list[$endPosCw] ?? null;
|
||||
$configCcw = $list[$endPosCcw] ?? null;
|
||||
$endIdCw = $configCw !== null && isset($configCw['id']) ? (int) $configCw['id'] : 0;
|
||||
$endIdCcw = $configCcw !== null && isset($configCcw['id']) ? (int) $configCcw['id'] : 0;
|
||||
|
||||
if ($configCw !== null) {
|
||||
$tier = isset($configCw['tier']) ? trim((string) $configCw['tier']) : '';
|
||||
if ($tier !== '') {
|
||||
// 使用对应奖励配置的 weight 作为格子权重(若未配置则退回最小权重)
|
||||
$weightCw = isset($configCw['weight']) && $configCw['weight'] !== null
|
||||
? $configCw['weight']
|
||||
: self::WEIGHT_MIN;
|
||||
$payloadCw = [
|
||||
'tier' => $tier,
|
||||
'weight' => $weightCw,
|
||||
'grid_number' => $gridNumber,
|
||||
'start_index' => $startId,
|
||||
'end_index' => $endIdCw,
|
||||
'ui_text' => $configCw['ui_text'] ?? '',
|
||||
'real_ev' => $configCw['real_ev'] ?? null,
|
||||
'remark' => $configCw['remark'] ?? '',
|
||||
'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0,
|
||||
];
|
||||
$existing = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber)->find();
|
||||
if ($existing) {
|
||||
DiceReward::where('id', $existing->id)->update($payloadCw);
|
||||
$updatedCw++;
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
$m->tier = $tier;
|
||||
$m->direction = DiceReward::DIRECTION_CLOCKWISE;
|
||||
$m->end_index = $endIdCw;
|
||||
$m->weight = $weightCw;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->start_index = $startId;
|
||||
$m->ui_text = $configCw['ui_text'] ?? '';
|
||||
$m->real_ev = $configCw['real_ev'] ?? null;
|
||||
$m->remark = $configCw['remark'] ?? '';
|
||||
$m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0;
|
||||
$m->save();
|
||||
$createdCw++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($configCcw !== null) {
|
||||
$tier = isset($configCcw['tier']) ? trim((string) $configCcw['tier']) : '';
|
||||
if ($tier !== '') {
|
||||
// 使用对应奖励配置的 weight 作为格子权重(若未配置则退回最小权重)
|
||||
$weightCcw = isset($configCcw['weight']) && $configCcw['weight'] !== null
|
||||
? $configCcw['weight']
|
||||
: self::WEIGHT_MIN;
|
||||
$payloadCcw = [
|
||||
'tier' => $tier,
|
||||
'weight' => $weightCcw,
|
||||
'grid_number' => $gridNumber,
|
||||
'start_index' => $startId,
|
||||
'end_index' => $endIdCcw,
|
||||
'ui_text' => $configCcw['ui_text'] ?? '',
|
||||
'real_ev' => $configCcw['real_ev'] ?? null,
|
||||
'remark' => $configCcw['remark'] ?? '',
|
||||
'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0,
|
||||
];
|
||||
$existing = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber)->find();
|
||||
if ($existing) {
|
||||
DiceReward::where('id', $existing->id)->update($payloadCcw);
|
||||
$updatedCcw++;
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
$m->tier = $tier;
|
||||
$m->direction = DiceReward::DIRECTION_COUNTERCLOCKWISE;
|
||||
$m->end_index = $endIdCcw;
|
||||
$m->weight = $weightCcw;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->start_index = $startId;
|
||||
$m->ui_text = $configCcw['ui_text'] ?? '';
|
||||
$m->real_ev = $configCcw['real_ev'] ?? null;
|
||||
$m->remark = $configCcw['remark'] ?? '';
|
||||
$m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0;
|
||||
$m->save();
|
||||
$createdCcw++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DiceReward::refreshCache();
|
||||
return [
|
||||
'created_clockwise' => $createdCw,
|
||||
'created_counterclockwise' => $createdCcw,
|
||||
'updated_clockwise' => $updatedCw,
|
||||
'updated_counterclockwise' => $updatedCcw,
|
||||
'skipped' => $skipped,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,22 +6,408 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\reward_config;
|
||||
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 奖励配置逻辑层
|
||||
* 奖励配置逻辑层(DiceRewardConfig)
|
||||
* weight 1-10000,各档位权重和不限制
|
||||
*/
|
||||
class DiceRewardConfigLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
/** weight 取值范围 */
|
||||
private const WEIGHT_MIN = 1;
|
||||
private const WEIGHT_MAX = 10000;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceRewardConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增:保存后刷新缓存(权重已迁移至 dice_reward 表)
|
||||
*/
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
$result = parent::add($data);
|
||||
DiceRewardConfig::refreshCache();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改:保存后刷新缓存;BIGWIN 的 weight 直接写入 dice_reward_config 表,抽奖时从 Config 读取
|
||||
*/
|
||||
public function edit($id, array $data): mixed
|
||||
{
|
||||
$result = parent::edit($id, $data);
|
||||
DiceRewardConfig::refreshCache();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为列表/分页数据中的 BIGWIN 行附加 weight(来自 DiceReward 缓存)
|
||||
*/
|
||||
public function enrichBigwinWeight(array $listResult): array
|
||||
{
|
||||
$key = isset($listResult['data']) ? 'data' : (isset($listResult['records']) ? 'records' : null);
|
||||
if ($key === null || empty($listResult[$key])) {
|
||||
return $listResult;
|
||||
}
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
foreach ($listResult[$key] as $i => $row) {
|
||||
if (isset($row['tier']) && $row['tier'] === 'BIGWIN' && isset($row['grid_number'])) {
|
||||
$listResult[$key][$i]['weight'] = $rewardLogic->getBigwinWeightByGridNumber((int) $row['grid_number']);
|
||||
}
|
||||
}
|
||||
return $listResult;
|
||||
}
|
||||
|
||||
/** 奖励索引必须为 26 条,id 为 0~25,点数 5~30 各出现一次 */
|
||||
private const BATCH_INDEX_COUNT = 26;
|
||||
private const INDEX_ID_MIN = 0;
|
||||
private const INDEX_ID_MAX = 25;
|
||||
private const GRID_NUMBER_MIN = 5;
|
||||
private const GRID_NUMBER_MAX = 30;
|
||||
|
||||
/**
|
||||
* 校验批量更新项(奖励索引表单独立提交,可能只含非 BIGWIN 的若干条)
|
||||
* - 每项必须包含 id、grid_number;grid_number 须在 5~30,提交项内 grid_number 不能重复
|
||||
* - 若为 26 条则额外校验:id 为 0~25 各一、grid_number 为 5~30 各一
|
||||
* @return string|null 校验失败返回错误信息,通过返回 null
|
||||
*/
|
||||
public function validateBatchUpdateItems(array $items): ?string
|
||||
{
|
||||
if (count($items) === 0) {
|
||||
return '提交数据不能为空';
|
||||
}
|
||||
$ids = [];
|
||||
$gridNumbers = [];
|
||||
foreach ($items as $item) {
|
||||
if (! array_key_exists('id', $item) || $item['id'] === null || $item['id'] === '') {
|
||||
return '每项必须包含 id';
|
||||
}
|
||||
$id = (int) $item['id'];
|
||||
$ids[] = $id;
|
||||
if (! array_key_exists('grid_number', $item)) {
|
||||
return '每项必须包含 grid_number';
|
||||
}
|
||||
$gn = (int) $item['grid_number'];
|
||||
if ($gn < self::GRID_NUMBER_MIN || $gn > self::GRID_NUMBER_MAX) {
|
||||
return '色子点数 grid_number 只能为 ' . self::GRID_NUMBER_MIN . '~' . self::GRID_NUMBER_MAX . ',当前存在 ' . $gn;
|
||||
}
|
||||
$gridNumbers[] = $gn;
|
||||
}
|
||||
$gridDuplicates = $this->findDuplicateValues($gridNumbers);
|
||||
if ($gridDuplicates !== []) {
|
||||
sort($gridDuplicates);
|
||||
return '色子点数在本批内不能重复,重复的点数为:' . implode('、', $gridDuplicates);
|
||||
}
|
||||
$cnt = count($items);
|
||||
if ($cnt === self::BATCH_INDEX_COUNT) {
|
||||
foreach ($ids as $id) {
|
||||
if ($id < self::INDEX_ID_MIN || $id > self::INDEX_ID_MAX) {
|
||||
return '索引 id 只能为 ' . self::INDEX_ID_MIN . '~' . self::INDEX_ID_MAX . ',当前存在 id=' . $id;
|
||||
}
|
||||
}
|
||||
$idDuplicates = $this->findDuplicateValues($ids);
|
||||
if ($idDuplicates !== []) {
|
||||
sort($idDuplicates);
|
||||
return '索引 id 必须为 0~25 各出现一次不能重复,重复的 id 为:' . implode('、', $idDuplicates);
|
||||
}
|
||||
$requiredIds = range(self::INDEX_ID_MIN, self::INDEX_ID_MAX);
|
||||
if (array_diff($requiredIds, $ids) !== [] || array_diff($ids, $requiredIds) !== []) {
|
||||
return '索引 id 必须且只能为 0~25 各一个';
|
||||
}
|
||||
$requiredGrid = range(self::GRID_NUMBER_MIN, self::GRID_NUMBER_MAX);
|
||||
if (array_diff($requiredGrid, $gridNumbers) !== [] || array_diff($gridNumbers, $requiredGrid) !== []) {
|
||||
return '色子点数必须且只能为 5~30 各一个';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找出数组中出现多于一次的值
|
||||
* @param array $arr
|
||||
* @return array 重复出现的值(去重)
|
||||
*/
|
||||
private function findDuplicateValues(array $arr): array
|
||||
{
|
||||
$counts = array_count_values($arr);
|
||||
$duplicates = [];
|
||||
foreach ($counts as $value => $count) {
|
||||
if ($count > 1) {
|
||||
$duplicates[] = $value;
|
||||
}
|
||||
}
|
||||
return $duplicates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新奖励索引配置:grid_number、ui_text、real_ev、tier、remark(不含 weight,BIGWIN 权重单独接口)
|
||||
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
|
||||
*/
|
||||
public function batchUpdate(array $items): void
|
||||
{
|
||||
foreach ($items as $row) {
|
||||
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
|
||||
continue;
|
||||
}
|
||||
$id = (int) $row['id'];
|
||||
$data = [];
|
||||
foreach (['grid_number', 'ui_text', 'ui_text_en', 'real_ev', 'tier', 'remark'] as $field) {
|
||||
if (array_key_exists($field, $row)) {
|
||||
$data[$field] = $row[$field];
|
||||
}
|
||||
}
|
||||
if (! empty($data)) {
|
||||
parent::edit($id, $data);
|
||||
}
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验大奖权重提交项:点数 5~30,本批内 grid_number 不能重复
|
||||
* @return string|null 校验失败返回错误信息(含重复的点数),通过返回 null
|
||||
*/
|
||||
public function validateBigwinWeightItems(array $items): ?string
|
||||
{
|
||||
if (count($items) === 0) {
|
||||
return '提交数据不能为空';
|
||||
}
|
||||
$gridNumbers = [];
|
||||
foreach ($items as $row) {
|
||||
$gn = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
if ($gn < self::GRID_NUMBER_MIN || $gn > self::GRID_NUMBER_MAX) {
|
||||
return '色子点数 grid_number 只能为 ' . self::GRID_NUMBER_MIN . '~' . self::GRID_NUMBER_MAX . ',当前存在 ' . $gn;
|
||||
}
|
||||
$gridNumbers[] = $gn;
|
||||
}
|
||||
$duplicates = $this->findDuplicateValues($gridNumbers);
|
||||
if ($duplicates !== []) {
|
||||
sort($duplicates);
|
||||
return '大奖权重本批内点数不能重复,重复的点数为:' . implode('、', $duplicates);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward)
|
||||
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
|
||||
*/
|
||||
public function batchUpdateBigwinWeight(array $items): void
|
||||
{
|
||||
$weightMin = 0;
|
||||
$weightMax = 10000;
|
||||
foreach ($items as $row) {
|
||||
$gridNumber = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
$weight = isset($row['weight']) ? (int) $row['weight'] : 0;
|
||||
if ($gridNumber < 5 || $gridNumber > 30) {
|
||||
continue;
|
||||
}
|
||||
$weight = max($weightMin, min($weightMax, $weight));
|
||||
$this->model->where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除后刷新缓存
|
||||
*/
|
||||
public function destroy($ids): bool
|
||||
{
|
||||
$result = parent::destroy($ids);
|
||||
if ($result) {
|
||||
DiceRewardConfig::refreshCache();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位分组返回奖励配置列表(仅配置,权重在 dice_reward 表;权重配比请用 DiceRewardLogic::getListGroupedByTierWithDirection)
|
||||
*/
|
||||
public function getListGroupedByTier(): array
|
||||
{
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'];
|
||||
$list = $this->model->whereIn('tier', $tiers)->order('tier')->order('id')->select()->toArray();
|
||||
$grouped = [];
|
||||
foreach ($tiers as $t) {
|
||||
$grouped[$t] = [];
|
||||
}
|
||||
foreach ($list as $row) {
|
||||
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
|
||||
if ($tier !== '' && isset($grouped[$tier])) {
|
||||
$grouped[$tier][] = $row;
|
||||
}
|
||||
}
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/** 测试时档位权重均为 0 的异常标识 */
|
||||
private const EXCEPTION_WEIGHT_ALL_ZERO = 'REWARD_WEIGHT_ALL_ZERO';
|
||||
|
||||
/**
|
||||
* 按权重抽取一条配置(与 PlayStartLogic 抽奖逻辑一致,仅 weight>0 参与)
|
||||
*/
|
||||
private static function drawRewardByWeight(array $rewards): array
|
||||
{
|
||||
if (empty($rewards)) {
|
||||
throw new \InvalidArgumentException('rewards 不能为空');
|
||||
}
|
||||
$candidateWeights = [];
|
||||
foreach ($rewards as $i => $row) {
|
||||
$w = isset($row['weight']) ? (float) $row['weight'] : 0.0;
|
||||
if ($w > 0) {
|
||||
$candidateWeights[$i] = $w;
|
||||
}
|
||||
}
|
||||
$total = (float) array_sum($candidateWeights);
|
||||
if ($total > 0) {
|
||||
$r = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX) * $total;
|
||||
$acc = 0.0;
|
||||
foreach ($candidateWeights as $i => $w) {
|
||||
$acc += $w;
|
||||
if ($r < $acc) {
|
||||
return $rewards[$i];
|
||||
}
|
||||
}
|
||||
return $rewards[array_key_last($candidateWeights)];
|
||||
}
|
||||
throw new \RuntimeException(self::EXCEPTION_WEIGHT_ALL_ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位权重数组抽取 T1-T5
|
||||
*/
|
||||
private static function drawTierByWeightArray(array $tiers, array $weights): string
|
||||
{
|
||||
$total = array_sum($weights);
|
||||
if ($total <= 0) {
|
||||
return $tiers[random_int(0, count($tiers) - 1)];
|
||||
}
|
||||
$r = random_int(1, (int) $total);
|
||||
$acc = 0;
|
||||
foreach ($weights as $i => $w) {
|
||||
$acc += (int) $w;
|
||||
if ($r <= $acc) {
|
||||
return $tiers[$i];
|
||||
}
|
||||
}
|
||||
return $tiers[count($tiers) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行权重配比测试:仅按当前配置在内存中模拟 N 次抽奖,统计各 grid_number 落点数量。
|
||||
* 不创建任何游玩记录(DicePlayRecord)、不扣券、不写钱包,仅用于验证权重配比效果。
|
||||
*
|
||||
* @param int $testCount 测试次数 100/500/1000/5000/10000
|
||||
* @param bool $saveRecord 是否保存到 dice_reward_config_record(测试记录表,非游玩记录)
|
||||
* @param int|null $adminId 执行人管理员ID
|
||||
* @param int|null $lotteryConfigId 奖池配置ID(DiceLotteryPoolConfig),用于设定 T1-T5 档位概率;不传则使用 type=0 的配置或均等
|
||||
* @return array{counts: array<int,int>, record_id: int|null} counts 为 grid_number=>出现次数
|
||||
*/
|
||||
public function runWeightTest(int $testCount, bool $saveRecord = true, ?int $adminId = null, ?int $lotteryConfigId = null): array
|
||||
{
|
||||
$allowedCounts = [100, 500, 1000, 5000, 10000];
|
||||
if (!in_array($testCount, $allowedCounts, true)) {
|
||||
throw new ApiException('测试次数仅支持 100、500、1000、5000、10000');
|
||||
}
|
||||
|
||||
$grouped = [];
|
||||
foreach (['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'] as $t) {
|
||||
$grouped[$t] = $this->model::getCachedByTierForDirection($t, 0);
|
||||
}
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$tierWeights = [1, 1, 1, 1, 1];
|
||||
$config = null;
|
||||
if ($lotteryConfigId !== null && $lotteryConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
|
||||
}
|
||||
if (!$config) {
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
}
|
||||
if ($config) {
|
||||
$tierWeights = [
|
||||
(int) ($config->t1_weight ?? 0),
|
||||
(int) ($config->t2_weight ?? 0),
|
||||
(int) ($config->t3_weight ?? 0),
|
||||
(int) ($config->t4_weight ?? 0),
|
||||
(int) ($config->t5_weight ?? 0),
|
||||
];
|
||||
if (array_sum($tierWeights) <= 0) {
|
||||
$tierWeights = [1, 1, 1, 1, 1];
|
||||
}
|
||||
}
|
||||
|
||||
$counts = [];
|
||||
$maxRetry = 20;
|
||||
for ($i = 0; $i < $testCount; $i++) {
|
||||
$tier = self::drawTierByWeightArray($tiers, $tierWeights);
|
||||
$rewards = $grouped[$tier] ?? [];
|
||||
if (empty($rewards)) {
|
||||
continue;
|
||||
}
|
||||
$attempt = 0;
|
||||
while ($attempt < $maxRetry) {
|
||||
try {
|
||||
$chosen = self::drawRewardByWeight($rewards);
|
||||
$gridNumber = isset($chosen['grid_number']) ? (int) $chosen['grid_number'] : 0;
|
||||
if ($gridNumber >= 5 && $gridNumber <= 30) {
|
||||
$counts[$gridNumber] = ($counts[$gridNumber] ?? 0) + 1;
|
||||
}
|
||||
break;
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === self::EXCEPTION_WEIGHT_ALL_ZERO) {
|
||||
$attempt++;
|
||||
continue;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$snapshot = [];
|
||||
foreach ($grouped as $tierKey => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
$snapshot[] = [
|
||||
'id' => (int) ($row['id'] ?? 0),
|
||||
'grid_number' => (int) ($row['grid_number'] ?? 0),
|
||||
'tier' => (string) ($row['tier'] ?? ''),
|
||||
'weight' => (int) ($row['weight'] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$tierWeightsSnapshot = [
|
||||
'T1' => $tierWeights[0] ?? 0,
|
||||
'T2' => $tierWeights[1] ?? 0,
|
||||
'T3' => $tierWeights[2] ?? 0,
|
||||
'T4' => $tierWeights[3] ?? 0,
|
||||
'T5' => $tierWeights[4] ?? 0,
|
||||
];
|
||||
$recordId = null;
|
||||
if ($saveRecord) {
|
||||
$record = new DiceRewardConfigRecord();
|
||||
$record->test_count = $testCount;
|
||||
$record->weight_config_snapshot = $snapshot;
|
||||
$record->tier_weights_snapshot = $tierWeightsSnapshot;
|
||||
$record->lottery_config_id = $config ? (int) $config->id : null;
|
||||
$record->result_counts = $counts;
|
||||
$record->admin_id = $adminId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
$recordId = (int) $record->id;
|
||||
}
|
||||
|
||||
return ['counts' => $counts, 'record_id' => $recordId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\reward_config_record;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录逻辑层
|
||||
*/
|
||||
class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceRewardConfigRecord();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表,并为每条记录附加 admin_name(管理员姓名:realname 或 username)
|
||||
*/
|
||||
public function getList($query): mixed
|
||||
{
|
||||
$result = parent::getList($query);
|
||||
if (!is_array($result)) {
|
||||
return $result;
|
||||
}
|
||||
$rows = $result['data'] ?? $result['records'] ?? null;
|
||||
if (!is_array($rows) || empty($rows)) {
|
||||
return $result;
|
||||
}
|
||||
$adminIds = array_unique(array_filter(array_column($rows, 'admin_id')));
|
||||
$nameMap = $this->getAdminNameMap($adminIds);
|
||||
$key = isset($result['data']) ? 'data' : 'records';
|
||||
foreach ($result[$key] as &$row) {
|
||||
$aid = isset($row['admin_id']) ? (int) $row['admin_id'] : 0;
|
||||
$row['admin_name'] = $nameMap[$aid] ?? ($aid > 0 ? '' : '—');
|
||||
}
|
||||
unset($row);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据管理员 ID 列表获取 id => 姓名(realname 优先,否则 username)
|
||||
* @param array $adminIds
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function getAdminNameMap(array $adminIds): array
|
||||
{
|
||||
if (empty($adminIds)) {
|
||||
return [];
|
||||
}
|
||||
$list = SystemUser::whereIn('id', $adminIds)->field('id,realname,username')->select()->toArray();
|
||||
$map = [];
|
||||
foreach ($list as $user) {
|
||||
$user = is_array($user) ? $user : (array) $user;
|
||||
$id = (int) ($user['id'] ?? 0);
|
||||
$name = trim((string) ($user['realname'] ?? ''));
|
||||
if ($name === '') {
|
||||
$name = trim((string) ($user['username'] ?? ''));
|
||||
}
|
||||
$map[$id] = $name !== '' ? $name : (string) $id;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将测试记录导入:DiceReward(权重快照)、DiceRewardConfig(BIGWIN weight)、DiceLotteryPoolConfig(付费/免费 T1-T5)
|
||||
* @param int $recordId 测试记录 ID
|
||||
* @param int|null $paidLotteryConfigId 导入付费档位概率到的奖池(type=0),不传则用记录 paid_lottery_config_id
|
||||
* @param int|null $freeLotteryConfigId 导入免费档位概率到的奖池(type=1),不传则用记录 free_lottery_config_id
|
||||
* @param int|null $lotteryConfigId 兼容旧版:不传 paid/free 时用作统一奖池
|
||||
*/
|
||||
public function importFromRecord(int $recordId, ?int $paidLotteryConfigId = null, ?int $freeLotteryConfigId = null, ?int $lotteryConfigId = null): void
|
||||
{
|
||||
$record = $this->model->find($recordId);
|
||||
if (!$record) {
|
||||
throw new ApiException('测试记录不存在');
|
||||
}
|
||||
$record = is_array($record) ? $record : $record->toArray();
|
||||
|
||||
$snapshot = $record['weight_config_snapshot'] ?? null;
|
||||
if (is_string($snapshot)) {
|
||||
$snapshot = json_decode($snapshot, true);
|
||||
}
|
||||
if (is_array($snapshot) && !empty($snapshot)) {
|
||||
foreach ($snapshot as $item) {
|
||||
$direction = isset($item['direction']) ? (int) $item['direction'] : null;
|
||||
$gridNumber = isset($item['grid_number']) ? (int) $item['grid_number'] : 0;
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : 1;
|
||||
$weight = max(1, min(10000, $weight));
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
continue;
|
||||
}
|
||||
if ($gridNumber <= 0) {
|
||||
continue;
|
||||
}
|
||||
$tier = isset($item['tier']) ? (string) $item['tier'] : '';
|
||||
if ($tier === '') {
|
||||
// 若快照中未带 tier,则尝试按方向+点数从现有配置中取
|
||||
$tierFromDb = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber)->value('tier');
|
||||
$tier = $tierFromDb !== null ? (string) $tierFromDb : '';
|
||||
}
|
||||
// 仅按方向 + 点数更新 DiceReward(若存在则更新,不存在才插入,避免唯一键冲突)
|
||||
$reward = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if ($reward) {
|
||||
$reward->weight = $weight;
|
||||
// 若快照中有 tier,补齐 tier 信息
|
||||
if ($tier !== '' && (string) $reward->tier !== $tier) {
|
||||
$reward->tier = $tier;
|
||||
}
|
||||
$reward->save();
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
if ($tier !== '') {
|
||||
$m->tier = $tier;
|
||||
}
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->weight = $weight;
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
|
||||
$recordBigwinWeight = $record['bigwin_weight'] ?? null;
|
||||
if (is_string($recordBigwinWeight)) {
|
||||
$decoded = json_decode($recordBigwinWeight, true);
|
||||
$recordBigwinWeight = is_array($decoded) ? $decoded : null;
|
||||
}
|
||||
if (is_array($recordBigwinWeight) && !empty($recordBigwinWeight)) {
|
||||
foreach ($recordBigwinWeight as $grid => $w) {
|
||||
$gridNumber = (int) $grid;
|
||||
$weight = (int) $w;
|
||||
if ($gridNumber <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($weight < 0) {
|
||||
$weight = 0;
|
||||
}
|
||||
DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
}
|
||||
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$tierSnapshot = $record['tier_weights_snapshot'] ?? null;
|
||||
if (is_string($tierSnapshot)) {
|
||||
$tierSnapshot = json_decode($tierSnapshot, true);
|
||||
}
|
||||
$paidWeights = $record['paid_tier_weights'] ?? null;
|
||||
if (is_string($paidWeights)) {
|
||||
$paidWeights = json_decode($paidWeights, true);
|
||||
}
|
||||
$freeWeights = $record['free_tier_weights'] ?? null;
|
||||
if (is_string($freeWeights)) {
|
||||
$freeWeights = json_decode($freeWeights, true);
|
||||
}
|
||||
$fallbackLotteryId = $lotteryConfigId > 0 ? $lotteryConfigId : (isset($record['lottery_config_id']) && (int) $record['lottery_config_id'] > 0 ? (int) $record['lottery_config_id'] : null);
|
||||
$paidTargetId = $paidLotteryConfigId > 0 ? $paidLotteryConfigId : ($fallbackLotteryId ?? (isset($record['paid_lottery_config_id']) && (int) $record['paid_lottery_config_id'] > 0 ? (int) $record['paid_lottery_config_id'] : null));
|
||||
$freeTargetId = $freeLotteryConfigId > 0 ? $freeLotteryConfigId : (isset($record['free_lottery_config_id']) && (int) $record['free_lottery_config_id'] > 0 ? (int) $record['free_lottery_config_id'] : null);
|
||||
|
||||
// tier_weights_snapshot 新结构:['paid' => [...], 'free' => [...]]
|
||||
$snapshotPaid = null;
|
||||
$snapshotFree = null;
|
||||
if (is_array($tierSnapshot) && !empty($tierSnapshot)) {
|
||||
if (array_key_exists('paid', $tierSnapshot) || array_key_exists('free', $tierSnapshot)) {
|
||||
if (isset($tierSnapshot['paid']) && is_array($tierSnapshot['paid'])) {
|
||||
$snapshotPaid = $tierSnapshot['paid'];
|
||||
}
|
||||
if (isset($tierSnapshot['free']) && is_array($tierSnapshot['free'])) {
|
||||
$snapshotFree = $tierSnapshot['free'];
|
||||
}
|
||||
} else {
|
||||
// 兼容旧结构:直接就是一个 T1-T5 的数组,视为付费
|
||||
$snapshotPaid = $tierSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
$paidData = is_array($paidWeights) && !empty($paidWeights) ? $paidWeights : $snapshotPaid;
|
||||
$freeData = is_array($freeWeights) && !empty($freeWeights) ? $freeWeights : $snapshotFree;
|
||||
|
||||
if (is_array($paidData) && $paidTargetId > 0) {
|
||||
$pool = DiceLotteryPoolConfig::find($paidTargetId);
|
||||
if (!$pool) {
|
||||
throw new ApiException('付费奖池配置不存在');
|
||||
}
|
||||
$update = [
|
||||
't1_weight' => (int) ($paidData['T1'] ?? $paidData['t1'] ?? 0),
|
||||
't2_weight' => (int) ($paidData['T2'] ?? $paidData['t2'] ?? 0),
|
||||
't3_weight' => (int) ($paidData['T3'] ?? $paidData['t3'] ?? 0),
|
||||
't4_weight' => (int) ($paidData['T4'] ?? $paidData['t4'] ?? 0),
|
||||
't5_weight' => (int) ($paidData['T5'] ?? $paidData['t5'] ?? 0),
|
||||
];
|
||||
DiceLotteryPoolConfig::where('id', $paidTargetId)->update($update);
|
||||
}
|
||||
if (is_array($freeData) && $freeTargetId > 0) {
|
||||
$pool = DiceLotteryPoolConfig::find($freeTargetId);
|
||||
if (!$pool) {
|
||||
throw new ApiException('免费奖池配置不存在');
|
||||
}
|
||||
$update = [
|
||||
't1_weight' => (int) ($freeData['T1'] ?? $freeData['t1'] ?? 0),
|
||||
't2_weight' => (int) ($freeData['T2'] ?? $freeData['t2'] ?? 0),
|
||||
't3_weight' => (int) ($freeData['T3'] ?? $freeData['t3'] ?? 0),
|
||||
't4_weight' => (int) ($freeData['T4'] ?? $freeData['t4'] ?? 0),
|
||||
't5_weight' => (int) ($freeData['T5'] ?? $freeData['t5'] ?? 0),
|
||||
];
|
||||
DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update);
|
||||
}
|
||||
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一键测试权重记录并返回 ID,供后台执行器按付费/免费、顺逆方向交替写入 dice_play_record_test
|
||||
* 支持两种模式:1)选择奖池配置 lottery_config_id,档位概率取自配置;2)不选配置,使用自定义 paid_tier_weights / free_tier_weights
|
||||
* @param array|int $params 数组:lottery_config_id(可选), paid_s_count, paid_n_count, free_s_count, free_n_count;或兼容旧版传 4 个 int 时视为 (paid_s_count, paid_n_count, free_s_count, free_n_count)
|
||||
* @param int|null $adminId 执行人(旧版 4 参调用时第二参为 paid_n_count,此处不传 adminId)
|
||||
* @return int 记录 ID
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function createWeightTestRecord(array|int $params, mixed $adminIdOrFreeS = null, mixed $freeSOrFreeN = null, mixed $freeN = null): int
|
||||
{
|
||||
$adminId = null;
|
||||
if (!is_array($params)) {
|
||||
// 兼容旧版调用:createWeightTestRecord(paid_s_count, paid_n_count, free_s_count, free_n_count)
|
||||
$params = [
|
||||
'paid_s_count' => (int) $params,
|
||||
'paid_n_count' => (int) $adminIdOrFreeS,
|
||||
'free_s_count' => (int) $freeSOrFreeN,
|
||||
'free_n_count' => (int) $freeN,
|
||||
];
|
||||
} else {
|
||||
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
|
||||
}
|
||||
$allowed = [100, 500, 1000, 5000];
|
||||
$lotteryConfigId = isset($params['lottery_config_id']) ? (int) $params['lottery_config_id'] : 0;
|
||||
$paidConfigId = isset($params['paid_lottery_config_id']) ? (int) $params['paid_lottery_config_id'] : 0;
|
||||
$freeConfigId = isset($params['free_lottery_config_id']) ? (int) $params['free_lottery_config_id'] : 0;
|
||||
if ($paidConfigId <= 0 && $lotteryConfigId > 0) {
|
||||
$paidConfigId = $lotteryConfigId;
|
||||
}
|
||||
if ($freeConfigId <= 0 && $lotteryConfigId > 0) {
|
||||
$freeConfigId = $lotteryConfigId;
|
||||
}
|
||||
$paidS = isset($params['paid_s_count']) ? (int) $params['paid_s_count'] : (int) ($params['s_count'] ?? 0);
|
||||
$paidN = isset($params['paid_n_count']) ? (int) $params['paid_n_count'] : (int) ($params['n_count'] ?? 0);
|
||||
$freeS = (int) ($params['free_s_count'] ?? 0);
|
||||
$freeN = (int) ($params['free_n_count'] ?? 0);
|
||||
|
||||
foreach ([$paidS, $paidN, $freeS, $freeN] as $c) {
|
||||
if ($c !== 0 && !in_array($c, $allowed, true)) {
|
||||
throw new ApiException('各抽奖次数仅支持 0、100、500、1000、5000');
|
||||
}
|
||||
}
|
||||
$total = $paidS + $paidN + $freeS + $freeN;
|
||||
if ($total <= 0) {
|
||||
throw new ApiException('付费或免费至少一种方向次数之和大于 0');
|
||||
}
|
||||
|
||||
$snapshot = [];
|
||||
// 档位权重快照:区分付费/免费,结构为 ['paid' => [...], 'free' => [...]]
|
||||
$tierWeightsSnapshot = [
|
||||
'paid' => null,
|
||||
'free' => null,
|
||||
];
|
||||
$paidTierWeights = null;
|
||||
$freeTierWeights = null;
|
||||
|
||||
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟
|
||||
$instance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $instance['by_tier_direction'] ?? [];
|
||||
foreach ($byTierDirection as $tier => $byDir) {
|
||||
foreach ($byDir as $dir => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
$snapshot[] = [
|
||||
// 不再记录 DiceReward.id,只记录方向、点数和、档位与权重
|
||||
'direction' => (int) $dir,
|
||||
'grid_number' => (int) ($row['grid_number'] ?? 0),
|
||||
'tier' => (string) ($tier ?? ''),
|
||||
'weight' => (int) ($row['weight'] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
|
||||
// JSON 结构 {"grid_number": weight, ...}
|
||||
$bigwinWeights = [];
|
||||
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN');
|
||||
foreach ($bigwinConfigs as $cfg) {
|
||||
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
|
||||
if ($grid <= 0) {
|
||||
continue;
|
||||
}
|
||||
$w = isset($cfg['weight']) ? (int) $cfg['weight'] : 0;
|
||||
$bigwinWeights[$grid] = $w;
|
||||
}
|
||||
|
||||
if ($paidConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($paidConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('付费奖池配置不存在');
|
||||
}
|
||||
$tierWeightsSnapshot['paid'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
'T2' => (int) ($config->t2_weight ?? 0),
|
||||
'T3' => (int) ($config->t3_weight ?? 0),
|
||||
'T4' => (int) ($config->t4_weight ?? 0),
|
||||
'T5' => (int) ($config->t5_weight ?? 0),
|
||||
];
|
||||
} else {
|
||||
$paidTierWeights = $params['paid_tier_weights'] ?? null;
|
||||
if (!is_array($paidTierWeights)) {
|
||||
throw new ApiException('付费未选择奖池配置时,请填写付费自定义档位概率(T1~T5)');
|
||||
}
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
foreach ($tiers as $t) {
|
||||
$v = (int) ($paidTierWeights[$t] ?? 0);
|
||||
if ($v < 0 || $v > 100) {
|
||||
throw new ApiException('付费档位概率每档只能 0-100%');
|
||||
}
|
||||
$paidTierWeights[$t] = $v;
|
||||
}
|
||||
$paidSum = array_sum(array_intersect_key($paidTierWeights, array_flip($tiers)));
|
||||
if ($paidSum > 100) {
|
||||
throw new ApiException('付费档位概率 T1~T5 之和不能超过 100%');
|
||||
}
|
||||
$tierWeightsSnapshot['paid'] = $paidTierWeights;
|
||||
}
|
||||
|
||||
if ($freeConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($freeConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('免费奖池配置不存在');
|
||||
}
|
||||
$tierWeightsSnapshot['free'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
'T2' => (int) ($config->t2_weight ?? 0),
|
||||
'T3' => (int) ($config->t3_weight ?? 0),
|
||||
'T4' => (int) ($config->t4_weight ?? 0),
|
||||
'T5' => (int) ($config->t5_weight ?? 0),
|
||||
];
|
||||
} else {
|
||||
$freeTierWeights = $params['free_tier_weights'] ?? null;
|
||||
if (!is_array($freeTierWeights)) {
|
||||
throw new ApiException('免费未选择奖池配置时,请填写免费自定义档位概率(T1~T5)');
|
||||
}
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
foreach ($tiers as $t) {
|
||||
$v = (int) ($freeTierWeights[$t] ?? 0);
|
||||
if ($v < 0 || $v > 100) {
|
||||
throw new ApiException('免费档位概率每档只能 0-100%');
|
||||
}
|
||||
$freeTierWeights[$t] = $v;
|
||||
}
|
||||
$freeSum = array_sum(array_intersect_key($freeTierWeights, array_flip($tiers)));
|
||||
if ($freeSum > 100) {
|
||||
throw new ApiException('免费档位概率 T1~T5 之和不能超过 100%');
|
||||
}
|
||||
$tierWeightsSnapshot['free'] = $freeTierWeights;
|
||||
}
|
||||
|
||||
// 兼容:若某一侧未配置,则保存为空数组,方便前端直接解构
|
||||
if (!is_array($tierWeightsSnapshot['paid'])) {
|
||||
$tierWeightsSnapshot['paid'] = [];
|
||||
}
|
||||
if (!is_array($tierWeightsSnapshot['free'])) {
|
||||
$tierWeightsSnapshot['free'] = [];
|
||||
}
|
||||
|
||||
$record = new DiceRewardConfigRecord();
|
||||
$record->test_count = $total;
|
||||
$record->weight_config_snapshot = $snapshot;
|
||||
$record->tier_weights_snapshot = $tierWeightsSnapshot;
|
||||
$record->lottery_config_id = $lotteryConfigId > 0 ? $lotteryConfigId : null;
|
||||
$record->paid_lottery_config_id = $paidConfigId > 0 ? $paidConfigId : null;
|
||||
$record->free_lottery_config_id = $freeConfigId > 0 ? $freeConfigId : null;
|
||||
$record->total_play_count = $total;
|
||||
$record->over_play_count = 0;
|
||||
$record->status = DiceRewardConfigRecord::STATUS_RUNNING;
|
||||
$record->remark = null;
|
||||
$record->s_count = $paidS + $paidN;
|
||||
$record->n_count = $freeS + $freeN;
|
||||
$record->paid_s_count = $paidS;
|
||||
$record->paid_n_count = $paidN;
|
||||
$record->free_s_count = $freeS;
|
||||
$record->free_n_count = $freeN;
|
||||
$record->paid_tier_weights = $paidTierWeights;
|
||||
$record->free_tier_weights = $freeTierWeights;
|
||||
$record->result_counts = [];
|
||||
$record->tier_counts = null;
|
||||
$record->bigwin_weight = $bigwinWeights ?: null;
|
||||
$record->admin_id = $adminId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
|
||||
return (int) $record->id;
|
||||
}
|
||||
}
|
||||
255
server/app/dice/logic/reward_config_record/WeightTestRunner.php
Normal file
255
server/app/dice/logic/reward_config_record/WeightTestRunner.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\dice\logic\reward_config_record;
|
||||
|
||||
use app\api\logic\PlayStartLogic;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use support\Log;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 一键测试权重:单进程后台执行模拟摇色子,写入 dice_play_record_test 并更新 dice_reward_config_record 进度
|
||||
*/
|
||||
class WeightTestRunner
|
||||
{
|
||||
private const BATCH_SIZE = 10;
|
||||
|
||||
/**
|
||||
* 执行指定测试记录:按付费/免费、顺/逆方向交替模拟(付费顺→付费逆→免费顺→免费逆),每 10 条写入一次测试表并更新进度
|
||||
* 支持:1)lottery_config_id 有值时用奖池配置档位权重;2)无值时用记录中的 paid_tier_weights / free_tier_weights
|
||||
* @param int $recordId dice_reward_config_record.id
|
||||
*/
|
||||
public function run(int $recordId): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if (!$record) {
|
||||
Log::error("WeightTestRunner: 记录不存在 record_id={$recordId}");
|
||||
return;
|
||||
}
|
||||
|
||||
$paidS = (int) ($record->paid_s_count ?? 0);
|
||||
$paidN = (int) ($record->paid_n_count ?? 0);
|
||||
$freeS = (int) ($record->free_s_count ?? 0);
|
||||
$freeN = (int) ($record->free_n_count ?? 0);
|
||||
if ($paidS + $paidN + $freeS + $freeN <= 0) {
|
||||
$sCount = (int) ($record->s_count ?? 0);
|
||||
$nCount = (int) ($record->n_count ?? 0);
|
||||
$total = $sCount + $nCount;
|
||||
if ($total <= 0) {
|
||||
$this->markFailed($recordId, '抽奖次数必须大于 0');
|
||||
return;
|
||||
}
|
||||
$paidS = $sCount;
|
||||
$paidN = $nCount;
|
||||
} else {
|
||||
$total = $paidS + $paidN + $freeS + $freeN;
|
||||
}
|
||||
|
||||
$paidConfigId = (int) ($record->paid_lottery_config_id ?? 0);
|
||||
$freeConfigId = (int) ($record->free_lottery_config_id ?? 0);
|
||||
if ($paidConfigId <= 0) {
|
||||
$paidConfigId = (int) ($record->lottery_config_id ?? 0);
|
||||
}
|
||||
if ($freeConfigId <= 0) {
|
||||
$freeConfigId = (int) ($record->lottery_config_id ?? 0);
|
||||
}
|
||||
$paidConfig = $paidConfigId > 0 ? DiceLotteryPoolConfig::find($paidConfigId) : null;
|
||||
$freeConfig = $freeConfigId > 0 ? DiceLotteryPoolConfig::find($freeConfigId) : null;
|
||||
if ($paidConfigId > 0 && !$paidConfig) {
|
||||
$this->markFailed($recordId, '付费奖池配置不存在');
|
||||
return;
|
||||
}
|
||||
if ($freeConfigId > 0 && !$freeConfig) {
|
||||
$this->markFailed($recordId, '免费奖池配置不存在');
|
||||
return;
|
||||
}
|
||||
$paidTierWeights = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
|
||||
? $record->paid_tier_weights
|
||||
: null;
|
||||
$freeTierWeights = (is_array($record->free_tier_weights ?? null) && $record->free_tier_weights !== [])
|
||||
? $record->free_tier_weights
|
||||
: null;
|
||||
if ($paidConfig === null && $paidTierWeights === null) {
|
||||
$this->markFailed($recordId, '付费未选奖池时需提供 paid_tier_weights');
|
||||
return;
|
||||
}
|
||||
if ($freeConfig === null && $freeTierWeights === null) {
|
||||
$this->markFailed($recordId, '免费未选奖池时需提供 free_tier_weights');
|
||||
return;
|
||||
}
|
||||
|
||||
// 每次测试开始前清空进程内静态缓存,强制从共享缓存读取最新 BIGWIN/奖励配置,与数据库一致
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
DiceReward::clearRequestInstance();
|
||||
|
||||
// 测试时按“单个虚拟玩家”累计中奖金额来判断是否触发杀分:达到 safety_line 前用自定义档位(玩家权重),达到后用奖池权重
|
||||
$paidSafetyLine = $paidConfig !== null ? (int) ($paidConfig->safety_line ?? 0) : 0;
|
||||
$freeSafetyLine = $freeConfig !== null ? (int) ($freeConfig->safety_line ?? 0) : 0;
|
||||
$paidPlayerWinTotal = 0.0;
|
||||
$freePlayerWinTotal = 0.0;
|
||||
|
||||
$playLogic = new PlayStartLogic();
|
||||
$resultCounts = [];
|
||||
$tierCounts = [];
|
||||
$buffer = [];
|
||||
$done = 0;
|
||||
|
||||
try {
|
||||
for ($i = 0; $i < $paidS; $i++) {
|
||||
$usePoolWeights = $paidConfig !== null && $paidPlayerWinTotal >= $paidSafetyLine && $paidSafetyLine > 0;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $customWeights);
|
||||
$this->accumulatePlayerWin($row, $paidPlayerWinTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $paidN; $i++) {
|
||||
$usePoolWeights = $paidConfig !== null && $paidPlayerWinTotal >= $paidSafetyLine && $paidSafetyLine > 0;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $customWeights);
|
||||
$this->accumulatePlayerWin($row, $paidPlayerWinTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $freeS; $i++) {
|
||||
$usePoolWeights = $freeConfig !== null && $freePlayerWinTotal >= $freeSafetyLine && $freeSafetyLine > 0;
|
||||
$customWeights = $usePoolWeights ? null : $freeTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, $customWeights);
|
||||
$this->accumulatePlayerWin($row, $freePlayerWinTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $freeN; $i++) {
|
||||
$usePoolWeights = $freeConfig !== null && $freePlayerWinTotal >= $freeSafetyLine && $freeSafetyLine > 0;
|
||||
$customWeights = $usePoolWeights ? null : $freeTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, $customWeights);
|
||||
$this->accumulatePlayerWin($row, $freePlayerWinTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
if (!empty($buffer)) {
|
||||
$this->insertBuffer($buffer);
|
||||
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
|
||||
}
|
||||
// 平台赚取金额:通过关联 DicePlayRecordTest(reward_config_record_id)统计
|
||||
$this->markSuccess($recordId, $resultCounts, $tierCounts);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
|
||||
$this->markFailed($recordId, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** 累加单个虚拟玩家在测试过程中的中奖金额(win_coin) */
|
||||
private function accumulatePlayerWin(array $row, float &$runningWinTotal): void
|
||||
{
|
||||
if (!isset($row['win_coin'])) {
|
||||
return;
|
||||
}
|
||||
$runningWinTotal += (float) $row['win_coin'];
|
||||
}
|
||||
|
||||
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
|
||||
{
|
||||
$grid = (int) ($row['roll_number_for_count'] ?? $row['roll_number'] ?? 0);
|
||||
if ($grid >= 5 && $grid <= 30) {
|
||||
$resultCounts[$grid] = ($resultCounts[$grid] ?? 0) + 1;
|
||||
}
|
||||
$tier = (string) ($row['tier'] ?? '');
|
||||
if ($tier !== '') {
|
||||
$tierCounts[$tier] = ($tierCounts[$tier] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function rowForInsert(array $row, int $rewardConfigRecordId): array
|
||||
{
|
||||
$out = [
|
||||
'reward_config_record_id' => $rewardConfigRecordId,
|
||||
];
|
||||
$keys = [
|
||||
'player_id', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
'super_win_coin', 'reward_win_coin', 'use_coins', 'direction', 'reward_config_id',
|
||||
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
|
||||
];
|
||||
foreach ($keys as $k) {
|
||||
if (array_key_exists($k, $row)) {
|
||||
$out[$k] = $row[$k];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function flushIfNeeded(array &$buffer, int $recordId, int $done, int $total, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
if (count($buffer) < self::BATCH_SIZE) {
|
||||
return;
|
||||
}
|
||||
$this->insertBuffer($buffer);
|
||||
$buffer = [];
|
||||
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
|
||||
}
|
||||
|
||||
private function insertBuffer(array $rows): void
|
||||
{
|
||||
if (empty($rows)) {
|
||||
return;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
DicePlayRecordTest::create($row);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if ($record) {
|
||||
$record->over_play_count = $overPlayCount;
|
||||
$record->result_counts = $resultCounts;
|
||||
$record->tier_counts = $tierCounts;
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记测试成功并记录平台总盈利 platform_profit
|
||||
* 通过关联 DicePlayRecordTest(reward_config_record_id)统计:付费(lottery_type=0)次数×100 - win_coin 求和
|
||||
*/
|
||||
private function markSuccess(int $recordId, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if ($record) {
|
||||
// 平台盈利通过关联测试记录统计
|
||||
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
|
||||
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空
|
||||
$dbResultCounts = DiceRewardConfigRecord::computeResultCountsFromRelated($recordId);
|
||||
|
||||
$record->status = DiceRewardConfigRecord::STATUS_SUCCESS;
|
||||
$record->result_counts = !empty($dbResultCounts) ? $dbResultCounts : $resultCounts;
|
||||
$record->tier_counts = $tierCounts;
|
||||
$record->remark = null;
|
||||
$record->platform_profit = $platformProfit;
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function markFailed(int $recordId, string $message): void
|
||||
{
|
||||
DiceRewardConfigRecord::where('id', $recordId)->update([
|
||||
'status' => DiceRewardConfigRecord::STATUS_FAIL,
|
||||
'remark' => mb_substr($message, 0, 500),
|
||||
'platform_profit' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
83
server/app/dice/model/config/DiceConfig.php
Normal file
83
server/app/dice/model/config/DiceConfig.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\config;
|
||||
|
||||
use plugin\saiadmin\basic\eloquent\BaseModel;
|
||||
|
||||
/**
|
||||
* 摇色子配置模型
|
||||
*
|
||||
* dice_config 摇色子配置
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $name 配置名称
|
||||
* @property $group 分组
|
||||
* @property $title 标题
|
||||
* @property $title_en 标题(英文)
|
||||
* @property $value 值
|
||||
* @property $value_en 值(英文)
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DiceConfig extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 数据库表名称
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dice_config';
|
||||
|
||||
/**
|
||||
* 是否自动维护 create_time / update_time(继承基类 CREATED_AT / UPDATED_AT)
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* 属性转换
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return array_merge(parent::casts(), [
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* 配置名称 搜索
|
||||
*/
|
||||
public function searchNameAttr($query, $value)
|
||||
{
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组 搜索
|
||||
*/
|
||||
public function searchGroupAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$query->where('group', '=', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标题 搜索
|
||||
*/
|
||||
public function searchTitleAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$query->where('title', 'like', '%' . $value . '%');
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\lottery_config;
|
||||
namespace app\dice\model\lottery_pool_config;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
@@ -20,13 +20,14 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property $safety_line 安全线
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
* @property $t1_wight T1池权重
|
||||
* @property $t2_wight T2池权重
|
||||
* @property $t3_wight T3池权重
|
||||
* @property $t4_wight T4池权重
|
||||
* @property $t5_wight T5池权重
|
||||
* @property $t1_weight T1池权重
|
||||
* @property $t2_weight T2池权重
|
||||
* @property $t3_weight T3池权重
|
||||
* @property $t4_weight T4池权重
|
||||
* @property $t5_weight T5池权重
|
||||
* @property $profit_amount 池子累计盈利(每局抽奖累加 100-real_ev,仅展示不可编辑)
|
||||
*/
|
||||
class DiceLotteryConfig extends BaseModel
|
||||
class DiceLotteryPoolConfig extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
@@ -48,4 +49,13 @@ class DiceLotteryConfig extends BaseModel
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖池类型 搜索(type=0/1/2 等)
|
||||
*/
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('type', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\play_record;
|
||||
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
@@ -19,16 +19,20 @@ use think\model\relation\BelongsTo;
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $player_id 玩家id
|
||||
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||
* @property $lottery_config_id 彩金池配置
|
||||
* @property $lottery_type 抽奖类型
|
||||
* @property $is_win 中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[6,6,6,6,6]为1,否则0
|
||||
* @property $win_coin 赢取平台币(= super_win_coin + reward_win_coin)
|
||||
* @property $super_win_coin 中大奖平台币(豹子时发放)
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $lottery_id 奖池
|
||||
* @property $start_index 起始索引
|
||||
* @property $target_index 结束索引
|
||||
* @property $roll_array 摇取点数,格式:[1,2,3,4,5](5个点数)
|
||||
* @property $roll_number 摇取点数和(5个色子点数之和,5-30)
|
||||
* @property $lottery_name 奖池名
|
||||
* @property $status 状态:0=超时/失败 1=成功
|
||||
* @property $create_time 创建时间
|
||||
@@ -67,12 +71,12 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 彩金配置
|
||||
* 关联模型 diceLotteryConfig
|
||||
* 彩金池配置
|
||||
* 关联模型 diceLotteryPoolConfig
|
||||
*/
|
||||
public function diceLotteryConfig(): BelongsTo
|
||||
public function diceLotteryPoolConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
|
||||
/** 按玩家用户名模糊(dicePlayer.username) */
|
||||
@@ -89,13 +93,13 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 按彩金池配置名称模糊(diceLotteryConfig.name) */
|
||||
/** 按彩金池配置名称模糊(diceLotteryPoolConfig.name) */
|
||||
public function searchLotteryConfigNameAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceLotteryConfig::where('name', 'like', '%' . $value . '%')->column('id');
|
||||
$ids = DiceLotteryPoolConfig::where('name', 'like', '%' . $value . '%')->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('lottery_config_id', $ids);
|
||||
} else {
|
||||
@@ -103,6 +107,58 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 roll_array 时:若为空且 roll_number 在 5~30,则按点数和生成默认 5 个色子数组,避免“点数和有值但五个点数空”的展示问题
|
||||
* @param mixed $value 库中原始值(JSON 字符串或 null)
|
||||
* @param array $data 当前记录数据
|
||||
* @return array 5 个元素的数组,每项 1~6
|
||||
*/
|
||||
public function getRollArrayAttr($value, $data = []): array
|
||||
{
|
||||
$arr = [];
|
||||
if (is_string($value) && $value !== '') {
|
||||
$decoded = json_decode($value, true);
|
||||
$arr = is_array($decoded) ? $decoded : [];
|
||||
} elseif (is_array($value)) {
|
||||
$arr = $value;
|
||||
}
|
||||
$sum = isset($data['roll_number']) ? (int) $data['roll_number'] : 0;
|
||||
if (count($arr) === 5 && array_sum($arr) === $sum) {
|
||||
$valid = true;
|
||||
foreach ($arr as $v) {
|
||||
if (!is_numeric($v) || (int) $v < 1 || (int) $v > 6) {
|
||||
$valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($valid) {
|
||||
return array_map('intval', array_slice($arr, 0, 5));
|
||||
}
|
||||
}
|
||||
if ($sum >= 5 && $sum <= 30) {
|
||||
return self::defaultRollArrayForSum($sum);
|
||||
}
|
||||
return array_slice(array_map('intval', $arr), 0, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据点数和生成默认 5 个色子数组(每项 1~6),用于补全缺失的 roll_array
|
||||
*/
|
||||
public static function defaultRollArrayForSum(int $sum): array
|
||||
{
|
||||
$sum = max(5, min(30, $sum));
|
||||
$base = (int) floor($sum / 5);
|
||||
$rem = $sum - 5 * $base;
|
||||
$arr = array_fill(0, 5, $base);
|
||||
for ($i = 0; $i < $rem; $i++) {
|
||||
$arr[$i]++;
|
||||
}
|
||||
$arr = array_map(function ($v) {
|
||||
return max(1, min(6, (int) $v));
|
||||
}, $arr);
|
||||
return array_values($arr);
|
||||
}
|
||||
|
||||
/** 抽奖类型 */
|
||||
public function searchLotteryTypeAttr($query, $value)
|
||||
{
|
||||
@@ -111,7 +167,25 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖 */
|
||||
/**
|
||||
* 是否豹子号(中大奖):5 个点数相同且为 1~6 之一(含 [6,6,6,6,6])
|
||||
* @param int[] $rollArray 摇取点数数组,如 [1,1,1,1,1] 或 [6,6,6,6,6]
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSuperWin(array $rollArray): bool
|
||||
{
|
||||
if (count($rollArray) !== 5) {
|
||||
return false;
|
||||
}
|
||||
$unique = array_unique($rollArray);
|
||||
if (count($unique) !== 1) {
|
||||
return false;
|
||||
}
|
||||
$value = reset($unique);
|
||||
return in_array($value, [1, 2, 3, 4, 5, 6], true);
|
||||
}
|
||||
|
||||
/** 是否中大奖 */
|
||||
public function searchIsWinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -135,6 +209,38 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币下限 */
|
||||
public function searchSuperWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币上限 */
|
||||
public function searchSuperWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币下限 */
|
||||
public function searchRewardWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币上限 */
|
||||
public function searchRewardWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 按奖励配置前端显示文本模糊(diceRewardConfig.ui_text) */
|
||||
public function searchRewardUiTextAttr($query, $value)
|
||||
{
|
||||
@@ -170,4 +276,20 @@ class DicePlayRecord extends BaseModel
|
||||
$query->where('direction', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇取点数和下限 */
|
||||
public function searchRollNumberMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('roll_number', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇取点数和上限 */
|
||||
public function searchRollNumberMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('roll_number', '<=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
141
server/app/dice/model/play_record_test/DicePlayRecordTest.php
Normal file
141
server/app/dice/model/play_record_test/DicePlayRecordTest.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)模型
|
||||
*
|
||||
* dice_play_record_test 玩家抽奖记录(测试数据)
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $lottery_config_id 彩金池配置id
|
||||
* @property $lottery_type 抽奖类型:0=付费,1=赠送
|
||||
* @property $is_win 中大奖:0=无,1=中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
* @property $start_index 起始索引
|
||||
* @property $target_index 结束索引
|
||||
* @property $roll_number 摇取点数和
|
||||
* @property $roll_array 摇取点数:[1,2,3,4,5,6]
|
||||
* @property $status 状态:0=失败,1=成功
|
||||
* @property $super_win_coin 中大奖平台币
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $admin_id 所属管理员
|
||||
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id(权重测试记录)
|
||||
*/
|
||||
class DicePlayRecordTest extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 数据库表名称
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dice_play_record_test';
|
||||
|
||||
/**
|
||||
* 彩金池配置
|
||||
* 关联 lottery_config_id -> DiceLotteryPoolConfig.id
|
||||
*/
|
||||
public function diceLotteryPoolConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖励配置(终点格 = target_index 对应 DiceRewardConfig.id,表中为 reward_config_id)
|
||||
* 关联 reward_config_id -> DiceRewardConfig.id
|
||||
*/
|
||||
public function diceRewardConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的权重测试记录
|
||||
* reward_config_record_id -> DiceRewardConfigRecord.id
|
||||
*/
|
||||
public function diceRewardConfigRecord(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfigRecord::class, 'reward_config_record_id', 'id');
|
||||
}
|
||||
|
||||
/** 抽奖类型 0=付费 1=赠送 */
|
||||
public function searchLotteryTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('lottery_type', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 方向 0=顺时针 1=逆时针 */
|
||||
public function searchDirectionAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('direction', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否中大奖 0=无 1=中大奖 */
|
||||
public function searchIsWinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_win', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 赢取平台币下限 */
|
||||
public function searchWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 赢取平台币上限 */
|
||||
public function searchWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖档位(按 reward_config_id 对应 DiceRewardConfig.tier) */
|
||||
public function searchRewardTierAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('reward_config_id', $ids);
|
||||
} else {
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
}
|
||||
|
||||
/** 点数和 roll_number(摇取点数和 5-30) */
|
||||
public function searchRollNumberAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('roll_number', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家模型
|
||||
@@ -22,18 +22,19 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
* @property $password 密码
|
||||
* @property $status 状态
|
||||
* @property $coin 平台币
|
||||
* @property $is_up 倍率
|
||||
* @property $t1_wight T1池权重
|
||||
* @property $t2_wight T2池权重
|
||||
* @property $t3_wight T3池权重
|
||||
* @property $t4_wight T4池权重
|
||||
* @property $t5_wight T5池权重
|
||||
* @property $admin_id 创建该玩家的后台管理员ID,关联 sa_system_user.id
|
||||
* @property $lottery_config_id 彩金池配置ID(0或null时使用自定义权重*_weight)
|
||||
* @property $t1_weight T1池权重
|
||||
* @property $t2_weight T2池权重
|
||||
* @property $t3_weight T3池权重
|
||||
* @property $t4_weight T4池权重
|
||||
* @property $t5_weight T5池权重
|
||||
* @property $total_ticket_count 总抽奖次数
|
||||
* @property $paid_ticket_count 购买抽奖次数
|
||||
* @property $free_ticket_count 赠送抽奖次数
|
||||
* @property $created_at 创建时间
|
||||
* @property $updated_at 更新时间
|
||||
* @property $deleted_at 删除时间
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 更新时间
|
||||
* @property $delete_time 删除时间
|
||||
*/
|
||||
class DicePlayer extends BaseModel
|
||||
{
|
||||
@@ -49,6 +50,10 @@ class DicePlayer extends BaseModel
|
||||
*/
|
||||
protected $table = 'dice_player';
|
||||
|
||||
protected $createTime = 'create_time';
|
||||
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
/**
|
||||
* 新增前:生成唯一 uid,昵称 name 默认使用 uid
|
||||
* 用 try-catch 避免表尚未含 uid 时 getAttr/getData 抛 InvalidArgumentException
|
||||
@@ -73,20 +78,30 @@ class DicePlayer extends BaseModel
|
||||
if ($name === null || $name === '') {
|
||||
$model->setAttr('name', $uid);
|
||||
}
|
||||
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig type=0 的 id,没有则为 0
|
||||
try {
|
||||
$lotteryConfigId = $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = null;
|
||||
}
|
||||
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
|
||||
}
|
||||
// 彩金池权重默认取 type=0 的奖池配置
|
||||
self::setDefaultWeightsFromLotteryConfig($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 DiceLotteryConfig type=0 取 t1_wight~t5_wight 作为玩家未设置时的默认值
|
||||
* 从 DiceLotteryPoolConfig type=0 取 t1_weight~t5_weight 作为玩家未设置时的默认值
|
||||
*/
|
||||
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
|
||||
{
|
||||
$config = DiceLotteryConfig::where('type', 0)->find();
|
||||
$config = DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
if (!$config) {
|
||||
return;
|
||||
}
|
||||
$fields = ['t1_wight', 't2_wight', 't3_wight', 't4_wight', 't5_wight'];
|
||||
$fields = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'];
|
||||
foreach ($fields as $field) {
|
||||
try {
|
||||
$val = $model->getAttr($field);
|
||||
@@ -158,13 +173,20 @@ class DicePlayer extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 倍率 搜索
|
||||
* 彩金池配置ID 搜索
|
||||
*/
|
||||
public function searchIs_upAttr($query, $value)
|
||||
public function searchLottery_config_idAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_up', '=', $value);
|
||||
$query->where('lottery_config_id', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联彩金池配置
|
||||
*/
|
||||
public function diceLotteryPoolConfig()
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use think\model\relation\BelongsTo;
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $player_id 玩家id
|
||||
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||
* @property $use_coins 消耗硬币
|
||||
* @property $total_ticket_count 总抽奖次数
|
||||
* @property $paid_ticket_count 购买抽奖次数
|
||||
|
||||
@@ -18,6 +18,7 @@ use think\model\relation\BelongsTo;
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $player_id 用户id
|
||||
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||
* @property $coin 平台币变化
|
||||
* @property $type 类型:0=充值 1=提现 2=购买抽奖次数
|
||||
* @property $wallet_before 钱包操作前
|
||||
|
||||
140
server/app/dice/model/reward/DiceReward.php
Normal file
140
server/app/dice/model/reward/DiceReward.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 奖励对照模型
|
||||
*
|
||||
* dice_reward 奖励对照表(主键 id 自增)
|
||||
* 唯一约束 (direction, grid_number),保证每个点数、每个方向各一条;end_index 关联 DiceRewardConfig.id
|
||||
*
|
||||
* @property $id 主键
|
||||
* @property $tier 档位 T1-T5/BIGWIN
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $end_index 结束索引(DiceRewardConfig.id)
|
||||
* @property $weight 权重 1-10000,档位内按权重比抽取
|
||||
* @property $grid_number 色子点数(摇取值)
|
||||
* @property $start_index 起始索引(DiceRewardConfig.id)
|
||||
* @property $ui_text 显示文本(来自config)
|
||||
* @property $real_ev 实际中奖金额(来自config)
|
||||
* @property $remark 备注(来自config)
|
||||
* @property $type 奖励类型(来自config)
|
||||
*/
|
||||
class DiceReward extends BaseModel
|
||||
{
|
||||
/** 方向:顺时针 */
|
||||
public const DIRECTION_CLOCKWISE = 0;
|
||||
/** 方向:逆时针 */
|
||||
public const DIRECTION_COUNTERCLOCKWISE = 1;
|
||||
|
||||
/** 缓存键:奖励对照实例 */
|
||||
private const CACHE_KEY_INSTANCE = 'dice:reward:instance';
|
||||
|
||||
private const CACHE_TTL = 86400 * 30;
|
||||
|
||||
private static ?array $instance = null;
|
||||
|
||||
protected $table = 'dice_reward';
|
||||
|
||||
/** 主键 id 自增,唯一约束 (direction, grid_number) */
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比)
|
||||
* 优先从共享缓存读取,保证多进程(如一键测试 worker)与数据库一致
|
||||
* @return array{list: array, by_tier_direction: array}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
if ($instance !== null && is_array($instance)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位+方向取权重列表(用于抽奖:该档位该方向下 end_index => weight)
|
||||
* @return array<int, int> end_index => weight
|
||||
*/
|
||||
public static function getCachedByTierAndDirection(string $tier, int $direction): array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
$byTierDirection = $inst['by_tier_direction'] ?? [];
|
||||
$list = $byTierDirection[$tier][$direction] ?? [];
|
||||
$result = [];
|
||||
foreach ($list as $row) {
|
||||
$endIndex = isset($row['end_index']) ? (int) $row['end_index'] : 0;
|
||||
$weight = isset($row['weight']) ? (int) $row['weight'] : 1;
|
||||
$result[$endIndex] = $weight;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新从数据库加载并写入缓存;修改/新增/删除后需调用以实例化
|
||||
*/
|
||||
public static function refreshCache(): void
|
||||
{
|
||||
$list = (new self())->order('tier')->order('direction')->order('end_index')->select()->toArray();
|
||||
$byTierDirection = [];
|
||||
foreach ($list as $row) {
|
||||
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
|
||||
$direction = isset($row['direction']) ? (int) $row['direction'] : 0;
|
||||
if ($tier !== '') {
|
||||
if (!isset($byTierDirection[$tier])) {
|
||||
$byTierDirection[$tier] = [0 => [], 1 => []];
|
||||
}
|
||||
if (!isset($byTierDirection[$tier][$direction])) {
|
||||
$byTierDirection[$tier][$direction] = [];
|
||||
}
|
||||
$byTierDirection[$tier][$direction][] = $row;
|
||||
}
|
||||
}
|
||||
self::$instance = [
|
||||
'list' => $list,
|
||||
'by_tier_direction' => $byTierDirection,
|
||||
];
|
||||
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
|
||||
}
|
||||
|
||||
private static function buildEmptyInstance(): array
|
||||
{
|
||||
return [
|
||||
'list' => [],
|
||||
'by_tier_direction' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function clearRequestInstance(): void
|
||||
{
|
||||
self::$instance = null;
|
||||
}
|
||||
|
||||
public static function onAfterInsert($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
|
||||
public static function onAfterDelete($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
}
|
||||
9
server/app/dice/model/reward/DiceRewardConfig.php
Normal file
9
server/app/dice/model/reward/DiceRewardConfig.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 别名:reward 命名空间下引用 reward_config\DiceRewardConfig
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward;
|
||||
|
||||
class DiceRewardConfig extends \app\dice\model\reward_config\DiceRewardConfig
|
||||
{
|
||||
}
|
||||
@@ -6,37 +6,186 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward_config;
|
||||
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
* 奖励配置模型
|
||||
*
|
||||
* dice_reward_config 奖励配置
|
||||
* dice_reward_config 奖励配置;BIGWIN 档位使用本表 weight(0-10000,10000=100% 中大奖)
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $grid_number 色子点数
|
||||
* @property $ui_text 前端显示文本
|
||||
* @property $ui_text_en 前端显示文本(英文)
|
||||
* @property $real_ev 真实资金结算
|
||||
* @property $tier 所属档位
|
||||
* @property $weight 权重(仅 BIGWIN 使用,0-10000)
|
||||
* @property $remark 备注
|
||||
* @property $type 奖励类型 -2=唯一惩罚,-1=抽水,0=回本,1=再来一次,2=小赚,3=大奖格
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DiceRewardConfig extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
/** 缓存键:彩金池奖励列表实例 */
|
||||
private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance';
|
||||
|
||||
private const CACHE_TTL = 86400 * 30;
|
||||
|
||||
private static ?array $instance = null;
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 数据库表名称
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dice_reward_config';
|
||||
|
||||
/** 色子点数下限 */
|
||||
/**
|
||||
* 获取彩金池实例(含 list / by_tier / by_tier_grid),无则从库加载并写入缓存
|
||||
* 优先从共享缓存读取,保证多进程(如一键测试 worker)能拿到最新配置,与数据库一致
|
||||
* @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
if ($instance !== null && is_array($instance)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function getCachedList(): array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
return $inst['list'] ?? [];
|
||||
}
|
||||
|
||||
public static function getCachedById(int $id): ?array
|
||||
{
|
||||
$list = self::getCachedList();
|
||||
foreach ($list as $row) {
|
||||
if (isset($row['id']) && (int) $row['id'] === $id) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新从数据库加载并写入缓存(按档位+权重抽 grid_number,含 by_tier、by_tier_grid)
|
||||
*/
|
||||
public static function refreshCache(): void
|
||||
{
|
||||
$list = (new self())->order('id', 'asc')->select()->toArray();
|
||||
$byTier = [];
|
||||
$byTierGrid = [];
|
||||
foreach ($list as $row) {
|
||||
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
|
||||
if ($tier !== '') {
|
||||
if (!isset($byTier[$tier])) {
|
||||
$byTier[$tier] = [];
|
||||
}
|
||||
$byTier[$tier][] = $row;
|
||||
$gridNum = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
if (!isset($byTierGrid[$tier])) {
|
||||
$byTierGrid[$tier] = [];
|
||||
}
|
||||
if (!isset($byTierGrid[$tier][$gridNum])) {
|
||||
$byTierGrid[$tier][$gridNum] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
$minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev'));
|
||||
self::$instance = [
|
||||
'list' => $list,
|
||||
'by_tier' => $byTier,
|
||||
'by_tier_grid' => $byTierGrid,
|
||||
'min_real_ev' => $minRealEv,
|
||||
];
|
||||
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
|
||||
}
|
||||
|
||||
private static function buildEmptyInstance(): array
|
||||
{
|
||||
return [
|
||||
'list' => [],
|
||||
'by_tier' => [],
|
||||
'by_tier_grid' => [],
|
||||
'min_real_ev' => 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位+色子点数取一条(用于 BIGWIN)
|
||||
*/
|
||||
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
$byTierGrid = $inst['by_tier_grid'] ?? [];
|
||||
$tierData = $byTierGrid[$tier] ?? [];
|
||||
$row = $tierData[$gridNumber] ?? null;
|
||||
return is_array($row) ? $row : null;
|
||||
}
|
||||
|
||||
public static function getCachedMinRealEv(): float
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
return (float) ($inst['min_real_ev'] ?? 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存按档位取奖励列表(不含权重,仅配置)
|
||||
*/
|
||||
public static function getCachedByTier(string $tier): array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
$byTier = $inst['by_tier'] ?? [];
|
||||
return $byTier[$tier] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按档位+方向取奖励列表(合并 dice_reward 权重,用于抽奖)
|
||||
* @param int $direction 0=顺时针, 1=逆时针
|
||||
* @return array 每行含 id, grid_number, real_ev, tier, weight 等
|
||||
*/
|
||||
public static function getCachedByTierForDirection(string $tier, int $direction): array
|
||||
{
|
||||
$list = self::getCachedByTier($tier);
|
||||
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction);
|
||||
foreach ($list as $i => $row) {
|
||||
$id = isset($row['id']) ? (int) $row['id'] : 0;
|
||||
$list[$i]['weight'] = $weightMap[$id] ?? 1;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function clearRequestInstance(): void
|
||||
{
|
||||
self::$instance = null;
|
||||
}
|
||||
|
||||
public static function onAfterInsert($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
|
||||
public static function onAfterDelete($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
}
|
||||
|
||||
public function searchGridNumberMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -44,7 +193,6 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 色子点数上限 */
|
||||
public function searchGridNumberMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -52,7 +200,6 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 前端显示文本模糊 */
|
||||
public function searchUiTextAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -60,7 +207,6 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 真实资金结算下限 */
|
||||
public function searchRealEvMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -68,7 +214,6 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 真实资金结算上限 */
|
||||
public function searchRealEvMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -76,7 +221,6 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 所属档位 */
|
||||
public function searchTierAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward_config;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
/**
|
||||
* 权重配比测试记录模型
|
||||
*
|
||||
* dice_reward_config_record 保存测试时的权重快照与落点统计
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $test_count 测试次数 100/500/1000/5000/10000
|
||||
* @property array $weight_config_snapshot 测试时权重配比快照
|
||||
* @property array $tier_weights_snapshot 测试时 T1-T5 档位权重快照(来自奖池配置)
|
||||
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID
|
||||
* @property array $result_counts 落点统计 grid_number=>出现次数
|
||||
* @property int|null $admin_id 执行测试的管理员ID
|
||||
* @property string|null $create_time 创建时间
|
||||
*/
|
||||
class DiceRewardConfigRecord extends BaseModel
|
||||
{
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $table = 'dice_reward_config_record';
|
||||
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts'];
|
||||
|
||||
protected $jsonAssoc = true;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward_config_record;
|
||||
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use think\model\relation\HasMany;
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录模型
|
||||
*
|
||||
* dice_reward_config_record 奖励配置权重测试记录
|
||||
*
|
||||
* @property int $id 主键
|
||||
* @property int $test_count 测试次数 100/500/1000/5000/10000
|
||||
* @property array $weight_config_snapshot 测试时权重配比快照:按档位 id,grid_number,tier,weight
|
||||
* @property array $tier_weights_snapshot 测试时 T1-T5 档位权重快照(来自奖池配置)
|
||||
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID(兼容旧:付费+免费共用)
|
||||
* @property int|null $paid_lottery_config_id 付费抽奖奖池配置 ID,默认 type=0
|
||||
* @property int|null $free_lottery_config_id 免费抽奖奖池配置 ID,默认 type=1
|
||||
* @property int $total_play_count 总模拟次数(s_count+n_count)
|
||||
* @property int $over_play_count 已完成次数
|
||||
* @property int $status 状态 -1失败 0进行中 1成功
|
||||
* @property string|null $remark 失败时记录原因
|
||||
* @property int $s_count 顺时针模拟次数(兼容旧数据)
|
||||
* @property int $n_count 逆时针模拟次数(兼容旧数据)
|
||||
* @property int $paid_s_count 付费抽奖顺时针次数
|
||||
* @property int $paid_n_count 付费抽奖逆时针次数
|
||||
* @property int $free_s_count 免费抽奖顺时针次数
|
||||
* @property int $free_n_count 免费抽奖逆时针次数
|
||||
* @property array|null $paid_tier_weights 付费自定义档位权重 T1-T5
|
||||
* @property array|null $free_tier_weights 免费自定义档位权重 T1-T5
|
||||
* @property array $result_counts 落点统计 grid_number=>出现次数
|
||||
* @property array|null $tier_counts 档位出现次数 T1=>count
|
||||
* @property float|null $platform_profit 平台赚取金额(付费抽取次数×100-玩家总收益)
|
||||
* @property array|null $bigwin_weight 测试时 BIGWIN 档位权重快照(JSON:grid_number=>weight)
|
||||
* @property int|null $admin_id 执行测试的管理员ID
|
||||
* @property string|null $create_time 创建时间
|
||||
*/
|
||||
class DiceRewardConfigRecord extends BaseModel
|
||||
{
|
||||
/** 状态:失败 */
|
||||
public const STATUS_FAIL = -1;
|
||||
/** 状态:待执行(队列中) */
|
||||
public const STATUS_RUNNING = 0;
|
||||
/** 状态:执行中(已被某进程领取,防止定时器重入重复执行) */
|
||||
public const STATUS_EXECUTING = 2;
|
||||
/** 状态:成功 */
|
||||
public const STATUS_SUCCESS = 1;
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $table = 'dice_reward_config_record';
|
||||
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts', 'tier_counts', 'paid_tier_weights', 'free_tier_weights', 'bigwin_weight'];
|
||||
|
||||
protected $jsonAssoc = true;
|
||||
|
||||
/**
|
||||
* 关联的测试抽奖记录(通过 reward_config_record_id)
|
||||
*/
|
||||
public function playRecordTests(): HasMany
|
||||
{
|
||||
return $this->hasMany(DicePlayRecordTest::class, 'reward_config_record_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联的 DicePlayRecordTest 统计平台赚取平台币
|
||||
* platform_profit = 关联的付费(lottery_type=0)抽取次数 × 100 - 关联的 win_coin 求和
|
||||
* @param int $recordId dice_reward_config_record.id
|
||||
* @return float
|
||||
*/
|
||||
public static function computePlatformProfitFromRelated(int $recordId): float
|
||||
{
|
||||
$paidCount = DicePlayRecordTest::where('reward_config_record_id', $recordId)
|
||||
->where('lottery_type', 0)
|
||||
->count();
|
||||
$sumWinCoin = (float) DicePlayRecordTest::where('reward_config_record_id', $recordId)
|
||||
->sum('win_coin');
|
||||
return round($paidCount * 100 - $sumWinCoin, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联的 DicePlayRecordTest 统计落点次数
|
||||
* result_counts = [grid_number => 出现次数],只统计 roll_number 在 5-30 之间的记录
|
||||
* @param int $recordId
|
||||
* @return array<int,int>
|
||||
*/
|
||||
public static function computeResultCountsFromRelated(int $recordId): array
|
||||
{
|
||||
$rows = DicePlayRecordTest::where('reward_config_record_id', $recordId)
|
||||
->where('roll_number', '>=', 5)
|
||||
->where('roll_number', '<=', 30)
|
||||
->field('roll_number, COUNT(*) AS c')
|
||||
->group('roll_number')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$result = [];
|
||||
foreach ($rows as $row) {
|
||||
$grid = (int) ($row['roll_number'] ?? 0);
|
||||
$cnt = (int) ($row['c'] ?? 0);
|
||||
if ($grid > 0 && $cnt > 0) {
|
||||
$result[$grid] = $cnt;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
58
server/app/dice/validate/config/DiceConfigValidate.php
Normal file
58
server/app/dice/validate/config/DiceConfigValidate.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\config;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 摇色子配置验证器
|
||||
*/
|
||||
class DiceConfigValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'name' => 'require',
|
||||
'group' => 'require',
|
||||
'title' => 'require',
|
||||
'value' => 'require',
|
||||
'title_en' => 'max:100',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'name' => '配置名称必须填写',
|
||||
'group' => '分组必须填写',
|
||||
'title' => '标题必须填写',
|
||||
'value' => '值必须填写',
|
||||
'title_en' => '英文标题长度需小于 100 字符',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'name',
|
||||
'group',
|
||||
'title',
|
||||
'value',
|
||||
'title_en',
|
||||
],
|
||||
'update' => [
|
||||
'name',
|
||||
'group',
|
||||
'title',
|
||||
'value',
|
||||
'title_en',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
@@ -4,14 +4,14 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\lottery_config;
|
||||
namespace app\dice\validate\lottery_pool_config;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 色子奖池配置验证器
|
||||
*/
|
||||
class DiceLotteryConfigValidate extends BaseValidate
|
||||
class DiceLotteryPoolConfigValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
@@ -19,11 +19,11 @@ class DiceLotteryConfigValidate extends BaseValidate
|
||||
protected $rule = [
|
||||
'name' => 'require',
|
||||
'type' => 'require',
|
||||
't1_wight' => 'require',
|
||||
't2_wight' => 'require',
|
||||
't3_wight' => 'require',
|
||||
't4_wight' => 'require',
|
||||
't5_wight' => 'require',
|
||||
't1_weight' => 'require',
|
||||
't2_weight' => 'require',
|
||||
't3_weight' => 'require',
|
||||
't4_weight' => 'require',
|
||||
't5_weight' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -32,11 +32,11 @@ class DiceLotteryConfigValidate extends BaseValidate
|
||||
protected $message = [
|
||||
'name' => '名称必须填写',
|
||||
'type' => '奖池类型必须填写',
|
||||
't1_wight' => 'T1池权重必须填写',
|
||||
't2_wight' => 'T2池权重必须填写',
|
||||
't3_wight' => 'T3池权重必须填写',
|
||||
't4_wight' => 'T4池权重必须填写',
|
||||
't5_wight' => 'T5池权重必须填写',
|
||||
't1_weight' => 'T1池权重必须填写',
|
||||
't2_weight' => 'T2池权重必须填写',
|
||||
't3_weight' => 'T3池权重必须填写',
|
||||
't4_weight' => 'T4池权重必须填写',
|
||||
't5_weight' => 'T5池权重必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -46,20 +46,20 @@ class DiceLotteryConfigValidate extends BaseValidate
|
||||
'save' => [
|
||||
'name',
|
||||
'type',
|
||||
't1_wight',
|
||||
't2_wight',
|
||||
't3_wight',
|
||||
't4_wight',
|
||||
't5_wight',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
't4_weight',
|
||||
't5_weight',
|
||||
],
|
||||
'update' => [
|
||||
'name',
|
||||
'type',
|
||||
't1_wight',
|
||||
't2_wight',
|
||||
't3_wight',
|
||||
't4_wight',
|
||||
't5_wight',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
't4_weight',
|
||||
't5_weight',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)验证器
|
||||
*/
|
||||
class DicePlayRecordTestValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'lottery_config_id' => 'require',
|
||||
'lottery_type' => 'require',
|
||||
'is_win' => 'require',
|
||||
'direction' => 'require',
|
||||
'reward_config_id' => 'require',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'lottery_config_id' => '彩金池配置id必须填写',
|
||||
'lottery_type' => '抽奖类型:0=付费,1=赠送必须填写',
|
||||
'is_win' => '中大奖:0=无,1=中奖必须填写',
|
||||
'direction' => '方向:0=顺时针,1=逆时针必须填写',
|
||||
'reward_config_id' => '奖励配置id必须填写',
|
||||
'status' => '状态:0=失败,1=成功必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'status',
|
||||
],
|
||||
'update' => [
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'status',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
@@ -9,46 +9,36 @@ namespace app\dice\validate\reward_config;
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 奖励配置验证器
|
||||
* 奖励配置验证器(DiceRewardConfig;BIGWIN 的 weight 存本表,0-10000)
|
||||
*/
|
||||
class DiceRewardConfigValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'grid_number' => 'require',
|
||||
'ui_text' => 'require',
|
||||
'real_ev' => 'require',
|
||||
'tier' => 'require',
|
||||
/** 色子点数范围:5~30 共 26 个点数 */
|
||||
public const GRID_NUMBER_MIN = 5;
|
||||
public const GRID_NUMBER_MAX = 30;
|
||||
|
||||
protected $rule = [
|
||||
'grid_number' => 'require|integer|between:5,30',
|
||||
'ui_text' => 'require',
|
||||
'ui_text_en' => 'max:255',
|
||||
'real_ev' => 'require',
|
||||
'tier' => 'require',
|
||||
'type' => 'number',
|
||||
'weight' => 'number|between:0,10000', // BIGWIN 大奖权重,仅档位为 BIGWIN 时使用
|
||||
'remark' => 'max:500',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'grid_number' => '色子点数必须填写',
|
||||
'ui_text' => '前端显示文本必须填写',
|
||||
'real_ev' => '真实资金结算必须填写',
|
||||
'tier' => '所属档位必须填写',
|
||||
protected $message = [
|
||||
'grid_number' => '色子点数必须为 5~30 之间的整数(共26个点数)',
|
||||
'ui_text' => '前端显示文本必须填写',
|
||||
'real_ev' => '真实资金结算必须填写',
|
||||
'tier' => '所属档位必须填写',
|
||||
'type' => '奖励类型须为数字',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'grid_number',
|
||||
'ui_text',
|
||||
'real_ev',
|
||||
'tier',
|
||||
],
|
||||
'update' => [
|
||||
'grid_number',
|
||||
'ui_text',
|
||||
'real_ev',
|
||||
'tier',
|
||||
],
|
||||
'save' => ['grid_number', 'ui_text', 'ui_text_en', 'real_ev', 'tier', 'type'],
|
||||
'update' => ['grid_number', 'ui_text', 'ui_text_en', 'real_ev', 'tier', 'type', 'weight', 'remark'],
|
||||
'batch_update' => ['grid_number', 'ui_text', 'ui_text_en', 'real_ev', 'tier', 'remark'],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\reward_config_record;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 奖励配置权重测试记录验证器
|
||||
*/
|
||||
class DiceRewardConfigRecordValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'test_count' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'test_count' => '测试次数:100/500/1000必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'test_count',
|
||||
],
|
||||
'update' => [
|
||||
'test_count',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
51
server/app/process/WeightTestProcess.php
Normal file
51
server/app/process/WeightTestProcess.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\process;
|
||||
|
||||
use app\dice\logic\reward_config_record\WeightTestRunner;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use Workerman\Timer;
|
||||
use Workerman\Worker;
|
||||
|
||||
/**
|
||||
* 一键测试权重定时任务进程:每隔一定时间检查 status=0 的测试记录并执行一条,不占用 HTTP worker 资源
|
||||
*/
|
||||
class WeightTestProcess
|
||||
{
|
||||
/** 轮询间隔(秒) */
|
||||
private const INTERVAL = 15;
|
||||
|
||||
public function onWorkerStart(Worker $worker): void
|
||||
{
|
||||
Timer::add(self::INTERVAL, function () {
|
||||
$this->runOnePending();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行一条待完成的测试记录(status=0)
|
||||
* 先原子更新为 STATUS_EXECUTING,避免定时器 15 秒重入时同一条记录被重复执行(导致顺/逆时针各跑两倍次数)
|
||||
*/
|
||||
private function runOnePending(): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::where('status', DiceRewardConfigRecord::STATUS_RUNNING)
|
||||
->order('id')
|
||||
->find();
|
||||
if (!$record) {
|
||||
return;
|
||||
}
|
||||
$recordId = (int) $record->id;
|
||||
$affected = DiceRewardConfigRecord::where('id', $recordId)
|
||||
->where('status', DiceRewardConfigRecord::STATUS_RUNNING)
|
||||
->update(['status' => DiceRewardConfigRecord::STATUS_EXECUTING]);
|
||||
if ($affected !== 1) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
(new WeightTestRunner())->run($recordId);
|
||||
} catch (\Throwable $e) {
|
||||
// WeightTestRunner 内部会更新 status=-1 和 remark
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,14 @@
|
||||
* API 鉴权与用户相关配置
|
||||
*/
|
||||
return [
|
||||
// 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777
|
||||
'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'),
|
||||
// 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token
|
||||
'game_url' => env('GAME_URL', 'dice-game.yuliao666.top'),
|
||||
// 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验
|
||||
'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'),
|
||||
// 登录会话过期时间(秒),默认 7 天
|
||||
'session_expire' => (int) env('API_SESSION_EXPIRE', 604800),
|
||||
// auth-token 签名密钥(与客户端约定,用于 /api/authToken 的 signature 校验,必填)
|
||||
'auth_token_secret' => env('API_AUTH_TOKEN_SECRET', ''),
|
||||
// auth-token 时间戳允许误差(秒),防重放,默认 300 秒
|
||||
@@ -11,6 +19,8 @@ return [
|
||||
'auth_token_exp' => (int) env('API_AUTH_TOKEN_EXP', 86400),
|
||||
// auth-token 按设备存储的 Redis key 前缀(同一设备只保留最新一个 auth-token)
|
||||
'auth_token_device_prefix' => env('API_AUTH_TOKEN_DEVICE_PREFIX', 'api:auth_token:'),
|
||||
// auth-token 按 token 存储的 Redis key 前缀(用于校验 auth-token 请求头)
|
||||
'auth_token_prefix' => env('API_AUTH_TOKEN_PREFIX', 'api:auth_token:t:'),
|
||||
// user-token 有效期(秒),默认 7 天
|
||||
'user_token_exp' => (int) env('API_USER_TOKEN_EXP', 604800),
|
||||
// 按用户存储当前有效 user-token 的 Redis key 前缀(同一用户仅保留最新一次登录的 token)
|
||||
@@ -21,4 +31,7 @@ return [
|
||||
'user_cache_prefix' => env('API_USER_CACHE_PREFIX', 'api:user:'),
|
||||
// 用户信息加密密钥(用于 Redis 中 value 的加密),建议 32 位
|
||||
'user_encrypt_key' => env('API_USER_ENCRYPT_KEY', 'dafuweng_api_user_cache_key_32'),
|
||||
// 玩家信息按 username 缓存(Token 中间件用),0 表示不缓存
|
||||
'player_cache_ttl' => (int) env('API_PLAYER_CACHE_TTL', 300),
|
||||
'player_cache_prefix' => env('API_PLAYER_CACHE_PREFIX', 'api:player:'),
|
||||
];
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
use support\Request;
|
||||
|
||||
return [
|
||||
'debug' => true,
|
||||
// 生产环境务必设为 false,减少 I/O 与堆栈输出,提升接口响应
|
||||
'debug' => env('APP_DEBUG', false),
|
||||
'error_reporting' => E_ALL,
|
||||
'default_timezone' => 'Asia/Shanghai',
|
||||
'request_class' => Request::class,
|
||||
|
||||
@@ -18,10 +18,10 @@ return [
|
||||
PDO::ATTR_EMULATE_PREPARES => false, // Must be false for Swoole and Swow drivers.
|
||||
],
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'idle_timeout' => 60,
|
||||
'max_connections' => (int) env('DB_POOL_MAX', 20),
|
||||
'min_connections' => (int) env('DB_POOL_MIN', 2),
|
||||
'wait_timeout' => (float) env('DB_POOL_WAIT_TIMEOUT', 1.0),
|
||||
'idle_timeout' => (int) env('DB_POOL_IDLE_TIMEOUT', 60),
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
],
|
||||
|
||||
@@ -20,7 +20,7 @@ return [
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/webman.log',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
env('LOG_LEVEL', Monolog\Logger::INFO),
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
|
||||
@@ -35,6 +35,11 @@ return [
|
||||
'publicPath' => public_path()
|
||||
]
|
||||
],
|
||||
// 一键测试权重:定时轮询 status=0 的测试记录并执行,不占用 HTTP 资源
|
||||
'weight_test' => [
|
||||
'handler' => app\process\WeightTestProcess::class,
|
||||
'count' => 1,
|
||||
],
|
||||
// File update detection and automatic reload
|
||||
'monitor' => [
|
||||
'handler' => app\process\Monitor::class,
|
||||
|
||||
@@ -7,9 +7,9 @@ return [
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
'database' => env('REDIS_DB', 0),
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'max_connections' => (int) env('REDIS_POOL_MAX', 20),
|
||||
'min_connections' => (int) env('REDIS_POOL_MIN', 2),
|
||||
'wait_timeout' => (float) env('REDIS_POOL_WAIT_TIMEOUT', 1.0),
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
|
||||
@@ -13,29 +13,42 @@
|
||||
*/
|
||||
|
||||
use Webman\Route;
|
||||
use app\api\middleware\CheckAuthTokenMiddleware;
|
||||
use app\api\middleware\CheckUserTokenMiddleware;
|
||||
use app\api\middleware\TokenMiddleware;
|
||||
use app\api\middleware\AuthTokenMiddleware;
|
||||
|
||||
// 仅需 auth-token 的路由组(authToken 接口在中间件内白名单跳过)
|
||||
Route::group('/api', function () {
|
||||
Route::any('/authToken', [app\api\controller\AuthTokenController::class, 'index']);
|
||||
Route::any('/user/login', [app\api\controller\UserController::class, 'login']);
|
||||
Route::any('/user/register', [app\api\controller\UserController::class, 'register']);
|
||||
// 平台鉴权接口:/api/v1/authToken,请求头 signature/secret/time/agent_id,返回 authtToken
|
||||
Route::group('/api/v1', function () {
|
||||
Route::any('/authToken', [app\api\controller\v1\AuthTokenController::class, 'index']);
|
||||
})->middleware([]);
|
||||
|
||||
// 平台 v1 接口:需在请求头携带 auth-token
|
||||
Route::group('/api/v1', function () {
|
||||
Route::any('/getGameUrl', [app\api\controller\v1\GameController::class, 'getGameUrl']);
|
||||
Route::any('/getPlayerInfo', [app\api\controller\v1\GameController::class, 'getPlayerInfo']);
|
||||
Route::any('/getPlayerGameRecord', [app\api\controller\v1\GameController::class, 'getPlayerGameRecord']);
|
||||
Route::any('/getPlayerWalletRecord', [app\api\controller\v1\GameController::class, 'getPlayerWalletRecord']);
|
||||
Route::any('/getPlayerTicketRecord', [app\api\controller\v1\GameController::class, 'getPlayerTicketRecord']);
|
||||
Route::any('/setPlayerWallet', [app\api\controller\v1\GameController::class, 'setPlayerWallet']);
|
||||
})->middleware([
|
||||
CheckAuthTokenMiddleware::class,
|
||||
AuthTokenMiddleware::class,
|
||||
]);
|
||||
|
||||
// 需 auth-token + user-token 的路由组
|
||||
// 登录接口:无需 token,提交 JSON 获取带 token 的连接地址
|
||||
Route::group('/api', function () {
|
||||
Route::any('/user/Login', [app\api\controller\UserController::class, 'Login']);
|
||||
})->middleware([]);
|
||||
|
||||
// 其余接口:仅经 token 中间件鉴权(header: token,base64(username.-.time))
|
||||
Route::group('/api', function () {
|
||||
Route::any('/user/logout', [app\api\controller\UserController::class, 'logout']);
|
||||
Route::any('/user/info', [app\api\controller\UserController::class, 'info']);
|
||||
Route::any('/user/balance', [app\api\controller\UserController::class, 'balance']);
|
||||
Route::any('/user/walletRecord', [app\api\controller\UserController::class, 'walletRecord']);
|
||||
Route::any('/user/playGameRecord', [app\api\controller\UserController::class, 'playGameRecord']);
|
||||
Route::any('/game/config', [app\api\controller\GameController::class, 'config']);
|
||||
Route::any('/game/buyLotteryTickets', [app\api\controller\GameController::class, 'buyLotteryTickets']);
|
||||
Route::any('/game/lotteryPool', [app\api\controller\GameController::class, 'lotteryPool']);
|
||||
Route::any('/game/playStart', [app\api\controller\GameController::class, 'playStart']);
|
||||
})->middleware([
|
||||
CheckAuthTokenMiddleware::class,
|
||||
CheckUserTokenMiddleware::class,
|
||||
TokenMiddleware::class,
|
||||
]);
|
||||
|
||||
@@ -24,13 +24,13 @@ return [
|
||||
'tag_expire' => 86400 * 30,
|
||||
// 缓存标签前缀
|
||||
'tag_prefix' => 'tag:',
|
||||
// 连接池配置
|
||||
// 连接池配置(与 redis.php 对齐,生产可调大以减少等待)
|
||||
'pool' => [
|
||||
'max_connections' => 5, // 最大连接数
|
||||
'min_connections' => 1, // 最小连接数
|
||||
'wait_timeout' => 3, // 从连接池获取连接等待超时时间
|
||||
'idle_timeout' => 60, // 连接最大空闲时间,超过该时间会被回收
|
||||
'heartbeat_interval' => 50, // 心跳检测间隔,需要小于60秒
|
||||
'max_connections' => (int) env('REDIS_POOL_MAX', 20),
|
||||
'min_connections' => (int) env('REDIS_POOL_MIN', 2),
|
||||
'wait_timeout' => (float) env('REDIS_POOL_WAIT_TIMEOUT', 1.0),
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
],
|
||||
// 文件缓存
|
||||
|
||||
@@ -18,8 +18,7 @@ return [
|
||||
'hostport' => env('DB_PORT', 3306),
|
||||
// 数据库连接参数
|
||||
'params' => [
|
||||
// 连接超时3秒
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
\PDO::ATTR_TIMEOUT => (int) env('DB_CONNECT_TIMEOUT', 2),
|
||||
],
|
||||
// 数据库编码默认采用utf8
|
||||
'charset' => 'utf8',
|
||||
@@ -29,13 +28,13 @@ return [
|
||||
'break_reconnect' => true,
|
||||
// 自定义分页类
|
||||
'bootstrap' => '',
|
||||
// 连接池配置
|
||||
// 连接池配置(与 database.php 对齐)
|
||||
'pool' => [
|
||||
'max_connections' => 5, // 最大连接数
|
||||
'min_connections' => 1, // 最小连接数
|
||||
'wait_timeout' => 3, // 从连接池获取连接等待超时时间
|
||||
'idle_timeout' => 60, // 连接最大空闲时间,超过该时间会被回收
|
||||
'heartbeat_interval' => 50, // 心跳检测间隔,需要小于60秒
|
||||
'max_connections' => (int) env('DB_POOL_MAX', 20),
|
||||
'min_connections' => (int) env('DB_POOL_MIN', 2),
|
||||
'wait_timeout' => (float) env('DB_POOL_WAIT_TIMEOUT', 1.0),
|
||||
'idle_timeout' => (int) env('DB_POOL_IDLE_TIMEOUT', 60),
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
21
server/docs/DICE_REWARD_CONFIG_START_INDEX_IMPACT.md
Normal file
21
server/docs/DICE_REWARD_CONFIG_START_INDEX_IMPACT.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# 移除 DiceRewardConfig 表 s_start_index / n_start_index 的说明(已处理)
|
||||
|
||||
**`s_start_index`**(顺时针起始索引)、**`n_start_index`**(逆时针起始索引)已从业务与表单中移除,起始索引统一使用 **dice_reward.start_index**。
|
||||
|
||||
## 1. 当前状态(移除后无影响)
|
||||
|
||||
| 位置 | 处理情况 |
|
||||
|------|----------|
|
||||
| **PlayStartLogic** | 已使用 **DiceReward** 的 `start_index`,不读 config,无影响 |
|
||||
| **DiceRewardLogic::getListWithConfig** | 已去掉对 config 的 join 与回填,仅使用 `r.start_index` |
|
||||
| **DiceRewardConfigValidate** | 已从规则与 save/update 场景中删除这两项 |
|
||||
| **奖励配置编辑弹窗** | 已移除「顺时针/逆时针起始索引」表单项及提交字段 |
|
||||
| **DiceRewardConfig 模型** | 已从属性注释中删除 |
|
||||
|
||||
## 2. 数据库表结构
|
||||
|
||||
若表中仍有这两列,可执行:
|
||||
|
||||
- `server/db/dice_reward_config_drop_start_index.sql`:删除 `s_start_index`、`n_start_index` 列。
|
||||
|
||||
执行前请确认已通过「创建奖励对照」生成 dice_reward 数据,且 `dice_reward.start_index` 已正确写入。
|
||||
286
server/docs/PERFORMANCE_AND_QPS_ANALYSIS.md
Normal file
286
server/docs/PERFORMANCE_AND_QPS_ANALYSIS.md
Normal file
@@ -0,0 +1,286 @@
|
||||
# Game Performance & QPS Analysis (Dice Project)
|
||||
|
||||
> This document describes the current dice game backend architecture, key endpoints, approximate QPS capacity, and concrete optimization suggestions.
|
||||
> It is written in plain ASCII to avoid any encoding or garbled-text issues.
|
||||
|
||||
---
|
||||
|
||||
## 1. Runtime Environment Overview
|
||||
|
||||
| Item | Description |
|
||||
|-----------------|-----------------------------------------------------------------------------|
|
||||
| Framework | Webman (on top of Workerman, long-running PHP workers) |
|
||||
| Business module | `app/dice` (players, play records, rewards, lottery pool, dashboard, etc.) |
|
||||
| HTTP endpoint | Typically `http://0.0.0.0:6688` |
|
||||
| Worker count | Recommended: `cpu_count() * 4` (for example, 8 cores -> 32 workers) |
|
||||
| Database | MySQL + ThinkORM, with connection pool (for example, max=20 / min=2) |
|
||||
| Cache | Redis + think-cache, with connection pool (for example, max=20 / min=2) |
|
||||
|
||||
Recommended production configuration:
|
||||
|
||||
- Use Redis as default cache: in `.env`, set `CACHE_MODE=redis`.
|
||||
- Align `DB_POOL_MAX` / `REDIS_POOL_MAX` with worker count and MySQL `max_connections`.
|
||||
|
||||
---
|
||||
|
||||
## 2. Key Endpoints and Load Characteristics
|
||||
|
||||
From the codebase, main game-related endpoints can be roughly grouped into:
|
||||
|
||||
- High-load: multiple DB writes plus Redis and non-trivial business logic.
|
||||
- Medium-load: some DB writes or heavier DB reads.
|
||||
- Light: mostly cache reads or simple DB queries.
|
||||
|
||||
### 2.1 Main endpoints (current project)
|
||||
|
||||
Below is a simplified view; exact routes live in the dice module and API controllers:
|
||||
|
||||
| Endpoint | Purpose | Load level | Notes / risks |
|
||||
|-------------------------------------|--------------------------|------------|----------------------------------------------------------|
|
||||
| `POST /api/game/playStart` | Start a play / roll | High | Multiple DB + Redis ops, main QPS bottleneck |
|
||||
| `POST /api/game/buyLotteryTickets` | Buy tickets / chances | Med-High | Multiple table writes, wallet and ticket records |
|
||||
| `GET /api/game/config` | Game config for frontend | Medium | Depends on `DiceConfig` and cache |
|
||||
| `GET /api/game/lotteryPool` | Lottery / reward config | Medium | Depends on `DiceLotteryPoolConfig` / `DiceRewardConfig` |
|
||||
| `POST /api/v1/getGameUrl` | Get game URL / entry | Medium | JWT + Redis auth; light DB usage |
|
||||
| `POST /api/v1/getPlayerInfo` | Get player info | Medium | Needs index on `dice_player.username` |
|
||||
| `POST /api/v1/getPlayerGameRecord` | Player history records | Med-High | Risk of N+1 if not using batch/with |
|
||||
| `POST /api/v1/setPlayerWallet` | Adjust wallet balance | Medium | Wallet + records, must be concurrency-safe |
|
||||
|
||||
For QPS capacity analysis, focus on:
|
||||
|
||||
- `playStart` (core hot path).
|
||||
- Ticket, wallet, record-related endpoints.
|
||||
|
||||
---
|
||||
|
||||
## 3. `playStart` Call Flow and Resource Usage
|
||||
|
||||
The exact implementation is in the dice game logic layer and related services. A typical call flow looks like the following.
|
||||
|
||||
### 3.1 DB access (typical)
|
||||
|
||||
1. Load player:
|
||||
- `DicePlayer::find($playerId)`
|
||||
- Should be done once per request and reused.
|
||||
|
||||
2. Load reward EV / minimum real EV:
|
||||
- `DiceRewardConfig::getCachedMinRealEv()`
|
||||
- First call hits DB and writes Redis; later calls hit Redis only.
|
||||
|
||||
3. Get or create lottery pool:
|
||||
- `LotteryService::getOrCreate()`
|
||||
- Reads from Redis; if missing, reads from DB (for example, `DiceLotteryPoolConfig::where('type', 0/1)->find()`).
|
||||
|
||||
4. Load concrete pool config for this play:
|
||||
- `DiceLotteryPoolConfig::find($configId)`
|
||||
|
||||
5. Persist this play and its side effects (within one or several transactions):
|
||||
- `DicePlayRecord::create()` (play record)
|
||||
- `DicePlayer::save()` (balance and state)
|
||||
- `DicePlayerTicketRecord::create()` (ticket usage)
|
||||
- `DiceLotteryPoolConfig::where('id')->update(['ev' => Db::raw(...)]` (EV statistics)
|
||||
- `DicePlayerWalletRecord::create()` (wallet history)
|
||||
|
||||
6. Refresh player cache:
|
||||
- Reuse or reload player and call `UserCache::setUser($player)`.
|
||||
|
||||
Rough DB count (assuming good caching and no redundant `find` calls):
|
||||
|
||||
- About 3-6 DB queries/updates per `playStart`.
|
||||
- About 3-6 Redis operations per `playStart`.
|
||||
|
||||
If the code calls `DicePlayer::find($playerId)` multiple times in one request, DB usage and latency will increase accordingly.
|
||||
|
||||
### 3.2 Redis access
|
||||
|
||||
Typical Redis usages in the current design:
|
||||
|
||||
- Reward / pool configs: `DiceRewardConfig::getCachedInstance()`, `getCachedByTier()`, `LotteryService::getOrCreate()`.
|
||||
- Player cache: `UserCache::getUser()`, `UserCache::setUser()`.
|
||||
- Optional counters: EV / statistics counters can be done via Redis `INCRBY`, etc.
|
||||
|
||||
Goal: hot paths should hit Redis most of the time, and DB should primarily be for persistence and cold reads.
|
||||
|
||||
---
|
||||
|
||||
## 4. Main Bottlenecks and Optimizations
|
||||
|
||||
### 4.1 DB connections and slow SQL
|
||||
|
||||
1. Connection pool sizing:
|
||||
- With 32 workers and `DB_POOL_MAX=20`, connection exhaustion and waiting are likely at higher QPS.
|
||||
- Recommendation: set `DB_POOL_MAX` to something like 32-64 (depending on CPU and MySQL `max_connections`), and check that MySQL allows enough connections.
|
||||
|
||||
2. Avoid redundant queries:
|
||||
- In `playStart`, ensure player is loaded once and reused (do not call `DicePlayer::find` multiple times per request).
|
||||
|
||||
3. EV update strategy:
|
||||
- Repeated `UPDATE dice_lottery_config SET ev = ev - ?` on a hot row causes lock contention.
|
||||
- Better:
|
||||
- Accumulate EV deltas in Redis (per pool or per shard).
|
||||
- Periodic cron job to aggregate Redis deltas back into MySQL in batches.
|
||||
|
||||
4. Index coverage:
|
||||
- Ensure all high-frequency queries (`username`, `player_id`, `create_time`, status fields) use proper indexes (see section 6).
|
||||
|
||||
### 4.2 Cache and serialization overhead
|
||||
|
||||
1. Use Redis cache driver:
|
||||
- In `.env`, set `CACHE_MODE=redis`.
|
||||
- In `config/cache.php`, the default store should be Redis in production.
|
||||
|
||||
2. Player cache encryption:
|
||||
- If `UserCache` encrypts/decrypts data (for example, AES), CPU cost can be high at large QPS.
|
||||
- Possible mitigations:
|
||||
- Keep cached value small (only necessary fields).
|
||||
- Limit how often `setUser` is called (only on actual state changes).
|
||||
- Avoid double-encryption or repeated heavy serialization in hot paths.
|
||||
|
||||
### 4.3 N+1 queries
|
||||
|
||||
Endpoints like "get player game record" or wallet histories can easily trigger N+1 patterns:
|
||||
|
||||
- Use `whereIn('player_id', $playerIds)` instead of one query per player.
|
||||
- Use eager loading (`with(['dicePlayer'])`) for related player info.
|
||||
- Keep page size (`limit`) moderate (for example, 100 rows or less per page).
|
||||
|
||||
### 4.4 Redis vs DB coordination
|
||||
|
||||
- Ensure worker count, DB pool and Redis pool are balanced:
|
||||
- If CPU is not saturated but DB or Redis is fully blocked, it is a typical sign of misconfiguration.
|
||||
- Monitor Redis:
|
||||
- Use slowlog for heavy commands.
|
||||
- Watch for large keys or hot keys; consider hash or sharding if needed.
|
||||
|
||||
---
|
||||
|
||||
## 5. Approximate QPS Capacity (Single Node)
|
||||
|
||||
These are ballpark figures for a single node with something like 8 cores and 32 workers, with MySQL and Redis in the same LAN and the optimizations above applied. Real numbers must come from your own load tests.
|
||||
|
||||
### 5.1 Per-endpoint estimates
|
||||
|
||||
- `playStart`:
|
||||
- Typical latency: about 50-150 ms.
|
||||
- Expected QPS: about 200-300 per node.
|
||||
|
||||
- `buyLotteryTickets`:
|
||||
- Typical latency: about 20-60 ms.
|
||||
- Expected QPS: about 500-1000+ per node.
|
||||
|
||||
- `getGameUrl` / login-style endpoints:
|
||||
- Typical latency: about 30-80 ms.
|
||||
- Expected QPS: about 400-800 per node.
|
||||
|
||||
### 5.2 Mixed traffic scenario
|
||||
|
||||
Example traffic mix:
|
||||
|
||||
- 70% `playStart`
|
||||
- 30% lighter endpoints (`getGameUrl`, `getPlayerInfo`, and similar)
|
||||
|
||||
Under such a mix, with reasonable indexing and caching:
|
||||
|
||||
- A single 8-core node can typically sustain about 250-400 QPS overall.
|
||||
- To go significantly beyond that, you will normally use horizontal scaling (multiple app nodes) plus DB/Redis scaling (read replicas, sharding, and so on).
|
||||
|
||||
---
|
||||
|
||||
## 6. Index and Table Design Recommendations
|
||||
|
||||
### 6.1 Must-have indexes
|
||||
|
||||
| Table | Index | Purpose |
|
||||
|-----------------------------|-----------------------------------|------------------------------------------|
|
||||
| `dice_player` | unique(`username`) | Fast lookup by username (login, API) |
|
||||
| `dice_play_record` | index(`player_id`, `create_time`) | Player record listing plus time sorting |
|
||||
| `dice_player_wallet_record` | index(`player_id`, `create_time`) | Wallet history listing |
|
||||
| `dice_player_ticket_record` | index(`player_id`, `create_time`) | Ticket history listing |
|
||||
|
||||
Example SQL:
|
||||
|
||||
```sql
|
||||
ALTER TABLE dice_player ADD UNIQUE INDEX uk_username (username);
|
||||
ALTER TABLE dice_play_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
ALTER TABLE dice_player_wallet_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
ALTER TABLE dice_player_ticket_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
```
|
||||
|
||||
### 6.2 Large-table strategy
|
||||
|
||||
For very large history tables (play records, wallet logs, ticket logs), plan ahead:
|
||||
|
||||
- Partitioning or sharding (by time or by player ID).
|
||||
- Archival strategy (move very old data to cold storage or delete).
|
||||
|
||||
---
|
||||
|
||||
## 7. Load Testing and Metrics
|
||||
|
||||
### 7.1 Load testing `playStart`
|
||||
|
||||
1. Prepare:
|
||||
- Seed enough test players and balances.
|
||||
- Obtain valid JWT tokens.
|
||||
|
||||
2. `ab` example:
|
||||
|
||||
```bash
|
||||
ab -n 2000 -c 32 \
|
||||
-p post_body.json \
|
||||
-T application/json \
|
||||
-H "token: YOUR_JWT" \
|
||||
http://127.0.0.1:6688/api/game/playStart
|
||||
```
|
||||
|
||||
3. `wrk` example:
|
||||
|
||||
```bash
|
||||
wrk -t4 -c32 -d60s -s play_start.lua http://127.0.0.1:6688/api/game/playStart
|
||||
```
|
||||
|
||||
4. Focus on:
|
||||
- QPS (Requests per second)
|
||||
- P95 / P99 latency
|
||||
- Error rates (HTTP 5xx, timeouts, business failures)
|
||||
- MySQL / Redis CPU and connection usage
|
||||
|
||||
### 7.2 Typical troubleshooting
|
||||
|
||||
- Low QPS but low CPU:
|
||||
- Likely DB or Redis connection pool exhaustion or slow queries.
|
||||
- High P99 spikes:
|
||||
- Check for large transactions, schema changes, backup jobs, GC, or disk I/O hiccups.
|
||||
- Redis issues:
|
||||
- Look for big keys, blocking commands (for example, `KEYS`), or high single-key contention.
|
||||
|
||||
---
|
||||
|
||||
## 8. Configuration and Code Checklist
|
||||
|
||||
Use this list before load tests or production deployments.
|
||||
|
||||
### 8.1 Configuration
|
||||
|
||||
- `.env`:
|
||||
- [ ] `CACHE_MODE=redis`
|
||||
- [ ] `DB_POOL_MAX` / `DB_POOL_MIN` tuned for CPU and MySQL `max_connections`
|
||||
- [ ] `REDIS_POOL_MAX` large enough for concurrent traffic
|
||||
- MySQL:
|
||||
- [ ] `max_connections` greater than or equal to the sum of all app DB pools
|
||||
- [ ] Slow query log enabled with a reasonable threshold
|
||||
|
||||
### 8.2 Code
|
||||
|
||||
- [ ] `playStart` loads player once and reuses it everywhere.
|
||||
- [ ] Reward and pool configuration is always accessed via cache; after changes, cache is refreshed.
|
||||
- [ ] History and wallet endpoints avoid N+1; use batch queries and eager loading.
|
||||
- [ ] EV and other hot counters use Redis aggregation instead of per-request `UPDATE` on hot rows.
|
||||
|
||||
---
|
||||
|
||||
## 9. Summary
|
||||
|
||||
- For the current dice project, `playStart` and related lottery, wallet, and ticket flows define the backend QPS ceiling.
|
||||
- With proper connection pool tuning, Redis caching, indexing, and fewer redundant DB operations, a single 8-core node can typically handle a few hundred QPS of mixed traffic.
|
||||
- Real capacity must be validated via `ab`, `wrk`, or `k6` load tests against your environment; this document serves as a practical guide for identifying and fixing performance bottlenecks.
|
||||
293
server/docs/PERFORMANCE_AND_QPS_ANALYSIS_CN.md
Normal file
293
server/docs/PERFORMANCE_AND_QPS_ANALYSIS_CN.md
Normal file
@@ -0,0 +1,293 @@
|
||||
# 游戏性能与 QPS 分析(Dice 项目)
|
||||
|
||||
> 本文基于当前骰子游戏(dice)项目的实际代码结构,对后端接口的性能瓶颈、QPS 能力和优化方向做说明,便于后续压测、扩容和排查问题。
|
||||
|
||||
---
|
||||
|
||||
## 1. 运行环境与架构概览
|
||||
|
||||
| 项目 | 说明 |
|
||||
|----------------|----------------------------------------------------------------------|
|
||||
| 应用框架 | Webman(基于 Workerman 的常驻内存 PHP 框架) |
|
||||
| 业务模块 | `app/dice`(玩家、抽奖记录、奖励配置、奖池配置、看板等) |
|
||||
| HTTP 监听地址 | 通常为 `http://0.0.0.0:6688` |
|
||||
| Worker 数量 | 推荐:`cpu_count() * 4`(例如 8 核 CPU → 32 个 Worker 进程) |
|
||||
| 数据库 | MySQL + ThinkORM,使用连接池(例如 max=20 / min=2) |
|
||||
| 缓存 | Redis + think-cache,使用连接池(例如 max=20 / min=2) |
|
||||
|
||||
**生产环境配置建议:**
|
||||
|
||||
- 在 `.env` 中统一使用 Redis 作为默认缓存:`CACHE_MODE=redis`
|
||||
- 调整 `DB_POOL_MAX` / `REDIS_POOL_MAX`,使其与 Worker 数量和 MySQL `max_connections` 匹配
|
||||
|
||||
---
|
||||
|
||||
## 2. 核心接口与负载特征
|
||||
|
||||
从当前项目代码来看,游戏相关接口大致可以分为三类:
|
||||
|
||||
- **高负载型**:强依赖 DB + Redis,多次写入或复杂逻辑(QPS 瓶颈主要在这里)
|
||||
- **中负载型**:部分写 DB 或复杂读 DB
|
||||
- **轻量型**:读缓存或简单 DB 查询
|
||||
|
||||
### 2.1 主要接口梳理
|
||||
|
||||
| 接口 | 用途 | 负载级别 | 说明 / 风险点 |
|
||||
|-------------------------------------|--------------------|----------|--------------------------------------------------------|
|
||||
| `POST /api/game/playStart` | 开始一局游戏 / 抽奖 | 高 | 多次 DB + Redis 操作,是整体 QPS 的核心瓶颈 |
|
||||
| `POST /api/game/buyLotteryTickets` | 购买门票 / 次数 | 中-高 | 多表写入:门票记录、钱包记录等 |
|
||||
| `GET /api/game/config` | 获取游戏配置 | 中 | 依赖 `DiceConfig`,若无缓存会有全表扫描风险 |
|
||||
| `GET /api/game/lotteryPool` | 获取奖池 / 奖励配置 | 中 | 依赖 `DiceLotteryPoolConfig` / `DiceRewardConfig` |
|
||||
| `POST /api/v1/getGameUrl` | 获取游戏 URL | 中 | JWT + Redis 鉴权,DB 较少,Redis 压力较大 |
|
||||
| `POST /api/v1/getPlayerInfo` | 获取玩家信息 | 中 | 需要 `dice_player.username` 索引,否则易产生慢查询 |
|
||||
| `POST /api/v1/getPlayerGameRecord` | 获取玩家历史记录 | 中-高 | 若未优化,容易出现 N+1 查询问题 |
|
||||
| `POST /api/v1/setPlayerWallet` | 调整玩家钱包余额 | 中 | 涉及余额变更与流水写入,需处理好并发与幂等 |
|
||||
|
||||
在进行 QPS 能力评估或性能优化时,优先关注:
|
||||
|
||||
- `playStart` 接口;
|
||||
- 门票 / 钱包 / 流水相关接口。
|
||||
|
||||
---
|
||||
|
||||
## 3. `playStart` 调用链与资源消耗
|
||||
|
||||
以下是典型的一次 `playStart` 请求在后端的大致流程(抽象描述):
|
||||
|
||||
### 3.1 数据库访问路径(典型情况)
|
||||
|
||||
1. **加载玩家信息**
|
||||
- 调用 `DicePlayer::find($playerId)`
|
||||
- 建议:每个请求只查询一次,并在后续逻辑中复用该对象。
|
||||
|
||||
2. **加载奖励 EV / 最小实际 EV**
|
||||
- 调用 `DiceRewardConfig::getCachedMinRealEv()`
|
||||
- 首次会访问 DB 并写入 Redis;后续命中 Redis 即可。
|
||||
|
||||
3. **获取或创建奖池(LotteryService)**
|
||||
- 调用 `LotteryService::getOrCreate()`:
|
||||
- 优先从 Redis 中读取奖池信息;
|
||||
- 若缓存不存在,则从 DB 中加载:如 `DiceLotteryPoolConfig::where('type', 0/1)->find()`。
|
||||
|
||||
4. **根据本次玩法加载奖池配置**
|
||||
- 调用 `DiceLotteryPoolConfig::find($configId)`。
|
||||
|
||||
5. **核心业务落库(可能在事务中执行)**
|
||||
- `DicePlayRecord::create()`:写入本次抽奖记录;
|
||||
- `DicePlayer::save()`:更新玩家余额、状态等;
|
||||
- `DicePlayerTicketRecord::create()`:写入门票/次数流水;
|
||||
- `DiceLotteryPoolConfig::where('id')->update(['ev' => Db::raw(...)]`:更新 EV 统计;
|
||||
- `DicePlayerWalletRecord::create()`:写入钱包流水。
|
||||
|
||||
6. **刷新玩家缓存**
|
||||
- 再次使用(或重新加载)玩家信息,调用 `UserCache::setUser($player)` 同步到 Redis。
|
||||
|
||||
**DB / Redis 调用次数粗略估算:**
|
||||
|
||||
- 在写法合理、缓存命中良好的情况下,每次 `playStart` 大致会产生:
|
||||
- 3 ~ 6 次 DB 访问(读 + 写);
|
||||
- 3 ~ 6 次 Redis 操作。
|
||||
- 若在同一请求中多次重复调用 `DicePlayer::find($playerId)`,DB 调用次数和耗时都会显著上升。
|
||||
|
||||
### 3.2 Redis 使用路径
|
||||
|
||||
在当前设计中,Redis 主要用于:
|
||||
|
||||
- 奖励 / 奖池配置缓存:`DiceRewardConfig::getCachedInstance()`、`getCachedByTier()`、`LotteryService::getOrCreate()` 等;
|
||||
- 玩家缓存:`UserCache::getUser()`、`UserCache::setUser()`;
|
||||
- 统计计数:可以使用 Redis `INCRBY` 等命令维护 EV 或其他统计数据。
|
||||
|
||||
**目标:** 热路径尽量命中 Redis,DB 主要负责落库和冷数据读取。
|
||||
|
||||
---
|
||||
|
||||
## 4. 性能瓶颈与优化方向
|
||||
|
||||
### 4.1 数据库连接与 SQL
|
||||
|
||||
1. **连接池大小**
|
||||
- 在 32 个 Worker 且 `DB_POOL_MAX=20` 的情况下,高并发时容易出现连接耗尽和等待。
|
||||
- 建议:根据 CPU 核心数和目标 QPS,将 `DB_POOL_MAX` 调整到 **32 ~ 64** 左右,并保证 MySQL `max_connections` 足够大。
|
||||
|
||||
2. **避免重复查询**
|
||||
- 在 `playStart` 中,玩家信息应只查询一次:`$player = DicePlayer::find($playerId)`,后续逻辑统一使用 `$player`,避免重复 `find`。
|
||||
|
||||
3. **EV 更新策略**
|
||||
- 频繁在在线请求中执行 `UPDATE dice_lottery_config SET ev = ev - ?`,会造成该行热点锁竞争;
|
||||
- 建议:
|
||||
- 在线请求仅将 EV 变动累加到 Redis 计数器;
|
||||
- 通过定时任务批量同步 Redis 中的统计数据回 MySQL。
|
||||
|
||||
4. **索引覆盖**
|
||||
- 高频查询条件(如 `username`、`player_id`、`create_time`、`status` 等)必须有合适索引(见第 6 节)。
|
||||
|
||||
### 4.2 缓存与序列化开销
|
||||
|
||||
1. **统一使用 Redis 缓存驱动**
|
||||
- `.env` 中设置:`CACHE_MODE=redis`;
|
||||
- `config/cache.php` 中,生产环境默认缓存驱动应为 Redis。
|
||||
|
||||
2. **UserCache 加解密成本**
|
||||
- 若 `UserCache` 中对玩家信息做 AES 加解密,在高 QPS 场景下会占用较多 CPU;
|
||||
- 可以:
|
||||
- 精简缓存字段,只缓存必要信息;
|
||||
- 控制 `setUser` 调用频率,避免无意义重复写入;
|
||||
- 评估哪些字段确实需要加密,非敏感字段可不加密。
|
||||
|
||||
### 4.3 N+1 查询问题
|
||||
|
||||
历史记录、钱包流水等接口非常容易出现 N+1 查询,例如:
|
||||
|
||||
- 循环按玩家逐条查询记录;
|
||||
- 循环对每条记录再单独查询玩家信息。
|
||||
|
||||
建议:
|
||||
|
||||
- 使用 `whereIn('player_id', $playerIds)` 做批量查询;
|
||||
- 使用 `with(['dicePlayer'])` 或 join 预加载关联的玩家信息;
|
||||
- 控制单页 `limit`,例如不超过 100 条。
|
||||
|
||||
### 4.4 Redis 与 DB 的整体协同
|
||||
|
||||
- Worker 数、DB 连接池、Redis 连接池三者要相互匹配:
|
||||
- 出现 CPU 未打满但 DB/Redis 已经“顶满”的情况,多半是配置不平衡。
|
||||
- 对 Redis 的监控要关注:
|
||||
- 慢日志(慢命令);
|
||||
- 大 Key 或热点 Key(必要时做拆分或分桶)。
|
||||
|
||||
---
|
||||
|
||||
## 5. 单机 QPS 能力(估算)
|
||||
|
||||
> 以下为在常见生产环境(如 8C32G 单机、MySQL/Redis 与应用在同一内网)且做好上述优化后的大致量级,仅用于评估和对比,实际仍需通过压测确认。
|
||||
|
||||
### 5.1 单接口预估
|
||||
|
||||
- `playStart`
|
||||
- 单次耗时:约 50 ~ 150 ms(受 DB/Redis 延迟和业务分支影响);
|
||||
- 单机 QPS:约 **200 ~ 300**。
|
||||
|
||||
- `buyLotteryTickets`
|
||||
- 单次耗时:约 20 ~ 60 ms;
|
||||
- 单机 QPS:约 **500 ~ 1000+**。
|
||||
|
||||
- `getGameUrl` / 登录类接口
|
||||
- 单次耗时:约 30 ~ 80 ms;
|
||||
- 单机 QPS:约 **400 ~ 800**。
|
||||
|
||||
### 5.2 混合业务场景
|
||||
|
||||
假设:
|
||||
|
||||
- 70% 请求是 `playStart`;
|
||||
- 30% 请求为 `getGameUrl`、`getPlayerInfo` 等轻 / 中量接口;
|
||||
|
||||
在 8 核 32 Worker、索引和缓存配置合理的前提下:
|
||||
|
||||
- 单机综合 QPS 约可达到 **250 ~ 400 QPS**;
|
||||
- 若需要显著更高的整体 QPS,应采用多节点水平扩展 + DB/Redis 扩容(读写分离、分库分表等)。
|
||||
|
||||
---
|
||||
|
||||
## 6. 索引与表结构建议
|
||||
|
||||
### 6.1 必备索引
|
||||
|
||||
| 表名 | 索引 | 用途说明 |
|
||||
|------------------------------|-----------------------------------|--------------------------------|
|
||||
| `dice_player` | 唯一索引 `unique(username)` | 通过用户名快速定位玩家 |
|
||||
| `dice_play_record` | 普通索引 `(player_id, create_time)` | 玩家历史记录分页 + 时间排序 |
|
||||
| `dice_player_wallet_record` | 普通索引 `(player_id, create_time)` | 钱包流水查询 |
|
||||
| `dice_player_ticket_record` | 普通索引 `(player_id, create_time)` | 门票流水查询 |
|
||||
|
||||
示例 SQL:
|
||||
|
||||
```sql
|
||||
ALTER TABLE dice_player ADD UNIQUE INDEX uk_username (username);
|
||||
ALTER TABLE dice_play_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
ALTER TABLE dice_player_wallet_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
ALTER TABLE dice_player_ticket_record ADD INDEX idx_player_create (player_id, create_time);
|
||||
```
|
||||
|
||||
### 6.2 大表策略
|
||||
|
||||
对于体量较大的历史表(抽奖记录、钱包流水、门票流水等),建议提前规划:
|
||||
|
||||
- 分区或分表策略(按时间或按玩家 ID);
|
||||
- 归档 / 删除过旧数据,例如只保留最近 N 个月的在线查询。
|
||||
|
||||
---
|
||||
|
||||
## 7. 压测步骤与指标观测
|
||||
|
||||
### 7.1 压测 `playStart`
|
||||
|
||||
1. 准备数据:
|
||||
- 预先创建足够多的测试玩家及初始余额;
|
||||
- 获取一批可用的 JWT token。
|
||||
|
||||
2. 使用 `ab` 压测示例:
|
||||
|
||||
```bash
|
||||
ab -n 2000 -c 32 \
|
||||
-p post_body.json \
|
||||
-T application/json \
|
||||
-H "token: YOUR_JWT" \
|
||||
http://127.0.0.1:6688/api/game/playStart
|
||||
```
|
||||
|
||||
3. 使用 `wrk` 压测示例:
|
||||
|
||||
```bash
|
||||
wrk -t4 -c32 -d60s -s play_start.lua http://127.0.0.1:6688/api/game/playStart
|
||||
```
|
||||
|
||||
4. 重点关注指标:
|
||||
- QPS(Requests per second);
|
||||
- P95 / P99 延迟;
|
||||
- 错误率(HTTP 5xx、超时、业务失败);
|
||||
- MySQL / Redis 的 CPU 使用率与连接数。
|
||||
|
||||
### 7.2 常见问题排查思路
|
||||
|
||||
1. **QPS 上不去,CPU 却不高**
|
||||
- 检查 DB / Redis 连接池是否经常“打满”;
|
||||
- 是否存在慢 SQL(全表扫描、缺索引);
|
||||
- 是否有外部依赖(如第三方接口)拖慢整体。
|
||||
|
||||
2. **P99 延迟偶尔飙高**
|
||||
- 查看是否有大事务 / 大批量更新与压测同时进行;
|
||||
- 观察磁盘 I/O 和 GC 情况;
|
||||
- 检查 Redis 是否有大 Key 或阻塞命令(如 `KEYS`)。
|
||||
|
||||
---
|
||||
|
||||
## 8. 配置与代码自查清单
|
||||
|
||||
> 建议在压测前和上线前都按此清单进行一次自查。
|
||||
|
||||
### 8.1 配置层面
|
||||
|
||||
- `.env`:
|
||||
- [ ] `CACHE_MODE=redis` 已开启;
|
||||
- [ ] `DB_POOL_MAX` / `DB_POOL_MIN` 已根据 CPU 与 MySQL `max_connections` 调整;
|
||||
- [ ] `REDIS_POOL_MAX` 能够支撑预期并发量。
|
||||
- MySQL:
|
||||
- [ ] `max_connections` 不小于所有应用实例 DB 连接池上限之和;
|
||||
- [ ] 已开启慢查询日志,并设置了合理阈值。
|
||||
|
||||
### 8.2 代码层面
|
||||
|
||||
- [ ] `playStart` 在一次请求中只加载一次玩家信息并全程复用;
|
||||
- [ ] 奖励/奖池配置统一通过缓存访问,修改后有刷新缓存逻辑(如 `refreshCache()`);
|
||||
- [ ] 历史记录、钱包流水接口避免 N+1 查询,使用批量查询或预加载;
|
||||
- [ ] EV 等高频统计字段不直接在在线请求中频繁 `UPDATE`,而是通过 Redis 聚合后批量回写。
|
||||
|
||||
---
|
||||
|
||||
## 9. 总结
|
||||
|
||||
1. 对于当前 dice 项目,`playStart` 以及与之相关的奖池、钱包、门票逻辑,是后端 QPS 能力的关键瓶颈所在。
|
||||
2. 通过合理配置 DB/Redis 连接池、充分利用缓存、补齐必要索引、减少重复查询和热点 UPDATE,可以大幅提升单机可承载的 QPS,并降低 P99 延迟。
|
||||
3. 真正的容量边界必须通过 `ab` / `wrk` / `k6` 等工具在接近真实数据和流量模型的情况下进行压测验证,本文档主要为定位瓶颈和指导优化提供一个工程实践层面的参考。
|
||||
|
||||
49
server/docs/PLAY_START_FLOW_COMPARISON.md
Normal file
49
server/docs/PLAY_START_FLOW_COMPARISON.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# 抽奖流程对比:当前实现 vs 预期流程
|
||||
|
||||
## 你描述的预期流程
|
||||
|
||||
1. **先判断中的是 T1–T5 中的哪个奖**
|
||||
→ 按彩金池/玩家权重抽档位 T1–T5。
|
||||
|
||||
2. **根据 (1) 中奖类型从 DiceRewardConfig 读取数据,再根据权重 weight 抽取点数 grid_number**
|
||||
→ 该档位下多条配置,按每条配置的 **weight** 抽一条,得到这条配置的 **grid_number**(以及 real_ev 等)。
|
||||
|
||||
3. **根据抽取的 grid_number 查找有无对应的 s_end_index(n_end_index)**
|
||||
→ 用上一步得到的 grid_number(及方向)去查「带该 grid_number 且带 s_end_index/n_end_index 的配置」是否存在。
|
||||
|
||||
4. **若有则输出 s_end_index(n_end_index)对应的点数和起始点数;中奖数据仍用步骤 2 抽到的 grid_number 对应配置**
|
||||
→ 输出:起始点、终点(s_end_index 或 n_end_index)、点数和 roll_number;中奖金额等用步骤 2 抽到的那条配置。
|
||||
|
||||
5. **判断是否中大奖**
|
||||
→ 若点数和为豹子组合 (5,10,15,20,25,30),其中 5 和 30 必中大奖,其余按 BIGWIN 的 weight 再判一次;中大奖则返回 BIGWIN 的 roll_array。
|
||||
|
||||
---
|
||||
|
||||
## 当前实现
|
||||
|
||||
| 步骤 | 预期 | 当前实现 | 是否一致 |
|
||||
|------|------|----------|----------|
|
||||
| 1 | 先抽 T1–T5 档位 | 按彩金池/玩家权重抽 T1–T5 | ✅ 一致 |
|
||||
| 2 | 按该档位配置的 **weight** 抽取 **grid_number**(即抽一条配置) | 该档位配置**等权随机**选一条 `chosen`,**没有用 weight**;且当前用的 **grid_number 来自后面的「路径」配置**,不是来自这条 chosen | ❌ 不一致:未按 weight 抽,grid_number 来源也不对 |
|
||||
| 3 | 根据 grid_number 查 s_end_index / n_end_index | 根据 **chosen.id** 查「s_end_index = chosen.id 或 n_end_index = chosen.id」的配置,得到若干 **startCandidates**(路径列表) | ❌ 不一致:是按「终点 id」查路径,不是按 grid_number 查 |
|
||||
| 4 | 若有则输出终点、点数和、起始点;中奖数据用步骤 2 的配置 | 从 startCandidates 里再**等权随机**一条 `startRecord`,用 **startRecord.id** 作起始、**startRecord.grid_number** 作点数和、**startRecord.s_end_index/n_end_index** 作终点;中奖数据(real_ev 等)用的是 **chosen** | ⚠️ 部分一致:终点、起始、点数和都有,但 grid_number 来自路径而不是「按 weight 抽出的那条配置」 |
|
||||
| 5 | 豹子点数 5,10,15,20,25,30;5/30 必中大奖;其余按 BIGWIN.weight 判 | 逻辑一致:5/30 必中大奖,其余用 BIGWIN 的 weight 判定 | ✅ 一致 |
|
||||
|
||||
### weight 是否实例化(入缓存)
|
||||
|
||||
- **BIGWIN**:缓存里有完整行,含 **weight**,`getCachedByTierAndGridNumber('BIGWIN', rollNumber)` 返回的配置里带 weight,已用于步骤 5。✅ 已实例化。
|
||||
- **T1–T5**:`getCachedByTier(tier)` 返回的每条配置也是完整行(含 weight),但当前代码**没有用这些 weight**,只用 `array_rand` 等权选一条。即:weight 已在缓存里,但**未参与抽奖**。⚠️ 已实例化但未使用。
|
||||
|
||||
---
|
||||
|
||||
## 结论与建议
|
||||
|
||||
- **不一致点**:
|
||||
- 步骤 2:应用「该档位下按 **weight** 抽一条配置」,用这条配置的 **grid_number**(和 real_ev 等);当前是等权抽一条且 grid_number 实际来自路径。
|
||||
- 步骤 3:应用「用步骤 2 得到的 **grid_number**(及方向)查是否有 s_end_index/n_end_index」;当前是用 chosen.id 查「以该 id 为终点的路径」。
|
||||
|
||||
- **建议**:
|
||||
- 改为「先按档位内 weight 抽一条配置」,以该条为**唯一**来源得到 grid_number、real_ev、以及 s_end_index/n_end_index(若表结构是一条配置同时带 grid_number 与 s_end_index/n_end_index)。
|
||||
- 若表结构是「奖励配置」与「路径配置」分离,则需在步骤 2 按 weight 抽到 grid_number 后,再按 **grid_number + 方向** 查路径表得到 s_end_index/n_end_index 与起始点;并保证只对「在该方向下有有效 s_end_index/n_end_index 的配置」做 weight 抽取。
|
||||
|
||||
若你确认表结构(是否同一张表、是否一条既有 grid_number 又有 s_end_index/n_end_index),我可以按上述思路给出具体修改方案(含要改的类/方法名和伪代码)。
|
||||
39
server/docs/README_WEIGHT_TEST.md
Normal file
39
server/docs/README_WEIGHT_TEST.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# 一键测试权重 - 数据库 SQL 操作说明
|
||||
|
||||
## 1. 新建表 dice_play_record_test
|
||||
|
||||
测试用游玩记录表,结构与 `dice_play_record` 完全一致,不关联真实玩家(`player_id` 填 0),用于写入模拟数据并可一键清空。
|
||||
|
||||
**执行脚本:** `dice_play_record_test.sql`
|
||||
|
||||
```sql
|
||||
-- 若表已存在可跳过;执行前请确认 dice_play_record 表已存在
|
||||
CREATE TABLE IF NOT EXISTS `dice_play_record_test` LIKE `dice_play_record`;
|
||||
```
|
||||
|
||||
## 2. 扩展表 dice_reward_config_record
|
||||
|
||||
为一键测试权重增加进度与结果字段:总次数、已完成次数、状态、备注、顺/逆时针次数、档位出现次数(档位概率)。
|
||||
|
||||
**执行脚本:** `dice_reward_config_record_add_test_progress.sql`
|
||||
|
||||
若某列已存在会报错,可跳过该条继续执行下一条。
|
||||
|
||||
- `total_play_count`:总模拟次数(s_count + n_count)
|
||||
- `over_play_count`:已完成次数,每完成 10 条写入 `dice_play_record_test` 后更新
|
||||
- `status`:-1 失败,0 进行中,1 成功
|
||||
- `remark`:失败时记录原因
|
||||
- `s_count`:顺时针模拟次数
|
||||
- `n_count`:逆时针模拟次数
|
||||
- `tier_counts`:档位出现次数 JSON(T1=>count),用于档位概率
|
||||
|
||||
原有字段 `result_counts` 已存在,用于点数出现次数(点数概率)。
|
||||
|
||||
## 3. 导入操作
|
||||
|
||||
`dice_reward_config_record` 的**导入**功能保持不变:可将测试记录的权重快照导入到 `DiceReward` 与 `DiceLotteryPoolConfig`,并刷新缓存。无需额外 SQL。
|
||||
|
||||
## 执行顺序建议
|
||||
|
||||
1. 先执行 `dice_play_record_test.sql` 创建测试表。
|
||||
2. 再执行 `dice_reward_config_record_add_test_progress.sql` 为测试记录表增加字段(逐条执行,已存在的列可忽略)。
|
||||
78
server/docs/ROLL_NUMBER_ANALYSIS.md
Normal file
78
server/docs/ROLL_NUMBER_ANALYSIS.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# 色子点数(5–30)抽中概率分析
|
||||
|
||||
## 一、当前流程(为何 5 和 30 容易出、部分点数可能摇不到)
|
||||
|
||||
点数 `rollNumber`(5–30)由**两步**决定,而不是在 5–30 里直接按权重抽一次:
|
||||
|
||||
1. **先抽档位**
|
||||
按池子/玩家权重抽 T1–T5 之一。
|
||||
|
||||
2. **再在该档位内按权重抽一条“奖励配置”**
|
||||
`$chosen = drawRewardByWeight(tierRewards)`,得到一条配置,记其主键为 `chosenId`。
|
||||
|
||||
3. **按 chosenId 取“路径候选”**
|
||||
- 顺时针:`startCandidates = getCachedBySEndIndex(chosenId)` → 所有 **s_end_index = chosenId** 的配置。
|
||||
- 逆时针:`startCandidates = getCachedByNEndIndex(chosenId)` → 所有 **n_end_index = chosenId** 的配置。
|
||||
|
||||
4. **在路径候选中再按权重抽一条**
|
||||
`$startRecord = drawRewardByWeight(startCandidates)`,最终 **rollNumber = $startRecord['grid_number']**。
|
||||
|
||||
因此:
|
||||
|
||||
- **本局能出现哪些点数,完全由“当前 chosenId 对应的路径组”决定。**
|
||||
- 只有**在 startCandidates 里出现的 grid_number** 才会被摇到;**不在该组里的点数本局根本不会参与抽取**,相当于被“跳过”。
|
||||
|
||||
## 二、为何 5 和 30 摇到的概率会很大
|
||||
|
||||
可能原因:
|
||||
|
||||
1. **路径数据里 5、30 占比高**
|
||||
对很多 `chosenId`,其 `s_end_index=chosenId`(或 n_end_index)的配置里,grid_number=5 和 30 的条数多、或 weight 设得大,其它点数少/权重小,所以在这组里一抽就经常是 5 或 30。
|
||||
|
||||
2. **被抽中的 chosenId 偏集中在“含 5、30 的路径组”**
|
||||
档位内按权重抽到的 `$chosen` 的 id,如果经常落在某几类 id 上,而这些 id 对应的路径组里又以 5、30 为主,整体就会表现为 5、30 出现很多。
|
||||
|
||||
3. **5、30 出现在很多路径组里**
|
||||
若 5、30 对应的配置的 `s_end_index`/`n_end_index` 覆盖了很多不同的 id(即出现在很多“路径组”里),而其它点数只出现在少数几个 id 的路径组里,那么 5、30 被抽到的机会自然更多。
|
||||
|
||||
## 三、为何有些点数“摇不到、像被跳过”
|
||||
|
||||
- 某点数 **grid_number = G** 本局能出,**仅当**:
|
||||
当前 `chosenId` 对应的路径组里,**存在至少一条配置的 grid_number = G**(且 weight>0 会参与权重抽)。
|
||||
- 若在**所有** `s_end_index = 某 id`(或 n_end_index)的路径组里,**都没有** grid_number=12 的配置,那么 12 就**永远不会**被摇到,即被“跳过”。
|
||||
- 若 12 只出现在“很少被选中的 chosenId”对应的路径组里(例如这些 id 在档位内权重很低),那 12 就会**很少**出现。
|
||||
|
||||
所以:**不是代码故意跳过某些点数,而是这些点数在当前数据下,没有进入“本局实际参与抽奖的那组路径”里。**
|
||||
5、30 摇得多 = 它们在这组路径里权重大或出现次数多;某些点数摇不到 = 它们没进这组路径或权重为 0。
|
||||
|
||||
## 四、建议的数据检查(在库里直接查)
|
||||
|
||||
在 `dice_reward_config` 表里可以做两类检查:
|
||||
|
||||
**1)每个点数是否至少能出现在某个路径组里(避免永远摇不到)**
|
||||
|
||||
- 顺时针:对每个 grid_number(5–30),是否存在至少一行 **s_end_index = 某个在 T1–T5 里出现过的 id**,且该行 weight > 0。
|
||||
(“在 T1–T5 里出现过的 id” = 作为某条 T1–T5 配置的主键 id。)
|
||||
- 逆时针:同上,把 `s_end_index` 换成 `n_end_index`。
|
||||
|
||||
若某点数在顺时针(或逆时针)下没有任何一条这样的行,则该点数在该方向下**永远不会**被摇到。
|
||||
|
||||
**2)各点数在“路径组内”的权重是否过于悬殊**
|
||||
|
||||
- 对常见的 chosenId(例如在 T1 里权重高的几条配置的 id),查:
|
||||
`SELECT grid_number, SUM(weight) FROM dice_reward_config WHERE s_end_index = ? AND tier IN ('T1','T2',...) GROUP BY grid_number`
|
||||
看 5、30 的权重和是否明显高于 6–29,导致在该路径组内一抽就经常是 5 或 30。
|
||||
|
||||
## 五、可选:打开调试日志看“本局路径组里有哪些点数”
|
||||
|
||||
在 `PlayStartLogic` 里,在 `$startRecord = drawRewardByWeight(...)` 之后可加一段**仅调试时启用**的日志,例如:
|
||||
|
||||
- 打出:`chosenId`、`direction`、本局路径组里出现的 **grid_number 列表**及每个 grid_number 的**权重和**(或条数)。
|
||||
这样可以看到:每次抽奖时“实际参与抽奖的点数集合”是哪些,5、30 在该组里的权重是否偏大,以及哪些点数从未出现在日志里(即被跳过)。
|
||||
|
||||
---
|
||||
|
||||
**结论**:
|
||||
- 5 和 30 摇到的概率大,是因为在“当前 chosenId 对应的路径组”里,它们权重高或出现次数多。
|
||||
- 某些点数摇不到,是因为它们没有出现在任何“本局会用到”的路径组里,或只出现在极少被选中的路径组里。
|
||||
要平衡概率,需要从**路径数据**入手:保证每个点数 5–30 至少出现在若干路径组中且 weight>0,并调低 5、30 在路径组内的权重或条数占比。
|
||||
@@ -33,24 +33,39 @@ class SystemController extends BaseController
|
||||
*/
|
||||
public function userInfo(): Response
|
||||
{
|
||||
$info['user'] = $this->adminInfo;
|
||||
$adminInfo = $this->adminInfo;
|
||||
if ($adminInfo === null || !is_array($adminInfo) || !isset($adminInfo['id'])) {
|
||||
$token = getCurrentInfo();
|
||||
if (!is_array($token) || empty($token['id'])) {
|
||||
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
|
||||
}
|
||||
$adminInfo = UserInfoCache::getUserInfo($token['id']);
|
||||
if (empty($adminInfo) || !isset($adminInfo['id'])) {
|
||||
$adminInfo = UserInfoCache::setUserInfo($token['id']);
|
||||
}
|
||||
if (empty($adminInfo) || !isset($adminInfo['id'])) {
|
||||
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
|
||||
}
|
||||
$this->adminInfo = $adminInfo;
|
||||
}
|
||||
|
||||
$info = [];
|
||||
$info['id'] = $this->adminInfo['id'];
|
||||
$info['username'] = $this->adminInfo['username'];
|
||||
$info['dashboard'] = $this->adminInfo['dashboard'];
|
||||
$info['avatar'] = $this->adminInfo['avatar'];
|
||||
$info['email'] = $this->adminInfo['email'];
|
||||
$info['phone'] = $this->adminInfo['phone'];
|
||||
$info['gender'] = $this->adminInfo['gender'];
|
||||
$info['signed'] = $this->adminInfo['signed'];
|
||||
$info['realname'] = $this->adminInfo['realname'];
|
||||
$info['department'] = $this->adminInfo['deptList'];
|
||||
if ($this->adminInfo['id'] === 1) {
|
||||
$info['id'] = $adminInfo['id'];
|
||||
$info['username'] = $adminInfo['username'] ?? '';
|
||||
$info['dashboard'] = $adminInfo['dashboard'] ?? '';
|
||||
$info['avatar'] = $adminInfo['avatar'] ?? '';
|
||||
$info['email'] = $adminInfo['email'] ?? '';
|
||||
$info['phone'] = $adminInfo['phone'] ?? '';
|
||||
$info['gender'] = $adminInfo['gender'] ?? '';
|
||||
$info['signed'] = $adminInfo['signed'] ?? '';
|
||||
$info['realname'] = $adminInfo['realname'] ?? '';
|
||||
$info['department'] = $adminInfo['deptList'] ?? [];
|
||||
if (isset($adminInfo['id']) && $adminInfo['id'] == 1) {
|
||||
$info['buttons'] = ['*'];
|
||||
$info['roles'] = ['super_admin'];
|
||||
} else {
|
||||
$info['buttons'] = UserAuthCache::getUserAuth($this->adminInfo['id']);
|
||||
$info['roles'] = Arr::getArrayColumn($this->adminInfo['roleList'], 'code');
|
||||
$info['buttons'] = UserAuthCache::getUserAuth($adminInfo['id']);
|
||||
$info['roles'] = Arr::getArrayColumn($adminInfo['roleList'] ?? [], 'code');
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
@@ -70,6 +85,9 @@ class SystemController extends BaseController
|
||||
*/
|
||||
public function menu(): Response
|
||||
{
|
||||
if (!$this->ensureAdminInfo()) {
|
||||
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
|
||||
}
|
||||
$data = UserMenuCache::getUserMenu($this->adminInfo['id']);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -39,30 +39,4 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
$this->logger->error($logs);
|
||||
}
|
||||
|
||||
public function render(Request $request, Throwable $exception): Response
|
||||
{
|
||||
$debug = config('app.debug', true);
|
||||
$code = $exception->getCode();
|
||||
$json = [
|
||||
'code' => $code ? $code : 500,
|
||||
'message' => $code !== 500 ? $exception->getMessage() : 'Server internal error',
|
||||
'type' => 'failed'
|
||||
];
|
||||
if ($debug) {
|
||||
$json['request_url'] = $request->method() . ' ' . $request->uri();
|
||||
$json['timestamp'] = date('Y-m-d H:i:s');
|
||||
$json['client_ip'] = $request->getRealIp();
|
||||
$json['request_param'] = $request->all();
|
||||
$json['exception_handle'] = get_class($exception);
|
||||
$json['exception_info'] = [
|
||||
'code' => $exception->getCode(),
|
||||
'message' => $exception->getMessage(),
|
||||
'file' => $exception->getFile(),
|
||||
'line' => $exception->getLine(),
|
||||
'trace' => explode("\n", $exception->getTraceAsString())
|
||||
];
|
||||
}
|
||||
return new Response(200, ['Content-Type' => 'application/json;charset=utf-8'], json_encode($json));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,10 @@ class SystemDeptLogic extends BaseLogic
|
||||
public function accessDept(array $where = []): array
|
||||
{
|
||||
$query = $this->search($where);
|
||||
$query->auth($this->adminInfo['deptList']);
|
||||
// 超级管理员(id=1)可查看全部部门,普通管理员按部门权限过滤
|
||||
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
}
|
||||
$query->field('id, id as value, name as label, parent_id');
|
||||
$query->order('sort', 'desc');
|
||||
$data = $this->getAll($query);
|
||||
|
||||
@@ -40,7 +40,10 @@ class SystemUserLogic extends BaseLogic
|
||||
{
|
||||
$query = $this->search($where);
|
||||
$query->with(['depts']);
|
||||
$query->auth($this->adminInfo['deptList']);
|
||||
// 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤
|
||||
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
}
|
||||
return $this->getList($query);
|
||||
}
|
||||
|
||||
@@ -132,9 +135,11 @@ class SystemUserLogic extends BaseLogic
|
||||
return $this->transaction(function () use ($data, $id) {
|
||||
$role_ids = $data['role_ids'] ?? [];
|
||||
$post_ids = $data['post_ids'] ?? [];
|
||||
// 仅可修改当前部门和子部门的用户
|
||||
// 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户
|
||||
$query = $this->model->where('id', $id);
|
||||
$query->auth($this->adminInfo['deptList']);
|
||||
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
}
|
||||
$user = $query->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new ApiException('没有权限操作该数据');
|
||||
@@ -182,7 +187,10 @@ class SystemUserLogic extends BaseLogic
|
||||
throw new ApiException('超级管理员禁止删除');
|
||||
}
|
||||
$query = $this->model->where('id', $ids);
|
||||
$query->auth($this->adminInfo['deptList']);
|
||||
// 超级管理员可删除任意用户,普通管理员仅可删除当前部门和子部门的用户
|
||||
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
}
|
||||
$user = $query->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new ApiException('没有权限操作该数据');
|
||||
|
||||
@@ -32,8 +32,11 @@ class CheckLogin implements MiddlewareInterface
|
||||
if ($token['plat'] !== 'saiadmin') {
|
||||
throw new ApiException('登录凭证校验失败');
|
||||
}
|
||||
$request->setHeader('check_login', true);
|
||||
$request->setHeader('check_admin', $token);
|
||||
// 一次合并设置,避免 setHeader 覆盖导致只保留最后一个
|
||||
$request->setHeader(array_merge($request->header() ?: [], [
|
||||
'check_login' => true,
|
||||
'check_admin' => $token,
|
||||
]));
|
||||
}
|
||||
return $handler($request);
|
||||
}
|
||||
|
||||
@@ -42,11 +42,14 @@ class SystemDept extends BaseModel
|
||||
*/
|
||||
public function scopeAuth($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (!empty($value) && isset($value['id'])) {
|
||||
$deptIds = [$value['id']];
|
||||
$deptLevel = $value['level'] . $value['id'] . ',';
|
||||
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
|
||||
$deptIds = array_merge($deptIds, $ids);
|
||||
$level = $value['level'] ?? '';
|
||||
if ($level !== '' && $level !== null) {
|
||||
$deptLevel = $level . $value['id'] . ',';
|
||||
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
|
||||
$deptIds = array_merge($deptIds, $ids);
|
||||
}
|
||||
$query->whereIn('id', $deptIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* sa_system_user 用户表
|
||||
*
|
||||
* @property $id
|
||||
* @property $agent_id 代理标识,md5(id)唯一
|
||||
* @property $username 登录账号
|
||||
* @property $password 加密密码
|
||||
* @property $realname 真实姓名
|
||||
@@ -49,6 +50,30 @@ class SystemUser extends BaseModel
|
||||
*/
|
||||
protected $table = 'sa_system_user';
|
||||
|
||||
/**
|
||||
* 插入后:自动填充 agent_id = md5(id),保证唯一
|
||||
*/
|
||||
public static function onAfterInsert($model): void
|
||||
{
|
||||
$id = $model->getAttr('id');
|
||||
if ($id !== null && $id !== '') {
|
||||
$agentId = md5((string) $id);
|
||||
(new static())->where('id', $id)->update(['agent_id' => $agentId]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 agent_id:若未存储则返回 md5(id)
|
||||
*/
|
||||
public function getAgentIdAttr($value, $data)
|
||||
{
|
||||
if ($value !== null && $value !== '') {
|
||||
return $value;
|
||||
}
|
||||
$id = $data['id'] ?? null;
|
||||
return $id !== null ? md5((string) $id) : '';
|
||||
}
|
||||
|
||||
public function searchKeywordAttr($query, $value)
|
||||
{
|
||||
if ($value) {
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class AbstractLogic implements LogicInterface
|
||||
* 模型注入
|
||||
* @var object
|
||||
*/
|
||||
protected $model;
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* 管理员信息
|
||||
|
||||
@@ -45,19 +45,48 @@ class BaseController extends OpenController
|
||||
*/
|
||||
protected function init(): void
|
||||
{
|
||||
// 登录模式赋值
|
||||
$isLogin = request()->header('check_login', false);
|
||||
if ($isLogin) {
|
||||
$result = request()->header('check_admin');
|
||||
// 登录模式赋值:优先从中间件注入的 header 取,否则从 JWT 当前用户取
|
||||
$result = request()->header('check_admin');
|
||||
if (!is_array($result) || empty($result['id'])) {
|
||||
$result = getCurrentInfo();
|
||||
}
|
||||
if (is_array($result) && !empty($result['id'])) {
|
||||
$this->adminId = $result['id'];
|
||||
$this->adminName = $result['username'];
|
||||
$this->adminName = $result['username'] ?? '';
|
||||
$this->adminInfo = UserInfoCache::getUserInfo($result['id']);
|
||||
if (empty($this->adminInfo) || !isset($this->adminInfo['id'])) {
|
||||
$this->adminInfo = UserInfoCache::setUserInfo($result['id']);
|
||||
}
|
||||
|
||||
// 用户数据传递给逻辑层
|
||||
$this->logic && $this->logic->init($this->adminInfo);
|
||||
if ($this->logic && !empty($this->adminInfo)) {
|
||||
$this->logic->init($this->adminInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保当前请求已加载管理员信息(用于 init 未正确注入时的回退)
|
||||
* @return bool 是否已有有效的 adminInfo
|
||||
*/
|
||||
protected function ensureAdminInfo(): bool
|
||||
{
|
||||
if ($this->adminInfo !== null && is_array($this->adminInfo) && isset($this->adminInfo['id'])) {
|
||||
return true;
|
||||
}
|
||||
$token = getCurrentInfo();
|
||||
if (!is_array($token) || empty($token['id'])) {
|
||||
return false;
|
||||
}
|
||||
$this->adminId = $token['id'];
|
||||
$this->adminName = $token['username'] ?? '';
|
||||
$this->adminInfo = UserInfoCache::getUserInfo($token['id']);
|
||||
if (empty($this->adminInfo) || !isset($this->adminInfo['id'])) {
|
||||
$this->adminInfo = UserInfoCache::setUserInfo($token['id']);
|
||||
}
|
||||
return is_array($this->adminInfo) && isset($this->adminInfo['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证器调用
|
||||
*/
|
||||
|
||||
@@ -35,6 +35,12 @@ class BaseModel extends Model implements ModelInterface
|
||||
*/
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
/**
|
||||
* 自动写入时间戳(创建时写 create_time,更新时写 update_time)
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
/**
|
||||
* 隐藏字段
|
||||
* @var array
|
||||
@@ -94,24 +100,54 @@ class BaseModel extends Model implements ModelInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增前事件
|
||||
* 新增前事件:自动写入 create_time,有后台登录信息时写入 created_by
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeInsert($model): void
|
||||
{
|
||||
$info = getCurrentInfo();
|
||||
$info && $model->setAttr('created_by', $info['id']);
|
||||
try {
|
||||
$createTime = $model->createTime ?? 'create_time';
|
||||
if ($createTime && !$model->getData($createTime)) {
|
||||
$model->set($createTime, date('Y-m-d H:i:s'));
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
try {
|
||||
if (function_exists('getCurrentInfo')) {
|
||||
$info = getCurrentInfo();
|
||||
if (!empty($info['id'])) {
|
||||
$model->setAttr('created_by', $info['id']);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入前事件
|
||||
* 写入前事件:更新时自动写入 update_time,有后台登录信息时写入 updated_by
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public static function onBeforeWrite($model): void
|
||||
{
|
||||
$info = getCurrentInfo();
|
||||
$info && $model->setAttr('updated_by', $info['id']);
|
||||
try {
|
||||
if ($model->isExists()) {
|
||||
$updateTime = $model->updateTime ?? 'update_time';
|
||||
if ($updateTime) {
|
||||
$model->set($updateTime, date('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
try {
|
||||
if (function_exists('getCurrentInfo')) {
|
||||
$info = getCurrentInfo();
|
||||
if (!empty($info['id'])) {
|
||||
$model->setAttr('updated_by', $info['id']);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ use plugin\saiadmin\app\middleware\SystemLog;
|
||||
use plugin\saiadmin\app\middleware\CheckLogin;
|
||||
use plugin\saiadmin\app\middleware\CheckAuth;
|
||||
|
||||
// 仅对 /core 后台路由生效,避免 /api 请求经过登录/权限/操作日志中间件,提升接口响应
|
||||
return [
|
||||
'' => [
|
||||
'core' => [
|
||||
CheckLogin::class,
|
||||
CheckAuth::class,
|
||||
SystemLog::class,
|
||||
|
||||
@@ -17,6 +17,12 @@ Route::group('/core', function () {
|
||||
Route::get('/system/statistics', [plugin\saiadmin\app\controller\SystemController::class, 'statistics']);
|
||||
Route::get('/system/loginChart', [plugin\saiadmin\app\controller\SystemController::class, 'loginChart']);
|
||||
Route::get('/system/loginBarChart', [plugin\saiadmin\app\controller\SystemController::class, 'loginBarChart']);
|
||||
// 大富翁工作台统计(覆盖默认统计)
|
||||
Route::get('/dice/dashboard/statistics', [\app\dice\controller\DiceDashboardController::class, 'statistics']);
|
||||
Route::get('/dice/dashboard/rechargeChart', [\app\dice\controller\DiceDashboardController::class, 'rechargeChart']);
|
||||
Route::get('/dice/dashboard/rechargeBarChart', [\app\dice\controller\DiceDashboardController::class, 'rechargeBarChart']);
|
||||
Route::get('/dice/dashboard/walletRecordList', [\app\dice\controller\DiceDashboardController::class, 'walletRecordList']);
|
||||
Route::get('/dice/dashboard/newPlayerList', [\app\dice\controller\DiceDashboardController::class, 'newPlayerList']);
|
||||
Route::get('/system/clearAllCache', [plugin\saiadmin\app\controller\SystemController::class, 'clearAllCache']);
|
||||
|
||||
Route::get("/system/getResourceCategory", [plugin\saiadmin\app\controller\SystemController::class, 'getResourceCategory']);
|
||||
@@ -82,6 +88,46 @@ Route::group('/core', function () {
|
||||
Route::get("/server/cache", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'cache']);
|
||||
Route::post("/server/clear", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'clear']);
|
||||
|
||||
// 大富翁 Dice 模块
|
||||
fastRoute('dice/config/DiceConfig', \app\dice\controller\config\DiceConfigController::class);
|
||||
fastRoute('dice/player/DicePlayer', \app\dice\controller\player\DicePlayerController::class);
|
||||
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
|
||||
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
|
||||
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
|
||||
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class);
|
||||
Route::get('/dice/play_record/DicePlayRecord/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
|
||||
Route::get('/dice/play_record/DicePlayRecord/getLotteryConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getLotteryConfigOptions']);
|
||||
Route::get('/dice/play_record/DicePlayRecord/getRewardConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getRewardConfigOptions']);
|
||||
fastRoute('dice/player_wallet_record/DicePlayerWalletRecord', \app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class);
|
||||
Route::get('/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions', [\app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class, 'getPlayerOptions']);
|
||||
Route::get('/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore', [\app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class, 'getPlayerWalletBefore']);
|
||||
Route::post('/dice/player_wallet_record/DicePlayerWalletRecord/adminOperate', [\app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class, 'adminOperate']);
|
||||
fastRoute('dice/player_ticket_record/DicePlayerTicketRecord', \app\dice\controller\player_ticket_record\DicePlayerTicketRecordController::class);
|
||||
Route::get('/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions', [\app\dice\controller\player_ticket_record\DicePlayerTicketRecordController::class, 'getPlayerOptions']);
|
||||
fastRoute('dice/reward/DiceReward', \app\dice\controller\reward\DiceRewardController::class);
|
||||
Route::get('/dice/reward/DiceReward/weightRatioList', [\app\dice\controller\reward\DiceRewardController::class, 'weightRatioList']);
|
||||
Route::get('/dice/reward/DiceReward/weightRatioListWithDirection', [\app\dice\controller\reward\DiceRewardController::class, 'weightRatioListWithDirection']);
|
||||
Route::post('/dice/reward/DiceReward/batchUpdateWeights', [\app\dice\controller\reward\DiceRewardController::class, 'batchUpdateWeights']);
|
||||
Route::post('/dice/reward/DiceReward/batchUpdateWeightsByDirection', [\app\dice\controller\reward\DiceRewardController::class, 'batchUpdateWeightsByDirection']);
|
||||
Route::post('/dice/reward/DiceReward/startWeightTest', [\app\dice\controller\reward\DiceRewardController::class, 'startWeightTest']);
|
||||
Route::get('/dice/reward/DiceReward/getTestProgress', [\app\dice\controller\reward\DiceRewardController::class, 'getTestProgress']);
|
||||
fastRoute('dice/reward_config/DiceRewardConfig', \app\dice\controller\reward_config\DiceRewardConfigController::class);
|
||||
Route::get('/dice/reward_config/DiceRewardConfig/weightRatioList', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'weightRatioList']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdateWeights', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdateWeights']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'saveBigwinWeightsByGrid']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdate', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdate']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/createRewardReference', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'createRewardReference']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
|
||||
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class);
|
||||
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getOptions']);
|
||||
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getCurrentPool']);
|
||||
Route::post('/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'updateCurrentPool']);
|
||||
Route::post('/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'resetProfitAmount']);
|
||||
fastRoute('dice/reward_config_record/DiceRewardConfigRecord', \app\dice\controller\reward_config_record\DiceRewardConfigRecordController::class);
|
||||
Route::post('/dice/reward_config_record/DiceRewardConfigRecord/importFromRecord', [\app\dice\controller\reward_config_record\DiceRewardConfigRecordController::class, 'importFromRecord']);
|
||||
fastRoute('dice/play_record_test/DicePlayRecordTest', \app\dice\controller\play_record_test\DicePlayRecordTestController::class);
|
||||
Route::post('/dice/play_record_test/DicePlayRecordTest/clearAll', [\app\dice\controller\play_record_test\DicePlayRecordTestController::class, 'clearAll']);
|
||||
|
||||
// 数据表维护
|
||||
Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']);
|
||||
Route::get("/database/recycle", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'recycle']);
|
||||
|
||||
@@ -17,6 +17,11 @@ class ApiException extends BusinessException
|
||||
{
|
||||
public function render(Request $request): ?Response
|
||||
{
|
||||
return json(['code' => $this->getCode() ?: 500, 'message' => $this->getMessage()]);
|
||||
$message = $this->getMessage();
|
||||
$path = $request->path();
|
||||
if (str_contains($path, 'api/')) {
|
||||
$message = \app\api\util\ApiLang::translate($message, $request);
|
||||
}
|
||||
return json(['code' => $this->getCode() ?: 500, 'message' => $message]);
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ namespace support;
|
||||
*/
|
||||
class Request extends \Webman\Http\Request
|
||||
{
|
||||
/** 由 CheckUserTokenMiddleware 注入:当前用户 ID */
|
||||
public ?int $user_id = null;
|
||||
/** 由 TokenMiddleware 注入:当前玩家 ID(DicePlayer.id) */
|
||||
public ?int $player_id = null;
|
||||
|
||||
/** 由 CheckUserTokenMiddleware 注入:当前 user-token 原始字符串 */
|
||||
public ?string $userToken = null;
|
||||
/** 由 TokenMiddleware 注入:当前玩家模型实例 */
|
||||
public $player = null;
|
||||
|
||||
/**
|
||||
* 获取参数增强方法
|
||||
|
||||
Reference in New Issue
Block a user