1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道 3.优化后台页面设置
This commit is contained in:
@@ -1,32 +1,36 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
export type DashboardQueryParams = {
|
||||
dept_id?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 大富翁工作台卡片统计(玩家注册、充值、提现、游玩次数,含较上周对比)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchStatistics() {
|
||||
export function fetchStatistics(params?: DashboardQueryParams) {
|
||||
return request.get<any>({
|
||||
url: '/core/dice/dashboard/statistics'
|
||||
url: '/core/dice/dashboard/statistics',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 近期玩家充值统计(近10天每日充值金额)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchRechargeChart() {
|
||||
export function fetchRechargeChart(params?: DashboardQueryParams) {
|
||||
return request.get<any>({
|
||||
url: '/core/dice/dashboard/rechargeChart'
|
||||
url: '/core/dice/dashboard/rechargeChart',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 月度玩家充值汇总(当年1-12月每月充值金额)
|
||||
* @returns 响应
|
||||
*/
|
||||
export function fetchRechargeBarChart() {
|
||||
export function fetchRechargeBarChart(params?: DashboardQueryParams) {
|
||||
return request.get<any>({
|
||||
url: '/core/dice/dashboard/rechargeBarChart'
|
||||
url: '/core/dice/dashboard/rechargeBarChart',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,11 +43,11 @@ export interface WalletRecordItem {
|
||||
|
||||
/**
|
||||
* 工作台-玩家充值记录(最新50条)
|
||||
* @returns 列表
|
||||
*/
|
||||
export function fetchWalletRecordList() {
|
||||
export function fetchWalletRecordList(params?: DashboardQueryParams) {
|
||||
return request.get<WalletRecordItem[]>({
|
||||
url: '/core/dice/dashboard/walletRecordList'
|
||||
url: '/core/dice/dashboard/walletRecordList',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
@@ -66,21 +70,20 @@ export interface PlayRecordItem {
|
||||
|
||||
/**
|
||||
* 工作台-新增玩家记录(最新50条)
|
||||
* @returns 列表
|
||||
*/
|
||||
export function fetchNewPlayerList() {
|
||||
export function fetchNewPlayerList(params?: DashboardQueryParams) {
|
||||
return request.get<NewPlayerItem[]>({
|
||||
url: '/core/dice/dashboard/newPlayerList'
|
||||
url: '/core/dice/dashboard/newPlayerList',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 工作台-玩家游玩记录(最新50条)
|
||||
* @returns 列表
|
||||
*/
|
||||
export function fetchPlayRecordList() {
|
||||
export function fetchPlayRecordList(params?: DashboardQueryParams) {
|
||||
return request.get<PlayRecordItem[]>({
|
||||
url: '/core/dice/dashboard/playRecordList'
|
||||
url: '/core/dice/dashboard/playRecordList',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -71,5 +71,19 @@ export default {
|
||||
return request.get<Api.Common.ApiData[]>({
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,9 +79,10 @@ export default {
|
||||
* 可操作角色
|
||||
* @returns 数据列表
|
||||
*/
|
||||
accessRole() {
|
||||
accessRole(params?: Record<string, unknown>) {
|
||||
return request.get<Api.Common.ApiData[]>({
|
||||
url: '/core/role/accessRole'
|
||||
url: '/core/role/accessRole',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
138
saiadmin-artd/src/components/channel/SuperAdminChannelShell.vue
Normal file
138
saiadmin-artd/src/components/channel/SuperAdminChannelShell.vue
Normal 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>
|
||||
@@ -18,22 +18,34 @@
|
||||
<!-- 缓存路由动画 -->
|
||||
<Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
|
||||
<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
|
||||
v-else-if="route.meta.keepAlive"
|
||||
class="art-page-view"
|
||||
:is="Component"
|
||||
:key="route.path"
|
||||
v-if="route.meta.keepAlive"
|
||||
/>
|
||||
</KeepAlive>
|
||||
</Transition>
|
||||
|
||||
<!-- 非缓存路由动画 -->
|
||||
<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
|
||||
v-else-if="!route.meta.keepAlive"
|
||||
class="art-page-view"
|
||||
:is="Component"
|
||||
:key="route.path"
|
||||
v-if="!route.meta.keepAlive"
|
||||
/>
|
||||
</Transition>
|
||||
</RouterView>
|
||||
@@ -53,6 +65,8 @@
|
||||
import { useAutoLayoutHeight } from '@/hooks/core/useLayoutHeight'
|
||||
import { useSettingStore } from '@/store/modules/setting'
|
||||
import { useWorktabStore } from '@/store/modules/worktab'
|
||||
import SuperAdminChannelShell from '@/components/channel/SuperAdminChannelShell.vue'
|
||||
import { shouldWrapSuperAdminChannelLayout as shouldWrapChannelLayout } from '@/utils/channelLayout'
|
||||
|
||||
defineOptions({ name: 'ArtPageContent' })
|
||||
|
||||
|
||||
12
saiadmin-artd/src/components/dice/ChannelConfigLayout.vue
Normal file
12
saiadmin-artd/src/components/dice/ChannelConfigLayout.vue
Normal 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>
|
||||
6
saiadmin-artd/src/composables/useChannelConfigScope.ts
Normal file
6
saiadmin-artd/src/composables/useChannelConfigScope.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/** @deprecated 请使用 useChannelDeptScope */
|
||||
export {
|
||||
DEFAULT_CHANNEL_ID,
|
||||
useChannelDeptScope as useChannelConfigScope,
|
||||
type ChannelTreeNode
|
||||
} from './useChannelDeptScope'
|
||||
230
saiadmin-artd/src/composables/useChannelDeptScope.ts
Normal file
230
saiadmin-artd/src/composables/useChannelDeptScope.ts
Normal 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
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
createErrorHandler
|
||||
} from '../../utils/table/tableUtils'
|
||||
import { tableConfig } from '../../utils/table/tableConfig'
|
||||
import { bindChannelDeptToSearchParams, useInjectedChannelDept, getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
// 类型推导工具类型
|
||||
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 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> => {
|
||||
// 取消防抖的搜索
|
||||
@@ -645,7 +663,7 @@ function useTableImpl<TApiFn extends (params: any) => Promise<any>>(
|
||||
}
|
||||
|
||||
// 挂载时自动加载数据
|
||||
if (immediate) {
|
||||
if (immediate && !hasChannelScope) {
|
||||
onMounted(async () => {
|
||||
await getData()
|
||||
})
|
||||
|
||||
@@ -37,7 +37,15 @@
|
||||
"tips": "Prompt",
|
||||
"cancel": "Cancel",
|
||||
"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": {
|
||||
"titlePrompt": "Prompt",
|
||||
@@ -387,7 +395,7 @@
|
||||
"role": "Role Management",
|
||||
"userCenter": "User Center",
|
||||
"menu": "Menu Management",
|
||||
"dept": "Department Management",
|
||||
"dept": "Channel Management",
|
||||
"config": "System Config"
|
||||
},
|
||||
"safeguard": {
|
||||
@@ -516,12 +524,12 @@
|
||||
"system": {
|
||||
"username": "Username",
|
||||
"phone": "Phone",
|
||||
"dept": "Department",
|
||||
"dept": "Channel",
|
||||
"dashboard": "Dashboard",
|
||||
"loginTime": "Last Login",
|
||||
"agentId": "Agent ID",
|
||||
"deptName": "Dept Name",
|
||||
"deptCode": "Dept Code",
|
||||
"deptName": "Channel Name",
|
||||
"deptCode": "Channel Code",
|
||||
"leader": "Leader",
|
||||
"roleName": "Role Name",
|
||||
"roleCode": "Role Code",
|
||||
|
||||
45
saiadmin-artd/src/locales/langs/en/dice/game.json
Normal file
45
saiadmin-artd/src/locales/langs/en/dice/game.json
Normal 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"
|
||||
}
|
||||
}
|
||||
@@ -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.",
|
||||
"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).",
|
||||
"enableKillScore": "Enable kill score",
|
||||
"killScoreWeights": "Kill weights",
|
||||
"killWeightNote": "(Kill weights from pool config type=1; edit in list.)",
|
||||
"btnResetProfit": "Reset Player Total Profit",
|
||||
|
||||
@@ -34,7 +34,15 @@
|
||||
"placeholderRewardTier": "Select reward tier",
|
||||
"addSuccess": "Added 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": {
|
||||
"platformTotalProfit": "Platform Total Profit"
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"status": "Status",
|
||||
"adminId": "Admin",
|
||||
"placeholderAdmin": "Select admin (optional)",
|
||||
"placeholderAdminTree": "Select admin by channel",
|
||||
"unassignedChannel": "Unassigned channel",
|
||||
"coin": "Coin",
|
||||
"placeholderCoinAdd": "Default 0 on create, read-only",
|
||||
"lotteryPoolConfig": "Lottery Pool Config",
|
||||
@@ -44,7 +46,18 @@
|
||||
"ruleEnterCoin": "Please enter coin change",
|
||||
"ruleCoinPositive": "Coin change must be greater than 0",
|
||||
"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": {
|
||||
"username": "Username",
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
"placeholderTotalDrawCount": "Auto sum",
|
||||
"placeholderRemark": "Remark (required)",
|
||||
"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": {
|
||||
"player": "Player",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"toolbar": {
|
||||
"coinChangeSummary": "Coin Change Summary"
|
||||
},
|
||||
"form": {
|
||||
"dialogTitleAdd": "Add Wallet Record",
|
||||
"dialogTitleEdit": "Edit Wallet Record",
|
||||
@@ -19,7 +22,10 @@
|
||||
"placeholderWalletAfter": "Auto calculated",
|
||||
"placeholderRemark": "Optional",
|
||||
"addSuccess": "Added successfully",
|
||||
"editSuccess": "Updated successfully"
|
||||
"editSuccess": "Updated successfully",
|
||||
"ruleUserRequired": "Please select user",
|
||||
"ruleCoinRequired": "Coin change is required",
|
||||
"ruleTypeRequired": "Please select type"
|
||||
},
|
||||
"search": {
|
||||
"type": "Type",
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
"labelLotteryTypePaid": "Test pool type",
|
||||
"labelLotteryTypeFree": "Test pool type",
|
||||
"labelAnte": "Ante",
|
||||
"placeholderAnte": "Select ante config",
|
||||
"placeholderPaidPool": "Leave empty for custom tier odds below (default: default)",
|
||||
"placeholderFreePool": "Leave empty for custom tier odds below (default: killScore)",
|
||||
"tierProbHint": "Custom tier odds (T1–T5), each 0–100%, sum of five must not exceed 100%",
|
||||
@@ -81,7 +82,7 @@
|
||||
"btnNext": "Next",
|
||||
"btnStart": "Start test",
|
||||
"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",
|
||||
"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",
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
{
|
||||
"search": {
|
||||
"deptName": "channel(Department) Name",
|
||||
"deptCode": "Dept Code",
|
||||
"deptName": "Channel Name",
|
||||
"deptCode": "Channel Code",
|
||||
"status": "Status",
|
||||
"placeholderDeptName": "Please enter dept name",
|
||||
"placeholderDeptCode": "Please enter dept code",
|
||||
"placeholderDeptName": "Please enter channel name",
|
||||
"placeholderDeptCode": "Please enter channel code",
|
||||
"searchSelectPlaceholder": "Please select"
|
||||
},
|
||||
"table": {
|
||||
"deptName": "channel(Department) Name",
|
||||
"deptCode": "Dept Code",
|
||||
"leader": "Leader",
|
||||
"deptName": "Channel Name",
|
||||
"deptCode": "Channel Code",
|
||||
"leader": "Channel Leader",
|
||||
"sort": "Sort",
|
||||
"status": "Status",
|
||||
"createTime": "Create Time"
|
||||
},
|
||||
"form": {
|
||||
"titleAdd": "Add Department",
|
||||
"titleEdit": "Edit Department",
|
||||
"labelParentDept": "Parent Department",
|
||||
"labelDeptName": "Dept Name",
|
||||
"labelDeptCode": "Dept Code",
|
||||
"labelLeader": "Leader",
|
||||
"titleAdd": "Add Channel",
|
||||
"titleEdit": "Edit Channel",
|
||||
"labelDeptName": "Channel Name",
|
||||
"labelDeptCode": "Channel Code",
|
||||
"labelLeader": "Channel Leader",
|
||||
"labelRemark": "Description",
|
||||
"labelSort": "Sort",
|
||||
"labelStatus": "Enabled",
|
||||
"placeholderDeptName": "Please enter dept name",
|
||||
"placeholderDeptCode": "Please enter dept code",
|
||||
"placeholderDeptName": "Please enter channel name",
|
||||
"placeholderDeptCode": "Please enter channel code",
|
||||
"placeholderRemark": "Please enter description",
|
||||
"placeholderSort": "Please enter sort",
|
||||
"noParentDept": "No parent department",
|
||||
"ruleParentDeptRequired": "Please select parent department",
|
||||
"ruleDeptNameRequired": "Please enter dept name",
|
||||
"ruleDeptCodeRequired": "Please enter dept code",
|
||||
"ruleDeptNameRequired": "Please enter channel name",
|
||||
"ruleDeptCodeRequired": "Please enter channel code",
|
||||
"addSuccess": "Added successfully",
|
||||
"editSuccess": "Updated successfully"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"table": {
|
||||
"username": "Username",
|
||||
"phone": "Phone",
|
||||
"dept": "Department",
|
||||
"dept": "Channel",
|
||||
"dashboard": "Dashboard",
|
||||
"loginTime": "Last Login",
|
||||
"agentId": "Agent ID",
|
||||
@@ -28,7 +28,7 @@
|
||||
"labelPasswordConfirm": "Confirm Password",
|
||||
"labelEmail": "Email",
|
||||
"labelPhone": "Phone",
|
||||
"labelDept": "Department",
|
||||
"labelDept": "Channel",
|
||||
"labelRole": "Role",
|
||||
"labelGender": "Gender",
|
||||
"labelStatus": "Status",
|
||||
@@ -42,12 +42,15 @@
|
||||
"rulePasswordRequired": "Please enter password",
|
||||
"rulePasswordLength": "Length must be between 6 and 20 characters",
|
||||
"rulePasswordConfirmRequired": "Please enter confirm password",
|
||||
"ruleDeptRequired": "Please select department",
|
||||
"ruleDeptRequired": "Please select channel",
|
||||
"ruleRoleRequired": "Please select role",
|
||||
"addSuccess": "Added successfully",
|
||||
"editSuccess": "Updated successfully"
|
||||
},
|
||||
"ui": {
|
||||
"channelList": "Channel List",
|
||||
"viewingChannel": "Current channel",
|
||||
"defaultConfigTemplate": "Default config template",
|
||||
"promptNewPassword": "Please enter a new password",
|
||||
"passwordLengthError": "Password length must be between 6 and 16",
|
||||
"passwordChanged": "Password updated",
|
||||
|
||||
@@ -37,7 +37,15 @@
|
||||
"tips": "提示",
|
||||
"cancel": "取消",
|
||||
"confirm": "确定",
|
||||
"logOutTips": "您是否要退出登录?"
|
||||
"logOutTips": "您是否要退出登录?",
|
||||
"channelScope": {
|
||||
"listTitle": "渠道列表",
|
||||
"defaultTemplate": "默认配置模板",
|
||||
"defaultRoleTemplate": "默认角色模板",
|
||||
"currentConfig": "当前配置",
|
||||
"currentChannel": "当前渠道",
|
||||
"currentRole": "当前角色范围"
|
||||
}
|
||||
},
|
||||
"uiMsg": {
|
||||
"titlePrompt": "提示",
|
||||
@@ -383,7 +391,7 @@
|
||||
"role": "角色管理",
|
||||
"userCenter": "个人中心",
|
||||
"menu": "菜单管理",
|
||||
"dept": "渠道(部门)管理",
|
||||
"dept": "渠道管理",
|
||||
"config": "系统配置"
|
||||
},
|
||||
"safeguard": {
|
||||
@@ -445,8 +453,8 @@
|
||||
"placeholderTaskName": "请输入任务名称",
|
||||
"placeholderTableName": "请输入数据表名称",
|
||||
"placeholderDataSource": "请输入数据源名称",
|
||||
"placeholderDeptName": "请输入部门名称",
|
||||
"placeholderDeptCode": "请输入部门编码",
|
||||
"placeholderDeptName": "请输入渠道名称",
|
||||
"placeholderDeptCode": "请输入渠道编码",
|
||||
"placeholderRoleName": "请输入角色名称",
|
||||
"placeholderRoleCode": "请输入角色编码",
|
||||
"placeholderMenuName": "请输入菜单名称",
|
||||
@@ -512,13 +520,13 @@
|
||||
"system": {
|
||||
"username": "用户名",
|
||||
"phone": "手机号",
|
||||
"dept": "部门",
|
||||
"dept": "渠道",
|
||||
"dashboard": "首页",
|
||||
"loginTime": "上次登录",
|
||||
"agentId": "代理ID",
|
||||
"deptName": "部门名称",
|
||||
"deptCode": "部门编码",
|
||||
"leader": "部门领导",
|
||||
"deptName": "渠道名称",
|
||||
"deptCode": "渠道编码",
|
||||
"leader": "渠道负责人",
|
||||
"roleName": "角色名称",
|
||||
"roleCode": "角色编码",
|
||||
"level": "角色级别",
|
||||
@@ -538,7 +546,7 @@
|
||||
"titleEn": "标题(英文)",
|
||||
"value": "值",
|
||||
"valueEn": "值(英文)",
|
||||
"noParentDept": "无上级部门",
|
||||
"noParentDept": "无上级渠道",
|
||||
"noParentMenu": "无上级菜单",
|
||||
"input": "文本框",
|
||||
"textarea": "文本域",
|
||||
|
||||
45
saiadmin-artd/src/locales/langs/zh/dice/game.json
Normal file
45
saiadmin-artd/src/locales/langs/zh/dice/game.json
Normal 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": "禁用"
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
"profitCalcHint": "计算方式:付费每局按“赢取平台币 win_coin(含 BIGWIN)减去付费金额 压注金额paid_amount(= 压注倍数ante×1)”累加;免费每局按“玩家赢得平台币win_coin”累加。弹窗打开期间每 2 秒自动刷新",
|
||||
"tierRuleTitle": "抽奖档位规则",
|
||||
"tierRuleContent": "当玩家在当前彩金池的累计盈利 低于安全线 时,按 玩家 的 T*_weight 权重抽取档位;当累计盈利 高于或等于安全线 时,按 当前彩金池 的 T*_weight 权重抽取档位(杀分)。",
|
||||
"enableKillScore": "开启杀分",
|
||||
"killScoreWeights": "杀分权重",
|
||||
"killWeightNote": "(杀分权重来自奖池配置,请在列表中编辑对应记录)",
|
||||
"btnResetProfit": "重置玩家累计盈利",
|
||||
|
||||
@@ -34,7 +34,15 @@
|
||||
"placeholderRewardTier": "请选择中奖档位",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功",
|
||||
"validateFailed": "表单验证失败,请检查必填项与格式"
|
||||
"validateFailed": "表单验证失败,请检查必填项与格式",
|
||||
"rulePlayerRequired": "请选择玩家",
|
||||
"ruleLotteryConfigRequired": "请选择彩金池配置",
|
||||
"ruleLotteryTypeRequired": "请选择抽奖类型",
|
||||
"ruleIsWinRequired": "请选择是否中大奖",
|
||||
"ruleWinCoinRequired": "赢取平台币必填",
|
||||
"ruleRollArrayLength": "摇取点数必须为 5 个数",
|
||||
"ruleRollArrayValues": "摇取点数必须填写 5 个数,每个 1~6",
|
||||
"ruleRewardTierRequired": "请选择中奖档位"
|
||||
},
|
||||
"toolbar": {
|
||||
"platformTotalProfit": "平台总盈利"
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
"status": "状态",
|
||||
"adminId": "所属管理员",
|
||||
"placeholderAdmin": "选择后台管理员(可选)",
|
||||
"placeholderAdminTree": "按渠道选择后台管理员",
|
||||
"unassignedChannel": "未分配渠道",
|
||||
"coin": "平台币",
|
||||
"placeholderCoinAdd": "创建时默认0,不可改",
|
||||
"lotteryPoolConfig": "彩金池配置",
|
||||
@@ -44,7 +46,18 @@
|
||||
"ruleEnterCoin": "请输入平台币变动",
|
||||
"ruleCoinPositive": "平台币变动必须大于 0",
|
||||
"ruleDeductExceed": "扣点不能超过当前余额",
|
||||
"operateSuccess": "操作成功"
|
||||
"operateSuccess": "操作成功",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功",
|
||||
"rulePasswordRequired": "密码必需填写",
|
||||
"ruleUsernameRequired": "用户名必需填写",
|
||||
"ruleNicknameRequired": "昵称必需填写",
|
||||
"rulePhoneRequired": "手机号必需填写",
|
||||
"ruleStatusRequired": "状态必需填写",
|
||||
"ruleCoinRequired": "平台币必需填写",
|
||||
"configTypeDefault": "默认",
|
||||
"configTypeKillScore": "杀分",
|
||||
"configTypeUp": "上分"
|
||||
},
|
||||
"search": {
|
||||
"username": "用户名",
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
"placeholderTotalDrawCount": "自动求和",
|
||||
"placeholderRemark": "请输入备注(必填)",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功"
|
||||
"editSuccess": "修改成功",
|
||||
"rulePlayerRequired": "请选择玩家",
|
||||
"ruleUseCoinsRequired": "消耗硬币必需填写",
|
||||
"rulePaidDrawRequired": "购买抽奖次数必需填写",
|
||||
"ruleFreeDrawRequired": "赠送抽奖次数必需填写",
|
||||
"ruleRemarkRequired": "备注必需填写"
|
||||
},
|
||||
"search": {
|
||||
"player": "玩家",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"toolbar": {
|
||||
"coinChangeSummary": "平台币变化统计"
|
||||
},
|
||||
"form": {
|
||||
"dialogTitleAdd": "新增玩家钱包流水",
|
||||
"dialogTitleEdit": "编辑玩家钱包流水",
|
||||
@@ -19,7 +22,10 @@
|
||||
"placeholderWalletAfter": "根据平台币变化自动计算",
|
||||
"placeholderRemark": "选填",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功"
|
||||
"editSuccess": "修改成功",
|
||||
"ruleUserRequired": "请选择用户",
|
||||
"ruleCoinRequired": "平台币变化必填",
|
||||
"ruleTypeRequired": "请选择类型"
|
||||
},
|
||||
"search": {
|
||||
"type": "类型",
|
||||
|
||||
@@ -68,7 +68,8 @@
|
||||
"stepFree": "免费抽奖券",
|
||||
"labelLotteryTypePaid": "测试数据档位类型",
|
||||
"labelLotteryTypeFree": "测试数据档位类型",
|
||||
"labelAnte": "底注 ante",
|
||||
"labelAnte": "底注",
|
||||
"placeholderAnte": "请选择底注配置",
|
||||
"placeholderPaidPool": "不选则下方自定义档位概率(默认 default)",
|
||||
"placeholderFreePool": "不选则下方自定义档位概率(默认 killScore)",
|
||||
"tierProbHint": "自定义档位概率(T1~T5),每档 0-100%,五档之和不能超过 100%",
|
||||
@@ -81,7 +82,7 @@
|
||||
"btnNext": "下一步",
|
||||
"btnStart": "开始测试",
|
||||
"btnCancel": "取消",
|
||||
"warnAnte": "底注 ante 必须大于 0",
|
||||
"warnAnte": "请选择底注",
|
||||
"warnPaidSpins": "付费抽奖顺时针与逆时针次数之和须大于 0",
|
||||
"warnTestSafetyLine": "测试安全线必须大于或等于 0",
|
||||
"warnTotalSpins": "付费或免费至少一种方向次数之和大于 0",
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
{
|
||||
"search": {
|
||||
"deptName": "渠道(部门)名称",
|
||||
"deptCode": "部门编码",
|
||||
"deptName": "渠道名称",
|
||||
"deptCode": "渠道编码",
|
||||
"status": "状态",
|
||||
"placeholderDeptName": "请输入部门名称",
|
||||
"placeholderDeptCode": "请输入部门编码",
|
||||
"placeholderDeptName": "请输入渠道名称",
|
||||
"placeholderDeptCode": "请输入渠道编码",
|
||||
"searchSelectPlaceholder": "请选择"
|
||||
},
|
||||
"table": {
|
||||
"deptName": "渠道(部门)名称",
|
||||
"deptCode": "部门编码",
|
||||
"leader": "部门领导",
|
||||
"deptName": "渠道名称",
|
||||
"deptCode": "渠道编码",
|
||||
"leader": "渠道负责人",
|
||||
"sort": "排序",
|
||||
"status": "状态",
|
||||
"createTime": "创建时间"
|
||||
},
|
||||
"form": {
|
||||
"titleAdd": "新增部门",
|
||||
"titleEdit": "编辑部门",
|
||||
"labelParentDept": "上级部门",
|
||||
"labelDeptName": "部门名称",
|
||||
"labelDeptCode": "部门编码",
|
||||
"labelLeader": "部门领导",
|
||||
"titleAdd": "新增渠道",
|
||||
"titleEdit": "编辑渠道",
|
||||
"labelDeptName": "渠道名称",
|
||||
"labelDeptCode": "渠道编码",
|
||||
"labelLeader": "渠道负责人",
|
||||
"labelRemark": "描述",
|
||||
"labelSort": "排序",
|
||||
"labelStatus": "启用",
|
||||
"placeholderDeptName": "请输入部门名称",
|
||||
"placeholderDeptCode": "请输入部门编码",
|
||||
"placeholderRemark": "请输入部门描述",
|
||||
"placeholderDeptName": "请输入渠道名称",
|
||||
"placeholderDeptCode": "请输入渠道编码",
|
||||
"placeholderRemark": "请输入渠道描述",
|
||||
"placeholderSort": "请输入排序",
|
||||
"noParentDept": "无上级部门",
|
||||
"ruleParentDeptRequired": "请选择上级部门",
|
||||
"ruleDeptNameRequired": "请输入部门名称",
|
||||
"ruleDeptCodeRequired": "请输入部门编码",
|
||||
"ruleDeptNameRequired": "请输入渠道名称",
|
||||
"ruleDeptCodeRequired": "请输入渠道编码",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"table": {
|
||||
"username": "用户名",
|
||||
"phone": "手机号",
|
||||
"dept": "部门",
|
||||
"dept": "渠道",
|
||||
"dashboard": "首页",
|
||||
"loginTime": "上次登录",
|
||||
"agentId": "代理ID",
|
||||
@@ -28,7 +28,7 @@
|
||||
"labelPasswordConfirm": "确认密码",
|
||||
"labelEmail": "邮箱",
|
||||
"labelPhone": "手机号",
|
||||
"labelDept": "部门",
|
||||
"labelDept": "渠道",
|
||||
"labelRole": "角色",
|
||||
"labelGender": "性别",
|
||||
"labelStatus": "状态",
|
||||
@@ -42,12 +42,15 @@
|
||||
"rulePasswordRequired": "请输入密码",
|
||||
"rulePasswordLength": "长度在 6 到 20 个字符",
|
||||
"rulePasswordConfirmRequired": "请输入确认密码",
|
||||
"ruleDeptRequired": "请选择部门",
|
||||
"ruleDeptRequired": "请选择渠道",
|
||||
"ruleRoleRequired": "请选择角色",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功"
|
||||
},
|
||||
"ui": {
|
||||
"channelList": "渠道列表",
|
||||
"viewingChannel": "当前配置渠道",
|
||||
"defaultConfigTemplate": "默认配置模板",
|
||||
"promptNewPassword": "请输入新密码",
|
||||
"passwordLengthError": "密码长度在6到16之间",
|
||||
"passwordChanged": "修改密码成功",
|
||||
|
||||
48
saiadmin-artd/src/utils/channelLayout.ts
Normal file
48
saiadmin-artd/src/utils/channelLayout.ts
Normal 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
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchRechargeBarChart } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
/**
|
||||
* 充值金额数据
|
||||
@@ -29,10 +30,12 @@
|
||||
*/
|
||||
const xData = ref<string[]>([])
|
||||
|
||||
onMounted(async () => {
|
||||
fetchRechargeBarChart().then((data: any) => {
|
||||
const loadChart = () => {
|
||||
fetchRechargeBarChart(getChannelDeptRequestParams()).then((data: any) => {
|
||||
yData.value = data?.recharge_amount ?? []
|
||||
xData.value = data?.recharge_month ?? []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadChart)
|
||||
</script>
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchStatistics } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const statData = ref({
|
||||
player_count: 0,
|
||||
@@ -123,8 +124,8 @@
|
||||
return 'text-g-600'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchStatistics().then((data: any) => {
|
||||
const loadStatistics = () => {
|
||||
fetchStatistics(getChannelDeptRequestParams()).then((data: any) => {
|
||||
statData.value = {
|
||||
player_count: data?.player_count ?? 0,
|
||||
player_count_change: data?.player_count_change ?? 0,
|
||||
@@ -136,5 +137,7 @@
|
||||
play_count_change: data?.play_count_change ?? 0
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadStatistics)
|
||||
</script>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchNewPlayerList, type NewPlayerItem } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const tableData = ref<NewPlayerItem[]>([])
|
||||
|
||||
@@ -49,9 +50,11 @@
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchNewPlayerList().then((data) => {
|
||||
const loadList = () => {
|
||||
fetchNewPlayerList(getChannelDeptRequestParams()).then((data) => {
|
||||
tableData.value = Array.isArray(data) ? data : []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadList)
|
||||
</script>
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchPlayRecordList, type PlayRecordItem } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const tableData = ref<PlayRecordItem[]>([])
|
||||
|
||||
@@ -59,9 +60,11 @@
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchPlayRecordList().then((data) => {
|
||||
const loadList = () => {
|
||||
fetchPlayRecordList(getChannelDeptRequestParams()).then((data) => {
|
||||
tableData.value = Array.isArray(data) ? data : []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadList)
|
||||
</script>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchRechargeChart } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
/**
|
||||
* 充值金额数据
|
||||
@@ -28,10 +29,12 @@
|
||||
*/
|
||||
const xData = ref<string[]>([])
|
||||
|
||||
onMounted(async () => {
|
||||
fetchRechargeChart().then((data: any) => {
|
||||
const loadChart = () => {
|
||||
fetchRechargeChart(getChannelDeptRequestParams()).then((data: any) => {
|
||||
yData.value = data?.recharge_amount ?? []
|
||||
xData.value = data?.recharge_date ?? []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadChart)
|
||||
</script>
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchWalletRecordList, type WalletRecordItem } from '@/api/dashboard'
|
||||
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const tableData = ref<WalletRecordItem[]>([])
|
||||
|
||||
@@ -38,9 +39,11 @@
|
||||
return Number(val).toFixed(2)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWalletRecordList().then((data) => {
|
||||
const loadList = () => {
|
||||
fetchWalletRecordList(getChannelDeptRequestParams()).then((data) => {
|
||||
tableData.value = Array.isArray(data) ? data : []
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
useChannelDeptReload(loadList)
|
||||
</script>
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiParams: { limit: 100 },
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -111,10 +112,10 @@
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -36,5 +36,16 @@ export default {
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/destroy',
|
||||
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 : []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
* 获取 DiceLotteryPoolConfig 列表数据,含 id、name、t1_weight~t5_weight,用于一键测试权重档位类型下拉
|
||||
* name 映射:default=原 type=0,killScore=原 type=1,up=原 type=2
|
||||
*/
|
||||
async getOptions(): Promise<
|
||||
async getOptions(params?: Record<string, unknown>): Promise<
|
||||
Array<{
|
||||
id: number
|
||||
name: string
|
||||
@@ -32,7 +32,8 @@ export default {
|
||||
}>
|
||||
> {
|
||||
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 : [])
|
||||
if (!Array.isArray(rows)) return []
|
||||
@@ -97,7 +98,7 @@ export default {
|
||||
/**
|
||||
* 获取当前彩金池(Redis 实例化,无则按 type=0 创建),含玩家累计盈利 profit_amount 实时值
|
||||
*/
|
||||
getCurrentPool() {
|
||||
getCurrentPool(params?: { dept_id?: number }) {
|
||||
return request.get<{
|
||||
id: number
|
||||
name: string
|
||||
@@ -110,14 +111,15 @@ export default {
|
||||
t5_weight: number
|
||||
profit_amount: number
|
||||
}>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool'
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新当前彩金池:仅 safety_line、t1_weight~t5_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>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool',
|
||||
data: params
|
||||
@@ -127,9 +129,10 @@ export default {
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利(profit_amount 置为 0)
|
||||
*/
|
||||
resetProfitAmount() {
|
||||
resetProfitAmount(params?: { dept_id?: number }) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount'
|
||||
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount',
|
||||
data: params || {}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,16 +64,18 @@ export default {
|
||||
},
|
||||
|
||||
/** 获取玩家选项(id、username) */
|
||||
getPlayerOptions() {
|
||||
getPlayerOptions(params?: Record<string, unknown>) {
|
||||
return request.get<{ id: number; username: string }[]>({
|
||||
url: '/core/dice/play_record/DicePlayRecord/getPlayerOptions'
|
||||
url: '/core/dice/play_record/DicePlayRecord/getPlayerOptions',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/** 获取彩金池配置选项(id、name) */
|
||||
getLotteryConfigOptions() {
|
||||
getLotteryConfigOptions(params?: Record<string, unknown>) {
|
||||
return request.get<{ id: number; name: string }[]>({
|
||||
url: '/core/dice/play_record/DicePlayRecord/getLotteryConfigOptions'
|
||||
url: '/core/dice/play_record/DicePlayRecord/getLotteryConfigOptions',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +87,10 @@ export default {
|
||||
* 获取彩金池配置选项(DiceLotteryPoolConfig.id、name),供 lottery_config_id 下拉使用
|
||||
* @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>({
|
||||
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 }>
|
||||
return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
|
||||
@@ -99,11 +100,12 @@ export default {
|
||||
* 获取后台管理员选项(SystemUser),供 admin_id 下拉使用
|
||||
* @returns [ { id, username, realname, label } ]
|
||||
*/
|
||||
async getSystemUserOptions(): Promise<
|
||||
async getSystemUserOptions(params?: Record<string, unknown>): Promise<
|
||||
Array<{ id: number; username: string; realname: string; label: string }>
|
||||
> {
|
||||
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<{
|
||||
id: number
|
||||
@@ -117,5 +119,29 @@ export default {
|
||||
realname: String(r.realname ?? ''),
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +66,10 @@ export default {
|
||||
/**
|
||||
* 获取玩家选项(id、username)用于下拉
|
||||
*/
|
||||
getPlayerOptions() {
|
||||
getPlayerOptions(params?: Record<string, unknown>) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions'
|
||||
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export default {
|
||||
* @returns 数据列表
|
||||
*/
|
||||
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',
|
||||
params
|
||||
})
|
||||
@@ -66,9 +66,10 @@ export default {
|
||||
/**
|
||||
* 获取玩家选项(id、username)用于下拉
|
||||
*/
|
||||
getPlayerOptions() {
|
||||
getPlayerOptions(params?: Record<string, unknown>) {
|
||||
return request.get<{ id: number; username: string }[]>({
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions'
|
||||
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -19,19 +19,20 @@ export default {
|
||||
* 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向)
|
||||
* @param direction 0=顺时针 1=逆时针
|
||||
*/
|
||||
weightRatioList(direction: 0 | 1) {
|
||||
weightRatioList(direction: 0 | 1, params?: Record<string, unknown>) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/reward/DiceReward/weightRatioList',
|
||||
params: { direction }
|
||||
params: { direction, ...(params || {}) }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重(dice_reward 双方向)
|
||||
*/
|
||||
weightRatioListWithDirection() {
|
||||
weightRatioListWithDirection(params?: Record<string, unknown>) {
|
||||
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
|
||||
* @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>({
|
||||
url: '/core/dice/reward/DiceReward/batchUpdateWeights',
|
||||
data: { items }
|
||||
data: { items, ...(extra || {}) }
|
||||
})
|
||||
},
|
||||
|
||||
@@ -62,6 +66,7 @@ export default {
|
||||
*/
|
||||
startWeightTest(params: {
|
||||
ante?: number
|
||||
ante_config_id?: number
|
||||
lottery_config_id?: number
|
||||
paid_lottery_config_id?: number
|
||||
free_lottery_config_id?: number
|
||||
|
||||
@@ -66,19 +66,23 @@ export default {
|
||||
/**
|
||||
* 批量更新奖励索引配置(第一页: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>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdate',
|
||||
data: { items }
|
||||
data: { items, ...(extra || {}) }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* T1-T5、BIGWIN 权重配比:按档位分组获取配置列表
|
||||
*/
|
||||
weightRatioList() {
|
||||
weightRatioList(params?: Record<string, unknown>) {
|
||||
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)
|
||||
*/
|
||||
/** 按 DiceReward 主键 id 批量更新 weight;items: [{ id, weight }, ...] */
|
||||
batchUpdateWeights(items: Array<{ id: number; weight: number }>) {
|
||||
batchUpdateWeights(
|
||||
items: Array<{ id: number; weight: number }>,
|
||||
extra?: Record<string, unknown>
|
||||
) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdateWeights',
|
||||
data: { items }
|
||||
data: { items, ...(extra || {}) }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 大奖权重:按 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>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid',
|
||||
data: { items }
|
||||
data: { items, ...(extra || {}) }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建奖励对照:按当前奖励配置为顺时针(0)、逆时针(1)生成所有色子可能对应的 dice_reward 记录,权重默认 1,可在奖励对照页权重编辑中调整
|
||||
*/
|
||||
createRewardReference() {
|
||||
createRewardReference(params?: Record<string, any>) {
|
||||
return request.post<{
|
||||
created_clockwise: number
|
||||
created_counterclockwise: number
|
||||
updated_clockwise: number
|
||||
updated_counterclockwise: number
|
||||
}>({
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference'
|
||||
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference',
|
||||
data: params || {}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiParams: { limit: 100 },
|
||||
columnsFactory: () => [
|
||||
// { type: 'selection' },
|
||||
{ prop: 'group', label: 'page.table.group', minWidth: 140, align: 'center' },
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -162,10 +163,10 @@
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.saveSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.updateSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<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 #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
@@ -103,6 +105,7 @@
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiParams: { limit: 100 },
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection', align: 'center' },
|
||||
{ prop: 'id', label: 'ID', width: 80, align: 'center' },
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? '新增游戏' : '编辑游戏'"
|
||||
:title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
|
||||
width="680px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@@ -10,55 +10,55 @@
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="供应商" prop="provider">
|
||||
<el-input v-model="formData.provider" placeholder="请输入供应商名称" />
|
||||
<el-form-item :label="$t('page.form.provider')" prop="provider">
|
||||
<el-input v-model="formData.provider" :placeholder="$t('page.form.placeholderProvider')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="供应商编码" prop="provider_code">
|
||||
<el-input v-model="formData.provider_code" placeholder="请输入供应商编码" />
|
||||
<el-form-item :label="$t('page.form.providerCode')" prop="provider_code">
|
||||
<el-input v-model="formData.provider_code" :placeholder="$t('page.form.placeholderProviderCode')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="游戏编号" prop="game_code">
|
||||
<el-input v-model="formData.game_code" placeholder="请输入游戏编号" />
|
||||
<el-form-item :label="$t('page.form.gameCode')" prop="game_code">
|
||||
<el-input v-model="formData.game_code" :placeholder="$t('page.form.placeholderGameCode')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="游戏唯一值" prop="game_key">
|
||||
<el-input v-model="formData.game_key" placeholder="请输入游戏唯一值" />
|
||||
<el-form-item :label="$t('page.form.gameKey')" prop="game_key">
|
||||
<el-input v-model="formData.game_key" :placeholder="$t('page.form.placeholderGameKey')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="中文名称" prop="game_name">
|
||||
<el-input v-model="formData.game_name" placeholder="请输入中文名称" />
|
||||
<el-form-item :label="$t('page.form.gameName')" prop="game_name">
|
||||
<el-input v-model="formData.game_name" :placeholder="$t('page.form.placeholderGameName')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="英文名称" prop="game_name_en">
|
||||
<el-input v-model="formData.game_name_en" placeholder="请输入英文名称" />
|
||||
<el-form-item :label="$t('page.form.gameNameEn')" prop="game_name_en">
|
||||
<el-input v-model="formData.game_name_en" :placeholder="$t('page.form.placeholderGameNameEn')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="游戏类型" prop="game_type">
|
||||
<el-input v-model="formData.game_type" placeholder="请输入游戏类型" />
|
||||
<el-form-item :label="$t('page.form.gameType')" prop="game_type">
|
||||
<el-input v-model="formData.game_type" :placeholder="$t('page.form.placeholderGameType')" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<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-form-item>
|
||||
</el-col>
|
||||
</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-tab-pane label="图片选择" name="picker">
|
||||
<el-tab-pane :label="$t('page.form.tabPicker')" name="picker">
|
||||
<sa-image-picker
|
||||
v-model="formData.logo"
|
||||
:multiple="false"
|
||||
@@ -67,7 +67,7 @@
|
||||
height="120px"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="图片上传" name="upload">
|
||||
<el-tab-pane :label="$t('page.form.tabUpload')" name="upload">
|
||||
<sa-image-upload
|
||||
v-model="formData.logo"
|
||||
:multiple="false"
|
||||
@@ -78,33 +78,42 @@
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-form-item>
|
||||
<el-form-item label="游戏地址" prop="game_url">
|
||||
<el-input v-model="formData.game_url" placeholder="请输入游戏地址" />
|
||||
<el-form-item :label="$t('page.form.gameUrl')" prop="game_url">
|
||||
<el-input v-model="formData.game_url" :placeholder="$t('page.form.placeholderGameUrl')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="大厅地址" prop="hall_url">
|
||||
<el-input v-model="formData.hall_url" placeholder="请输入大厅地址" />
|
||||
<el-form-item :label="$t('page.form.hallUrl')" prop="hall_url">
|
||||
<el-input v-model="formData.hall_url" :placeholder="$t('page.form.placeholderHallUrl')" />
|
||||
</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 :value="1">启用</el-radio>
|
||||
<el-radio :value="0">禁用</el-radio>
|
||||
<el-radio :value="1">{{ $t('page.form.statusEnabled') }}</el-radio>
|
||||
<el-radio :value="0">{{ $t('page.form.statusDisabled') }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="请输入备注" />
|
||||
<el-form-item :label="$t('page.form.remark')" prop="remark">
|
||||
<el-input
|
||||
v-model="formData.remark"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
:placeholder="$t('page.form.placeholderRemark')"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
<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/game/index'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
@@ -121,40 +130,24 @@
|
||||
data: undefined
|
||||
})
|
||||
const emit = defineEmits<Emits>()
|
||||
const formRef = ref<FormInstance>()
|
||||
const logoInputMode = ref<'picker' | 'upload'>('picker')
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
type GameFormData = {
|
||||
id: number | null
|
||||
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 formRef = ref<FormInstance>()
|
||||
const logoInputMode = ref('picker')
|
||||
|
||||
const initialFormData: GameFormData = {
|
||||
id: null,
|
||||
provider: 'Dicey Fun',
|
||||
provider_code: 'DF',
|
||||
const initialFormData = {
|
||||
id: undefined as number | undefined,
|
||||
provider: '',
|
||||
provider_code: '',
|
||||
game_code: '',
|
||||
game_key: '',
|
||||
game_name: '',
|
||||
game_name_en: '',
|
||||
game_type: 'slot',
|
||||
game_type: '',
|
||||
logo: '',
|
||||
game_url: '',
|
||||
hall_url: '',
|
||||
@@ -166,12 +159,12 @@
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
const rules = computed<FormRules>(() => ({
|
||||
provider: [{ required: true, message: '请输入供应商', trigger: 'blur' }],
|
||||
provider_code: [{ required: true, message: '请输入供应商编码', trigger: 'blur' }],
|
||||
game_code: [{ required: true, message: '请输入游戏编号', trigger: 'blur' }],
|
||||
game_key: [{ required: true, message: '请输入游戏唯一值', trigger: 'blur' }],
|
||||
game_name: [{ required: true, message: '请输入中文名称', trigger: 'blur' }],
|
||||
game_type: [{ required: true, message: '请输入游戏类型', trigger: 'blur' }]
|
||||
provider: [{ required: true, message: t('page.form.ruleProviderRequired'), trigger: 'blur' }],
|
||||
provider_code: [{ required: true, message: t('page.form.ruleProviderCodeRequired'), trigger: 'blur' }],
|
||||
game_code: [{ required: true, message: t('page.form.ruleGameCodeRequired'), trigger: 'blur' }],
|
||||
game_key: [{ required: true, message: t('page.form.ruleGameKeyRequired'), trigger: 'blur' }],
|
||||
game_name: [{ required: true, message: t('page.form.ruleGameNameRequired'), trigger: 'blur' }],
|
||||
game_type: [{ required: true, message: t('page.form.ruleGameTypeRequired'), trigger: 'blur' }]
|
||||
}))
|
||||
|
||||
watch(
|
||||
@@ -209,11 +202,11 @@
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
ElMessage.success('新增成功')
|
||||
await api.save(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
ElMessage.success('更新成功')
|
||||
await api.update(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<!-- 搜索面板 -->
|
||||
<div class="flex-1 min-h-0 flex flex-col">
|
||||
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
|
||||
|
||||
<ElCard class="art-table-card" shadow="never">
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</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-form-item>
|
||||
<el-form-item :label="$t('page.form.killScoreWeights')">
|
||||
@@ -85,8 +85,13 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
getChannelDeptRequestParams,
|
||||
withChannelDeptParams
|
||||
} from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
const channelDeptParams = () => getChannelDeptRequestParams()
|
||||
|
||||
interface PoolData {
|
||||
id: number
|
||||
@@ -151,7 +156,7 @@
|
||||
if (!visible.value) return
|
||||
try {
|
||||
loading.value = true
|
||||
const res = await api.getCurrentPool()
|
||||
const res = await api.getCurrentPool(channelDeptParams())
|
||||
const data = res as unknown as PoolData
|
||||
if (data && typeof data === 'object') {
|
||||
pool.value = data
|
||||
@@ -172,7 +177,7 @@
|
||||
stopPolling()
|
||||
return
|
||||
}
|
||||
api.getCurrentPool().then((res) => {
|
||||
api.getCurrentPool(channelDeptParams()).then((res) => {
|
||||
const data = res as unknown as PoolData
|
||||
if (pool.value && data && typeof data === 'object' && data.profit_amount != null) {
|
||||
pool.value.profit_amount = data.profit_amount
|
||||
@@ -193,10 +198,12 @@
|
||||
try {
|
||||
await formRef.value?.validate?.()
|
||||
saving.value = true
|
||||
await api.updateCurrentPool({
|
||||
safety_line: formData.safety_line,
|
||||
kill_enabled: formData.kill_enabled
|
||||
})
|
||||
await api.updateCurrentPool(
|
||||
withChannelDeptParams({
|
||||
safety_line: formData.safety_line,
|
||||
kill_enabled: formData.kill_enabled
|
||||
})
|
||||
)
|
||||
ElMessage.success(t('page.form.msgSaveSuccess'))
|
||||
await loadPool()
|
||||
emit('success')
|
||||
@@ -211,7 +218,7 @@
|
||||
if (!pool.value) return
|
||||
try {
|
||||
resetting.value = true
|
||||
await api.resetProfitAmount()
|
||||
await api.resetProfitAmount(channelDeptParams())
|
||||
ElMessage.success(t('page.form.msgResetProfitSuccess'))
|
||||
await loadPool()
|
||||
emit('success')
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useInjectedChannelDept, withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -127,6 +128,7 @@
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null as number | null,
|
||||
dept_id: undefined as number | undefined,
|
||||
name: '',
|
||||
remark: '',
|
||||
safety_line: 0 as number,
|
||||
@@ -174,6 +176,7 @@
|
||||
if (!props.data) return
|
||||
const numKeys = [
|
||||
'id',
|
||||
'dept_id',
|
||||
'safety_line',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
@@ -204,6 +207,8 @@
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const channelScope = useInjectedChannelDept()
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
@@ -212,11 +217,18 @@
|
||||
ElMessage.warning(t('page.form.msgWeightsMust100'))
|
||||
return
|
||||
}
|
||||
const submitData = withChannelDeptParams({
|
||||
...formData,
|
||||
dept_id:
|
||||
formData.dept_id ??
|
||||
props.data?.dept_id ??
|
||||
channelScope?.selectedDeptId.value
|
||||
})
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(submitData)
|
||||
ElMessage.success(t('page.form.msgAddSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(submitData)
|
||||
ElMessage.success(t('page.form.msgUpdateSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -181,6 +181,7 @@
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/play_record/index'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
@@ -212,22 +213,22 @@
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
const rules = reactive<FormRules>({
|
||||
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
|
||||
lottery_config_id: [{ required: true, message: '请选择彩金池配置', trigger: 'change' }],
|
||||
lottery_type: [{ required: true, message: '请选择抽奖类型', trigger: 'change' }],
|
||||
is_win: [{ required: true, message: '请选择是否中大奖', trigger: 'change' }],
|
||||
win_coin: [{ required: true, message: '赢取平台币必填', trigger: 'blur' }],
|
||||
const rules = computed<FormRules>(() => ({
|
||||
player_id: [{ required: true, message: t('page.form.rulePlayerRequired'), trigger: 'change' }],
|
||||
lottery_config_id: [{ required: true, message: t('page.form.ruleLotteryConfigRequired'), trigger: 'change' }],
|
||||
lottery_type: [{ required: true, message: t('page.form.ruleLotteryTypeRequired'), trigger: 'change' }],
|
||||
is_win: [{ required: true, message: t('page.form.ruleIsWinRequired'), trigger: 'change' }],
|
||||
win_coin: [{ required: true, message: t('page.form.ruleWinCoinRequired'), trigger: 'blur' }],
|
||||
rollArrayItems: [
|
||||
{
|
||||
validator: (_rule: any, value: (number | null)[], callback: (e?: Error) => void) => {
|
||||
if (!value || value.length !== 5) {
|
||||
callback(new Error('摇取点数必须为 5 个数'))
|
||||
callback(new Error(t('page.form.ruleRollArrayLength')))
|
||||
return
|
||||
}
|
||||
const ok = value.every((n) => n != null && n >= 1 && n <= 6)
|
||||
if (!ok) {
|
||||
callback(new Error('摇取点数必须填写 5 个数,每个 1~6'))
|
||||
callback(new Error(t('page.form.ruleRollArrayValues')))
|
||||
return
|
||||
}
|
||||
callback()
|
||||
@@ -235,8 +236,8 @@
|
||||
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 lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
@@ -272,9 +273,10 @@
|
||||
if (open) {
|
||||
initPage()
|
||||
try {
|
||||
const deptParams = getChannelDeptRequestParams()
|
||||
const [players, lotteryConfigs] = await Promise.all([
|
||||
api.getPlayerOptions(),
|
||||
api.getLotteryConfigOptions()
|
||||
api.getPlayerOptions(deptParams),
|
||||
api.getLotteryConfigOptions(deptParams)
|
||||
])
|
||||
playerOptions.value = Array.isArray(players) ? players : ((players as any)?.data ?? [])
|
||||
lotteryConfigOptions.value = Array.isArray(lotteryConfigs)
|
||||
@@ -391,10 +393,10 @@
|
||||
delete payload.rollArrayItems
|
||||
if (props.dialogType === 'add') {
|
||||
delete payload.id
|
||||
await api.save(payload)
|
||||
await api.save(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(payload)
|
||||
await api.update(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
@@ -262,10 +263,10 @@
|
||||
await formRef.value.validate()
|
||||
const payload = { ...formData }
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
await api.save(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(payload)
|
||||
await api.update(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/player/index'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
import WalletOperateDialog from './modules/WalletOperateDialog.vue'
|
||||
@@ -244,7 +245,7 @@
|
||||
const handleStatusChange = async (row: Record<string, any>, status: number) => {
|
||||
row._statusLoading = true
|
||||
try {
|
||||
await api.updateStatus({ id: row.id, status })
|
||||
await api.updateStatus(withChannelDeptParams({ id: row.id, status }))
|
||||
row.status = status
|
||||
} catch {
|
||||
refreshData()
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -157,12 +158,14 @@
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
await walletRecordApi.adminOperate({
|
||||
player_id: props.player.id,
|
||||
type: formData.type!,
|
||||
coin,
|
||||
remark: formData.remark?.trim() || undefined
|
||||
})
|
||||
await walletRecordApi.adminOperate(
|
||||
withChannelDeptParams({
|
||||
player_id: props.player.id,
|
||||
type: formData.type!,
|
||||
coin,
|
||||
remark: formData.remark?.trim() || undefined
|
||||
})
|
||||
)
|
||||
ElMessage.success(t('page.form.operateSuccess'))
|
||||
emit('success')
|
||||
handleClose()
|
||||
|
||||
@@ -35,7 +35,20 @@
|
||||
<sa-switch v-model="formData.status" />
|
||||
</el-form-item>
|
||||
<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
|
||||
v-else
|
||||
v-model="formData.admin_id"
|
||||
:placeholder="$t('page.form.placeholderAdmin')"
|
||||
clearable
|
||||
@@ -172,6 +185,8 @@
|
||||
import api from '../../../api/player/index'
|
||||
import lotteryConfigApi from '../../../api/lottery_pool_config/index'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import { isSuperAdminUser } from '@/utils/channelLayout'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
@@ -222,16 +237,18 @@
|
||||
|
||||
/** 新增时密码必填,编辑时选填 */
|
||||
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>({
|
||||
username: [{ required: true, message: '用户名必需填写', trigger: 'blur' }],
|
||||
name: [{ required: true, message: '昵称必需填写', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '手机号必需填写', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '状态必需填写', trigger: 'blur' }],
|
||||
coin: [{ required: true, message: '平台币必需填写', trigger: 'blur' }]
|
||||
})
|
||||
const rules = computed<FormRules>(() => ({
|
||||
username: [{ required: true, message: t('page.form.ruleUsernameRequired'), trigger: 'blur' }],
|
||||
name: [{ required: true, message: t('page.form.ruleNicknameRequired'), trigger: 'blur' }],
|
||||
phone: [{ required: true, message: t('page.form.rulePhoneRequired'), trigger: 'blur' }],
|
||||
status: [{ required: true, message: t('page.form.ruleStatusRequired'), trigger: 'blur' }],
|
||||
coin: [{ required: true, message: t('page.form.ruleCoinRequired'), trigger: 'blur' }]
|
||||
}))
|
||||
|
||||
const initialFormData = {
|
||||
id: null as number | null,
|
||||
@@ -262,6 +279,22 @@
|
||||
const systemUserOptions = ref<
|
||||
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)
|
||||
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
|
||||
@@ -269,9 +302,9 @@
|
||||
|
||||
function lotteryConfigTypeText(name: unknown): string {
|
||||
const n = String(name ?? '')
|
||||
if (n === 'default') return '默认'
|
||||
if (n === 'killScore') return '杀分'
|
||||
if (n === 'up') return '上分'
|
||||
if (n === 'default') return t('page.form.configTypeDefault')
|
||||
if (n === 'killScore') return t('page.form.configTypeKillScore')
|
||||
if (n === 'up') return t('page.form.configTypeUp')
|
||||
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() {
|
||||
systemUserOptionsLoading.value = true
|
||||
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 {
|
||||
systemUserOptions.value = []
|
||||
systemUserTreeOptions.value = []
|
||||
} finally {
|
||||
systemUserOptionsLoading.value = false
|
||||
}
|
||||
@@ -363,7 +427,7 @@
|
||||
async function loadLotteryConfigOptions() {
|
||||
lotteryConfigLoading.value = true
|
||||
try {
|
||||
lotteryConfigOptions.value = await api.getLotteryConfigOptions()
|
||||
lotteryConfigOptions.value = await api.getLotteryConfigOptions(getChannelDeptRequestParams())
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
} finally {
|
||||
@@ -376,6 +440,7 @@
|
||||
'status',
|
||||
'coin',
|
||||
'lottery_config_id',
|
||||
'admin_id',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
@@ -397,7 +462,7 @@
|
||||
;(formData as any)[key] = val != null ? Number(val) || null : null
|
||||
} else if (key === 'lottery_config_id' || key === 'admin_id') {
|
||||
const num = Number(val)
|
||||
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null
|
||||
;(formData as any)[key] = val != null && !Number.isNaN(num) && num > 0 ? num : null
|
||||
} else {
|
||||
;(formData as any)[key] = Number(val) || 0
|
||||
}
|
||||
@@ -429,10 +494,10 @@
|
||||
delete (payload as any).password
|
||||
}
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
await api.save(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(payload)
|
||||
await api.update(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/player_ticket_record/index'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
@@ -120,11 +121,11 @@
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
|
||||
use_coins: [{ required: true, message: '消耗硬币必需填写', trigger: 'blur' }],
|
||||
paid_ticket_count: [{ required: true, message: '购买抽奖次数必需填写', trigger: 'blur' }],
|
||||
free_ticket_count: [{ required: true, message: '赠送抽奖次数必需填写', trigger: 'blur' }],
|
||||
remark: [{ required: true, message: '备注必需填写', trigger: 'blur' }]
|
||||
player_id: [{ required: true, message: t('page.form.rulePlayerRequired'), trigger: 'change' }],
|
||||
use_coins: [{ required: true, message: t('page.form.ruleUseCoinsRequired'), trigger: 'blur' }],
|
||||
paid_ticket_count: [{ required: true, message: t('page.form.rulePaidDrawRequired'), trigger: 'blur' }],
|
||||
free_ticket_count: [{ required: true, message: t('page.form.ruleFreeDrawRequired'), trigger: 'blur' }],
|
||||
remark: [{ required: true, message: t('page.form.ruleRemarkRequired'), trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/** 玩家下拉选项(id、username) */
|
||||
@@ -168,7 +169,7 @@
|
||||
if (open) {
|
||||
initPage()
|
||||
try {
|
||||
const list = await api.getPlayerOptions()
|
||||
const list = await api.getPlayerOptions(getChannelDeptRequestParams())
|
||||
const arr = Array.isArray(list) ? list : (list as any)?.data
|
||||
playerOptions.value = Array.isArray(arr)
|
||||
? (arr as Array<{ id: number; username: string }>)
|
||||
@@ -232,10 +233,10 @@
|
||||
if (props.dialogType === 'add') {
|
||||
const rest = { ...formData } as Record<string, unknown>
|
||||
delete rest.id
|
||||
await api.save(rest)
|
||||
await api.save(withChannelDeptParams(rest))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
<!-- 表格头部 -->
|
||||
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
||||
<template #left>
|
||||
<span v-if="totalCoinChange !== null" class="table-summary-inline">
|
||||
{{ $t('page.toolbar.coinChangeSummary') }}:<strong :class="coinSummaryClass">{{
|
||||
formatMoney2(totalCoinChange)
|
||||
}}</strong>
|
||||
</span>
|
||||
<!-- <ElSpace wrap>-->
|
||||
<!-- <ElButton-->
|
||||
<!-- v-permission="'dice:player_wallet_record:index:save'"-->
|
||||
@@ -83,6 +88,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/player_wallet_record/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
@@ -97,15 +103,55 @@
|
||||
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 }
|
||||
if (Array.isArray(p.create_time) && p.create_time.length === 2) {
|
||||
p.create_time_min = p.create_time[0]
|
||||
p.create_time_max = p.create_time[1]
|
||||
}
|
||||
delete p.create_time
|
||||
const paramsRecord = searchParams as Record<string, unknown>
|
||||
WALLET_SEARCH_KEYS.forEach((key) => {
|
||||
delete paramsRecord[key]
|
||||
})
|
||||
Object.assign(searchParams, p)
|
||||
}
|
||||
|
||||
// 搜索处理:将 create_time 区间转为 create_time_min / create_time_max
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
applySearchParams(params)
|
||||
getData()
|
||||
}
|
||||
|
||||
@@ -169,8 +215,9 @@
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
apiFn: listApi,
|
||||
apiParams: { limit: 100 },
|
||||
excludeParams: ['create_time'],
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection', align: 'center' },
|
||||
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
|
||||
@@ -231,6 +278,25 @@
|
||||
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>
|
||||
|
||||
<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) */
|
||||
:deep(.wallet-record-type-tag) {
|
||||
transform: scale(0.8);
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/player_wallet_record/index'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
@@ -127,9 +128,9 @@
|
||||
})
|
||||
|
||||
const rules = reactive<FormRules>({
|
||||
player_id: [{ required: true, message: '请选择用户', trigger: 'change' }],
|
||||
coin: [{ required: true, message: '平台币变化必填', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }]
|
||||
player_id: [{ required: true, message: t('page.form.ruleUserRequired'), trigger: 'change' }],
|
||||
coin: [{ required: true, message: t('page.form.ruleCoinRequired'), trigger: 'blur' }],
|
||||
type: [{ required: true, message: t('page.form.ruleTypeRequired'), trigger: 'change' }]
|
||||
})
|
||||
|
||||
const initialFormData: {
|
||||
@@ -188,7 +189,7 @@
|
||||
if (open) {
|
||||
initPage()
|
||||
try {
|
||||
const list = await api.getPlayerOptions()
|
||||
const list = await api.getPlayerOptions(getChannelDeptRequestParams())
|
||||
playerOptions.value = Array.isArray(list) ? list : []
|
||||
} catch {
|
||||
playerOptions.value = []
|
||||
@@ -237,10 +238,10 @@
|
||||
calcWalletAfter()
|
||||
const payload = { ...formData }
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
await api.save(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(payload)
|
||||
await api.update(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -46,17 +46,25 @@
|
||||
</ElCard>
|
||||
|
||||
<WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" />
|
||||
<WeightTestDialog v-model="weightTestVisible" @success="refreshData" />
|
||||
<WeightTestDialog
|
||||
v-model="weightTestVisible"
|
||||
:channel-dept-id="channelDeptId"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useInjectedChannelDept } from '@/composables/useChannelDeptScope'
|
||||
import api from '../../api/reward/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import WeightRatioDialog from './modules/weight-ratio-dialog.vue'
|
||||
import WeightTestDialog from './modules/weight-test-dialog.vue'
|
||||
|
||||
const channelScope = useInjectedChannelDept()
|
||||
const channelDeptId = computed(() => channelScope?.selectedDeptId.value)
|
||||
|
||||
const currentDirection = ref<0 | 1>(0)
|
||||
const weightRatioVisible = ref(false)
|
||||
const weightTestVisible = ref(false)
|
||||
|
||||
@@ -262,6 +262,7 @@
|
||||
}
|
||||
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -447,7 +448,7 @@
|
||||
function loadData() {
|
||||
loading.value = true
|
||||
api
|
||||
.weightRatioListWithDirection()
|
||||
.weightRatioListWithDirection(getChannelDeptRequestParams())
|
||||
.then((res: any) => {
|
||||
grouped.value = parsePayload(res)
|
||||
})
|
||||
@@ -483,7 +484,7 @@
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.batchUpdateWeights(items, getChannelDeptRequestParams())
|
||||
.then(() => {
|
||||
ElMessage.success(t('page.weightShared.saveSuccess'))
|
||||
emit('success')
|
||||
|
||||
@@ -319,6 +319,7 @@
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
|
||||
function formatMoney2(val: unknown): string {
|
||||
if (val === '' || val === null || val === undefined) return '-'
|
||||
const n = typeof val === 'number' ? val : Number(val)
|
||||
@@ -482,7 +483,7 @@
|
||||
function loadData() {
|
||||
loading.value = true
|
||||
api
|
||||
.weightRatioListWithDirection()
|
||||
.weightRatioListWithDirection(getChannelDeptRequestParams())
|
||||
.then((res: any) => {
|
||||
grouped.value = parsePayload(res)
|
||||
})
|
||||
@@ -521,7 +522,7 @@
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.batchUpdateWeights(items, getChannelDeptRequestParams())
|
||||
.then(() => {
|
||||
ElMessage.success(t('page.weightShared.saveSuccess'))
|
||||
emit('success')
|
||||
|
||||
@@ -2,146 +2,170 @@
|
||||
<ElDialog
|
||||
v-model="visible"
|
||||
:title="$t('page.weightTest.title')"
|
||||
width="560px"
|
||||
width="920px"
|
||||
top="4vh"
|
||||
class="weight-test-dialog"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@close="onClose"
|
||||
>
|
||||
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip">
|
||||
<template #title>{{ $t('page.weightTest.alertTitle') }}</template>
|
||||
{{ $t('page.weightTest.alertBody') }}
|
||||
</ElAlert>
|
||||
<ElAlert type="warning" :closable="false" show-icon class="weight-test-tip chain-tip">
|
||||
{{ $t('page.weightTest.chainModeHint') }}
|
||||
</ElAlert>
|
||||
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip chain-tip">
|
||||
{{ $t('page.weightTest.killModeHint') }}
|
||||
</ElAlert>
|
||||
<ElForm :model="form" label-width="140px">
|
||||
<ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante" required>
|
||||
<ElInputNumber v-model="form.ante" :min="1" :step="1" style="width: 100%" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="$t('page.weightTest.labelKillModeEnabled')" prop="kill_mode_enabled">
|
||||
<ElSwitch v-model="form.kill_mode_enabled" />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="$t('page.weightTest.labelTestSafetyLine')" prop="test_safety_line">
|
||||
<ElInputNumber
|
||||
v-model="form.test_safety_line"
|
||||
:min="0"
|
||||
:step="100"
|
||||
:disabled="!form.kill_mode_enabled"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<div class="weight-test-dialog-body">
|
||||
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip compact-tip">
|
||||
<div class="tip-lines">
|
||||
<div>{{ $t('page.weightTest.alertBody') }}</div>
|
||||
<div>{{ $t('page.weightTest.chainModeHint') }}</div>
|
||||
<div>{{ $t('page.weightTest.killModeHint') }}</div>
|
||||
</div>
|
||||
</ElAlert>
|
||||
|
||||
<div class="section-title">{{ $t('page.weightTest.sectionPaid') }}</div>
|
||||
<ElFormItem
|
||||
:label="$t('page.weightTest.labelLotteryTypePaid')"
|
||||
prop="paid_lottery_config_id"
|
||||
>
|
||||
<ElSelect
|
||||
v-model="form.paid_lottery_config_id"
|
||||
:placeholder="$t('page.weightTest.placeholderPaidPool')"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in paidLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.paid_lottery_config_id == null">
|
||||
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
|
||||
<ElRow :gutter="12" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">{{
|
||||
$t('page.weightTest.tierFieldLabel', { tier: t })
|
||||
}}</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getPaidTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setPaidTier(t, $event)"
|
||||
<ElForm :model="form" label-width="108px" class="weight-test-form">
|
||||
<ElRow :gutter="16">
|
||||
<ElCol :span="8">
|
||||
<ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante_config_id" required>
|
||||
<ElSelect
|
||||
v-model="form.ante_config_id"
|
||||
:placeholder="$t('page.weightTest.placeholderAnte')"
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="syncAnteFromSelect"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in anteOptions"
|
||||
:key="item.id"
|
||||
:label="anteOptionLabel(item)"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="8">
|
||||
<ElFormItem :label="$t('page.weightTest.labelKillModeEnabled')" prop="kill_mode_enabled">
|
||||
<ElSwitch v-model="form.kill_mode_enabled" />
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="8">
|
||||
<ElFormItem :label="$t('page.weightTest.labelTestSafetyLine')" prop="test_safety_line">
|
||||
<ElInputNumber
|
||||
v-model="form.test_safety_line"
|
||||
:min="0"
|
||||
:step="100"
|
||||
:disabled="!form.kill_mode_enabled"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="paidTierSum > 100" class="tier-error">{{
|
||||
$t('page.weightTest.tierSumError', { sum: paidTierSum })
|
||||
}}</div>
|
||||
</template>
|
||||
<ElFormItem :label="$t('page.weightTest.labelCwCount')" prop="paid_s_count" required>
|
||||
<ElSelect
|
||||
v-model="form.paid_s_count"
|
||||
:placeholder="$t('page.weightTest.placeholderSelect')"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="$t('page.weightTest.labelCcwCount')" prop="paid_n_count" required>
|
||||
<ElSelect
|
||||
v-model="form.paid_n_count"
|
||||
:placeholder="$t('page.weightTest.placeholderSelect')"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
|
||||
<div class="section-title">{{ $t('page.weightTest.sectionFreeAfterPlayAgain') }}</div>
|
||||
<ElFormItem
|
||||
:label="$t('page.weightTest.labelLotteryTypeFree')"
|
||||
prop="free_lottery_config_id"
|
||||
>
|
||||
<ElSelect
|
||||
v-model="form.free_lottery_config_id"
|
||||
:placeholder="$t('page.weightTest.placeholderFreePool')"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in freeLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.free_lottery_config_id == null">
|
||||
<div class="tier-label">{{ $t('page.weightTest.tierProbHintFreeChain') }}</div>
|
||||
<ElRow :gutter="12" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">{{
|
||||
$t('page.weightTest.tierFieldLabel', { tier: t })
|
||||
}}</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getFreeTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setFreeTier(t, $event)"
|
||||
/>
|
||||
</div>
|
||||
<ElRow :gutter="20" class="section-row">
|
||||
<ElCol :span="12">
|
||||
<div class="section-title">{{ $t('page.weightTest.sectionPaid') }}</div>
|
||||
<ElFormItem :label="$t('page.weightTest.labelLotteryTypePaid')" prop="paid_lottery_config_id">
|
||||
<ElSelect
|
||||
v-model="form.paid_lottery_config_id"
|
||||
:placeholder="$t('page.weightTest.placeholderPaidPool')"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in paidLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.paid_lottery_config_id == null">
|
||||
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
|
||||
<ElRow :gutter="8" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">{{
|
||||
$t('page.weightTest.tierFieldLabel', { tier: t })
|
||||
}}</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getPaidTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setPaidTier(t, $event)"
|
||||
/>
|
||||
</div>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="paidTierSum > 100" class="tier-error">{{
|
||||
$t('page.weightTest.tierSumError', { sum: paidTierSum })
|
||||
}}</div>
|
||||
</template>
|
||||
<ElFormItem :label="$t('page.weightTest.labelCwCount')" prop="paid_s_count" required>
|
||||
<ElSelect
|
||||
v-model="form.paid_s_count"
|
||||
:placeholder="$t('page.weightTest.placeholderSelect')"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="$t('page.weightTest.labelCcwCount')" prop="paid_n_count" required>
|
||||
<ElSelect
|
||||
v-model="form.paid_n_count"
|
||||
:placeholder="$t('page.weightTest.placeholderSelect')"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption v-for="c in countOptions" :key="'n-' + c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
|
||||
<ElCol :span="12">
|
||||
<div class="section-title">{{ $t('page.weightTest.sectionFreeAfterPlayAgain') }}</div>
|
||||
<ElFormItem :label="$t('page.weightTest.labelLotteryTypeFree')" prop="free_lottery_config_id">
|
||||
<ElSelect
|
||||
v-model="form.free_lottery_config_id"
|
||||
:placeholder="$t('page.weightTest.placeholderFreePool')"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in freeLotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<template v-if="form.free_lottery_config_id == null">
|
||||
<div class="tier-label">{{ $t('page.weightTest.tierProbHintFreeChain') }}</div>
|
||||
<ElRow :gutter="8" class="tier-row">
|
||||
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
|
||||
<div class="tier-field">
|
||||
<label class="tier-field-label">{{
|
||||
$t('page.weightTest.tierFieldLabel', { tier: t })
|
||||
}}</label>
|
||||
<input
|
||||
type="number"
|
||||
:value="getFreeTier(t)"
|
||||
min="0"
|
||||
max="100"
|
||||
placeholder="0"
|
||||
class="tier-input"
|
||||
@input="setFreeTier(t, $event)"
|
||||
/>
|
||||
</div>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="freeTierSum > 100" class="tier-error">{{
|
||||
$t('page.weightTest.tierSumError', { sum: freeTierSum })
|
||||
}}</div>
|
||||
</template>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<div v-if="freeTierSum > 100" class="tier-error">{{
|
||||
$t('page.weightTest.tierSumError', { sum: freeTierSum })
|
||||
}}</div>
|
||||
</template>
|
||||
</ElForm>
|
||||
</ElForm>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<ElButton
|
||||
@@ -160,11 +184,23 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward/index'
|
||||
import anteConfigApi from '../../../api/ante_config/index'
|
||||
import lotteryPoolApi from '../../../api/lottery_pool_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
getChannelDeptRequestParams,
|
||||
useInjectedChannelDept,
|
||||
withChannelDeptParams
|
||||
} from '@/composables/useChannelDeptScope'
|
||||
|
||||
const props = defineProps<{
|
||||
/** 父页面渠道栏选中值(弹窗 teleport 后 inject 可能失效) */
|
||||
channelDeptId?: number
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
const channelScope = useInjectedChannelDept()
|
||||
|
||||
const countOptions = [0, 100, 500, 1000, 5000]
|
||||
const tierKeys = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
|
||||
@@ -172,8 +208,13 @@
|
||||
const visible = defineModel<boolean>({ default: false })
|
||||
const emit = defineEmits<{ (e: 'success'): void }>()
|
||||
|
||||
const anteOptions = ref<
|
||||
Array<{ id: number; name: string; title: string; mult: number; is_default: number }>
|
||||
>([])
|
||||
|
||||
const form = reactive({
|
||||
ante: 1,
|
||||
ante_config_id: undefined as number | undefined,
|
||||
paid_lottery_config_id: undefined as number | undefined,
|
||||
free_lottery_config_id: undefined as number | undefined,
|
||||
paid_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
|
||||
@@ -184,11 +225,9 @@
|
||||
test_safety_line: 5000
|
||||
})
|
||||
const lotteryOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
/** 付费抽奖券可选档位:name=default */
|
||||
const paidLotteryOptions = computed(() =>
|
||||
lotteryOptions.value.filter((r) => r.name === 'default')
|
||||
)
|
||||
/** 免费抽奖券可选档位:优先 name=killScore,若无则显示全部以便下拉有选项 */
|
||||
const freeLotteryOptions = computed(() => {
|
||||
const list = lotteryOptions.value.filter((r) => r.name === 'killScore')
|
||||
return list.length > 0 ? list : lotteryOptions.value
|
||||
@@ -230,9 +269,61 @@
|
||||
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() {
|
||||
try {
|
||||
const list = await lotteryPoolApi.getOptions()
|
||||
const list = await lotteryPoolApi.getOptions(resolveDeptParams())
|
||||
lotteryOptions.value = list.map((r: { id: number; name: string }) => ({
|
||||
id: r.id,
|
||||
name: r.name
|
||||
@@ -255,6 +346,7 @@
|
||||
function buildPayload() {
|
||||
const payload: Record<string, unknown> = {
|
||||
ante: form.ante,
|
||||
ante_config_id: form.ante_config_id,
|
||||
paid_s_count: form.paid_s_count,
|
||||
paid_n_count: form.paid_n_count,
|
||||
free_s_count: 0,
|
||||
@@ -277,6 +369,11 @@
|
||||
}
|
||||
|
||||
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) {
|
||||
ElMessage.warning(t('page.weightTest.warnAnte'))
|
||||
return false
|
||||
@@ -320,7 +417,12 @@
|
||||
if (!validateForm()) return
|
||||
running.value = true
|
||||
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'))
|
||||
visible.value = false
|
||||
emit('success')
|
||||
@@ -333,73 +435,122 @@
|
||||
|
||||
watch(visible, (v) => {
|
||||
if (v) {
|
||||
loadLotteryOptions()
|
||||
void loadAnteOptions()
|
||||
void loadLotteryOptions()
|
||||
} else {
|
||||
onClose()
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.channelDeptId ?? channelScope?.selectedDeptId.value,
|
||||
() => {
|
||||
if (visible.value) {
|
||||
void loadAnteOptions()
|
||||
void loadLotteryOptions()
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.weight-test-tip {
|
||||
margin-bottom: 16px;
|
||||
.weight-test-dialog-body {
|
||||
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 {
|
||||
font-size: 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
margin: 8px 0 12px;
|
||||
padding-bottom: 6px;
|
||||
margin: 0 0 10px;
|
||||
padding-bottom: 4px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.tier-label {
|
||||
font-size: 13px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.tier-row {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.tier-row {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.tier-field {
|
||||
margin-bottom: 12px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.tier-field-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-regular);
|
||||
margin-bottom: 4px;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 2px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.tier-input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
padding: 4px 8px;
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
color: var(--el-text-color-regular);
|
||||
background-color: var(--el-fill-color-blank);
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: var(--el-border-radius-base);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.tier-input:hover {
|
||||
border-color: var(--el-border-color-hover);
|
||||
}
|
||||
|
||||
.tier-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--el-color-primary);
|
||||
box-shadow: 0 0 0 2px var(--el-color-primary-light-7);
|
||||
}
|
||||
.tier-input::placeholder {
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
|
||||
.tier-error {
|
||||
font-size: 12px;
|
||||
color: var(--el-color-danger);
|
||||
margin-top: 4px;
|
||||
margin-bottom: 8px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
</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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="art-full-height reward-config-form">
|
||||
<ElCard shadow="never" class="form-card">
|
||||
<div class="reward-config-form flex-1 min-h-0 flex flex-col">
|
||||
<ElCard shadow="never" class="form-card flex-1 min-h-0 flex flex-col">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>{{ $t('page.toolbar.gameRewardConfig') }}</span>
|
||||
@@ -446,6 +446,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
DEFAULT_CHANNEL_ID,
|
||||
getChannelDeptRequestParams,
|
||||
useChannelDeptReload,
|
||||
useInjectedChannelDept
|
||||
} from '@/composables/useChannelDeptScope'
|
||||
import { useWindowSize } from '@vueuse/core'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -484,6 +490,21 @@
|
||||
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 loading = ref(false)
|
||||
const savingIndex = ref(false)
|
||||
@@ -506,15 +527,6 @@
|
||||
const REWARD_INDEX_MAX = 25
|
||||
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 表) */
|
||||
const indexRows = ref<IndexRow[]>([])
|
||||
/** 奖励索引 Tab:排除 tier=BIGWIN,仅显示 T1~T5 */
|
||||
@@ -524,6 +536,15 @@
|
||||
/** 原始 list 快照,用于重置 */
|
||||
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 {
|
||||
const n = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
|
||||
if (Number.isNaN(n)) return 0
|
||||
@@ -584,7 +605,7 @@
|
||||
}
|
||||
createRewardLoading.value = true
|
||||
try {
|
||||
const res: any = await api.createRewardReference()
|
||||
const res: any = await api.createRewardReference({ dept_id: filterDeptId.value as number })
|
||||
const data = res?.data ?? res
|
||||
let msg = t('page.configPage.createRefSuccessSimple')
|
||||
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() {
|
||||
loading.value = true
|
||||
return api
|
||||
.list({ limit: 200 })
|
||||
.then((res: any) => {
|
||||
const list = res?.data?.records ?? res?.records ?? res?.data ?? []
|
||||
const rows = Array.isArray(list)
|
||||
? list.map((r: Record<string, unknown>) => normalizeIndexRow(r))
|
||||
: []
|
||||
.list({ saiType: 'all', limit: 200, dept_id: filterDeptId.value })
|
||||
.then((res: unknown) => {
|
||||
const rows = extractIndexList(res).map((r) => normalizeIndexRow(r))
|
||||
indexRows.value = rows
|
||||
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 {
|
||||
return row.grid_number === 5 || row.grid_number === 30
|
||||
}
|
||||
@@ -805,7 +850,7 @@
|
||||
remark: r.remark
|
||||
})
|
||||
)
|
||||
await api.batchUpdate(indexPayload)
|
||||
await api.batchUpdate(indexPayload, { dept_id: filterDeptId.value })
|
||||
ElMessage.success(
|
||||
t('page.configPage.ruleGenSuccess', {
|
||||
cwT1: sc.cw.T1,
|
||||
@@ -854,7 +899,7 @@
|
||||
tier: r.tier,
|
||||
remark: r.remark
|
||||
}))
|
||||
await api.batchUpdate(indexPayload)
|
||||
await api.batchUpdate(indexPayload, { dept_id: filterDeptId.value })
|
||||
ElMessage.success(t('page.configPage.saveSuccess'))
|
||||
indexRowsSnapshot = indexRows.value.map((r) => ({ ...r }))
|
||||
} catch (e: any) {
|
||||
@@ -915,14 +960,14 @@
|
||||
tier: r.tier,
|
||||
remark: r.remark
|
||||
}))
|
||||
await api.batchUpdate(batchPayload)
|
||||
await api.batchUpdate(batchPayload, { dept_id: filterDeptId.value })
|
||||
const weightItems = rows.map((r) => ({
|
||||
grid_number: r.grid_number,
|
||||
weight: isBigwinWeightDisabled(r)
|
||||
? 10000
|
||||
: Math.max(0, Math.min(10000, Math.floor(r.weight)))
|
||||
}))
|
||||
await api.saveBigwinWeightsByGrid(weightItems)
|
||||
await api.saveBigwinWeightsByGrid(weightItems, { dept_id: filterDeptId.value })
|
||||
ElMessage.success(t('page.configPage.saveSuccess'))
|
||||
loadIndexList()
|
||||
} catch (e: any) {
|
||||
@@ -938,9 +983,6 @@
|
||||
ElMessage.info(t('page.configPage.resetBigwinReloaded'))
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadIndexList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
@@ -229,10 +230,10 @@
|
||||
delete payload.weight
|
||||
}
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
await api.save(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(payload)
|
||||
await api.update(withChannelDeptParams(payload))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -173,6 +173,7 @@
|
||||
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -360,7 +361,7 @@
|
||||
|
||||
function loadData() {
|
||||
api
|
||||
.weightRatioList()
|
||||
.weightRatioList(getChannelDeptRequestParams())
|
||||
.then((res: any) => {
|
||||
grouped.value = parseWeightRatioPayload(res)
|
||||
})
|
||||
@@ -393,7 +394,7 @@
|
||||
}
|
||||
submitting.value = true
|
||||
api
|
||||
.batchUpdateWeights(items)
|
||||
.batchUpdateWeights(items, getChannelDeptRequestParams())
|
||||
.then(() => {
|
||||
ElMessage.success(t('page.weightRatio.saveSuccess'))
|
||||
emit('success')
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
@@ -137,10 +138,10 @@
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(withChannelDeptParams(formData))
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<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>
|
||||
@@ -14,30 +12,22 @@
|
||||
</template>
|
||||
{{ $t('table.actions.add') }}
|
||||
</ElButton>
|
||||
<ElButton @click="toggleExpand" 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 v-permission="'core:dept:update'" @click="handleSyncConfigs" v-ripple>
|
||||
补齐渠道配置
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:default-expand-all="true"
|
||||
@sort-change="handleSortChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
@@ -48,20 +38,26 @@
|
||||
<SaButton
|
||||
v-permission="'core:dept:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
@click="openDeleteDialog(row)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
|
||||
<DeleteChannelDialog
|
||||
v-model="deleteDialogVisible"
|
||||
:dept-id="deleteDeptId"
|
||||
:dept-name="deleteDeptName"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -69,27 +65,26 @@
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '@/api/system/dept'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import TableSearch from './modules/table-search.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({
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
status: undefined
|
||||
})
|
||||
|
||||
// 搜索处理
|
||||
const deleteDialogVisible = ref(false)
|
||||
const deleteDeptId = ref<number | null>(null)
|
||||
const deleteDeptName = ref('')
|
||||
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
@@ -118,26 +113,20 @@
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const { dialogType, dialogVisible, dialogData, showDialog, deleteRow } = useSaiAdmin()
|
||||
const { dialogType, dialogVisible, dialogData, showDialog } = useSaiAdmin()
|
||||
|
||||
/**
|
||||
* 切换展开/收起所有菜单
|
||||
*/
|
||||
const toggleExpand = (): void => {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
processRows(data.value)
|
||||
}
|
||||
})
|
||||
const openDeleteDialog = (row: any) => {
|
||||
deleteDeptId.value = row.id
|
||||
deleteDeptName.value = row.name
|
||||
deleteDialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleSyncConfigs = async () => {
|
||||
try {
|
||||
await api.syncChannelConfigs()
|
||||
ElMessage.success('已为缺失配置的渠道补齐默认配置')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '补齐失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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>
|
||||
@@ -8,15 +8,6 @@
|
||||
@close="handleClose"
|
||||
>
|
||||
<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-input v-model="formData.name" :placeholder="$t('page.form.placeholderDeptName')" />
|
||||
</el-form-item>
|
||||
@@ -75,36 +66,21 @@
|
||||
const { t } = useI18n()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const optionData = reactive({
|
||||
treeData: <any[]>[]
|
||||
})
|
||||
|
||||
/**
|
||||
* 弹窗显示状态双向绑定
|
||||
*/
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
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' }],
|
||||
code: [{ required: true, message: t('page.form.ruleDeptCodeRequired'), trigger: 'blur' }]
|
||||
}))
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null,
|
||||
parent_id: null,
|
||||
level: '',
|
||||
parent_id: 0,
|
||||
level: '0',
|
||||
name: '',
|
||||
code: '',
|
||||
leader_id: null,
|
||||
@@ -113,14 +89,8 @@
|
||||
status: 1
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据
|
||||
*/
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/**
|
||||
* 监听弹窗打开,初始化表单数据
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
@@ -130,33 +100,14 @@
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
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) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
@@ -167,21 +118,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置表单
|
||||
*/
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
formData.parent_id = 0
|
||||
formData.level = '0'
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '@/api/system/role'
|
||||
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -155,11 +156,12 @@
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
const payload = withChannelDeptParams({ ...formData })
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
await api.save(payload)
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
await api.update(payload)
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
<template>
|
||||
<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="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">
|
||||
<div
|
||||
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>
|
||||
<b>部门列表</b>
|
||||
<b>{{ $t('page.ui.channelList') }}</b>
|
||||
</template>
|
||||
<ElScrollbar>
|
||||
<ElTree
|
||||
:data="treeData"
|
||||
:props="{ children: 'children', label: 'label' }"
|
||||
node-key="id"
|
||||
:current-node-key="currentChannelId"
|
||||
default-expand-all
|
||||
highlight-current
|
||||
@node-click="handleNodeClick"
|
||||
@@ -136,10 +144,19 @@
|
||||
import WorkDialog from './modules/work-dialog.vue'
|
||||
import api from '@/api/system/user'
|
||||
import deptApi from '@/api/system/dept'
|
||||
import { isSuperAdminUser } from '@/utils/channelLayout'
|
||||
|
||||
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 } =
|
||||
@@ -228,24 +245,79 @@
|
||||
const handleReset = () => {
|
||||
searchForm.value.dept_id = undefined
|
||||
resetSearchParams()
|
||||
if (isSuperAdminUser()) {
|
||||
currentChannelId.value = undefined
|
||||
} else {
|
||||
applyDefaultChannelSelection()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换部门
|
||||
* @param data
|
||||
*/
|
||||
const handleNodeClick = (data: any) => {
|
||||
const handleNodeClick = (data: ChannelTreeNode) => {
|
||||
currentChannelId.value = data.id
|
||||
searchParams.dept_id = data.id
|
||||
getData()
|
||||
}
|
||||
|
||||
/** 仅超管显示左侧渠道列表;渠道管理员固定本渠道,由后端过滤 */
|
||||
const showChannelSidebar = computed(() => isSuperAdminUser())
|
||||
|
||||
const normalizeChannelTree = (list: unknown[]): ChannelTreeNode[] => {
|
||||
if (!Array.isArray(list)) {
|
||||
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 = () => {
|
||||
deptApi.accessDept().then((data: any) => {
|
||||
treeData.value = data
|
||||
})
|
||||
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(() => {
|
||||
getDeptList()
|
||||
if (isSuperAdminUser()) {
|
||||
getDeptList()
|
||||
} else {
|
||||
applyDefaultChannelSelection()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -52,13 +52,14 @@
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item :label="$t('page.form.labelDept')" prop="dept_id">
|
||||
<el-tree-select
|
||||
v-model="formData.dept_id"
|
||||
:data="optionData.deptData"
|
||||
:render-after-expand="false"
|
||||
check-strictly
|
||||
clearable
|
||||
/>
|
||||
<el-select v-model="formData.dept_id" clearable filterable>
|
||||
<el-option
|
||||
v-for="item in optionData.deptData"
|
||||
:key="item.id"
|
||||
:label="item.label"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -206,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(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
@@ -214,26 +250,23 @@
|
||||
}
|
||||
}
|
||||
)
|
||||
// 初始化页面数据
|
||||
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
Object.assign(formData, initialFormData)
|
||||
// 部门数据
|
||||
const deptData = await deptApi.accessDept()
|
||||
optionData.deptData = deptData
|
||||
optionData.deptData = flattenDeptOptions(Array.isArray(deptData) ? deptData : [])
|
||||
// 角色数据
|
||||
const roleData = await roleApi.accessRole()
|
||||
optionData.roleList = roleData
|
||||
// 如果有数据,则填充数据
|
||||
if (props.data) {
|
||||
if (props.data?.id) {
|
||||
await nextTick()
|
||||
if (props.data.id) {
|
||||
let data = await api.read(props.data.id)
|
||||
const role = (data.roleList as any[])?.map((item: any) => item.id)
|
||||
data.role_ids = role
|
||||
data.password = ''
|
||||
initForm(data)
|
||||
}
|
||||
const data = await api.read(props.data.id)
|
||||
const role = (data.roleList as any[])?.map((item: any) => item.id)
|
||||
data.role_ids = role
|
||||
data.password = ''
|
||||
initForm(data)
|
||||
await loadRoleOptions()
|
||||
} else {
|
||||
await loadRoleOptions()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use support\think\Db;
|
||||
use app\api\logic\GameLogic;
|
||||
use app\api\logic\PlayStartLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\config\DiceConfig;
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
@@ -34,7 +35,12 @@ class GameController extends BaseController
|
||||
*/
|
||||
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');
|
||||
if (!is_string($lang) || $lang === '') {
|
||||
$lang = 'zh';
|
||||
@@ -43,15 +49,15 @@ class GameController extends BaseController
|
||||
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
|
||||
$data = [];
|
||||
foreach ($rows as $row) {
|
||||
$group = $row->group ?? '';
|
||||
$group = $row['group'] ?? '';
|
||||
if (!isset($data[$group])) {
|
||||
$data[$group] = [];
|
||||
}
|
||||
$title = $row->title;
|
||||
$value = $row->value;
|
||||
$title = $row['title'] ?? '';
|
||||
$value = $row['value'] ?? '';
|
||||
if ($isEn) {
|
||||
$titleEn = $row->title_en ?? '';
|
||||
$valueEn = $row->value_en ?? '';
|
||||
$titleEn = $row['title_en'] ?? '';
|
||||
$valueEn = $row['value_en'] ?? '';
|
||||
if ($titleEn !== '') {
|
||||
$title = $titleEn;
|
||||
}
|
||||
@@ -60,11 +66,11 @@ class GameController extends BaseController
|
||||
}
|
||||
}
|
||||
$data[$group][] = [
|
||||
'name' => $row->name,
|
||||
'name' => $row['name'] ?? '',
|
||||
'title' => $title,
|
||||
'value' => $value,
|
||||
'create_time' => $row->create_time,
|
||||
'update_time' => $row->update_time,
|
||||
'create_time' => $row['create_time'] ?? '',
|
||||
'update_time' => $row['update_time'] ?? '',
|
||||
];
|
||||
}
|
||||
return $this->success($data);
|
||||
@@ -107,7 +113,8 @@ class GameController extends BaseController
|
||||
*/
|
||||
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) {
|
||||
return (string) ($row['tier'] ?? '') !== 'BIGWIN';
|
||||
}));
|
||||
@@ -145,9 +152,9 @@ class GameController extends BaseController
|
||||
*/
|
||||
public function anteConfig(Request $request): Response
|
||||
{
|
||||
// 用于后续抽奖校验:在接口中实例化 model,后续逻辑可复用相同的数据读取方式。
|
||||
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -200,7 +207,8 @@ class GameController extends BaseController
|
||||
$rewardTier = array_key_exists('reward_tier', $data) ? (string) ($data['reward_tier'] ?? '') : '';
|
||||
$targetIndex = array_key_exists('target_index', $data) ? (int) ($data['target_index'] ?? 0) : 0;
|
||||
if ($rewardTier !== 'BIGWIN' && $targetIndex > 0) {
|
||||
$configRow = DiceRewardConfig::getCachedById($targetIndex);
|
||||
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
|
||||
$configRow = DiceRewardConfig::getCachedById($targetIndex, $configDeptId);
|
||||
if ($configRow !== null) {
|
||||
$uiText = '';
|
||||
$uiTextEn = '';
|
||||
@@ -273,4 +281,20 @@ class GameController extends BaseController
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,26 @@ return [
|
||||
'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed',
|
||||
'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted',
|
||||
'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',
|
||||
];
|
||||
|
||||
@@ -9,6 +9,28 @@ declare(strict_types=1);
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'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',
|
||||
'请携带 token' => 'Please provide token',
|
||||
'token 无效' => 'Invalid or expired token',
|
||||
|
||||
@@ -36,5 +36,27 @@ return [
|
||||
'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作',
|
||||
'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除',
|
||||
'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',
|
||||
];
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace app\api\logic;
|
||||
use app\api\cache\UserCache;
|
||||
use app\api\util\ApiLang;
|
||||
use app\api\service\LotteryService;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
@@ -64,6 +65,8 @@ class PlayStartLogic
|
||||
throw new ApiException('User not found');
|
||||
}
|
||||
|
||||
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
|
||||
|
||||
$coin = (float) $player->coin;
|
||||
if ($ante <= 0) {
|
||||
throw new ApiException('ante must be a positive integer');
|
||||
@@ -71,7 +74,7 @@ class PlayStartLogic
|
||||
|
||||
// 注数合规校验:ante 必须存在于 dice_ante_config.mult
|
||||
$anteConfigModel = new DiceAnteConfig();
|
||||
$exists = $anteConfigModel->where('mult', $ante)->count();
|
||||
$exists = $anteConfigModel->where('mult', $ante)->where('dept_id', $configDeptId)->count();
|
||||
if ($exists <= 0) {
|
||||
throw new ApiException('当前注数不合规,请选择正确的注数');
|
||||
}
|
||||
@@ -109,8 +112,8 @@ class PlayStartLogic
|
||||
}
|
||||
}
|
||||
|
||||
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
|
||||
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
|
||||
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->where('dept_id', $configDeptId)->find();
|
||||
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->where('dept_id', $configDeptId)->find();
|
||||
if (!$configType0) {
|
||||
throw new ApiException('Lottery pool config not found (name=default required)');
|
||||
}
|
||||
@@ -120,7 +123,7 @@ class PlayStartLogic
|
||||
|
||||
// 游玩前余额校验(按 T4 惩罚最大值兜底):
|
||||
// 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante
|
||||
$t4List = DiceRewardConfig::getCachedByTier('T4');
|
||||
$t4List = DiceRewardConfig::getCachedByTier('T4', $configDeptId);
|
||||
$t4MinRealEv = null;
|
||||
foreach ($t4List as $row) {
|
||||
$ev = $row['real_ev'] ?? null;
|
||||
@@ -155,7 +158,7 @@ class PlayStartLogic
|
||||
: $configType0;
|
||||
|
||||
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$rewardInstance = DiceReward::getCachedInstance($configDeptId);
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
$maxTierRetry = 10;
|
||||
$chosen = null;
|
||||
@@ -216,7 +219,7 @@ class PlayStartLogic
|
||||
$superWinCoin = 0.0;
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
} else {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
$doSuperWin = $alwaysSuperWin;
|
||||
if (!$doSuperWin) {
|
||||
@@ -639,9 +642,9 @@ class PlayStartLogic
|
||||
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
|
||||
* @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'] ?? [];
|
||||
$maxTierRetry = 10;
|
||||
$chosen = null;
|
||||
@@ -698,7 +701,7 @@ class PlayStartLogic
|
||||
$superWinCoin = 0.0;
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
} else {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
$doSuperWin = $alwaysSuperWin;
|
||||
if (!$doSuperWin) {
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace app\api\logic;
|
||||
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\api\cache\UserCache;
|
||||
use plugin\saiadmin\app\model\system\SystemDept;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
@@ -44,46 +43,8 @@ class UserLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 parent_id 向上遍历找到顶级部门(parent_id=0)
|
||||
*/
|
||||
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 是否属于该部门,同顶级部门下不重复创建玩家
|
||||
* 根据 agent_id 获取同渠道下的所有管理员 ID 列表
|
||||
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该渠道,同渠道下不重复创建玩家
|
||||
*
|
||||
* @param string $agentId 代理标识(sa_system_user.agent_id)
|
||||
* @return int[] 管理员 ID 列表,空数组表示未找到或无法解析
|
||||
@@ -103,16 +64,8 @@ class UserLogic
|
||||
return [(int) $admin->id];
|
||||
}
|
||||
$deptId = (int) $deptId;
|
||||
$topId = self::getTopDeptIdByParentId($deptId);
|
||||
if ($topId === null) {
|
||||
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);
|
||||
$adminIds = SystemUser::where('dept_id', $deptId)->column('id');
|
||||
return array_map('intval', $adminIds ?: [(int) $admin->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,6 +108,10 @@ class UserLogic
|
||||
$player->coin = $coin;
|
||||
if ($adminId !== null && $adminId > 0) {
|
||||
$player->admin_id = $adminId;
|
||||
$adminUser = SystemUser::find($adminId);
|
||||
if ($adminUser && !empty($adminUser->dept_id)) {
|
||||
$player->dept_id = $adminUser->dept_id;
|
||||
}
|
||||
}
|
||||
$player->save();
|
||||
}
|
||||
|
||||
20
server/app/dice/basic/DiceBaseLogic.php
Normal file
20
server/app/dice/basic/DiceBaseLogic.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use app\dice\model\play_record\DicePlayRecord;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\think\Db;
|
||||
|
||||
@@ -22,7 +23,7 @@ class DiceDashboardController extends BaseController
|
||||
* 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比)
|
||||
*/
|
||||
#[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'));
|
||||
$thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week'));
|
||||
@@ -30,11 +31,12 @@ class DiceDashboardController extends BaseController
|
||||
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
|
||||
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$filterDeptId = $request->input('dept_id');
|
||||
|
||||
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo, $filterDeptId);
|
||||
$playerThis = $playerQueryThis->count();
|
||||
$playerLast = $playerQueryLast->count();
|
||||
|
||||
@@ -44,8 +46,8 @@ class DiceDashboardController extends BaseController
|
||||
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
|
||||
->where('coin', '>', 0)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo, $filterDeptId);
|
||||
$chargeThis = $chargeQueryThis->sum('coin');
|
||||
$chargeLast = $chargeQueryLast->sum('coin');
|
||||
|
||||
@@ -53,15 +55,15 @@ class DiceDashboardController extends BaseController
|
||||
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo, $filterDeptId);
|
||||
$withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)'));
|
||||
$withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)'));
|
||||
|
||||
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo, $filterDeptId);
|
||||
$playThis = $playQueryThis->count();
|
||||
$playLast = $playQueryLast->count();
|
||||
|
||||
@@ -86,13 +88,11 @@ class DiceDashboardController extends BaseController
|
||||
* 近期玩家充值统计(近10天每日充值金额)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function rechargeChart(): Response
|
||||
public function rechargeChart(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
|
||||
$adminCondition = '';
|
||||
if ($allowedIds !== null) {
|
||||
if (empty($allowedIds)) {
|
||||
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
|
||||
if ($deptCondition === '__empty__') {
|
||||
$data = [];
|
||||
foreach (range(0, 9) as $n) {
|
||||
$data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0];
|
||||
@@ -102,9 +102,6 @@ class DiceDashboardController extends BaseController
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_date' => array_column($data, 'recharge_date'),
|
||||
]);
|
||||
}
|
||||
$idsStr = implode(',', array_map('intval', $allowedIds));
|
||||
$adminCondition = " AND w.admin_id IN ({$idsStr})";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
@@ -117,7 +114,7 @@ class DiceDashboardController extends BaseController
|
||||
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
|
||||
) d
|
||||
LEFT JOIN dice_player_wallet_record w
|
||||
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$adminCondition}
|
||||
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$deptCondition}
|
||||
GROUP BY d.date
|
||||
ORDER BY d.date ASC
|
||||
";
|
||||
@@ -132,13 +129,11 @@ class DiceDashboardController extends BaseController
|
||||
* 月度玩家充值汇总(当年1-12月每月充值金额)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function rechargeBarChart(): Response
|
||||
public function rechargeBarChart(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
|
||||
$adminCondition = '';
|
||||
if ($allowedIds !== null) {
|
||||
if (empty($allowedIds)) {
|
||||
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
|
||||
if ($deptCondition === '__empty__') {
|
||||
$data = [];
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0];
|
||||
@@ -147,9 +142,6 @@ class DiceDashboardController extends BaseController
|
||||
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
|
||||
'recharge_month' => array_column($data, 'recharge_month'),
|
||||
]);
|
||||
}
|
||||
$idsStr = implode(',', array_map('intval', $allowedIds));
|
||||
$adminCondition = " AND w.admin_id IN ({$idsStr})";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
@@ -163,7 +155,7 @@ class DiceDashboardController extends BaseController
|
||||
LEFT JOIN dice_player_wallet_record w
|
||||
ON YEAR(w.create_time) = YEAR(CURDATE())
|
||||
AND MONTH(w.create_time) = m.month_num
|
||||
AND w.type = 0 AND w.coin > 0 {$adminCondition}
|
||||
AND w.type = 0 AND w.coin > 0 {$deptCondition}
|
||||
GROUP BY m.month_num
|
||||
ORDER BY m.month_num ASC
|
||||
";
|
||||
@@ -179,7 +171,7 @@ class DiceDashboardController extends BaseController
|
||||
* 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function walletRecordList(): Response
|
||||
public function walletRecordList(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayerWalletRecord::with([
|
||||
@@ -190,7 +182,7 @@ class DiceDashboardController extends BaseController
|
||||
->where('type', 0)
|
||||
->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$rows = [];
|
||||
foreach ($list as $row) {
|
||||
@@ -209,13 +201,13 @@ class DiceDashboardController extends BaseController
|
||||
* 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count)
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function newPlayerList(): Response
|
||||
public function newPlayerList(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayer::field('username,coin,total_ticket_count,create_time')
|
||||
->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$rows = [];
|
||||
foreach ($list as $row) {
|
||||
@@ -234,7 +226,7 @@ class DiceDashboardController extends BaseController
|
||||
* 返回:玩家账号、中奖档位、赢取平台币、游玩时间
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function playRecordList(): Response
|
||||
public function playRecordList(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayRecord::with([
|
||||
@@ -246,7 +238,7 @@ class DiceDashboardController extends BaseController
|
||||
->field('id,player_id,reward_tier,win_coin,create_time')
|
||||
->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$tierLabels = $this->buildRewardTierLabels();
|
||||
$rows = [];
|
||||
@@ -290,4 +282,23 @@ class DiceDashboardController extends BaseController
|
||||
}
|
||||
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 '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\ante_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\ante_config\DiceAnteConfigLogic;
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
use app\dice\validate\ante_config\DiceAnteConfigValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
@@ -34,10 +36,32 @@ class DiceAnteConfigController extends BaseController
|
||||
['is_default', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
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')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
@@ -52,6 +76,7 @@ class DiceAnteConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
return $result ? $this->success('add success') : $this->fail('add failed');
|
||||
}
|
||||
@@ -60,8 +85,19 @@ class DiceAnteConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\config\DiceConfigLogic;
|
||||
use app\dice\validate\config\DiceConfigValidate;
|
||||
@@ -42,6 +43,7 @@ class DiceConfigController extends BaseController
|
||||
['title', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -74,6 +76,7 @@ class DiceConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -91,8 +94,20 @@ class DiceConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$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) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\game;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\game\DiceGameLogic;
|
||||
use app\dice\validate\game\DiceGameValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
@@ -33,6 +34,7 @@ class DiceGameController extends BaseController
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -54,6 +56,7 @@ class DiceGameController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if (!$result) {
|
||||
return $this->fail('add failed');
|
||||
@@ -65,8 +68,19 @@ class DiceGameController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$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) {
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace app\dice\controller\lottery_pool_config;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
|
||||
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
|
||||
@@ -37,9 +38,10 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
public function getOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
$query = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
|
||||
->order('id', 'asc');
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return [
|
||||
'id' => (int) $item['id'],
|
||||
@@ -67,6 +69,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
['type', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -99,6 +102,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -116,8 +120,19 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$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) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
@@ -152,7 +167,8 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')]
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -163,7 +179,12 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
public function updateCurrentPool(Request $request): Response
|
||||
{
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -173,7 +194,8 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')]
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DicePlayRecordController extends BaseController
|
||||
['direction', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'diceLotteryPoolConfig',
|
||||
@@ -78,7 +78,7 @@ class DicePlayRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -92,9 +92,15 @@ class DicePlayRecordController extends BaseController
|
||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||
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) {
|
||||
return ['id' => $item['id'], 'name' => $item['name'] ?? ''];
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -112,8 +118,7 @@ class DicePlayRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -130,6 +135,7 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$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');
|
||||
@@ -148,6 +154,13 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\play_record_test;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
|
||||
use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
|
||||
@@ -50,6 +51,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
['roll_number', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
|
||||
// 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和)
|
||||
@@ -92,6 +94,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
$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');
|
||||
@@ -110,6 +113,13 @@ class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace app\dice\controller\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
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\basic\BaseController;
|
||||
use app\dice\logic\player\DicePlayerLogic;
|
||||
@@ -42,7 +43,13 @@ class DicePlayerController extends BaseController
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
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) {
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
@@ -57,12 +64,17 @@ class DicePlayerController extends BaseController
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getSystemUserOptions(Request $request): Response
|
||||
{
|
||||
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
|
||||
$deptList = $this->adminInfo['deptList'] ?? [];
|
||||
if (!empty($deptList)) {
|
||||
$query->auth($deptList);
|
||||
$query = SystemUser::field('id,username,realname,dept_id')->where('status', 1)->order('id', 'asc');
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
|
||||
$request->input('dept_id'),
|
||||
$request->all()
|
||||
);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null) {
|
||||
if ($allowedIds === []) {
|
||||
return $this->success([]);
|
||||
}
|
||||
$query->whereIn('id', $allowedIds);
|
||||
}
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
@@ -71,12 +83,89 @@ class DicePlayerController extends BaseController
|
||||
'id' => (int) $item['id'],
|
||||
'username' => (string) ($item['username'] ?? ''),
|
||||
'realname' => (string) ($item['realname'] ?? ''),
|
||||
'dept_id' => isset($item['dept_id']) ? (int) $item['dept_id'] : null,
|
||||
'label' => $label ?: (string) $item['id'],
|
||||
];
|
||||
})->toArray();
|
||||
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
|
||||
@@ -94,7 +183,7 @@ class DicePlayerController extends BaseController
|
||||
['lottery_config_id', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
@@ -113,8 +202,7 @@ class DicePlayerController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -130,20 +218,32 @@ class DicePlayerController extends BaseController
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
// 类型转化
|
||||
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
||||
$data['admin_id'] = (int) $this->adminInfo['id'];
|
||||
}
|
||||
$result = $this->logic->add($data);
|
||||
if ($result && isset($result['id'])) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($result['id']);
|
||||
$player = DicePlayer::find($result['id']);
|
||||
AdminScopeHelper::prepareBusinessSaveData(
|
||||
$data,
|
||||
$this->adminInfo ?? null,
|
||||
$request->input('dept_id'),
|
||||
$data
|
||||
);
|
||||
$this->validate('save', $data);
|
||||
try {
|
||||
$result = $this->logic->add($data);
|
||||
} catch (\Throwable $e) {
|
||||
if (self::isDeptUsernameDuplicateException($e)) {
|
||||
return $this->fail('PLAYER_USERNAME_DEPT_UNIQUE');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
$playerId = is_array($result) ? ($result['id'] ?? null) : $result;
|
||||
if ($playerId) {
|
||||
UserCache::deleteUser($playerId);
|
||||
$player = DicePlayer::find($playerId);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('add success');
|
||||
return $this->success('ADD_SUCCESS');
|
||||
}
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
@@ -157,14 +257,16 @@ class DicePlayerController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
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);
|
||||
if ($result) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
@@ -173,7 +275,7 @@ class DicePlayerController extends BaseController
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('update success');
|
||||
return $this->success('UPDATE_SUCCESS');
|
||||
}
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
@@ -196,8 +298,7 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
@@ -227,8 +328,7 @@ class DicePlayerController extends BaseController
|
||||
if (!$player) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
if ((int) ($player->status ?? 1) === 0) {
|
||||
@@ -281,13 +381,12 @@ class DicePlayerController extends BaseController
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null) {
|
||||
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id');
|
||||
$deptId = AdminScopeHelper::getDeptId($this->adminInfo ?? null);
|
||||
if ($deptId !== null) {
|
||||
$models = $this->logic->model->whereIn('id', $ids)->column('dept_id', 'id');
|
||||
$validIds = [];
|
||||
foreach ($ids as $id) {
|
||||
$adminId = (int) ($models[$id] ?? 0);
|
||||
if (in_array($adminId, $allowedIds, true)) {
|
||||
if (AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $models[$id] ?? null)) {
|
||||
$validIds[] = $id;
|
||||
}
|
||||
}
|
||||
@@ -311,4 +410,17 @@ class DicePlayerController extends BaseController
|
||||
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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
]);
|
||||
@@ -70,7 +70,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -91,8 +91,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -109,6 +108,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$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');
|
||||
@@ -127,6 +127,13 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -47,13 +47,18 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
['create_time_min', ''],
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$deptId = $request->input('dept_id');
|
||||
$totalCoinChange = $this->logic->sumCoinBySearch($where, $this->adminInfo ?? null, $deptId);
|
||||
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $deptId);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'operator',
|
||||
]);
|
||||
|
||||
$data = $this->logic->getList($query);
|
||||
$data['total_coin_change'] = $totalCoinChange;
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -66,7 +71,7 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -87,12 +92,11 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
if ($playerId === null || $playerId === '') {
|
||||
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) {
|
||||
return $this->fail('Player not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||
@@ -111,8 +115,7 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -166,12 +169,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
return $this->fail('please login first');
|
||||
}
|
||||
|
||||
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
|
||||
if ($player) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
$player = DicePlayer::field('dept_id')->where('id', $playerId)->find();
|
||||
if ($player && !AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -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
|
||||
@@ -192,6 +210,13 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
@@ -42,11 +43,18 @@ class DiceRewardController extends BaseController
|
||||
$orderType = $request->input('orderType', 'asc');
|
||||
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListWithConfig($direction, [
|
||||
'tier' => $tier,
|
||||
'orderField' => $orderField,
|
||||
'orderType' => $orderType,
|
||||
], $page, $limit);
|
||||
$data = $logic->getListWithConfig(
|
||||
$direction,
|
||||
[
|
||||
'tier' => $tier,
|
||||
'orderField' => $orderField,
|
||||
'orderType' => $orderType,
|
||||
],
|
||||
$page,
|
||||
$limit,
|
||||
$this->adminInfo ?? null,
|
||||
$request->input('dept_id')
|
||||
);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -61,8 +69,10 @@ class DiceRewardController extends BaseController
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
$direction = DiceReward::DIRECTION_CLOCKWISE;
|
||||
}
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierForDirection($direction);
|
||||
$data = $logic->getListGroupedByTierForDirection($direction, $deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -74,9 +84,10 @@ class DiceRewardController extends BaseController
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function weightRatioListWithDirection(Request $request): Response
|
||||
{
|
||||
DiceReward::refreshCache();
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierWithDirection();
|
||||
$data = $logic->getListGroupedByTierWithDirection($deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -103,11 +114,14 @@ class DiceRewardController extends BaseController
|
||||
'chain_free_mode' => $post['chain_free_mode'] ?? null,
|
||||
'kill_mode_enabled' => $post['kill_mode_enabled'] ?? 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;
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $post);
|
||||
try {
|
||||
$logic = new DiceRewardConfigRecordLogic();
|
||||
$recordId = $logic->createWeightTestRecord($params, $adminId);
|
||||
$recordId = $logic->createWeightTestRecord($params, $adminId, $this->adminInfo ?? null, $requestDeptId);
|
||||
return $this->success(['record_id' => $recordId]);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -167,8 +181,9 @@ class DiceRewardController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeights($items);
|
||||
$logic->batchUpdateWeights($items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -191,8 +206,9 @@ class DiceRewardController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items);
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\reward_config\DiceRewardConfigLogic;
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\validate\reward_config\DiceRewardConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
@@ -46,7 +48,9 @@ class DiceRewardConfigController extends BaseController
|
||||
['tier', ''],
|
||||
]);
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -78,6 +82,7 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -95,8 +100,19 @@ class DiceRewardConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$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) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
@@ -123,7 +139,9 @@ class DiceRewardConfigController extends BaseController
|
||||
foreach ($items as $item) {
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -139,7 +157,7 @@ class DiceRewardConfigController extends BaseController
|
||||
if (empty($ids)) {
|
||||
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) {
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
@@ -155,8 +173,10 @@ class DiceRewardConfigController extends BaseController
|
||||
#[Permission('奖励配置列表', 'dice:reward_config:index:index')]
|
||||
public function weightRatioList(Request $request): Response
|
||||
{
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$data = $rewardLogic->getListGroupedByTierWithDirection();
|
||||
$data = $rewardLogic->getListGroupedByTierWithDirection($deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -174,8 +194,9 @@ class DiceRewardConfigController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$rewardLogic->batchUpdateWeights($items);
|
||||
$rewardLogic->batchUpdateWeights($items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -199,7 +220,8 @@ class DiceRewardConfigController extends BaseController
|
||||
if ($err !== null) {
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -214,7 +236,8 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
try {
|
||||
$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');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace app\dice\controller\reward_config_record;
|
||||
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
@@ -42,6 +43,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
['ante', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -96,6 +98,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$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');
|
||||
@@ -114,6 +117,13 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -3,21 +3,75 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\dice\helper;
|
||||
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
|
||||
/**
|
||||
* 管理员数据范围辅助类
|
||||
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
|
||||
* 大富翁数据范围:按渠道 dept_id 隔离(关联 sa_system_dept)
|
||||
*/
|
||||
class AdminScopeHelper
|
||||
{
|
||||
/** 超管查看默认配置模板 */
|
||||
public const DEFAULT_TEMPLATE_DEPT = 0;
|
||||
|
||||
/**
|
||||
* 获取当前管理员可访问的 admin_id 列表
|
||||
* 超级管理员(id=1) 返回 null 表示不限制
|
||||
* 普通管理员返回其本人及部门下属管理员的 id 列表
|
||||
* 当前管理员所属渠道 ID;超级管理员(id=1) 返回 null 表示不限制
|
||||
*/
|
||||
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=不限制(超级管理员),否则为可访问的 admin_id 数组
|
||||
* @return int[]|null null=不限制
|
||||
*/
|
||||
public static function getAllowedAdminIds(?array $adminInfo): ?array
|
||||
{
|
||||
@@ -28,33 +82,285 @@ class AdminScopeHelper
|
||||
if ($adminId <= 1) {
|
||||
return null;
|
||||
}
|
||||
$deptList = $adminInfo['deptList'] ?? [];
|
||||
if (empty($deptList) || !isset($deptList['id'])) {
|
||||
$deptId = self::getDeptId($adminInfo);
|
||||
if ($deptId === null) {
|
||||
return null;
|
||||
}
|
||||
if ($deptId <= 0) {
|
||||
return [$adminId];
|
||||
}
|
||||
$query = SystemUser::field('id');
|
||||
$query->auth($deptList);
|
||||
$ids = $query->column('id');
|
||||
return array_map('intval', $ids ?: []);
|
||||
$ids = SystemUser::where('dept_id', $deptId)->column('id');
|
||||
return array_map('intval', $ids ?: [$adminId]);
|
||||
}
|
||||
|
||||
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 范围过滤
|
||||
*
|
||||
* @param object $query ThinkORM 查询对象
|
||||
* @param array|null $adminInfo 当前登录管理员信息
|
||||
* @return void
|
||||
* 业务数据新增:按渠道写入 dept_id(玩家、记录等)
|
||||
* 优先级:已有 dept_id → 所属管理员 admin_id → 请求渠道 → 当前登录人渠道
|
||||
*/
|
||||
public static function applyAdminScope($query, ?array $adminInfo): void
|
||||
public static function fillBusinessDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
|
||||
{
|
||||
$allowedIds = self::getAllowedAdminIds($adminInfo);
|
||||
if ($allowedIds === null) {
|
||||
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
|
||||
$data['dept_id'] = (int) $data['dept_id'];
|
||||
if ($data['dept_id'] > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (empty($allowedIds)) {
|
||||
|
||||
$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_id(null 视为默认模板 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');
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
139
server/app/dice/helper/ConfigScopeEditHelper.php
Normal file
139
server/app/dice/helper/ConfigScopeEditHelper.php
Normal 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 渠道 ID(0=默认模板)
|
||||
* @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:业务 id(0~25 等)+ 渠道更新
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,15 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\ante_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\helper\ConfigScopeEditHelper;
|
||||
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()
|
||||
{
|
||||
@@ -23,21 +25,32 @@ class DiceAnteConfigLogic extends BaseLogic
|
||||
{
|
||||
return $this->transaction(function () use ($data) {
|
||||
$this->normalizeDefaultField($data);
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId(null, $data['dept_id'] ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
|
||||
if ((int) ($data['is_default'] ?? 0) === 1) {
|
||||
$this->clearOtherDefaults();
|
||||
$this->clearOtherDefaults(null, $deptId);
|
||||
}
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
|
||||
if ($excludeId !== null && $excludeId > 0) {
|
||||
$query->where('id', '<>', $excludeId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\helper\ConfigScopeEditHelper;
|
||||
use plugin\saiadmin\basic\eloquent\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,33 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\game;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\helper\ConfigScopeEditHelper;
|
||||
use plugin\saiadmin\basic\eloquent\BaseLogic;
|
||||
use app\dice\model\game\DiceGame;
|
||||
|
||||
/**
|
||||
* 游戏管理逻辑层
|
||||
*/
|
||||
class DiceGameLogic extends BaseLogic
|
||||
class DiceGameLogic extends DiceBaseLogic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 plugin\saiadmin\basic\think\BaseLogic;
|
||||
use app\dice\basic\DiceBaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
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 创建 */
|
||||
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
|
||||
@@ -30,19 +32,55 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
|
||||
$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 的只读展示
|
||||
* profit_amount 每次从 DB 实时读取;t1_weight~t5_weight 来自 type=1(杀分权重,不可在弹窗内修改)
|
||||
*
|
||||
* @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) {
|
||||
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();
|
||||
$profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0);
|
||||
$pool = [
|
||||
@@ -66,9 +104,9 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
|
||||
*
|
||||
* @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'];
|
||||
if (!array_key_exists('safety_line', $data) && !array_key_exists('kill_enabled', $data)) {
|
||||
return;
|
||||
@@ -83,17 +121,21 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
|
||||
if ($update === []) {
|
||||
return;
|
||||
}
|
||||
DiceLotteryPoolConfig::where('id', $id)->update($update);
|
||||
$query = DiceLotteryPoolConfig::where('id', $id);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
|
||||
$query->update($update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置当前彩金池的玩家累计盈利:将 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'];
|
||||
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;
|
||||
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\utils\Helper;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\utils\Helper;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use app\dice\basic\DiceBaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
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 统一) */
|
||||
private const PASSWORD_SALT = 'dice_player_salt_2024';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\utils\Helper;
|
||||
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
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按与列表相同的筛选条件汇总平台币变化(不含 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;
|
||||
$playerDeptId = ($player->dept_id ?? null) ? (int) $player->dept_id : null;
|
||||
$record = [
|
||||
'player_id' => $playerId,
|
||||
'admin_id' => $playerAdminId,
|
||||
'dept_id' => $playerDeptId,
|
||||
'coin' => $type === 3 ? $coin : -$coin,
|
||||
'type' => $type,
|
||||
'wallet_before' => $walletBefore,
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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_config\DiceRewardConfig;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
@@ -29,8 +31,14 @@ class DiceRewardLogic
|
||||
* @param int $limit
|
||||
* @return array{total: int, per_page: int, current_page: int, data: array}
|
||||
*/
|
||||
public function getListWithConfig(int $direction, array $where, int $page = 1, int $limit = 10): array
|
||||
{
|
||||
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']) : '';
|
||||
$orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier';
|
||||
$orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc';
|
||||
@@ -41,6 +49,10 @@ class DiceRewardLogic
|
||||
->order($orderField, $orderType)
|
||||
->order('r.end_index', 'asc');
|
||||
|
||||
if ($adminInfo !== null) {
|
||||
AdminScopeHelper::applyConfigScope($query, $adminInfo, $requestDeptId, 'r.dept_id');
|
||||
}
|
||||
|
||||
if ($tier !== '') {
|
||||
$query->where('r.tier', $tier);
|
||||
}
|
||||
@@ -74,7 +86,7 @@ class DiceRewardLogic
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @param array<int, array{id: int, weight: int}> $items id 为 end_index(DiceRewardConfig.id)
|
||||
*/
|
||||
public function batchUpdateWeightsByDirection(int $direction, array $items): void
|
||||
public function batchUpdateWeightsByDirection(int $direction, array $items, ?int $deptId = null): void
|
||||
{
|
||||
if (empty($items)) {
|
||||
return;
|
||||
@@ -90,23 +102,36 @@ class DiceRewardLogic
|
||||
}
|
||||
$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 === '') {
|
||||
throw new ApiException(\app\api\util\ApiLang::translateParams('配置ID %s 不存在或档位为空', [$id]));
|
||||
}
|
||||
$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) {
|
||||
$m = new DiceReward();
|
||||
$m->tier = $tier;
|
||||
$m->direction = $direction;
|
||||
$m->end_index = $id;
|
||||
$m->weight = $weight;
|
||||
if ($deptId !== null && $deptId > 0) {
|
||||
$m->dept_id = $deptId;
|
||||
}
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
DiceReward::refreshCache($deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,11 +139,11 @@ class DiceRewardLogic
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @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'] ?? [];
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$rewardInstance = DiceReward::getCachedInstance($deptId);
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
|
||||
$result = [];
|
||||
@@ -153,9 +178,9 @@ class DiceRewardLogic
|
||||
*
|
||||
* @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'] ?? [];
|
||||
|
||||
$result = [];
|
||||
@@ -185,7 +210,7 @@ class DiceRewardLogic
|
||||
* @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键,weight 为 1-10000
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function batchUpdateWeights(array $items): void
|
||||
public function batchUpdateWeights(array $items, ?int $deptId = null): void
|
||||
{
|
||||
if (empty($items)) {
|
||||
return;
|
||||
@@ -203,13 +228,24 @@ class DiceRewardLogic
|
||||
}
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
$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) {
|
||||
$model->weight = $weight;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
DiceReward::refreshCache($deptId);
|
||||
}
|
||||
|
||||
/** BIGWIN 权重范围:0=0% 中奖,10000=100% 中奖;grid_number=5/30 固定 100% 不可改 */
|
||||
@@ -219,9 +255,9 @@ class DiceRewardLogic
|
||||
* 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示)
|
||||
* 若 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] ?? [];
|
||||
foreach ($rows as $row) {
|
||||
if ((int) ($row['grid_number'] ?? 0) === $gridNumber) {
|
||||
@@ -235,21 +271,24 @@ class DiceRewardLogic
|
||||
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新);0=0% 中奖,10000=100% 中奖
|
||||
* 表 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));
|
||||
$config = DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if ($deptId === null) {
|
||||
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
|
||||
}
|
||||
$configQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
|
||||
$config = $configQuery->find();
|
||||
if (! $config) {
|
||||
return;
|
||||
}
|
||||
$configArr = $config->toArray();
|
||||
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
|
||||
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
|
||||
$row = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
$rowQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($rowQuery, $deptId);
|
||||
$row = $rowQuery->find();
|
||||
if ($row) {
|
||||
$row->tier = 'BIGWIN';
|
||||
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
@@ -272,10 +311,13 @@ class DiceRewardLogic
|
||||
$m->remark = (string) ($configArr['remark'] ?? '');
|
||||
$m->type = $configArr['type'] ?? null;
|
||||
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
if (!AdminScopeHelper::isTemplateDeptId($deptId)) {
|
||||
$m->dept_id = $deptId;
|
||||
}
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
DiceReward::refreshCache($deptId);
|
||||
}
|
||||
|
||||
/** 盘面格数(用于顺时针/逆时针计算 end_index) */
|
||||
@@ -309,9 +351,19 @@ class DiceRewardLogic
|
||||
* @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int}
|
||||
* @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)) {
|
||||
throw new ApiException('Reward config is empty, please maintain dice_reward_config first');
|
||||
}
|
||||
@@ -326,8 +378,12 @@ class DiceRewardLogic
|
||||
}
|
||||
|
||||
$table = (new DiceReward())->getTable();
|
||||
Db::execute('DELETE FROM `' . $table . '`');
|
||||
DiceReward::refreshCache();
|
||||
if ($deptId === null) {
|
||||
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 时取模结果找不到
|
||||
$gridToPosition = [];
|
||||
@@ -379,7 +435,13 @@ class DiceRewardLogic
|
||||
'remark' => $configCw['remark'] ?? '',
|
||||
'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) {
|
||||
DiceReward::where('id', $existing->id)->update($payloadCw);
|
||||
$updatedCw++;
|
||||
@@ -395,6 +457,9 @@ class DiceRewardLogic
|
||||
$m->real_ev = $configCw['real_ev'] ?? null;
|
||||
$m->remark = $configCw['remark'] ?? '';
|
||||
$m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0;
|
||||
if ($deptId !== null) {
|
||||
$m->dept_id = $deptId;
|
||||
}
|
||||
$m->save();
|
||||
$createdCw++;
|
||||
}
|
||||
@@ -419,7 +484,13 @@ class DiceRewardLogic
|
||||
'remark' => $configCcw['remark'] ?? '',
|
||||
'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) {
|
||||
DiceReward::where('id', $existing->id)->update($payloadCcw);
|
||||
$updatedCcw++;
|
||||
@@ -435,6 +506,9 @@ class DiceRewardLogic
|
||||
$m->real_ev = $configCcw['real_ev'] ?? null;
|
||||
$m->remark = $configCcw['remark'] ?? '';
|
||||
$m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0;
|
||||
if ($deptId !== null) {
|
||||
$m->dept_id = $deptId;
|
||||
}
|
||||
$m->save();
|
||||
$createdCcw++;
|
||||
}
|
||||
@@ -442,7 +516,7 @@ class DiceRewardLogic
|
||||
}
|
||||
}
|
||||
|
||||
DiceReward::refreshCache();
|
||||
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
|
||||
return [
|
||||
'created_clockwise' => $createdCw,
|
||||
'created_counterclockwise' => $createdCcw,
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use app\dice\basic\DiceBaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use support\Log;
|
||||
@@ -19,7 +21,7 @@ use support\Log;
|
||||
* 奖励配置逻辑层(DiceRewardConfig)
|
||||
* weight 1-10000,各档位权重和不限制
|
||||
*/
|
||||
class DiceRewardConfigLogic extends BaseLogic
|
||||
class DiceRewardConfigLogic extends DiceBaseLogic
|
||||
{
|
||||
/** weight 取值范围 */
|
||||
private const WEIGHT_MIN = 1;
|
||||
@@ -36,18 +38,23 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
$result = parent::add($data);
|
||||
DiceRewardConfig::refreshCache();
|
||||
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
|
||||
DiceRewardConfig::refreshCache($deptId);
|
||||
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);
|
||||
DiceRewardConfig::refreshCache();
|
||||
return $result;
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId(
|
||||
$adminInfo,
|
||||
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(不含 weight,BIGWIN 权重单独接口)
|
||||
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
|
||||
* @param int $deptId 渠道 ID(0=默认模板)
|
||||
*/
|
||||
public function batchUpdate(array $items): void
|
||||
public function batchUpdate(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
|
||||
{
|
||||
foreach ($items as $row) {
|
||||
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
|
||||
@@ -167,10 +175,18 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
if (! empty($data)) {
|
||||
parent::edit($id, $data);
|
||||
$this->updateByBusinessIdAndDept($id, $deptId, $data);
|
||||
}
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::refreshCache($deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按业务 id(0~25)与渠道更新单条配置
|
||||
*/
|
||||
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)
|
||||
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
|
||||
* @param int $deptId 渠道 ID(0=默认模板)
|
||||
*/
|
||||
public function batchUpdateBigwinWeight(array $items): void
|
||||
public function batchUpdateBigwinWeight(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
|
||||
{
|
||||
$weightMin = 0;
|
||||
$weightMax = 10000;
|
||||
@@ -213,21 +230,33 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
continue;
|
||||
}
|
||||
$weight = max($weightMin, min($weightMax, $weight));
|
||||
$this->model->where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
$query = $this->model->where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
|
||||
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);
|
||||
}
|
||||
$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();
|
||||
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);
|
||||
if ($result) {
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::refreshCache($deptId);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -403,6 +432,12 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
$record->lottery_config_id = $config ? (int) $config->id : null;
|
||||
$record->result_counts = $counts;
|
||||
$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->save();
|
||||
$recordId = (int) $record->id;
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use app\dice\basic\DiceBaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
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()
|
||||
{
|
||||
@@ -88,6 +91,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
throw new ApiException('Test record not found');
|
||||
}
|
||||
$record = is_array($record) ? $record : $record->toArray();
|
||||
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($record['dept_id'] ?? null);
|
||||
|
||||
$snapshot = $record['weight_config_snapshot'] ?? null;
|
||||
if (is_string($snapshot)) {
|
||||
@@ -112,9 +116,9 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$tier = $tierFromDb !== null ? (string) $tierFromDb : '';
|
||||
}
|
||||
// 仅按方向 + 点数更新 DiceReward(若存在则更新,不存在才插入,避免唯一键冲突)
|
||||
$reward = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
$rewardQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $configDeptId);
|
||||
$reward = $rewardQuery->find();
|
||||
if ($reward) {
|
||||
$reward->weight = $weight;
|
||||
// 若快照中有 tier,补齐 tier 信息
|
||||
@@ -130,10 +134,13 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->weight = $weight;
|
||||
if (!AdminScopeHelper::isTemplateDeptId($configDeptId)) {
|
||||
$m->dept_id = $configDeptId;
|
||||
}
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
DiceReward::refreshCache($configDeptId);
|
||||
}
|
||||
|
||||
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
|
||||
@@ -152,11 +159,11 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
if ($weight < 0) {
|
||||
$weight = 0;
|
||||
}
|
||||
DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
$bigwinQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($bigwinQuery, $configDeptId);
|
||||
$bigwinQuery->update(['weight' => $weight]);
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::refreshCache($configDeptId);
|
||||
}
|
||||
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
@@ -225,7 +232,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update);
|
||||
}
|
||||
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::refreshCache($configDeptId);
|
||||
DiceReward::refreshCache($configDeptId);
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
}
|
||||
|
||||
@@ -237,8 +245,12 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
* @return int 记录 ID
|
||||
* @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;
|
||||
if (!is_array($params)) {
|
||||
// 兼容旧版调用:createWeightTestRecord(paid_s_count, paid_n_count)
|
||||
@@ -249,15 +261,14 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
} else {
|
||||
$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];
|
||||
$ante = isset($params['ante']) ? intval($params['ante']) : 1;
|
||||
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);
|
||||
}
|
||||
$ante = $this->resolveWeightTestAnte($params, $deptId);
|
||||
|
||||
$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;
|
||||
@@ -296,8 +307,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$paidTierWeights = null;
|
||||
$freeTierWeights = null;
|
||||
|
||||
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟
|
||||
$instance = DiceReward::getCachedInstance();
|
||||
// 来自当前渠道的 DiceReward 权重快照(按方向+点数),用于权重测试模拟
|
||||
$instance = DiceReward::getCachedInstance($deptId);
|
||||
$byTierDirection = $instance['by_tier_direction'] ?? [];
|
||||
foreach ($byTierDirection as $tier => $byDir) {
|
||||
foreach ($byDir as $dir => $rows) {
|
||||
@@ -316,7 +327,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
|
||||
// JSON 结构 {"grid_number": weight, ...}
|
||||
$bigwinWeights = [];
|
||||
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN');
|
||||
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN', $deptId);
|
||||
foreach ($bigwinConfigs as $cfg) {
|
||||
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
|
||||
if ($grid <= 0) {
|
||||
@@ -327,10 +338,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
}
|
||||
|
||||
if ($paidConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($paidConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('Paid pool config not found');
|
||||
}
|
||||
$config = $this->findPoolConfigInDept($paidConfigId, $deptId, 'Paid pool config not found');
|
||||
$tierWeightsSnapshot['paid'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
'T2' => (int) ($config->t2_weight ?? 0),
|
||||
@@ -359,10 +367,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
}
|
||||
|
||||
if ($freeConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($freeConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('Free pool config not found');
|
||||
}
|
||||
$config = $this->findPoolConfigInDept($freeConfigId, $deptId, 'Free pool config not found');
|
||||
$tierWeightsSnapshot['free'] = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
'T2' => (int) ($config->t2_weight ?? 0),
|
||||
@@ -428,9 +433,94 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$record->bigwin_weight = $bigwinWeights ?: null;
|
||||
$record->ante = $ante;
|
||||
$record->admin_id = $adminId;
|
||||
$record->dept_id = $deptId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace app\dice\logic\reward_config_record;
|
||||
|
||||
use app\api\logic\PlayStartLogic;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
@@ -19,9 +20,13 @@ use support\think\Db;
|
||||
class WeightTestRunner
|
||||
{
|
||||
private const BATCH_SIZE = 10;
|
||||
|
||||
/** 本次测试所属渠道(与 dice_reward_config_record.dept_id 一致) */
|
||||
private int $runDeptId = 0;
|
||||
/** 测试记录写库白名单字段 */
|
||||
private const PLAY_RECORD_TEST_COLUMNS = [
|
||||
'reward_config_record_id',
|
||||
'dept_id',
|
||||
'admin_id',
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
@@ -61,10 +66,15 @@ class WeightTestRunner
|
||||
return;
|
||||
}
|
||||
|
||||
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
|
||||
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
|
||||
$this->runDeptId = $this->resolveRunDeptId($recordId, $record);
|
||||
$deptId = $this->runDeptId;
|
||||
DiceReward::setRequestDeptId($deptId);
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
|
||||
$configType0 = DiceLotteryPoolConfig::findByNameForDept('default', $deptId);
|
||||
$configType1 = DiceLotteryPoolConfig::findByNameForDept('killScore', $deptId);
|
||||
if (!$configType0) {
|
||||
$this->markFailed($recordId, '彩金池配置 name=default 不存在');
|
||||
$this->markFailed($recordId, '彩金池配置 name=default 不存在(当前渠道)');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,12 +89,12 @@ class WeightTestRunner
|
||||
$freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0);
|
||||
|
||||
$paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0;
|
||||
if (!$paidPoolConfig) {
|
||||
if (!$paidPoolConfig || AdminScopeHelper::normalizeRecordDeptId($paidPoolConfig->dept_id ?? null) !== $deptId) {
|
||||
$paidPoolConfig = $configType0;
|
||||
}
|
||||
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
|
||||
if (!$freePoolConfig) {
|
||||
$freePoolConfig = $configType0;
|
||||
if (!$freePoolConfig || AdminScopeHelper::normalizeRecordDeptId($freePoolConfig->dept_id ?? null) !== $deptId) {
|
||||
$freePoolConfig = $configType1 ?: $configType0;
|
||||
}
|
||||
|
||||
if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) {
|
||||
@@ -118,6 +128,7 @@ class WeightTestRunner
|
||||
try {
|
||||
$this->runChainFreeMode(
|
||||
$recordId,
|
||||
$deptId,
|
||||
$playLogic,
|
||||
$paidS,
|
||||
$paidN,
|
||||
@@ -145,6 +156,9 @@ class WeightTestRunner
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
|
||||
$this->markFailed($recordId, $e->getMessage());
|
||||
} finally {
|
||||
DiceReward::clearRequestInstance();
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +167,7 @@ class WeightTestRunner
|
||||
*/
|
||||
private function runChainFreeMode(
|
||||
int $recordId,
|
||||
int $deptId,
|
||||
PlayStartLogic $playLogic,
|
||||
int $paidS,
|
||||
int $paidN,
|
||||
@@ -199,12 +214,12 @@ class WeightTestRunner
|
||||
$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);
|
||||
$paidAmount = (float) ($row['paid_amount'] ?? 0);
|
||||
$playerProfitTotal += $winCoin - $paidAmount;
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId, $deptId);
|
||||
$done++;
|
||||
|
||||
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
|
||||
{
|
||||
$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 = [
|
||||
'reward_config_record_id' => $rewardConfigRecordId,
|
||||
'dept_id' => $bindDeptId,
|
||||
];
|
||||
$keys = [
|
||||
'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
@@ -254,7 +325,7 @@ class WeightTestRunner
|
||||
return;
|
||||
}
|
||||
$this->insertBuffer($buffer);
|
||||
$buffer = [];
|
||||
array_splice($buffer, 0, count($buffer));
|
||||
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts, $recordTotalPlayCount);
|
||||
}
|
||||
|
||||
@@ -263,6 +334,7 @@ class WeightTestRunner
|
||||
if (empty($rows)) {
|
||||
return;
|
||||
}
|
||||
$table = (new DicePlayRecordTest())->getTable();
|
||||
foreach ($rows as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
@@ -273,6 +345,9 @@ class WeightTestRunner
|
||||
$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'] === '') {
|
||||
$payload['create_time'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
@@ -282,10 +357,26 @@ class WeightTestRunner
|
||||
if ($payload === []) {
|
||||
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
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
@@ -308,6 +399,13 @@ class WeightTestRunner
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
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);
|
||||
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空
|
||||
|
||||
25
server/app/dice/model/DiceModel.php
Normal file
25
server/app/dice/model/DiceModel.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 $update_time 更新时间
|
||||
*/
|
||||
class DiceAnteConfig extends BaseModel
|
||||
class DiceAnteConfig extends DiceModel
|
||||
{
|
||||
protected $pk = 'id';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 $update_time 修改时间
|
||||
*/
|
||||
class DiceConfig extends BaseModel
|
||||
class DiceConfig extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\game;
|
||||
|
||||
use plugin\saiadmin\basic\eloquent\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
|
||||
/**
|
||||
* 游戏管理模型
|
||||
*
|
||||
* dice_game 游戏配置表
|
||||
*/
|
||||
class DiceGame extends BaseModel
|
||||
class DiceGame extends DiceModel
|
||||
{
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 $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';
|
||||
|
||||
/**
|
||||
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
|
||||
*/
|
||||
public static function findByNameForDept(string $name, int $deptId): ?self
|
||||
{
|
||||
$query = (new self())->where('name', $name);
|
||||
ConfigScopeEditHelper::applyDeptIdWhere($query, AdminScopeHelper::normalizeRecordDeptId($deptId));
|
||||
return $query->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 名称 搜索
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace app\dice\model\play_record;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DicePlayRecord extends BaseModel
|
||||
class DicePlayRecord extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use think\model\relation\BelongsTo;
|
||||
@@ -37,7 +37,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $admin_id 所属管理员
|
||||
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id(权重测试记录)
|
||||
*/
|
||||
class DicePlayRecordTest extends BaseModel
|
||||
class DicePlayRecordTest extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,8 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
* dice_player 大富翁-玩家
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $username 用户名
|
||||
* @property $dept_id 所属渠道ID
|
||||
* @property $username 用户名(同渠道内唯一)
|
||||
* @property $phone 手机
|
||||
* @property $uid uid
|
||||
* @property $name 昵称
|
||||
@@ -37,7 +38,7 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
* @property $update_time 更新时间
|
||||
* @property $delete_time 删除时间
|
||||
*/
|
||||
class DicePlayer extends BaseModel
|
||||
class DicePlayer extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace app\dice\model\player_ticket_record;
|
||||
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DicePlayerTicketRecord extends BaseModel
|
||||
class DicePlayerTicketRecord extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace app\dice\model\player_wallet_record;
|
||||
|
||||
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 think\model\relation\BelongsTo;
|
||||
|
||||
@@ -31,7 +31,7 @@ use think\model\relation\BelongsTo;
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DicePlayerWalletRecord extends BaseModel
|
||||
class DicePlayerWalletRecord extends DiceModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -25,42 +27,70 @@ use support\think\Cache;
|
||||
* @property $remark 备注(来自config)
|
||||
* @property $type 奖励类型(来自config)
|
||||
*/
|
||||
class DiceReward extends BaseModel
|
||||
class DiceReward extends DiceModel
|
||||
{
|
||||
/** 方向:顺时针 */
|
||||
public const DIRECTION_CLOCKWISE = 0;
|
||||
/** 方向:逆时针 */
|
||||
public const DIRECTION_COUNTERCLOCKWISE = 1;
|
||||
|
||||
/** 缓存键:奖励对照实例 */
|
||||
/** 缓存键前缀:奖励对照实例(按渠道分键) */
|
||||
private const CACHE_KEY_INSTANCE = 'dice:reward:instance';
|
||||
|
||||
private const CACHE_TTL = 86400 * 30;
|
||||
|
||||
private static ?array $instance = null;
|
||||
|
||||
private static ?int $requestDeptId = null;
|
||||
|
||||
protected $table = 'dice_reward';
|
||||
|
||||
/** 主键 id 自增,唯一约束 (direction, grid_number) */
|
||||
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)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
if (self::$instance !== null && self::$requestDeptId === $deptId) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::refreshCache($deptId);
|
||||
$instance = Cache::get($cacheKey);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
return self::$instance;
|
||||
}
|
||||
@@ -69,9 +99,9 @@ class DiceReward extends BaseModel
|
||||
* 按档位+方向取权重列表(用于抽奖:该档位该方向下 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'] ?? [];
|
||||
$list = $byTierDirection[$tier][$direction] ?? [];
|
||||
$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 = [];
|
||||
foreach ($list as $row) {
|
||||
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
|
||||
@@ -103,11 +136,12 @@ class DiceReward extends BaseModel
|
||||
$byTierDirection[$tier][$direction][] = $row;
|
||||
}
|
||||
}
|
||||
self::$instance = [
|
||||
$instance = [
|
||||
'list' => $list,
|
||||
'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
|
||||
@@ -121,20 +155,29 @@ class DiceReward extends BaseModel
|
||||
public static function clearRequestInstance(): void
|
||||
{
|
||||
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
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
|
||||
public static function onAfterDelete($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\reward_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\helper\ConfigScopeEditHelper;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
use support\think\Cache;
|
||||
|
||||
/**
|
||||
@@ -27,7 +29,7 @@ use support\think\Cache;
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
class DiceRewardConfig extends BaseModel
|
||||
class DiceRewardConfig extends DiceModel
|
||||
{
|
||||
/** 缓存键:彩金池奖励列表实例 */
|
||||
private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance';
|
||||
@@ -45,31 +47,35 @@ class DiceRewardConfig extends BaseModel
|
||||
* 优先从共享缓存读取,保证多进程(如一键测试 worker)能拿到最新配置,与数据库一致
|
||||
* @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)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
return self::$instance;
|
||||
self::refreshCache($deptId);
|
||||
$instance = Cache::get($cacheKey);
|
||||
return is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
}
|
||||
|
||||
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'] ?? [];
|
||||
}
|
||||
|
||||
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) {
|
||||
if (isset($row['id']) && (int) $row['id'] === $id) {
|
||||
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 = [];
|
||||
$byTierGrid = [];
|
||||
foreach ($list as $row) {
|
||||
@@ -103,13 +114,16 @@ class DiceRewardConfig extends BaseModel
|
||||
}
|
||||
}
|
||||
$minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev'));
|
||||
self::$instance = [
|
||||
$instance = [
|
||||
'list' => $list,
|
||||
'by_tier' => $byTier,
|
||||
'by_tier_grid' => $byTierGrid,
|
||||
'min_real_ev' => $minRealEv,
|
||||
];
|
||||
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
|
||||
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
|
||||
if ($deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
|
||||
self::$instance = $instance;
|
||||
}
|
||||
}
|
||||
|
||||
private static function buildEmptyInstance(): array
|
||||
@@ -125,9 +139,9 @@ class DiceRewardConfig extends BaseModel
|
||||
/**
|
||||
* 按档位+色子点数取一条(用于 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'] ?? [];
|
||||
$tierData = $byTierGrid[$tier] ?? [];
|
||||
$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'] ?? [];
|
||||
return $byTier[$tier] ?? [];
|
||||
}
|
||||
@@ -155,10 +169,10 @@ class DiceRewardConfig extends BaseModel
|
||||
* @param int $direction 0=顺时针, 1=逆时针
|
||||
* @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);
|
||||
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction);
|
||||
$list = self::getCachedByTier($tier, $deptId);
|
||||
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction, $deptId);
|
||||
foreach ($list as $i => $row) {
|
||||
$id = isset($row['id']) ? (int) $row['id'] : 0;
|
||||
$list[$i]['weight'] = $weightMap[$id] ?? 1;
|
||||
@@ -171,19 +185,27 @@ class DiceRewardConfig extends BaseModel
|
||||
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
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
|
||||
public static function onAfterUpdate($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
|
||||
public static function onAfterDelete($model): void
|
||||
{
|
||||
self::refreshCache();
|
||||
self::refreshCacheForModel($model);
|
||||
}
|
||||
|
||||
public function searchGridNumberMinAttr($query, $value)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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 string|null $create_time 创建时间
|
||||
*/
|
||||
class DiceRewardConfigRecord extends BaseModel
|
||||
class DiceRewardConfigRecord extends DiceModel
|
||||
{
|
||||
protected $pk = 'id';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace app\dice\model\reward_config_record;
|
||||
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\DiceModel;
|
||||
use think\model\relation\HasMany;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ use think\model\relation\HasMany;
|
||||
* @property int|null $admin_id 执行测试的管理员ID
|
||||
* @property string|null $create_time 创建时间
|
||||
*/
|
||||
class DiceRewardConfigRecord extends BaseModel
|
||||
class DiceRewardConfigRecord extends DiceModel
|
||||
{
|
||||
/** 状态:失败 */
|
||||
public const STATUS_FAIL = -1;
|
||||
|
||||
497
server/app/dice/service/DiceChannelConfigService.php
Normal file
497
server/app/dice/service/DiceChannelConfigService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\player;
|
||||
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,7 @@ class DicePlayerValidate extends BaseValidate
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'username' => 'require',
|
||||
'username' => 'require|unique:' . DicePlayer::class . ',username^dept_id',
|
||||
'name' => 'require',
|
||||
'phone' => 'require',
|
||||
'password' => 'require',
|
||||
@@ -30,6 +31,7 @@ class DicePlayerValidate extends BaseValidate
|
||||
*/
|
||||
protected $message = [
|
||||
'username' => '用户名必须填写',
|
||||
'username.unique' => 'PLAYER_USERNAME_DEPT_UNIQUE',
|
||||
'name' => '昵称必须填写',
|
||||
'phone' => '手机号必须填写',
|
||||
'password' => '密码必须填写',
|
||||
|
||||
@@ -6,7 +6,7 @@ return [
|
||||
// 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777
|
||||
'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'),
|
||||
// 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token
|
||||
'game_url' => env('GAME_URL', 'dice-game.h55555game.top'),
|
||||
'game_url' => env('GAME_URL', 'dice-v3-game.h55555game.top'),
|
||||
// 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验
|
||||
'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'),
|
||||
// 登录会话过期时间(秒),默认 7 天
|
||||
|
||||
@@ -14,7 +14,7 @@ use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 部门控制器
|
||||
* 渠道控制器
|
||||
*/
|
||||
class SystemDeptController extends BaseController
|
||||
{
|
||||
@@ -33,7 +33,7 @@ class SystemDeptController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据列表', 'core:dept:index')]
|
||||
#[Permission('渠道数据列表', 'core:dept:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
@@ -50,7 +50,7 @@ class SystemDeptController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据读取', 'core:dept:read')]
|
||||
#[Permission('渠道数据读取', 'core:dept:read')]
|
||||
public function read(Request $request) : Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
@@ -68,7 +68,7 @@ class SystemDeptController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据添加', 'core:dept:save')]
|
||||
#[Permission('渠道数据添加', 'core:dept:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
@@ -86,7 +86,7 @@ class SystemDeptController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据修改','core:dept:update')]
|
||||
#[Permission('渠道数据修改','core:dept:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
@@ -104,23 +104,58 @@ class SystemDeptController extends BaseController
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据删除','core:dept:destroy')]
|
||||
#[Permission('渠道数据删除','core:dept:destroy')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
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);
|
||||
if ($result) {
|
||||
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
|
||||
* @return Response
|
||||
*/
|
||||
|
||||
@@ -6,10 +6,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
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\app\cache\UserInfoCache;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\app\validate\system\SystemRoleValidate;
|
||||
use plugin\saiadmin\app\logic\system\SystemRoleLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
@@ -17,13 +15,10 @@ use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
* 角色控制器(按渠道隔离)
|
||||
*/
|
||||
class SystemRoleController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemRoleLogic();
|
||||
@@ -31,11 +26,6 @@ class SystemRoleController extends BaseController
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据列表', 'core:role:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
@@ -44,19 +34,14 @@ class SystemRoleController extends BaseController
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$levelArr = array_column($this->adminInfo['roleList'], 'level');
|
||||
$maxLevel = max($levelArr);
|
||||
$query->where('level', '<', $maxLevel);
|
||||
$data = $this->logic->getList($query);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
|
||||
$request->input('dept_id'),
|
||||
$request->all()
|
||||
);
|
||||
$data = $this->logic->indexList($where, $requestDeptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据读取', 'core:role:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
@@ -64,53 +49,49 @@ class SystemRoleController extends BaseController
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
$role = $this->logic->model->find($id);
|
||||
if ($role) {
|
||||
$this->logic->assertRoleWritable($role);
|
||||
}
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
return $this->fail('not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据添加', 'core:role:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$data['dept_id'] = $this->logic->resolveRequestDeptId(
|
||||
AdminScopeHelper::pickRequestDeptId($data['dept_id'] ?? null, $data)
|
||||
);
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
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')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$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);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
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')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
@@ -121,16 +102,10 @@ class SystemRoleController extends BaseController
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
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')]
|
||||
public function getMenuByRole(Request $request): Response
|
||||
{
|
||||
@@ -139,11 +114,6 @@ class SystemRoleController extends BaseController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单权限
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色菜单权限', 'core:role:menu')]
|
||||
public function menuPermission(Request $request): Response
|
||||
{
|
||||
@@ -153,16 +123,14 @@ class SystemRoleController extends BaseController
|
||||
return $this->success('operation success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作角色
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function accessRole(Request $request): Response
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,129 +2,123 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
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\exception\ApiException;
|
||||
use plugin\saiadmin\app\model\system\SystemDept;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use plugin\saiadmin\utils\Arr;
|
||||
|
||||
/**
|
||||
* 部门逻辑层
|
||||
* 渠道逻辑层(表 sa_system_dept)
|
||||
*/
|
||||
class SystemDeptLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new SystemDept();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据
|
||||
*/
|
||||
public function add($data): mixed
|
||||
{
|
||||
$data = $this->handleData($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
|
||||
{
|
||||
$oldLevel = $data['level'] . $id . ',';
|
||||
$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
|
||||
{
|
||||
$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();
|
||||
if ($count > 0) {
|
||||
throw new ApiException('This department has users, please delete or transfer them first');
|
||||
}
|
||||
return $this->model->destroy($ids);
|
||||
$count = SystemUser::where('dept_id', 'in', $ids)->count();
|
||||
if ($count > 0) {
|
||||
throw new ApiException('This channel has users, please delete or transfer them first');
|
||||
}
|
||||
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)
|
||||
{
|
||||
// 处理上级部门
|
||||
if (empty($data['parent_id']) || $data['parent_id'] == 0) {
|
||||
$data['level'] = '0';
|
||||
$data['parent_id'] = 0;
|
||||
} else {
|
||||
$parentMenu = SystemDept::findOrEmpty($data['parent_id']);
|
||||
$data['level'] = $parentMenu['level'] . $parentMenu['id'] . ',';
|
||||
}
|
||||
$data['level'] = '0';
|
||||
$data['parent_id'] = 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据树形化
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function tree(array $where = []): array
|
||||
{
|
||||
$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->with(['leader']);
|
||||
$data = $this->getAll($query);
|
||||
return Helper::makeTree($data);
|
||||
return $this->getAll($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作部门
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function accessDept(array $where = []): array
|
||||
{
|
||||
$query = $this->search($where);
|
||||
// 超级管理员(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');
|
||||
$data = $this->getAll($query);
|
||||
return Helper::makeTree($data);
|
||||
return $this->getAll($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前管理员可操作的渠道 ID(deptList 缺失时回退 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,121 +6,133 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\logic\system;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\app\cache\UserMenuCache;
|
||||
use plugin\saiadmin\app\model\system\SystemRole;
|
||||
use plugin\saiadmin\app\service\SystemRoleChannelService;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use support\think\Cache;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 角色逻辑层
|
||||
* 角色逻辑层(按渠道 dept_id 隔离)
|
||||
*/
|
||||
class SystemRoleLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*/
|
||||
public function edit($id, $data): bool
|
||||
{
|
||||
$model = $this->model->findOrEmpty($id);
|
||||
if ($model->isEmpty()) {
|
||||
throw new ApiException('Data not found');
|
||||
}
|
||||
$this->assertRoleWritable($model);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*/
|
||||
public function destroy($ids): bool
|
||||
{
|
||||
// 越权保护
|
||||
$levelArr = array_column($this->adminInfo['roleList'], 'level');
|
||||
$maxLevel = max($levelArr);
|
||||
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
|
||||
$maxLevel = !empty($levelArr) ? max($levelArr) : 100;
|
||||
|
||||
$num = SystemRole::where('level', '>=', $maxLevel)->whereIn('id', $ids)->count();
|
||||
if ($num > 0) {
|
||||
throw new ApiException('Cannot operate roles with higher level than current account');
|
||||
} else {
|
||||
return $this->model->destroy($ids);
|
||||
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->model->destroy($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据处理
|
||||
*/
|
||||
protected function handleData($data)
|
||||
{
|
||||
// 越权保护
|
||||
$levelArr = array_column($this->adminInfo['roleList'], 'level');
|
||||
$maxLevel = max($levelArr);
|
||||
if ($data['level'] >= $maxLevel) {
|
||||
throw new ApiException('Cannot operate roles with higher level than current account');
|
||||
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
|
||||
if (!empty($levelArr)) {
|
||||
$maxLevel = max($levelArr);
|
||||
if (($data['level'] ?? 0) >= $maxLevel) {
|
||||
throw new ApiException('Cannot operate roles with higher level than current account');
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作角色
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function accessRole(array $where = []): array
|
||||
public function accessRole(array $where = [], $requestDeptId = null): array
|
||||
{
|
||||
$query = $this->search($where);
|
||||
// 越权保护
|
||||
$levelArr = array_column($this->adminInfo['roleList'], 'level');
|
||||
$maxLevel = max($levelArr);
|
||||
$query->where('level', '<', $maxLevel);
|
||||
$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);
|
||||
$query->order('sort', 'desc');
|
||||
return $this->getAll($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色数组获取菜单
|
||||
* @param $ids
|
||||
* @return array
|
||||
*/
|
||||
public function getMenuIdsByRoleIds($ids): array
|
||||
{
|
||||
if (empty($ids))
|
||||
if (empty($ids)) {
|
||||
return [];
|
||||
}
|
||||
return $this->model->where('id', 'in', $ids)->with([
|
||||
'menus' => function ($query) {
|
||||
$query->where('status', 1)->order('sort', 'desc');
|
||||
}
|
||||
])->select()->toArray();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function getMenuByRole($id): array
|
||||
{
|
||||
$role = $this->model->findOrEmpty($id);
|
||||
if ($role->isEmpty()) {
|
||||
throw new ApiException('Data not found');
|
||||
}
|
||||
$this->assertRoleWritable($role);
|
||||
$menus = $role->menus ?: [];
|
||||
return [
|
||||
'id' => $id,
|
||||
@@ -128,14 +140,14 @@ class SystemRoleLogic extends BaseLogic
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存菜单权限
|
||||
* @param $id
|
||||
* @param $menu_ids
|
||||
* @return 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) {
|
||||
$role = $this->model->findOrEmpty($id);
|
||||
if ($role) {
|
||||
@@ -147,10 +159,90 @@ class SystemRoleLogic extends BaseLogic
|
||||
}
|
||||
$cache = config('plugin.saiadmin.saithink.button_cache');
|
||||
$tag = $cache['role'] . $id;
|
||||
Cache::tag($tag)->clear(); // 清理权限缓存-角色TAG
|
||||
UserMenuCache::clearMenuCache(); // 清理菜单缓存
|
||||
Cache::tag($tag)->clear();
|
||||
UserMenuCache::clearMenuCache();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,16 @@ class SystemUserLogic extends BaseLogic
|
||||
{
|
||||
$query = $this->search($where);
|
||||
$query->with(['depts']);
|
||||
// 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤
|
||||
// 超级管理员(id=1)可查看全部用户,渠道管理员按本渠道过滤
|
||||
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
$deptLogic = new SystemDeptLogic();
|
||||
$deptLogic->init($this->adminInfo);
|
||||
$deptId = $deptLogic->resolveAccessibleDeptId();
|
||||
if ($deptId > 0) {
|
||||
$query->where('dept_id', $deptId);
|
||||
} else {
|
||||
$query->auth($this->adminInfo['deptList'] ?? []);
|
||||
}
|
||||
}
|
||||
return $this->getList($query);
|
||||
}
|
||||
@@ -70,6 +77,12 @@ class SystemUserLogic extends BaseLogic
|
||||
$data = $admin->hidden(['password'])->toArray();
|
||||
$data['roleList'] = $admin->roles->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;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@ namespace plugin\saiadmin\app\model\system;
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
/**
|
||||
* 部门模型
|
||||
* 渠道模型
|
||||
*
|
||||
* sa_system_dept 部门表
|
||||
* sa_system_dept 渠道表
|
||||
*
|
||||
* @property $id 编号
|
||||
* @property $parent_id 父级ID,0为根节点
|
||||
* @property $name 部门名称
|
||||
* @property $code 部门编码
|
||||
* @property $leader_id 部门负责人ID
|
||||
* @property $parent_id 父级ID(扁平渠道固定为0)
|
||||
* @property $name 渠道名称
|
||||
* @property $code 渠道编码
|
||||
* @property $leader_id 渠道负责人ID
|
||||
* @property $level 祖级列表,格式: 0,1,5,
|
||||
* @property $sort 排序,数字越小越靠前
|
||||
* @property $status 状态: 1启用, 0禁用
|
||||
@@ -38,24 +38,21 @@ class SystemDept extends BaseModel
|
||||
protected $table = 'sa_system_dept';
|
||||
|
||||
/**
|
||||
* 权限范围
|
||||
* 权限范围(扁平渠道,仅本渠道)
|
||||
*/
|
||||
public function scopeAuth($query, $value)
|
||||
{
|
||||
if (!empty($value) && isset($value['id'])) {
|
||||
$deptIds = [$value['id']];
|
||||
$level = $value['level'] ?? '';
|
||||
if ($level !== '' && $level !== null) {
|
||||
$deptLevel = $level . $value['id'] . ',';
|
||||
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
|
||||
$deptIds = array_merge($deptIds, $ids);
|
||||
}
|
||||
$query->whereIn('id', $deptIds);
|
||||
if (is_array($value) && isset($value['id']) && (int) $value['id'] > 0) {
|
||||
$query->where('id', $value['id']);
|
||||
return;
|
||||
}
|
||||
if (is_numeric($value) && (int) $value > 0) {
|
||||
$query->where('id', (int) $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门领导
|
||||
* 渠道负责人
|
||||
*/
|
||||
public function leader()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,8 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
*
|
||||
* sa_system_role 角色表
|
||||
*
|
||||
* @property $id
|
||||
* @property $id
|
||||
* @property int $dept_id 所属渠道ID,0=默认模板
|
||||
* @property $name 角色名称
|
||||
* @property $code 角色标识,如: hr_manager
|
||||
* @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色
|
||||
@@ -41,6 +42,14 @@ class SystemRole extends BaseModel
|
||||
*/
|
||||
protected $table = 'sa_system_role';
|
||||
|
||||
/** 按渠道筛选 */
|
||||
public function searchDeptIdAttr($query, $value): void
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('dept_id', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限范围
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property $phone 手机号
|
||||
* @property $signed 个性签名
|
||||
* @property $dashboard 工作台
|
||||
* @property $dept_id 主归属部门
|
||||
* @property $dept_id 主归属渠道
|
||||
* @property $is_super 是否超级管理员: 1是
|
||||
* @property $status 状态: 1启用, 2禁用
|
||||
* @property $remark 备注
|
||||
@@ -82,16 +82,12 @@ class SystemUser extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限范围 - 过滤部门用户
|
||||
* 权限范围 - 过滤同渠道用户
|
||||
*/
|
||||
public function scopeAuth($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$deptIds = [$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);
|
||||
if (!empty($value) && isset($value['id'])) {
|
||||
$query->where('dept_id', $value['id']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +100,7 @@ class SystemUser extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表关联部门
|
||||
* 关联渠道
|
||||
*/
|
||||
public function depts()
|
||||
{
|
||||
|
||||
257
server/plugin/saiadmin/app/service/SystemRoleChannelService.php
Normal file
257
server/plugin/saiadmin/app/service/SystemRoleChannelService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace plugin\saiadmin\app\validate\system;
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 部门验证器
|
||||
* 渠道验证器
|
||||
*/
|
||||
class SystemDeptValidate extends BaseValidate
|
||||
{
|
||||
@@ -25,7 +25,7 @@ class SystemDeptValidate extends BaseValidate
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'name' => '部门名称必须填写',
|
||||
'name' => '渠道名称必须填写',
|
||||
'status' => '状态必须填写',
|
||||
];
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class SystemRoleValidate extends BaseValidate
|
||||
*/
|
||||
protected $rule = [
|
||||
'name' => 'require|max:16',
|
||||
'code' => 'require|alphaDash|unique:' . SystemRole::class,
|
||||
'code' => 'require|alphaDash|unique:' . SystemRole::class . ',code^dept_id',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\basic;
|
||||
|
||||
use app\api\util\ApiLang;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
@@ -36,6 +37,7 @@ class OpenController
|
||||
if (is_string($data)) {
|
||||
$msg = $data;
|
||||
}
|
||||
$msg = ApiLang::translate($msg, request());
|
||||
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
|
||||
{
|
||||
$msg = ApiLang::translate($msg, request());
|
||||
return json(['code' => $code, 'message' => $msg]);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,11 @@ Route::group('/core', function () {
|
||||
Route::get("/role/getMenuByRole", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'getMenuByRole']);
|
||||
Route::post("/role/menuPermission", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'menuPermission']);
|
||||
|
||||
// 部门管理
|
||||
// 渠道管理
|
||||
fastRoute("dept", \plugin\saiadmin\app\controller\system\SystemDeptController::class);
|
||||
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('menu', \plugin\saiadmin\app\controller\system\SystemMenuController::class);
|
||||
@@ -90,6 +92,7 @@ Route::group('/core', function () {
|
||||
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
|
||||
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
|
||||
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
|
||||
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']);
|
||||
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']);
|
||||
@@ -116,6 +119,7 @@ Route::group('/core', function () {
|
||||
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/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);
|
||||
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']);
|
||||
|
||||
@@ -72,4 +72,13 @@ return [
|
||||
'attr' => 'saiadmin:reflection_cache:attr_',
|
||||
],
|
||||
|
||||
/**
|
||||
* 新建渠道时从默认模板复制的角色 code(须存在于 dept_id=0 的模板角色)
|
||||
*/
|
||||
'channel_default_role_codes' => [
|
||||
'yijidaili',
|
||||
'erjidaili',
|
||||
'sanjidaili',
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
@@ -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 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',
|
||||
|
||||
@@ -254,6 +254,7 @@ return [
|
||||
'This category has sub-categories, please delete them first' => '该部门下存在子分类,请先删除子分类',
|
||||
'This department has sub-departments, please delete 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 menu has sub-menus, please delete them first' => '该菜单下存在子菜单,请先删除子菜单',
|
||||
'Timestamp expired or invalid, please sync time' => '时间戳已过期或无效,请同步时间',
|
||||
|
||||
Reference in New Issue
Block a user