Compare commits

..

2 Commits

Author SHA1 Message Date
dd264b1e97 1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道
3.优化后台页面设置
2026-05-19 09:49:02 +08:00
085454fb78 1.优化工作台页面/dashboard/console
2.移除岗位管理相关代码和数据库
2026-05-18 11:41:34 +08:00
160 changed files with 4933 additions and 2368 deletions

View File

@@ -1,32 +1,36 @@
import request from '@/utils/http' import request from '@/utils/http'
export type DashboardQueryParams = {
dept_id?: number
}
/** /**
* 大富翁工作台卡片统计(玩家注册、充值、提现、游玩次数,含较上周对比) * 大富翁工作台卡片统计(玩家注册、充值、提现、游玩次数,含较上周对比)
* @returns 响应
*/ */
export function fetchStatistics() { export function fetchStatistics(params?: DashboardQueryParams) {
return request.get<any>({ return request.get<any>({
url: '/core/dice/dashboard/statistics' url: '/core/dice/dashboard/statistics',
params
}) })
} }
/** /**
* 近期玩家充值统计近10天每日充值金额 * 近期玩家充值统计近10天每日充值金额
* @returns 响应
*/ */
export function fetchRechargeChart() { export function fetchRechargeChart(params?: DashboardQueryParams) {
return request.get<any>({ return request.get<any>({
url: '/core/dice/dashboard/rechargeChart' url: '/core/dice/dashboard/rechargeChart',
params
}) })
} }
/** /**
* 月度玩家充值汇总当年1-12月每月充值金额 * 月度玩家充值汇总当年1-12月每月充值金额
* @returns 响应
*/ */
export function fetchRechargeBarChart() { export function fetchRechargeBarChart(params?: DashboardQueryParams) {
return request.get<any>({ return request.get<any>({
url: '/core/dice/dashboard/rechargeBarChart' url: '/core/dice/dashboard/rechargeBarChart',
params
}) })
} }
@@ -39,11 +43,11 @@ export interface WalletRecordItem {
/** /**
* 工作台-玩家充值记录最新50条 * 工作台-玩家充值记录最新50条
* @returns 列表
*/ */
export function fetchWalletRecordList() { export function fetchWalletRecordList(params?: DashboardQueryParams) {
return request.get<WalletRecordItem[]>({ return request.get<WalletRecordItem[]>({
url: '/core/dice/dashboard/walletRecordList' url: '/core/dice/dashboard/walletRecordList',
params
}) })
} }
@@ -52,15 +56,34 @@ export interface NewPlayerItem {
name: string name: string
coin: number coin: number
total_ticket_count: number total_ticket_count: number
create_time: string
}
/** 玩家游玩记录项 */
export interface PlayRecordItem {
player_name: string
reward_tier: string
reward_tier_label: string
win_coin: number
create_time: string
} }
/** /**
* 工作台-新增玩家记录最新50条 * 工作台-新增玩家记录最新50条
* @returns 列表
*/ */
export function fetchNewPlayerList() { export function fetchNewPlayerList(params?: DashboardQueryParams) {
return request.get<NewPlayerItem[]>({ return request.get<NewPlayerItem[]>({
url: '/core/dice/dashboard/newPlayerList' url: '/core/dice/dashboard/newPlayerList',
params
}) })
} }
/**
* 工作台-玩家游玩记录最新50条
*/
export function fetchPlayRecordList(params?: DashboardQueryParams) {
return request.get<PlayRecordItem[]>({
url: '/core/dice/dashboard/playRecordList',
params
})
}

View File

@@ -71,5 +71,19 @@ export default {
return request.get<Api.Common.ApiData[]>({ return request.get<Api.Common.ApiData[]>({
url: '/core/dept/accessDept' url: '/core/dept/accessDept'
}) })
},
destroyPreview(ids: string | number | Array<string | number>) {
const idStr = Array.isArray(ids) ? ids.join(',') : String(ids)
return request.get<Api.Common.ApiData>({
url: '/core/dept/destroyPreview',
params: { ids: idStr }
})
},
syncChannelConfigs() {
return request.post<any>({
url: '/core/dept/syncChannelConfigs'
})
} }
} }

View File

@@ -1,75 +0,0 @@
import request from '@/utils/http'
/**
* 岗位API
*/
export default {
/**
* 获取数据列表
* @param params 搜索参数
* @returns 数据列表
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/core/post/index',
params
})
},
/**
* 读取数据
* @param id 数据ID
* @returns 数据详情
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/core/post/read?id=' + id
})
},
/**
* 创建数据
* @param params 数据参数
* @returns 执行结果
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/core/post/save',
data: params
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/core/post/update',
data: params
})
},
/**
* 删除数据
* @param id 数据ID
* @returns 执行结果
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/core/post/destroy',
data: params
})
},
/**
* 可操作岗位
* @returns 数据列表
*/
accessPost() {
return request.get<Api.Common.ApiData[]>({
url: '/core/post/accessPost'
})
}
}

View File

@@ -79,9 +79,10 @@ export default {
* 可操作角色 * 可操作角色
* @returns 数据列表 * @returns 数据列表
*/ */
accessRole() { accessRole(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData[]>({ return request.get<Api.Common.ApiData[]>({
url: '/core/role/accessRole' url: '/core/role/accessRole',
params
}) })
}, },

View File

@@ -0,0 +1,138 @@
<template>
<div v-if="props.enabled" class="art-full-height super-admin-channel-shell">
<div class="box-border flex gap-3 h-full max-md:block max-md:gap-0 max-md:h-auto">
<div class="channel-list-panel flex-shrink-0 h-full max-md:w-full max-md:h-auto max-md:mb-5">
<ElCard
class="channel-tree-card tree-card art-card-xs flex flex-col h-full mt-0"
shadow="never"
v-loading="loadingChannels"
>
<template #header>
<b class="channel-list-title">{{ $t('common.channelScope.listTitle') }}</b>
</template>
<ElScrollbar>
<ElTree
:data="displayTreeData"
:props="{ children: 'children', label: 'label' }"
node-key="id"
:current-node-key="selectedDeptId"
default-expand-all
highlight-current
@node-click="onNodeClick"
/>
</ElScrollbar>
</ElCard>
</div>
<div class="flex flex-col flex-grow min-w-0 min-h-0">
<div v-if="selectedDeptLabel" class="channel-banner mb-3 text-sm text-g-500">
{{ bannerLabel }}<b>{{ selectedDeptLabel }}</b>
</div>
<div class="flex flex-col flex-1 min-h-0 min-w-0">
<slot />
</div>
</div>
</div>
</div>
<slot v-else />
</template>
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { isRoleChannelRoute } from '@/utils/channelLayout'
import {
DEFAULT_CHANNEL_ID,
useChannelDeptScope,
type ChannelTreeNode
} from '@/composables/useChannelDeptScope'
const route = useRoute()
defineOptions({ name: 'SuperAdminChannelShell' })
const props = withDefaults(
defineProps<{
enabled?: boolean
}>(),
{
enabled: true
}
)
const { t } = useI18n()
const {
treeData,
selectedDeptId,
loadingChannels,
selectedDeptLabel,
handleChannelClick,
provideScope,
isConfigScope,
showDefaultTemplate
} = useChannelDeptScope()
provideScope()
const displayTreeData = computed(() => {
const nodes = showDefaultTemplate.value
? treeData.value
: treeData.value.filter((n) => n.id !== DEFAULT_CHANNEL_ID)
const defaultLabel = isRoleChannelRoute(route)
? t('common.channelScope.defaultRoleTemplate')
: t('common.channelScope.defaultTemplate')
return nodes.map((node) =>
node.id === DEFAULT_CHANNEL_ID && !node.label ? { ...node, label: defaultLabel } : node
)
})
const bannerLabel = computed(() => {
if (isConfigScope.value) {
return t('common.channelScope.currentConfig')
}
if (isRoleChannelRoute(route)) {
return t('common.channelScope.currentRole')
}
return t('common.channelScope.currentChannel')
})
const onNodeClick = (data: ChannelTreeNode) => {
handleChannelClick(data)
}
</script>
<style scoped>
.super-admin-channel-shell {
min-height: 0;
}
/* 原 w-64(16rem) 的 0.6 倍 */
.channel-list-panel {
width: 9.6rem;
}
.channel-tree-card :deep(.el-card__header) {
padding: 10px 12px;
}
.channel-list-title {
font-size: 13px;
}
.channel-tree-card :deep(.el-tree-node__content) {
height: 30px;
padding-right: 4px;
}
.channel-tree-card :deep(.el-tree-node__label) {
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.channel-banner b {
color: var(--el-color-primary);
}
</style>

View File

@@ -18,22 +18,34 @@
<!-- 缓存路由动画 --> <!-- 缓存路由动画 -->
<Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear> <Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
<KeepAlive :max="10" :exclude="keepAliveExclude"> <KeepAlive :max="10" :exclude="keepAliveExclude">
<SuperAdminChannelShell
v-if="route.meta.keepAlive && shouldWrapChannelLayout(route)"
:key="'ch-' + route.path"
>
<component class="art-page-view" :is="Component" :key="route.path" />
</SuperAdminChannelShell>
<component <component
v-else-if="route.meta.keepAlive"
class="art-page-view" class="art-page-view"
:is="Component" :is="Component"
:key="route.path" :key="route.path"
v-if="route.meta.keepAlive"
/> />
</KeepAlive> </KeepAlive>
</Transition> </Transition>
<!-- 非缓存路由动画 --> <!-- 非缓存路由动画 -->
<Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear> <Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
<SuperAdminChannelShell
v-if="!route.meta.keepAlive && shouldWrapChannelLayout(route)"
:key="'ch-' + route.path"
>
<component class="art-page-view" :is="Component" :key="route.path" />
</SuperAdminChannelShell>
<component <component
v-else-if="!route.meta.keepAlive"
class="art-page-view" class="art-page-view"
:is="Component" :is="Component"
:key="route.path" :key="route.path"
v-if="!route.meta.keepAlive"
/> />
</Transition> </Transition>
</RouterView> </RouterView>
@@ -53,6 +65,8 @@
import { useAutoLayoutHeight } from '@/hooks/core/useLayoutHeight' import { useAutoLayoutHeight } from '@/hooks/core/useLayoutHeight'
import { useSettingStore } from '@/store/modules/setting' import { useSettingStore } from '@/store/modules/setting'
import { useWorktabStore } from '@/store/modules/worktab' import { useWorktabStore } from '@/store/modules/worktab'
import SuperAdminChannelShell from '@/components/channel/SuperAdminChannelShell.vue'
import { shouldWrapSuperAdminChannelLayout as shouldWrapChannelLayout } from '@/utils/channelLayout'
defineOptions({ name: 'ArtPageContent' }) defineOptions({ name: 'ArtPageContent' })

View File

@@ -0,0 +1,12 @@
<!-- 兼容旧引用超管渠道栏已提升至全局 SuperAdminChannelShell -->
<template>
<slot :dept-id="deptId" :dept-params="deptParams" />
</template>
<script setup lang="ts">
import { useInjectedChannelDept, DEFAULT_CHANNEL_ID } from '@/composables/useChannelDeptScope'
const channel = useInjectedChannelDept()
const deptId = computed(() => channel?.selectedDeptId.value ?? DEFAULT_CHANNEL_ID)
const deptParams = computed(() => ({ dept_id: deptId.value }))
</script>

View File

@@ -0,0 +1,6 @@
/** @deprecated 请使用 useChannelDeptScope */
export {
DEFAULT_CHANNEL_ID,
useChannelDeptScope as useChannelConfigScope,
type ChannelTreeNode
} from './useChannelDeptScope'

View File

@@ -0,0 +1,230 @@
import type { InjectionKey, Ref, ComputedRef } from 'vue'
import { useRoute } from 'vue-router'
import deptApi from '@/api/system/dept'
import { useUserStore } from '@/store/modules/user'
import { isConfigChannelRoute, isRoleChannelRoute, isSuperAdminUser } from '@/utils/channelLayout'
export interface ChannelTreeNode {
id: number
label: string
children?: ChannelTreeNode[]
}
/** 默认配置模板dept_id = 0 */
export const DEFAULT_CHANNEL_ID = 0
export interface ChannelDeptScopeContext {
treeData: Ref<ChannelTreeNode[]>
selectedDeptId: Ref<number>
loadingChannels: Ref<boolean>
isSuperAdmin: Ref<boolean>
selectedDeptLabel: Ref<string>
deptQueryParams: ComputedRef<{ dept_id: number }>
isConfigScope: ComputedRef<boolean>
showDefaultTemplate: ComputedRef<boolean>
}
export const CHANNEL_DEPT_SCOPE_KEY: InjectionKey<ChannelDeptScopeContext> =
Symbol('channelDeptScope')
export function provideChannelDeptScope(ctx: ChannelDeptScopeContext) {
provide(CHANNEL_DEPT_SCOPE_KEY, ctx)
}
export function useInjectedChannelDept(): ChannelDeptScopeContext | null {
return inject(CHANNEL_DEPT_SCOPE_KEY, null)
}
/** 超管全局渠道栏:创建并 provide 渠道上下文 */
export function useChannelDeptScope() {
const route = useRoute()
const userStore = useUserStore()
const treeData = ref<ChannelTreeNode[]>([])
const selectedDeptId = ref<number>(DEFAULT_CHANNEL_ID)
const loadingChannels = ref(false)
const isConfigScope = computed(() => isConfigChannelRoute(route))
const isRoleScope = computed(() => isRoleChannelRoute(route))
const showDefaultTemplate = computed(() => isConfigScope.value || isRoleScope.value)
const isSuperAdmin = computed(() => isSuperAdminUser())
const selectedDeptLabel = computed(() => {
const find = (nodes: ChannelTreeNode[]): string => {
for (const n of nodes) {
if (n.id === selectedDeptId.value) {
return n.label
}
if (n.children?.length) {
const sub = find(n.children)
if (sub) return sub
}
}
return ''
}
return find(treeData.value)
})
const deptQueryParams = computed(() => {
const id = selectedDeptId.value
if (!showDefaultTemplate.value && id <= 0) {
return { dept_id: 0 }
}
return { dept_id: id }
})
const loadChannels = async () => {
loadingChannels.value = true
try {
const list = await deptApi.accessDept()
const channels = Array.isArray(list) ? list : []
const nodes: ChannelTreeNode[] = channels.map((item: Record<string, unknown>) => ({
id: Number(item.id ?? item.value),
label: String(item.label ?? item.name ?? item.id)
}))
if (isSuperAdmin.value) {
if (showDefaultTemplate.value) {
treeData.value = [{ id: DEFAULT_CHANNEL_ID, label: '' }, ...nodes]
if (!treeData.value.some((n) => n.id === selectedDeptId.value)) {
selectedDeptId.value = DEFAULT_CHANNEL_ID
}
} else {
treeData.value = nodes
if (nodes.length > 0) {
const valid = nodes.some((n) => n.id === selectedDeptId.value)
if (!valid || selectedDeptId.value <= 0) {
selectedDeptId.value = nodes[0].id
}
}
}
} else {
treeData.value = nodes
if (nodes.length > 0) {
selectedDeptId.value = nodes[0].id
}
}
} finally {
loadingChannels.value = false
}
}
const handleChannelClick = (data: ChannelTreeNode) => {
selectedDeptId.value = Number(data.id)
}
const ctx: ChannelDeptScopeContext = {
treeData,
selectedDeptId,
loadingChannels,
isSuperAdmin,
selectedDeptLabel,
deptQueryParams,
isConfigScope,
showDefaultTemplate
}
onMounted(() => {
loadChannels()
})
return {
...ctx,
loadChannels,
handleChannelClick,
provideScope: () => provideChannelDeptScope(ctx)
}
}
/** 将当前选中渠道写入列表查询参数并刷新 */
export function bindChannelDeptToSearchParams(
searchParams: Record<string, unknown>,
refresh: () => void,
options?: { immediate?: boolean; enabled?: boolean }
) {
const channel = useInjectedChannelDept()
if (!channel || options?.enabled === false) {
return
}
const apply = (deptId: number) => {
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
searchParams.dept_id = deptId
refresh()
}
watch(
() => channel.selectedDeptId.value,
(deptId) => apply(deptId),
{ immediate: options?.immediate ?? true }
)
}
/** 工作台等非 useTable 页面:渠道切换时重新拉数 */
export function useChannelDeptReload(loadFn: () => void | Promise<void>) {
const channel = useInjectedChannelDept()
if (!channel) {
onMounted(() => {
void loadFn()
})
return
}
watch(
() => channel.selectedDeptId.value,
(deptId) => {
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
void loadFn()
},
{ immediate: true }
)
}
/** 请求参数:业务页附带 dept_id渠道管理员固定本渠道 */
export function getChannelDeptRequestParams(): { dept_id?: number } {
const channel = useInjectedChannelDept()
if (channel?.isSuperAdmin.value) {
const deptId = channel.selectedDeptId.value
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return {}
}
if (deptId > 0) {
return { dept_id: deptId }
}
if (channel.showDefaultTemplate.value) {
return { dept_id: deptId }
}
return {}
}
const userStore = useUserStore()
const dept = userStore.info?.department
if (dept && Number(dept.id) > 0) {
return { dept_id: Number(dept.id) }
}
return {}
}
/** 保存/更新时附带 dept_id优先渠道栏选中值其次表单/行数据中的 dept_id */
export function withChannelDeptParams<T extends Record<string, unknown>>(payload: T): T {
const extra = getChannelDeptRequestParams()
if ('dept_id' in extra) {
return { ...payload, ...extra }
}
const rowDeptId = payload.dept_id
if (rowDeptId !== undefined && rowDeptId !== null && rowDeptId !== '') {
const num = Number(rowDeptId)
if (num > 0) {
return { ...payload, dept_id: num }
}
}
const channel = useInjectedChannelDept()
if (channel && channel.selectedDeptId.value > 0) {
return { ...payload, dept_id: channel.selectedDeptId.value }
}
return payload
}

View File

@@ -35,6 +35,7 @@ import {
createErrorHandler createErrorHandler
} from '../../utils/table/tableUtils' } from '../../utils/table/tableUtils'
import { tableConfig } from '../../utils/table/tableConfig' import { tableConfig } from '../../utils/table/tableConfig'
import { bindChannelDeptToSearchParams, useInjectedChannelDept, getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
// 类型推导工具类型 // 类型推导工具类型
type InferApiParams<T> = T extends (params: infer P) => any ? P : never type InferApiParams<T> = T extends (params: infer P) => any ? P : never
@@ -441,6 +442,23 @@ function useTableImpl<TApiFn extends (params: any) => Promise<any>>(
// 智能防抖搜索函数 // 智能防抖搜索函数
const debouncedGetDataByPage = createSmartDebounce(getDataByPage, debounceTime) const debouncedGetDataByPage = createSmartDebounce(getDataByPage, debounceTime)
const channelScope = useInjectedChannelDept()
const hasChannelScope = !!channelScope
bindChannelDeptToSearchParams(
searchParams as Record<string, unknown>,
() => {
void getDataByPage()
},
{ immediate: hasChannelScope }
)
if (!hasChannelScope) {
const channelDeptParams = getChannelDeptRequestParams()
if (channelDeptParams.dept_id !== undefined) {
Object.assign(searchParams as Record<string, unknown>, channelDeptParams)
}
}
// 重置搜索参数 // 重置搜索参数
const resetSearchParams = async (): Promise<void> => { const resetSearchParams = async (): Promise<void> => {
// 取消防抖的搜索 // 取消防抖的搜索
@@ -645,7 +663,7 @@ function useTableImpl<TApiFn extends (params: any) => Promise<any>>(
} }
// 挂载时自动加载数据 // 挂载时自动加载数据
if (immediate) { if (immediate && !hasChannelScope) {
onMounted(async () => { onMounted(async () => {
await getData() await getData()
}) })

View File

@@ -37,7 +37,15 @@
"tips": "Prompt", "tips": "Prompt",
"cancel": "Cancel", "cancel": "Cancel",
"confirm": "Confirm", "confirm": "Confirm",
"logOutTips": "Do you want to log out?" "logOutTips": "Do you want to log out?",
"channelScope": {
"listTitle": "Channels",
"defaultTemplate": "Default template",
"defaultRoleTemplate": "Default role template",
"currentConfig": "Current config",
"currentChannel": "Current channel",
"currentRole": "Current roles"
}
}, },
"uiMsg": { "uiMsg": {
"titlePrompt": "Prompt", "titlePrompt": "Prompt",
@@ -303,7 +311,16 @@
"subtitle": "Latest 50 new player records", "subtitle": "Latest 50 new player records",
"player": "Player", "player": "Player",
"balance": "Balance", "balance": "Balance",
"ticket": "Tickets" "ticket": "Tickets",
"registerTime": "Register Time"
},
"playRecord": {
"title": "Player Play Records",
"subtitle": "Latest 50 play records",
"player": "Player",
"reward": "Reward Tier",
"winCoin": "Win Amount",
"playTime": "Play Time"
}, },
"walletRecord": { "walletRecord": {
"title": "Player Charge Records", "title": "Player Charge Records",
@@ -378,8 +395,7 @@
"role": "Role Management", "role": "Role Management",
"userCenter": "User Center", "userCenter": "User Center",
"menu": "Menu Management", "menu": "Menu Management",
"dept": "Department Management", "dept": "Channel Management",
"post": "Post Management",
"config": "System Config" "config": "System Config"
}, },
"safeguard": { "safeguard": {
@@ -445,8 +461,6 @@
"placeholderDeptCode": "Dept Code", "placeholderDeptCode": "Dept Code",
"placeholderRoleName": "Role Name", "placeholderRoleName": "Role Name",
"placeholderRoleCode": "Role Code", "placeholderRoleCode": "Role Code",
"placeholderPostName": "Post Name",
"placeholderPostCode": "Post Code",
"placeholderMenuName": "Menu Name", "placeholderMenuName": "Menu Name",
"placeholderMenuRoute": "Menu Route", "placeholderMenuRoute": "Menu Route",
"placeholderOperator": "Operator", "placeholderOperator": "Operator",
@@ -510,14 +524,12 @@
"system": { "system": {
"username": "Username", "username": "Username",
"phone": "Phone", "phone": "Phone",
"dept": "Department", "dept": "Channel",
"dashboard": "Dashboard", "dashboard": "Dashboard",
"loginTime": "Last Login", "loginTime": "Last Login",
"agentId": "Agent ID", "agentId": "Agent ID",
"postName": "Post Name", "deptName": "Channel Name",
"postCode": "Post Code", "deptCode": "Channel Code",
"deptName": "Dept Name",
"deptCode": "Dept Code",
"leader": "Leader", "leader": "Leader",
"roleName": "Role Name", "roleName": "Role Name",
"roleCode": "Role Code", "roleCode": "Role Code",

View File

@@ -0,0 +1,45 @@
{
"form": {
"dialogTitleAdd": "Add Game",
"dialogTitleEdit": "Edit Game",
"provider": "Provider",
"placeholderProvider": "Enter provider name",
"providerCode": "Provider Code",
"placeholderProviderCode": "Enter provider code",
"gameCode": "Game Code",
"placeholderGameCode": "Enter game code",
"gameKey": "Game Key",
"placeholderGameKey": "Enter unique game key",
"gameName": "Name (ZH)",
"placeholderGameName": "Enter Chinese name",
"gameNameEn": "Name (EN)",
"placeholderGameNameEn": "Enter English name",
"gameType": "Game Type",
"placeholderGameType": "Enter game type",
"sort": "Sort",
"logo": "Logo URL",
"tabPicker": "Pick Image",
"tabUpload": "Upload Image",
"gameUrl": "Game URL",
"placeholderGameUrl": "Enter game URL",
"hallUrl": "Hall URL",
"placeholderHallUrl": "Enter hall URL",
"status": "Status",
"statusEnabled": "Enabled",
"statusDisabled": "Disabled",
"remark": "Remark",
"placeholderRemark": "Enter remark",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully",
"ruleProviderRequired": "Provider is required",
"ruleProviderCodeRequired": "Provider code is required",
"ruleGameCodeRequired": "Game code is required",
"ruleGameKeyRequired": "Game key is required",
"ruleGameNameRequired": "Chinese name is required",
"ruleGameTypeRequired": "Game type is required"
},
"table": {
"statusEnabled": "Enabled",
"statusDisabled": "Disabled"
}
}

View File

@@ -26,6 +26,7 @@
"profitCalcHint": "Profit per round: paid = win_coin (incl. BIGWIN) - paid_amount (= ante×1); free = win_coin. Refreshes every 2s while open.", "profitCalcHint": "Profit per round: paid = win_coin (incl. BIGWIN) - paid_amount (= ante×1); free = win_coin. Refreshes every 2s while open.",
"tierRuleTitle": "Tier Rule", "tierRuleTitle": "Tier Rule",
"tierRuleContent": "When player profit in this pool is below safety line, use player T*_weight; when above or equal, use pool T*_weight (kill).", "tierRuleContent": "When player profit in this pool is below safety line, use player T*_weight; when above or equal, use pool T*_weight (kill).",
"enableKillScore": "Enable kill score",
"killScoreWeights": "Kill weights", "killScoreWeights": "Kill weights",
"killWeightNote": "(Kill weights from pool config type=1; edit in list.)", "killWeightNote": "(Kill weights from pool config type=1; edit in list.)",
"btnResetProfit": "Reset Player Total Profit", "btnResetProfit": "Reset Player Total Profit",

View File

@@ -34,7 +34,15 @@
"placeholderRewardTier": "Select reward tier", "placeholderRewardTier": "Select reward tier",
"addSuccess": "Added successfully", "addSuccess": "Added successfully",
"editSuccess": "Updated successfully", "editSuccess": "Updated successfully",
"validateFailed": "Validation failed, please check required fields and format" "validateFailed": "Validation failed, please check required fields and format",
"rulePlayerRequired": "Please select player",
"ruleLotteryConfigRequired": "Please select lottery pool config",
"ruleLotteryTypeRequired": "Please select draw type",
"ruleIsWinRequired": "Please select big win status",
"ruleWinCoinRequired": "Win coin is required",
"ruleRollArrayLength": "Roll array must have 5 numbers",
"ruleRollArrayValues": "Enter 5 numbers, each between 1 and 6",
"ruleRewardTierRequired": "Please select reward tier"
}, },
"toolbar": { "toolbar": {
"platformTotalProfit": "Platform Total Profit" "platformTotalProfit": "Platform Total Profit"

View File

@@ -14,6 +14,8 @@
"status": "Status", "status": "Status",
"adminId": "Admin", "adminId": "Admin",
"placeholderAdmin": "Select admin (optional)", "placeholderAdmin": "Select admin (optional)",
"placeholderAdminTree": "Select admin by channel",
"unassignedChannel": "Unassigned channel",
"coin": "Coin", "coin": "Coin",
"placeholderCoinAdd": "Default 0 on create, read-only", "placeholderCoinAdd": "Default 0 on create, read-only",
"lotteryPoolConfig": "Lottery Pool Config", "lotteryPoolConfig": "Lottery Pool Config",
@@ -44,7 +46,18 @@
"ruleEnterCoin": "Please enter coin change", "ruleEnterCoin": "Please enter coin change",
"ruleCoinPositive": "Coin change must be greater than 0", "ruleCoinPositive": "Coin change must be greater than 0",
"ruleDeductExceed": "Deduct cannot exceed current balance", "ruleDeductExceed": "Deduct cannot exceed current balance",
"operateSuccess": "Success" "operateSuccess": "Success",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully",
"rulePasswordRequired": "Password is required",
"ruleUsernameRequired": "Username is required",
"ruleNicknameRequired": "Nickname is required",
"rulePhoneRequired": "Phone is required",
"ruleStatusRequired": "Status is required",
"ruleCoinRequired": "Coin is required",
"configTypeDefault": "Default",
"configTypeKillScore": "Kill score",
"configTypeUp": "Up score"
}, },
"search": { "search": {
"username": "Username", "username": "Username",

View File

@@ -14,7 +14,12 @@
"placeholderTotalDrawCount": "Auto sum", "placeholderTotalDrawCount": "Auto sum",
"placeholderRemark": "Remark (required)", "placeholderRemark": "Remark (required)",
"addSuccess": "Added successfully", "addSuccess": "Added successfully",
"editSuccess": "Updated successfully" "editSuccess": "Updated successfully",
"rulePlayerRequired": "Please select player",
"ruleUseCoinsRequired": "Coins used is required",
"rulePaidDrawRequired": "Paid draw count is required",
"ruleFreeDrawRequired": "Free draw count is required",
"ruleRemarkRequired": "Remark is required"
}, },
"search": { "search": {
"player": "Player", "player": "Player",

View File

@@ -1,4 +1,7 @@
{ {
"toolbar": {
"coinChangeSummary": "Coin Change Summary"
},
"form": { "form": {
"dialogTitleAdd": "Add Wallet Record", "dialogTitleAdd": "Add Wallet Record",
"dialogTitleEdit": "Edit Wallet Record", "dialogTitleEdit": "Edit Wallet Record",
@@ -19,7 +22,10 @@
"placeholderWalletAfter": "Auto calculated", "placeholderWalletAfter": "Auto calculated",
"placeholderRemark": "Optional", "placeholderRemark": "Optional",
"addSuccess": "Added successfully", "addSuccess": "Added successfully",
"editSuccess": "Updated successfully" "editSuccess": "Updated successfully",
"ruleUserRequired": "Please select user",
"ruleCoinRequired": "Coin change is required",
"ruleTypeRequired": "Please select type"
}, },
"search": { "search": {
"type": "Type", "type": "Type",

View File

@@ -69,6 +69,7 @@
"labelLotteryTypePaid": "Test pool type", "labelLotteryTypePaid": "Test pool type",
"labelLotteryTypeFree": "Test pool type", "labelLotteryTypeFree": "Test pool type",
"labelAnte": "Ante", "labelAnte": "Ante",
"placeholderAnte": "Select ante config",
"placeholderPaidPool": "Leave empty for custom tier odds below (default: default)", "placeholderPaidPool": "Leave empty for custom tier odds below (default: default)",
"placeholderFreePool": "Leave empty for custom tier odds below (default: killScore)", "placeholderFreePool": "Leave empty for custom tier odds below (default: killScore)",
"tierProbHint": "Custom tier odds (T1T5), each 0100%, sum of five must not exceed 100%", "tierProbHint": "Custom tier odds (T1T5), each 0100%, sum of five must not exceed 100%",
@@ -81,7 +82,7 @@
"btnNext": "Next", "btnNext": "Next",
"btnStart": "Start test", "btnStart": "Start test",
"btnCancel": "Cancel", "btnCancel": "Cancel",
"warnAnte": "Ante must be greater than 0", "warnAnte": "Please select ante",
"warnPaidSpins": "Paid clockwise + counter-clockwise spin counts must be greater than 0", "warnPaidSpins": "Paid clockwise + counter-clockwise spin counts must be greater than 0",
"warnTestSafetyLine": "Test safety line must be greater than or equal to 0", "warnTestSafetyLine": "Test safety line must be greater than or equal to 0",
"warnTotalSpins": "At least one of paid/free direction spin counts must be greater than 0", "warnTotalSpins": "At least one of paid/free direction spin counts must be greater than 0",

View File

@@ -1,38 +1,35 @@
{ {
"search": { "search": {
"deptName": "channel(Department) Name", "deptName": "Channel Name",
"deptCode": "Dept Code", "deptCode": "Channel Code",
"status": "Status", "status": "Status",
"placeholderDeptName": "Please enter dept name", "placeholderDeptName": "Please enter channel name",
"placeholderDeptCode": "Please enter dept code", "placeholderDeptCode": "Please enter channel code",
"searchSelectPlaceholder": "Please select" "searchSelectPlaceholder": "Please select"
}, },
"table": { "table": {
"deptName": "channel(Department) Name", "deptName": "Channel Name",
"deptCode": "Dept Code", "deptCode": "Channel Code",
"leader": "Leader", "leader": "Channel Leader",
"sort": "Sort", "sort": "Sort",
"status": "Status", "status": "Status",
"createTime": "Create Time" "createTime": "Create Time"
}, },
"form": { "form": {
"titleAdd": "Add Department", "titleAdd": "Add Channel",
"titleEdit": "Edit Department", "titleEdit": "Edit Channel",
"labelParentDept": "Parent Department", "labelDeptName": "Channel Name",
"labelDeptName": "Dept Name", "labelDeptCode": "Channel Code",
"labelDeptCode": "Dept Code", "labelLeader": "Channel Leader",
"labelLeader": "Leader",
"labelRemark": "Description", "labelRemark": "Description",
"labelSort": "Sort", "labelSort": "Sort",
"labelStatus": "Enabled", "labelStatus": "Enabled",
"placeholderDeptName": "Please enter dept name", "placeholderDeptName": "Please enter channel name",
"placeholderDeptCode": "Please enter dept code", "placeholderDeptCode": "Please enter channel code",
"placeholderRemark": "Please enter description", "placeholderRemark": "Please enter description",
"placeholderSort": "Please enter sort", "placeholderSort": "Please enter sort",
"noParentDept": "No parent department", "ruleDeptNameRequired": "Please enter channel name",
"ruleParentDeptRequired": "Please select parent department", "ruleDeptCodeRequired": "Please enter channel code",
"ruleDeptNameRequired": "Please enter dept name",
"ruleDeptCodeRequired": "Please enter dept code",
"addSuccess": "Added successfully", "addSuccess": "Added successfully",
"editSuccess": "Updated successfully" "editSuccess": "Updated successfully"
} }

View File

@@ -1,34 +0,0 @@
{
"search": {
"postName": "Post Name",
"postCode": "Post Code",
"status": "Status",
"placeholderPostName": "Please enter post name",
"placeholderPostCode": "Please enter post code",
"searchSelectPlaceholder": "Please select"
},
"table": {
"postName": "Post Name",
"postCode": "Post Code",
"sort": "Sort",
"status": "Status",
"createTime": "Create Time"
},
"form": {
"titleAdd": "Add Post",
"titleEdit": "Edit Post",
"labelName": "Post Name",
"labelCode": "Post Code",
"labelRemark": "Description",
"labelSort": "Sort",
"labelStatus": "Enabled",
"placeholderName": "Please enter post name",
"placeholderCode": "Please enter post code",
"placeholderRemark": "Please enter description",
"placeholderSort": "Please enter sort",
"ruleNameRequired": "Please enter post name",
"ruleCodeRequired": "Please enter post code",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
}
}

View File

@@ -10,7 +10,7 @@
"table": { "table": {
"username": "Username", "username": "Username",
"phone": "Phone", "phone": "Phone",
"dept": "Department", "dept": "Channel",
"dashboard": "Dashboard", "dashboard": "Dashboard",
"loginTime": "Last Login", "loginTime": "Last Login",
"agentId": "Agent ID", "agentId": "Agent ID",
@@ -28,9 +28,8 @@
"labelPasswordConfirm": "Confirm Password", "labelPasswordConfirm": "Confirm Password",
"labelEmail": "Email", "labelEmail": "Email",
"labelPhone": "Phone", "labelPhone": "Phone",
"labelDept": "Department", "labelDept": "Channel",
"labelRole": "Role", "labelRole": "Role",
"labelPost": "Post",
"labelGender": "Gender", "labelGender": "Gender",
"labelStatus": "Status", "labelStatus": "Status",
"labelRemark": "Remark", "labelRemark": "Remark",
@@ -43,12 +42,15 @@
"rulePasswordRequired": "Please enter password", "rulePasswordRequired": "Please enter password",
"rulePasswordLength": "Length must be between 6 and 20 characters", "rulePasswordLength": "Length must be between 6 and 20 characters",
"rulePasswordConfirmRequired": "Please enter confirm password", "rulePasswordConfirmRequired": "Please enter confirm password",
"ruleDeptRequired": "Please select department", "ruleDeptRequired": "Please select channel",
"ruleRoleRequired": "Please select role", "ruleRoleRequired": "Please select role",
"addSuccess": "Added successfully", "addSuccess": "Added successfully",
"editSuccess": "Updated successfully" "editSuccess": "Updated successfully"
}, },
"ui": { "ui": {
"channelList": "Channel List",
"viewingChannel": "Current channel",
"defaultConfigTemplate": "Default config template",
"promptNewPassword": "Please enter a new password", "promptNewPassword": "Please enter a new password",
"passwordLengthError": "Password length must be between 6 and 16", "passwordLengthError": "Password length must be between 6 and 16",
"passwordChanged": "Password updated", "passwordChanged": "Password updated",

View File

@@ -37,7 +37,15 @@
"tips": "提示", "tips": "提示",
"cancel": "取消", "cancel": "取消",
"confirm": "确定", "confirm": "确定",
"logOutTips": "您是否要退出登录?" "logOutTips": "您是否要退出登录?",
"channelScope": {
"listTitle": "渠道列表",
"defaultTemplate": "默认配置模板",
"defaultRoleTemplate": "默认角色模板",
"currentConfig": "当前配置",
"currentChannel": "当前渠道",
"currentRole": "当前角色范围"
}
}, },
"uiMsg": { "uiMsg": {
"titlePrompt": "提示", "titlePrompt": "提示",
@@ -303,7 +311,16 @@
"subtitle": "最新50条新增玩家记录", "subtitle": "最新50条新增玩家记录",
"player": "玩家", "player": "玩家",
"balance": "余额", "balance": "余额",
"ticket": "抽奖券" "ticket": "抽奖券",
"registerTime": "注册时间"
},
"playRecord": {
"title": "玩家游玩记录",
"subtitle": "最新50条游玩记录",
"player": "玩家",
"reward": "中奖档位",
"winCoin": "赢取平台币",
"playTime": "游玩时间"
}, },
"walletRecord": { "walletRecord": {
"title": "玩家充值记录", "title": "玩家充值记录",
@@ -374,8 +391,7 @@
"role": "角色管理", "role": "角色管理",
"userCenter": "个人中心", "userCenter": "个人中心",
"menu": "菜单管理", "menu": "菜单管理",
"dept": "渠道(部门)管理", "dept": "渠道管理",
"post": "岗位管理",
"config": "系统配置" "config": "系统配置"
}, },
"safeguard": { "safeguard": {
@@ -437,12 +453,10 @@
"placeholderTaskName": "请输入任务名称", "placeholderTaskName": "请输入任务名称",
"placeholderTableName": "请输入数据表名称", "placeholderTableName": "请输入数据表名称",
"placeholderDataSource": "请输入数据源名称", "placeholderDataSource": "请输入数据源名称",
"placeholderDeptName": "请输入部门名称", "placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入部门编码", "placeholderDeptCode": "请输入渠道编码",
"placeholderRoleName": "请输入角色名称", "placeholderRoleName": "请输入角色名称",
"placeholderRoleCode": "请输入角色编码", "placeholderRoleCode": "请输入角色编码",
"placeholderPostName": "请输入岗位名称",
"placeholderPostCode": "请输入岗位编码",
"placeholderMenuName": "请输入菜单名称", "placeholderMenuName": "请输入菜单名称",
"placeholderMenuRoute": "请输入菜单路由", "placeholderMenuRoute": "请输入菜单路由",
"placeholderOperator": "请输入操作用户", "placeholderOperator": "请输入操作用户",
@@ -506,15 +520,13 @@
"system": { "system": {
"username": "用户名", "username": "用户名",
"phone": "手机号", "phone": "手机号",
"dept": "部门", "dept": "渠道",
"dashboard": "首页", "dashboard": "首页",
"loginTime": "上次登录", "loginTime": "上次登录",
"agentId": "代理ID", "agentId": "代理ID",
"postName": "岗位名称", "deptName": "渠道名称",
"postCode": "岗位编码", "deptCode": "渠道编码",
"deptName": "部门名称", "leader": "渠道负责人",
"deptCode": "部门编码",
"leader": "部门领导",
"roleName": "角色名称", "roleName": "角色名称",
"roleCode": "角色编码", "roleCode": "角色编码",
"level": "角色级别", "level": "角色级别",
@@ -534,7 +546,7 @@
"titleEn": "标题(英文)", "titleEn": "标题(英文)",
"value": "值", "value": "值",
"valueEn": "值(英文)", "valueEn": "值(英文)",
"noParentDept": "无上级部门", "noParentDept": "无上级渠道",
"noParentMenu": "无上级菜单", "noParentMenu": "无上级菜单",
"input": "文本框", "input": "文本框",
"textarea": "文本域", "textarea": "文本域",

View File

@@ -0,0 +1,45 @@
{
"form": {
"dialogTitleAdd": "新增游戏",
"dialogTitleEdit": "编辑游戏",
"provider": "供应商",
"placeholderProvider": "请输入供应商名称",
"providerCode": "供应商编码",
"placeholderProviderCode": "请输入供应商编码",
"gameCode": "游戏编号",
"placeholderGameCode": "请输入游戏编号",
"gameKey": "游戏唯一值",
"placeholderGameKey": "请输入游戏唯一值",
"gameName": "中文名称",
"placeholderGameName": "请输入中文名称",
"gameNameEn": "英文名称",
"placeholderGameNameEn": "请输入英文名称",
"gameType": "游戏类型",
"placeholderGameType": "请输入游戏类型",
"sort": "排序",
"logo": "Logo地址",
"tabPicker": "图片选择",
"tabUpload": "图片上传",
"gameUrl": "游戏地址",
"placeholderGameUrl": "请输入游戏地址",
"hallUrl": "大厅地址",
"placeholderHallUrl": "请输入大厅地址",
"status": "状态",
"statusEnabled": "启用",
"statusDisabled": "禁用",
"remark": "备注",
"placeholderRemark": "请输入备注",
"addSuccess": "新增成功",
"editSuccess": "更新成功",
"ruleProviderRequired": "请输入供应商",
"ruleProviderCodeRequired": "请输入供应商编码",
"ruleGameCodeRequired": "请输入游戏编号",
"ruleGameKeyRequired": "请输入游戏唯一值",
"ruleGameNameRequired": "请输入中文名称",
"ruleGameTypeRequired": "请输入游戏类型"
},
"table": {
"statusEnabled": "启用",
"statusDisabled": "禁用"
}
}

View File

@@ -26,6 +26,7 @@
"profitCalcHint": "计算方式:付费每局按“赢取平台币 win_coin含 BIGWIN减去付费金额 压注金额paid_amount= 压注倍数ante×1”累加免费每局按“玩家赢得平台币win_coin”累加。弹窗打开期间每 2 秒自动刷新", "profitCalcHint": "计算方式:付费每局按“赢取平台币 win_coin含 BIGWIN减去付费金额 压注金额paid_amount= 压注倍数ante×1”累加免费每局按“玩家赢得平台币win_coin”累加。弹窗打开期间每 2 秒自动刷新",
"tierRuleTitle": "抽奖档位规则", "tierRuleTitle": "抽奖档位规则",
"tierRuleContent": "当玩家在当前彩金池的累计盈利 低于安全线 时,按 玩家 的 T*_weight 权重抽取档位;当累计盈利 高于或等于安全线 时,按 当前彩金池 的 T*_weight 权重抽取档位(杀分)。", "tierRuleContent": "当玩家在当前彩金池的累计盈利 低于安全线 时,按 玩家 的 T*_weight 权重抽取档位;当累计盈利 高于或等于安全线 时,按 当前彩金池 的 T*_weight 权重抽取档位(杀分)。",
"enableKillScore": "开启杀分",
"killScoreWeights": "杀分权重", "killScoreWeights": "杀分权重",
"killWeightNote": "(杀分权重来自奖池配置,请在列表中编辑对应记录)", "killWeightNote": "(杀分权重来自奖池配置,请在列表中编辑对应记录)",
"btnResetProfit": "重置玩家累计盈利", "btnResetProfit": "重置玩家累计盈利",

View File

@@ -34,7 +34,15 @@
"placeholderRewardTier": "请选择中奖档位", "placeholderRewardTier": "请选择中奖档位",
"addSuccess": "新增成功", "addSuccess": "新增成功",
"editSuccess": "修改成功", "editSuccess": "修改成功",
"validateFailed": "表单验证失败,请检查必填项与格式" "validateFailed": "表单验证失败,请检查必填项与格式",
"rulePlayerRequired": "请选择玩家",
"ruleLotteryConfigRequired": "请选择彩金池配置",
"ruleLotteryTypeRequired": "请选择抽奖类型",
"ruleIsWinRequired": "请选择是否中大奖",
"ruleWinCoinRequired": "赢取平台币必填",
"ruleRollArrayLength": "摇取点数必须为 5 个数",
"ruleRollArrayValues": "摇取点数必须填写 5 个数,每个 16",
"ruleRewardTierRequired": "请选择中奖档位"
}, },
"toolbar": { "toolbar": {
"platformTotalProfit": "平台总盈利" "platformTotalProfit": "平台总盈利"

View File

@@ -14,6 +14,8 @@
"status": "状态", "status": "状态",
"adminId": "所属管理员", "adminId": "所属管理员",
"placeholderAdmin": "选择后台管理员(可选)", "placeholderAdmin": "选择后台管理员(可选)",
"placeholderAdminTree": "按渠道选择后台管理员",
"unassignedChannel": "未分配渠道",
"coin": "平台币", "coin": "平台币",
"placeholderCoinAdd": "创建时默认0不可改", "placeholderCoinAdd": "创建时默认0不可改",
"lotteryPoolConfig": "彩金池配置", "lotteryPoolConfig": "彩金池配置",
@@ -44,7 +46,18 @@
"ruleEnterCoin": "请输入平台币变动", "ruleEnterCoin": "请输入平台币变动",
"ruleCoinPositive": "平台币变动必须大于 0", "ruleCoinPositive": "平台币变动必须大于 0",
"ruleDeductExceed": "扣点不能超过当前余额", "ruleDeductExceed": "扣点不能超过当前余额",
"operateSuccess": "操作成功" "operateSuccess": "操作成功",
"addSuccess": "新增成功",
"editSuccess": "修改成功",
"rulePasswordRequired": "密码必需填写",
"ruleUsernameRequired": "用户名必需填写",
"ruleNicknameRequired": "昵称必需填写",
"rulePhoneRequired": "手机号必需填写",
"ruleStatusRequired": "状态必需填写",
"ruleCoinRequired": "平台币必需填写",
"configTypeDefault": "默认",
"configTypeKillScore": "杀分",
"configTypeUp": "上分"
}, },
"search": { "search": {
"username": "用户名", "username": "用户名",

View File

@@ -14,7 +14,12 @@
"placeholderTotalDrawCount": "自动求和", "placeholderTotalDrawCount": "自动求和",
"placeholderRemark": "请输入备注(必填)", "placeholderRemark": "请输入备注(必填)",
"addSuccess": "新增成功", "addSuccess": "新增成功",
"editSuccess": "修改成功" "editSuccess": "修改成功",
"rulePlayerRequired": "请选择玩家",
"ruleUseCoinsRequired": "消耗硬币必需填写",
"rulePaidDrawRequired": "购买抽奖次数必需填写",
"ruleFreeDrawRequired": "赠送抽奖次数必需填写",
"ruleRemarkRequired": "备注必需填写"
}, },
"search": { "search": {
"player": "玩家", "player": "玩家",

View File

@@ -1,4 +1,7 @@
{ {
"toolbar": {
"coinChangeSummary": "平台币变化统计"
},
"form": { "form": {
"dialogTitleAdd": "新增玩家钱包流水", "dialogTitleAdd": "新增玩家钱包流水",
"dialogTitleEdit": "编辑玩家钱包流水", "dialogTitleEdit": "编辑玩家钱包流水",
@@ -19,7 +22,10 @@
"placeholderWalletAfter": "根据平台币变化自动计算", "placeholderWalletAfter": "根据平台币变化自动计算",
"placeholderRemark": "选填", "placeholderRemark": "选填",
"addSuccess": "新增成功", "addSuccess": "新增成功",
"editSuccess": "修改成功" "editSuccess": "修改成功",
"ruleUserRequired": "请选择用户",
"ruleCoinRequired": "平台币变化必填",
"ruleTypeRequired": "请选择类型"
}, },
"search": { "search": {
"type": "类型", "type": "类型",

View File

@@ -68,7 +68,8 @@
"stepFree": "免费抽奖券", "stepFree": "免费抽奖券",
"labelLotteryTypePaid": "测试数据档位类型", "labelLotteryTypePaid": "测试数据档位类型",
"labelLotteryTypeFree": "测试数据档位类型", "labelLotteryTypeFree": "测试数据档位类型",
"labelAnte": "底注 ante", "labelAnte": "底注",
"placeholderAnte": "请选择底注配置",
"placeholderPaidPool": "不选则下方自定义档位概率(默认 default", "placeholderPaidPool": "不选则下方自定义档位概率(默认 default",
"placeholderFreePool": "不选则下方自定义档位概率(默认 killScore", "placeholderFreePool": "不选则下方自定义档位概率(默认 killScore",
"tierProbHint": "自定义档位概率T1T5每档 0-100%,五档之和不能超过 100%", "tierProbHint": "自定义档位概率T1T5每档 0-100%,五档之和不能超过 100%",
@@ -81,7 +82,7 @@
"btnNext": "下一步", "btnNext": "下一步",
"btnStart": "开始测试", "btnStart": "开始测试",
"btnCancel": "取消", "btnCancel": "取消",
"warnAnte": "底注 ante 必须大于 0", "warnAnte": "请选择底注",
"warnPaidSpins": "付费抽奖顺时针与逆时针次数之和须大于 0", "warnPaidSpins": "付费抽奖顺时针与逆时针次数之和须大于 0",
"warnTestSafetyLine": "测试安全线必须大于或等于 0", "warnTestSafetyLine": "测试安全线必须大于或等于 0",
"warnTotalSpins": "付费或免费至少一种方向次数之和大于 0", "warnTotalSpins": "付费或免费至少一种方向次数之和大于 0",

View File

@@ -1,38 +1,35 @@
{ {
"search": { "search": {
"deptName": "渠道(部门)名称", "deptName": "渠道名称",
"deptCode": "部门编码", "deptCode": "渠道编码",
"status": "状态", "status": "状态",
"placeholderDeptName": "请输入部门名称", "placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入部门编码", "placeholderDeptCode": "请输入渠道编码",
"searchSelectPlaceholder": "请选择" "searchSelectPlaceholder": "请选择"
}, },
"table": { "table": {
"deptName": "渠道(部门)名称", "deptName": "渠道名称",
"deptCode": "部门编码", "deptCode": "渠道编码",
"leader": "部门领导", "leader": "渠道负责人",
"sort": "排序", "sort": "排序",
"status": "状态", "status": "状态",
"createTime": "创建时间" "createTime": "创建时间"
}, },
"form": { "form": {
"titleAdd": "新增部门", "titleAdd": "新增渠道",
"titleEdit": "编辑部门", "titleEdit": "编辑渠道",
"labelParentDept": "上级部门", "labelDeptName": "渠道名称",
"labelDeptName": "部门名称", "labelDeptCode": "渠道编码",
"labelDeptCode": "部门编码", "labelLeader": "渠道负责人",
"labelLeader": "部门领导",
"labelRemark": "描述", "labelRemark": "描述",
"labelSort": "排序", "labelSort": "排序",
"labelStatus": "启用", "labelStatus": "启用",
"placeholderDeptName": "请输入部门名称", "placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入部门编码", "placeholderDeptCode": "请输入渠道编码",
"placeholderRemark": "请输入部门描述", "placeholderRemark": "请输入渠道描述",
"placeholderSort": "请输入排序", "placeholderSort": "请输入排序",
"noParentDept": "无上级部门", "ruleDeptNameRequired": "请输入渠道名称",
"ruleParentDeptRequired": "请选择上级部门", "ruleDeptCodeRequired": "请输入渠道编码",
"ruleDeptNameRequired": "请输入部门名称",
"ruleDeptCodeRequired": "请输入部门编码",
"addSuccess": "新增成功", "addSuccess": "新增成功",
"editSuccess": "修改成功" "editSuccess": "修改成功"
} }

View File

@@ -1,34 +0,0 @@
{
"search": {
"postName": "岗位名称",
"postCode": "岗位编码",
"status": "状态",
"placeholderPostName": "请输入岗位名称",
"placeholderPostCode": "请输入岗位编码",
"searchSelectPlaceholder": "请选择"
},
"table": {
"postName": "岗位名称",
"postCode": "岗位编码",
"sort": "排序",
"status": "状态",
"createTime": "创建时间"
},
"form": {
"titleAdd": "新增岗位",
"titleEdit": "编辑岗位",
"labelName": "岗位名称",
"labelCode": "岗位编码",
"labelRemark": "描述",
"labelSort": "排序",
"labelStatus": "启用",
"placeholderName": "请输入岗位名称",
"placeholderCode": "请输入岗位编码",
"placeholderRemark": "请输入岗位描述",
"placeholderSort": "请输入排序",
"ruleNameRequired": "请输入岗位名称",
"ruleCodeRequired": "请输入岗位编码",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
}
}

View File

@@ -10,7 +10,7 @@
"table": { "table": {
"username": "用户名", "username": "用户名",
"phone": "手机号", "phone": "手机号",
"dept": "部门", "dept": "渠道",
"dashboard": "首页", "dashboard": "首页",
"loginTime": "上次登录", "loginTime": "上次登录",
"agentId": "代理ID", "agentId": "代理ID",
@@ -28,9 +28,8 @@
"labelPasswordConfirm": "确认密码", "labelPasswordConfirm": "确认密码",
"labelEmail": "邮箱", "labelEmail": "邮箱",
"labelPhone": "手机号", "labelPhone": "手机号",
"labelDept": "部门", "labelDept": "渠道",
"labelRole": "角色", "labelRole": "角色",
"labelPost": "岗位",
"labelGender": "性别", "labelGender": "性别",
"labelStatus": "状态", "labelStatus": "状态",
"labelRemark": "备注", "labelRemark": "备注",
@@ -43,12 +42,15 @@
"rulePasswordRequired": "请输入密码", "rulePasswordRequired": "请输入密码",
"rulePasswordLength": "长度在 6 到 20 个字符", "rulePasswordLength": "长度在 6 到 20 个字符",
"rulePasswordConfirmRequired": "请输入确认密码", "rulePasswordConfirmRequired": "请输入确认密码",
"ruleDeptRequired": "请选择部门", "ruleDeptRequired": "请选择渠道",
"ruleRoleRequired": "请选择角色", "ruleRoleRequired": "请选择角色",
"addSuccess": "新增成功", "addSuccess": "新增成功",
"editSuccess": "修改成功" "editSuccess": "修改成功"
}, },
"ui": { "ui": {
"channelList": "渠道列表",
"viewingChannel": "当前配置渠道",
"defaultConfigTemplate": "默认配置模板",
"promptNewPassword": "请输入新密码", "promptNewPassword": "请输入新密码",
"passwordLengthError": "密码长度在6到16之间", "passwordLengthError": "密码长度在6到16之间",
"passwordChanged": "修改密码成功", "passwordChanged": "修改密码成功",

View File

@@ -0,0 +1,48 @@
import type { RouteLocationNormalized } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
/** 页面自带左侧渠道栏,不再包一层全局渠道壳 */
const BUILTIN_CHANNEL_LAYOUT_PATHS = [
'/system/user',
'/system/dept'
]
export function isSuperAdminUser(): boolean {
const userStore = useUserStore()
return Number(userStore.info?.id ?? 0) === 1
}
/** 游戏配置类页面:显示「默认配置模板」 */
export function isConfigChannelRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.channelScope === 'config') {
return true
}
return /\/(config|ante_config|lottery_pool_config|reward_config|game)(\/|$)/.test(route.path)
}
/** 角色管理左侧渠道树含默认模板dept_id=0与各渠道角色 */
export function isRoleChannelRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.channelScope === 'role') {
return true
}
return route.path.startsWith('/system/role')
}
export function shouldWrapSuperAdminChannelLayout(route: RouteLocationNormalized): boolean {
if (!isSuperAdminUser()) {
return false
}
if (route.meta?.isFullPage) {
return false
}
if (route.meta?.noChannelLayout === true) {
return false
}
const path = route.path
for (let i = 0; i < BUILTIN_CHANNEL_LAYOUT_PATHS.length; i++) {
if (path.startsWith(BUILTIN_CHANNEL_LAYOUT_PATHS[i])) {
return false
}
}
return true
}

View File

@@ -25,7 +25,6 @@ export const MAP_PATH_TO_MENU_I18N_KEY: Record<string, string> = {
'/system/user-center': 'menus.system.userCenter', '/system/user-center': 'menus.system.userCenter',
'/system/menu': 'menus.system.menu', '/system/menu': 'menus.system.menu',
'/system/dept': 'menus.system.dept', '/system/dept': 'menus.system.dept',
'/system/post': 'menus.system.post',
'/system/config': 'menus.system.config', '/system/config': 'menus.system.config',
'/safeguard': 'menus.safeguard.title', '/safeguard': 'menus.safeguard.title',
'/safeguard/dict': 'menus.safeguard.dict', '/safeguard/dict': 'menus.safeguard.dict',

View File

@@ -1,9 +1,9 @@
<!-- 工作台页面 --> <!-- 工作台页面大富翁色子游戏数据统计 -->
<template> <template>
<div> <div>
<template v-if="userInfo.dashboard === 'statistics'"> <CardList />
<CardList></CardList>
<template v-if="isStatisticsDashboard">
<ElRow :gutter="20"> <ElRow :gutter="20">
<ElCol :sm="24" :md="12" :lg="10"> <ElCol :sm="24" :md="12" :lg="10">
<ActiveUser /> <ActiveUser />
@@ -12,30 +12,22 @@
<SalesOverview /> <SalesOverview />
</ElCol> </ElCol>
</ElRow> </ElRow>
</template>
<ElRow :gutter="20"> <ElRow :gutter="20">
<ElCol :sm="24" :md="12" :lg="12">
<WalletRecordList />
</ElCol>
<ElCol :sm="24" :md="12" :lg="12"> <ElCol :sm="24" :md="12" :lg="12">
<NewPlayerList /> <NewPlayerList />
</ElCol> </ElCol>
<ElCol :sm="24" :md="12" :lg="12">
<WalletRecordList />
</ElCol>
</ElRow> </ElRow>
</template>
<template v-if="userInfo.dashboard === 'work'">
<ElRow :gutter="20"> <ElRow :gutter="20">
<ElCol :sm="24" :md="24" :lg="12"> <ElCol :sm="24" :md="24" :lg="24">
<NewUser /> <PlayRecordList />
</ElCol>
<ElCol :sm="24" :md="12" :lg="6">
<Dynamic />
</ElCol>
<ElCol :sm="24" :md="12" :lg="6">
<TodoList />
</ElCol> </ElCol>
</ElRow> </ElRow>
</template>
</div> </div>
</template> </template>
@@ -45,16 +37,18 @@
import SalesOverview from './modules/sales-overview.vue' import SalesOverview from './modules/sales-overview.vue'
import WalletRecordList from './modules/wallet-record-list.vue' import WalletRecordList from './modules/wallet-record-list.vue'
import NewPlayerList from './modules/new-player-list.vue' import NewPlayerList from './modules/new-player-list.vue'
import NewUser from './modules/new-user.vue' import PlayRecordList from './modules/play-record-list.vue'
import Dynamic from './modules/dynamic-stats.vue'
import TodoList from './modules/todo-list.vue'
import { useCommon } from '@/hooks/core/useCommon' import { useCommon } from '@/hooks/core/useCommon'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
defineOptions({ name: 'Console' }) defineOptions({ name: 'Console' })
const userStore = useUserStore() const userStore = useUserStore()
const userInfo = userStore.getUserInfo
/** 统计页额外展示充值图表 */
const isStatisticsDashboard = computed(
() => userStore.getUserInfo.dashboard === 'statistics'
)
const { scrollToTop } = useCommon() const { scrollToTop } = useCommon()
scrollToTop() scrollToTop()

View File

@@ -18,6 +18,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchRechargeBarChart } from '@/api/dashboard' import { fetchRechargeBarChart } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
/** /**
* 充值金额数据 * 充值金额数据
@@ -29,10 +30,12 @@
*/ */
const xData = ref<string[]>([]) const xData = ref<string[]>([])
onMounted(async () => { const loadChart = () => {
fetchRechargeBarChart().then((data: any) => { fetchRechargeBarChart(getChannelDeptRequestParams()).then((data: any) => {
yData.value = data?.recharge_amount ?? [] yData.value = data?.recharge_amount ?? []
xData.value = data?.recharge_month ?? [] xData.value = data?.recharge_month ?? []
}) })
}) }
useChannelDeptReload(loadChart)
</script> </script>

View File

@@ -99,6 +99,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchStatistics } from '@/api/dashboard' import { fetchStatistics } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const statData = ref({ const statData = ref({
player_count: 0, player_count: 0,
@@ -123,8 +124,8 @@
return 'text-g-600' return 'text-g-600'
} }
onMounted(() => { const loadStatistics = () => {
fetchStatistics().then((data: any) => { fetchStatistics(getChannelDeptRequestParams()).then((data: any) => {
statData.value = { statData.value = {
player_count: data?.player_count ?? 0, player_count: data?.player_count ?? 0,
player_count_change: data?.player_count_change ?? 0, player_count_change: data?.player_count_change ?? 0,
@@ -136,5 +137,7 @@
play_count_change: data?.play_count_change ?? 0 play_count_change: data?.play_count_change ?? 0
} }
}) })
}) }
useChannelDeptReload(loadStatistics)
</script> </script>

View File

@@ -17,11 +17,23 @@
> >
<template #default> <template #default>
<ElTableColumn :label="$t('console.newPlayer.player')" prop="name" min-width="120" align="center" /> <ElTableColumn :label="$t('console.newPlayer.player')" prop="name" min-width="120" align="center" />
<ElTableColumn :label="$t('console.newPlayer.balance')" prop="coin" min-width="120" align="center"> <ElTableColumn :label="$t('console.newPlayer.balance')" prop="coin" min-width="100" align="center">
<template #default="scope"> <template #default="scope">
{{ formatCoin(scope.row.coin) }} {{ formatCoin(scope.row.coin) }}
</template> </template>
</ElTableColumn> </ElTableColumn>
<ElTableColumn
:label="$t('console.newPlayer.ticket')"
prop="total_ticket_count"
min-width="90"
align="center"
/>
<ElTableColumn
:label="$t('console.newPlayer.registerTime')"
prop="create_time"
min-width="170"
align="center"
/>
</template> </template>
</ArtTable> </ArtTable>
</div> </div>
@@ -29,6 +41,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchNewPlayerList, type NewPlayerItem } from '@/api/dashboard' import { fetchNewPlayerList, type NewPlayerItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<NewPlayerItem[]>([]) const tableData = ref<NewPlayerItem[]>([])
@@ -37,9 +50,11 @@
return Number(val).toFixed(2) return Number(val).toFixed(2)
} }
onMounted(() => { const loadList = () => {
fetchNewPlayerList().then((data) => { fetchNewPlayerList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : [] tableData.value = Array.isArray(data) ? data : []
}) })
}) }
useChannelDeptReload(loadList)
</script> </script>

View File

@@ -0,0 +1,70 @@
<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>{{ $t('console.playRecord.title') }}</h4>
<p class="text-g-600 text-sm mt-1">{{ $t('console.playRecord.subtitle') }}</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="$t('console.playRecord.player')"
prop="player_name"
min-width="120"
align="center"
/>
<ElTableColumn
:label="$t('console.playRecord.reward')"
prop="reward_tier_label"
min-width="140"
align="center"
/>
<ElTableColumn
:label="$t('console.playRecord.winCoin')"
prop="win_coin"
min-width="120"
align="center"
>
<template #default="scope">
{{ formatCoin(scope.row.win_coin) }}
</template>
</ElTableColumn>
<ElTableColumn
:label="$t('console.playRecord.playTime')"
prop="create_time"
min-width="170"
align="center"
/>
</template>
</ArtTable>
</div>
</template>
<script setup lang="ts">
import { fetchPlayRecordList, type PlayRecordItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<PlayRecordItem[]>([])
function formatCoin(val: number | undefined): string {
if (val === undefined || val === null) return '0.00'
return Number(val).toFixed(2)
}
const loadList = () => {
fetchPlayRecordList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : []
})
}
useChannelDeptReload(loadList)
</script>

View File

@@ -17,6 +17,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchRechargeChart } from '@/api/dashboard' import { fetchRechargeChart } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
/** /**
* 充值金额数据 * 充值金额数据
@@ -28,10 +29,12 @@
*/ */
const xData = ref<string[]>([]) const xData = ref<string[]>([])
onMounted(async () => { const loadChart = () => {
fetchRechargeChart().then((data: any) => { fetchRechargeChart(getChannelDeptRequestParams()).then((data: any) => {
yData.value = data?.recharge_amount ?? [] yData.value = data?.recharge_amount ?? []
xData.value = data?.recharge_date ?? [] xData.value = data?.recharge_date ?? []
}) })
}) }
useChannelDeptReload(loadChart)
</script> </script>

View File

@@ -30,6 +30,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchWalletRecordList, type WalletRecordItem } from '@/api/dashboard' import { fetchWalletRecordList, type WalletRecordItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<WalletRecordItem[]>([]) const tableData = ref<WalletRecordItem[]>([])
@@ -38,9 +39,11 @@
return Number(val).toFixed(2) return Number(val).toFixed(2)
} }
onMounted(() => { const loadList = () => {
fetchWalletRecordList().then((data) => { fetchWalletRecordList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : [] tableData.value = Array.isArray(data) ? data : []
}) })
}) }
useChannelDeptReload(loadList)
</script> </script>

View File

@@ -109,6 +109,7 @@
} = useTable({ } = useTable({
core: { core: {
apiFn: api.list, apiFn: api.list,
apiParams: { limit: 100 },
columnsFactory: () => [ columnsFactory: () => [
{ type: 'selection' }, { type: 'selection' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' }, { prop: 'id', label: 'page.table.id', width: 80, align: 'center' },

View File

@@ -36,6 +36,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -111,10 +112,10 @@
try { try {
await formRef.value.validate() await formRef.value.validate()
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(withChannelDeptParams(formData))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(formData) await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -36,5 +36,16 @@ export default {
url: '/core/dice/ante_config/DiceAnteConfig/destroy', url: '/core/dice/ante_config/DiceAnteConfig/destroy',
data: params data: params
}) })
},
/** 底注下拉(按渠道) */
async getOptions(params?: Record<string, unknown>) {
const res = await request.get<
Array<{ id: number; name: string; title: string; mult: number; is_default: number }>
>({
url: '/core/dice/ante_config/DiceAnteConfig/getOptions',
params
})
return Array.isArray(res) ? res : []
} }
} }

View File

@@ -20,7 +20,7 @@ export default {
* 获取 DiceLotteryPoolConfig 列表数据,含 id、name、t1_weightt5_weight用于一键测试权重档位类型下拉 * 获取 DiceLotteryPoolConfig 列表数据,含 id、name、t1_weightt5_weight用于一键测试权重档位类型下拉
* name 映射default=原 type=0killScore=原 type=1up=原 type=2 * name 映射default=原 type=0killScore=原 type=1up=原 type=2
*/ */
async getOptions(): Promise< async getOptions(params?: Record<string, unknown>): Promise<
Array<{ Array<{
id: number id: number
name: string name: string
@@ -32,7 +32,8 @@ export default {
}> }>
> { > {
const res = await request.get<any>({ const res = await request.get<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions' url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions',
params
}) })
const rows = Array.isArray(res) ? res : (Array.isArray((res as any)?.data) ? (res as any).data : []) const rows = Array.isArray(res) ? res : (Array.isArray((res as any)?.data) ? (res as any).data : [])
if (!Array.isArray(rows)) return [] if (!Array.isArray(rows)) return []
@@ -97,7 +98,7 @@ export default {
/** /**
* 获取当前彩金池Redis 实例化,无则按 type=0 创建),含玩家累计盈利 profit_amount 实时值 * 获取当前彩金池Redis 实例化,无则按 type=0 创建),含玩家累计盈利 profit_amount 实时值
*/ */
getCurrentPool() { getCurrentPool(params?: { dept_id?: number }) {
return request.get<{ return request.get<{
id: number id: number
name: string name: string
@@ -110,14 +111,15 @@ export default {
t5_weight: number t5_weight: number
profit_amount: number profit_amount: number
}>({ }>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool' url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool',
params
}) })
}, },
/** /**
* 更新当前彩金池:仅 safety_line、t1_weightt5_weight不可改 profit_amount * 更新当前彩金池:仅 safety_line、t1_weightt5_weight不可改 profit_amount
*/ */
updateCurrentPool(params: { safety_line?: number; kill_enabled?: number }) { updateCurrentPool(params: { safety_line?: number; kill_enabled?: number; dept_id?: number }) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool', url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool',
data: params data: params
@@ -127,9 +129,10 @@ export default {
/** /**
* 重置当前彩金池的玩家累计盈利profit_amount 置为 0 * 重置当前彩金池的玩家累计盈利profit_amount 置为 0
*/ */
resetProfitAmount() { resetProfitAmount(params?: { dept_id?: number }) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount' url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount',
data: params || {}
}) })
} }
} }

View File

@@ -64,16 +64,18 @@ export default {
}, },
/** 获取玩家选项id、username */ /** 获取玩家选项id、username */
getPlayerOptions() { getPlayerOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; username: string }[]>({ return request.get<{ id: number; username: string }[]>({
url: '/core/dice/play_record/DicePlayRecord/getPlayerOptions' url: '/core/dice/play_record/DicePlayRecord/getPlayerOptions',
params
}) })
}, },
/** 获取彩金池配置选项id、name */ /** 获取彩金池配置选项id、name */
getLotteryConfigOptions() { getLotteryConfigOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; name: string }[]>({ return request.get<{ id: number; name: string }[]>({
url: '/core/dice/play_record/DicePlayRecord/getLotteryConfigOptions' url: '/core/dice/play_record/DicePlayRecord/getLotteryConfigOptions',
params
}) })
} }
} }

View File

@@ -87,9 +87,10 @@ export default {
* 获取彩金池配置选项DiceLotteryPoolConfig.id、name供 lottery_config_id 下拉使用 * 获取彩金池配置选项DiceLotteryPoolConfig.id、name供 lottery_config_id 下拉使用
* @returns [ { id, name } ] * @returns [ { id, name } ]
*/ */
async getLotteryConfigOptions(): Promise<Array<{ id: number; name: string }>> { async getLotteryConfigOptions(params?: Record<string, unknown>): Promise<Array<{ id: number; name: string }>> {
const res = await request.get<any>({ const res = await request.get<any>({
url: '/core/dice/player/DicePlayer/getLotteryConfigOptions' url: '/core/dice/player/DicePlayer/getLotteryConfigOptions',
params
}) })
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }> 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 ?? '') })) return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
@@ -99,11 +100,12 @@ export default {
* 获取后台管理员选项SystemUser供 admin_id 下拉使用 * 获取后台管理员选项SystemUser供 admin_id 下拉使用
* @returns [ { id, username, realname, label } ] * @returns [ { id, username, realname, label } ]
*/ */
async getSystemUserOptions(): Promise< async getSystemUserOptions(params?: Record<string, unknown>): Promise<
Array<{ id: number; username: string; realname: string; label: string }> Array<{ id: number; username: string; realname: string; label: string }>
> { > {
const res = await request.get<any>({ const res = await request.get<any>({
url: '/core/dice/player/DicePlayer/getSystemUserOptions' url: '/core/dice/player/DicePlayer/getSystemUserOptions',
params
}) })
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
id: number id: number
@@ -117,5 +119,29 @@ export default {
realname: String(r.realname ?? ''), realname: String(r.realname ?? ''),
label: String(r.label ?? r.username ?? r.id ?? '') label: String(r.label ?? r.username ?? r.id ?? '')
})) }))
},
/**
* 超管:按渠道树状展示全部管理员;非超管:扁平列表
*/
async getSystemUserTreeOptions(params?: Record<string, unknown>): Promise<
Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
> {
const res = await request.get<any>({
url: '/core/dice/player/DicePlayer/getSystemUserTreeOptions',
params
})
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
return rows
} }
} }

View File

@@ -66,9 +66,10 @@ export default {
/** /**
* 获取玩家选项id、username用于下拉 * 获取玩家选项id、username用于下拉
*/ */
getPlayerOptions() { getPlayerOptions(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions' url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions',
params
}) })
} }
} }

View File

@@ -10,7 +10,7 @@ export default {
* @returns 数据列表 * @returns 数据列表
*/ */
list(params: Record<string, any>) { list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({ return request.get<Api.Common.ApiPage & { total_coin_change?: number }>({
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/index', url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/index',
params params
}) })
@@ -66,9 +66,10 @@ export default {
/** /**
* 获取玩家选项id、username用于下拉 * 获取玩家选项id、username用于下拉
*/ */
getPlayerOptions() { getPlayerOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; username: string }[]>({ return request.get<{ id: number; username: string }[]>({
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions' url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions',
params
}) })
}, },

View File

@@ -19,19 +19,20 @@ export default {
* 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向) * 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向)
* @param direction 0=顺时针 1=逆时针 * @param direction 0=顺时针 1=逆时针
*/ */
weightRatioList(direction: 0 | 1) { weightRatioList(direction: 0 | 1, params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/core/dice/reward/DiceReward/weightRatioList', url: '/core/dice/reward/DiceReward/weightRatioList',
params: { direction } params: { direction, ...(params || {}) }
}) })
}, },
/** /**
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重dice_reward 双方向) * 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重dice_reward 双方向)
*/ */
weightRatioListWithDirection() { weightRatioListWithDirection(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/core/dice/reward/DiceReward/weightRatioListWithDirection' url: '/core/dice/reward/DiceReward/weightRatioListWithDirection',
params
}) })
}, },
@@ -39,10 +40,13 @@ export default {
* 权重编辑弹窗:按 DiceReward 主键 id 批量更新 weight * 权重编辑弹窗:按 DiceReward 主键 id 批量更新 weight
* @param items [{ id: DiceReward.id, weight: 1-10000 }, ...] * @param items [{ id: DiceReward.id, weight: 1-10000 }, ...]
*/ */
batchUpdateWeights(items: Array<{ id: number; weight: number }>) { batchUpdateWeights(
items: Array<{ id: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/reward/DiceReward/batchUpdateWeights', url: '/core/dice/reward/DiceReward/batchUpdateWeights',
data: { items } data: { items, ...(extra || {}) }
}) })
}, },
@@ -62,6 +66,7 @@ export default {
*/ */
startWeightTest(params: { startWeightTest(params: {
ante?: number ante?: number
ante_config_id?: number
lottery_config_id?: number lottery_config_id?: number
paid_lottery_config_id?: number paid_lottery_config_id?: number
free_lottery_config_id?: number free_lottery_config_id?: number

View File

@@ -66,19 +66,23 @@ export default {
/** /**
* 批量更新奖励索引配置第一页id、grid_number、ui_text、real_ev、tier、remark * 批量更新奖励索引配置第一页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 }>) { batchUpdate(
items: Array<{ id: number; grid_number?: number; ui_text?: string; real_ev?: number; tier?: string; remark?: string }>,
extra?: Record<string, any>
) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdate', url: '/core/dice/reward_config/DiceRewardConfig/batchUpdate',
data: { items } data: { items, ...(extra || {}) }
}) })
}, },
/** /**
* T1-T5、BIGWIN 权重配比:按档位分组获取配置列表 * T1-T5、BIGWIN 权重配比:按档位分组获取配置列表
*/ */
weightRatioList() { weightRatioList(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/core/dice/reward_config/DiceRewardConfig/weightRatioList' url: '/core/dice/reward_config/DiceRewardConfig/weightRatioList',
params
}) })
}, },
@@ -86,34 +90,41 @@ export default {
* T1-T5、BIGWIN 权重配比:批量更新顺时针/逆时针权重(写入 dice_reward * T1-T5、BIGWIN 权重配比:批量更新顺时针/逆时针权重(写入 dice_reward
*/ */
/** 按 DiceReward 主键 id 批量更新 weightitems: [{ id, weight }, ...] */ /** 按 DiceReward 主键 id 批量更新 weightitems: [{ id, weight }, ...] */
batchUpdateWeights(items: Array<{ id: number; weight: number }>) { batchUpdateWeights(
items: Array<{ id: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdateWeights', url: '/core/dice/reward_config/DiceRewardConfig/batchUpdateWeights',
data: { items } data: { items, ...(extra || {}) }
}) })
}, },
/** /**
* 大奖权重:按 grid_number 批量保存 BIGWIN 权重(无需 reward id不存在则自动创建 * 大奖权重:按 grid_number 批量保存 BIGWIN 权重(无需 reward id不存在则自动创建
*/ */
saveBigwinWeightsByGrid(items: Array<{ grid_number: number; weight: number }>) { saveBigwinWeightsByGrid(
items: Array<{ grid_number: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({ return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid', url: '/core/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid',
data: { items } data: { items, ...(extra || {}) }
}) })
}, },
/** /**
* 创建奖励对照:按当前奖励配置为顺时针(0)、逆时针(1)生成所有色子可能对应的 dice_reward 记录,权重默认 1可在奖励对照页权重编辑中调整 * 创建奖励对照:按当前奖励配置为顺时针(0)、逆时针(1)生成所有色子可能对应的 dice_reward 记录,权重默认 1可在奖励对照页权重编辑中调整
*/ */
createRewardReference() { createRewardReference(params?: Record<string, any>) {
return request.post<{ return request.post<{
created_clockwise: number created_clockwise: number
created_counterclockwise: number created_counterclockwise: number
updated_clockwise: number updated_clockwise: number
updated_counterclockwise: number updated_counterclockwise: number
}>({ }>({
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference' url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference',
data: params || {}
}) })
} }
} }

View File

@@ -107,6 +107,7 @@
} = useTable({ } = useTable({
core: { core: {
apiFn: api.list, apiFn: api.list,
apiParams: { limit: 100 },
columnsFactory: () => [ columnsFactory: () => [
// { type: 'selection' }, // { type: 'selection' },
{ prop: 'group', label: 'page.table.group', minWidth: 140, align: 'center' }, { prop: 'group', label: 'page.table.group', minWidth: 140, align: 'center' },

View File

@@ -47,6 +47,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -162,10 +163,10 @@
try { try {
await formRef.value.validate() await formRef.value.validate()
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(withChannelDeptParams(formData))
ElMessage.success(t('page.form.saveSuccess')) ElMessage.success(t('page.form.saveSuccess'))
} else { } else {
await api.update(formData) await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.updateSuccess')) ElMessage.success(t('page.form.updateSuccess'))
} }
emit('success') emit('success')

View File

@@ -40,7 +40,9 @@
@pagination:current-change="handleCurrentChange" @pagination:current-change="handleCurrentChange"
> >
<template #status="{ row }"> <template #status="{ row }">
<ElTag :type="row.status === 1 ? 'success' : 'info'">{{ row.status === 1 ? '启用' : '禁用' }}</ElTag> <ElTag :type="row.status === 1 ? 'success' : 'info'">{{
row.status === 1 ? $t('page.table.statusEnabled') : $t('page.table.statusDisabled')
}}</ElTag>
</template> </template>
<template #operation="{ row }"> <template #operation="{ row }">
<div class="flex gap-2"> <div class="flex gap-2">
@@ -103,6 +105,7 @@
} = useTable({ } = useTable({
core: { core: {
apiFn: api.list, apiFn: api.list,
apiParams: { limit: 100 },
columnsFactory: () => [ columnsFactory: () => [
{ type: 'selection', align: 'center' }, { type: 'selection', align: 'center' },
{ prop: 'id', label: 'ID', width: 80, align: 'center' }, { prop: 'id', label: 'ID', width: 80, align: 'center' },

View File

@@ -1,7 +1,7 @@
<template> <template>
<el-dialog <el-dialog
v-model="visible" v-model="visible"
:title="dialogType === 'add' ? '新增游戏' : '编辑游戏'" :title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
width="680px" width="680px"
align-center align-center
:close-on-click-modal="false" :close-on-click-modal="false"
@@ -10,55 +10,55 @@
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :span="12"> <el-col :span="12">
<el-form-item label="供应商" prop="provider"> <el-form-item :label="$t('page.form.provider')" prop="provider">
<el-input v-model="formData.provider" placeholder="请输入供应商名称" /> <el-input v-model="formData.provider" :placeholder="$t('page.form.placeholderProvider')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="供应商编码" prop="provider_code"> <el-form-item :label="$t('page.form.providerCode')" prop="provider_code">
<el-input v-model="formData.provider_code" placeholder="请输入供应商编码" /> <el-input v-model="formData.provider_code" :placeholder="$t('page.form.placeholderProviderCode')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :span="12"> <el-col :span="12">
<el-form-item label="游戏编号" prop="game_code"> <el-form-item :label="$t('page.form.gameCode')" prop="game_code">
<el-input v-model="formData.game_code" placeholder="请输入游戏编号" /> <el-input v-model="formData.game_code" :placeholder="$t('page.form.placeholderGameCode')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="游戏唯一值" prop="game_key"> <el-form-item :label="$t('page.form.gameKey')" prop="game_key">
<el-input v-model="formData.game_key" placeholder="请输入游戏唯一值" /> <el-input v-model="formData.game_key" :placeholder="$t('page.form.placeholderGameKey')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :span="12"> <el-col :span="12">
<el-form-item label="中文名称" prop="game_name"> <el-form-item :label="$t('page.form.gameName')" prop="game_name">
<el-input v-model="formData.game_name" placeholder="请输入中文名称" /> <el-input v-model="formData.game_name" :placeholder="$t('page.form.placeholderGameName')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="英文名称" prop="game_name_en"> <el-form-item :label="$t('page.form.gameNameEn')" prop="game_name_en">
<el-input v-model="formData.game_name_en" placeholder="请输入英文名称" /> <el-input v-model="formData.game_name_en" :placeholder="$t('page.form.placeholderGameNameEn')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :span="12"> <el-col :span="12">
<el-form-item label="游戏类型" prop="game_type"> <el-form-item :label="$t('page.form.gameType')" prop="game_type">
<el-input v-model="formData.game_type" placeholder="请输入游戏类型" /> <el-input v-model="formData.game_type" :placeholder="$t('page.form.placeholderGameType')" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="排序" prop="sort"> <el-form-item :label="$t('page.form.sort')" prop="sort">
<el-input-number v-model="formData.sort" :min="1" :step="1" style="width: 100%" /> <el-input-number v-model="formData.sort" :min="1" :step="1" style="width: 100%" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-form-item label="Logo地址" prop="logo"> <el-form-item :label="$t('page.form.logo')" prop="logo">
<el-tabs v-model="logoInputMode" class="w-full"> <el-tabs v-model="logoInputMode" class="w-full">
<el-tab-pane label="图片选择" name="picker"> <el-tab-pane :label="$t('page.form.tabPicker')" name="picker">
<sa-image-picker <sa-image-picker
v-model="formData.logo" v-model="formData.logo"
:multiple="false" :multiple="false"
@@ -67,7 +67,7 @@
height="120px" height="120px"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="图片上传" name="upload"> <el-tab-pane :label="$t('page.form.tabUpload')" name="upload">
<sa-image-upload <sa-image-upload
v-model="formData.logo" v-model="formData.logo"
:multiple="false" :multiple="false"
@@ -78,33 +78,42 @@
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-form-item> </el-form-item>
<el-form-item label="游戏地址" prop="game_url"> <el-form-item :label="$t('page.form.gameUrl')" prop="game_url">
<el-input v-model="formData.game_url" placeholder="请输入游戏地址" /> <el-input v-model="formData.game_url" :placeholder="$t('page.form.placeholderGameUrl')" />
</el-form-item> </el-form-item>
<el-form-item label="大厅地址" prop="hall_url"> <el-form-item :label="$t('page.form.hallUrl')" prop="hall_url">
<el-input v-model="formData.hall_url" placeholder="请输入大厅地址" /> <el-input v-model="formData.hall_url" :placeholder="$t('page.form.placeholderHallUrl')" />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item :label="$t('page.form.status')" prop="status">
<el-radio-group v-model="formData.status"> <el-radio-group v-model="formData.status">
<el-radio :value="1">启用</el-radio> <el-radio :value="1">{{ $t('page.form.statusEnabled') }}</el-radio>
<el-radio :value="0">禁用</el-radio> <el-radio :value="0">{{ $t('page.form.statusDisabled') }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="备注" prop="remark"> <el-form-item :label="$t('page.form.remark')" prop="remark">
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="请输入备注" /> <el-input
v-model="formData.remark"
type="textarea"
:rows="2"
:placeholder="$t('page.form.placeholderRemark')"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button @click="handleClose">取消</el-button> <el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">确定</el-button> <el-button type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/game/index' import api from '../../../api/game/index'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@@ -121,40 +130,24 @@
data: undefined data: undefined
}) })
const emit = defineEmits<Emits>() const emit = defineEmits<Emits>()
const formRef = ref<FormInstance>()
const logoInputMode = ref<'picker' | 'upload'>('picker')
const visible = computed({ const visible = computed({
get: () => props.modelValue, get: () => props.modelValue,
set: (value) => emit('update:modelValue', value) set: (val) => emit('update:modelValue', val)
}) })
type GameFormData = { const formRef = ref<FormInstance>()
id: number | null const logoInputMode = ref('picker')
provider: string
provider_code: string
game_code: string
game_key: string
game_name: string
game_name_en: string
game_type: string
logo: string
game_url: string
hall_url: string
status: number
sort: number
remark: string
}
const initialFormData: GameFormData = { const initialFormData = {
id: null, id: undefined as number | undefined,
provider: 'Dicey Fun', provider: '',
provider_code: 'DF', provider_code: '',
game_code: '', game_code: '',
game_key: '', game_key: '',
game_name: '', game_name: '',
game_name_en: '', game_name_en: '',
game_type: 'slot', game_type: '',
logo: '', logo: '',
game_url: '', game_url: '',
hall_url: '', hall_url: '',
@@ -166,12 +159,12 @@
const formData = reactive({ ...initialFormData }) const formData = reactive({ ...initialFormData })
const rules = computed<FormRules>(() => ({ const rules = computed<FormRules>(() => ({
provider: [{ required: true, message: '请输入供应商', trigger: 'blur' }], provider: [{ required: true, message: t('page.form.ruleProviderRequired'), trigger: 'blur' }],
provider_code: [{ required: true, message: '请输入供应商编码', trigger: 'blur' }], provider_code: [{ required: true, message: t('page.form.ruleProviderCodeRequired'), trigger: 'blur' }],
game_code: [{ required: true, message: '请输入游戏编号', trigger: 'blur' }], game_code: [{ required: true, message: t('page.form.ruleGameCodeRequired'), trigger: 'blur' }],
game_key: [{ required: true, message: '请输入游戏唯一值', trigger: 'blur' }], game_key: [{ required: true, message: t('page.form.ruleGameKeyRequired'), trigger: 'blur' }],
game_name: [{ required: true, message: '请输入中文名称', trigger: 'blur' }], game_name: [{ required: true, message: t('page.form.ruleGameNameRequired'), trigger: 'blur' }],
game_type: [{ required: true, message: '请输入游戏类型', trigger: 'blur' }] game_type: [{ required: true, message: t('page.form.ruleGameTypeRequired'), trigger: 'blur' }]
})) }))
watch( watch(
@@ -209,11 +202,11 @@
try { try {
await formRef.value.validate() await formRef.value.validate()
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(withChannelDeptParams(formData))
ElMessage.success('新增成功') ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(formData) await api.update(withChannelDeptParams(formData))
ElMessage.success('更新成功') ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')
handleClose() handleClose()

View File

@@ -1,6 +1,5 @@
<template> <template>
<div class="art-full-height"> <div class="flex-1 min-h-0 flex flex-col">
<!-- 搜索面板 -->
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" /> <TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never"> <ElCard class="art-table-card" shadow="never">

View File

@@ -42,7 +42,7 @@
style="width: 100%" style="width: 100%"
/> />
</el-form-item> </el-form-item>
<el-form-item label="开启杀分"> <el-form-item :label="$t('page.form.enableKillScore')">
<el-switch v-model="formData.kill_enabled" :active-value="1" :inactive-value="0" /> <el-switch v-model="formData.kill_enabled" :active-value="1" :inactive-value="0" />
</el-form-item> </el-form-item>
<el-form-item :label="$t('page.form.killScoreWeights')"> <el-form-item :label="$t('page.form.killScoreWeights')">
@@ -85,8 +85,13 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import {
getChannelDeptRequestParams,
withChannelDeptParams
} from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
const channelDeptParams = () => getChannelDeptRequestParams()
interface PoolData { interface PoolData {
id: number id: number
@@ -151,7 +156,7 @@
if (!visible.value) return if (!visible.value) return
try { try {
loading.value = true loading.value = true
const res = await api.getCurrentPool() const res = await api.getCurrentPool(channelDeptParams())
const data = res as unknown as PoolData const data = res as unknown as PoolData
if (data && typeof data === 'object') { if (data && typeof data === 'object') {
pool.value = data pool.value = data
@@ -172,7 +177,7 @@
stopPolling() stopPolling()
return return
} }
api.getCurrentPool().then((res) => { api.getCurrentPool(channelDeptParams()).then((res) => {
const data = res as unknown as PoolData const data = res as unknown as PoolData
if (pool.value && data && typeof data === 'object' && data.profit_amount != null) { if (pool.value && data && typeof data === 'object' && data.profit_amount != null) {
pool.value.profit_amount = data.profit_amount pool.value.profit_amount = data.profit_amount
@@ -193,10 +198,12 @@
try { try {
await formRef.value?.validate?.() await formRef.value?.validate?.()
saving.value = true saving.value = true
await api.updateCurrentPool({ await api.updateCurrentPool(
withChannelDeptParams({
safety_line: formData.safety_line, safety_line: formData.safety_line,
kill_enabled: formData.kill_enabled kill_enabled: formData.kill_enabled
}) })
)
ElMessage.success(t('page.form.msgSaveSuccess')) ElMessage.success(t('page.form.msgSaveSuccess'))
await loadPool() await loadPool()
emit('success') emit('success')
@@ -211,7 +218,7 @@
if (!pool.value) return if (!pool.value) return
try { try {
resetting.value = true resetting.value = true
await api.resetProfitAmount() await api.resetProfitAmount(channelDeptParams())
ElMessage.success(t('page.form.msgResetProfitSuccess')) ElMessage.success(t('page.form.msgResetProfitSuccess'))
await loadPool() await loadPool()
emit('success') emit('success')

View File

@@ -70,6 +70,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useInjectedChannelDept, withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -127,6 +128,7 @@
*/ */
const initialFormData = { const initialFormData = {
id: null as number | null, id: null as number | null,
dept_id: undefined as number | undefined,
name: '', name: '',
remark: '', remark: '',
safety_line: 0 as number, safety_line: 0 as number,
@@ -174,6 +176,7 @@
if (!props.data) return if (!props.data) return
const numKeys = [ const numKeys = [
'id', 'id',
'dept_id',
'safety_line', 'safety_line',
't1_weight', 't1_weight',
't2_weight', 't2_weight',
@@ -204,6 +207,8 @@
/** /**
* 提交表单 * 提交表单
*/ */
const channelScope = useInjectedChannelDept()
const handleSubmit = async () => { const handleSubmit = async () => {
if (!formRef.value) return if (!formRef.value) return
try { try {
@@ -212,11 +217,18 @@
ElMessage.warning(t('page.form.msgWeightsMust100')) ElMessage.warning(t('page.form.msgWeightsMust100'))
return return
} }
const submitData = withChannelDeptParams({
...formData,
dept_id:
formData.dept_id ??
props.data?.dept_id ??
channelScope?.selectedDeptId.value
})
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(submitData)
ElMessage.success(t('page.form.msgAddSuccess')) ElMessage.success(t('page.form.msgAddSuccess'))
} else { } else {
await api.update(formData) await api.update(submitData)
ElMessage.success(t('page.form.msgUpdateSuccess')) ElMessage.success(t('page.form.msgUpdateSuccess'))
} }
emit('success') emit('success')

View File

@@ -181,6 +181,7 @@
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/play_record/index' import api from '../../../api/play_record/index'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
@@ -212,22 +213,22 @@
set: (value) => emit('update:modelValue', value) set: (value) => emit('update:modelValue', value)
}) })
const rules = reactive<FormRules>({ const rules = computed<FormRules>(() => ({
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }], player_id: [{ required: true, message: t('page.form.rulePlayerRequired'), trigger: 'change' }],
lottery_config_id: [{ required: true, message: '请选择彩金池配置', trigger: 'change' }], lottery_config_id: [{ required: true, message: t('page.form.ruleLotteryConfigRequired'), trigger: 'change' }],
lottery_type: [{ required: true, message: '请选择抽奖类型', trigger: 'change' }], lottery_type: [{ required: true, message: t('page.form.ruleLotteryTypeRequired'), trigger: 'change' }],
is_win: [{ required: true, message: '请选择是否中大奖', trigger: 'change' }], is_win: [{ required: true, message: t('page.form.ruleIsWinRequired'), trigger: 'change' }],
win_coin: [{ required: true, message: '赢取平台币必填', trigger: 'blur' }], win_coin: [{ required: true, message: t('page.form.ruleWinCoinRequired'), trigger: 'blur' }],
rollArrayItems: [ rollArrayItems: [
{ {
validator: (_rule: any, value: (number | null)[], callback: (e?: Error) => void) => { validator: (_rule: any, value: (number | null)[], callback: (e?: Error) => void) => {
if (!value || value.length !== 5) { if (!value || value.length !== 5) {
callback(new Error('摇取点数必须为 5 个数')) callback(new Error(t('page.form.ruleRollArrayLength')))
return return
} }
const ok = value.every((n) => n != null && n >= 1 && n <= 6) const ok = value.every((n) => n != null && n >= 1 && n <= 6)
if (!ok) { if (!ok) {
callback(new Error('摇取点数必须填写 5 个数,每个 16')) callback(new Error(t('page.form.ruleRollArrayValues')))
return return
} }
callback() callback()
@@ -235,8 +236,8 @@
trigger: 'change' trigger: 'change'
} }
], ],
reward_tier: [{ required: true, message: '请选择中奖档位', trigger: 'change' }] reward_tier: [{ required: true, message: t('page.form.ruleRewardTierRequired'), trigger: 'change' }]
}) }))
const playerOptions = ref<Array<{ id: number; username: string }>>([]) const playerOptions = ref<Array<{ id: number; username: string }>>([])
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([]) const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
@@ -272,9 +273,10 @@
if (open) { if (open) {
initPage() initPage()
try { try {
const deptParams = getChannelDeptRequestParams()
const [players, lotteryConfigs] = await Promise.all([ const [players, lotteryConfigs] = await Promise.all([
api.getPlayerOptions(), api.getPlayerOptions(deptParams),
api.getLotteryConfigOptions() api.getLotteryConfigOptions(deptParams)
]) ])
playerOptions.value = Array.isArray(players) ? players : ((players as any)?.data ?? []) playerOptions.value = Array.isArray(players) ? players : ((players as any)?.data ?? [])
lotteryConfigOptions.value = Array.isArray(lotteryConfigs) lotteryConfigOptions.value = Array.isArray(lotteryConfigs)
@@ -391,10 +393,10 @@
delete payload.rollArrayItems delete payload.rollArrayItems
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
delete payload.id delete payload.id
await api.save(payload) await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(payload) await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -125,6 +125,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@@ -262,10 +263,10 @@
await formRef.value.validate() await formRef.value.validate()
const payload = { ...formData } const payload = { ...formData }
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(payload) await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(payload) await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -111,6 +111,7 @@
import { useTable } from '@/hooks/core/useTable' import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin' import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/player/index' import api from '../../api/player/index'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
import TableSearch from './modules/table-search.vue' import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue' import EditDialog from './modules/edit-dialog.vue'
import WalletOperateDialog from './modules/WalletOperateDialog.vue' import WalletOperateDialog from './modules/WalletOperateDialog.vue'
@@ -244,7 +245,7 @@
const handleStatusChange = async (row: Record<string, any>, status: number) => { const handleStatusChange = async (row: Record<string, any>, status: number) => {
row._statusLoading = true row._statusLoading = true
try { try {
await api.updateStatus({ id: row.id, status }) await api.updateStatus(withChannelDeptParams({ id: row.id, status }))
row.status = status row.status = status
} catch { } catch {
refreshData() refreshData()

View File

@@ -59,6 +59,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -157,12 +158,14 @@
return return
} }
submitting.value = true submitting.value = true
await walletRecordApi.adminOperate({ await walletRecordApi.adminOperate(
withChannelDeptParams({
player_id: props.player.id, player_id: props.player.id,
type: formData.type!, type: formData.type!,
coin, coin,
remark: formData.remark?.trim() || undefined remark: formData.remark?.trim() || undefined
}) })
)
ElMessage.success(t('page.form.operateSuccess')) ElMessage.success(t('page.form.operateSuccess'))
emit('success') emit('success')
handleClose() handleClose()

View File

@@ -35,7 +35,20 @@
<sa-switch v-model="formData.status" /> <sa-switch v-model="formData.status" />
</el-form-item> </el-form-item>
<el-form-item :label="$t('page.form.adminId')" prop="admin_id"> <el-form-item :label="$t('page.form.adminId')" prop="admin_id">
<el-tree-select
v-if="useAdminTreeSelect"
v-model="formData.admin_id"
:data="systemUserTreeOptions"
:props="systemUserTreeProps"
:placeholder="$t('page.form.placeholderAdminTree')"
clearable
filterable
check-strictly
style="width: 100%"
:loading="systemUserOptionsLoading"
/>
<el-select <el-select
v-else
v-model="formData.admin_id" v-model="formData.admin_id"
:placeholder="$t('page.form.placeholderAdmin')" :placeholder="$t('page.form.placeholderAdmin')"
clearable clearable
@@ -172,6 +185,8 @@
import api from '../../../api/player/index' import api from '../../../api/player/index'
import lotteryConfigApi from '../../../api/lottery_pool_config/index' import lotteryConfigApi from '../../../api/lottery_pool_config/index'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { isSuperAdminUser } from '@/utils/channelLayout'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
@@ -222,16 +237,18 @@
/** 新增时密码必填,编辑时选填 */ /** 新增时密码必填,编辑时选填 */
const passwordRules = computed(() => const passwordRules = computed(() =>
props.dialogType === 'add' ? [{ required: true, message: '密码必需填写', trigger: 'blur' }] : [] props.dialogType === 'add'
? [{ required: true, message: t('page.form.rulePasswordRequired'), trigger: 'blur' }]
: []
) )
const rules = reactive<FormRules>({ const rules = computed<FormRules>(() => ({
username: [{ required: true, message: '用户名必需填写', trigger: 'blur' }], username: [{ required: true, message: t('page.form.ruleUsernameRequired'), trigger: 'blur' }],
name: [{ required: true, message: '昵称必需填写', trigger: 'blur' }], name: [{ required: true, message: t('page.form.ruleNicknameRequired'), trigger: 'blur' }],
phone: [{ required: true, message: '手机号必需填写', trigger: 'blur' }], phone: [{ required: true, message: t('page.form.rulePhoneRequired'), trigger: 'blur' }],
status: [{ required: true, message: '状态必需填写', trigger: 'blur' }], status: [{ required: true, message: t('page.form.ruleStatusRequired'), trigger: 'blur' }],
coin: [{ required: true, message: '平台币必需填写', trigger: 'blur' }] coin: [{ required: true, message: t('page.form.ruleCoinRequired'), trigger: 'blur' }]
}) }))
const initialFormData = { const initialFormData = {
id: null as number | null, id: null as number | null,
@@ -262,6 +279,22 @@
const systemUserOptions = ref< const systemUserOptions = ref<
Array<{ id: number; username: string; realname: string; label: string }> Array<{ id: number; username: string; realname: string; label: string }>
>([]) >([])
/** 超管:按渠道分组的管理员树 */
const systemUserTreeOptions = ref<
Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
>([])
const useAdminTreeSelect = computed(() => isSuperAdminUser())
const systemUserTreeProps = {
label: 'label',
value: 'id',
children: 'children',
disabled: 'disabled'
}
/** 管理员选项加载中 */ /** 管理员选项加载中 */
const systemUserOptionsLoading = ref(false) const systemUserOptionsLoading = ref(false)
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */ /** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
@@ -269,9 +302,9 @@
function lotteryConfigTypeText(name: unknown): string { function lotteryConfigTypeText(name: unknown): string {
const n = String(name ?? '') const n = String(name ?? '')
if (n === 'default') return '默认' if (n === 'default') return t('page.form.configTypeDefault')
if (n === 'killScore') return '杀分' if (n === 'killScore') return t('page.form.configTypeKillScore')
if (n === 'up') return '上分' if (n === 'up') return t('page.form.configTypeUp')
return n || '-' return n || '-'
} }
@@ -335,12 +368,43 @@
} }
/** 加载后台管理员选项 */ /** 加载后台管理员选项 */
function normalizeAdminTreeLabels(
nodes: Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
) {
return nodes.map((node) => {
const item = { ...node }
if (item.label === '__unassigned__') {
item.label = t('page.form.unassignedChannel')
}
if (item.children?.length) {
item.children = item.children.map((child) => ({
...child,
label: child.label || child.username || `#${child.id}`
}))
}
return item
})
}
async function loadSystemUserOptions() { async function loadSystemUserOptions() {
systemUserOptionsLoading.value = true systemUserOptionsLoading.value = true
try { try {
systemUserOptions.value = await api.getSystemUserOptions() if (useAdminTreeSelect.value) {
const tree = await api.getSystemUserTreeOptions(getChannelDeptRequestParams())
systemUserTreeOptions.value = normalizeAdminTreeLabels(tree)
systemUserOptions.value = []
} else {
systemUserOptions.value = await api.getSystemUserOptions(getChannelDeptRequestParams())
systemUserTreeOptions.value = []
}
} catch { } catch {
systemUserOptions.value = [] systemUserOptions.value = []
systemUserTreeOptions.value = []
} finally { } finally {
systemUserOptionsLoading.value = false systemUserOptionsLoading.value = false
} }
@@ -363,7 +427,7 @@
async function loadLotteryConfigOptions() { async function loadLotteryConfigOptions() {
lotteryConfigLoading.value = true lotteryConfigLoading.value = true
try { try {
lotteryConfigOptions.value = await api.getLotteryConfigOptions() lotteryConfigOptions.value = await api.getLotteryConfigOptions(getChannelDeptRequestParams())
} catch { } catch {
lotteryConfigOptions.value = [] lotteryConfigOptions.value = []
} finally { } finally {
@@ -376,6 +440,7 @@
'status', 'status',
'coin', 'coin',
'lottery_config_id', 'lottery_config_id',
'admin_id',
't1_weight', 't1_weight',
't2_weight', 't2_weight',
't3_weight', 't3_weight',
@@ -397,7 +462,7 @@
;(formData as any)[key] = val != null ? Number(val) || null : null ;(formData as any)[key] = val != null ? Number(val) || null : null
} else if (key === 'lottery_config_id' || key === 'admin_id') { } else if (key === 'lottery_config_id' || key === 'admin_id') {
const num = Number(val) const num = Number(val)
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null ;(formData as any)[key] = val != null && !Number.isNaN(num) && num > 0 ? num : null
} else { } else {
;(formData as any)[key] = Number(val) || 0 ;(formData as any)[key] = Number(val) || 0
} }
@@ -429,10 +494,10 @@
delete (payload as any).password delete (payload as any).password
} }
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(payload) await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(payload) await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -82,6 +82,7 @@
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/player_ticket_record/index' import api from '../../../api/player_ticket_record/index'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
@@ -120,11 +121,11 @@
* 表单验证规则 * 表单验证规则
*/ */
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }], player_id: [{ required: true, message: t('page.form.rulePlayerRequired'), trigger: 'change' }],
use_coins: [{ required: true, message: '消耗硬币必需填写', trigger: 'blur' }], use_coins: [{ required: true, message: t('page.form.ruleUseCoinsRequired'), trigger: 'blur' }],
paid_ticket_count: [{ required: true, message: '购买抽奖次数必需填写', trigger: 'blur' }], paid_ticket_count: [{ required: true, message: t('page.form.rulePaidDrawRequired'), trigger: 'blur' }],
free_ticket_count: [{ required: true, message: '赠送抽奖次数必需填写', trigger: 'blur' }], free_ticket_count: [{ required: true, message: t('page.form.ruleFreeDrawRequired'), trigger: 'blur' }],
remark: [{ required: true, message: '备注必需填写', trigger: 'blur' }] remark: [{ required: true, message: t('page.form.ruleRemarkRequired'), trigger: 'blur' }]
}) })
/** 玩家下拉选项id、username */ /** 玩家下拉选项id、username */
@@ -168,7 +169,7 @@
if (open) { if (open) {
initPage() initPage()
try { try {
const list = await api.getPlayerOptions() const list = await api.getPlayerOptions(getChannelDeptRequestParams())
const arr = Array.isArray(list) ? list : (list as any)?.data const arr = Array.isArray(list) ? list : (list as any)?.data
playerOptions.value = Array.isArray(arr) playerOptions.value = Array.isArray(arr)
? (arr as Array<{ id: number; username: string }>) ? (arr as Array<{ id: number; username: string }>)
@@ -232,10 +233,10 @@
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
const rest = { ...formData } as Record<string, unknown> const rest = { ...formData } as Record<string, unknown>
delete rest.id delete rest.id
await api.save(rest) await api.save(withChannelDeptParams(rest))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(formData) await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -7,6 +7,11 @@
<!-- 表格头部 --> <!-- 表格头部 -->
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData"> <ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left> <template #left>
<span v-if="totalCoinChange !== null" class="table-summary-inline">
{{ $t('page.toolbar.coinChangeSummary') }}<strong :class="coinSummaryClass">{{
formatMoney2(totalCoinChange)
}}</strong>
</span>
<!-- <ElSpace wrap>--> <!-- <ElSpace wrap>-->
<!-- <ElButton--> <!-- <ElButton-->
<!-- v-permission="'dice:player_wallet_record:index:save'"--> <!-- v-permission="'dice:player_wallet_record:index:save'"-->
@@ -83,6 +88,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { useTable } from '@/hooks/core/useTable' import { useTable } from '@/hooks/core/useTable'
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
import { useSaiAdmin } from '@/composables/useSaiAdmin' import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/player_wallet_record/index' import api from '../../api/player_wallet_record/index'
import TableSearch from './modules/table-search.vue' import TableSearch from './modules/table-search.vue'
@@ -97,15 +103,55 @@
create_time: undefined as [string, string] | undefined create_time: undefined as [string, string] | undefined
}) })
// 搜索处理:将 create_time 区间转为 create_time_min / create_time_max /** 当前筛选条件下平台币变化合计 */
const handleSearch = (params: Record<string, any>) => { const totalCoinChange = ref<number | null>(null)
const coinSummaryClass = computed(() => {
if (totalCoinChange.value === null) return ''
if (totalCoinChange.value > 0) return 'coin-summary-positive'
if (totalCoinChange.value < 0) return 'coin-summary-negative'
return ''
})
const WALLET_SEARCH_KEYS = [
'type',
'username',
'coin_min',
'coin_max',
'create_time_min',
'create_time_max'
] as const
let summaryRequestSeq = 0
const listApi = async (params: Record<string, any>) => {
const reqId = ++summaryRequestSeq
const res = await api.list(params)
if (reqId === summaryRequestSeq) {
const summary = (res as Record<string, unknown> | undefined)?.total_coin_change
totalCoinChange.value =
summary !== undefined && summary !== null && summary !== '' ? Number(summary) : null
}
return res
}
const applySearchParams = (params: Record<string, any>) => {
const p = { ...params } const p = { ...params }
if (Array.isArray(p.create_time) && p.create_time.length === 2) { if (Array.isArray(p.create_time) && p.create_time.length === 2) {
p.create_time_min = p.create_time[0] p.create_time_min = p.create_time[0]
p.create_time_max = p.create_time[1] p.create_time_max = p.create_time[1]
} }
delete p.create_time delete p.create_time
const paramsRecord = searchParams as Record<string, unknown>
WALLET_SEARCH_KEYS.forEach((key) => {
delete paramsRecord[key]
})
Object.assign(searchParams, p) Object.assign(searchParams, p)
}
// 搜索处理:将 create_time 区间转为 create_time_min / create_time_max
const handleSearch = (params: Record<string, any>) => {
applySearchParams(params)
getData() getData()
} }
@@ -169,8 +215,9 @@
refreshData refreshData
} = useTable({ } = useTable({
core: { core: {
apiFn: api.list, apiFn: listApi,
apiParams: { limit: 100 }, apiParams: { limit: 100 },
excludeParams: ['create_time'],
columnsFactory: () => [ columnsFactory: () => [
{ type: 'selection', align: 'center' }, { type: 'selection', align: 'center' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' }, { prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
@@ -231,6 +278,25 @@
useSlot: true useSlot: true
} }
] ]
},
hooks: {
onSuccess(_data, response) {
const raw = response as unknown as Record<string, unknown>
const summary = raw?.total_coin_change
if (summary !== undefined && summary !== null && summary !== '') {
totalCoinChange.value = Number(summary)
}
}
},
transform: {
responseAdapter(response) {
const raw = (response ?? {}) as Record<string, unknown>
const base = defaultResponseAdapter(response)
if (raw.total_coin_change !== undefined && raw.total_coin_change !== null) {
;(base as Record<string, unknown>).total_coin_change = raw.total_coin_change
}
return base
}
} }
}) })
@@ -248,6 +314,25 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.table-summary-inline {
margin-right: 12px;
font-size: 14px;
color: var(--el-text-color-regular);
white-space: nowrap;
}
.table-summary-inline strong {
font-weight: 600;
}
.coin-summary-positive {
color: var(--el-color-success);
}
.coin-summary-negative {
color: var(--el-color-danger);
}
/* 类型 tag 放大一倍large + scale */ /* 类型 tag 放大一倍large + scale */
:deep(.wallet-record-type-tag) { :deep(.wallet-record-type-tag) {
transform: scale(0.8); transform: scale(0.8);

View File

@@ -92,6 +92,7 @@
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/player_wallet_record/index' import api from '../../../api/player_wallet_record/index'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
@@ -127,9 +128,9 @@
}) })
const rules = reactive<FormRules>({ const rules = reactive<FormRules>({
player_id: [{ required: true, message: '请选择用户', trigger: 'change' }], player_id: [{ required: true, message: t('page.form.ruleUserRequired'), trigger: 'change' }],
coin: [{ required: true, message: '平台币变化必填', trigger: 'blur' }], coin: [{ required: true, message: t('page.form.ruleCoinRequired'), trigger: 'blur' }],
type: [{ required: true, message: '请选择类型', trigger: 'change' }] type: [{ required: true, message: t('page.form.ruleTypeRequired'), trigger: 'change' }]
}) })
const initialFormData: { const initialFormData: {
@@ -188,7 +189,7 @@
if (open) { if (open) {
initPage() initPage()
try { try {
const list = await api.getPlayerOptions() const list = await api.getPlayerOptions(getChannelDeptRequestParams())
playerOptions.value = Array.isArray(list) ? list : [] playerOptions.value = Array.isArray(list) ? list : []
} catch { } catch {
playerOptions.value = [] playerOptions.value = []
@@ -237,10 +238,10 @@
calcWalletAfter() calcWalletAfter()
const payload = { ...formData } const payload = { ...formData }
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(payload) await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(payload) await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -46,17 +46,25 @@
</ElCard> </ElCard>
<WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" /> <WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" />
<WeightTestDialog v-model="weightTestVisible" @success="refreshData" /> <WeightTestDialog
v-model="weightTestVisible"
:channel-dept-id="channelDeptId"
@success="refreshData"
/>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useTable } from '@/hooks/core/useTable' import { useTable } from '@/hooks/core/useTable'
import { useInjectedChannelDept } from '@/composables/useChannelDeptScope'
import api from '../../api/reward/index' import api from '../../api/reward/index'
import TableSearch from './modules/table-search.vue' import TableSearch from './modules/table-search.vue'
import WeightRatioDialog from './modules/weight-ratio-dialog.vue' import WeightRatioDialog from './modules/weight-ratio-dialog.vue'
import WeightTestDialog from './modules/weight-test-dialog.vue' import WeightTestDialog from './modules/weight-test-dialog.vue'
const channelScope = useInjectedChannelDept()
const channelDeptId = computed(() => channelScope?.selectedDeptId.value)
const currentDirection = ref<0 | 1>(0) const currentDirection = ref<0 | 1>(0)
const weightRatioVisible = ref(false) const weightRatioVisible = ref(false)
const weightTestVisible = ref(false) const weightTestVisible = ref(false)

View File

@@ -262,6 +262,7 @@
} }
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -447,7 +448,7 @@
function loadData() { function loadData() {
loading.value = true loading.value = true
api api
.weightRatioListWithDirection() .weightRatioListWithDirection(getChannelDeptRequestParams())
.then((res: any) => { .then((res: any) => {
grouped.value = parsePayload(res) grouped.value = parsePayload(res)
}) })
@@ -483,7 +484,7 @@
} }
submitting.value = true submitting.value = true
api api
.batchUpdateWeights(items) .batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => { .then(() => {
ElMessage.success(t('page.weightShared.saveSuccess')) ElMessage.success(t('page.weightShared.saveSuccess'))
emit('success') emit('success')

View File

@@ -319,6 +319,7 @@
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue' import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
function formatMoney2(val: unknown): string { function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-' if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val) const n = typeof val === 'number' ? val : Number(val)
@@ -482,7 +483,7 @@
function loadData() { function loadData() {
loading.value = true loading.value = true
api api
.weightRatioListWithDirection() .weightRatioListWithDirection(getChannelDeptRequestParams())
.then((res: any) => { .then((res: any) => {
grouped.value = parsePayload(res) grouped.value = parsePayload(res)
}) })
@@ -521,7 +522,7 @@
} }
submitting.value = true submitting.value = true
api api
.batchUpdateWeights(items) .batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => { .then(() => {
ElMessage.success(t('page.weightShared.saveSuccess')) ElMessage.success(t('page.weightShared.saveSuccess'))
emit('success') emit('success')

View File

@@ -2,43 +2,65 @@
<ElDialog <ElDialog
v-model="visible" v-model="visible"
:title="$t('page.weightTest.title')" :title="$t('page.weightTest.title')"
width="560px" width="920px"
top="4vh"
class="weight-test-dialog"
:close-on-click-modal="false" :close-on-click-modal="false"
destroy-on-close destroy-on-close
@close="onClose" @close="onClose"
> >
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip"> <div class="weight-test-dialog-body">
<template #title>{{ $t('page.weightTest.alertTitle') }}</template> <ElAlert type="info" :closable="false" show-icon class="weight-test-tip compact-tip">
{{ $t('page.weightTest.alertBody') }} <div class="tip-lines">
<div>{{ $t('page.weightTest.alertBody') }}</div>
<div>{{ $t('page.weightTest.chainModeHint') }}</div>
<div>{{ $t('page.weightTest.killModeHint') }}</div>
</div>
</ElAlert> </ElAlert>
<ElAlert type="warning" :closable="false" show-icon class="weight-test-tip chain-tip">
{{ $t('page.weightTest.chainModeHint') }} <ElForm :model="form" label-width="108px" class="weight-test-form">
</ElAlert> <ElRow :gutter="16">
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip chain-tip"> <ElCol :span="8">
{{ $t('page.weightTest.killModeHint') }} <ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante_config_id" required>
</ElAlert> <ElSelect
<ElForm :model="form" label-width="140px"> v-model="form.ante_config_id"
<ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante" required> :placeholder="$t('page.weightTest.placeholderAnte')"
<ElInputNumber v-model="form.ante" :min="1" :step="1" style="width: 100%" /> filterable
style="width: 100%"
@change="syncAnteFromSelect"
>
<ElOption
v-for="item in anteOptions"
:key="item.id"
:label="anteOptionLabel(item)"
:value="item.id"
/>
</ElSelect>
</ElFormItem> </ElFormItem>
</ElCol>
<ElCol :span="8">
<ElFormItem :label="$t('page.weightTest.labelKillModeEnabled')" prop="kill_mode_enabled"> <ElFormItem :label="$t('page.weightTest.labelKillModeEnabled')" prop="kill_mode_enabled">
<ElSwitch v-model="form.kill_mode_enabled" /> <ElSwitch v-model="form.kill_mode_enabled" />
</ElFormItem> </ElFormItem>
</ElCol>
<ElCol :span="8">
<ElFormItem :label="$t('page.weightTest.labelTestSafetyLine')" prop="test_safety_line"> <ElFormItem :label="$t('page.weightTest.labelTestSafetyLine')" prop="test_safety_line">
<ElInputNumber <ElInputNumber
v-model="form.test_safety_line" v-model="form.test_safety_line"
:min="0" :min="0"
:step="100" :step="100"
:disabled="!form.kill_mode_enabled" :disabled="!form.kill_mode_enabled"
controls-position="right"
style="width: 100%" style="width: 100%"
/> />
</ElFormItem> </ElFormItem>
</ElCol>
</ElRow>
<ElRow :gutter="20" class="section-row">
<ElCol :span="12">
<div class="section-title">{{ $t('page.weightTest.sectionPaid') }}</div> <div class="section-title">{{ $t('page.weightTest.sectionPaid') }}</div>
<ElFormItem <ElFormItem :label="$t('page.weightTest.labelLotteryTypePaid')" prop="paid_lottery_config_id">
:label="$t('page.weightTest.labelLotteryTypePaid')"
prop="paid_lottery_config_id"
>
<ElSelect <ElSelect
v-model="form.paid_lottery_config_id" v-model="form.paid_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderPaidPool')" :placeholder="$t('page.weightTest.placeholderPaidPool')"
@@ -56,7 +78,7 @@
</ElFormItem> </ElFormItem>
<template v-if="form.paid_lottery_config_id == null"> <template v-if="form.paid_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div> <div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
<ElRow :gutter="12" class="tier-row"> <ElRow :gutter="8" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8"> <ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
<div class="tier-field"> <div class="tier-field">
<label class="tier-field-label">{{ <label class="tier-field-label">{{
@@ -93,15 +115,14 @@
:placeholder="$t('page.weightTest.placeholderSelect')" :placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%" style="width: 100%"
> >
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" /> <ElOption v-for="c in countOptions" :key="'n-' + c" :label="String(c)" :value="c" />
</ElSelect> </ElSelect>
</ElFormItem> </ElFormItem>
</ElCol>
<ElCol :span="12">
<div class="section-title">{{ $t('page.weightTest.sectionFreeAfterPlayAgain') }}</div> <div class="section-title">{{ $t('page.weightTest.sectionFreeAfterPlayAgain') }}</div>
<ElFormItem <ElFormItem :label="$t('page.weightTest.labelLotteryTypeFree')" prop="free_lottery_config_id">
:label="$t('page.weightTest.labelLotteryTypeFree')"
prop="free_lottery_config_id"
>
<ElSelect <ElSelect
v-model="form.free_lottery_config_id" v-model="form.free_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderFreePool')" :placeholder="$t('page.weightTest.placeholderFreePool')"
@@ -119,7 +140,7 @@
</ElFormItem> </ElFormItem>
<template v-if="form.free_lottery_config_id == null"> <template v-if="form.free_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHintFreeChain') }}</div> <div class="tier-label">{{ $t('page.weightTest.tierProbHintFreeChain') }}</div>
<ElRow :gutter="12" class="tier-row"> <ElRow :gutter="8" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8"> <ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
<div class="tier-field"> <div class="tier-field">
<label class="tier-field-label">{{ <label class="tier-field-label">{{
@@ -141,7 +162,10 @@
$t('page.weightTest.tierSumError', { sum: freeTierSum }) $t('page.weightTest.tierSumError', { sum: freeTierSum })
}}</div> }}</div>
</template> </template>
</ElCol>
</ElRow>
</ElForm> </ElForm>
</div>
<template #footer> <template #footer>
<ElButton <ElButton
@@ -160,11 +184,23 @@
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/reward/index' import api from '../../../api/reward/index'
import anteConfigApi from '../../../api/ante_config/index'
import lotteryPoolApi from '../../../api/lottery_pool_config/index' import lotteryPoolApi from '../../../api/lottery_pool_config/index'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import {
getChannelDeptRequestParams,
useInjectedChannelDept,
withChannelDeptParams
} from '@/composables/useChannelDeptScope'
const props = defineProps<{
/** 父页面渠道栏选中值(弹窗 teleport 后 inject 可能失效) */
channelDeptId?: number
}>()
const { t } = useI18n() const { t } = useI18n()
const channelScope = useInjectedChannelDept()
const countOptions = [0, 100, 500, 1000, 5000] const countOptions = [0, 100, 500, 1000, 5000]
const tierKeys = ['T1', 'T2', 'T3', 'T4', 'T5'] as const const tierKeys = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
@@ -172,8 +208,13 @@
const visible = defineModel<boolean>({ default: false }) const visible = defineModel<boolean>({ default: false })
const emit = defineEmits<{ (e: 'success'): void }>() const emit = defineEmits<{ (e: 'success'): void }>()
const anteOptions = ref<
Array<{ id: number; name: string; title: string; mult: number; is_default: number }>
>([])
const form = reactive({ const form = reactive({
ante: 1, ante: 1,
ante_config_id: undefined as number | undefined,
paid_lottery_config_id: undefined as number | undefined, paid_lottery_config_id: undefined as number | undefined,
free_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>, paid_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
@@ -184,11 +225,9 @@
test_safety_line: 5000 test_safety_line: 5000
}) })
const lotteryOptions = ref<Array<{ id: number; name: string }>>([]) const lotteryOptions = ref<Array<{ id: number; name: string }>>([])
/** 付费抽奖券可选档位name=default */
const paidLotteryOptions = computed(() => const paidLotteryOptions = computed(() =>
lotteryOptions.value.filter((r) => r.name === 'default') lotteryOptions.value.filter((r) => r.name === 'default')
) )
/** 免费抽奖券可选档位:优先 name=killScore若无则显示全部以便下拉有选项 */
const freeLotteryOptions = computed(() => { const freeLotteryOptions = computed(() => {
const list = lotteryOptions.value.filter((r) => r.name === 'killScore') const list = lotteryOptions.value.filter((r) => r.name === 'killScore')
return list.length > 0 ? list : lotteryOptions.value return list.length > 0 ? list : lotteryOptions.value
@@ -230,9 +269,61 @@
tierKeys.reduce((s, t) => s + (form.free_tier_weights[t] ?? 0), 0) tierKeys.reduce((s, t) => s + (form.free_tier_weights[t] ?? 0), 0)
) )
function resolveDeptParams(): { dept_id?: number } {
if (props.channelDeptId !== undefined && props.channelDeptId !== null) {
return { dept_id: props.channelDeptId }
}
const extra = getChannelDeptRequestParams()
if (extra.dept_id !== undefined) {
return extra
}
if (channelScope) {
return { dept_id: channelScope.selectedDeptId.value }
}
return {}
}
function resolveSubmitDeptId(): number | undefined {
const params = resolveDeptParams()
if (params.dept_id !== undefined) {
return params.dept_id
}
return undefined
}
function anteOptionLabel(item: { name: string; title: string; mult: number }): string {
const label = (item.title || item.name || '').trim()
return label ? `${label} (×${item.mult})` : `×${item.mult}`
}
function syncAnteFromSelect() {
const opt = anteOptions.value.find((o) => o.id === form.ante_config_id)
if (opt) {
form.ante = opt.mult
}
}
async function loadAnteOptions() {
try {
const list = await anteConfigApi.getOptions(resolveDeptParams())
anteOptions.value = list
const def = list.find((i) => i.is_default === 1) ?? list[0]
if (def) {
form.ante_config_id = def.id
form.ante = def.mult
} else {
form.ante_config_id = undefined
form.ante = 1
}
} catch {
anteOptions.value = []
form.ante_config_id = undefined
}
}
async function loadLotteryOptions() { async function loadLotteryOptions() {
try { try {
const list = await lotteryPoolApi.getOptions() const list = await lotteryPoolApi.getOptions(resolveDeptParams())
lotteryOptions.value = list.map((r: { id: number; name: string }) => ({ lotteryOptions.value = list.map((r: { id: number; name: string }) => ({
id: r.id, id: r.id,
name: r.name name: r.name
@@ -255,6 +346,7 @@
function buildPayload() { function buildPayload() {
const payload: Record<string, unknown> = { const payload: Record<string, unknown> = {
ante: form.ante, ante: form.ante,
ante_config_id: form.ante_config_id,
paid_s_count: form.paid_s_count, paid_s_count: form.paid_s_count,
paid_n_count: form.paid_n_count, paid_n_count: form.paid_n_count,
free_s_count: 0, free_s_count: 0,
@@ -277,6 +369,11 @@
} }
function validateForm(): boolean { function validateForm(): boolean {
if (form.ante_config_id == null || form.ante_config_id <= 0) {
ElMessage.warning(t('page.weightTest.warnAnte'))
return false
}
syncAnteFromSelect()
if (form.ante == null || form.ante <= 0) { if (form.ante == null || form.ante <= 0) {
ElMessage.warning(t('page.weightTest.warnAnte')) ElMessage.warning(t('page.weightTest.warnAnte'))
return false return false
@@ -320,7 +417,12 @@
if (!validateForm()) return if (!validateForm()) return
running.value = true running.value = true
try { try {
await api.startWeightTest(buildPayload()) const payload = buildPayload()
const deptId = resolveSubmitDeptId()
if (deptId !== undefined) {
payload.dept_id = deptId
}
await api.startWeightTest(withChannelDeptParams(payload))
ElMessage.success(t('page.weightTest.successCreated')) ElMessage.success(t('page.weightTest.successCreated'))
visible.value = false visible.value = false
emit('success') emit('success')
@@ -333,73 +435,122 @@
watch(visible, (v) => { watch(visible, (v) => {
if (v) { if (v) {
loadLotteryOptions() void loadAnteOptions()
void loadLotteryOptions()
} else { } else {
onClose() onClose()
} }
}) })
watch(
() => props.channelDeptId ?? channelScope?.selectedDeptId.value,
() => {
if (visible.value) {
void loadAnteOptions()
void loadLotteryOptions()
}
}
)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.weight-test-tip { .weight-test-dialog-body {
margin-bottom: 16px; max-height: calc(100vh - 168px);
overflow: visible;
} }
.chain-tip {
margin-top: -8px; .compact-tip {
margin-bottom: 12px;
:deep(.el-alert__content) {
line-height: 1.45;
} }
}
.tip-lines {
font-size: 12px;
color: var(--el-text-color-regular);
div + div {
margin-top: 4px;
}
}
.weight-test-form {
:deep(.el-form-item) {
margin-bottom: 12px;
}
}
.section-row {
margin-top: 4px;
}
.section-title { .section-title {
font-size: 14px; font-size: 13px;
font-weight: 600; font-weight: 600;
color: var(--el-text-color-primary); color: var(--el-text-color-primary);
margin: 8px 0 12px; margin: 0 0 10px;
padding-bottom: 6px; padding-bottom: 4px;
border-bottom: 1px solid var(--el-border-color-lighter); border-bottom: 1px solid var(--el-border-color-lighter);
} }
.tier-label { .tier-label {
font-size: 13px; font-size: 12px;
color: var(--el-text-color-secondary); color: var(--el-text-color-secondary);
margin-bottom: 6px;
}
.tier-row {
margin-bottom: 8px; margin-bottom: 8px;
} }
.tier-row {
margin-bottom: 12px;
}
.tier-field { .tier-field {
margin-bottom: 12px; margin-bottom: 6px;
} }
.tier-field-label { .tier-field-label {
display: block; display: block;
font-size: 14px; font-size: 12px;
color: var(--el-text-color-regular); color: var(--el-text-color-regular);
margin-bottom: 4px; margin-bottom: 2px;
line-height: 1.5; line-height: 1.4;
} }
.tier-input { .tier-input {
display: block; display: block;
width: 100%; width: 100%;
padding: 8px 12px; padding: 4px 8px;
font-size: 14px; font-size: 13px;
line-height: 1.5; line-height: 1.4;
color: var(--el-text-color-regular); color: var(--el-text-color-regular);
background-color: var(--el-fill-color-blank); background-color: var(--el-fill-color-blank);
border: 1px solid var(--el-border-color); border: 1px solid var(--el-border-color);
border-radius: var(--el-border-radius-base); border-radius: var(--el-border-radius-base);
box-sizing: border-box; box-sizing: border-box;
} }
.tier-input:hover { .tier-input:hover {
border-color: var(--el-border-color-hover); border-color: var(--el-border-color-hover);
} }
.tier-input:focus { .tier-input:focus {
outline: none; outline: none;
border-color: var(--el-color-primary); border-color: var(--el-color-primary);
box-shadow: 0 0 0 2px var(--el-color-primary-light-7); box-shadow: 0 0 0 2px var(--el-color-primary-light-7);
} }
.tier-input::placeholder {
color: var(--el-text-color-placeholder);
}
.tier-error { .tier-error {
font-size: 12px; font-size: 12px;
color: var(--el-color-danger); color: var(--el-color-danger);
margin-top: 4px; margin-bottom: 6px;
margin-bottom: 8px; }
</style>
<style lang="scss">
.weight-test-dialog.el-dialog {
margin-bottom: 4vh;
}
.weight-test-dialog .el-dialog__body {
padding-top: 12px;
padding-bottom: 8px;
} }
</style> </style>

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="art-full-height reward-config-form"> <div class="reward-config-form flex-1 min-h-0 flex flex-col">
<ElCard shadow="never" class="form-card"> <ElCard shadow="never" class="form-card flex-1 min-h-0 flex flex-col">
<template #header> <template #header>
<div class="card-header"> <div class="card-header">
<span>{{ $t('page.toolbar.gameRewardConfig') }}</span> <span>{{ $t('page.toolbar.gameRewardConfig') }}</span>
@@ -446,6 +446,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {
DEFAULT_CHANNEL_ID,
getChannelDeptRequestParams,
useChannelDeptReload,
useInjectedChannelDept
} from '@/composables/useChannelDeptScope'
import { useWindowSize } from '@vueuse/core' import { useWindowSize } from '@vueuse/core'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
@@ -484,6 +490,21 @@
weight: number weight: number
} }
const channelScope = useInjectedChannelDept()
const filterDeptId = computed(() => {
const scopedId = channelScope?.selectedDeptId.value
if (scopedId !== undefined && scopedId !== null) {
if (scopedId > 0 || channelScope?.showDefaultTemplate.value) {
return scopedId
}
}
const extra = getChannelDeptRequestParams()
if (extra.dept_id !== undefined) {
return extra.dept_id
}
return DEFAULT_CHANNEL_ID
})
const activeTab = ref<'index' | 'bigwin'>('index') const activeTab = ref<'index' | 'bigwin'>('index')
const loading = ref(false) const loading = ref(false)
const savingIndex = ref(false) const savingIndex = ref(false)
@@ -506,15 +527,6 @@
const REWARD_INDEX_MAX = 25 const REWARD_INDEX_MAX = 25
const ALLOWED_INDEX_TIERS = ['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'] as const const ALLOWED_INDEX_TIERS = ['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'] as const
function isAllowedIndexTier(s: string): boolean {
for (let i = 0; i < ALLOWED_INDEX_TIERS.length; i++) {
if (ALLOWED_INDEX_TIERS[i] === s) {
return true
}
}
return false
}
/** 第一页数据(来自 api.list即 DiceRewardConfig 表) */ /** 第一页数据(来自 api.list即 DiceRewardConfig 表) */
const indexRows = ref<IndexRow[]>([]) const indexRows = ref<IndexRow[]>([])
/** 奖励索引 Tab排除 tier=BIGWIN仅显示 T1T5 */ /** 奖励索引 Tab排除 tier=BIGWIN仅显示 T1T5 */
@@ -524,6 +536,15 @@
/** 原始 list 快照,用于重置 */ /** 原始 list 快照,用于重置 */
let indexRowsSnapshot: IndexRow[] = [] let indexRowsSnapshot: IndexRow[] = []
function isAllowedIndexTier(s: string): boolean {
for (let i = 0; i < ALLOWED_INDEX_TIERS.length; i++) {
if (ALLOWED_INDEX_TIERS[i] === s) {
return true
}
}
return false
}
function toWeight(v: unknown): number { function toWeight(v: unknown): number {
const n = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v) const n = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
if (Number.isNaN(n)) return 0 if (Number.isNaN(n)) return 0
@@ -584,7 +605,7 @@
} }
createRewardLoading.value = true createRewardLoading.value = true
try { try {
const res: any = await api.createRewardReference() const res: any = await api.createRewardReference({ dept_id: filterDeptId.value as number })
const data = res?.data ?? res const data = res?.data ?? res
let msg = t('page.configPage.createRefSuccessSimple') let msg = t('page.configPage.createRefSuccessSimple')
if (typeof data === 'object' && data !== null) { if (typeof data === 'object' && data !== null) {
@@ -608,15 +629,28 @@
} }
} }
function extractIndexList(res: unknown): Record<string, unknown>[] {
if (Array.isArray(res)) {
return res as Record<string, unknown>[]
}
if (res && typeof res === 'object') {
const obj = res as Record<string, unknown>
if (Array.isArray(obj.data)) {
return obj.data as Record<string, unknown>[]
}
if (Array.isArray(obj.records)) {
return obj.records as Record<string, unknown>[]
}
}
return []
}
function loadIndexList() { function loadIndexList() {
loading.value = true loading.value = true
return api return api
.list({ limit: 200 }) .list({ saiType: 'all', limit: 200, dept_id: filterDeptId.value })
.then((res: any) => { .then((res: unknown) => {
const list = res?.data?.records ?? res?.records ?? res?.data ?? [] const rows = extractIndexList(res).map((r) => normalizeIndexRow(r))
const rows = Array.isArray(list)
? list.map((r: Record<string, unknown>) => normalizeIndexRow(r))
: []
indexRows.value = rows indexRows.value = rows
indexRowsSnapshot = rows.map((r) => ({ ...r })) indexRowsSnapshot = rows.map((r) => ({ ...r }))
}) })
@@ -628,6 +662,17 @@
}) })
} }
/** 挂载时拉数;超管切换左侧渠道时重新拉数 */
useChannelDeptReload(loadIndexList)
watch(
() => filterDeptId.value,
(deptId, prev) => {
if (deptId !== prev) {
loadIndexList()
}
}
)
function isBigwinWeightDisabled(row: IndexRow): boolean { function isBigwinWeightDisabled(row: IndexRow): boolean {
return row.grid_number === 5 || row.grid_number === 30 return row.grid_number === 5 || row.grid_number === 30
} }
@@ -805,7 +850,7 @@
remark: r.remark remark: r.remark
}) })
) )
await api.batchUpdate(indexPayload) await api.batchUpdate(indexPayload, { dept_id: filterDeptId.value })
ElMessage.success( ElMessage.success(
t('page.configPage.ruleGenSuccess', { t('page.configPage.ruleGenSuccess', {
cwT1: sc.cw.T1, cwT1: sc.cw.T1,
@@ -854,7 +899,7 @@
tier: r.tier, tier: r.tier,
remark: r.remark remark: r.remark
})) }))
await api.batchUpdate(indexPayload) await api.batchUpdate(indexPayload, { dept_id: filterDeptId.value })
ElMessage.success(t('page.configPage.saveSuccess')) ElMessage.success(t('page.configPage.saveSuccess'))
indexRowsSnapshot = indexRows.value.map((r) => ({ ...r })) indexRowsSnapshot = indexRows.value.map((r) => ({ ...r }))
} catch (e: any) { } catch (e: any) {
@@ -915,14 +960,14 @@
tier: r.tier, tier: r.tier,
remark: r.remark remark: r.remark
})) }))
await api.batchUpdate(batchPayload) await api.batchUpdate(batchPayload, { dept_id: filterDeptId.value })
const weightItems = rows.map((r) => ({ const weightItems = rows.map((r) => ({
grid_number: r.grid_number, grid_number: r.grid_number,
weight: isBigwinWeightDisabled(r) weight: isBigwinWeightDisabled(r)
? 10000 ? 10000
: Math.max(0, Math.min(10000, Math.floor(r.weight))) : Math.max(0, Math.min(10000, Math.floor(r.weight)))
})) }))
await api.saveBigwinWeightsByGrid(weightItems) await api.saveBigwinWeightsByGrid(weightItems, { dept_id: filterDeptId.value })
ElMessage.success(t('page.configPage.saveSuccess')) ElMessage.success(t('page.configPage.saveSuccess'))
loadIndexList() loadIndexList()
} catch (e: any) { } catch (e: any) {
@@ -938,9 +983,6 @@
ElMessage.info(t('page.configPage.resetBigwinReloaded')) ElMessage.info(t('page.configPage.resetBigwinReloaded'))
} }
onMounted(() => {
loadIndexList()
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -83,6 +83,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@@ -229,10 +230,10 @@
delete payload.weight delete payload.weight
} }
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(payload) await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(payload) await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -173,6 +173,7 @@
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue' import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n() const { t } = useI18n()
@@ -360,7 +361,7 @@
function loadData() { function loadData() {
api api
.weightRatioList() .weightRatioList(getChannelDeptRequestParams())
.then((res: any) => { .then((res: any) => {
grouped.value = parseWeightRatioPayload(res) grouped.value = parseWeightRatioPayload(res)
}) })
@@ -393,7 +394,7 @@
} }
submitting.value = true submitting.value = true
api api
.batchUpdateWeights(items) .batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => { .then(() => {
ElMessage.success(t('page.weightRatio.saveSuccess')) ElMessage.success(t('page.weightRatio.saveSuccess'))
emit('success') emit('success')

View File

@@ -30,6 +30,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@@ -137,10 +138,10 @@
try { try {
await formRef.value.validate() await formRef.value.validate()
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(withChannelDeptParams(formData))
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(formData) await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -1,10 +1,8 @@
<template> <template>
<div class="art-full-height"> <div class="art-full-height">
<!-- 搜索面板 -->
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" /> <TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never"> <ElCard class="art-table-card" shadow="never">
<!-- 表格头部 -->
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData"> <ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left> <template #left>
<ElSpace wrap> <ElSpace wrap>
@@ -14,30 +12,22 @@
</template> </template>
{{ $t('table.actions.add') }} {{ $t('table.actions.add') }}
</ElButton> </ElButton>
<ElButton @click="toggleExpand" v-ripple> <ElButton v-permission="'core:dept:update'" @click="handleSyncConfigs" v-ripple>
<template #icon> 补齐渠道配置
<ArtSvgIcon v-if="isExpanded" icon="ri:collapse-diagonal-line" />
<ArtSvgIcon v-else icon="ri:expand-diagonal-line" />
</template>
{{ isExpanded ? $t('table.searchBar.collapse') : $t('table.searchBar.expand') }}
</ElButton> </ElButton>
</ElSpace> </ElSpace>
</template> </template>
</ArtTableHeader> </ArtTableHeader>
<!-- 表格 -->
<ArtTable <ArtTable
ref="tableRef"
rowKey="id" rowKey="id"
:loading="loading" :loading="loading"
:data="data" :data="data"
:columns="columns" :columns="columns"
:default-expand-all="true"
@sort-change="handleSortChange" @sort-change="handleSortChange"
@pagination:size-change="handleSizeChange" @pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange" @pagination:current-change="handleCurrentChange"
> >
<!-- 操作列 -->
<template #operation="{ row }"> <template #operation="{ row }">
<div class="flex gap-2"> <div class="flex gap-2">
<SaButton <SaButton
@@ -48,20 +38,26 @@
<SaButton <SaButton
v-permission="'core:dept:destroy'" v-permission="'core:dept:destroy'"
type="error" type="error"
@click="deleteRow(row, api.delete, refreshData)" @click="openDeleteDialog(row)"
/> />
</div> </div>
</template> </template>
</ArtTable> </ArtTable>
</ElCard> </ElCard>
<!-- 编辑弹窗 -->
<EditDialog <EditDialog
v-model="dialogVisible" v-model="dialogVisible"
:dialog-type="dialogType" :dialog-type="dialogType"
:data="dialogData" :data="dialogData"
@success="refreshData" @success="refreshData"
/> />
<DeleteChannelDialog
v-model="deleteDialogVisible"
:dept-id="deleteDeptId"
:dept-name="deleteDeptName"
@success="refreshData"
/>
</div> </div>
</template> </template>
@@ -69,27 +65,26 @@
import { useTable } from '@/hooks/core/useTable' import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin' import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '@/api/system/dept' import api from '@/api/system/dept'
import { ElMessage } from 'element-plus'
import TableSearch from './modules/table-search.vue' import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue' import EditDialog from './modules/edit-dialog.vue'
import DeleteChannelDialog from './modules/delete-channel-dialog.vue'
// 状态管理
const isExpanded = ref(true)
const tableRef = ref()
// 搜索表单
const searchForm = ref({ const searchForm = ref({
name: undefined, name: undefined,
code: undefined, code: undefined,
status: undefined status: undefined
}) })
// 搜索处理 const deleteDialogVisible = ref(false)
const deleteDeptId = ref<number | null>(null)
const deleteDeptName = ref('')
const handleSearch = (params: Record<string, any>) => { const handleSearch = (params: Record<string, any>) => {
Object.assign(searchParams, params) Object.assign(searchParams, params)
getData() getData()
} }
// 表格配置
const { const {
columns, columns,
columnChecks, columnChecks,
@@ -118,26 +113,20 @@
} }
}) })
// 编辑配置 const { dialogType, dialogVisible, dialogData, showDialog } = useSaiAdmin()
const { dialogType, dialogVisible, dialogData, showDialog, deleteRow } = useSaiAdmin()
/** const openDeleteDialog = (row: any) => {
* 切换展开/收起所有菜单 deleteDeptId.value = row.id
*/ deleteDeptName.value = row.name
const toggleExpand = (): void => { deleteDialogVisible.value = true
isExpanded.value = !isExpanded.value
nextTick(() => {
if (tableRef.value?.elTableRef && data.value) {
const processRows = (rows: any[]) => {
rows.forEach((row) => {
if (row.children?.length) {
tableRef.value.elTableRef.toggleRowExpansion(row, isExpanded.value)
processRows(row.children)
} }
})
const handleSyncConfigs = async () => {
try {
await api.syncChannelConfigs()
ElMessage.success('已为缺失配置的渠道补齐默认配置')
} catch (e: any) {
ElMessage.error(e?.message || '补齐失败')
} }
processRows(data.value)
}
})
} }
</script> </script>

View File

@@ -0,0 +1,115 @@
<template>
<el-dialog
v-model="visible"
title="删除渠道"
width="560px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<div v-loading="loading">
<p class="mb-3 text-sm text-gray-600">确定删除渠道{{ deptName }}可勾选一并删除的关联数据</p>
<el-alert
v-if="preview?.user_count > 0"
type="error"
:closable="false"
class="mb-3"
:title="`该渠道下仍有 ${preview.user_count} 个用户,请先转移或删除用户`"
/>
<el-checkbox-group v-model="checkedTables" class="flex flex-col gap-2">
<el-checkbox
v-for="item in preview?.relations || []"
:key="item.table"
:label="item.table"
:disabled="preview?.user_count > 0"
>
{{ item.label }}{{ item.count }}
</el-checkbox>
</el-checkbox-group>
<p v-if="!preview?.relations?.length" class="text-sm text-gray-500">无关联业务数据仅删除渠道本身</p>
</div>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button
type="danger"
:loading="submitting"
:disabled="preview?.user_count > 0"
@click="handleConfirm"
>
确认删除
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '@/api/system/dept'
import { ElMessage } from 'element-plus'
interface Props {
modelValue: boolean
deptId?: number | null
deptName?: string
}
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
deptId: null,
deptName: ''
})
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}>()
const visible = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v)
})
const loading = ref(false)
const submitting = ref(false)
const preview = ref<any>(null)
const checkedTables = ref<string[]>([])
watch(
() => props.modelValue,
async (open) => {
if (!open || !props.deptId) {
return
}
loading.value = true
checkedTables.value = []
try {
const res: any = await api.destroyPreview(props.deptId)
const list = res?.data ?? res
preview.value = Array.isArray(list) ? list[0] : list
checkedTables.value = (preview.value?.relations || []).map((r: any) => r.table)
} finally {
loading.value = false
}
}
)
const handleClose = () => {
visible.value = false
}
const handleConfirm = async () => {
if (!props.deptId) {
return
}
submitting.value = true
try {
await api.delete({ ids: props.deptId, delete_tables: checkedTables.value })
ElMessage.success('删除成功')
emit('success')
handleClose()
} catch (e: any) {
ElMessage.error(e?.message || '删除失败')
} finally {
submitting.value = false
}
}
</script>

View File

@@ -8,15 +8,6 @@
@close="handleClose" @close="handleClose"
> >
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form-item :label="$t('page.form.labelParentDept')" prop="parent_id">
<el-tree-select
v-model="formData.parent_id"
:data="optionData.treeData"
:render-after-expand="false"
check-strictly
clearable
/>
</el-form-item>
<el-form-item :label="$t('page.form.labelDeptName')" prop="name"> <el-form-item :label="$t('page.form.labelDeptName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderDeptName')" /> <el-input v-model="formData.name" :placeholder="$t('page.form.placeholderDeptName')" />
</el-form-item> </el-form-item>
@@ -75,36 +66,21 @@
const { t } = useI18n() const { t } = useI18n()
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const optionData = reactive({
treeData: <any[]>[]
})
/**
* 弹窗显示状态双向绑定
*/
const visible = computed({ const visible = computed({
get: () => props.modelValue, get: () => props.modelValue,
set: (value) => emit('update:modelValue', value) set: (value) => emit('update:modelValue', value)
}) })
/**
* 表单验证规则
*/
const rules = computed<FormRules>(() => ({ const rules = computed<FormRules>(() => ({
parent_id: [
{ required: true, message: t('page.form.ruleParentDeptRequired'), trigger: 'change' }
],
name: [{ required: true, message: t('page.form.ruleDeptNameRequired'), trigger: 'blur' }], name: [{ required: true, message: t('page.form.ruleDeptNameRequired'), trigger: 'blur' }],
code: [{ required: true, message: t('page.form.ruleDeptCodeRequired'), trigger: 'blur' }] code: [{ required: true, message: t('page.form.ruleDeptCodeRequired'), trigger: 'blur' }]
})) }))
/**
* 初始数据
*/
const initialFormData = { const initialFormData = {
id: null, id: null,
parent_id: null, parent_id: 0,
level: '', level: '0',
name: '', name: '',
code: '', code: '',
leader_id: null, leader_id: null,
@@ -113,14 +89,8 @@
status: 1 status: 1
} }
/**
* 表单数据
*/
const formData = reactive({ ...initialFormData }) const formData = reactive({ ...initialFormData })
/**
* 监听弹窗打开,初始化表单数据
*/
watch( watch(
() => props.modelValue, () => props.modelValue,
(newVal) => { (newVal) => {
@@ -130,33 +100,14 @@
} }
) )
/**
* 初始化页面数据
*/
const initPage = async () => { const initPage = async () => {
// 先重置为初始值
Object.assign(formData, initialFormData) Object.assign(formData, initialFormData)
const data = await api.list({ tree: true })
optionData.treeData = [
{
id: 0,
value: 0,
label: t('page.form.noParentDept'),
children: data
}
]
// 如果有数据,则填充数据
if (props.data) { if (props.data) {
await nextTick() await nextTick()
initForm() initForm()
} }
} }
/**
* 初始化表单数据
*/
const initForm = () => { const initForm = () => {
if (props.data) { if (props.data) {
for (const key in formData) { for (const key in formData) {
@@ -167,21 +118,17 @@
} }
} }
/**
* 关闭弹窗并重置表单
*/
const handleClose = () => { const handleClose = () => {
visible.value = false visible.value = false
formRef.value?.resetFields() formRef.value?.resetFields()
} }
/**
* 提交表单
*/
const handleSubmit = async () => { const handleSubmit = async () => {
if (!formRef.value) return if (!formRef.value) return
try { try {
await formRef.value.validate() await formRef.value.validate()
formData.parent_id = 0
formData.level = '0'
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(formData)
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))

View File

@@ -1,142 +0,0 @@
<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="'core:post:save'" @click="showDialog('add')" v-ripple>
<template #icon>
<ArtSvgIcon icon="ri:add-fill" />
</template>
{{ $t('table.actions.add') }}
</ElButton>
<ElButton
v-permission="'core:post:destroy'"
:disabled="selectedRows.length === 0"
@click="deleteSelectedRows(api.delete, refreshData)"
v-ripple
>
<template #icon>
<ArtSvgIcon icon="ri:delete-bin-5-line" />
</template>
{{ $t('table.actions.delete') }}
</ElButton>
<SaImport
v-permission="'core:post:import'"
download-url="/core/post/downloadTemplate"
upload-url="/core/post/import"
@success="refreshData"
/>
<SaExport v-permission="'core:post:export'" url="/core/post/export" />
</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="'core:post:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<SaButton
v-permission="'core:post: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/system/post'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
// 搜索表单
const searchForm = ref({
name: undefined,
code: undefined,
status: 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: 'id', label: 'table.columns.common.no', width: 100, align: 'center' },
{ prop: 'name', label: 'page.table.postName', minWidth: 120 },
{ prop: 'code', label: 'page.table.postCode', minWidth: 120 },
{ prop: 'remark', label: 'table.columns.common.description', minWidth: 150, showOverflowTooltip: true },
{ prop: 'sort', label: 'page.table.sort', width: 100 },
{ prop: 'status', label: 'page.table.status', saiType: 'dict', saiDict: 'data_status', width: 100 },
{ prop: 'create_time', label: 'page.table.createTime', width: 180, sortable: true },
{ prop: 'operation', label: 'table.actions.operation', width: 100, fixed: 'right', useSlot: true }
]
}
})
// 编辑配置
const {
dialogType,
dialogVisible,
dialogData,
showDialog,
deleteRow,
deleteSelectedRows,
handleSelectionChange,
selectedRows
} = useSaiAdmin()
</script>

View File

@@ -1,166 +0,0 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
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="$t('page.form.labelName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderName')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelCode')" prop="code">
<el-input v-model="formData.code" :placeholder="$t('page.form.placeholderCode')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelRemark')" prop="remark">
<el-input
v-model="formData.remark"
type="textarea"
:rows="3"
:placeholder="$t('page.form.placeholderRemark')"
/>
</el-form-item>
<el-form-item :label="$t('page.form.labelSort')" prop="sort">
<el-input-number v-model="formData.sort" :placeholder="$t('page.form.placeholderSort')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelStatus')" prop="status">
<sa-radio v-model="formData.status" dict="data_status" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '@/api/system/post'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
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 { t } = useI18n()
const formRef = ref<FormInstance>()
/**
* 弹窗显示状态双向绑定
*/
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
/**
* 表单验证规则
*/
const rules = computed<FormRules>(() => ({
name: [{ required: true, message: t('page.form.ruleNameRequired'), trigger: 'blur' }],
code: [{ required: true, message: t('page.form.ruleCodeRequired'), trigger: 'blur' }]
}))
/**
* 初始数据
*/
const initialFormData = {
id: null,
name: '',
code: '',
remark: '',
sort: 100,
status: 1
}
/**
* 表单数据
*/
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(t('page.form.addSuccess'))
} else {
await api.update(formData)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log('表单验证失败:', error)
}
}
</script>

View File

@@ -1,77 +0,0 @@
<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="$t('page.search.postName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.search.placeholderPostName')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.postCode')" prop="code">
<el-input v-model="formData.code" :placeholder="$t('page.search.placeholderPostCode')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.status')" prop="status">
<sa-select v-model="formData.status" dict="data_status" :placeholder="$t('page.search.searchSelectPlaceholder')" 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>

View File

@@ -41,6 +41,7 @@
<script setup lang="ts"> <script setup lang="ts">
import api from '@/api/system/role' import api from '@/api/system/role'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
@@ -155,11 +156,12 @@
if (!formRef.value) return if (!formRef.value) return
try { try {
await formRef.value.validate() await formRef.value.validate()
const payload = withChannelDeptParams({ ...formData })
if (props.dialogType === 'add') { if (props.dialogType === 'add') {
await api.save(formData) await api.save(payload)
ElMessage.success(t('page.form.addSuccess')) ElMessage.success(t('page.form.addSuccess'))
} else { } else {
await api.update(formData) await api.update(payload)
ElMessage.success(t('page.form.editSuccess')) ElMessage.success(t('page.form.editSuccess'))
} }
emit('success') emit('success')

View File

@@ -1,16 +1,24 @@
<template> <template>
<div class="art-full-height"> <div class="art-full-height">
<div class="box-border flex gap-4 h-full max-md:block max-md:gap-0 max-md:h-auto"> <div class="box-border flex gap-4 h-full max-md:block max-md:gap-0 max-md:h-auto">
<div class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5"> <div
<ElCard class="tree-card art-card-xs flex flex-col h-full mt-0" shadow="never"> v-show="showChannelSidebar"
class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5"
>
<ElCard
class="tree-card art-card-xs flex flex-col h-full mt-0"
shadow="never"
v-loading="channelTreeLoading"
>
<template #header> <template #header>
<b>部门列表</b> <b>{{ $t('page.ui.channelList') }}</b>
</template> </template>
<ElScrollbar> <ElScrollbar>
<ElTree <ElTree
:data="treeData" :data="treeData"
:props="{ children: 'children', label: 'label' }" :props="{ children: 'children', label: 'label' }"
node-key="id" node-key="id"
:current-node-key="currentChannelId"
default-expand-all default-expand-all
highlight-current highlight-current
@node-click="handleNodeClick" @node-click="handleNodeClick"
@@ -136,10 +144,19 @@
import WorkDialog from './modules/work-dialog.vue' import WorkDialog from './modules/work-dialog.vue'
import api from '@/api/system/user' import api from '@/api/system/user'
import deptApi from '@/api/system/dept' import deptApi from '@/api/system/dept'
import { isSuperAdminUser } from '@/utils/channelLayout'
const userStore = useUserStore() const userStore = useUserStore()
const treeData = ref([]) interface ChannelTreeNode {
id: number
label: string
children?: ChannelTreeNode[]
}
const treeData = ref<ChannelTreeNode[]>([])
const channelTreeLoading = ref(false)
const currentChannelId = ref<number | undefined>(undefined)
// 编辑框 // 编辑框
const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange, deleteRow } = const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange, deleteRow } =
@@ -228,24 +245,79 @@
const handleReset = () => { const handleReset = () => {
searchForm.value.dept_id = undefined searchForm.value.dept_id = undefined
resetSearchParams() resetSearchParams()
if (isSuperAdminUser()) {
currentChannelId.value = undefined
} else {
applyDefaultChannelSelection()
}
} }
/** /**
* 切换部门 * 切换部门
* @param data * @param data
*/ */
const handleNodeClick = (data: any) => { const handleNodeClick = (data: ChannelTreeNode) => {
currentChannelId.value = data.id
searchParams.dept_id = data.id searchParams.dept_id = data.id
getData() getData()
} }
/** /** 仅超管显示左侧渠道列表;渠道管理员固定本渠道,由后端过滤 */
* 获取部门数据 const showChannelSidebar = computed(() => isSuperAdminUser())
*/
const getDeptList = () => { const normalizeChannelTree = (list: unknown[]): ChannelTreeNode[] => {
deptApi.accessDept().then((data: any) => { if (!Array.isArray(list)) {
treeData.value = data return []
}
return list
.map((item) => {
const row = item as Record<string, unknown>
const id = Number(row.id ?? row.value ?? 0)
const label = String(row.label ?? row.name ?? '')
return { id, label }
}) })
.filter((node) => node.id > 0 && node.label !== '')
}
const fallbackChannelTree = (): ChannelTreeNode[] => {
const dept = userStore.info?.department
if (!dept || Number(dept.id) <= 0) {
return []
}
return [
{
id: Number(dept.id),
label: String(dept.name ?? '')
}
]
}
const applyDefaultChannelSelection = () => {
if (treeData.value.length === 0 || isSuperAdminUser()) {
return
}
const first = treeData.value[0]
currentChannelId.value = first.id
searchParams.dept_id = first.id
getData()
}
/**
* 获取可操作渠道(渠道管理员至少展示本渠道)
*/
const getDeptList = async () => {
channelTreeLoading.value = true
try {
const data = await deptApi.accessDept()
const nodes = normalizeChannelTree(Array.isArray(data) ? data : [])
treeData.value = nodes.length > 0 ? nodes : fallbackChannelTree()
applyDefaultChannelSelection()
} catch {
treeData.value = fallbackChannelTree()
applyDefaultChannelSelection()
} finally {
channelTreeLoading.value = false
}
} }
/** /**
@@ -283,6 +355,10 @@
} }
onMounted(() => { onMounted(() => {
if (isSuperAdminUser()) {
getDeptList() getDeptList()
} else {
applyDefaultChannelSelection()
}
}) })
</script> </script>

View File

@@ -52,13 +52,14 @@
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('page.form.labelDept')" prop="dept_id"> <el-form-item :label="$t('page.form.labelDept')" prop="dept_id">
<el-tree-select <el-select v-model="formData.dept_id" clearable filterable>
v-model="formData.dept_id" <el-option
:data="optionData.deptData" v-for="item in optionData.deptData"
:render-after-expand="false" :key="item.id"
check-strictly :label="item.label"
clearable :value="item.id"
/> />
</el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
@@ -76,18 +77,6 @@
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="12">
<el-form-item :label="$t('page.form.labelPost')" prop="post_ids">
<el-select v-model="formData.post_ids" multiple clearable>
<el-option
v-for="post in optionData.postList"
:key="(post as any)?.id"
:value="(post as any)?.id"
:label="(post as any)?.name"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item :label="$t('page.form.labelGender')" prop="gender"> <el-form-item :label="$t('page.form.labelGender')" prop="gender">
<sa-radio v-model="formData.gender" dict="gender" valueType="string" /> <sa-radio v-model="formData.gender" dict="gender" valueType="string" />
@@ -129,7 +118,6 @@
import api from '@/api/system/user' import api from '@/api/system/user'
import deptApi from '@/api/system/dept' import deptApi from '@/api/system/dept'
import roleApi from '@/api/system/role' import roleApi from '@/api/system/role'
import postApi from '@/api/system/post'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
@@ -156,8 +144,7 @@
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const optionData = reactive({ const optionData = reactive({
deptData: <any>[], deptData: <any>[],
roleList: <any>[], roleList: <any>[]
postList: <any>[]
}) })
/** /**
@@ -207,7 +194,6 @@
phone: '', phone: '',
email: '', email: '',
role_ids: [], role_ids: [],
post_ids: [],
status: 1, status: 1,
gender: '', gender: '',
remark: '' remark: ''
@@ -221,6 +207,41 @@
/** /**
* 监听弹窗打开,初始化表单数据 * 监听弹窗打开,初始化表单数据
*/ */
const flattenDeptOptions = (list: any[], result: { id: number; label: string }[] = []) => {
for (const item of list) {
const id = item.id ?? item.value
if (id !== undefined && id !== null) {
result.push({
id,
label: String(item.label ?? item.name ?? id)
})
}
if (item.children?.length) {
flattenDeptOptions(item.children, result)
}
}
return result
}
const loadRoleOptions = async () => {
const deptId = formData.dept_id
const params =
deptId !== undefined && deptId !== null && deptId !== ''
? { dept_id: deptId }
: undefined
const roleData = await roleApi.accessRole(params)
optionData.roleList = Array.isArray(roleData) ? roleData : []
}
watch(
() => formData.dept_id,
() => {
if (props.modelValue) {
void loadRoleOptions()
}
}
)
watch( watch(
() => props.modelValue, () => props.modelValue,
(newVal) => { (newVal) => {
@@ -229,33 +250,23 @@
} }
} }
) )
// 初始化页面数据
const initPage = async () => { const initPage = async () => {
// 先重置为初始值 // 先重置为初始值
Object.assign(formData, initialFormData) Object.assign(formData, initialFormData)
// 部门数据
const deptData = await deptApi.accessDept() const deptData = await deptApi.accessDept()
optionData.deptData = deptData optionData.deptData = flattenDeptOptions(Array.isArray(deptData) ? deptData : [])
// 角色数据 // 角色数据
const roleData = await roleApi.accessRole() if (props.data?.id) {
optionData.roleList = roleData
// 岗位数据
const postData = await postApi.accessPost()
optionData.postList = postData
// 如果有数据,则填充数据
if (props.data) {
await nextTick() await nextTick()
if (props.data.id) { const data = await api.read(props.data.id)
let data = await api.read(props.data.id)
if (data.postList) {
const post = (data.postList as any[])?.map((item: any) => item.id)
data.post_ids = post
}
const role = (data.roleList as any[])?.map((item: any) => item.id) const role = (data.roleList as any[])?.map((item: any) => item.id)
data.role_ids = role data.role_ids = role
data.password = '' data.password = ''
initForm(data) initForm(data)
} await loadRoleOptions()
} else {
await loadRoleOptions()
} }
} }

View File

@@ -10,6 +10,7 @@ use support\think\Db;
use app\api\logic\GameLogic; use app\api\logic\GameLogic;
use app\api\logic\PlayStartLogic; use app\api\logic\PlayStartLogic;
use app\api\util\ReturnCode; use app\api\util\ReturnCode;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\config\DiceConfig; use app\dice\model\config\DiceConfig;
use app\dice\model\ante_config\DiceAnteConfig; use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\play_record\DicePlayRecord; use app\dice\model\play_record\DicePlayRecord;
@@ -34,7 +35,12 @@ class GameController extends BaseController
*/ */
public function config(Request $request): Response public function config(Request $request): Response
{ {
$rows = DiceConfig::select('name', 'group', 'title', 'title_en', 'value', 'value_en', 'create_time', 'update_time')->get(); $configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$rows = (new DiceConfig())
->field('name,group,title,title_en,value,value_en,create_time,update_time')
->where('dept_id', $configDeptId)
->select()
->toArray();
$lang = $request->header('lang', 'zh'); $lang = $request->header('lang', 'zh');
if (!is_string($lang) || $lang === '') { if (!is_string($lang) || $lang === '') {
$lang = 'zh'; $lang = 'zh';
@@ -43,15 +49,15 @@ class GameController extends BaseController
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-'); $isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
$data = []; $data = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$group = $row->group ?? ''; $group = $row['group'] ?? '';
if (!isset($data[$group])) { if (!isset($data[$group])) {
$data[$group] = []; $data[$group] = [];
} }
$title = $row->title; $title = $row['title'] ?? '';
$value = $row->value; $value = $row['value'] ?? '';
if ($isEn) { if ($isEn) {
$titleEn = $row->title_en ?? ''; $titleEn = $row['title_en'] ?? '';
$valueEn = $row->value_en ?? ''; $valueEn = $row['value_en'] ?? '';
if ($titleEn !== '') { if ($titleEn !== '') {
$title = $titleEn; $title = $titleEn;
} }
@@ -60,11 +66,11 @@ class GameController extends BaseController
} }
} }
$data[$group][] = [ $data[$group][] = [
'name' => $row->name, 'name' => $row['name'] ?? '',
'title' => $title, 'title' => $title,
'value' => $value, 'value' => $value,
'create_time' => $row->create_time, 'create_time' => $row['create_time'] ?? '',
'update_time' => $row->update_time, 'update_time' => $row['update_time'] ?? '',
]; ];
} }
return $this->success($data); return $this->success($data);
@@ -107,7 +113,8 @@ class GameController extends BaseController
*/ */
public function lotteryPool(Request $request): Response public function lotteryPool(Request $request): Response
{ {
$list = DiceRewardConfig::getCachedList(); $configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$list = DiceRewardConfig::getCachedList($configDeptId);
$list = array_values(array_filter($list, function ($row) { $list = array_values(array_filter($list, function ($row) {
return (string) ($row['tier'] ?? '') !== 'BIGWIN'; return (string) ($row['tier'] ?? '') !== 'BIGWIN';
})); }));
@@ -145,9 +152,9 @@ class GameController extends BaseController
*/ */
public function anteConfig(Request $request): Response public function anteConfig(Request $request): Response
{ {
// 用于后续抽奖校验:在接口中实例化 model后续逻辑可复用相同的数据读取方式。 $configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$anteConfigModel = new DiceAnteConfig(); $anteConfigModel = new DiceAnteConfig();
$rows = $anteConfigModel->order('id', 'asc')->select()->toArray(); $rows = $anteConfigModel->where('dept_id', $configDeptId)->order('id', 'asc')->select()->toArray();
return $this->success($rows); return $this->success($rows);
} }
@@ -200,7 +207,8 @@ class GameController extends BaseController
$rewardTier = array_key_exists('reward_tier', $data) ? (string) ($data['reward_tier'] ?? '') : ''; $rewardTier = array_key_exists('reward_tier', $data) ? (string) ($data['reward_tier'] ?? '') : '';
$targetIndex = array_key_exists('target_index', $data) ? (int) ($data['target_index'] ?? 0) : 0; $targetIndex = array_key_exists('target_index', $data) ? (int) ($data['target_index'] ?? 0) : 0;
if ($rewardTier !== 'BIGWIN' && $targetIndex > 0) { if ($rewardTier !== 'BIGWIN' && $targetIndex > 0) {
$configRow = DiceRewardConfig::getCachedById($targetIndex); $configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$configRow = DiceRewardConfig::getCachedById($targetIndex, $configDeptId);
if ($configRow !== null) { if ($configRow !== null) {
$uiText = ''; $uiText = '';
$uiTextEn = ''; $uiTextEn = '';
@@ -273,4 +281,20 @@ class GameController extends BaseController
Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]); Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]);
} }
} }
/**
* 从 token 注入的 player_id 解析所属渠道配置 ID
*/
private function resolvePlayerConfigDeptIdFromRequest(Request $request): int
{
$userId = (int) ($request->player_id ?? 0);
if ($userId <= 0) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$player = DicePlayer::find($userId);
if (!$player) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
return AdminScopeHelper::resolvePlayerConfigDeptId($player);
}
} }

View File

@@ -36,4 +36,26 @@ return [
'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed', 'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed',
'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted', 'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted',
'OLD_PASSWORD_WRONG' => 'Old password is incorrect', 'OLD_PASSWORD_WRONG' => 'Old password is incorrect',
'ADD_SUCCESS' => 'Added successfully',
'UPDATE_SUCCESS' => 'Updated successfully',
'DELETE_SUCCESS' => 'Deleted successfully',
'ADD_FAILED' => 'Add failed',
'UPDATE_FAILED' => 'Update failed',
'DELETE_FAILED' => 'Delete failed',
'NOT_FOUND' => 'Data not found',
'ANTE_MUST_POSITIVE' => 'Ante must be greater than 0',
'ANTE_NOT_ALLOWED' => 'Ante %s is not available for current channel, please select from ante config',
'ANTE_CONFIG_NOT_FOUND' => 'Ante config not found',
'ANTE_CONFIG_NOT_IN_CHANNEL' => 'Ante config does not belong to current channel',
'POOL_CONFIG_NOT_IN_CHANNEL' => 'Pool config does not belong to current channel',
'CHANNEL_DEPT_ID_REQUIRED' => 'Please select a channel, or assign a valid administrator/player for this record',
'INVALID_CHANNEL_DEPT_ID' => 'Invalid channel. Please reselect channel or administrator',
'PLAYER_USERNAME_DEPT_UNIQUE' => 'Username already exists in this channel',
'NO_PERMISSION_UPDATE' => 'No permission to update this record',
'NO_PERMISSION_VIEW' => 'No permission to view this record',
'NO_PERMISSION_OPERATE_PLAYER' => 'No permission to operate this player',
'PLEASE_SELECT_DATA' => 'Please select data to delete',
'OPERATION_SUCCESS' => 'Operation successful',
'TEST_DATA_CLEARED' => 'Test data cleared',
'CLEAR_FAILED' => 'Clear failed: %s',
]; ];

View File

@@ -9,6 +9,28 @@ declare(strict_types=1);
return [ return [
'success' => 'Success', 'success' => 'Success',
'fail' => 'Fail', 'fail' => 'Fail',
'add success' => 'Added successfully',
'update success' => 'Updated successfully',
'save success' => 'Saved successfully',
'delete success' => 'Deleted successfully',
'add failed' => 'Add failed',
'update failed' => 'Update failed',
'delete failed' => 'Delete failed',
'not found' => 'Data not found',
'operation success' => 'Operation successful',
'test data cleared' => 'Test data cleared',
'ante must be greater than 0' => 'Ante must be greater than 0',
'ante not allowed: %s' => 'Ante %s is not available for current channel, please select from ante config',
'pool config does not belong to current channel' => 'Pool config does not belong to current channel',
'no permission to update this record' => 'No permission to update this record',
'no permission to view this record' => 'No permission to view this record',
'no permission to operate this player' => 'No permission to operate this player',
'please select data to delete' => 'Please select data to delete',
'please select player' => 'Please select player',
'please login first' => 'Please login first',
'missing player_id' => 'Missing player_id',
'Player not found' => 'Player not found',
'record not found' => 'Record not found',
'username、password 不能为空' => 'username and password are required', 'username、password 不能为空' => 'username and password are required',
'请携带 token' => 'Please provide token', '请携带 token' => 'Please provide token',
'token 无效' => 'Invalid or expired token', 'token 无效' => 'Invalid or expired token',

View File

@@ -36,5 +36,27 @@ return [
'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作', 'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作',
'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除', 'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除',
'OLD_PASSWORD_WRONG' => '原密码错误', 'OLD_PASSWORD_WRONG' => '原密码错误',
'ADD_SUCCESS' => '添加成功',
'UPDATE_SUCCESS' => '修改成功',
'DELETE_SUCCESS' => '删除成功',
'ADD_FAILED' => '添加失败',
'UPDATE_FAILED' => '修改失败',
'DELETE_FAILED' => '删除失败',
'NOT_FOUND' => '数据不存在',
'ANTE_MUST_POSITIVE' => '底注必须大于 0',
'ANTE_NOT_ALLOWED' => '底注 %s 在当前渠道不可用,请从底注配置中选择',
'ANTE_CONFIG_NOT_FOUND' => '底注配置不存在',
'ANTE_CONFIG_NOT_IN_CHANNEL' => '底注配置不属于当前渠道',
'POOL_CONFIG_NOT_IN_CHANNEL' => '奖池配置不属于当前渠道',
'CHANNEL_DEPT_ID_REQUIRED' => '请选择所属渠道,或为记录指定有效的所属管理员/玩家',
'INVALID_CHANNEL_DEPT_ID' => '渠道无效,请重新选择所属渠道或管理员',
'PLAYER_USERNAME_DEPT_UNIQUE' => '该渠道下用户名已存在',
'NO_PERMISSION_UPDATE' => '无权限修改该记录',
'NO_PERMISSION_VIEW' => '无权限查看该记录',
'NO_PERMISSION_OPERATE_PLAYER' => '无权限操作该玩家',
'PLEASE_SELECT_DATA' => '请选择要删除的数据',
'OPERATION_SUCCESS' => '操作成功',
'TEST_DATA_CLEARED' => '测试数据已清空',
'CLEAR_FAILED' => '清空失败:%s',
]; ];

View File

@@ -6,6 +6,7 @@ namespace app\api\logic;
use app\api\cache\UserCache; use app\api\cache\UserCache;
use app\api\util\ApiLang; use app\api\util\ApiLang;
use app\api\service\LotteryService; use app\api\service\LotteryService;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record\DicePlayRecord; use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\ante_config\DiceAnteConfig; use app\dice\model\ante_config\DiceAnteConfig;
@@ -64,6 +65,8 @@ class PlayStartLogic
throw new ApiException('User not found'); throw new ApiException('User not found');
} }
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$coin = (float) $player->coin; $coin = (float) $player->coin;
if ($ante <= 0) { if ($ante <= 0) {
throw new ApiException('ante must be a positive integer'); throw new ApiException('ante must be a positive integer');
@@ -71,7 +74,7 @@ class PlayStartLogic
// 注数合规校验ante 必须存在于 dice_ante_config.mult // 注数合规校验ante 必须存在于 dice_ante_config.mult
$anteConfigModel = new DiceAnteConfig(); $anteConfigModel = new DiceAnteConfig();
$exists = $anteConfigModel->where('mult', $ante)->count(); $exists = $anteConfigModel->where('mult', $ante)->where('dept_id', $configDeptId)->count();
if ($exists <= 0) { if ($exists <= 0) {
throw new ApiException('当前注数不合规,请选择正确的注数'); throw new ApiException('当前注数不合规,请选择正确的注数');
} }
@@ -109,8 +112,8 @@ class PlayStartLogic
} }
} }
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find(); $configType0 = DiceLotteryPoolConfig::where('name', 'default')->where('dept_id', $configDeptId)->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find(); $configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->where('dept_id', $configDeptId)->find();
if (!$configType0) { if (!$configType0) {
throw new ApiException('Lottery pool config not found (name=default required)'); throw new ApiException('Lottery pool config not found (name=default required)');
} }
@@ -120,7 +123,7 @@ class PlayStartLogic
// 游玩前余额校验(按 T4 惩罚最大值兜底): // 游玩前余额校验(按 T4 惩罚最大值兜底):
// 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante // 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante
$t4List = DiceRewardConfig::getCachedByTier('T4'); $t4List = DiceRewardConfig::getCachedByTier('T4', $configDeptId);
$t4MinRealEv = null; $t4MinRealEv = null;
foreach ($t4List as $row) { foreach ($t4List as $row) {
$ev = $row['real_ev'] ?? null; $ev = $row['real_ev'] ?? null;
@@ -155,7 +158,7 @@ class PlayStartLogic
: $configType0; : $configType0;
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number // 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
$rewardInstance = DiceReward::getCachedInstance(); $rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? []; $byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10; $maxTierRetry = 10;
$chosen = null; $chosen = null;
@@ -216,7 +219,7 @@ class PlayStartLogic
$superWinCoin = 0.0; $superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber); $rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else { } else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber); $bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true); $alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin; $doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) { if (!$doSuperWin) {
@@ -639,9 +642,9 @@ class PlayStartLogic
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重 * @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率 * @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率
*/ */
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null): array public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null, ?int $configDeptId = null): array
{ {
$rewardInstance = DiceReward::getCachedInstance(); $rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? []; $byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10; $maxTierRetry = 10;
$chosen = null; $chosen = null;
@@ -698,7 +701,7 @@ class PlayStartLogic
$superWinCoin = 0.0; $superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber); $rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else { } else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber); $bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true); $alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin; $doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) { if (!$doSuperWin) {

View File

@@ -5,7 +5,6 @@ namespace app\api\logic;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
use app\api\cache\UserCache; use app\api\cache\UserCache;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use Tinywan\Jwt\JwtToken; use Tinywan\Jwt\JwtToken;
@@ -44,46 +43,8 @@ class UserLogic
} }
/** /**
* 根据 parent_id 向上遍历找到顶级部门parent_id=0 * 根据 agent_id 获取同渠道下的所有管理员 ID 列表
*/ * 用于 getGameUrl 接口判断 DicePlayer 是否属于该渠道,同渠道下不重复创建玩家
private static function getTopDeptIdByParentId(int $deptId): ?int
{
$currentId = $deptId;
$visited = [];
while ($currentId > 0 && !isset($visited[$currentId])) {
$visited[$currentId] = true;
$dept = SystemDept::find($currentId);
if (!$dept) {
return null;
}
$parentId = (int) ($dept->parent_id ?? 0);
if ($parentId === 0) {
return $currentId;
}
$currentId = $parentId;
}
return $currentId > 0 ? $currentId : null;
}
/**
* 根据顶级部门 id递归获取其下所有部门 id含自身仅用 id 和 parent_id
*/
private static function getAllDeptIdsUnderTop(int $topId): array
{
$deptIds = [$topId];
$prevCount = 0;
while (count($deptIds) > $prevCount) {
$prevCount = count($deptIds);
$children = SystemDept::whereIn('parent_id', $deptIds)->column('id');
$deptIds = array_unique(array_merge($deptIds, array_map('intval', $children)));
}
return array_values($deptIds);
}
/**
* 根据 agent_id 获取当前管理员所在顶级部门下的所有管理员 ID 列表
* 使用 SystemDept 的 id 和 parent_id 字段遍历:先向上找顶级部门(parent_id=0),再向下收集所有子部门
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该部门,同顶级部门下不重复创建玩家
* *
* @param string $agentId 代理标识sa_system_user.agent_id * @param string $agentId 代理标识sa_system_user.agent_id
* @return int[] 管理员 ID 列表,空数组表示未找到或无法解析 * @return int[] 管理员 ID 列表,空数组表示未找到或无法解析
@@ -103,16 +64,8 @@ class UserLogic
return [(int) $admin->id]; return [(int) $admin->id];
} }
$deptId = (int) $deptId; $deptId = (int) $deptId;
$topId = self::getTopDeptIdByParentId($deptId); $adminIds = SystemUser::where('dept_id', $deptId)->column('id');
if ($topId === null) { return array_map('intval', $adminIds ?: [(int) $admin->id]);
return [(int) $admin->id];
}
$deptIds = self::getAllDeptIdsUnderTop($topId);
if (empty($deptIds)) {
$deptIds = [$deptId];
}
$adminIds = SystemUser::whereIn('dept_id', $deptIds)->column('id');
return array_map('intval', $adminIds);
} }
/** /**
@@ -155,6 +108,10 @@ class UserLogic
$player->coin = $coin; $player->coin = $coin;
if ($adminId !== null && $adminId > 0) { if ($adminId !== null && $adminId > 0) {
$player->admin_id = $adminId; $player->admin_id = $adminId;
$adminUser = SystemUser::find($adminId);
if ($adminUser && !empty($adminUser->dept_id)) {
$player->dept_id = $adminUser->dept_id;
}
} }
$player->save(); $player->save();
} }

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace app\dice\basic;
use plugin\saiadmin\basic\think\BaseLogic;
/**
* 大富翁逻辑层基类:删除均为硬删除
*/
class DiceBaseLogic extends BaseLogic
{
/**
* @param mixed $ids
*/
public function destroy($ids): bool
{
return $this->model->destroy($ids, true);
}
}

View File

@@ -7,8 +7,10 @@ use app\dice\helper\AdminScopeHelper;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord; use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\play_record\DicePlayRecord; use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response; use support\Response;
use support\think\Db; use support\think\Db;
@@ -21,7 +23,7 @@ class DiceDashboardController extends BaseController
* 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比) * 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比)
*/ */
#[Permission('工作台数据统计', 'core:console:list')] #[Permission('工作台数据统计', 'core:console:list')]
public function statistics(): Response public function statistics(Request $request): Response
{ {
$thisWeekStart = date('Y-m-d 00:00:00', strtotime('monday this week')); $thisWeekStart = date('Y-m-d 00:00:00', strtotime('monday this week'));
$thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week')); $thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week'));
@@ -29,11 +31,12 @@ class DiceDashboardController extends BaseController
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week')); $lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
$adminInfo = $this->adminInfo ?? null; $adminInfo = $this->adminInfo ?? null;
$filterDeptId = $request->input('dept_id');
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]); $playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]); $playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo); AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo); AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo, $filterDeptId);
$playerThis = $playerQueryThis->count(); $playerThis = $playerQueryThis->count();
$playerLast = $playerQueryLast->count(); $playerLast = $playerQueryLast->count();
@@ -43,8 +46,8 @@ class DiceDashboardController extends BaseController
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0) $chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
->where('coin', '>', 0) ->where('coin', '>', 0)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]); ->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo); AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo); AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo, $filterDeptId);
$chargeThis = $chargeQueryThis->sum('coin'); $chargeThis = $chargeQueryThis->sum('coin');
$chargeLast = $chargeQueryLast->sum('coin'); $chargeLast = $chargeQueryLast->sum('coin');
@@ -52,15 +55,15 @@ class DiceDashboardController extends BaseController
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]); ->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1) $withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]); ->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo); AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo); AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo, $filterDeptId);
$withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)')); $withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)'));
$withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)')); $withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)'));
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]); $playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]); $playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo); AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo); AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo, $filterDeptId);
$playThis = $playQueryThis->count(); $playThis = $playQueryThis->count();
$playLast = $playQueryLast->count(); $playLast = $playQueryLast->count();
@@ -85,13 +88,11 @@ class DiceDashboardController extends BaseController
* 近期玩家充值统计近10天每日充值金额 * 近期玩家充值统计近10天每日充值金额
*/ */
#[Permission('工作台数据统计', 'core:console:list')] #[Permission('工作台数据统计', 'core:console:list')]
public function rechargeChart(): Response public function rechargeChart(Request $request): Response
{ {
$adminInfo = $this->adminInfo ?? null; $adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo); $deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
$adminCondition = ''; if ($deptCondition === '__empty__') {
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$data = []; $data = [];
foreach (range(0, 9) as $n) { foreach (range(0, 9) as $n) {
$data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0]; $data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0];
@@ -102,9 +103,6 @@ class DiceDashboardController extends BaseController
'recharge_date' => array_column($data, 'recharge_date'), 'recharge_date' => array_column($data, 'recharge_date'),
]); ]);
} }
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = " $sql = "
SELECT SELECT
d.date AS recharge_date, d.date AS recharge_date,
@@ -116,7 +114,7 @@ class DiceDashboardController extends BaseController
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
) d ) d
LEFT JOIN dice_player_wallet_record w LEFT JOIN dice_player_wallet_record w
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$adminCondition} ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY d.date GROUP BY d.date
ORDER BY d.date ASC ORDER BY d.date ASC
"; ";
@@ -131,13 +129,11 @@ class DiceDashboardController extends BaseController
* 月度玩家充值汇总当年1-12月每月充值金额 * 月度玩家充值汇总当年1-12月每月充值金额
*/ */
#[Permission('工作台数据统计', 'core:console:list')] #[Permission('工作台数据统计', 'core:console:list')]
public function rechargeBarChart(): Response public function rechargeBarChart(Request $request): Response
{ {
$adminInfo = $this->adminInfo ?? null; $adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo); $deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
$adminCondition = ''; if ($deptCondition === '__empty__') {
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$data = []; $data = [];
for ($m = 1; $m <= 12; $m++) { for ($m = 1; $m <= 12; $m++) {
$data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0]; $data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0];
@@ -147,9 +143,6 @@ class DiceDashboardController extends BaseController
'recharge_month' => array_column($data, 'recharge_month'), 'recharge_month' => array_column($data, 'recharge_month'),
]); ]);
} }
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = " $sql = "
SELECT SELECT
CONCAT(LPAD(m.month_num, 2, '0'), '月') AS recharge_month, CONCAT(LPAD(m.month_num, 2, '0'), '月') AS recharge_month,
@@ -162,7 +155,7 @@ class DiceDashboardController extends BaseController
LEFT JOIN dice_player_wallet_record w LEFT JOIN dice_player_wallet_record w
ON YEAR(w.create_time) = YEAR(CURDATE()) ON YEAR(w.create_time) = YEAR(CURDATE())
AND MONTH(w.create_time) = m.month_num AND MONTH(w.create_time) = m.month_num
AND w.type = 0 AND w.coin > 0 {$adminCondition} AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY m.month_num GROUP BY m.month_num
ORDER BY m.month_num ASC ORDER BY m.month_num ASC
"; ";
@@ -178,7 +171,7 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time) * 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time)
*/ */
#[Permission('工作台数据统计', 'core:console:list')] #[Permission('工作台数据统计', 'core:console:list')]
public function walletRecordList(): Response public function walletRecordList(Request $request): Response
{ {
$adminInfo = $this->adminInfo ?? null; $adminInfo = $this->adminInfo ?? null;
$query = DicePlayerWalletRecord::with([ $query = DicePlayerWalletRecord::with([
@@ -189,7 +182,7 @@ class DiceDashboardController extends BaseController
->where('type', 0) ->where('type', 0)
->order('create_time', 'desc') ->order('create_time', 'desc')
->limit(50); ->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo); AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select(); $list = $query->select();
$rows = []; $rows = [];
foreach ($list as $row) { foreach ($list as $row) {
@@ -208,13 +201,13 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count) * 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count)
*/ */
#[Permission('工作台数据统计', 'core:console:list')] #[Permission('工作台数据统计', 'core:console:list')]
public function newPlayerList(): Response public function newPlayerList(Request $request): Response
{ {
$adminInfo = $this->adminInfo ?? null; $adminInfo = $this->adminInfo ?? null;
$query = DicePlayer::field('username,coin,total_ticket_count,create_time') $query = DicePlayer::field('username,coin,total_ticket_count,create_time')
->order('create_time', 'desc') ->order('create_time', 'desc')
->limit(50); ->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo); AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select(); $list = $query->select();
$rows = []; $rows = [];
foreach ($list as $row) { foreach ($list as $row) {
@@ -222,11 +215,66 @@ class DiceDashboardController extends BaseController
'name' => $row->getAttr('username'), 'name' => $row->getAttr('username'),
'coin' => $row->getAttr('coin'), 'coin' => $row->getAttr('coin'),
'total_ticket_count' => $row->getAttr('total_ticket_count'), 'total_ticket_count' => $row->getAttr('total_ticket_count'),
'create_time' => $row->getAttr('create_time'),
]; ];
} }
return $this->success($rows); return $this->success($rows);
} }
/**
* 工作台-玩家游玩记录最新50条
* 返回:玩家账号、中奖档位、赢取平台币、游玩时间
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function playRecordList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayRecord::with([
'dicePlayer' => function ($q) {
$q->field('id,username');
},
])
->where('status', 1)
->field('id,player_id,reward_tier,win_coin,create_time')
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$tierLabels = $this->buildRewardTierLabels();
$rows = [];
foreach ($list as $row) {
$player = $row->dicePlayer;
$tier = $row->getAttr('reward_tier');
$rows[] = [
'player_name' => $player ? $player->getAttr('username') : '',
'reward_tier' => $tier,
'reward_tier_label' => $tierLabels[$tier] ?? $tier,
'win_coin' => $row->getAttr('win_coin'),
'create_time' => $row->getAttr('create_time'),
];
}
return $this->success($rows);
}
/**
* @return array<string, string>
*/
private function buildRewardTierLabels(): array
{
$rows = DiceRewardConfig::field('tier,ui_text')->select();
$labels = [];
foreach ($rows as $row) {
$tier = $row->getAttr('tier');
if ($tier === '' || $tier === null) {
continue;
}
if (!isset($labels[$tier])) {
$labels[$tier] = $row->getAttr('ui_text') ?: $tier;
}
}
return $labels;
}
private function calcWeekChange($current, $last): float private function calcWeekChange($current, $last): float
{ {
if ($last == 0) { if ($last == 0) {
@@ -234,4 +282,23 @@ class DiceDashboardController extends BaseController
} }
return round((($current - $last) / $last) * 100, 1); return round((($current - $last) / $last) * 100, 1);
} }
/**
* 钱包流水 SQL 渠道条件;非超管无渠道时返回 __empty__
*/
private function buildWalletSqlDeptCondition(?array $adminInfo, $requestDeptId): string
{
if (AdminScopeHelper::getDeptId($adminInfo) !== null) {
$deptId = AdminScopeHelper::getDeptId($adminInfo);
if ($deptId <= 0) {
return '__empty__';
}
return ' AND w.dept_id = ' . $deptId;
}
$target = AdminScopeHelper::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
return ' AND w.dept_id = ' . $target;
}
return '';
}
} }

View File

@@ -6,7 +6,9 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\ante_config; namespace app\dice\controller\ante_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\ante_config\DiceAnteConfigLogic; use app\dice\logic\ante_config\DiceAnteConfigLogic;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\validate\ante_config\DiceAnteConfigValidate; use app\dice\validate\ante_config\DiceAnteConfigValidate;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
@@ -34,10 +36,32 @@ class DiceAnteConfigController extends BaseController
['is_default', ''], ['is_default', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
} }
/**
* 底注下拉选项(按渠道),供一键测试权重等使用
*/
#[Permission('底注配置列表', 'dice:ante_config:index:index')]
public function getOptions(Request $request): Response
{
$query = DiceAnteConfig::field('id,name,title,mult,is_default')->order('mult', 'asc')->order('id', 'asc');
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(static function ($item) {
return [
'id' => (int) $item['id'],
'name' => (string) ($item['name'] ?? ''),
'title' => (string) ($item['title'] ?? ''),
'mult' => (int) ($item['mult'] ?? 0),
'is_default' => (int) ($item['is_default'] ?? 0),
];
})->toArray();
return $this->success($data);
}
#[Permission('底注配置读取', 'dice:ante_config:index:read')] #[Permission('底注配置读取', 'dice:ante_config:index:read')]
public function read(Request $request): Response public function read(Request $request): Response
{ {
@@ -52,6 +76,7 @@ class DiceAnteConfigController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
return $result ? $this->success('add success') : $this->fail('add failed'); return $result ? $this->success('add success') : $this->fail('add failed');
} }
@@ -60,8 +85,19 @@ class DiceAnteConfigController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
return $result ? $this->success('update success') : $this->fail('update failed'); return $result ? $this->success('update success') : $this->fail('update failed');
} }

View File

@@ -6,6 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\config; namespace app\dice\controller\config;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use app\dice\logic\config\DiceConfigLogic; use app\dice\logic\config\DiceConfigLogic;
use app\dice\validate\config\DiceConfigValidate; use app\dice\validate\config\DiceConfigValidate;
@@ -42,6 +43,7 @@ class DiceConfigController extends BaseController
['title', ''], ['title', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
} }
@@ -74,6 +76,7 @@ class DiceConfigController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -91,8 +94,20 @@ class DiceConfigController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');
} else { } else {

View File

@@ -4,6 +4,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\game; namespace app\dice\controller\game;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\game\DiceGameLogic; use app\dice\logic\game\DiceGameLogic;
use app\dice\validate\game\DiceGameValidate; use app\dice\validate\game\DiceGameValidate;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
@@ -33,6 +34,7 @@ class DiceGameController extends BaseController
['status', ''], ['status', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
} }
@@ -54,6 +56,7 @@ class DiceGameController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if (!$result) { if (!$result) {
return $this->fail('add failed'); return $this->fail('add failed');
@@ -65,8 +68,19 @@ class DiceGameController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if (!$result) { if (!$result) {
return $this->fail('update failed'); return $this->fail('update failed');
} }

View File

@@ -7,6 +7,7 @@
namespace app\dice\controller\lottery_pool_config; namespace app\dice\controller\lottery_pool_config;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic; use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate; use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
@@ -37,9 +38,10 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')] #[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(Request $request): Response public function getOptions(Request $request): Response
{ {
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight') $query = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
->order('id', 'asc') ->order('id', 'asc');
->select(); AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return [ return [
'id' => (int) $item['id'], 'id' => (int) $item['id'],
@@ -67,6 +69,7 @@ class DiceLotteryPoolConfigController extends BaseController
['type', ''], ['type', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
} }
@@ -99,6 +102,7 @@ class DiceLotteryPoolConfigController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -116,8 +120,19 @@ class DiceLotteryPoolConfigController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');
} else { } else {
@@ -152,7 +167,8 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')] #[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')]
public function getCurrentPool(Request $request): Response public function getCurrentPool(Request $request): Response
{ {
$data = $this->logic->getCurrentPool(); $deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getCurrentPool($deptId);
return $this->success($data); return $this->success($data);
} }
@@ -163,7 +179,12 @@ class DiceLotteryPoolConfigController extends BaseController
public function updateCurrentPool(Request $request): Response public function updateCurrentPool(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$this->logic->updateCurrentPool($data); if ($data === [] || $data === null) {
$data = $request->all();
}
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$this->logic->updateCurrentPool($data, $deptId);
return $this->success('save success'); return $this->success('save success');
} }
@@ -173,7 +194,8 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')] #[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')]
public function resetProfitAmount(Request $request): Response public function resetProfitAmount(Request $request): Response
{ {
$this->logic->resetProfitAmount(); $deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$this->logic->resetProfitAmount($deptId);
return $this->success('reset success'); return $this->success('reset success');
} }
} }

View File

@@ -53,7 +53,7 @@ class DicePlayRecordController extends BaseController
['direction', ''], ['direction', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with([ $query->with([
'dicePlayer', 'dicePlayer',
'diceLotteryPoolConfig', 'diceLotteryPoolConfig',
@@ -78,7 +78,7 @@ class DicePlayRecordController extends BaseController
public function getPlayerOptions(Request $request): Response public function getPlayerOptions(Request $request): Response
{ {
$query = DicePlayer::field('id,username'); $query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select(); $list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? '']; return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -92,9 +92,15 @@ class DicePlayRecordController extends BaseController
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')] #[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
public function getLotteryConfigOptions(Request $request): Response public function getLotteryConfigOptions(Request $request): Response
{ {
$list = DiceLotteryPoolConfig::field('id,name')->select(); $query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return ['id' => $item['id'], 'name' => $item['name'] ?? '']; return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
})->toArray(); })->toArray();
return $this->success($data); return $this->success($data);
} }
@@ -112,8 +118,7 @@ class DicePlayRecordController extends BaseController
if (!$model) { if (!$model) {
return $this->fail('not found'); return $this->fail('not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to view this record'); return $this->fail('no permission to view this record');
} }
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
@@ -130,6 +135,7 @@ class DicePlayRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -148,6 +154,13 @@ class DicePlayRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data); $this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');

View File

@@ -6,6 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\play_record_test; namespace app\dice\controller\play_record_test;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use app\dice\logic\play_record_test\DicePlayRecordTestLogic; use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
use app\dice\validate\play_record_test\DicePlayRecordTestValidate; use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
@@ -50,6 +51,7 @@ class DicePlayRecordTestController extends BaseController
['roll_number', ''], ['roll_number', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with(['diceLotteryPoolConfig']); $query->with(['diceLotteryPoolConfig']);
// 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和) // 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和)
@@ -92,6 +94,7 @@ class DicePlayRecordTestController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -110,6 +113,13 @@ class DicePlayRecordTestController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data); $this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');

View File

@@ -8,6 +8,7 @@ namespace app\dice\controller\player;
use app\dice\helper\AdminScopeHelper; use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use app\dice\logic\player\DicePlayerLogic; use app\dice\logic\player\DicePlayerLogic;
@@ -42,7 +43,13 @@ class DicePlayerController extends BaseController
#[Permission('玩家列表', 'dice:player:index:index')] #[Permission('玩家列表', 'dice:player:index:index')]
public function getLotteryConfigOptions(Request $request): Response public function getLotteryConfigOptions(Request $request): Response
{ {
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select(); $query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')]; return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
})->toArray(); })->toArray();
@@ -57,12 +64,17 @@ class DicePlayerController extends BaseController
#[Permission('玩家列表', 'dice:player:index:index')] #[Permission('玩家列表', 'dice:player:index:index')]
public function getSystemUserOptions(Request $request): Response public function getSystemUserOptions(Request $request): Response
{ {
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc'); $query = SystemUser::field('id,username,realname,dept_id')->where('status', 1)->order('id', 'asc');
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) { $requestDeptId = AdminScopeHelper::pickRequestDeptId(
$deptList = $this->adminInfo['deptList'] ?? []; $request->input('dept_id'),
if (!empty($deptList)) { $request->all()
$query->auth($deptList); );
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null) {
if ($allowedIds === []) {
return $this->success([]);
} }
$query->whereIn('id', $allowedIds);
} }
$list = $query->select(); $list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
@@ -71,12 +83,89 @@ class DicePlayerController extends BaseController
'id' => (int) $item['id'], 'id' => (int) $item['id'],
'username' => (string) ($item['username'] ?? ''), 'username' => (string) ($item['username'] ?? ''),
'realname' => (string) ($item['realname'] ?? ''), 'realname' => (string) ($item['realname'] ?? ''),
'dept_id' => isset($item['dept_id']) ? (int) $item['dept_id'] : null,
'label' => $label ?: (string) $item['id'], 'label' => $label ?: (string) $item['id'],
]; ];
})->toArray(); })->toArray();
return $this->success($data); return $this->success($data);
} }
/**
* 超管:按渠道树状展示全部管理员;非超管:同 getSystemUserOptions 扁平列表
*/
#[Permission('玩家列表', 'dice:player:index:index')]
public function getSystemUserTreeOptions(Request $request): Response
{
if (!AdminScopeHelper::isSuperAdmin($this->adminInfo ?? null)) {
return $this->getSystemUserOptions($request);
}
$users = SystemUser::field('id,username,realname,dept_id')
->where('status', 1)
->order('id', 'asc')
->select()
->toArray();
$depts = SystemDept::field('id,name')
->where('status', 1)
->order('id', 'asc')
->select()
->toArray();
$deptNameMap = [];
foreach ($depts as $dept) {
$deptNameMap[(int) $dept['id']] = (string) ($dept['name'] ?? $dept['id']);
}
$grouped = [];
$unassigned = [];
foreach ($users as $user) {
$item = [
'id' => (int) $user['id'],
'username' => (string) ($user['username'] ?? ''),
'realname' => (string) ($user['realname'] ?? ''),
'dept_id' => isset($user['dept_id']) ? (int) $user['dept_id'] : null,
];
$label = trim($item['realname']) ?: $item['username'];
$item['label'] = $label ?: (string) $item['id'];
$deptId = $item['dept_id'] ?? 0;
if ($deptId > 0 && isset($deptNameMap[$deptId])) {
if (!isset($grouped[$deptId])) {
$grouped[$deptId] = [];
}
$grouped[$deptId][] = $item;
} else {
$unassigned[] = $item;
}
}
$tree = [];
foreach ($depts as $dept) {
$deptId = (int) $dept['id'];
$children = $grouped[$deptId] ?? [];
if ($children === []) {
continue;
}
$tree[] = [
'id' => 'dept_' . $deptId,
'label' => (string) ($dept['name'] ?? $deptId),
'disabled' => true,
'children' => $children,
];
}
if ($unassigned !== []) {
$tree[] = [
'id' => 'dept_unassigned',
'label' => '__unassigned__',
'disabled' => true,
'children' => $unassigned,
];
}
return $this->success($tree);
}
/** /**
* 数据列表 * 数据列表
* @param Request $request * @param Request $request
@@ -94,7 +183,7 @@ class DicePlayerController extends BaseController
['lottery_config_id', ''], ['lottery_config_id', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with(['diceLotteryPoolConfig']); $query->with(['diceLotteryPoolConfig']);
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
@@ -113,8 +202,7 @@ class DicePlayerController extends BaseController
if (!$model) { if (!$model) {
return $this->fail('not found'); return $this->fail('not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to view this record'); return $this->fail('no permission to view this record');
} }
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
@@ -130,20 +218,32 @@ class DicePlayerController extends BaseController
public function save(Request $request): Response public function save(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data);
// 类型转化
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) { if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
$data['admin_id'] = (int) $this->adminInfo['id']; $data['admin_id'] = (int) $this->adminInfo['id'];
} }
AdminScopeHelper::prepareBusinessSaveData(
$data,
$this->adminInfo ?? null,
$request->input('dept_id'),
$data
);
$this->validate('save', $data);
try {
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result && isset($result['id'])) { } catch (\Throwable $e) {
// 出于安全:删除该玩家缓存,后续 API 按需重建 if (self::isDeptUsernameDuplicateException($e)) {
UserCache::deleteUser($result['id']); return $this->fail('PLAYER_USERNAME_DEPT_UNIQUE');
$player = DicePlayer::find($result['id']); }
throw $e;
}
$playerId = is_array($result) ? ($result['id'] ?? null) : $result;
if ($playerId) {
UserCache::deleteUser($playerId);
$player = DicePlayer::find($playerId);
if ($player && $player->username !== '') { if ($player && $player->username !== '') {
UserCache::deletePlayerByUsername($player->username); UserCache::deletePlayerByUsername($player->username);
} }
return $this->success('add success'); return $this->success('ADD_SUCCESS');
} }
return $this->fail('add failed'); return $this->fail('add failed');
} }
@@ -157,14 +257,16 @@ class DicePlayerController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0); $model = $this->logic->read($data['id'] ?? 0);
if ($model) { if ($model) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to update this record'); return $this->fail('no permission to update this record');
} }
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
$data['dept_id'] = $model->dept_id ?? null;
} }
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
// 出于安全:删除该玩家缓存,后续 API 按需重建 // 出于安全:删除该玩家缓存,后续 API 按需重建
@@ -173,7 +275,7 @@ class DicePlayerController extends BaseController
if ($player && $player->username !== '') { if ($player && $player->username !== '') {
UserCache::deletePlayerByUsername($player->username); UserCache::deletePlayerByUsername($player->username);
} }
return $this->success('update success'); return $this->success('UPDATE_SUCCESS');
} }
return $this->fail('update failed'); return $this->fail('update failed');
} }
@@ -196,8 +298,7 @@ class DicePlayerController extends BaseController
} }
$model = $this->logic->read($id); $model = $this->logic->read($id);
if ($model) { if ($model) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to update this record'); return $this->fail('no permission to update this record');
} }
} }
@@ -227,8 +328,7 @@ class DicePlayerController extends BaseController
if (!$player) { if (!$player) {
return $this->fail('not found'); return $this->fail('not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to view this record'); return $this->fail('no permission to view this record');
} }
if ((int) ($player->status ?? 1) === 0) { if ((int) ($player->status ?? 1) === 0) {
@@ -281,13 +381,12 @@ class DicePlayerController extends BaseController
return $this->fail('please select data to delete'); return $this->fail('please select data to delete');
} }
$ids = is_array($ids) ? $ids : explode(',', (string) $ids); $ids = is_array($ids) ? $ids : explode(',', (string) $ids);
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); $deptId = AdminScopeHelper::getDeptId($this->adminInfo ?? null);
if ($allowedIds !== null) { if ($deptId !== null) {
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id'); $models = $this->logic->model->whereIn('id', $ids)->column('dept_id', 'id');
$validIds = []; $validIds = [];
foreach ($ids as $id) { foreach ($ids as $id) {
$adminId = (int) ($models[$id] ?? 0); if (AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $models[$id] ?? null)) {
if (in_array($adminId, $allowedIds, true)) {
$validIds[] = $id; $validIds[] = $id;
} }
} }
@@ -311,4 +410,17 @@ class DicePlayerController extends BaseController
return $this->fail('delete failed'); return $this->fail('delete failed');
} }
/**
* 判断是否违反 dice_player (dept_id, username) 唯一索引
*/
private static function isDeptUsernameDuplicateException(\Throwable $e): bool
{
$message = $e->getMessage();
if ($message === '') {
return false;
}
return str_contains($message, 'uk_dice_player_dept_username')
|| (str_contains($message, 'Duplicate entry') && str_contains($message, 'username'));
}
} }

View File

@@ -53,7 +53,7 @@ class DicePlayerTicketRecordController extends BaseController
['create_time_max', ''], ['create_time_max', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with([ $query->with([
'dicePlayer', 'dicePlayer',
]); ]);
@@ -70,7 +70,7 @@ class DicePlayerTicketRecordController extends BaseController
public function getPlayerOptions(Request $request): Response public function getPlayerOptions(Request $request): Response
{ {
$query = DicePlayer::field('id,username'); $query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select(); $list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? '']; return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -91,8 +91,7 @@ class DicePlayerTicketRecordController extends BaseController
if (!$model) { if (!$model) {
return $this->fail('not found'); return $this->fail('not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to view this record'); return $this->fail('no permission to view this record');
} }
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
@@ -109,6 +108,7 @@ class DicePlayerTicketRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -127,6 +127,13 @@ class DicePlayerTicketRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data); $this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');

View File

@@ -47,13 +47,18 @@ class DicePlayerWalletRecordController extends BaseController
['create_time_min', ''], ['create_time_min', ''],
['create_time_max', ''], ['create_time_max', ''],
]); ]);
$deptId = $request->input('dept_id');
$totalCoinChange = $this->logic->sumCoinBySearch($where, $this->adminInfo ?? null, $deptId);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $deptId);
$query->with([ $query->with([
'dicePlayer', 'dicePlayer',
'operator', 'operator',
]); ]);
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
$data['total_coin_change'] = $totalCoinChange;
return $this->success($data); return $this->success($data);
} }
@@ -66,7 +71,7 @@ class DicePlayerWalletRecordController extends BaseController
public function getPlayerOptions(Request $request): Response public function getPlayerOptions(Request $request): Response
{ {
$query = DicePlayer::field('id,username'); $query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null); AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select(); $list = $query->select();
$data = $list->map(function ($item) { $data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? '']; return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -87,12 +92,11 @@ class DicePlayerWalletRecordController extends BaseController
if ($playerId === null || $playerId === '') { if ($playerId === null || $playerId === '') {
return $this->fail('missing player_id'); return $this->fail('missing player_id');
} }
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find(); $player = DicePlayer::field('coin,dept_id')->where('id', $playerId)->find();
if (!$player) { if (!$player) {
return $this->fail('Player not found'); return $this->fail('Player not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to operate this player'); return $this->fail('no permission to operate this player');
} }
return $this->success(['wallet_before' => (float) $player['coin']]); return $this->success(['wallet_before' => (float) $player['coin']]);
@@ -111,8 +115,7 @@ class DicePlayerWalletRecordController extends BaseController
if (!$model) { if (!$model) {
return $this->fail('not found'); return $this->fail('not found');
} }
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null); if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to view this record'); return $this->fail('no permission to view this record');
} }
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
@@ -166,13 +169,10 @@ class DicePlayerWalletRecordController extends BaseController
return $this->fail('please login first'); return $this->fail('please login first');
} }
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find(); $player = DicePlayer::field('dept_id')->where('id', $playerId)->find();
if ($player) { if ($player && !AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null, $request->input('dept_id'))) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to operate this player'); return $this->fail('no permission to operate this player');
} }
}
try { try {
$this->logic->adminOperate($data, $adminId); $this->logic->adminOperate($data, $adminId);
@@ -182,6 +182,24 @@ class DicePlayerWalletRecordController extends BaseController
} }
} }
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('玩家钱包流水添加', 'dice:player_wallet_record:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
}
return $this->fail('add failed');
}
/** /**
* 更新数据 * 更新数据
* @param Request $request * @param Request $request
@@ -192,6 +210,13 @@ class DicePlayerWalletRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data); $this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');

View File

@@ -4,6 +4,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\reward; namespace app\dice\controller\reward;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic; use app\dice\logic\reward\DiceRewardLogic;
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic; use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
use app\dice\model\reward\DiceReward; use app\dice\model\reward\DiceReward;
@@ -42,11 +43,18 @@ class DiceRewardController extends BaseController
$orderType = $request->input('orderType', 'asc'); $orderType = $request->input('orderType', 'asc');
$logic = new DiceRewardLogic(); $logic = new DiceRewardLogic();
$data = $logic->getListWithConfig($direction, [ $data = $logic->getListWithConfig(
$direction,
[
'tier' => $tier, 'tier' => $tier,
'orderField' => $orderField, 'orderField' => $orderField,
'orderType' => $orderType, 'orderType' => $orderType,
], $page, $limit); ],
$page,
$limit,
$this->adminInfo ?? null,
$request->input('dept_id')
);
return $this->success($data); return $this->success($data);
} }
@@ -61,8 +69,10 @@ class DiceRewardController extends BaseController
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) { if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
$direction = DiceReward::DIRECTION_CLOCKWISE; $direction = DiceReward::DIRECTION_CLOCKWISE;
} }
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$logic = new DiceRewardLogic(); $logic = new DiceRewardLogic();
$data = $logic->getListGroupedByTierForDirection($direction); $data = $logic->getListGroupedByTierForDirection($direction, $deptId);
return $this->success($data); return $this->success($data);
} }
@@ -74,9 +84,10 @@ class DiceRewardController extends BaseController
#[Permission('奖励对照列表', 'dice:reward:index:index')] #[Permission('奖励对照列表', 'dice:reward:index:index')]
public function weightRatioListWithDirection(Request $request): Response public function weightRatioListWithDirection(Request $request): Response
{ {
DiceReward::refreshCache(); $deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$logic = new DiceRewardLogic(); $logic = new DiceRewardLogic();
$data = $logic->getListGroupedByTierWithDirection(); $data = $logic->getListGroupedByTierWithDirection($deptId);
return $this->success($data); return $this->success($data);
} }
@@ -103,11 +114,14 @@ class DiceRewardController extends BaseController
'chain_free_mode' => $post['chain_free_mode'] ?? null, 'chain_free_mode' => $post['chain_free_mode'] ?? null,
'kill_mode_enabled' => $post['kill_mode_enabled'] ?? null, 'kill_mode_enabled' => $post['kill_mode_enabled'] ?? null,
'test_safety_line' => $post['test_safety_line'] ?? null, 'test_safety_line' => $post['test_safety_line'] ?? null,
'dept_id' => $post['dept_id'] ?? null,
'ante_config_id' => $post['ante_config_id'] ?? null,
]; ];
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null; $adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $post);
try { try {
$logic = new DiceRewardConfigRecordLogic(); $logic = new DiceRewardConfigRecordLogic();
$recordId = $logic->createWeightTestRecord($params, $adminId); $recordId = $logic->createWeightTestRecord($params, $adminId, $this->adminInfo ?? null, $requestDeptId);
return $this->success(['record_id' => $recordId]); return $this->success(['record_id' => $recordId]);
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());
@@ -167,8 +181,9 @@ class DiceRewardController extends BaseController
return $this->fail('parameter items must be an array'); return $this->fail('parameter items must be an array');
} }
try { try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$logic = new DiceRewardLogic(); $logic = new DiceRewardLogic();
$logic->batchUpdateWeights($items); $logic->batchUpdateWeights($items, $deptId);
return $this->success('save success'); return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());
@@ -191,8 +206,9 @@ class DiceRewardController extends BaseController
return $this->fail('parameter items must be an array'); return $this->fail('parameter items must be an array');
} }
try { try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$logic = new DiceRewardLogic(); $logic = new DiceRewardLogic();
$logic->batchUpdateWeightsByDirection($direction, $items); $logic->batchUpdateWeightsByDirection($direction, $items, $deptId);
return $this->success('save success'); return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());

View File

@@ -6,9 +6,11 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\controller\reward_config; namespace app\dice\controller\reward_config;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use app\dice\logic\reward_config\DiceRewardConfigLogic; use app\dice\logic\reward_config\DiceRewardConfigLogic;
use app\dice\logic\reward\DiceRewardLogic; use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\reward\DiceReward;
use app\dice\validate\reward_config\DiceRewardConfigValidate; use app\dice\validate\reward_config\DiceRewardConfigValidate;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
use support\Request; use support\Request;
@@ -46,7 +48,9 @@ class DiceRewardConfigController extends BaseController
['tier', ''], ['tier', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
$data = $this->logic->getList($query); AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
// 奖励索引 + 大奖权重共约 32 条,配置页需一次返回本渠道全部数据
$data = $query->order('id', 'asc')->select()->toArray();
return $this->success($data); return $this->success($data);
} }
@@ -78,6 +82,7 @@ class DiceRewardConfigController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -95,8 +100,19 @@ class DiceRewardConfigController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');
} else { } else {
@@ -123,7 +139,9 @@ class DiceRewardConfigController extends BaseController
foreach ($items as $item) { foreach ($items as $item) {
$this->validate('batch_update', array_merge($item, ['id' => $item['id']])); $this->validate('batch_update', array_merge($item, ['id' => $item['id']]));
} }
$this->logic->batchUpdate($items); $requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $request->post());
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$this->logic->batchUpdate($items, $deptId);
return $this->success('save success'); return $this->success('save success');
} }
@@ -139,7 +157,7 @@ class DiceRewardConfigController extends BaseController
if (empty($ids)) { if (empty($ids)) {
return $this->fail('please select data to delete'); return $this->fail('please select data to delete');
} }
$result = $this->logic->destroy($ids); $result = $this->logic->destroy($ids, $this->adminInfo ?? null, $request->input('dept_id'));
if ($result) { if ($result) {
return $this->success('delete success'); return $this->success('delete success');
} else { } else {
@@ -155,8 +173,10 @@ class DiceRewardConfigController extends BaseController
#[Permission('奖励配置列表', 'dice:reward_config:index:index')] #[Permission('奖励配置列表', 'dice:reward_config:index:index')]
public function weightRatioList(Request $request): Response public function weightRatioList(Request $request): Response
{ {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$rewardLogic = new DiceRewardLogic(); $rewardLogic = new DiceRewardLogic();
$data = $rewardLogic->getListGroupedByTierWithDirection(); $data = $rewardLogic->getListGroupedByTierWithDirection($deptId);
return $this->success($data); return $this->success($data);
} }
@@ -174,8 +194,9 @@ class DiceRewardConfigController extends BaseController
return $this->fail('parameter items must be an array'); return $this->fail('parameter items must be an array');
} }
try { try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$rewardLogic = new DiceRewardLogic(); $rewardLogic = new DiceRewardLogic();
$rewardLogic->batchUpdateWeights($items); $rewardLogic->batchUpdateWeights($items, $deptId);
return $this->success('save success'); return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());
@@ -199,7 +220,8 @@ class DiceRewardConfigController extends BaseController
if ($err !== null) { if ($err !== null) {
return $this->fail($err); return $this->fail($err);
} }
$this->logic->batchUpdateBigwinWeight($items); $deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$this->logic->batchUpdateBigwinWeight($items, $deptId);
return $this->success('save success'); return $this->success('save success');
} }
@@ -214,7 +236,8 @@ class DiceRewardConfigController extends BaseController
{ {
try { try {
$rewardLogic = new DiceRewardLogic(); $rewardLogic = new DiceRewardLogic();
$result = $rewardLogic->createRewardReferenceFromConfig(); $deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$result = $rewardLogic->createRewardReferenceFromConfig($deptId);
return $this->success($result, 'create reward mapping success'); return $this->success($result, 'create reward mapping success');
} catch (\plugin\saiadmin\exception\ApiException $e) { } catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());

View File

@@ -8,6 +8,7 @@ namespace app\dice\controller\reward_config_record;
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic; use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate; use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
@@ -42,6 +43,7 @@ class DiceRewardConfigRecordController extends BaseController
['ante', ''], ['ante', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
return $this->success($data); return $this->success($data);
} }
@@ -96,6 +98,7 @@ class DiceRewardConfigRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('save', $data); $this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
@@ -114,6 +117,13 @@ class DiceRewardConfigRecordController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
$this->validate('update', $data); $this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');

View File

@@ -3,21 +3,75 @@ declare(strict_types=1);
namespace app\dice\helper; namespace app\dice\helper;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
/** /**
* 管理员数据范围辅助类 * 大富翁数据范围:按渠道 dept_id 隔离(关联 sa_system_dept
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
*/ */
class AdminScopeHelper class AdminScopeHelper
{ {
/** 超管查看默认配置模板 */
public const DEFAULT_TEMPLATE_DEPT = 0;
/** /**
* 获取当前管理员可访问的 admin_id 列表 * 当前管理员所属渠道 ID超级管理员(id=1) 返回 null 表示不限制
* 超级管理员(id=1) 返回 null 表示不限制 */
* 普通管理员返回其本人及部门下属管理员的 id 列表 public static function getDeptId(?array $adminInfo): ?int
{
if (empty($adminInfo) || !isset($adminInfo['id'])) {
return null;
}
$adminId = (int) $adminInfo['id'];
if ($adminId <= 1) {
return null;
}
$deptList = $adminInfo['deptList'] ?? [];
if (!empty($deptList['id'])) {
return (int) $deptList['id'];
}
if (!empty($adminInfo['dept_id'])) {
return (int) $adminInfo['dept_id'];
}
return 0;
}
public static function isSuperAdmin(?array $adminInfo): bool
{
return !empty($adminInfo['id']) && (int) $adminInfo['id'] <= 1;
}
/**
* 解析配置类接口的渠道 ID请求参数 dept_id
* 超管0 或空=默认模板(null)>0=指定渠道
* 普通管理员:固定本渠道
*/
public static function resolveConfigDeptId(?array $adminInfo, $requestDeptId): int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : self::DEFAULT_TEMPLATE_DEPT;
}
if ($requestDeptId === null || $requestDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
$id = (int) $requestDeptId;
if ($id === self::DEFAULT_TEMPLATE_DEPT) {
return self::DEFAULT_TEMPLATE_DEPT;
}
return $id > 0 ? $id : self::DEFAULT_TEMPLATE_DEPT;
}
public static function isTemplateDeptId($deptId): bool
{
return $deptId === null || $deptId === '' || (int) $deptId === self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 同渠道下可访问的管理员 ID
* *
* @param array|null $adminInfo 当前登录管理员信息(含 id、deptList * @return int[]|null null=不限制
* @return int[]|null null=不限制(超级管理员),否则为可访问的 admin_id 数组
*/ */
public static function getAllowedAdminIds(?array $adminInfo): ?array public static function getAllowedAdminIds(?array $adminInfo): ?array
{ {
@@ -28,33 +82,285 @@ class AdminScopeHelper
if ($adminId <= 1) { if ($adminId <= 1) {
return null; return null;
} }
$deptList = $adminInfo['deptList'] ?? []; $deptId = self::getDeptId($adminInfo);
if (empty($deptList) || !isset($deptList['id'])) { if ($deptId === null) {
return null;
}
if ($deptId <= 0) {
return [$adminId]; return [$adminId];
} }
$query = SystemUser::field('id'); $ids = SystemUser::where('dept_id', $deptId)->column('id');
$query->auth($deptList); return array_map('intval', $ids ?: [$adminId]);
$ids = $query->column('id'); }
return array_map('intval', $ids ?: []);
public static function fillDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
return;
}
$deptId = self::resolveConfigDeptId($adminInfo, $requestDeptId ?? ($data['filter_dept_id'] ?? null));
if ($deptId > 0) {
$data['dept_id'] = $deptId;
} elseif (!isset($data['dept_id']) || self::isTemplateDeptId($data['dept_id'])) {
$data['dept_id'] = self::DEFAULT_TEMPLATE_DEPT;
}
} }
/** /**
* 对查询应用 admin_id 范围过滤 * 业务数据新增:按渠道写入 dept_id玩家、记录等
* * 优先级:已有 dept_id → 所属管理员 admin_id → 请求渠道 → 当前登录人渠道
* @param object $query ThinkORM 查询对象
* @param array|null $adminInfo 当前登录管理员信息
* @return void
*/ */
public static function applyAdminScope($query, ?array $adminInfo): void public static function fillBusinessDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{ {
$allowedIds = self::getAllowedAdminIds($adminInfo); if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
if ($allowedIds === null) { $data['dept_id'] = (int) $data['dept_id'];
if ($data['dept_id'] > 0) {
return; return;
} }
if (empty($allowedIds)) { }
if (!empty($data['player_id'])) {
$playerDeptId = self::resolveDeptIdByPlayerId($data['player_id']);
if ($playerDeptId !== null && $playerDeptId > 0) {
$data['dept_id'] = $playerDeptId;
return;
}
}
if (!empty($data['admin_id'])) {
$ownerDeptId = self::resolveDeptIdByAdminId($data['admin_id']);
if ($ownerDeptId !== null && $ownerDeptId > 0) {
$data['dept_id'] = $ownerDeptId;
return;
}
}
$deptId = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($deptId !== null && $deptId > 0) {
$data['dept_id'] = $deptId;
return;
}
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
$data['dept_id'] = $scopeDeptId;
}
}
/**
* 业务新增:解析请求渠道并填充 dept_id缺失时抛错
*/
public static function prepareBusinessSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillBusinessDeptId($data, $adminInfo, $requestDeptId);
self::assertBusinessDeptId($data);
}
/**
* 配置新增:解析请求渠道并填充 dept_id
*/
public static function prepareConfigSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillDeptId($data, $adminInfo, $requestDeptId);
}
/**
* 业务表 dept_id 必须 > 0非默认模板
*/
public static function assertBusinessDeptId(array $data): void
{
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
throw new ApiException('CHANNEL_DEPT_ID_REQUIRED');
}
if ((int) $data['dept_id'] <= 0) {
throw new ApiException('INVALID_CHANNEL_DEPT_ID');
}
}
/**
* 根据玩家 ID 解析所属渠道
*/
public static function resolveDeptIdByPlayerId($playerId): ?int
{
if ($playerId === null || $playerId === '') {
return null;
}
$player = DicePlayer::field('dept_id,admin_id')->find($playerId);
if (!$player || $player->isEmpty()) {
return null;
}
$deptId = $player->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if (!empty($player->admin_id)) {
return self::resolveDeptIdByAdminId($player->admin_id);
}
return null;
}
/**
* 根据后台管理员 ID 解析所属渠道
*/
public static function resolveDeptIdByAdminId($adminId): ?int
{
if ($adminId === null || $adminId === '') {
return null;
}
$admin = SystemUser::find($adminId);
if (!$admin || $admin->isEmpty()) {
return null;
}
$deptId = $admin->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return null;
}
/**
* 规范化记录上的 dept_idnull 视为默认模板 0
*/
public static function normalizeRecordDeptId($recordDeptId): int
{
if ($recordDeptId === null || $recordDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
return (int) $recordDeptId;
}
/**
* 玩家端读取游戏配置时使用的渠道 ID玩家 dept_id 优先,否则按所属管理员)
*/
public static function resolvePlayerConfigDeptId($player): int
{
$deptId = null;
$adminId = null;
if (is_array($player)) {
$deptId = $player['dept_id'] ?? null;
$adminId = $player['admin_id'] ?? null;
} elseif (is_object($player)) {
$deptId = $player->dept_id ?? null;
$adminId = $player->admin_id ?? null;
}
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if ($adminId !== null && $adminId !== '') {
$fromAdmin = self::resolveDeptIdByAdminId($adminId);
if ($fromAdmin !== null && $fromAdmin > 0) {
return $fromAdmin;
}
}
return self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 从请求参数或请求体中解析 dept_id兼容 PUT JSON 仅出现在 body 的情况)
*/
public static function pickRequestDeptId($inputDeptId, array $body = [])
{
if ($inputDeptId !== null && $inputDeptId !== '') {
return $inputDeptId;
}
if (isset($body['dept_id']) && $body['dept_id'] !== '' && $body['dept_id'] !== null) {
return $body['dept_id'];
}
return null;
}
public static function canAccessDept(?array $adminInfo, $recordDeptId, $requestDeptId = null): bool
{
$recordDeptId = self::normalizeRecordDeptId($recordDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId === null) {
if ($requestDeptId === null || $requestDeptId === '') {
return true;
}
$target = self::resolveConfigDeptId($adminInfo, $requestDeptId);
if (self::isTemplateDeptId($target)) {
return self::isTemplateDeptId($recordDeptId);
}
return $recordDeptId === $target;
}
if ($recordDeptId === self::DEFAULT_TEMPLATE_DEPT && $scopeDeptId > 0) {
return false;
}
return $recordDeptId === $scopeDeptId;
}
/**
* 业务页渠道 ID超管通过请求 dept_id 筛选;未传或 <=0 时不限制
*/
public static function resolveBusinessDeptId(?array $adminInfo, $requestDeptId): ?int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : null;
}
if ($requestDeptId === null || $requestDeptId === '') {
return null;
}
$id = (int) $requestDeptId;
return $id > 0 ? $id : null;
}
/**
* 业务数据列表(玩家、记录、工作台等)
*/
public static function applyAdminScope($query, ?array $adminInfo, $requestDeptId = null): void
{
if (self::getDeptId($adminInfo) === null) {
$target = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
$query->where('dept_id', $target);
}
return;
}
$deptId = self::getDeptId($adminInfo);
if ($deptId <= 0) {
$query->whereRaw('1=0'); $query->whereRaw('1=0');
return; return;
} }
$query->whereIn('admin_id', $allowedIds); $query->where('dept_id', $deptId);
}
/**
* 配置类列表:超管按所选渠道/默认模板筛选
*/
public static function applyConfigScope($query, ?array $adminInfo, $requestDeptId = null, string $deptColumn = 'dept_id'): void
{
$targetDeptId = self::resolveConfigDeptId($adminInfo, $requestDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && !self::isSuperAdmin($adminInfo)) {
if ($scopeDeptId <= 0) {
$query->whereRaw('1=0');
return;
}
$query->where($deptColumn, $scopeDeptId);
return;
}
if (self::isTemplateDeptId($targetDeptId)) {
$templateId = self::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId, $deptColumn) {
$q->where($deptColumn, $templateId)->whereOr($deptColumn, null);
});
return;
}
$query->where($deptColumn, $targetDeptId);
} }
} }

View File

@@ -0,0 +1,139 @@
<?php
declare(strict_types=1);
namespace app\dice\helper;
use plugin\saiadmin\exception\ApiException;
/**
* 配置类数据按渠道隔离的更新(防止 find(id) 误更新其他渠道同业务主键行)
*/
class ConfigScopeEditHelper
{
/**
* 在查询上附加渠道条件
*/
public static function applyDeptIdWhere($query, int $deptId, string $column = 'dept_id'): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) use ($deptId, $column) {
$q->where($column, $deptId);
if (method_exists($q, 'orWhereNull')) {
$q->orWhereNull($column);
} else {
$q->whereOr($column, null);
}
});
return;
}
$query->where($column, $deptId);
}
/**
* 按主键 + 渠道更新配置行
*
* @param Model $model 模型实例(用于取表名、主键)
* @param mixed $primaryKeyValue 列表/表单中的主键值
* @param int $deptId 渠道 ID0=默认模板)
* @param array $data 更新字段
* @param array $forbidden 禁止写入的字段名
*/
/**
* 按主键更新(主键全局唯一表如 dice_lottery_pool_config
* 以库中记录的 dept_id 为准,避免请求未带 dept_id 时误按默认模板 0 查找失败
*/
public static function updateByPkAndDept(
object $model,
$primaryKeyValue,
int $requestDeptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
?array $adminInfo = null,
$rawRequestDeptId = null
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$pk = self::resolvePk($model);
$record = $model->where($pk, $primaryKeyValue)->find();
if ($record === null) {
throw new ApiException('data not found');
}
$recordDeptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($record) ? ($record['dept_id'] ?? null) : ($record->dept_id ?? null)
);
if ($adminInfo !== null && ! AdminScopeHelper::canAccessDept($adminInfo, $recordDeptId, $rawRequestDeptId)) {
throw new ApiException('no permission to update this record');
}
if ($rawRequestDeptId !== null && $rawRequestDeptId !== '') {
$targetDeptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $rawRequestDeptId);
if ($targetDeptId !== $recordDeptId) {
throw new ApiException('record does not belong to selected channel');
}
}
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $recordDeptId);
$affected = $query->update($data);
return $affected !== false;
}
/**
* dice_reward_config / dice_config业务 id025 等)+ 渠道更新
*/
public static function updateByBusinessIdAndDept(
object $model,
int $businessId,
int $deptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id']
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$query = $model->where('id', $businessId);
self::applyDeptIdWhere($query, $deptId);
$record = (clone $query)->find();
if ($record === null) {
throw new ApiException('config id=' . $businessId . ' not found for current channel');
}
$affected = $query->update($data);
return $affected !== false;
}
/**
* 列表/读取:按主键 + 渠道取单条(避免 find(pk) 命中其他渠道)
*/
private static function resolvePk(object $model): string
{
if (method_exists($model, 'getPk')) {
return (string) $model->getPk();
}
if (method_exists($model, 'getKeyName')) {
return (string) $model->getKeyName();
}
return 'id';
}
public static function findByPkAndDept(object $model, $primaryKeyValue, int $deptId)
{
$pk = self::resolvePk($model);
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $deptId);
return $query->find();
}
}

View File

@@ -6,13 +6,15 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\ante_config; namespace app\dice\logic\ante_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig; use app\dice\model\ante_config\DiceAnteConfig;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
/** /**
* 底注配置逻辑层 * 底注配置逻辑层
*/ */
class DiceAnteConfigLogic extends BaseLogic class DiceAnteConfigLogic extends DiceBaseLogic
{ {
public function __construct() public function __construct()
{ {
@@ -23,21 +25,32 @@ class DiceAnteConfigLogic extends BaseLogic
{ {
return $this->transaction(function () use ($data) { return $this->transaction(function () use ($data) {
$this->normalizeDefaultField($data); $this->normalizeDefaultField($data);
$deptId = AdminScopeHelper::resolveConfigDeptId(null, $data['dept_id'] ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
if ((int) ($data['is_default'] ?? 0) === 1) { if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults(); $this->clearOtherDefaults(null, $deptId);
} }
return parent::add($data); return parent::add($data);
}); });
} }
public function edit($id, array $data): mixed public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{ {
return $this->transaction(function () use ($id, $data) { $pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return $this->transaction(function () use ($id, $data, $deptId, $adminInfo, $pickedDeptId) {
$this->normalizeDefaultField($data); $this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) { if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults((int) $id); $this->clearOtherDefaults((int) $id, $deptId);
} }
return parent::edit($id, $data); return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}); });
} }
@@ -79,9 +92,10 @@ class DiceAnteConfigLogic extends BaseLogic
$data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0; $data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0;
} }
private function clearOtherDefaults(?int $excludeId = null): void private function clearOtherDefaults(?int $excludeId = null, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{ {
$query = $this->model->where('is_default', 1); $query = $this->model->where('is_default', 1);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
if ($excludeId !== null && $excludeId > 0) { if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId); $query->where('id', '<>', $excludeId);
} }

View File

@@ -6,6 +6,8 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\config; namespace app\dice\logic\config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use plugin\saiadmin\basic\eloquent\BaseLogic; use plugin\saiadmin\basic\eloquent\BaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
@@ -14,7 +16,7 @@ use app\dice\model\config\DiceConfig;
/** /**
* 摇色子配置逻辑层 * 摇色子配置逻辑层
*/ */
class DiceConfigLogic extends BaseLogic class DiceConfigLogic extends DiceBaseLogic
{ {
/** /**
* 构造函数 * 构造函数
@@ -24,4 +26,13 @@ class DiceConfigLogic extends BaseLogic
$this->model = new DiceConfig(); $this->model = new DiceConfig();
} }
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
return ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
}
} }

View File

@@ -4,16 +4,33 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\game; namespace app\dice\logic\game;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use plugin\saiadmin\basic\eloquent\BaseLogic; use plugin\saiadmin\basic\eloquent\BaseLogic;
use app\dice\model\game\DiceGame; use app\dice\model\game\DiceGame;
/** /**
* 游戏管理逻辑层 * 游戏管理逻辑层
*/ */
class DiceGameLogic extends BaseLogic class DiceGameLogic extends DiceBaseLogic
{ {
public function __construct() public function __construct()
{ {
$this->model = new DiceGame(); $this->model = new DiceGame();
} }
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
} }

View File

@@ -6,8 +6,10 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\lottery_pool_config; namespace app\dice\logic\lottery_pool_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use support\think\Cache; use support\think\Cache;
@@ -15,7 +17,7 @@ use support\think\Cache;
/** /**
* 色子奖池配置逻辑层 * 色子奖池配置逻辑层
*/ */
class DiceLotteryPoolConfigLogic extends BaseLogic class DiceLotteryPoolConfigLogic extends DiceBaseLogic
{ {
/** Redis 当前彩金池type=0 实例key无则按 type=0 创建 */ /** Redis 当前彩金池type=0 实例key无则按 type=0 创建 */
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default'; private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
@@ -30,19 +32,55 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
$this->model = new DiceLotteryPoolConfig(); $this->model = new DiceLotteryPoolConfig();
} }
/**
* 按渠道隔离更新(主键 id 全局唯一,仍校验 dept_id 防止越权)
*/
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
/** /**
* 获取当前彩金池type=0+ 杀分权重为 type=1 的只读展示 * 获取当前彩金池type=0+ 杀分权重为 type=1 的只读展示
* profit_amount 每次从 DB 实时读取t1_weightt5_weight 来自 type=1杀分权重不可在弹窗内修改 * profit_amount 每次从 DB 实时读取t1_weightt5_weight 来自 type=1杀分权重不可在弹窗内修改
* *
* @return array{id:int,name:string,safety_line:int,kill_enabled:int,t1_weight:int,...,t5_weight:int,profit_amount:float} * @return array{id:int,name:string,safety_line:int,kill_enabled:int,t1_weight:int,...,t5_weight:int,profit_amount:float}
*/ */
public function getCurrentPool(): array public function getCurrentPool(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): array
{ {
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find(); $query0 = DiceLotteryPoolConfig::where('name', 'default');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query0->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query0->where('dept_id', $deptId);
}
$configType0 = $query0->find();
if (!$configType0) { if (!$configType0) {
throw new ApiException('No name=default pool config found, please create one first'); throw new ApiException('No name=default pool config found, please create one first');
} }
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find(); $query1 = DiceLotteryPoolConfig::where('name', 'killScore');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query1->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query1->where('dept_id', $deptId);
}
$configType1 = $query1->find();
$row0 = $configType0->toArray(); $row0 = $configType0->toArray();
$profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0); $profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0);
$pool = [ $pool = [
@@ -66,9 +104,9 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
* *
* @param array{safety_line?:int,kill_enabled?:int} $data * @param array{safety_line?:int,kill_enabled?:int} $data
*/ */
public function updateCurrentPool(array $data): void public function updateCurrentPool(array $data, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{ {
$pool = $this->getCurrentPool(); $pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id']; $id = (int) $pool['id'];
if (!array_key_exists('safety_line', $data) && !array_key_exists('kill_enabled', $data)) { if (!array_key_exists('safety_line', $data) && !array_key_exists('kill_enabled', $data)) {
return; return;
@@ -83,17 +121,21 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
if ($update === []) { if ($update === []) {
return; return;
} }
DiceLotteryPoolConfig::where('id', $id)->update($update); $query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update($update);
} }
/** /**
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0并刷新 Redis 缓存 * 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0并刷新 Redis 缓存
*/ */
public function resetProfitAmount(): void public function resetProfitAmount(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{ {
$pool = $this->getCurrentPool(); $pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id']; $id = (int) $pool['id'];
DiceLotteryPoolConfig::where('id', $id)->update(['profit_amount' => 0]); $query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update(['profit_amount' => 0]);
$pool['profit_amount'] = 0.0; $pool['profit_amount'] = 0.0;
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE); Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
} }

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\play_record; namespace app\dice\logic\play_record;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record\DicePlayRecord; use app\dice\model\play_record\DicePlayRecord;
@@ -14,7 +14,7 @@ use app\dice\model\play_record\DicePlayRecord;
/** /**
* 玩家抽奖记录逻辑层 * 玩家抽奖记录逻辑层
*/ */
class DicePlayRecordLogic extends BaseLogic class DicePlayRecordLogic extends DiceBaseLogic
{ {
/** /**
* 构造函数 * 构造函数

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\play_record_test; namespace app\dice\logic\play_record_test;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record_test\DicePlayRecordTest; use app\dice\model\play_record_test\DicePlayRecordTest;
@@ -14,7 +14,7 @@ use app\dice\model\play_record_test\DicePlayRecordTest;
/** /**
* 玩家抽奖记录(测试数据)逻辑层 * 玩家抽奖记录(测试数据)逻辑层
*/ */
class DicePlayRecordTestLogic extends BaseLogic class DicePlayRecordTestLogic extends DiceBaseLogic
{ {
/** /**
* 构造函数 * 构造函数

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\player; namespace app\dice\logic\player;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
@@ -14,7 +14,7 @@ use app\dice\model\player\DicePlayer;
/** /**
* 大富翁-玩家逻辑层 * 大富翁-玩家逻辑层
*/ */
class DicePlayerLogic extends BaseLogic class DicePlayerLogic extends DiceBaseLogic
{ {
/** 密码加密盐(可与 config 统一) */ /** 密码加密盐(可与 config 统一) */
private const PASSWORD_SALT = 'dice_player_salt_2024'; private const PASSWORD_SALT = 'dice_player_salt_2024';

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\player_ticket_record; namespace app\dice\logic\player_ticket_record;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord; use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -14,7 +14,7 @@ use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
/** /**
* 抽奖券获取记录逻辑层 * 抽奖券获取记录逻辑层
*/ */
class DicePlayerTicketRecordLogic extends BaseLogic class DicePlayerTicketRecordLogic extends DiceBaseLogic
{ {
/** /**
* 构造函数 * 构造函数

View File

@@ -6,7 +6,8 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\player_wallet_record; namespace app\dice\logic\player_wallet_record;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\helper\AdminScopeHelper;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord; use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
@@ -15,7 +16,7 @@ use app\api\cache\UserCache;
/** /**
* 玩家钱包流水逻辑层 * 玩家钱包流水逻辑层
*/ */
class DicePlayerWalletRecordLogic extends BaseLogic class DicePlayerWalletRecordLogic extends DiceBaseLogic
{ {
/** /**
* 构造函数 * 构造函数
@@ -27,6 +28,18 @@ class DicePlayerWalletRecordLogic extends BaseLogic
$this->setOrderType('DESC'); $this->setOrderType('DESC');
} }
/**
* 按与列表相同的筛选条件汇总平台币变化(不含 with / 分页 / 排序)
*/
public function sumCoinBySearch(array $where, ?array $adminInfo, $requestDeptId = null): float
{
$query = $this->search($where);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $requestDeptId);
$table = $this->model->getTable();
$sum = $query->sum($table . '.coin');
return round((float) $sum, 2);
}
/** /**
* 添加数据(补全抽奖次数字段默认值) * 添加数据(补全抽奖次数字段默认值)
*/ */
@@ -83,9 +96,11 @@ class DicePlayerWalletRecordLogic extends BaseLogic
} }
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null; $playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$playerDeptId = ($player->dept_id ?? null) ? (int) $player->dept_id : null;
$record = [ $record = [
'player_id' => $playerId, 'player_id' => $playerId,
'admin_id' => $playerAdminId, 'admin_id' => $playerAdminId,
'dept_id' => $playerDeptId,
'coin' => $type === 3 ? $coin : -$coin, 'coin' => $type === 3 ? $coin : -$coin,
'type' => $type, 'type' => $type,
'wallet_before' => $walletBefore, 'wallet_before' => $walletBefore,

View File

@@ -4,6 +4,8 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\reward; namespace app\dice\logic\reward;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward; use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig; use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
@@ -29,8 +31,14 @@ class DiceRewardLogic
* @param int $limit * @param int $limit
* @return array{total: int, per_page: int, current_page: int, data: array} * @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 public function getListWithConfig(
{ int $direction,
array $where,
int $page = 1,
int $limit = 10,
?array $adminInfo = null,
$requestDeptId = null
): array {
$tier = isset($where['tier']) ? trim((string) $where['tier']) : ''; $tier = isset($where['tier']) ? trim((string) $where['tier']) : '';
$orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier'; $orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier';
$orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc'; $orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc';
@@ -41,6 +49,10 @@ class DiceRewardLogic
->order($orderField, $orderType) ->order($orderField, $orderType)
->order('r.end_index', 'asc'); ->order('r.end_index', 'asc');
if ($adminInfo !== null) {
AdminScopeHelper::applyConfigScope($query, $adminInfo, $requestDeptId, 'r.dept_id');
}
if ($tier !== '') { if ($tier !== '') {
$query->where('r.tier', $tier); $query->where('r.tier', $tier);
} }
@@ -74,7 +86,7 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针 * @param int $direction 0=顺时针 1=逆时针
* @param array<int, array{id: int, weight: int}> $items id 为 end_indexDiceRewardConfig.id * @param array<int, array{id: int, weight: int}> $items id 为 end_indexDiceRewardConfig.id
*/ */
public function batchUpdateWeightsByDirection(int $direction, array $items): void public function batchUpdateWeightsByDirection(int $direction, array $items, ?int $deptId = null): void
{ {
if (empty($items)) { if (empty($items)) {
return; return;
@@ -90,23 +102,36 @@ class DiceRewardLogic
} }
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight)); $weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$tier = DiceRewardConfig::where('id', $id)->value('tier'); $configQuery = DiceRewardConfig::where('id', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
}
$tier = $configQuery->value('tier');
if ($tier === null || $tier === '') { if ($tier === null || $tier === '') {
throw new ApiException(\app\api\util\ApiLang::translateParams('配置ID %s 不存在或档位为空', [$id])); throw new ApiException(\app\api\util\ApiLang::translateParams('配置ID %s 不存在或档位为空', [$id]));
} }
$tier = (string) $tier; $tier = (string) $tier;
$affected = DiceReward::where('tier', $tier)->where('direction', $direction)->where('end_index', $id)->update(['weight' => $weight]); $rewardQuery = DiceReward::where('tier', $tier)
->where('direction', $direction)
->where('end_index', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $deptId);
}
$affected = $rewardQuery->update(['weight' => $weight]);
if ($affected === 0) { if ($affected === 0) {
$m = new DiceReward(); $m = new DiceReward();
$m->tier = $tier; $m->tier = $tier;
$m->direction = $direction; $m->direction = $direction;
$m->end_index = $id; $m->end_index = $id;
$m->weight = $weight; $m->weight = $weight;
if ($deptId !== null && $deptId > 0) {
$m->dept_id = $deptId;
}
$m->save(); $m->save();
} }
} }
DiceReward::refreshCache(); DiceReward::refreshCache($deptId);
} }
/** /**
@@ -114,11 +139,11 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针 * @param int $direction 0=顺时针 1=逆时针
* @return array<string, array> 键 T1|T2|...|BIGWIN值为该档位下带 weight 的行数组 * @return array<string, array> 键 T1|T2|...|BIGWIN值为该档位下带 weight 的行数组
*/ */
public function getListGroupedByTierForDirection(int $direction): array public function getListGroupedByTierForDirection(int $direction, ?int $deptId = null): array
{ {
$configInstance = DiceRewardConfig::getCachedInstance(); $configInstance = DiceRewardConfig::getCachedInstance($deptId);
$byTier = $configInstance['by_tier'] ?? []; $byTier = $configInstance['by_tier'] ?? [];
$rewardInstance = DiceReward::getCachedInstance(); $rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? []; $byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = []; $result = [];
@@ -153,9 +178,9 @@ class DiceRewardLogic
* *
* @return array<string, array{0: array, 1: array}> * @return array<string, array{0: array, 1: array}>
*/ */
public function getListGroupedByTierWithDirection(): array public function getListGroupedByTierWithDirection(?int $deptId = null): array
{ {
$rewardInstance = DiceReward::getCachedInstance(); $rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? []; $byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = []; $result = [];
@@ -185,7 +210,7 @@ class DiceRewardLogic
* @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键weight 为 1-10000 * @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键weight 为 1-10000
* @throws ApiException * @throws ApiException
*/ */
public function batchUpdateWeights(array $items): void public function batchUpdateWeights(array $items, ?int $deptId = null): void
{ {
if (empty($items)) { if (empty($items)) {
return; return;
@@ -203,13 +228,24 @@ class DiceRewardLogic
} }
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN; $weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight)); $weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$model = DiceReward::find($id); $query = DiceReward::where('id', $id);
if ($deptId !== null) {
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
}
$model = $query->find();
if ($model !== null) { if ($model !== null) {
$model->weight = $weight; $model->weight = $weight;
$model->save(); $model->save();
} }
} }
DiceReward::refreshCache(); DiceReward::refreshCache($deptId);
} }
/** BIGWIN 权重范围0=0% 中奖10000=100% 中奖grid_number=5/30 固定 100% 不可改 */ /** BIGWIN 权重范围0=0% 中奖10000=100% 中奖grid_number=5/30 固定 100% 不可改 */
@@ -219,9 +255,9 @@ class DiceRewardLogic
* 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示) * 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示)
* 若 DiceReward 无该点数则 5/30 返回 10000其余返回 0 * 若 DiceReward 无该点数则 5/30 返回 10000其余返回 0
*/ */
public function getBigwinWeightByGridNumber(int $gridNumber): int public function getBigwinWeightByGridNumber(int $gridNumber, ?int $deptId = null): int
{ {
$inst = DiceReward::getCachedInstance(); $inst = DiceReward::getCachedInstance($deptId);
$rows = $inst['by_tier_direction']['BIGWIN'][DiceReward::DIRECTION_CLOCKWISE] ?? []; $rows = $inst['by_tier_direction']['BIGWIN'][DiceReward::DIRECTION_CLOCKWISE] ?? [];
foreach ($rows as $row) { foreach ($rows as $row) {
if ((int) ($row['grid_number'] ?? 0) === $gridNumber) { if ((int) ($row['grid_number'] ?? 0) === $gridNumber) {
@@ -235,21 +271,24 @@ class DiceRewardLogic
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新0=0% 中奖10000=100% 中奖 * 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新0=0% 中奖10000=100% 中奖
* 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入 * 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入
*/ */
public function updateBigwinWeight(int $gridNumber, int $weight): void public function updateBigwinWeight(int $gridNumber, int $weight, ?int $deptId = null): void
{ {
$weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight)); $weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight));
$config = DiceRewardConfig::where('tier', 'BIGWIN') if ($deptId === null) {
->where('grid_number', $gridNumber) $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
->find(); }
$configQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
$config = $configQuery->find();
if (! $config) { if (! $config) {
return; return;
} }
$configArr = $config->toArray(); $configArr = $config->toArray();
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) { foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入 // 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
$row = DiceReward::where('direction', $direction) $rowQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
->where('grid_number', $gridNumber) ConfigScopeEditHelper::applyDeptIdWhere($rowQuery, $deptId);
->find(); $row = $rowQuery->find();
if ($row) { if ($row) {
$row->tier = 'BIGWIN'; $row->tier = 'BIGWIN';
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN; $row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
@@ -272,10 +311,13 @@ class DiceRewardLogic
$m->remark = (string) ($configArr['remark'] ?? ''); $m->remark = (string) ($configArr['remark'] ?? '');
$m->type = $configArr['type'] ?? null; $m->type = $configArr['type'] ?? null;
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN; $m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
if (!AdminScopeHelper::isTemplateDeptId($deptId)) {
$m->dept_id = $deptId;
}
$m->save(); $m->save();
} }
} }
DiceReward::refreshCache(); DiceReward::refreshCache($deptId);
} }
/** 盘面格数(用于顺时针/逆时针计算 end_index */ /** 盘面格数(用于顺时针/逆时针计算 end_index */
@@ -309,9 +351,19 @@ class DiceRewardLogic
* @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int} * @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int}
* @throws ApiException * @throws ApiException
*/ */
public function createRewardReferenceFromConfig(): array public function createRewardReferenceFromConfig(?int $deptId = null): array
{ {
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray(); $configQuery = DiceRewardConfig::order('id', 'asc');
if ($deptId === null || $deptId === \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$configQuery->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
$deptId = null;
} else {
$configQuery->where('dept_id', $deptId);
}
$list = $configQuery->select()->toArray();
if (empty($list)) { if (empty($list)) {
throw new ApiException('Reward config is empty, please maintain dice_reward_config first'); throw new ApiException('Reward config is empty, please maintain dice_reward_config first');
} }
@@ -326,8 +378,12 @@ class DiceRewardLogic
} }
$table = (new DiceReward())->getTable(); $table = (new DiceReward())->getTable();
Db::execute('DELETE FROM `' . $table . '`'); if ($deptId === null) {
DiceReward::refreshCache(); Db::table($table)->whereNull('dept_id')->delete();
} else {
Db::table($table)->where('dept_id', $deptId)->delete();
}
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
// 按 id 排序后,盘面位置 0..25 对应 $list[$pos],避免 config.id 非 0-25/1-26 时取模结果找不到 // 按 id 排序后,盘面位置 0..25 对应 $list[$pos],避免 config.id 非 0-25/1-26 时取模结果找不到
$gridToPosition = []; $gridToPosition = [];
@@ -379,7 +435,13 @@ class DiceRewardLogic
'remark' => $configCw['remark'] ?? '', 'remark' => $configCw['remark'] ?? '',
'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0, 'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0,
]; ];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber)->find(); $existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) { if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCw); DiceReward::where('id', $existing->id)->update($payloadCw);
$updatedCw++; $updatedCw++;
@@ -395,6 +457,9 @@ class DiceRewardLogic
$m->real_ev = $configCw['real_ev'] ?? null; $m->real_ev = $configCw['real_ev'] ?? null;
$m->remark = $configCw['remark'] ?? ''; $m->remark = $configCw['remark'] ?? '';
$m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0; $m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save(); $m->save();
$createdCw++; $createdCw++;
} }
@@ -419,7 +484,13 @@ class DiceRewardLogic
'remark' => $configCcw['remark'] ?? '', 'remark' => $configCcw['remark'] ?? '',
'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0, 'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0,
]; ];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber)->find(); $existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) { if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCcw); DiceReward::where('id', $existing->id)->update($payloadCcw);
$updatedCcw++; $updatedCcw++;
@@ -435,6 +506,9 @@ class DiceRewardLogic
$m->real_ev = $configCcw['real_ev'] ?? null; $m->real_ev = $configCcw['real_ev'] ?? null;
$m->remark = $configCcw['remark'] ?? ''; $m->remark = $configCcw['remark'] ?? '';
$m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0; $m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save(); $m->save();
$createdCcw++; $createdCcw++;
} }
@@ -442,7 +516,7 @@ class DiceRewardLogic
} }
} }
DiceReward::refreshCache(); DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
return [ return [
'created_clockwise' => $createdCw, 'created_clockwise' => $createdCw,
'created_counterclockwise' => $createdCcw, 'created_counterclockwise' => $createdCcw,

View File

@@ -6,11 +6,13 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\reward_config; namespace app\dice\logic\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\logic\reward\DiceRewardLogic; use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceRewardConfig; use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord; use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper; use plugin\saiadmin\utils\Helper;
use support\Log; use support\Log;
@@ -19,7 +21,7 @@ use support\Log;
* 奖励配置逻辑层DiceRewardConfig * 奖励配置逻辑层DiceRewardConfig
* weight 1-10000各档位权重和不限制 * weight 1-10000各档位权重和不限制
*/ */
class DiceRewardConfigLogic extends BaseLogic class DiceRewardConfigLogic extends DiceBaseLogic
{ {
/** weight 取值范围 */ /** weight 取值范围 */
private const WEIGHT_MIN = 1; private const WEIGHT_MIN = 1;
@@ -36,18 +38,23 @@ class DiceRewardConfigLogic extends BaseLogic
public function add(array $data): mixed public function add(array $data): mixed
{ {
$result = parent::add($data); $result = parent::add($data);
DiceRewardConfig::refreshCache(); $deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
DiceRewardConfig::refreshCache($deptId);
return $result; return $result;
} }
/** /**
* 修改:保存后刷新缓存BIGWIN 的 weight 直接写入 dice_reward_config 表,抽奖时从 Config 读取 * 修改:按业务 id + 渠道更新;保存后刷新该渠道缓存
*/ */
public function edit($id, array $data): mixed public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{ {
$result = parent::edit($id, $data); $deptId = AdminScopeHelper::resolveConfigDeptId(
DiceRewardConfig::refreshCache(); $adminInfo,
return $result; AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
DiceRewardConfig::refreshCache($deptId);
return true;
} }
/** /**
@@ -152,8 +159,9 @@ class DiceRewardConfigLogic extends BaseLogic
/** /**
* 批量更新奖励索引配置grid_number、ui_text、real_ev、tier、remark不含 weightBIGWIN 权重单独接口) * 批量更新奖励索引配置grid_number、ui_text、real_ev、tier、remark不含 weightBIGWIN 权重单独接口)
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?] * @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
* @param int $deptId 渠道 ID0=默认模板)
*/ */
public function batchUpdate(array $items): void public function batchUpdate(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{ {
foreach ($items as $row) { foreach ($items as $row) {
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') { if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
@@ -167,10 +175,18 @@ class DiceRewardConfigLogic extends BaseLogic
} }
} }
if (! empty($data)) { if (! empty($data)) {
parent::edit($id, $data); $this->updateByBusinessIdAndDept($id, $deptId, $data);
} }
} }
DiceRewardConfig::refreshCache(); DiceRewardConfig::refreshCache($deptId);
}
/**
* 按业务 id025与渠道更新单条配置
*/
private function updateByBusinessIdAndDept(int $businessId, int $deptId, array $data): void
{
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, $businessId, $deptId, $data);
} }
/** /**
@@ -201,8 +217,9 @@ class DiceRewardConfigLogic extends BaseLogic
/** /**
* 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward * 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000] * @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
* @param int $deptId 渠道 ID0=默认模板)
*/ */
public function batchUpdateBigwinWeight(array $items): void public function batchUpdateBigwinWeight(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{ {
$weightMin = 0; $weightMin = 0;
$weightMax = 10000; $weightMax = 10000;
@@ -213,21 +230,33 @@ class DiceRewardConfigLogic extends BaseLogic
continue; continue;
} }
$weight = max($weightMin, min($weightMax, $weight)); $weight = max($weightMin, min($weightMax, $weight));
$this->model->where('tier', 'BIGWIN') $query = $this->model->where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
->where('grid_number', $gridNumber) if (AdminScopeHelper::isTemplateDeptId($deptId)) {
->update(['weight' => $weight]); $query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
} }
DiceRewardConfig::refreshCache(); $exists = (clone $query)->find();
if ($exists === null) {
throw new ApiException('BIGWIN grid_number=' . $gridNumber . ' not found for current channel');
}
$query->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache($deptId);
} }
/** /**
* 删除后刷新缓存 * 删除后刷新缓存
*/ */
public function destroy($ids): bool public function destroy($ids, ?array $adminInfo = null, $requestDeptId = null): bool
{ {
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
$result = parent::destroy($ids); $result = parent::destroy($ids);
if ($result) { if ($result) {
DiceRewardConfig::refreshCache(); DiceRewardConfig::refreshCache($deptId);
} }
return $result; return $result;
} }
@@ -403,6 +432,12 @@ class DiceRewardConfigLogic extends BaseLogic
$record->lottery_config_id = $config ? (int) $config->id : null; $record->lottery_config_id = $config ? (int) $config->id : null;
$record->result_counts = $counts; $record->result_counts = $counts;
$record->admin_id = $adminId; $record->admin_id = $adminId;
if ($adminId > 0) {
$admin = \plugin\saiadmin\app\model\system\SystemUser::find($adminId);
if ($admin && !empty($admin->dept_id)) {
$record->dept_id = $admin->dept_id;
}
}
$record->create_time = date('Y-m-d H:i:s'); $record->create_time = date('Y-m-d H:i:s');
$record->save(); $record->save();
$recordId = (int) $record->id; $recordId = (int) $record->id;

View File

@@ -4,12 +4,15 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\logic\reward_config_record; namespace app\dice\logic\reward_config_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\api\util\ApiLang;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig; use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceReward; use app\dice\model\reward\DiceReward;
use app\dice\model\reward\DiceRewardConfig; use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord; use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic; use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
@@ -17,7 +20,7 @@ use plugin\saiadmin\app\model\system\SystemUser;
* 奖励配置权重测试记录逻辑层 * 奖励配置权重测试记录逻辑层
* *
*/ */
class DiceRewardConfigRecordLogic extends BaseLogic class DiceRewardConfigRecordLogic extends DiceBaseLogic
{ {
public function __construct() public function __construct()
{ {
@@ -88,6 +91,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
throw new ApiException('Test record not found'); throw new ApiException('Test record not found');
} }
$record = is_array($record) ? $record : $record->toArray(); $record = is_array($record) ? $record : $record->toArray();
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($record['dept_id'] ?? null);
$snapshot = $record['weight_config_snapshot'] ?? null; $snapshot = $record['weight_config_snapshot'] ?? null;
if (is_string($snapshot)) { if (is_string($snapshot)) {
@@ -112,9 +116,9 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$tier = $tierFromDb !== null ? (string) $tierFromDb : ''; $tier = $tierFromDb !== null ? (string) $tierFromDb : '';
} }
// 仅按方向 + 点数更新 DiceReward若存在则更新不存在才插入避免唯一键冲突 // 仅按方向 + 点数更新 DiceReward若存在则更新不存在才插入避免唯一键冲突
$reward = DiceReward::where('direction', $direction) $rewardQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
->where('grid_number', $gridNumber) ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $configDeptId);
->find(); $reward = $rewardQuery->find();
if ($reward) { if ($reward) {
$reward->weight = $weight; $reward->weight = $weight;
// 若快照中有 tier补齐 tier 信息 // 若快照中有 tier补齐 tier 信息
@@ -130,10 +134,13 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$m->direction = $direction; $m->direction = $direction;
$m->grid_number = $gridNumber; $m->grid_number = $gridNumber;
$m->weight = $weight; $m->weight = $weight;
if (!AdminScopeHelper::isTemplateDeptId($configDeptId)) {
$m->dept_id = $configDeptId;
}
$m->save(); $m->save();
} }
} }
DiceReward::refreshCache(); DiceReward::refreshCache($configDeptId);
} }
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig // 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
@@ -152,11 +159,11 @@ class DiceRewardConfigRecordLogic extends BaseLogic
if ($weight < 0) { if ($weight < 0) {
$weight = 0; $weight = 0;
} }
DiceRewardConfig::where('tier', 'BIGWIN') $bigwinQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
->where('grid_number', $gridNumber) ConfigScopeEditHelper::applyDeptIdWhere($bigwinQuery, $configDeptId);
->update(['weight' => $weight]); $bigwinQuery->update(['weight' => $weight]);
} }
DiceRewardConfig::refreshCache(); DiceRewardConfig::refreshCache($configDeptId);
} }
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5']; $tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
@@ -225,7 +232,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update); DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update);
} }
DiceRewardConfig::refreshCache(); DiceRewardConfig::refreshCache($configDeptId);
DiceReward::refreshCache($configDeptId);
DiceRewardConfig::clearRequestInstance(); DiceRewardConfig::clearRequestInstance();
} }
@@ -237,8 +245,12 @@ class DiceRewardConfigRecordLogic extends BaseLogic
* @return int 记录 ID * @return int 记录 ID
* @throws ApiException * @throws ApiException
*/ */
public function createWeightTestRecord(array|int $params, mixed $adminIdOrFreeS = null, mixed $freeSOrFreeN = null, mixed $freeN = null): int public function createWeightTestRecord(
{ array|int $params,
mixed $adminIdOrFreeS = null,
?array $adminInfo = null,
$requestDeptId = null
): int {
$adminId = null; $adminId = null;
if (!is_array($params)) { if (!is_array($params)) {
// 兼容旧版调用createWeightTestRecord(paid_s_count, paid_n_count) // 兼容旧版调用createWeightTestRecord(paid_s_count, paid_n_count)
@@ -249,15 +261,14 @@ class DiceRewardConfigRecordLogic extends BaseLogic
} else { } else {
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null; $adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
} }
$deptId = $this->resolveWeightTestDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, is_array($params) ? $params : []),
is_array($params) ? $params : []
);
$allowed = [100, 500, 1000, 5000]; $allowed = [100, 500, 1000, 5000];
$ante = isset($params['ante']) ? intval($params['ante']) : 1; $ante = $this->resolveWeightTestAnte($params, $deptId);
if ($ante <= 0) {
throw new ApiException('ante must be greater than 0');
}
$anteExists = DiceAnteConfig::where('mult', $ante)->count();
if ($anteExists <= 0) {
throw new ApiException('ante not allowed: ' . $ante);
}
$lotteryConfigId = isset($params['lottery_config_id']) ? (int) $params['lottery_config_id'] : 0; $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; $paidConfigId = isset($params['paid_lottery_config_id']) ? (int) $params['paid_lottery_config_id'] : 0;
@@ -296,8 +307,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$paidTierWeights = null; $paidTierWeights = null;
$freeTierWeights = null; $freeTierWeights = null;
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟 // 来自当前渠道的 DiceReward 权重快照(按方向+点数),用于权重测试模拟
$instance = DiceReward::getCachedInstance(); $instance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $instance['by_tier_direction'] ?? []; $byTierDirection = $instance['by_tier_direction'] ?? [];
foreach ($byTierDirection as $tier => $byDir) { foreach ($byTierDirection as $tier => $byDir) {
foreach ($byDir as $dir => $rows) { foreach ($byDir as $dir => $rows) {
@@ -316,7 +327,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置) // BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
// JSON 结构 {"grid_number": weight, ...} // JSON 结构 {"grid_number": weight, ...}
$bigwinWeights = []; $bigwinWeights = [];
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN'); $bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN', $deptId);
foreach ($bigwinConfigs as $cfg) { foreach ($bigwinConfigs as $cfg) {
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0; $grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
if ($grid <= 0) { if ($grid <= 0) {
@@ -327,10 +338,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
} }
if ($paidConfigId > 0) { if ($paidConfigId > 0) {
$config = DiceLotteryPoolConfig::find($paidConfigId); $config = $this->findPoolConfigInDept($paidConfigId, $deptId, 'Paid pool config not found');
if (!$config) {
throw new ApiException('Paid pool config not found');
}
$tierWeightsSnapshot['paid'] = [ $tierWeightsSnapshot['paid'] = [
'T1' => (int) ($config->t1_weight ?? 0), 'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0), 'T2' => (int) ($config->t2_weight ?? 0),
@@ -359,10 +367,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
} }
if ($freeConfigId > 0) { if ($freeConfigId > 0) {
$config = DiceLotteryPoolConfig::find($freeConfigId); $config = $this->findPoolConfigInDept($freeConfigId, $deptId, 'Free pool config not found');
if (!$config) {
throw new ApiException('Free pool config not found');
}
$tierWeightsSnapshot['free'] = [ $tierWeightsSnapshot['free'] = [
'T1' => (int) ($config->t1_weight ?? 0), 'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0), 'T2' => (int) ($config->t2_weight ?? 0),
@@ -428,9 +433,94 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$record->bigwin_weight = $bigwinWeights ?: null; $record->bigwin_weight = $bigwinWeights ?: null;
$record->ante = $ante; $record->ante = $ante;
$record->admin_id = $adminId; $record->admin_id = $adminId;
$record->dept_id = $deptId;
$record->create_time = date('Y-m-d H:i:s'); $record->create_time = date('Y-m-d H:i:s');
$record->save(); $record->save();
return (int) $record->id; return (int) $record->id;
} }
/**
* 解析一键测试所属渠道:请求 dept_id > 奖池配置 dept_id > 渠道管理员本渠道
*/
private function resolveWeightTestDeptId(?array $adminInfo, $requestDeptId, array $params): int
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
foreach (['paid_lottery_config_id', 'free_lottery_config_id', 'lottery_config_id'] as $key) {
$poolId = isset($params[$key]) ? (int) $params[$key] : 0;
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
return $poolDeptId;
}
}
$scopeDeptId = AdminScopeHelper::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
return $scopeDeptId;
}
return $deptId;
}
/**
* 校验奖池配置属于当前渠道
*/
private function findPoolConfigInDept(int $poolId, int $deptId, string $notFoundMsg): DiceLotteryPoolConfig
{
$config = DiceLotteryPoolConfig::find($poolId);
if (!$config) {
throw new ApiException($notFoundMsg);
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($poolDeptId !== $deptId) {
throw new ApiException('POOL_CONFIG_NOT_IN_CHANNEL');
}
return $config;
}
/**
* 解析一键测试底注:优先 ante_config_id否则按 mult + 渠道校验
*/
private function resolveWeightTestAnte(array $params, int $deptId): int
{
$anteConfigId = isset($params['ante_config_id']) ? (int) $params['ante_config_id'] : 0;
if ($anteConfigId > 0) {
$config = DiceAnteConfig::find($anteConfigId);
if (! $config) {
throw new ApiException('ANTE_CONFIG_NOT_FOUND');
}
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($configDeptId !== $deptId) {
throw new ApiException('ANTE_CONFIG_NOT_IN_CHANNEL');
}
$mult = (int) ($config->mult ?? 0);
if ($mult <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
return $mult;
}
$ante = isset($params['ante']) ? (int) $params['ante'] : 0;
if ($ante <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
$anteQuery = DiceAnteConfig::where('mult', $ante);
ConfigScopeEditHelper::applyDeptIdWhere($anteQuery, $deptId);
if ($anteQuery->count() <= 0) {
throw new ApiException(ApiLang::translateParams('ANTE_NOT_ALLOWED', [$ante]));
}
return $ante;
}
} }

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\dice\logic\reward_config_record; namespace app\dice\logic\reward_config_record;
use app\api\logic\PlayStartLogic; use app\api\logic\PlayStartLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record_test\DicePlayRecordTest; use app\dice\model\play_record_test\DicePlayRecordTest;
use app\dice\model\reward_config_record\DiceRewardConfigRecord; use app\dice\model\reward_config_record\DiceRewardConfigRecord;
@@ -19,9 +20,13 @@ use support\think\Db;
class WeightTestRunner class WeightTestRunner
{ {
private const BATCH_SIZE = 10; private const BATCH_SIZE = 10;
/** 本次测试所属渠道(与 dice_reward_config_record.dept_id 一致) */
private int $runDeptId = 0;
/** 测试记录写库白名单字段 */ /** 测试记录写库白名单字段 */
private const PLAY_RECORD_TEST_COLUMNS = [ private const PLAY_RECORD_TEST_COLUMNS = [
'reward_config_record_id', 'reward_config_record_id',
'dept_id',
'admin_id', 'admin_id',
'lottery_config_id', 'lottery_config_id',
'lottery_type', 'lottery_type',
@@ -61,10 +66,15 @@ class WeightTestRunner
return; return;
} }
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find(); $this->runDeptId = $this->resolveRunDeptId($recordId, $record);
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find(); $deptId = $this->runDeptId;
DiceReward::setRequestDeptId($deptId);
DiceRewardConfig::clearRequestInstance();
$configType0 = DiceLotteryPoolConfig::findByNameForDept('default', $deptId);
$configType1 = DiceLotteryPoolConfig::findByNameForDept('killScore', $deptId);
if (!$configType0) { if (!$configType0) {
$this->markFailed($recordId, '彩金池配置 name=default 不存在'); $this->markFailed($recordId, '彩金池配置 name=default 不存在(当前渠道)');
return; return;
} }
@@ -79,12 +89,12 @@ class WeightTestRunner
$freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0); $freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0);
$paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0; $paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0;
if (!$paidPoolConfig) { if (!$paidPoolConfig || AdminScopeHelper::normalizeRecordDeptId($paidPoolConfig->dept_id ?? null) !== $deptId) {
$paidPoolConfig = $configType0; $paidPoolConfig = $configType0;
} }
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1; $freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
if (!$freePoolConfig) { if (!$freePoolConfig || AdminScopeHelper::normalizeRecordDeptId($freePoolConfig->dept_id ?? null) !== $deptId) {
$freePoolConfig = $configType0; $freePoolConfig = $configType1 ?: $configType0;
} }
if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) { if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) {
@@ -118,6 +128,7 @@ class WeightTestRunner
try { try {
$this->runChainFreeMode( $this->runChainFreeMode(
$recordId, $recordId,
$deptId,
$playLogic, $playLogic,
$paidS, $paidS,
$paidN, $paidN,
@@ -145,6 +156,9 @@ class WeightTestRunner
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]); Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
$this->markFailed($recordId, $e->getMessage()); $this->markFailed($recordId, $e->getMessage());
} finally {
DiceReward::clearRequestInstance();
DiceRewardConfig::clearRequestInstance();
} }
} }
@@ -153,6 +167,7 @@ class WeightTestRunner
*/ */
private function runChainFreeMode( private function runChainFreeMode(
int $recordId, int $recordId,
int $deptId,
PlayStartLogic $playLogic, PlayStartLogic $playLogic,
int $paidS, int $paidS,
int $paidN, int $paidN,
@@ -199,12 +214,12 @@ class WeightTestRunner
$customWeights = $freeTierWeightsCustom; $customWeights = $freeTierWeightsCustom;
} }
$row = $playLogic->simulateOnePlay($cfg, $dir, $lotteryType, $playAnte, $customWeights); $row = $playLogic->simulateOnePlay($cfg, $dir, $lotteryType, $playAnte, $customWeights, $deptId);
$winCoin = (float) ($row['win_coin'] ?? 0); $winCoin = (float) ($row['win_coin'] ?? 0);
$paidAmount = (float) ($row['paid_amount'] ?? 0); $paidAmount = (float) ($row['paid_amount'] ?? 0);
$playerProfitTotal += $winCoin - $paidAmount; $playerProfitTotal += $winCoin - $paidAmount;
$this->aggregate($row, $resultCounts, $tierCounts); $this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId); $buffer[] = $this->rowForInsert($row, $recordId, $deptId);
$done++; $done++;
if (!empty($row['grants_free_ticket'])) { if (!empty($row['grants_free_ticket'])) {
@@ -217,6 +232,58 @@ class WeightTestRunner
} }
} }
/**
* 解析本次测试渠道:优先读库字段,避免 ORM 字段缓存未含 dept_id 时读不到
*/
private function resolveRunDeptId(int $recordId, DiceRewardConfigRecord $record): int
{
$recordTable = (new DiceRewardConfigRecord())->getTable();
$fromDb = Db::table($recordTable)->where('id', $recordId)->value('dept_id');
$deptId = AdminScopeHelper::normalizeRecordDeptId($fromDb);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
return $this->resolveDeptIdFromRecordPools($record, $deptId);
}
/**
* 历史记录 dept_id=0 时,从关联奖池配置反推并回写
*/
private function resolveDeptIdFromRecordPools(DiceRewardConfigRecord $record, int $fallbackDeptId): int
{
foreach (
[
(int) ($record->paid_lottery_config_id ?? 0),
(int) ($record->free_lottery_config_id ?? 0),
(int) ($record->lottery_config_id ?? 0),
] as $poolId
) {
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
if (AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null) !== $poolDeptId) {
$record->dept_id = $poolDeptId;
$record->save();
}
return $poolDeptId;
}
}
return $fallbackDeptId;
}
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
{ {
$grid = (int) ($row['roll_number_for_count'] ?? $row['roll_number'] ?? 0); $grid = (int) ($row['roll_number_for_count'] ?? $row['roll_number'] ?? 0);
@@ -229,10 +296,14 @@ class WeightTestRunner
} }
} }
private function rowForInsert(array $row, int $rewardConfigRecordId): array private function rowForInsert(array $row, int $rewardConfigRecordId, int $deptId): array
{ {
$bindDeptId = ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)
? $this->runDeptId
: $deptId;
$out = [ $out = [
'reward_config_record_id' => $rewardConfigRecordId, 'reward_config_record_id' => $rewardConfigRecordId,
'dept_id' => $bindDeptId,
]; ];
$keys = [ $keys = [
'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
@@ -254,7 +325,7 @@ class WeightTestRunner
return; return;
} }
$this->insertBuffer($buffer); $this->insertBuffer($buffer);
$buffer = []; array_splice($buffer, 0, count($buffer));
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts, $recordTotalPlayCount); $this->updateProgress($recordId, $done, $resultCounts, $tierCounts, $recordTotalPlayCount);
} }
@@ -263,6 +334,7 @@ class WeightTestRunner
if (empty($rows)) { if (empty($rows)) {
return; return;
} }
$table = (new DicePlayRecordTest())->getTable();
foreach ($rows as $row) { foreach ($rows as $row) {
if (!is_array($row)) { if (!is_array($row)) {
continue; continue;
@@ -273,6 +345,9 @@ class WeightTestRunner
$payload[$column] = $row[$column]; $payload[$column] = $row[$column];
} }
} }
if (! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$payload['dept_id'] = $this->runDeptId;
}
if (!array_key_exists('create_time', $payload) || $payload['create_time'] === null || $payload['create_time'] === '') { if (!array_key_exists('create_time', $payload) || $payload['create_time'] === null || $payload['create_time'] === '') {
$payload['create_time'] = date('Y-m-d H:i:s'); $payload['create_time'] = date('Y-m-d H:i:s');
} }
@@ -282,10 +357,26 @@ class WeightTestRunner
if ($payload === []) { if ($payload === []) {
continue; continue;
} }
Db::name((new DicePlayRecordTest())->getTable())->insert($payload); // strict(false):表结构新增 dept_id 后,避免连接层字段缓存未刷新导致插入被丢弃
Db::table($table)->strict(false)->insert($payload);
} }
} }
/**
* 将本批测试明细 dept_id 与主记录对齐(修复历史 worker 未写入 dept_id 的情况)
*/
private function syncPlayRecordTestDeptId(int $recordId, int $deptId): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
return;
}
DicePlayRecordTest::where('reward_config_record_id', $recordId)
->where(function ($query) {
$query->whereNull('dept_id')->whereOr('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
})
->update(['dept_id' => $deptId]);
}
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts, ?int $totalPlayCount = null): void private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts, ?int $totalPlayCount = null): void
{ {
$record = DiceRewardConfigRecord::find($recordId); $record = DiceRewardConfigRecord::find($recordId);
@@ -308,6 +399,13 @@ class WeightTestRunner
{ {
$record = DiceRewardConfigRecord::find($recordId); $record = DiceRewardConfigRecord::find($recordId);
if ($record) { if ($record) {
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (AdminScopeHelper::isTemplateDeptId($deptId) && ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$deptId = $this->runDeptId;
$record->dept_id = $deptId;
}
$this->syncPlayRecordTestDeptId($recordId, $deptId);
// 平台盈利通过关联测试记录统计 // 平台盈利通过关联测试记录统计
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId); $platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空 // 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace app\dice\model;
use plugin\saiadmin\basic\think\BaseModel as SaiBaseModel;
/**
* 大富翁模块模型基类:删除均为硬删除(物理删除)
*/
abstract class DiceModel extends SaiBaseModel
{
/**
* @param mixed $data
*/
public static function destroy($data, bool $force = true): bool
{
return parent::destroy($data, true);
}
public function delete(): bool
{
return $this->force()->delete();
}
}

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\ante_config; namespace app\dice\model\ante_config;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
/** /**
* 底注配置模型 * 底注配置模型
@@ -19,7 +19,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property string $create_time 创建时间 * @property string $create_time 创建时间
* @property string $update_time 更新时间 * @property string $update_time 更新时间
*/ */
class DiceAnteConfig extends BaseModel class DiceAnteConfig extends DiceModel
{ {
protected $pk = 'id'; protected $pk = 'id';

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\config; namespace app\dice\model\config;
use plugin\saiadmin\basic\eloquent\BaseModel; use app\dice\model\DiceModel;
/** /**
* 摇色子配置模型 * 摇色子配置模型
@@ -23,7 +23,7 @@ use plugin\saiadmin\basic\eloquent\BaseModel;
* @property $create_time 创建时间 * @property $create_time 创建时间
* @property $update_time 修改时间 * @property $update_time 修改时间
*/ */
class DiceConfig extends BaseModel class DiceConfig extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -4,14 +4,14 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\game; namespace app\dice\model\game;
use plugin\saiadmin\basic\eloquent\BaseModel; use app\dice\model\DiceModel;
/** /**
* 游戏管理模型 * 游戏管理模型
* *
* dice_game 游戏配置表 * dice_game 游戏配置表
*/ */
class DiceGame extends BaseModel class DiceGame extends DiceModel
{ {
protected $primaryKey = 'id'; protected $primaryKey = 'id';

View File

@@ -6,7 +6,9 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\lottery_pool_config; namespace app\dice\model\lottery_pool_config;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
/** /**
* 色子奖池配置模型 * 色子奖池配置模型
@@ -27,7 +29,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $t5_weight T5池权重 * @property $t5_weight T5池权重
* @property $profit_amount 池子累计盈利(每局付费按 win_coin-paid_amount免费按 win_coin 累加;仅展示不可编辑) * @property $profit_amount 池子累计盈利(每局付费按 win_coin-paid_amount免费按 win_coin 累加;仅展示不可编辑)
*/ */
class DiceLotteryPoolConfig extends BaseModel class DiceLotteryPoolConfig extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键
@@ -41,6 +43,16 @@ class DiceLotteryPoolConfig extends BaseModel
*/ */
protected $table = 'dice_lottery_pool_config'; protected $table = 'dice_lottery_pool_config';
/**
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
*/
public static function findByNameForDept(string $name, int $deptId): ?self
{
$query = (new self())->where('name', $name);
ConfigScopeEditHelper::applyDeptIdWhere($query, AdminScopeHelper::normalizeRecordDeptId($deptId));
return $query->find();
}
/** /**
* 名称 搜索 * 名称 搜索
*/ */

View File

@@ -9,7 +9,7 @@ namespace app\dice\model\play_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
use app\dice\model\reward\DiceRewardConfig; use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
/** /**
@@ -41,7 +41,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间 * @property $create_time 创建时间
* @property $update_time 修改时间 * @property $update_time 修改时间
*/ */
class DicePlayRecord extends BaseModel class DicePlayRecord extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\play_record_test; namespace app\dice\model\play_record_test;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use app\dice\model\reward_config_record\DiceRewardConfigRecord; use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
@@ -37,7 +37,7 @@ use think\model\relation\BelongsTo;
* @property $admin_id 所属管理员 * @property $admin_id 所属管理员
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id权重测试记录 * @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id权重测试记录
*/ */
class DicePlayRecordTest extends BaseModel class DicePlayRecordTest extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -6,7 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\player; namespace app\dice\model\player;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig; use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
/** /**
@@ -15,7 +15,8 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* dice_player 大富翁-玩家 * dice_player 大富翁-玩家
* *
* @property $id ID * @property $id ID
* @property $username 用户名 * @property $dept_id 所属渠道ID
* @property $username 用户名(同渠道内唯一)
* @property $phone 手机 * @property $phone 手机
* @property $uid uid * @property $uid uid
* @property $name 昵称 * @property $name 昵称
@@ -37,7 +38,7 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* @property $update_time 更新时间 * @property $update_time 更新时间
* @property $delete_time 删除时间 * @property $delete_time 删除时间
*/ */
class DicePlayer extends BaseModel class DicePlayer extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player_ticket_record; namespace app\dice\model\player_ticket_record;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
/** /**
@@ -27,7 +27,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间 * @property $create_time 创建时间
* @property $update_time 修改时间 * @property $update_time 修改时间
*/ */
class DicePlayerTicketRecord extends BaseModel class DicePlayerTicketRecord extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player_wallet_record; namespace app\dice\model\player_wallet_record;
use app\dice\model\player\DicePlayer; use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
@@ -31,7 +31,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间 * @property $create_time 创建时间
* @property $update_time 修改时间 * @property $update_time 修改时间
*/ */
class DicePlayerWalletRecord extends BaseModel class DicePlayerWalletRecord extends DiceModel
{ {
/** /**
* 数据表主键 * 数据表主键

View File

@@ -4,7 +4,9 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\reward; namespace app\dice\model\reward;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
use support\think\Cache; use support\think\Cache;
/** /**
@@ -25,42 +27,70 @@ use support\think\Cache;
* @property $remark 备注(来自config) * @property $remark 备注(来自config)
* @property $type 奖励类型(来自config) * @property $type 奖励类型(来自config)
*/ */
class DiceReward extends BaseModel class DiceReward extends DiceModel
{ {
/** 方向:顺时针 */ /** 方向:顺时针 */
public const DIRECTION_CLOCKWISE = 0; public const DIRECTION_CLOCKWISE = 0;
/** 方向:逆时针 */ /** 方向:逆时针 */
public const DIRECTION_COUNTERCLOCKWISE = 1; public const DIRECTION_COUNTERCLOCKWISE = 1;
/** 缓存键:奖励对照实例 */ /** 缓存键前缀:奖励对照实例(按渠道分键) */
private const CACHE_KEY_INSTANCE = 'dice:reward:instance'; private const CACHE_KEY_INSTANCE = 'dice:reward:instance';
private const CACHE_TTL = 86400 * 30; private const CACHE_TTL = 86400 * 30;
private static ?array $instance = null; private static ?array $instance = null;
private static ?int $requestDeptId = null;
protected $table = 'dice_reward'; protected $table = 'dice_reward';
/** 主键 id 自增,唯一约束 (direction, grid_number) */ /** 主键 id 自增,唯一约束 (direction, grid_number) */
protected $pk = 'id'; protected $pk = 'id';
private static function cacheKeyForDept(int $deptId): string
{
return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
private static function resolveDeptId(?int $deptId): int
{
if ($deptId !== null) {
return AdminScopeHelper::normalizeRecordDeptId($deptId);
}
if (self::$requestDeptId !== null) {
return self::$requestDeptId;
}
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
/**
* 请求级设置当前渠道(一键测试 worker 内调用 simulateOnePlay 前设置)
*/
public static function setRequestDeptId(?int $deptId): void
{
self::$requestDeptId = $deptId !== null
? AdminScopeHelper::normalizeRecordDeptId($deptId)
: null;
}
/** /**
* 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比) * 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比)
* 优先从共享缓存读取,保证多进程(如一键测试 worker与数据库一致
* @return array{list: array, by_tier_direction: array}
*/ */
public static function getCachedInstance(): array public static function getCachedInstance(?int $deptId = null): array
{ {
$instance = Cache::get(self::CACHE_KEY_INSTANCE); $deptId = self::resolveDeptId($deptId);
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) { if ($instance !== null && is_array($instance)) {
self::$instance = $instance; self::$instance = $instance;
return $instance; return $instance;
} }
if (self::$instance !== null) { if (self::$instance !== null && self::$requestDeptId === $deptId) {
return self::$instance; return self::$instance;
} }
self::refreshCache(); self::refreshCache($deptId);
$instance = Cache::get(self::CACHE_KEY_INSTANCE); $instance = Cache::get($cacheKey);
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance(); self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
return self::$instance; return self::$instance;
} }
@@ -69,9 +99,9 @@ class DiceReward extends BaseModel
* 按档位+方向取权重列表(用于抽奖:该档位该方向下 end_index => weight * 按档位+方向取权重列表(用于抽奖:该档位该方向下 end_index => weight
* @return array<int, int> end_index => weight * @return array<int, int> end_index => weight
*/ */
public static function getCachedByTierAndDirection(string $tier, int $direction): array public static function getCachedByTierAndDirection(string $tier, int $direction, ?int $deptId = null): array
{ {
$inst = self::getCachedInstance(); $inst = self::getCachedInstance($deptId);
$byTierDirection = $inst['by_tier_direction'] ?? []; $byTierDirection = $inst['by_tier_direction'] ?? [];
$list = $byTierDirection[$tier][$direction] ?? []; $list = $byTierDirection[$tier][$direction] ?? [];
$result = []; $result = [];
@@ -84,11 +114,14 @@ class DiceReward extends BaseModel
} }
/** /**
* 重新从数据库加载并写入缓存;修改/新增/删除后需调用以实例化 * 按渠道从数据库加载并写入缓存
*/ */
public static function refreshCache(): void public static function refreshCache(?int $deptId = null): void
{ {
$list = (new self())->order('tier')->order('direction')->order('end_index')->select()->toArray(); $deptId = self::resolveDeptId($deptId);
$query = (new self())->order('tier')->order('direction')->order('end_index');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTierDirection = []; $byTierDirection = [];
foreach ($list as $row) { foreach ($list as $row) {
$tier = isset($row['tier']) ? (string) $row['tier'] : ''; $tier = isset($row['tier']) ? (string) $row['tier'] : '';
@@ -103,11 +136,12 @@ class DiceReward extends BaseModel
$byTierDirection[$tier][$direction][] = $row; $byTierDirection[$tier][$direction][] = $row;
} }
} }
self::$instance = [ $instance = [
'list' => $list, 'list' => $list,
'by_tier_direction' => $byTierDirection, 'by_tier_direction' => $byTierDirection,
]; ];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL); self::$instance = $instance;
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
} }
private static function buildEmptyInstance(): array private static function buildEmptyInstance(): array
@@ -121,20 +155,29 @@ class DiceReward extends BaseModel
public static function clearRequestInstance(): void public static function clearRequestInstance(): void
{ {
self::$instance = null; self::$instance = null;
self::$requestDeptId = null;
}
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
} }
public static function onAfterInsert($model): void public static function onAfterInsert($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
public static function onAfterUpdate($model): void public static function onAfterUpdate($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
public static function onAfterDelete($model): void public static function onAfterDelete($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
} }

View File

@@ -6,8 +6,10 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\reward_config; namespace app\dice\model\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward; use app\dice\model\reward\DiceReward;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use support\think\Cache; use support\think\Cache;
/** /**
@@ -27,7 +29,7 @@ use support\think\Cache;
* @property $create_time 创建时间 * @property $create_time 创建时间
* @property $update_time 修改时间 * @property $update_time 修改时间
*/ */
class DiceRewardConfig extends BaseModel class DiceRewardConfig extends DiceModel
{ {
/** 缓存键:彩金池奖励列表实例 */ /** 缓存键:彩金池奖励列表实例 */
private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance'; private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance';
@@ -45,31 +47,35 @@ class DiceRewardConfig extends BaseModel
* 优先从共享缓存读取,保证多进程(如一键测试 worker能拿到最新配置与数据库一致 * 优先从共享缓存读取,保证多进程(如一键测试 worker能拿到最新配置与数据库一致
* @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float} * @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float}
*/ */
public static function getCachedInstance(): array public static function getCachedInstance(?int $deptId = null): array
{ {
$instance = Cache::get(self::CACHE_KEY_INSTANCE); if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) { if ($instance !== null && is_array($instance)) {
self::$instance = $instance;
return $instance; return $instance;
} }
if (self::$instance !== null) { self::refreshCache($deptId);
return self::$instance; $instance = Cache::get($cacheKey);
} return is_array($instance) ? $instance : self::buildEmptyInstance();
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 private static function cacheKeyForDept(int $deptId): string
{ {
$inst = self::getCachedInstance(); return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
public static function getCachedList(?int $deptId = null): array
{
$inst = self::getCachedInstance($deptId);
return $inst['list'] ?? []; return $inst['list'] ?? [];
} }
public static function getCachedById(int $id): ?array public static function getCachedById(int $id, ?int $deptId = null): ?array
{ {
$list = self::getCachedList(); $list = self::getCachedList($deptId);
foreach ($list as $row) { foreach ($list as $row) {
if (isset($row['id']) && (int) $row['id'] === $id) { if (isset($row['id']) && (int) $row['id'] === $id) {
return $row; return $row;
@@ -79,11 +85,16 @@ class DiceRewardConfig extends BaseModel
} }
/** /**
* 重新从数据库加载并写入缓存(按档位+权重抽 grid_number含 by_tier、by_tier_grid * 按渠道从数据库加载并写入缓存(避免多渠道配置混在同一缓存键
*/ */
public static function refreshCache(): void public static function refreshCache(?int $deptId = null): void
{ {
$list = (new self())->order('id', 'asc')->select()->toArray(); if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$query = (new self())->order('id', 'asc');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTier = []; $byTier = [];
$byTierGrid = []; $byTierGrid = [];
foreach ($list as $row) { foreach ($list as $row) {
@@ -103,13 +114,16 @@ class DiceRewardConfig extends BaseModel
} }
} }
$minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev')); $minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev'));
self::$instance = [ $instance = [
'list' => $list, 'list' => $list,
'by_tier' => $byTier, 'by_tier' => $byTier,
'by_tier_grid' => $byTierGrid, 'by_tier_grid' => $byTierGrid,
'min_real_ev' => $minRealEv, 'min_real_ev' => $minRealEv,
]; ];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL); Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
if ($deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
self::$instance = $instance;
}
} }
private static function buildEmptyInstance(): array private static function buildEmptyInstance(): array
@@ -125,9 +139,9 @@ class DiceRewardConfig extends BaseModel
/** /**
* 按档位+色子点数取一条(用于 BIGWIN * 按档位+色子点数取一条(用于 BIGWIN
*/ */
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber, ?int $deptId = null): ?array
{ {
$inst = self::getCachedInstance(); $inst = self::getCachedInstance($deptId);
$byTierGrid = $inst['by_tier_grid'] ?? []; $byTierGrid = $inst['by_tier_grid'] ?? [];
$tierData = $byTierGrid[$tier] ?? []; $tierData = $byTierGrid[$tier] ?? [];
$row = $tierData[$gridNumber] ?? null; $row = $tierData[$gridNumber] ?? null;
@@ -143,9 +157,9 @@ class DiceRewardConfig extends BaseModel
/** /**
* 从缓存按档位取奖励列表(不含权重,仅配置) * 从缓存按档位取奖励列表(不含权重,仅配置)
*/ */
public static function getCachedByTier(string $tier): array public static function getCachedByTier(string $tier, ?int $deptId = null): array
{ {
$inst = self::getCachedInstance(); $inst = self::getCachedInstance($deptId);
$byTier = $inst['by_tier'] ?? []; $byTier = $inst['by_tier'] ?? [];
return $byTier[$tier] ?? []; return $byTier[$tier] ?? [];
} }
@@ -155,10 +169,10 @@ class DiceRewardConfig extends BaseModel
* @param int $direction 0=顺时针, 1=逆时针 * @param int $direction 0=顺时针, 1=逆时针
* @return array 每行含 id, grid_number, real_ev, tier, weight 等 * @return array 每行含 id, grid_number, real_ev, tier, weight 等
*/ */
public static function getCachedByTierForDirection(string $tier, int $direction): array public static function getCachedByTierForDirection(string $tier, int $direction, ?int $deptId = null): array
{ {
$list = self::getCachedByTier($tier); $list = self::getCachedByTier($tier, $deptId);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction); $weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction, $deptId);
foreach ($list as $i => $row) { foreach ($list as $i => $row) {
$id = isset($row['id']) ? (int) $row['id'] : 0; $id = isset($row['id']) ? (int) $row['id'] : 0;
$list[$i]['weight'] = $weightMap[$id] ?? 1; $list[$i]['weight'] = $weightMap[$id] ?? 1;
@@ -171,19 +185,27 @@ class DiceRewardConfig extends BaseModel
self::$instance = null; self::$instance = null;
} }
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
}
public static function onAfterInsert($model): void public static function onAfterInsert($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
public static function onAfterUpdate($model): void public static function onAfterUpdate($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
public static function onAfterDelete($model): void public static function onAfterDelete($model): void
{ {
self::refreshCache(); self::refreshCacheForModel($model);
} }
public function searchGridNumberMinAttr($query, $value) public function searchGridNumberMinAttr($query, $value)

View File

@@ -4,7 +4,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\model\reward_config; namespace app\dice\model\reward_config;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
/** /**
* 权重配比测试记录模型 * 权重配比测试记录模型
@@ -20,7 +20,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property int|null $admin_id 执行测试的管理员ID * @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间 * @property string|null $create_time 创建时间
*/ */
class DiceRewardConfigRecord extends BaseModel class DiceRewardConfigRecord extends DiceModel
{ {
protected $pk = 'id'; protected $pk = 'id';

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\reward_config_record; namespace app\dice\model\reward_config_record;
use app\dice\model\play_record_test\DicePlayRecordTest; use app\dice\model\play_record_test\DicePlayRecordTest;
use plugin\saiadmin\basic\think\BaseModel; use app\dice\model\DiceModel;
use think\model\relation\HasMany; use think\model\relation\HasMany;
/** /**
@@ -43,7 +43,7 @@ use think\model\relation\HasMany;
* @property int|null $admin_id 执行测试的管理员ID * @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间 * @property string|null $create_time 创建时间
*/ */
class DiceRewardConfigRecord extends BaseModel class DiceRewardConfigRecord extends DiceModel
{ {
/** 状态:失败 */ /** 状态:失败 */
public const STATUS_FAIL = -1; public const STATUS_FAIL = -1;

View File

@@ -0,0 +1,497 @@
<?php
declare(strict_types=1);
namespace app\dice\service;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道默认配置复制、补齐与关联删除
* 默认配置dept_id = 0与超管「默认配置模板」一致
*/
class DiceChannelConfigService
{
/** 需 (dept_id, id) 复合唯一的配置表 */
private const COMPOSITE_KEY_TABLES = [
'dice_config',
'dice_reward_config',
];
/** 从默认模板复制的配置表 */
private const CONFIG_TABLES = [
'dice_config',
'dice_ante_config',
'dice_lottery_pool_config',
'dice_reward_config',
'dice_game',
];
/** 复制时必须保留主键 id非自增或固定 0-25 */
private const TABLES_KEEP_ID = [
'dice_config',
'dice_reward_config',
];
/** 可关联删除的业务表 */
private const RELATION_TABLES = [
'dice_config' => ['label' => '游戏键值配置', 'group' => 'configs'],
'dice_ante_config' => ['label' => '底注配置', 'group' => 'configs'],
'dice_lottery_pool_config' => ['label' => '彩金池配置', 'group' => 'configs'],
'dice_reward_config' => ['label' => '奖励索引配置', 'group' => 'configs'],
'dice_reward' => ['label' => '中奖概率(奖励对照)', 'group' => 'configs'],
'dice_game' => ['label' => '游戏管理', 'group' => 'configs'],
'dice_player' => ['label' => '玩家', 'group' => 'players'],
'dice_play_record' => ['label' => '抽奖记录', 'group' => 'records'],
'dice_play_record_test' => ['label' => '测试抽奖记录', 'group' => 'records'],
'dice_player_wallet_record' => ['label' => '钱包流水', 'group' => 'records'],
'dice_player_ticket_record' => ['label' => '票券记录', 'group' => 'records'],
'dice_reward_config_record' => ['label' => '权重测试记录', 'group' => 'records'],
];
/**
* 默认模板 dept_id 统一为 0并为固定 id 的配置表建立 (dept_id, id) 唯一约束
*/
public function ensureConfigCompositeKeys(): void
{
foreach (array_merge(self::CONFIG_TABLES, ['dice_reward']) as $table) {
if ($this->tableHasColumn($table, 'dept_id')) {
Db::table($table)->whereNull('dept_id')->update(['dept_id' => AdminScopeHelper::DEFAULT_TEMPLATE_DEPT]);
}
}
foreach (self::COMPOSITE_KEY_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (!$this->tableHasColumn($table, 'row_id')) {
if ($table === 'dice_reward_config') {
Db::execute(
'ALTER TABLE `dice_reward_config`'
. ' MODIFY `id` int(11) NOT NULL COMMENT \'ID\','
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
} else {
Db::execute(
'ALTER TABLE `dice_config`'
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
}
}
$indexes = Db::query("SHOW INDEX FROM `{$table}` WHERE Key_name = 'uk_dept_config'");
if (empty($indexes)) {
Db::execute("ALTER TABLE `{$table}` ADD UNIQUE KEY `uk_dept_config` (`dept_id`, `id`)");
}
}
$this->ensureDeptScopedUniqueIndexes();
}
/**
* 将全局唯一键改为按渠道 (dept_id, 业务键) 唯一,便于复制默认模板
*/
private function ensureDeptScopedUniqueIndexes(): void
{
if ($this->tableHasColumn('dice_lottery_pool_config', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'dice_lottery_poll_config_unique'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` DROP INDEX `dice_lottery_poll_config_unique`');
}
$uk = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'uk_dept_name'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` ADD UNIQUE KEY `uk_dept_name` (`dept_id`, `name`)');
}
}
if ($this->tableHasColumn('dice_game', 'dept_id')) {
foreach (['uk_dice_game_code', 'uk_dice_game_key'] as $idx) {
$exists = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = '{$idx}'");
if (!empty($exists)) {
Db::execute("ALTER TABLE `dice_game` DROP INDEX `{$idx}`");
}
}
$ukCode = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_code'");
if (empty($ukCode)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_code` (`dept_id`, `game_code`)');
}
$ukKey = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_key'");
if (empty($ukKey)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_key` (`dept_id`, `game_key`)');
}
}
if ($this->tableHasColumn('dice_reward', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_direction_grid_number'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_reward` DROP INDEX `uk_direction_grid_number`');
}
$uk = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_dept_direction_grid'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_reward` ADD UNIQUE KEY `uk_dept_direction_grid` (`dept_id`, `direction`, `grid_number`)');
}
}
}
/**
* 将当前无 dept_id 的配置标记为默认模板(仅执行一次迁移)
*/
public function markLegacyConfigAsDefault(): int
{
$this->ensureConfigCompositeKeys();
$total = 0;
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$total += $this->countByDept($table, AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
}
return $total;
}
/**
* 为单个渠道从默认模板复制配置(已存在则跳过)
*/
public function copyDefaultConfigToDept(int $deptId): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$result = ['dept_id' => $deptId, 'copied' => [], 'skipped' => [], 'merged' => []];
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (in_array($table, self::TABLES_KEEP_ID, true)) {
$merged = $this->syncCompositeIdTableFromDefault($table, $deptId);
if ($merged > 0) {
$result['merged'][$table] = $merged;
} elseif ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
}
continue;
}
if ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
continue;
}
$rows = $this->defaultTemplateRows($table);
if (empty($rows)) {
continue;
}
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
}
$result['copied'][] = $table;
}
$this->ensureRewardReferenceForDept($deptId);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 按业务 id 从默认模板补齐配置dice_config / dice_reward_config
*/
private function syncCompositeIdTableFromDefault(string $table, int $deptId): int
{
$templateRows = $this->defaultTemplateRows($table);
if (empty($templateRows)) {
return 0;
}
$inserted = 0;
foreach ($templateRows as $row) {
$row = (array) $row;
if (!isset($row['id'])) {
continue;
}
$businessId = $row['id'];
$exists = Db::table($table)->where('dept_id', $deptId)->where('id', $businessId)->count();
if ($exists > 0) {
continue;
}
unset($row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
$inserted++;
}
return $inserted;
}
/**
* 渠道已有奖励索引时,自动生成 dice_reward 对照表
*/
public function ensureRewardReferenceForDept(int $deptId): void
{
if ($deptId <= 0 || !$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) <= 0) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
$logic = new DiceRewardLogic();
$logic->createRewardReferenceFromConfig($deptId);
}
/**
* 复制默认 dice_reward 到渠道
*/
public function copyDefaultRewardsToDept(int $deptId): void
{
$this->ensureRewardReferenceForDept($deptId);
if (!$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) > 0) {
return;
}
$rows = $this->defaultTemplateRows('dice_reward');
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id']);
unset($row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table('dice_reward')->insert($row);
}
}
/**
* 为所有已有渠道补齐缺失配置
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::column('id');
$summary = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$summary[$deptId] = $this->copyDefaultConfigToDept($deptId);
}
return $summary;
}
/**
* 修复已删除渠道 ID、无管理员关联的遗留数据归并到首个顶级渠道
*/
public function repairOrphanDeptReferences(): array
{
$validDeptIds = array_map('intval', SystemDept::column('id') ?: []);
if (empty($validDeptIds)) {
return [];
}
$rootDeptId = min($validDeptIds);
$stats = [];
$inList = implode(',', $validDeptIds);
$stats['sa_system_user'] = Db::execute(
"UPDATE sa_system_user SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
$bizTables = [
'dice_player',
'dice_play_record',
'dice_play_record_test',
'dice_player_wallet_record',
'dice_player_ticket_record',
'dice_reward_config_record',
];
foreach ($bizTables as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$stats[$table . '_invalid_dept'] = Db::execute(
"UPDATE `{$table}` SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
}
return $stats;
}
/**
* 根据管理员/玩家回填 dept_id
*/
public function backfillDataDeptId(): array
{
$stats = $this->repairOrphanDeptReferences();
if ($this->tableHasColumn('dice_player', 'dept_id') && $this->tableHasColumn('dice_player', 'admin_id')) {
$stats['dice_player'] = Db::execute(
'UPDATE dice_player p INNER JOIN sa_system_user u ON p.admin_id = u.id
SET p.dept_id = u.dept_id WHERE (p.dept_id IS NULL OR p.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
$validDeptIds = SystemDept::column('id') ?: [];
if (!empty($validDeptIds) && $this->tableHasColumn('dice_player', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_player_legacy'] = Db::table('dice_player')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_wallet_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_ticket_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record_test'));
if (!empty($validDeptIds) && $this->tableHasColumn('dice_play_record_test', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_play_record_test_legacy'] = Db::table('dice_play_record_test')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
if ($this->tableHasColumn('dice_reward_config_record', 'dept_id')) {
$stats['dice_reward_config_record'] = Db::execute(
'UPDATE dice_reward_config_record r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
return $stats;
}
/**
* 删除渠道前关联数据统计
*/
public function getDestroyPreview(array $deptIds): array
{
$items = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$dept = SystemDept::find($deptId);
$row = [
'dept_id' => $deptId,
'dept_name' => $dept ? $dept->name : '',
'user_count' => SystemUser::where('dept_id', $deptId)->count(),
'relations' => [],
];
foreach (self::RELATION_TABLES as $table => $meta) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$count = $this->countByDept($table, $deptId);
if ($count > 0) {
$row['relations'][] = [
'table' => $table,
'label' => $meta['label'],
'group' => $meta['group'],
'count' => $count,
];
}
}
$items[] = $row;
}
return $items;
}
/**
* 删除渠道及勾选的关联数据
*
* @param array $deleteTables 要删除的表名列表
*/
public function destroyDeptWithRelations(int $deptId, array $deleteTables): void
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$userCount = SystemUser::where('dept_id', $deptId)->count();
if ($userCount > 0) {
throw new ApiException('This channel has users, please delete or transfer them first');
}
$allowed = array_keys(self::RELATION_TABLES);
foreach ($deleteTables as $table) {
if (!in_array($table, $allowed, true)) {
continue;
}
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
Db::table($table)->where('dept_id', $deptId)->delete();
}
SystemDept::destroy($deptId, true);
DiceRewardConfig::refreshCache($deptId);
DiceReward::refreshCache($deptId);
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRows(string $table): array
{
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$rows = Db::table($table)->where('dept_id', $templateId)->select()->toArray();
if (!empty($rows)) {
return $rows;
}
return Db::table($table)->whereNull('dept_id')->select()->toArray();
}
private function backfillRecordDeptIdByPlayer(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'player_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN dice_player p ON r.player_id = p.id
SET r.dept_id = p.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND p.dept_id IS NOT NULL AND p.dept_id > 0"
),
];
}
private function backfillRecordDeptIdByAdmin(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'admin_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0"
),
];
}
private function countByDept(string $table, ?int $deptId): int
{
$query = Db::table($table);
if ($deptId === null || $deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
} else {
$query->where('dept_id', $deptId);
}
return $query->count();
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -6,6 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\dice\validate\player; namespace app\dice\validate\player;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\basic\BaseValidate;
/** /**
@@ -17,7 +18,7 @@ class DicePlayerValidate extends BaseValidate
* 定义验证规则 * 定义验证规则
*/ */
protected $rule = [ protected $rule = [
'username' => 'require', 'username' => 'require|unique:' . DicePlayer::class . ',username^dept_id',
'name' => 'require', 'name' => 'require',
'phone' => 'require', 'phone' => 'require',
'password' => 'require', 'password' => 'require',
@@ -30,6 +31,7 @@ class DicePlayerValidate extends BaseValidate
*/ */
protected $message = [ protected $message = [
'username' => '用户名必须填写', 'username' => '用户名必须填写',
'username.unique' => 'PLAYER_USERNAME_DEPT_UNIQUE',
'name' => '昵称必须填写', 'name' => '昵称必须填写',
'phone' => '手机号必须填写', 'phone' => '手机号必须填写',
'password' => '密码必须填写', 'password' => '密码必须填写',

View File

@@ -6,7 +6,7 @@ return [
// 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777 // 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777
'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'), 'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'),
// 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token // 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token
'game_url' => env('GAME_URL', 'dice-game.h55555game.top'), 'game_url' => env('GAME_URL', 'dice-v3-game.h55555game.top'),
// 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验 // 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验
'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'), 'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'),
// 登录会话过期时间(秒),默认 7 天 // 登录会话过期时间(秒),默认 7 天

View File

@@ -27,7 +27,6 @@ class UserInfoCache
'expire' => 60 * 60 * 4, 'expire' => 60 * 60 * 4,
'dept' => 'saiadmin:user_cache:dept_', 'dept' => 'saiadmin:user_cache:dept_',
'role' => 'saiadmin:user_cache:role_', 'role' => 'saiadmin:user_cache:role_',
'post' => 'saiadmin:user_cache:post_',
]); ]);
} }
@@ -73,11 +72,6 @@ class UserInfoCache
$tags[] = $cache['role'] . $role['id']; $tags[] = $cache['role'] . $role['id'];
} }
} }
if (!empty($data['postList'])) {
foreach ($data['postList'] as $post) {
$tags[] = $cache['post'] . $post['id'];
}
}
Cache::tag($tags)->set($cache['prefix'] . $uid, $data, $cache['expire']); Cache::tag($tags)->set($cache['prefix'] . $uid, $data, $cache['expire']);
return $data; return $data;
} }
@@ -125,21 +119,4 @@ class UserInfoCache
return Cache::tag($tags)->clear(); return Cache::tag($tags)->clear();
} }
/**
* 清理岗位下所有用户缓存
*/
public static function clearUserInfoByPostId($post_id): bool
{
$cache = static::cacheConfig();
if (is_array($post_id)) {
$tags = [];
foreach ($post_id as $id) {
$tags[] = $cache['post'] . $id;
}
} else {
$tags = $cache['post'] . $post_id;
}
return Cache::tag($tags)->clear();
}
} }

View File

@@ -14,7 +14,7 @@ use support\Request;
use support\Response; use support\Response;
/** /**
* 部门控制器 * 渠道控制器
*/ */
class SystemDeptController extends BaseController class SystemDeptController extends BaseController
{ {
@@ -33,7 +33,7 @@ class SystemDeptController extends BaseController
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
#[Permission('部门数据列表', 'core:dept:index')] #[Permission('渠道数据列表', 'core:dept:index')]
public function index(Request $request) : Response public function index(Request $request) : Response
{ {
$where = $request->more([ $where = $request->more([
@@ -50,7 +50,7 @@ class SystemDeptController extends BaseController
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
#[Permission('部门数据读取', 'core:dept:read')] #[Permission('渠道数据读取', 'core:dept:read')]
public function read(Request $request) : Response public function read(Request $request) : Response
{ {
$id = $request->input('id', ''); $id = $request->input('id', '');
@@ -68,7 +68,7 @@ class SystemDeptController extends BaseController
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
#[Permission('部门数据添加', 'core:dept:save')] #[Permission('渠道数据添加', 'core:dept:save')]
public function save(Request $request): Response public function save(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
@@ -86,7 +86,7 @@ class SystemDeptController extends BaseController
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
#[Permission('部门数据修改','core:dept:update')] #[Permission('渠道数据修改','core:dept:update')]
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
@@ -104,23 +104,58 @@ class SystemDeptController extends BaseController
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */
#[Permission('部门数据删除','core:dept:destroy')] #[Permission('渠道数据删除','core:dept:destroy')]
public function destroy(Request $request) : Response public function destroy(Request $request) : Response
{ {
$ids = $request->post('ids', ''); $ids = $request->post('ids', '');
if (empty($ids)) { if (empty($ids)) {
return $this->fail('please select data to delete'); return $this->fail('please select data to delete');
} }
$deleteTables = $request->post('delete_tables', []);
if (!is_array($deleteTables)) {
$deleteTables = [];
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
if (!empty($deleteTables)) {
foreach ($idList as $deptId) {
$this->logic->destroyWithRelations((int) $deptId, $deleteTables);
}
return $this->success('delete success');
}
$result = $this->logic->destroy($ids); $result = $this->logic->destroy($ids);
if ($result) { if ($result) {
return $this->success('delete success'); return $this->success('delete success');
} else {
return $this->fail('delete failed');
} }
return $this->fail('delete failed');
} }
/** /**
* 可操作部门 * 删除渠道前关联数据预览
*/
#[Permission('渠道数据删除', 'core:dept:destroy')]
public function destroyPreview(Request $request): Response
{
$ids = $request->input('ids', '');
if ($ids === '' || $ids === null) {
return $this->fail('please select data');
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
$data = $this->logic->getDestroyPreview($idList);
return $this->success($data);
}
/**
* 为所有渠道补齐默认配置
*/
#[Permission('渠道数据修改', 'core:dept:update')]
public function syncChannelConfigs(Request $request): Response
{
$data = $this->logic->syncAllChannelConfigs();
return $this->success($data, 'sync success');
}
/**
* 可操作渠道
* @param Request $request * @param Request $request
* @return Response * @return Response
*/ */

View File

@@ -1,177 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\logic\system\SystemPostLogic;
use plugin\saiadmin\app\validate\system\SystemPostValidate;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 岗位信息控制器
*/
class SystemPostController extends BaseController
{
/**
* 构造
*/
public function __construct()
{
$this->logic = new SystemPostLogic();
$this->validate = new SystemPostValidate;
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('岗位数据列表', 'core:post:index')]
public function index(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据读取', 'core:post: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('not found');
}
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据添加', 'core:post:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
} else {
return $this->fail('add failed');
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据修改', 'core:post: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('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据删除', 'core:post:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
}
/**
* 导入数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导入', 'core:post:import')]
public function import(Request $request): Response
{
$file = current($request->file());
if (!$file || !$file->isValid()) {
return $this->fail('uploaded file not found');
}
$this->logic->import($file);
return $this->success('import success');
}
/**
* 导出数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导出', 'core:post:export')]
public function export(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
return $this->logic->export($where);
}
/**
* 下载导入模板
* @return Response
*/
public function downloadTemplate(): Response
{
$file_name = "template.xlsx";
return downloadFile($file_name);
}
/**
* 可操作岗位
* @param Request $request
* @return Response
*/
public function accessPost(Request $request): Response
{
$where = ['status' => 1];
$data = $this->logic->accessPost($where);
return $this->success($data);
}
}

View File

@@ -6,10 +6,8 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system; namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\app\model\system\SystemUserRole; use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController; use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\cache\UserInfoCache;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\app\validate\system\SystemRoleValidate; use plugin\saiadmin\app\validate\system\SystemRoleValidate;
use plugin\saiadmin\app\logic\system\SystemRoleLogic; use plugin\saiadmin\app\logic\system\SystemRoleLogic;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
@@ -17,13 +15,10 @@ use support\Request;
use support\Response; use support\Response;
/** /**
* 角色控制器 * 角色控制器(按渠道隔离)
*/ */
class SystemRoleController extends BaseController class SystemRoleController extends BaseController
{ {
/**
* 构造
*/
public function __construct() public function __construct()
{ {
$this->logic = new SystemRoleLogic(); $this->logic = new SystemRoleLogic();
@@ -31,11 +26,6 @@ class SystemRoleController extends BaseController
parent::__construct(); parent::__construct();
} }
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')] #[Permission('角色数据列表', 'core:role:index')]
public function index(Request $request): Response public function index(Request $request): Response
{ {
@@ -44,19 +34,14 @@ class SystemRoleController extends BaseController
['code', ''], ['code', ''],
['status', ''], ['status', ''],
]); ]);
$query = $this->logic->search($where); $requestDeptId = AdminScopeHelper::pickRequestDeptId(
$levelArr = array_column($this->adminInfo['roleList'], 'level'); $request->input('dept_id'),
$maxLevel = max($levelArr); $request->all()
$query->where('level', '<', $maxLevel); );
$data = $this->logic->getList($query); $data = $this->logic->indexList($where, $requestDeptId);
return $this->success($data); return $this->success($data);
} }
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据读取', 'core:role:read')] #[Permission('角色数据读取', 'core:role:read')]
public function read(Request $request): Response public function read(Request $request): Response
{ {
@@ -64,53 +49,49 @@ class SystemRoleController extends BaseController
$model = $this->logic->read($id); $model = $this->logic->read($id);
if ($model) { if ($model) {
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
$role = $this->logic->model->find($id);
if ($role) {
$this->logic->assertRoleWritable($role);
}
return $this->success($data); return $this->success($data);
} else { }
return $this->fail('not found'); return $this->fail('not found');
} }
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据添加', 'core:role:save')] #[Permission('角色数据添加', 'core:role:save')]
public function save(Request $request): Response public function save(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$data['dept_id'] = $this->logic->resolveRequestDeptId(
AdminScopeHelper::pickRequestDeptId($data['dept_id'] ?? null, $data)
);
$this->validate('save', $data); $this->validate('save', $data);
$result = $this->logic->add($data); $result = $this->logic->add($data);
if ($result) { if ($result) {
return $this->success('add success'); return $this->success('add success');
} else { }
return $this->fail('add failed'); return $this->fail('add failed');
} }
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据修改', 'core:role:update')] #[Permission('角色数据修改', 'core:role:update')]
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$role = $this->logic->model->find($data['id'] ?? 0);
if ($role) {
$this->logic->assertRoleWritable($role);
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
$data['dept_id'] = $role->dept_id;
}
}
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
if ($result) { if ($result) {
return $this->success('update success'); return $this->success('update success');
} else { }
return $this->fail('update failed'); return $this->fail('update failed');
} }
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据删除', 'core:role:destroy')] #[Permission('角色数据删除', 'core:role:destroy')]
public function destroy(Request $request): Response public function destroy(Request $request): Response
{ {
@@ -121,16 +102,10 @@ class SystemRoleController extends BaseController
$result = $this->logic->destroy($ids); $result = $this->logic->destroy($ids);
if ($result) { if ($result) {
return $this->success('delete success'); return $this->success('delete success');
} else { }
return $this->fail('delete failed'); return $this->fail('delete failed');
} }
}
/**
* 根据角色获取菜单
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')] #[Permission('角色数据列表', 'core:role:index')]
public function getMenuByRole(Request $request): Response public function getMenuByRole(Request $request): Response
{ {
@@ -139,11 +114,6 @@ class SystemRoleController extends BaseController
return $this->success($data); return $this->success($data);
} }
/**
* 菜单权限
* @param Request $request
* @return Response
*/
#[Permission('角色菜单权限', 'core:role:menu')] #[Permission('角色菜单权限', 'core:role:menu')]
public function menuPermission(Request $request): Response public function menuPermission(Request $request): Response
{ {
@@ -153,16 +123,14 @@ class SystemRoleController extends BaseController
return $this->success('operation success'); return $this->success('operation success');
} }
/**
* 可操作角色
* @param Request $request
* @return Response
*/
public function accessRole(Request $request): Response public function accessRole(Request $request): Response
{ {
$where = ['status' => 1]; $where = ['status' => 1];
$data = $this->logic->accessRole($where); $requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$data = $this->logic->accessRole($where, $requestDeptId);
return $this->success($data); return $this->success($data);
} }
} }

View File

@@ -182,7 +182,6 @@ class SystemUserController extends BaseController
{ {
$data = $request->post(); $data = $request->post();
unset($data['deptList']); unset($data['deptList']);
unset($data['postList']);
unset($data['roleList']); unset($data['roleList']);
$result = $this->logic->updateInfo($this->adminId, $data); $result = $this->logic->updateInfo($this->adminId, $data);
if ($result) { if ($result) {

View File

@@ -2,129 +2,123 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ] // | saiadmin [ saiadmin快速开发框架 ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system; namespace plugin\saiadmin\app\logic\system;
use app\dice\service\DiceChannelConfigService;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemDept; use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\utils\Helper;
use plugin\saiadmin\utils\Arr;
/** /**
* 部门逻辑层 * 渠道逻辑层(表 sa_system_dept
*/ */
class SystemDeptLogic extends BaseLogic class SystemDeptLogic extends BaseLogic
{ {
/**
* 构造函数
*/
public function __construct() public function __construct()
{ {
$this->model = new SystemDept(); $this->model = new SystemDept();
} }
/**
* 添加数据
*/
public function add($data): mixed public function add($data): mixed
{ {
$data = $this->handleData($data); $data = $this->handleData($data);
$this->model->save($data); $this->model->save($data);
return $this->model->getKey(); $deptId = (int) $this->model->getKey();
if ($deptId > 0) {
(new DiceChannelConfigService())->copyDefaultConfigToDept($deptId);
(new SystemRoleChannelService())->copyDefaultRolesToDept($deptId, false);
}
return $deptId;
} }
/**
* 修改数据
*/
public function edit($id, $data): mixed public function edit($id, $data): mixed
{ {
$oldLevel = $data['level'] . $id . ',';
$data = $this->handleData($data); $data = $this->handleData($data);
if ($data['parent_id'] == $id) {
throw new ApiException('Parent department cannot be the same as current department');
}
if (in_array($id, explode(',', $data['level']))) {
throw new ApiException('Cannot set parent department to a child of current department');
}
$newLevel = $data['level'] . $id . ',';
$deptIds = $this->model->where('level', 'like', $oldLevel . '%')->column('id');
return $this->transaction(function () use ($deptIds, $oldLevel, $newLevel, $data, $id) {
$this->model->whereIn('id', $deptIds)->exp('level', "REPLACE(level, '$oldLevel', '$newLevel')")->update([]);
return $this->model->update($data, ['id' => $id]); return $this->model->update($data, ['id' => $id]);
});
} }
/**
* 数据删除
*/
public function destroy($ids): bool public function destroy($ids): bool
{ {
$num = $this->model->where('parent_id', 'in', $ids)->count();
if ($num > 0) {
throw new ApiException('This department has sub-departments, please delete them first');
} else {
$count = SystemUser::where('dept_id', 'in', $ids)->count(); $count = SystemUser::where('dept_id', 'in', $ids)->count();
if ($count > 0) { if ($count > 0) {
throw new ApiException('This department has users, please delete or transfer them first'); throw new ApiException('This channel has users, please delete or transfer them first');
} }
return $this->model->destroy($ids); return $this->model->destroy($ids);
} }
}
/** /**
* 数据处理 * 带关联选项删除渠道
*/ */
public function destroyWithRelations(int $deptId, array $deleteTables): bool
{
(new SystemRoleChannelService())->deleteRolesByDept($deptId);
(new DiceChannelConfigService())->destroyDeptWithRelations($deptId, $deleteTables);
return true;
}
public function getDestroyPreview(array $deptIds): array
{
return (new DiceChannelConfigService())->getDestroyPreview($deptIds);
}
public function syncAllChannelConfigs(): array
{
$config = (new DiceChannelConfigService())->syncAllChannelsFromDefault();
$roles = (new SystemRoleChannelService())->syncAllChannelsFromDefault();
return ['config' => $config, 'roles' => $roles];
}
protected function handleData($data) protected function handleData($data)
{ {
// 处理上级部门
if (empty($data['parent_id']) || $data['parent_id'] == 0) {
$data['level'] = '0'; $data['level'] = '0';
$data['parent_id'] = 0; $data['parent_id'] = 0;
} else {
$parentMenu = SystemDept::findOrEmpty($data['parent_id']);
$data['level'] = $parentMenu['level'] . $parentMenu['id'] . ',';
}
return $data; return $data;
} }
/**
* 数据树形化
* @param array $where
* @return array
*/
public function tree(array $where = []): array public function tree(array $where = []): array
{ {
$query = $this->search($where); $query = $this->search($where);
$request = request();
if ($request && $request->input('tree', 'false') === 'true') {
$query->field('id, id as value, name as label, parent_id');
}
$query->order('sort', 'desc'); $query->order('sort', 'desc');
$query->with(['leader']); $query->with(['leader']);
$data = $this->getAll($query); return $this->getAll($query);
return Helper::makeTree($data);
} }
/**
* 可操作部门
* @param array $where
* @return array
*/
public function accessDept(array $where = []): array public function accessDept(array $where = []): array
{ {
$query = $this->search($where); $query = $this->search($where);
// 超级管理员(id=1)可查看全部部门,普通管理员按部门权限过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) { if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$query->auth($this->adminInfo['deptList'] ?? []); $deptId = $this->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('id', $deptId);
} else {
return [];
} }
$query->field('id, id as value, name as label, parent_id'); }
$query->field('id, id as value, name as label');
$query->order('sort', 'desc'); $query->order('sort', 'desc');
$data = $this->getAll($query); return $this->getAll($query);
return Helper::makeTree($data);
} }
/**
* 当前管理员可操作的渠道 IDdeptList 缺失时回退 dept_id
*/
public function resolveAccessibleDeptId(?array $adminInfo = null): int
{
$adminInfo = $adminInfo ?? $this->adminInfo ?? [];
if (empty($adminInfo['id']) || (int) $adminInfo['id'] <= 1) {
return 0;
}
$deptList = $adminInfo['deptList'] ?? [];
if (is_array($deptList) && isset($deptList['id']) && (int) $deptList['id'] > 0) {
return (int) $deptList['id'];
}
$deptId = $adminInfo['dept_id'] ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return 0;
}
} }

View File

@@ -1,95 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use plugin\saiadmin\app\model\system\SystemPost;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\service\OpenSpoutWriter;
use OpenSpout\Reader\XLSX\Reader;
/**
* 岗位管理逻辑层
*/
class SystemPostLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemPost();
}
/**
* 可操作岗位
* @param array $where
* @return array
*/
public function accessPost(array $where = []): array
{
$query = $this->search($where);
$query->field('id, id as value, name as label, name, code');
return $this->getAll($query);
}
/**
* 导入数据
*/
public function import($file)
{
$path = $this->getImport($file);
$reader = new Reader();
try {
$reader->open($path);
$data = [];
foreach ($reader->getSheetIterator() as $sheet) {
$isHeader = true;
foreach ($sheet->getRowIterator() as $row) {
if ($isHeader) {
$isHeader = false;
continue;
}
$cells = $row->getCells();
$data[] = [
'name' => $cells[0]->getValue(),
'code' => $cells[1]->getValue(),
'sort' => $cells[2]->getValue(),
'status' => $cells[3]->getValue(),
];
}
}
$this->saveAll($data);
} catch (\Exception $e) {
throw new ApiException('Import file error, please upload correct xlsx file');
}
}
/**
* 导出数据
*/
public function export($where = [])
{
$query = $this->search($where)->field('id,name,code,sort,status,create_time');
$data = $this->getAll($query);
$file_name = '岗位数据.xlsx';
$header = ['编号', '岗位名称', '岗位标识', '排序', '状态', '创建时间'];
$filter = [
'status' => [
['value' => 1, 'label' => '正常'],
['value' => 2, 'label' => '禁用']
]
];
$writer = new OpenSpoutWriter($file_name);
$writer->setWidth([15, 15, 20, 15, 15, 25]);
$writer->setHeader($header);
$writer->setData($data, null, $filter);
$file_path = $writer->returnFile();
return response()->download($file_path, urlencode($file_name));
}
}

View File

@@ -6,121 +6,133 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system; namespace plugin\saiadmin\app\logic\system;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\app\cache\UserMenuCache; use plugin\saiadmin\app\cache\UserMenuCache;
use plugin\saiadmin\app\model\system\SystemRole; use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\think\Cache; use support\think\Cache;
use support\think\Db; use support\think\Db;
/** /**
* 角色逻辑层 * 角色逻辑层(按渠道 dept_id 隔离)
*/ */
class SystemRoleLogic extends BaseLogic class SystemRoleLogic extends BaseLogic
{ {
/**
* 构造函数
*/
public function __construct() public function __construct()
{ {
$this->model = new SystemRole(); $this->model = new SystemRole();
} }
/** /**
* 添加数据 * 分页列表(按渠道过滤)
*/ */
public function indexList(array $where, $requestDeptId = null): array
{
$query = $this->search($where);
$this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
return $this->getList($query);
}
public function add($data): bool public function add($data): bool
{ {
$data = $this->handleData($data); $data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, null);
return $this->model->save($data); return $this->model->save($data);
} }
/**
* 修改数据
*/
public function edit($id, $data): bool public function edit($id, $data): bool
{ {
$model = $this->model->findOrEmpty($id); $model = $this->model->findOrEmpty($id);
if ($model->isEmpty()) { if ($model->isEmpty()) {
throw new ApiException('Data not found'); throw new ApiException('Data not found');
} }
$this->assertRoleWritable($model);
$data = $this->handleData($data); $data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($model->dept_id ?? $data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, (int) $id);
return $model->save($data); return $model->save($data);
} }
/**
* 删除数据
*/
public function destroy($ids): bool public function destroy($ids): bool
{ {
// 越权保护 $levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
$levelArr = array_column($this->adminInfo['roleList'], 'level'); $maxLevel = !empty($levelArr) ? max($levelArr) : 100;
$maxLevel = max($levelArr);
$num = SystemRole::where('level', '>=', $maxLevel)->whereIn('id', $ids)->count(); $idList = is_array($ids) ? $ids : explode(',', (string) $ids);
if ($num > 0) { foreach ($idList as $roleId) {
$roleId = (int) $roleId;
if ($roleId === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot delete super admin role');
}
$role = $this->model->find($roleId);
if (!$role) {
continue;
}
$this->assertRoleWritable($role);
if ((int) ($role->level ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account'); throw new ApiException('Cannot operate roles with higher level than current account');
} else { }
}
return $this->model->destroy($ids); return $this->model->destroy($ids);
} }
}
/**
* 数据处理
*/
protected function handleData($data) protected function handleData($data)
{ {
// 越权保护 $levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
$levelArr = array_column($this->adminInfo['roleList'], 'level'); if (!empty($levelArr)) {
$maxLevel = max($levelArr); $maxLevel = max($levelArr);
if ($data['level'] >= $maxLevel) { if (($data['level'] ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account'); throw new ApiException('Cannot operate roles with higher level than current account');
} }
}
return $data; return $data;
} }
/** public function accessRole(array $where = [], $requestDeptId = null): array
* 可操作角色
* @param array $where
* @return array
*/
public function accessRole(array $where = []): array
{ {
$query = $this->search($where); $query = $this->search($where);
// 越权保护 $this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'], 'level'); $levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr); $maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel); $query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
$query->order('sort', 'desc'); $query->order('sort', 'desc');
return $this->getAll($query); return $this->getAll($query);
} }
/**
* 根据角色数组获取菜单
* @param $ids
* @return array
*/
public function getMenuIdsByRoleIds($ids): array public function getMenuIdsByRoleIds($ids): array
{ {
if (empty($ids)) if (empty($ids)) {
return []; return [];
}
return $this->model->where('id', 'in', $ids)->with([ return $this->model->where('id', 'in', $ids)->with([
'menus' => function ($query) { 'menus' => function ($query) {
$query->where('status', 1)->order('sort', 'desc'); $query->where('status', 1)->order('sort', 'desc');
} }
])->select()->toArray(); ])->select()->toArray();
} }
/**
* 根据角色获取菜单
* @param $id
* @return array
*/
public function getMenuByRole($id): array public function getMenuByRole($id): array
{ {
$role = $this->model->findOrEmpty($id); $role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
$menus = $role->menus ?: []; $menus = $role->menus ?: [];
return [ return [
'id' => $id, 'id' => $id,
@@ -128,14 +140,14 @@ class SystemRoleLogic extends BaseLogic
]; ];
} }
/**
* 保存菜单权限
* @param $id
* @param $menu_ids
* @return mixed
*/
public function saveMenuPermission($id, $menu_ids): mixed public function saveMenuPermission($id, $menu_ids): mixed
{ {
$role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
return $this->transaction(function () use ($id, $menu_ids) { return $this->transaction(function () use ($id, $menu_ids) {
$role = $this->model->findOrEmpty($id); $role = $this->model->findOrEmpty($id);
if ($role) { if ($role) {
@@ -147,10 +159,90 @@ class SystemRoleLogic extends BaseLogic
} }
$cache = config('plugin.saiadmin.saithink.button_cache'); $cache = config('plugin.saiadmin.saithink.button_cache');
$tag = $cache['role'] . $id; $tag = $cache['role'] . $id;
Cache::tag($tag)->clear(); // 清理权限缓存-角色TAG Cache::tag($tag)->clear();
UserMenuCache::clearMenuCache(); // 清理菜单缓存 UserMenuCache::clearMenuCache();
return true; return true;
}); });
} }
/**
* 解析并校验当前请求应操作的渠道 ID
*/
public function resolveRequestDeptId($requestDeptId): int
{
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
return $deptLogic->resolveAccessibleDeptId();
}
/**
* 列表/下拉按渠道过滤
*/
protected function applyDeptScope($query, $requestDeptId = null): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
$query->where('dept_id', $deptId);
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
}
}
/**
* 校验角色属于当前可操作渠道
*/
public function assertRoleWritable($role): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
$roleDeptId = AdminScopeHelper::normalizeRecordDeptId($role->dept_id ?? null);
if ((int) ($role->id ?? 0) === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot operate super admin role');
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$scopeDeptId = $deptLogic->resolveAccessibleDeptId();
if ($scopeDeptId > 0 && $roleDeptId !== $scopeDeptId) {
throw new ApiException('No permission to operate this channel role');
}
}
protected function assertCodeUniqueInDept(string $code, int $deptId, ?int $excludeId): void
{
if ($code === '') {
return;
}
$query = SystemRole::where('code', $code)->where('dept_id', $deptId);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
if ($query->count() > 0) {
throw new ApiException('Role code already exists in this channel');
}
}
protected function tableHasDeptIdColumn(): bool
{
try {
$fields = Db::getFields((new SystemRole())->getTable());
return isset($fields['dept_id']);
} catch (\Throwable $e) {
return false;
}
}
} }

View File

@@ -40,10 +40,17 @@ class SystemUserLogic extends BaseLogic
{ {
$query = $this->search($where); $query = $this->search($where);
$query->with(['depts']); $query->with(['depts']);
// 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤 // 超级管理员(id=1)可查看全部用户,渠道管理员按本渠道过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) { if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
} else {
$query->auth($this->adminInfo['deptList'] ?? []); $query->auth($this->adminInfo['deptList'] ?? []);
} }
}
return $this->getList($query); return $this->getList($query);
} }
@@ -69,8 +76,13 @@ class SystemUserLogic extends BaseLogic
$admin = $this->model->findOrEmpty($id); $admin = $this->model->findOrEmpty($id);
$data = $admin->hidden(['password'])->toArray(); $data = $admin->hidden(['password'])->toArray();
$data['roleList'] = $admin->roles->toArray() ?: []; $data['roleList'] = $admin->roles->toArray() ?: [];
$data['postList'] = $admin->posts->toArray() ?: [];
$data['deptList'] = $admin->depts ? $admin->depts->toArray() : []; $data['deptList'] = $admin->depts ? $admin->depts->toArray() : [];
if (empty($data['deptList']) && ! empty($admin->dept_id)) {
$dept = SystemDept::find($admin->dept_id);
if ($dept && ! $dept->isEmpty()) {
$data['deptList'] = $dept->toArray();
}
}
return $data; return $data;
} }
@@ -101,7 +113,6 @@ class SystemUserLogic extends BaseLogic
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT); $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
return $this->transaction(function () use ($data) { return $this->transaction(function () use ($data) {
$role_ids = $data['role_ids'] ?? []; $role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
if ($this->adminInfo['id'] > 1) { if ($this->adminInfo['id'] > 1) {
// 部门保护 // 部门保护
if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) { if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) {
@@ -114,11 +125,7 @@ class SystemUserLogic extends BaseLogic
} }
$user = SystemUser::create($data); $user = SystemUser::create($data);
$user->roles()->detach(); $user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids); $user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
return $user; return $user;
}); });
} }
@@ -134,7 +141,6 @@ class SystemUserLogic extends BaseLogic
unset($data['password']); unset($data['password']);
return $this->transaction(function () use ($data, $id) { return $this->transaction(function () use ($data, $id) {
$role_ids = $data['role_ids'] ?? []; $role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
// 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户 // 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户
$query = $this->model->where('id', $id); $query = $this->model->where('id', $id);
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) { if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
@@ -157,11 +163,7 @@ class SystemUserLogic extends BaseLogic
$result = parent::edit($id, $data); $result = parent::edit($id, $data);
if ($result) { if ($result) {
$user->roles()->detach(); $user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids); $user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
UserInfoCache::clearUserInfo($id); UserInfoCache::clearUserInfo($id);
UserAuthCache::clearUserAuth($id); UserAuthCache::clearUserAuth($id);
UserMenuCache::clearUserMenu($id); UserMenuCache::clearUserMenu($id);

View File

@@ -9,15 +9,15 @@ namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel; use plugin\saiadmin\basic\think\BaseModel;
/** /**
* 部门模型 * 渠道模型
* *
* sa_system_dept 部门 * sa_system_dept 渠道
* *
* @property $id 编号 * @property $id 编号
* @property $parent_id 父级ID0为根节点 * @property $parent_id 父级ID扁平渠道固定为0
* @property $name 部门名称 * @property $name 渠道名称
* @property $code 部门编码 * @property $code 渠道编码
* @property $leader_id 部门负责人ID * @property $leader_id 渠道负责人ID
* @property $level 祖级列表,格式: 0,1,5, * @property $level 祖级列表,格式: 0,1,5,
* @property $sort 排序,数字越小越靠前 * @property $sort 排序,数字越小越靠前
* @property $status 状态: 1启用, 0禁用 * @property $status 状态: 1启用, 0禁用
@@ -38,24 +38,21 @@ class SystemDept extends BaseModel
protected $table = 'sa_system_dept'; protected $table = 'sa_system_dept';
/** /**
* 权限范围 * 权限范围(扁平渠道,仅本渠道)
*/ */
public function scopeAuth($query, $value) public function scopeAuth($query, $value)
{ {
if (!empty($value) && isset($value['id'])) { if (is_array($value) && isset($value['id']) && (int) $value['id'] > 0) {
$deptIds = [$value['id']]; $query->where('id', $value['id']);
$level = $value['level'] ?? ''; return;
if ($level !== '' && $level !== null) {
$deptLevel = $level . $value['id'] . ',';
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $ids);
} }
$query->whereIn('id', $deptIds); if (is_numeric($value) && (int) $value > 0) {
$query->where('id', (int) $value);
} }
} }
/** /**
* 部门领导 * 渠道负责人
*/ */
public function leader() public function leader()
{ {

View File

@@ -1,37 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 岗位模型
*
* sa_system_post 岗位信息表
*
* @property $id 主键
* @property $name 岗位名称
* @property $code 岗位代码
* @property $sort 排序
* @property $status 状态
* @property $remark 备注
* @property $created_by 创建者
* @property $updated_by 更新者
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class SystemPost extends BaseModel
{
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
protected $table = 'sa_system_post';
}

View File

@@ -14,6 +14,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* sa_system_role 角色表 * sa_system_role 角色表
* *
* @property $id * @property $id
* @property int $dept_id 所属渠道ID0=默认模板
* @property $name 角色名称 * @property $name 角色名称
* @property $code 角色标识,如: hr_manager * @property $code 角色标识,如: hr_manager
* @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色 * @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色
@@ -41,6 +42,14 @@ class SystemRole extends BaseModel
*/ */
protected $table = 'sa_system_role'; protected $table = 'sa_system_role';
/** 按渠道筛选 */
public function searchDeptIdAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('dept_id', '=', $value);
}
}
/** /**
* 权限范围 * 权限范围
*/ */

View File

@@ -24,7 +24,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $phone 手机号 * @property $phone 手机号
* @property $signed 个性签名 * @property $signed 个性签名
* @property $dashboard 工作台 * @property $dashboard 工作台
* @property $dept_id 主归属部门 * @property $dept_id 主归属渠道
* @property $is_super 是否超级管理员: 1是 * @property $is_super 是否超级管理员: 1是
* @property $status 状态: 1启用, 2禁用 * @property $status 状态: 1启用, 2禁用
* @property $remark 备注 * @property $remark 备注
@@ -82,16 +82,12 @@ class SystemUser extends BaseModel
} }
/** /**
* 权限范围 - 过滤部门用户 * 权限范围 - 过滤同渠道用户
*/ */
public function scopeAuth($query, $value) public function scopeAuth($query, $value)
{ {
if (!empty($value)) { if (!empty($value) && isset($value['id'])) {
$deptIds = [$value['id']]; $query->where('dept_id', $value['id']);
$deptLevel = $value['level'] . $value['id'] . ',';
$dept_ids = SystemDept::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $dept_ids);
$query->whereIn('dept_id', $deptIds);
} }
} }
@@ -104,15 +100,7 @@ class SystemUser extends BaseModel
} }
/** /**
* 通过中间表关联岗位 * 关联渠道
*/
public function posts()
{
return $this->belongsToMany(SystemPost::class, SystemUserPost::class, 'post_id', 'user_id');
}
/**
* 通过中间表关联部门
*/ */
public function depts() public function depts()
{ {

View File

@@ -1,25 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use think\model\Pivot;
/**
* 用户岗位关联模型
*
* sa_system_user_post 用户与岗位关联表
*
* @property $id 主键
* @property $user_id 用户主键
* @property $post_id 岗位主键
*/
class SystemUserPost extends Pivot
{
protected $pk = 'id';
protected $table = 'sa_system_user_post';
}

View File

@@ -0,0 +1,257 @@
<?php
declare(strict_types=1);
namespace plugin\saiadmin\app\service;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道角色:从默认模板复制指定角色、同步与删除
*/
class SystemRoleChannelService
{
/** 全局超级管理员角色,不参与渠道复制 */
public const SUPER_ADMIN_ROLE_ID = 1;
/**
* 为渠道从默认模板复制三个代理角色(缺失则补齐,不整包跳过)
*/
public function copyDefaultRolesToDept(int $deptId, bool $pruneExtra = false): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'dept_id column missing'];
}
$templates = $this->defaultTemplateRoles();
if (empty($templates)) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'no template roles'];
}
$copied = 0;
$skipped = 0;
foreach ($templates as $template) {
$template = (array) $template;
$templateId = (int) ($template['id'] ?? 0);
$code = (string) ($template['code'] ?? '');
if ($templateId <= 0 || $code === '') {
continue;
}
if ($this->roleExists($deptId, $code)) {
$skipped++;
continue;
}
$newId = $this->insertRoleFromTemplate($template, $deptId);
if ($newId > 0) {
$this->copyRoleMenus($templateId, $newId);
$copied++;
}
}
$pruned = 0;
if ($pruneExtra) {
$pruned = $this->pruneExtraChannelRoles($deptId);
}
return ['dept_id' => $deptId, 'copied' => $copied, 'skipped' => $skipped, 'pruned' => $pruned];
}
/**
* 为所有已启用渠道补齐三个默认角色,并移除多余历史角色
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::where('status', 1)->where('id', '>', 0)->column('id');
$result = [];
foreach ($deptIds as $deptId) {
$result[(int) $deptId] = $this->copyDefaultRolesToDept((int) $deptId, true);
}
return $result;
}
/**
* 删除渠道下全部角色及菜单关联
*/
public function deleteRolesByDept(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$roleIds = SystemRole::where('dept_id', $deptId)->column('id');
if (empty($roleIds)) {
return 0;
}
Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_menu')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_dept')->whereIn('role_id', $roleIds)->delete();
return SystemRole::destroy($roleIds);
}
/**
* 将用户已绑定的模板角色映射到其渠道对应角色(仅三个默认 code
*/
public function remapUserRolesToChannelRoles(): int
{
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return 0;
}
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return 0;
}
$codeList = "'" . implode("','", array_map('addslashes', $codes)) . "'";
return Db::execute(
'UPDATE `sa_system_user_role` ur
INNER JOIN `sa_system_user` u ON ur.user_id = u.id
INNER JOIN `sa_system_role` r_old ON ur.role_id = r_old.id
INNER JOIN `sa_system_role` r_new ON r_new.dept_id = u.dept_id AND r_new.code = r_old.code
SET ur.role_id = r_new.id
WHERE u.dept_id > 0
AND r_old.dept_id = 0
AND r_old.code IN (' . $codeList . ')
AND r_old.id <> ' . self::SUPER_ADMIN_ROLE_ID
);
}
/**
* @return string[]
*/
public function getDefaultChannelRoleCodes(): array
{
$codes = config('plugin.saiadmin.saithink.channel_default_role_codes', []);
if (!is_array($codes) || $codes === []) {
return ['yijidaili', 'erjidaili', 'sanjidaili'];
}
$out = [];
foreach ($codes as $code) {
$code = trim((string) $code);
if ($code !== '') {
$out[] = $code;
}
}
return $out;
}
/**
* 删除渠道下不在默认三个 code 内、且未被用户绑定的角色
*/
public function pruneExtraChannelRoles(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$allowed = $this->getDefaultChannelRoleCodes();
if (empty($allowed)) {
return 0;
}
$query = SystemRole::where('dept_id', $deptId)->whereNotIn('code', $allowed);
$roleIds = $query->column('id');
if (empty($roleIds)) {
return 0;
}
$usedIds = Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->column('role_id');
$usedMap = array_flip($usedIds ?: []);
$pruned = 0;
foreach ($roleIds as $roleId) {
if (isset($usedMap[$roleId])) {
continue;
}
Db::name('sa_system_role_menu')->where('role_id', $roleId)->delete();
Db::name('sa_system_role_dept')->where('role_id', $roleId)->delete();
SystemRole::destroy($roleId);
$pruned++;
}
return $pruned;
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRoles(): array
{
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return [];
}
$query = Db::table('sa_system_role')
->where('id', '<>', self::SUPER_ADMIN_ROLE_ID)
->whereIn('code', $codes);
if ($this->tableHasColumn('sa_system_role', 'dept_id')) {
$query->where('dept_id', 0);
}
$rows = $query->order('sort', 'desc')->select()->toArray();
if (count($rows) === count($codes)) {
return $rows;
}
// 按配置顺序返回,缺失的 code 跳过
$byCode = [];
foreach ($rows as $row) {
$byCode[(string) ($row['code'] ?? '')] = $row;
}
$ordered = [];
foreach ($codes as $code) {
if (isset($byCode[$code])) {
$ordered[] = $byCode[$code];
}
}
return $ordered;
}
private function insertRoleFromTemplate(array $template, int $deptId): int
{
unset(
$template['id'],
$template['create_time'],
$template['update_time'],
$template['delete_time']
);
$template['dept_id'] = $deptId;
$now = date('Y-m-d H:i:s');
if (!isset($template['create_time'])) {
$template['create_time'] = $now;
}
if (!isset($template['update_time'])) {
$template['update_time'] = $now;
}
return (int) Db::table('sa_system_role')->insertGetId($template);
}
private function copyRoleMenus(int $fromRoleId, int $toRoleId): void
{
$menuIds = Db::name('sa_system_role_menu')->where('role_id', $fromRoleId)->column('menu_id');
if (empty($menuIds)) {
return;
}
$rows = [];
foreach ($menuIds as $menuId) {
$rows[] = ['role_id' => $toRoleId, 'menu_id' => $menuId];
}
Db::name('sa_system_role_menu')->limit(100)->insertAll($rows);
}
private function roleExists(int $deptId, string $code): bool
{
return SystemRole::where('dept_id', $deptId)->where('code', $code)->count() > 0;
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -9,7 +9,7 @@ namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate; use plugin\saiadmin\basic\BaseValidate;
/** /**
* 部门验证器 * 渠道验证器
*/ */
class SystemDeptValidate extends BaseValidate class SystemDeptValidate extends BaseValidate
{ {
@@ -25,7 +25,7 @@ class SystemDeptValidate extends BaseValidate
* 定义错误信息 * 定义错误信息
*/ */
protected $message = [ protected $message = [
'name' => '部门名称必须填写', 'name' => '渠道名称必须填写',
'status' => '状态必须填写', 'status' => '状态必须填写',
]; ];

View File

@@ -1,50 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate;
/**
* 用户角色验证器
*/
class SystemPostValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected $rule = [
'name' => 'require',
'code' => 'require',
'status' => 'require',
];
/**
* 定义错误信息
*/
protected $message = [
'name' => '岗位名称必须填写',
'code' => '岗位标识必须填写',
'status' => '状态必须填写',
];
/**
* 定义场景
*/
protected $scene = [
'save' => [
'name',
'code',
'status',
],
'update' => [
'name',
'code',
'status',
],
];
}

View File

@@ -19,7 +19,7 @@ class SystemRoleValidate extends BaseValidate
*/ */
protected $rule = [ protected $rule = [
'name' => 'require|max:16', 'name' => 'require|max:16',
'code' => 'require|alphaDash|unique:' . SystemRole::class, 'code' => 'require|alphaDash|unique:' . SystemRole::class . ',code^dept_id',
'status' => 'require', 'status' => 'require',
]; ];

View File

@@ -6,6 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace plugin\saiadmin\basic; namespace plugin\saiadmin\basic;
use app\api\util\ApiLang;
use support\Request; use support\Request;
use support\Response; use support\Response;
@@ -36,6 +37,7 @@ class OpenController
if (is_string($data)) { if (is_string($data)) {
$msg = $data; $msg = $data;
} }
$msg = ApiLang::translate($msg, request());
return json(['code' => 200, 'message' => $msg, 'data' => $data], $option); return json(['code' => 200, 'message' => $msg, 'data' => $data], $option);
} }
@@ -47,6 +49,7 @@ class OpenController
*/ */
public function fail(string $msg = 'fail', int $code = 400): Response public function fail(string $msg = 'fail', int $code = 400): Response
{ {
$msg = ApiLang::translate($msg, request());
return json(['code' => $code, 'message' => $msg]); return json(['code' => $code, 'message' => $msg]);
} }

View File

@@ -23,6 +23,7 @@ Route::group('/core', function () {
Route::get('/dice/dashboard/rechargeBarChart', [\app\dice\controller\DiceDashboardController::class, 'rechargeBarChart']); 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/walletRecordList', [\app\dice\controller\DiceDashboardController::class, 'walletRecordList']);
Route::get('/dice/dashboard/newPlayerList', [\app\dice\controller\DiceDashboardController::class, 'newPlayerList']); Route::get('/dice/dashboard/newPlayerList', [\app\dice\controller\DiceDashboardController::class, 'newPlayerList']);
Route::get('/dice/dashboard/playRecordList', [\app\dice\controller\DiceDashboardController::class, 'playRecordList']);
Route::get('/system/clearAllCache', [plugin\saiadmin\app\controller\SystemController::class, 'clearAllCache']); Route::get('/system/clearAllCache', [plugin\saiadmin\app\controller\SystemController::class, 'clearAllCache']);
Route::get("/system/getResourceCategory", [plugin\saiadmin\app\controller\SystemController::class, 'getResourceCategory']); Route::get("/system/getResourceCategory", [plugin\saiadmin\app\controller\SystemController::class, 'getResourceCategory']);
@@ -49,14 +50,11 @@ Route::group('/core', function () {
Route::get("/role/getMenuByRole", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'getMenuByRole']); Route::get("/role/getMenuByRole", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'getMenuByRole']);
Route::post("/role/menuPermission", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'menuPermission']); Route::post("/role/menuPermission", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'menuPermission']);
// 部门管理 // 渠道管理
fastRoute("dept", \plugin\saiadmin\app\controller\system\SystemDeptController::class); fastRoute("dept", \plugin\saiadmin\app\controller\system\SystemDeptController::class);
Route::get("/dept/accessDept", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'accessDept']); Route::get("/dept/accessDept", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'accessDept']);
Route::get("/dept/destroyPreview", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'destroyPreview']);
// 岗位管理 Route::post("/dept/syncChannelConfigs", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'syncChannelConfigs']);
fastRoute('post', \plugin\saiadmin\app\controller\system\SystemPostController::class);
Route::get("/post/accessPost", [\plugin\saiadmin\app\controller\system\SystemPostController::class, 'accessPost']);
Route::post("/post/downloadTemplate", [plugin\saiadmin\app\controller\system\SystemPostController::class, 'downloadTemplate']);
// 菜单管理 // 菜单管理
fastRoute('menu', \plugin\saiadmin\app\controller\system\SystemMenuController::class); fastRoute('menu', \plugin\saiadmin\app\controller\system\SystemMenuController::class);
@@ -94,6 +92,7 @@ Route::group('/core', function () {
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']); 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/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']); Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserTreeOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserTreeOptions']);
Route::get('/dice/player/DicePlayer/getGameUrl', [\app\dice\controller\player\DicePlayerController::class, 'getGameUrl']); Route::get('/dice/player/DicePlayer/getGameUrl', [\app\dice\controller\player\DicePlayerController::class, 'getGameUrl']);
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class); 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/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
@@ -120,6 +119,7 @@ Route::group('/core', function () {
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']); Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
fastRoute('dice/game/DiceGame', \app\dice\controller\game\DiceGameController::class); fastRoute('dice/game/DiceGame', \app\dice\controller\game\DiceGameController::class);
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class); fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
Route::get('/dice/ante_config/DiceAnteConfig/getOptions', [\app\dice\controller\ante_config\DiceAnteConfigController::class, 'getOptions']);
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class); 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/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::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getCurrentPool']);

View File

@@ -33,7 +33,6 @@ return [
'expire' => 60 * 60 * 4, 'expire' => 60 * 60 * 4,
'dept' => 'saiadmin:user_cache:dept_', 'dept' => 'saiadmin:user_cache:dept_',
'role' => 'saiadmin:user_cache:role_', 'role' => 'saiadmin:user_cache:role_',
'post' => 'saiadmin:user_cache:post_',
], ],
// 用户权限缓存 // 用户权限缓存
@@ -73,4 +72,13 @@ return [
'attr' => 'saiadmin:reflection_cache:attr_', 'attr' => 'saiadmin:reflection_cache:attr_',
], ],
/**
* 新建渠道时从默认模板复制的角色 code须存在于 dept_id=0 的模板角色)
*/
'channel_default_role_codes' => [
'yijidaili',
'erjidaili',
'sanjidaili',
],
]; ];

View File

@@ -391,7 +391,6 @@ INSERT INTO `sa_system_menu` VALUES (3, 0, '系统管理', 'System', NULL, 1, '/
INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (7, 3, '岗位管理', 'Post', '', 2, 'post', '/system/post', NULL, 'ri:signpost-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -423,13 +422,6 @@ INSERT INTO `sa_system_menu` VALUES (36, 6, '修改', '', 'core:role:update', 3,
INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (41, 7, '数据列表', '', 'core:post:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (42, 7, '添加', '', 'core:post:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (43, 7, '修改', '', 'core:post:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (44, 7, '读取', '', 'core:post:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (45, 7, '删除', '', 'core:post:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (46, 7, '导入', '', 'core:post:import', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (47, 7, '导出', '', 'core:post:export', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -501,31 +493,6 @@ CREATE TABLE `sa_system_oper_log` (
-- Records of sa_system_oper_log -- Records of sa_system_oper_log
-- ---------------------------- -- ----------------------------
-- ----------------------------
-- Table structure for sa_system_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_post`;
CREATE TABLE `sa_system_post` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(50) NULL DEFAULT NULL COMMENT '岗位名称',
`code` varchar(100) NULL DEFAULT NULL COMMENT '岗位代码',
`sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序',
`status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)',
`remark` varchar(255) NULL DEFAULT NULL COMMENT '备注',
`created_by` int(11) NULL DEFAULT NULL COMMENT '创建者',
`updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
`delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 87 COMMENT = '岗位信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_post
-- ----------------------------
INSERT INTO `sa_system_post` VALUES (1, '司机岗', 'driver', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_post` VALUES (2, '保安岗', 'security', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ---------------------------- -- ----------------------------
-- Table structure for sa_system_role -- Table structure for sa_system_role
-- ---------------------------- -- ----------------------------
@@ -635,23 +602,6 @@ INSERT INTO `sa_system_user` VALUES (10, 'timi_boss', '$2y$10$sY/4StKVV.N/8Ock8J
INSERT INTO `sa_system_user` VALUES (100, 'dev_wang', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '王程序员', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_user` VALUES (100, 'dev_wang', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '王程序员', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_user` VALUES (101, 'dev_li', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '李策划', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_user` VALUES (101, 'dev_li', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '李策划', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ----------------------------
-- Table structure for sa_system_user_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_user_post`;
CREATE TABLE `sa_system_user_post` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户主键',
`post_id` bigint(20) UNSIGNED NOT NULL COMMENT '岗位主键',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_user_id`(`user_id`) USING BTREE,
INDEX `idx_post_id`(`post_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '用户与岗位关联表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_user_post
-- ----------------------------
-- ---------------------------- -- ----------------------------
-- Table structure for sa_system_user_role -- Table structure for sa_system_user_role
-- ---------------------------- -- ----------------------------

View File

@@ -380,7 +380,6 @@ INSERT INTO `sa_system_menu` VALUES (3, 0, '系统管理', 'System', NULL, 1, '/
INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (7, 3, '岗位管理', 'Post', '', 2, 'post', '/system/post', NULL, 'ri:signpost-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -412,13 +411,6 @@ INSERT INTO `sa_system_menu` VALUES (36, 6, '修改', '', 'core:role:update', 3,
INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (41, 7, '数据列表', '', 'core:post:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (42, 7, '添加', '', 'core:post:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (43, 7, '修改', '', 'core:post:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (44, 7, '读取', '', 'core:post:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (45, 7, '删除', '', 'core:post:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (46, 7, '导入', '', 'core:post:import', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (47, 7, '导出', '', 'core:post:export', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -490,25 +482,6 @@ CREATE TABLE `sa_system_oper_log` (
-- Records of sa_system_oper_log -- Records of sa_system_oper_log
-- ---------------------------- -- ----------------------------
-- ----------------------------
-- Table structure for sa_system_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_post`;
CREATE TABLE `sa_system_post` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(50) NULL DEFAULT NULL COMMENT '岗位名称',
`code` varchar(100) NULL DEFAULT NULL COMMENT '岗位代码',
`sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序',
`status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)',
`remark` varchar(255) NULL DEFAULT NULL COMMENT '备注',
`created_by` int(11) NULL DEFAULT NULL COMMENT '创建者',
`updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
`delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 87 COMMENT = '岗位信息表' ROW_FORMAT = Dynamic;
-- ---------------------------- -- ----------------------------
-- Table structure for sa_system_role -- Table structure for sa_system_role
-- ---------------------------- -- ----------------------------
@@ -606,23 +579,6 @@ CREATE TABLE `sa_system_user` (
-- ---------------------------- -- ----------------------------
INSERT INTO `sa_system_user` VALUES (1, 'admin', '$2y$10$wnixh48uDnaW/6D9EygDd.OHJK0vQY/4nHaTjMKBCVDBP2NiTatqS', '祭道之上', '2', 'https://image.saithink.top/saiadmin/avatar.jpg', 'saiadmin@admin.com', '15888888888', 'SaiAdmin是兼具设计美学与高效开发的后台系统!', 'statistics', 1, 1, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL); INSERT INTO `sa_system_user` VALUES (1, 'admin', '$2y$10$wnixh48uDnaW/6D9EygDd.OHJK0vQY/4nHaTjMKBCVDBP2NiTatqS', '祭道之上', '2', 'https://image.saithink.top/saiadmin/avatar.jpg', 'saiadmin@admin.com', '15888888888', 'SaiAdmin是兼具设计美学与高效开发的后台系统!', 'statistics', 1, 1, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ----------------------------
-- Table structure for sa_system_user_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_user_post`;
CREATE TABLE `sa_system_user_post` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户主键',
`post_id` bigint(20) UNSIGNED NOT NULL COMMENT '岗位主键',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_user_id`(`user_id`) USING BTREE,
INDEX `idx_post_id`(`post_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '用户与岗位关联表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_user_post
-- ----------------------------
-- ---------------------------- -- ----------------------------
-- Table structure for sa_system_user_role -- Table structure for sa_system_user_role
-- ---------------------------- -- ----------------------------

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => 'This category has sub-categories, please delete them first', 'This category has sub-categories, please delete them first' => 'This category has sub-categories, please delete them first',
'This department has sub-departments, please delete them first' => 'This department has sub-departments, please delete them first', 'This department has sub-departments, please delete them first' => 'This department has sub-departments, please delete them first',
'This department has users, please delete or transfer them first' => 'This department has users, please delete or transfer them first', 'This department has users, please delete or transfer them first' => 'This department has users, please delete or transfer them first',
'This channel has users, please delete or transfer them first' => 'This channel has users, please delete or transfer them first',
'This dict code already exists' => 'This dict code already exists', 'This dict code already exists' => 'This dict code already exists',
'This menu has sub-menus, please delete them first' => 'This menu has sub-menus, please delete them first', 'This menu has sub-menus, please delete them first' => 'This menu has sub-menus, please delete them first',
'Timestamp expired or invalid, please sync time' => 'Timestamp expired or invalid, please sync time', 'Timestamp expired or invalid, please sync time' => 'Timestamp expired or invalid, please sync time',

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => '该部门下存在子分类,请先删除子分类', 'This category has sub-categories, please delete them first' => '该部门下存在子分类,请先删除子分类',
'This department has sub-departments, please delete them first' => '该部门下存在子部门,请先删除子部门', 'This department has sub-departments, please delete them first' => '该部门下存在子部门,请先删除子部门',
'This department has users, please delete or transfer them first' => '该部门下存在用户,请先删除或者转移用户', 'This department has users, please delete or transfer them first' => '该部门下存在用户,请先删除或者转移用户',
'This channel has users, please delete or transfer them first' => '该渠道下存在用户,请先删除或者转移用户',
'This dict code already exists' => '该字典标识已存在', 'This dict code already exists' => '该字典标识已存在',
'This menu has sub-menus, please delete them first' => '该菜单下存在子菜单,请先删除子菜单', 'This menu has sub-menus, please delete them first' => '该菜单下存在子菜单,请先删除子菜单',
'Timestamp expired or invalid, please sync time' => '时间戳已过期或无效,请同步时间', 'Timestamp expired or invalid, please sync time' => '时间戳已过期或无效,请同步时间',