修改渠道ChannelManage关联部门SystemDepart

This commit is contained in:
2026-03-10 10:09:35 +08:00
parent e94ebd3fe6
commit a6d87d5c0d
8 changed files with 242 additions and 15 deletions

View File

@@ -11,7 +11,7 @@ export default {
*/ */
list(params: Record<string, any>) { list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({ return request.get<Api.Common.ApiPage>({
url: '/channel/manage/ChannelManage/index', url: '/core/channel/manage/ChannelManage/index',
params params
}) })
}, },
@@ -23,7 +23,7 @@ export default {
*/ */
read(id: number | string) { read(id: number | string) {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/channel/manage/ChannelManage/read?id=' + id url: '/core/channel/manage/ChannelManage/read?id=' + id
}) })
}, },
@@ -34,7 +34,7 @@ export default {
*/ */
save(params: Record<string, any>) { save(params: Record<string, any>) {
return request.post<any>({ return request.post<any>({
url: '/channel/manage/ChannelManage/save', url: '/core/channel/manage/ChannelManage/save',
data: params data: params
}) })
}, },
@@ -46,7 +46,7 @@ export default {
*/ */
update(params: Record<string, any>) { update(params: Record<string, any>) {
return request.put<any>({ return request.put<any>({
url: '/channel/manage/ChannelManage/update', url: '/core/channel/manage/ChannelManage/update',
data: params data: params
}) })
}, },
@@ -58,7 +58,7 @@ export default {
*/ */
delete(params: Record<string, any>) { delete(params: Record<string, any>) {
return request.del<any>({ return request.del<any>({
url: '/channel/manage/ChannelManage/destroy', url: '/core/channel/manage/ChannelManage/destroy',
data: params data: params
}) })
}, },
@@ -68,18 +68,28 @@ export default {
*/ */
updateStatus(params: { id: number | string; status: number }) { updateStatus(params: { id: number | string; status: number }) {
return request.put<any>({ return request.put<any>({
url: '/channel/manage/ChannelManage/updateStatus', url: '/core/channel/manage/ChannelManage/updateStatus',
data: params data: params
}) })
}, },
/**
* 获取可操作部门列表(树形)
* @returns 部门树
*/
getDeptList() {
return request.get<Api.Common.ApiData>({
url: '/core/channel/manage/ChannelManage/getDeptList'
})
},
/** /**
* 获取管理员下拉列表SystemUser 的 id、username、realname * 获取管理员下拉列表SystemUser 的 id、username、realname
* @returns 管理员列表 * @returns 管理员列表
*/ */
getAdminList() { getAdminList() {
return request.get<Api.Common.ApiData>({ return request.get<Api.Common.ApiData>({
url: '/channel/manage/ChannelManage/getAdminList' url: '/core/channel/manage/ChannelManage/getAdminList'
}) })
} }
} }

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="art-full-height"> <div class="art-full-height">
<!-- 搜索面板 --> <!-- 搜索面板 -->
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" /> <TableSearch v-model="searchForm" @search="handleSearch" @reset="handleReset" />
<ElCard class="art-table-card" shadow="never"> <ElCard class="art-table-card" shadow="never">
<!-- 表格头部 --> <!-- 表格头部 -->
@@ -46,18 +46,20 @@
@pagination:size-change="handleSizeChange" @pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange" @pagination:current-change="handleCurrentChange"
> >
<!-- 状态开关直接修改 --> <!-- 状态开关直接修改仅渠道管理员和超管可操作 -->
<template #status="{ row }"> <template #status="{ row }">
<ElSwitch <ElSwitch
v-if="row.canOperate"
v-permission="'channel:manage:index:update'" v-permission="'channel:manage:index:update'"
:model-value="row.status === 1" :model-value="row.status === 1"
:loading="row._statusLoading" :loading="row._statusLoading"
@change="(v: string | number | boolean) => handleStatusChange(row, v ? 1 : 0)" @change="(v: string | number | boolean) => handleStatusChange(row, v ? 1 : 0)"
/> />
<span v-else>{{ row.status === 1 ? '启用' : '禁用' }}</span>
</template> </template>
<!-- 操作列 --> <!-- 操作列仅渠道管理员和超管可操作 -->
<template #operation="{ row }"> <template #operation="{ row }">
<div class="flex gap-2"> <div v-if="row.canOperate" class="flex gap-2">
<SaButton <SaButton
v-permission="'channel:manage:index:update'" v-permission="'channel:manage:index:update'"
type="secondary" type="secondary"
@@ -69,6 +71,7 @@
@click="deleteRow(row, api.delete, refreshData)" @click="deleteRow(row, api.delete, refreshData)"
/> />
</div> </div>
<span v-else class="text-gray-400">-</span>
</template> </template>
</ArtTable> </ArtTable>
</ElCard> </ElCard>
@@ -95,6 +98,7 @@
name: undefined, name: undefined,
title: undefined, title: undefined,
status: undefined, status: undefined,
department_id: undefined,
total_recharge: undefined, total_recharge: undefined,
total_withdrawal: undefined, total_withdrawal: undefined,
total_profit: undefined total_profit: undefined
@@ -106,6 +110,12 @@
getData() getData()
} }
// 重置时清空部门筛选
const handleReset = () => {
searchForm.value.department_id = undefined
resetSearchParams()
}
// 表格配置 // 表格配置
const { const {
columns, columns,
@@ -123,8 +133,14 @@
} = useTable({ } = useTable({
core: { core: {
apiFn: api.list, apiFn: api.list,
apiParams: {
...searchForm.value
},
columnsFactory: () => [ columnsFactory: () => [
{ type: 'selection' }, {
type: 'selection',
selectable: (row: Record<string, any>) => row.canOperate === true
},
{ prop: 'title', label: '标题' }, { prop: 'title', label: '标题' },
{ prop: 'status', label: '状态', useSlot: true }, { prop: 'status', label: '状态', useSlot: true },
{ {
@@ -138,6 +154,11 @@
) )
} }
}, },
{
prop: 'department_id',
label: '所属部门',
formatter: (row: Record<string, any>) => row.department?.name ?? row.department_id ?? '-'
},
{ prop: 'game_url', label: '游戏地址' }, { prop: 'game_url', label: '游戏地址' },
{ prop: 'image', label: '图标', saiType: 'image' }, { prop: 'image', label: '图标', saiType: 'image' },
{ prop: 'agent', label: '代理agent' }, { prop: 'agent', label: '代理agent' },

View File

@@ -34,6 +34,18 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="所属部门" prop="department_id">
<el-tree-select
v-model="formData.department_id"
:data="deptOptions"
:props="{ value: 'id', label: 'label' }"
placeholder="请选择部门"
clearable
check-strictly
:render-after-expand="false"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="游戏地址" prop="game_url"> <el-form-item label="游戏地址" prop="game_url">
<el-input v-model="formData.game_url" placeholder="请输入游戏地址" /> <el-input v-model="formData.game_url" placeholder="请输入游戏地址" />
</el-form-item> </el-form-item>
@@ -105,6 +117,7 @@
title: '', title: '',
status: 1, status: 1,
admin_id: null, admin_id: null,
department_id: null,
game_url: '', game_url: '',
image: '', image: '',
ip_white: '' ip_white: ''
@@ -131,6 +144,9 @@
const adminOptions = ref<Array<{ id: number; name: string }>>([]) const adminOptions = ref<Array<{ id: number; name: string }>>([])
const adminOptionsLoading = ref(false) const adminOptionsLoading = ref(false)
/** 部门下拉选项(树形) */
const deptOptions = ref<Array<{ id: number; label: string; children?: any[] }>>([])
const fetchAdminList = async () => { const fetchAdminList = async () => {
adminOptionsLoading.value = true adminOptionsLoading.value = true
try { try {
@@ -147,10 +163,19 @@
/** /**
* 初始化页面数据 * 初始化页面数据
*/ */
const fetchDeptList = async () => {
try {
const list = await api.getDeptList()
deptOptions.value = Array.isArray(list) ? list : []
} catch {
deptOptions.value = []
}
}
const initPage = async () => { const initPage = async () => {
// 先重置为初始值 // 先重置为初始值
Object.assign(formData, initialFormData) Object.assign(formData, initialFormData)
await fetchAdminList() await Promise.all([fetchAdminList(), fetchDeptList()])
// 如果有数据,则填充数据 // 如果有数据,则填充数据
if (props.data) { if (props.data) {
await nextTick() await nextTick()

View File

@@ -23,6 +23,20 @@
<el-input v-model="formData.status" placeholder="请输入状态" clearable /> <el-input v-model="formData.status" placeholder="请输入状态" clearable />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col v-bind="setSpan(6)">
<el-form-item label="所属部门" prop="department_id">
<el-tree-select
v-model="formData.department_id"
:data="deptOptions"
:props="{ value: 'id', label: 'label' }"
placeholder="请选择部门"
clearable
check-strictly
:render-after-expand="false"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)"> <el-col v-bind="setSpan(6)">
<el-form-item label="总充值" prop="total_recharge"> <el-form-item label="总充值" prop="total_recharge">
<el-input v-model="formData.total_recharge" placeholder="请输入总充值" clearable /> <el-input v-model="formData.total_recharge" placeholder="请输入总充值" clearable />
@@ -42,6 +56,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import api from '../../../api/manage/index'
interface Props { interface Props {
modelValue: Record<string, any> modelValue: Record<string, any>
} }
@@ -55,6 +71,17 @@
// 展开/收起 // 展开/收起
const isExpanded = ref<boolean>(false) const isExpanded = ref<boolean>(false)
// 部门下拉选项(树形,后端返回 id/label/children
const deptOptions = ref<Array<{ id: number; label: string; children?: any[] }>>([])
onMounted(async () => {
try {
const list = await api.getDeptList()
deptOptions.value = Array.isArray(list) ? list : []
} catch {
deptOptions.value = []
}
})
// 表单数据双向绑定 // 表单数据双向绑定
const searchBarRef = ref() const searchBarRef = ref()
const formData = computed({ const formData = computed({

View File

@@ -10,6 +10,8 @@ use plugin\saiadmin\basic\BaseController;
use app\channel\logic\manage\ChannelManageLogic; use app\channel\logic\manage\ChannelManageLogic;
use app\channel\validate\manage\ChannelManageValidate; use app\channel\validate\manage\ChannelManageValidate;
use plugin\saiadmin\app\model\system\SystemUser; use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\service\Permission; use plugin\saiadmin\service\Permission;
use support\Request; use support\Request;
use support\Response; use support\Response;
@@ -41,14 +43,20 @@ class ChannelManageController extends BaseController
['name', ''], ['name', ''],
['title', ''], ['title', ''],
['status', ''], ['status', ''],
['department_id', ''],
['total_recharge', ''], ['total_recharge', ''],
['total_withdrawal', ''], ['total_withdrawal', ''],
['total_profit', ''], ['total_profit', ''],
]); ]);
$query = $this->logic->search($where); $query = $this->logic->search($where);
// 不使用 with('admin')SystemUser 为 Think 模型,与 Eloquent 混用会触发 getConnectionName 报错,改为手动填充 // 仅渠道管理员和超级管理员可查看:超管看全部,渠道管理员只看自己管理的渠道
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
$query->where('admin_id', $this->adminInfo['id']);
}
$data = $this->logic->getList($query); $data = $this->logic->getList($query);
$data['data'] = $this->attachAdminToRows($data['data'] ?? []); $data['data'] = $this->attachAdminToRows($data['data'] ?? []);
$data['data'] = $this->attachDepartmentToRows($data['data'] ?? []);
$data['data'] = $this->attachCanOperate($data['data'] ?? []);
return $this->success($data); return $this->success($data);
} }
@@ -64,6 +72,9 @@ class ChannelManageController extends BaseController
$model = $this->logic->read($id); $model = $this->logic->read($id);
if ($model) { if ($model) {
$data = is_array($model) ? $model : $model->toArray(); $data = is_array($model) ? $model : $model->toArray();
if (!$this->logic->canOperateChannel($data)) {
throw new ApiException('没有权限查看该渠道');
}
return $this->success($data); return $this->success($data);
} else { } else {
return $this->fail('未查找到信息'); return $this->fail('未查找到信息');
@@ -98,6 +109,10 @@ class ChannelManageController extends BaseController
public function update(Request $request): Response public function update(Request $request): Response
{ {
$data = $request->post(); $data = $request->post();
$channel = $this->logic->read($data['id'] ?? 0);
if (!$channel || !$this->logic->canOperateChannel($channel)) {
throw new ApiException('没有权限修改该渠道');
}
$data['agent'] = md5((string)($data['name'] ?? '') . (string)($data['admin_id'] ?? '')); $data['agent'] = md5((string)($data['name'] ?? '') . (string)($data['admin_id'] ?? ''));
$this->validate('update', $data); $this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data); $result = $this->logic->edit($data['id'], $data);
@@ -124,6 +139,10 @@ class ChannelManageController extends BaseController
if ($status === null || $status === '') { if ($status === null || $status === '') {
return $this->fail('缺少 status'); return $this->fail('缺少 status');
} }
$channel = $this->logic->read($id);
if (!$channel || !$this->logic->canOperateChannel($channel)) {
throw new ApiException('没有权限修改该渠道');
}
$this->logic->edit($id, ['status' => (int) $status]); $this->logic->edit($id, ['status' => (int) $status]);
return $this->success('修改成功'); return $this->success('修改成功');
} }
@@ -140,6 +159,13 @@ class ChannelManageController extends BaseController
if (empty($ids)) { if (empty($ids)) {
return $this->fail('请选择要删除的数据'); return $this->fail('请选择要删除的数据');
} }
$idList = is_array($ids) ? $ids : (array) $ids;
foreach ($idList as $id) {
$channel = $this->logic->read($id);
if (!$channel || !$this->logic->canOperateChannel($channel)) {
throw new ApiException('没有权限删除该渠道');
}
}
$result = $this->logic->destroy($ids); $result = $this->logic->destroy($ids);
if ($result) { if ($result) {
return $this->success('删除成功'); return $this->success('删除成功');
@@ -148,6 +174,21 @@ class ChannelManageController extends BaseController
} }
} }
/**
* 获取可操作部门列表(树形,用于渠道所属部门选择)
* @param Request $request
* @return Response
*/
#[Permission('渠道部门列表', 'channel:manage:index:index')]
public function getDeptList(Request $request): Response
{
$this->ensureAdminInfo();
$logic = new \plugin\saiadmin\app\logic\system\SystemDeptLogic();
$logic->init($this->adminInfo ?? []);
$data = $logic->accessDept(['status' => 1]);
return $this->success($data);
}
/** /**
* 获取管理员下拉列表(远程关联 SystemUservalue=id, label=name * 获取管理员下拉列表(远程关联 SystemUservalue=id, label=name
* @param Request $request * @param Request $request
@@ -214,4 +255,73 @@ class ChannelManageController extends BaseController
return $rows; return $rows;
} }
/**
* 为列表行附加部门信息department_id 关联 SystemDept
* @param array $rows 列表行,可为 Eloquent 模型或数组
* @return array 已附加 department 的列表
*/
protected function attachDepartmentToRows(array $rows): array
{
if (empty($rows)) {
return $rows;
}
$deptIds = [];
foreach ($rows as $row) {
$id = is_array($row) ? ($row['department_id'] ?? null) : ($row->department_id ?? null);
if ($id !== null && $id !== '') {
$deptIds[(string) $id] = true;
}
}
$deptIds = array_keys($deptIds);
if (empty($deptIds)) {
foreach ($rows as &$row) {
if (is_array($row)) {
$row['department'] = null;
} else {
$row->setAttribute('department', null);
}
}
unset($row);
return $rows;
}
$depts = SystemDept::whereIn('id', $deptIds)
->field('id, name')
->select()
->toArray();
$map = [];
foreach ($depts as $d) {
$map[(string) ($d['id'] ?? '')] = $d;
}
foreach ($rows as &$row) {
$did = is_array($row) ? ($row['department_id'] ?? null) : ($row->department_id ?? null);
$dept = $map[(string) ($did ?? '')] ?? null;
if (is_array($row)) {
$row['department'] = $dept;
} else {
$row->setAttribute('department', $dept);
}
}
unset($row);
return $rows;
}
/**
* 为列表行附加是否可操作标记(仅渠道管理员和超级管理员可操作)
* @param array $rows 列表行
* @return array
*/
protected function attachCanOperate(array $rows): array
{
foreach ($rows as &$row) {
$canOperate = $this->logic->canOperateChannel($row);
if (is_array($row)) {
$row['canOperate'] = $canOperate;
} else {
$row->setAttribute('canOperate', $canOperate);
}
}
unset($row);
return $rows;
}
} }

View File

@@ -8,7 +8,6 @@ namespace app\channel\logic\manage;
use plugin\saiadmin\basic\eloquent\BaseLogic; use plugin\saiadmin\basic\eloquent\BaseLogic;
use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\channel\model\manage\ChannelManage; use app\channel\model\manage\ChannelManage;
/** /**
@@ -24,4 +23,22 @@ class ChannelManageLogic extends BaseLogic
$this->model = new ChannelManage(); $this->model = new ChannelManage();
} }
/**
* 判断当前用户是否可操作该渠道(仅渠道管理员或超级管理员可操作)
* @param object|array $channel 渠道数据,需包含 admin_id
* @return bool
*/
public function canOperateChannel($channel): bool
{
if (empty($this->adminInfo) || !isset($this->adminInfo['id'])) {
return false;
}
$adminId = (int) ($this->adminInfo['id']);
if ($adminId === 1) {
return true;
}
$channelAdminId = is_array($channel) ? ($channel['admin_id'] ?? null) : ($channel->admin_id ?? null);
return $channelAdminId !== null && (int) $channelAdminId === $adminId;
}
} }

View File

@@ -18,6 +18,7 @@ use plugin\saiadmin\basic\eloquent\BaseModel;
* @property $title 标题 * @property $title 标题
* @property $status 状态 * @property $status 状态
* @property $admin_id 管理员 * @property $admin_id 管理员
* @property $department_id 所属部门ID关联sa_system_dept
* @property $game_url 游戏地址 * @property $game_url 游戏地址
* @property $image 图标 * @property $image 图标
* @property $agent 代理agent * @property $agent 代理agent
@@ -67,6 +68,16 @@ class ChannelManage extends BaseModel
$query->where('title', 'like', '%'.$value.'%'); $query->where('title', 'like', '%'.$value.'%');
} }
/**
* 部门 搜索
*/
public function searchDepartmentIdAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('department_id', $value);
}
}
/** /**
* 总充值 搜索 * 总充值 搜索
*/ */

View File

@@ -82,6 +82,12 @@ Route::group('/core', function () {
Route::get("/server/cache", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'cache']); Route::get("/server/cache", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'cache']);
Route::post("/server/clear", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'clear']); Route::post("/server/clear", [\plugin\saiadmin\app\controller\system\SystemServerController::class, 'clear']);
// 渠道管理
fastRoute('channel/manage/ChannelManage', \app\channel\controller\manage\ChannelManageController::class);
Route::get("/channel/manage/ChannelManage/getDeptList", [\app\channel\controller\manage\ChannelManageController::class, 'getDeptList']);
Route::get("/channel/manage/ChannelManage/getAdminList", [\app\channel\controller\manage\ChannelManageController::class, 'getAdminList']);
Route::put("/channel/manage/ChannelManage/updateStatus", [\app\channel\controller\manage\ChannelManageController::class, 'updateStatus']);
// 数据表维护 // 数据表维护
Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']); Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']);
Route::get("/database/recycle", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'recycle']); Route::get("/database/recycle", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'recycle']);