[渠道管理]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\game;
|
||||
namespace app\admin\controller;
|
||||
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
@@ -14,9 +14,9 @@ use Webman\Http\Request as WebmanRequest;
|
||||
class Channel extends Backend
|
||||
{
|
||||
/**
|
||||
* GameChannel模型对象
|
||||
* Channel模型对象
|
||||
* @var object|null
|
||||
* @phpstan-var \app\common\model\GameChannel|null
|
||||
* @phpstan-var \app\common\model\Channel|null
|
||||
*/
|
||||
protected ?object $model = null;
|
||||
|
||||
@@ -26,9 +26,12 @@ class Channel extends Backend
|
||||
|
||||
protected string|array $quickSearchField = ['id', 'code', 'name'];
|
||||
|
||||
private array $currentChannelIds = [];
|
||||
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
$this->model = new \app\common\model\GameChannel();
|
||||
$this->model = new \app\common\model\Channel();
|
||||
$this->currentChannelIds = $this->getCurrentChannelIds();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,11 +43,13 @@ class Channel extends Backend
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
$channels = Db::name('game_channel')
|
||||
$query = Db::name('channel')
|
||||
->field(['id', 'name', 'admin_group_id'])
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
->order('id', 'asc');
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$query = $query->where('id', 'in', $this->currentChannelIds ?: [0]);
|
||||
}
|
||||
$channels = $query->select()->toArray();
|
||||
|
||||
$groupChildrenCache = [];
|
||||
$getGroupChildren = function ($groupId) use (&$getGroupChildren, &$groupChildrenCache) {
|
||||
@@ -131,13 +136,14 @@ class Channel extends Backend
|
||||
|
||||
$data = $this->applyInputFilter($data);
|
||||
$data = $this->excludeFields($data);
|
||||
$data = $this->normalizeAgentModeFields($data);
|
||||
unset($data['invite_code']);
|
||||
|
||||
$adminId = $data['admin_id'] ?? null;
|
||||
if ($adminId === null || $adminId === '') {
|
||||
return $this->error(__('Parameter %s can not be empty', ['admin_id']));
|
||||
}
|
||||
|
||||
// 不允许前端填写,统一后端根据管理员所属“顶级角色组(pid=0)”自动回填
|
||||
if (array_key_exists('admin_group_id', $data)) {
|
||||
unset($data['admin_group_id']);
|
||||
}
|
||||
@@ -153,6 +159,10 @@ class Channel extends Backend
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
$data['admin_group_id'] = $topGroupId;
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$data['top_admin_id'] = $this->auth->id;
|
||||
$data['admin_id'] = $this->auth->id;
|
||||
}
|
||||
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$data[$this->dataLimitField] = $this->auth->id;
|
||||
@@ -198,6 +208,9 @@ class Channel extends Backend
|
||||
if (!$row) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
if (!$this->auth->isSuperAdmin() && !in_array($row['id'], $this->currentChannelIds, true)) {
|
||||
return $this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||
@@ -212,8 +225,9 @@ class Channel extends Backend
|
||||
|
||||
$data = $this->applyInputFilter($data);
|
||||
$data = $this->excludeFields($data);
|
||||
$data = $this->normalizeAgentModeFields($data);
|
||||
unset($data['invite_code']);
|
||||
|
||||
// 不允许前端填写,统一后端根据管理员所属“顶级角色组(pid=0)”自动回填
|
||||
if (array_key_exists('admin_group_id', $data)) {
|
||||
unset($data['admin_group_id']);
|
||||
}
|
||||
@@ -232,6 +246,10 @@ class Channel extends Backend
|
||||
}
|
||||
$data['admin_group_id'] = $topGroupId;
|
||||
}
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$data['top_admin_id'] = $this->auth->id;
|
||||
$data['admin_id'] = $this->auth->id;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
@@ -270,17 +288,14 @@ class Channel extends Backend
|
||||
*/
|
||||
protected function _index(): Response
|
||||
{
|
||||
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||
if ($this->request && $this->request->get('select')) {
|
||||
return $this->select($this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. withJoin 不可使用 alias 方法设置表别名,别名将自动使用关联模型名称(小写下划线命名规则)
|
||||
* 2. 以下的别名设置了主表别名,同时便于拼接查询参数等
|
||||
* 3. paginate 数据集可使用链式操作 each(function($item, $key) {}) 遍历处理
|
||||
*/
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$where[] = [$alias['channel'] . '.id', 'in', $this->currentChannelIds ?: [0]];
|
||||
}
|
||||
$res = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
@@ -297,7 +312,36 @@ class Channel extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
||||
*/
|
||||
}
|
||||
private function getCurrentChannelIds(): array
|
||||
{
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return Db::name('channel')->column('id');
|
||||
}
|
||||
$admin = Db::name('admin')
|
||||
->field(['id', 'channel_id'])
|
||||
->where('id', $this->auth->id)
|
||||
->find();
|
||||
$ids = [];
|
||||
if ($admin && !empty($admin['channel_id'])) {
|
||||
$ids[] = $admin['channel_id'];
|
||||
}
|
||||
$owned = Db::name('channel')->where('top_admin_id', $this->auth->id)->column('id');
|
||||
$created = Db::name('channel')->where('admin_id', $this->auth->id)->column('id');
|
||||
return array_values(array_unique(array_merge($ids, $owned, $created)));
|
||||
}
|
||||
|
||||
private function normalizeAgentModeFields(array $data): array
|
||||
{
|
||||
$mode = $data['agent_mode'] ?? null;
|
||||
if ($mode === 'turnover') {
|
||||
$data['affiliate_share_rate'] = null;
|
||||
$data['affiliate_fee_rate'] = null;
|
||||
$data['carryover_balance'] = 0;
|
||||
return $data;
|
||||
}
|
||||
if ($mode === 'affiliate') {
|
||||
$data['turnover_share_rate'] = null;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ namespace app\common\model;
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
* GameChannel
|
||||
* Channel
|
||||
*/
|
||||
class GameChannel extends Model
|
||||
class Channel extends Model
|
||||
{
|
||||
// 表名
|
||||
protected $name = 'game_channel';
|
||||
protected $name = 'channel';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
@@ -21,7 +21,6 @@ class GameChannel extends Model
|
||||
'update_time' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
public function getprofitAmountAttr($value): ?float
|
||||
{
|
||||
return is_null($value) ? null : (float)$value;
|
||||
@@ -36,4 +35,4 @@ class GameChannel extends Model
|
||||
{
|
||||
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class GameChannel extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
protected $message = [
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => [],
|
||||
'edit' => [],
|
||||
];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user