diff --git a/saiadmin-artd/src/views/plugin/channel/api/manage/index.ts b/saiadmin-artd/src/views/plugin/channel/api/manage/index.ts new file mode 100644 index 0000000..65694d7 --- /dev/null +++ b/saiadmin-artd/src/views/plugin/channel/api/manage/index.ts @@ -0,0 +1,85 @@ +import request from '@/utils/http' + +/** + * 渠道 API接口 + */ +export default { + /** + * 获取数据列表 + * @param params 搜索参数 + * @returns 数据列表 + */ + list(params: Record) { + return request.get({ + url: '/channel/manage/ChannelManage/index', + params + }) + }, + + /** + * 读取数据 + * @param id 数据ID + * @returns 数据详情 + */ + read(id: number | string) { + return request.get({ + url: '/channel/manage/ChannelManage/read?id=' + id + }) + }, + + /** + * 创建数据 + * @param params 数据参数 + * @returns 执行结果 + */ + save(params: Record) { + return request.post({ + url: '/channel/manage/ChannelManage/save', + data: params + }) + }, + + /** + * 更新数据 + * @param params 数据参数 + * @returns 执行结果 + */ + update(params: Record) { + return request.put({ + url: '/channel/manage/ChannelManage/update', + data: params + }) + }, + + /** + * 删除数据 + * @returns 执行结果 + * @param params + */ + delete(params: Record) { + return request.del({ + url: '/channel/manage/ChannelManage/destroy', + data: params + }) + }, + + /** + * 仅更新状态(列表内开关用) + */ + updateStatus(params: { id: number | string; status: number }) { + return request.put({ + url: '/channel/manage/ChannelManage/updateStatus', + data: params + }) + }, + + /** + * 获取管理员下拉列表(SystemUser 的 id、username、realname) + * @returns 管理员列表 + */ + getAdminList() { + return request.get({ + url: '/channel/manage/ChannelManage/getAdminList' + }) + } +} diff --git a/saiadmin-artd/src/views/plugin/channel/manage/index/index.vue b/saiadmin-artd/src/views/plugin/channel/manage/index/index.vue new file mode 100644 index 0000000..7dee174 --- /dev/null +++ b/saiadmin-artd/src/views/plugin/channel/manage/index/index.vue @@ -0,0 +1,178 @@ + + + diff --git a/saiadmin-artd/src/views/plugin/channel/manage/index/modules/edit-dialog.vue b/saiadmin-artd/src/views/plugin/channel/manage/index/modules/edit-dialog.vue new file mode 100644 index 0000000..6f51e91 --- /dev/null +++ b/saiadmin-artd/src/views/plugin/channel/manage/index/modules/edit-dialog.vue @@ -0,0 +1,202 @@ + + + diff --git a/saiadmin-artd/src/views/plugin/channel/manage/index/modules/table-search.vue b/saiadmin-artd/src/views/plugin/channel/manage/index/modules/table-search.vue new file mode 100644 index 0000000..03c75c5 --- /dev/null +++ b/saiadmin-artd/src/views/plugin/channel/manage/index/modules/table-search.vue @@ -0,0 +1,92 @@ + + + diff --git a/server/app/channel/controller/manage/ChannelManageController.php b/server/app/channel/controller/manage/ChannelManageController.php new file mode 100644 index 0000000..49d3939 --- /dev/null +++ b/server/app/channel/controller/manage/ChannelManageController.php @@ -0,0 +1,217 @@ +logic = new ChannelManageLogic(); + $this->validate = new ChannelManageValidate; + parent::__construct(); + } + + /** + * 数据列表 + * @param Request $request + * @return Response + */ + #[Permission('渠道列表', 'channel:manage:index:index')] + public function index(Request $request): Response + { + $where = $request->more([ + ['name', ''], + ['title', ''], + ['status', ''], + ['total_recharge', ''], + ['total_withdrawal', ''], + ['total_profit', ''], + ]); + $query = $this->logic->search($where); + // 不使用 with('admin'):SystemUser 为 Think 模型,与 Eloquent 混用会触发 getConnectionName 报错,改为手动填充 + $data = $this->logic->getList($query); + $data['data'] = $this->attachAdminToRows($data['data'] ?? []); + return $this->success($data); + } + + /** + * 读取数据 + * @param Request $request + * @return Response + */ + #[Permission('渠道读取', 'channel:manage:index:read')] + public function read(Request $request): Response + { + $id = $request->input('id', ''); + $model = $this->logic->read($id); + if ($model) { + $data = is_array($model) ? $model : $model->toArray(); + return $this->success($data); + } else { + return $this->fail('未查找到信息'); + } + } + + /** + * 保存数据 + * @param Request $request + * @return Response + */ + #[Permission('渠道添加', 'channel:manage:index:save')] + public function save(Request $request): Response + { + $data = $request->post(); + $data['agent'] = md5((string)($data['name'] ?? '') . (string)($data['admin_id'] ?? '')); + $this->validate('save', $data); + $result = $this->logic->add($data); + if ($result) { + return $this->success('添加成功'); + } else { + return $this->fail('添加失败'); + } + } + + /** + * 更新数据 + * @param Request $request + * @return Response + */ + #[Permission('渠道修改', 'channel:manage:index:update')] + public function update(Request $request): Response + { + $data = $request->post(); + $data['agent'] = md5((string)($data['name'] ?? '') . (string)($data['admin_id'] ?? '')); + $this->validate('update', $data); + $result = $this->logic->edit($data['id'], $data); + if ($result) { + return $this->success('修改成功'); + } else { + return $this->fail('修改失败'); + } + } + + /** + * 仅更新状态(列表内开关用) + * @param Request $request + * @return Response + */ + #[Permission('渠道管理-更新状态', 'channel:manage:index:update')] + public function updateStatus(Request $request): Response + { + $id = $request->input('id'); + $status = $request->input('status'); + if ($id === null || $id === '') { + return $this->fail('缺少 id'); + } + if ($status === null || $status === '') { + return $this->fail('缺少 status'); + } + $this->logic->edit($id, ['status' => (int) $status]); + return $this->success('修改成功'); + } + + /** + * 删除数据 + * @param Request $request + * @return Response + */ + #[Permission('渠道删除', 'channel:manage:index:destroy')] + public function destroy(Request $request): Response + { + $ids = $request->post('ids', ''); + if (empty($ids)) { + return $this->fail('请选择要删除的数据'); + } + $result = $this->logic->destroy($ids); + if ($result) { + return $this->success('删除成功'); + } else { + return $this->fail('删除失败'); + } + } + + /** + * 获取管理员下拉列表(远程关联 SystemUser:value=id, label=name) + * @param Request $request + * @return Response + */ + #[Permission('渠道管理员列表', 'channel:manage:index:index')] + public function getAdminList(Request $request): Response + { + $list = SystemUser::where('status', 1) + ->field('id, username, realname') + ->select(); + $rows = $list->toArray(); + $data = array_map(function ($row) { + $name = !empty($row['realname']) && trim($row['realname']) !== '' + ? trim($row['realname']) + : ($row['username'] ?? '#' . $row['id']); + return [ + 'id' => $row['id'], + 'name' => $name, + ]; + }, $rows); + return $this->success($data); + } + + /** + * 为列表行附加管理员信息(避免 Eloquent with(Think 模型) 触发 getConnectionName 报错) + * @param array $rows 列表行,可为 Eloquent 模型或数组 + * @return array 已附加 admin 的列表 + */ + protected function attachAdminToRows(array $rows): array + { + if (empty($rows)) { + return $rows; + } + $adminIds = []; + foreach ($rows as $row) { + $id = is_array($row) ? ($row['admin_id'] ?? null) : $row->admin_id; + if ($id !== null && $id !== '') { + $adminIds[(string) $id] = true; + } + } + $adminIds = array_keys($adminIds); + if (empty($adminIds)) { + return $rows; + } + $admins = SystemUser::whereIn('id', $adminIds) + ->field('id, username, realname') + ->select() + ->toArray(); + $map = []; + foreach ($admins as $a) { + $map[(string) ($a['id'] ?? '')] = $a; + } + foreach ($rows as &$row) { + $aid = is_array($row) ? ($row['admin_id'] ?? null) : $row->admin_id; + $admin = $map[(string) ($aid ?? '')] ?? null; + if (is_array($row)) { + $row['admin'] = $admin; + } else { + $row->setAttribute('admin', $admin); + } + } + unset($row); + return $rows; + } + +} diff --git a/server/app/channel/logic/manage/ChannelManageLogic.php b/server/app/channel/logic/manage/ChannelManageLogic.php new file mode 100644 index 0000000..6a56a76 --- /dev/null +++ b/server/app/channel/logic/manage/ChannelManageLogic.php @@ -0,0 +1,27 @@ +model = new ChannelManage(); + } + +} diff --git a/server/app/channel/model/manage/ChannelManage.php b/server/app/channel/model/manage/ChannelManage.php new file mode 100644 index 0000000..5b2295a --- /dev/null +++ b/server/app/channel/model/manage/ChannelManage.php @@ -0,0 +1,103 @@ +where('name', 'like', '%'.$value.'%'); + } + + /** + * 标题 搜索 + */ + public function searchTitleAttr($query, $value) + { + $query->where('title', 'like', '%'.$value.'%'); + } + + /** + * 总充值 搜索 + */ + public function searchTotalRechargeAttr($query, $value) + { + $query->where('total_recharge', '>=', $value); + } + + /** + * 总提现 搜索 + */ + public function searchTotalWithdrawalAttr($query, $value) + { + $query->where('total_withdrawal', '>=', $value); + } + + /** + * 总盈利 搜索 + */ + public function searchTotalProfitAttr($query, $value) + { + $query->where('total_profit', '>=', $value); + } + + /** + * 管理员 + * 关联模型 systemUser + */ + public function admin(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(SystemUser::class, 'admin_id', 'id'); + } + +} diff --git a/server/app/channel/validate/manage/ChannelManageValidate.php b/server/app/channel/validate/manage/ChannelManageValidate.php new file mode 100644 index 0000000..83e2f2b --- /dev/null +++ b/server/app/channel/validate/manage/ChannelManageValidate.php @@ -0,0 +1,58 @@ + 'require', + 'title' => 'require', + 'admin_id' => 'require', + 'game_url' => 'require', + 'image' => 'require', + ]; + + /** + * 定义错误信息 + */ + protected $message = [ + 'name' => '名称必须填写', + 'title' => '标题必须填写', + 'admin_id' => '管理员必须填写', + 'game_url' => '游戏地址必须填写', + 'image' => '图标必须填写', + ]; + + /** + * 定义场景(agent 由后端按 md5(name.admin_id) 自动生成,无需校验) + */ + protected $scene = [ + 'save' => [ + 'name', + 'title', + 'admin_id', + 'game_url', + 'image', + ], + 'update' => [ + 'name', + 'title', + 'admin_id', + 'game_url', + 'image', + ], + ]; + +}