From db0ddb1a2aedde34234a24680e2b56bf4bbe583e Mon Sep 17 00:00:00 2001
From: zhenhui <1276357500@qq.com>
Date: Fri, 29 May 2026 17:33:48 +0800
Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E5=90=8E=E5=8F=B0=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E5=91=98=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2=E7=9A=84?=
=?UTF-8?q?=E6=9D=83=E9=99=90=E8=AE=BE=E7=BD=AE=EF=BC=8C=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?zihuaadmin=E8=B4=A6=E5=8F=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/admin/controller/auth/Admin.php | 143 +++++++-----------
.../views/backend/auth/admin/popupForm.vue | 89 +++++------
2 files changed, 94 insertions(+), 138 deletions(-)
diff --git a/app/admin/controller/auth/Admin.php b/app/admin/controller/auth/Admin.php
index 52f8c8e..046a5bb 100644
--- a/app/admin/controller/auth/Admin.php
+++ b/app/admin/controller/auth/Admin.php
@@ -156,20 +156,9 @@ class Admin extends Backend
$parentAdminId = intval($request->get('parent_admin_id', 0));
$excludeId = intval($request->get('exclude_id', 0));
- $isTopLevelGroup = ($request->get('is_top_level') ?? $request->post('is_top_level')) === '1'
- || ($request->get('is_top_level') ?? $request->post('is_top_level')) === 1
- || ($request->get('is_top_level') ?? $request->post('is_top_level')) === true;
$channelId = intval($request->get('channel_id', 0));
- if ($isTopLevelGroup) {
- if ($channelId <= 0) {
- return $this->success('', [
- 'used_rate' => '0.00',
- 'remaining_rate' => '100.00',
- 'parent_has_no_share' => false,
- 'is_top_level' => true,
- ]);
- }
+ if ($parentAdminId <= 0 && $channelId > 0) {
$stats = AdminCommissionDistributionService::getChannelRootShareRemainder(
$channelId,
$excludeId > 0 ? $excludeId : null
@@ -178,7 +167,7 @@ class Admin extends Backend
'used_rate' => $stats['used_rate'],
'remaining_rate' => $stats['remaining_rate'],
'parent_has_no_share' => bccomp($stats['remaining_rate'], '0', 2) <= 0,
- 'is_top_level' => true,
+ 'is_channel_root' => true,
]);
}
@@ -187,7 +176,7 @@ class Admin extends Backend
'used_rate' => '0.00',
'remaining_rate' => '100.00',
'parent_has_no_share' => false,
- 'is_top_level' => false,
+ 'is_channel_root' => false,
]);
}
@@ -524,17 +513,15 @@ class Admin extends Backend
$groupArr = is_array($rowData['group_arr'] ?? null) ? $rowData['group_arr'] : [];
$rowData['primary_group_is_top_level'] = $this->isPrimaryGroupTopLevel($groupArr);
$parentId = intval($rowData['parent_admin_id'] ?? 0);
- if ($rowData['primary_group_is_top_level']) {
- $channelId = intval($rowData['channel_id'] ?? 0);
- if ($channelId > 0) {
- $rowData['root_share_remainder'] = AdminCommissionDistributionService::getChannelRootShareRemainder(
- $channelId,
- intval($id)
- );
- }
- } elseif ($parentId > 0) {
+ $channelId = intval($rowData['channel_id'] ?? 0);
+ if ($parentId > 0) {
$remainder = AdminCommissionDistributionService::getShareRemainder($parentId, intval($id));
$rowData['share_remainder'] = $remainder;
+ } elseif ($channelId > 0) {
+ $rowData['root_share_remainder'] = AdminCommissionDistributionService::getChannelRootShareRemainder(
+ $channelId,
+ intval($id)
+ );
}
return $this->success('', [
@@ -742,89 +729,66 @@ class Admin extends Backend
{
if ($this->isPrimaryGroupTopLevel($groupIds)) {
$data['parent_admin_id'] = null;
- if (!$this->auth->isSuperAdmin()) {
- $mayAssignChannel = false;
- foreach (['channel/index', 'channel/Index', 'Channel/index', 'Channel/Index'] as $routePath) {
- if ($this->auth->check($routePath)) {
- $mayAssignChannel = true;
- break;
- }
- }
- if (!$mayAssignChannel) {
- unset($data['channel_id']);
- }
- }
- $channelId = $data['channel_id'] ?? null;
- $channelIdInt = intval($channelId ?? 0);
- if ($channelIdInt <= 0) {
- $data['channel_id'] = null;
- $data['commission_share_rate'] = null;
-
- return null;
- }
- $exists = Db::name('channel')->where('id', $channelIdInt)->value('id');
- if (!$exists) {
- return (string) __('Record not found');
- }
- $shareErr = AdminCommissionDistributionService::validateChannelRootCommissionShareRate(
- $channelIdInt,
- $data['commission_share_rate'] ?? null,
- $editAdminId
- );
- if ($shareErr !== null) {
- return $shareErr;
- }
- $data['commission_share_rate'] = bcadd(strval($data['commission_share_rate'] ?? '0'), '0', 2);
-
- return null;
}
$parentId = isset($data['parent_admin_id']) && $data['parent_admin_id'] !== '' && $data['parent_admin_id'] !== null
? intval($data['parent_admin_id'])
: 0;
- if ($parentId <= 0 && $editAdminId !== null && $editAdminId > 0) {
+ if ($parentId <= 0 && $editAdminId !== null && $editAdminId > 0 && !array_key_exists('parent_admin_id', $data)) {
$existingParent = Db::name('admin')->where('id', $editAdminId)->value('parent_admin_id');
$parentId = intval($existingParent ?? 0);
}
- if ($parentId <= 0) {
- $data['parent_admin_id'] = null;
- $data['commission_share_rate'] = null;
- if (!$this->auth->isSuperAdmin()) {
- $mayAssignChannel = false;
- foreach (['channel/index', 'channel/Index', 'Channel/index', 'Channel/Index'] as $routePath) {
- if ($this->auth->check($routePath)) {
- $mayAssignChannel = true;
- break;
- }
- }
- if (!$mayAssignChannel) {
- unset($data['channel_id']);
+
+ if ($parentId > 0) {
+ if ($editAdminId !== null && $parentId === $editAdminId) {
+ return (string) __('Cannot set yourself as parent administrator');
+ }
+
+ $parent = Db::name('admin')->where('id', $parentId)->find();
+ if (!is_array($parent)) {
+ return (string) __('Invalid parent administrator');
+ }
+ if (!$this->canManageAdminId($parentId) && !$this->auth->isSuperAdmin()) {
+ return (string) __('You have no permission');
+ }
+
+ $data['parent_admin_id'] = $parentId;
+ if (!empty($parent['channel_id'])) {
+ $data['channel_id'] = $parent['channel_id'];
+ $shareErr = AdminCommissionDistributionService::validateCommissionShareRate(
+ $parentId,
+ $data['commission_share_rate'] ?? null,
+ $editAdminId
+ );
+ if ($shareErr !== null) {
+ return $shareErr;
}
+ $data['commission_share_rate'] = bcadd(strval($data['commission_share_rate'] ?? '0'), '0', 2);
+ } else {
+ $data['channel_id'] = null;
+ $data['commission_share_rate'] = null;
}
return null;
}
- if ($editAdminId !== null && $parentId === $editAdminId) {
- return (string) __('Cannot set yourself as parent administrator');
+ $data['parent_admin_id'] = null;
+ if ($editAdminId !== null && $editAdminId > 0 && !array_key_exists('channel_id', $data)) {
+ return null;
}
-
- $parent = Db::name('admin')->where('id', $parentId)->find();
- if (!is_array($parent)) {
- return (string) __('Invalid parent administrator');
- }
- if (!$this->canManageAdminId($parentId) && !$this->auth->isSuperAdmin()) {
- return (string) __('You have no permission');
- }
-
- if (!empty($parent['channel_id'])) {
- $data['channel_id'] = $parent['channel_id'];
- } else {
+ $channelIdInt = intval($data['channel_id'] ?? 0);
+ if ($channelIdInt <= 0) {
$data['channel_id'] = null;
- }
+ $data['commission_share_rate'] = null;
- $shareErr = AdminCommissionDistributionService::validateCommissionShareRate(
- $parentId,
+ return null;
+ }
+ $exists = Db::name('channel')->where('id', $channelIdInt)->value('id');
+ if (!$exists) {
+ return (string) __('Record not found');
+ }
+ $shareErr = AdminCommissionDistributionService::validateChannelRootCommissionShareRate(
+ $channelIdInt,
$data['commission_share_rate'] ?? null,
$editAdminId
);
@@ -832,7 +796,6 @@ class Admin extends Backend
return $shareErr;
}
$data['commission_share_rate'] = bcadd(strval($data['commission_share_rate'] ?? '0'), '0', 2);
- $data['parent_admin_id'] = $parentId;
return null;
}
diff --git a/web/src/views/backend/auth/admin/popupForm.vue b/web/src/views/backend/auth/admin/popupForm.vue
index 47b79f3..c4e6af3 100644
--- a/web/src/views/backend/auth/admin/popupForm.vue
+++ b/web/src/views/backend/auth/admin/popupForm.vue
@@ -40,25 +40,6 @@
prop="nickname"
:placeholder="t('Please input field', { field: t('auth.admin.nickname') })"
/>
-
-
-
-
-
-
-
+
+
+
+
+
+
+
baTable.form.operate === 'Edit' && adminInfo.id == baTable.form.items?.id)
-const hasChannelIndexAuth = computed(
- () =>
- adminInfo.super ||
- auth({ name: '/admin/channel', subNodeName: '/admin/channel/index' }) ||
- auth({ name: '/admin/Channel', subNodeName: '/admin/Channel/index' })
-)
-
const hasParentAdmin = computed(() => {
const pid = baTable.form.items?.parent_admin_id
return pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
})
const showChannelEditable = computed(
- () => hasChannelIndexAuth.value && isTopLevelGroup.value && !hasParentAdmin.value && !isSelfEdit.value
+ () => adminInfo.super && !hasParentAdmin.value && !isSelfEdit.value
)
const channelDisplayName = computed(() => {
@@ -235,7 +227,7 @@ const showChannelReadonly = computed(() => {
if (isSelfEdit.value) return false
if (showChannelEditable.value) return false
if (hasParentAdmin.value) return true
- if (!isTopLevelGroup.value && hasChannelForShare.value) return true
+ if (!adminInfo.super && baTable.form.operate === 'Add') return true
return channelDisplayName.value !== ''
})
@@ -248,19 +240,9 @@ const hasChannelForShare = computed(() => {
const showShareRateField = computed(() => {
if (isSelfEdit.value) return false
- if (isTopLevelGroup.value) {
- if (!hasChannelForShare.value) return false
- return hasChannelIndexAuth.value || baTable.form.operate === 'Add'
- }
- if (adminInfo.super) {
- const pid = baTable.form.items?.parent_admin_id
- return pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
- }
- if (baTable.form.operate === 'Add') {
- return true
- }
- const pid = baTable.form.items?.parent_admin_id
- return pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
+ if (!hasChannelForShare.value) return false
+ if (hasParentAdmin.value) return true
+ return true
})
const parentSelectParams = computed(() => {
@@ -328,7 +310,7 @@ const loadParentChannelMeta = async (parentId: unknown) => {
const items = baTable.form.items
if (!items) return
if (parentId === null || parentId === undefined || parentId === '' || Number(parentId) <= 0) {
- if (!isTopLevelGroup.value) {
+ if (showChannelEditable.value) {
items['channel_name'] = ''
}
return
@@ -357,14 +339,13 @@ const loadShareRemainder = async () => {
shareHint.value = ''
return
}
- if (isTopLevelGroup.value) {
+ if (!hasParentAdmin.value && hasChannelForShare.value) {
const channelId = resolveChannelIdForShare()
try {
const res = await createAxios({
url: '/admin/auth.Admin/commissionShareRemainder',
method: 'get',
params: {
- is_top_level: 1,
channel_id: channelId,
exclude_id: baTable.form.items?.id || 0,
},
@@ -444,7 +425,6 @@ watch(
watch(
() => baTable.form.items?.parent_admin_id,
(parentId) => {
- if (isTopLevelGroup.value) return
void loadParentChannelMeta(parentId)
},
{ immediate: true }
@@ -491,7 +471,9 @@ watch(
watch(
() => baTable.form.items?.root_share_remainder,
(val) => {
- if (val && baTable.form.operate === 'Edit' && isTopLevelGroup.value) {
+ const pid = baTable.form.items?.parent_admin_id
+ const hasParent = pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
+ if (val && baTable.form.operate === 'Edit' && !hasParent) {
shareHint.value = t('auth.admin.Channel root share remainder hint', {
used: val.used_rate ?? '0.00',
remaining: val.remaining_rate ?? '100.00',
@@ -508,6 +490,17 @@ watch(isTopLevelGroup, (topLevel) => {
}
})
+watch(
+ () => baTable.form.operate,
+ (operate) => {
+ if (operate !== 'Add' || adminInfo.super || !baTable.form.items) {
+ return
+ }
+ baTable.form.items.parent_admin_id = adminInfo.id
+ void loadParentChannelMeta(adminInfo.id)
+ }
+)
+
const rules: Partial> = reactive({
username: [buildValidatorData({ name: 'required', title: t('auth.admin.username') }), buildValidatorData({ name: 'account' })],
nickname: [buildValidatorData({ name: 'required', title: t('auth.admin.nickname') })],