121 lines
3.5 KiB
PHP
121 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\game;
|
|
|
|
use app\common\controller\Backend;
|
|
use support\Response;
|
|
use Webman\Http\Request as WebmanRequest;
|
|
|
|
/**
|
|
* 游玩记录(原压注订单)
|
|
*/
|
|
class PlayRecord extends Backend
|
|
{
|
|
protected ?object $model = null;
|
|
|
|
protected bool $modelValidate = false;
|
|
|
|
protected string|array $quickSearchField = ['id', 'period_no', 'idempotency_key'];
|
|
|
|
protected string|array $defaultSortField = ['id' => 'desc'];
|
|
|
|
protected string|array $orderGuarantee = ['id' => 'desc'];
|
|
|
|
protected array $withJoinTable = ['user', 'channel', 'gameRecord'];
|
|
|
|
protected function initController(WebmanRequest $request): ?Response
|
|
{
|
|
$this->model = new \app\common\model\PlayRecord();
|
|
return null;
|
|
}
|
|
|
|
public function add(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error(__('Play record is generated by game API; manual creation is not allowed'));
|
|
}
|
|
|
|
public function edit(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error(__('Play record cannot be edited'));
|
|
}
|
|
|
|
public function del(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error(__('Play record cannot be deleted'));
|
|
}
|
|
|
|
public function sortable(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error(__('Sorting is not supported'));
|
|
}
|
|
|
|
protected function _index(): Response
|
|
{
|
|
if ($this->request && $this->request->get('select')) {
|
|
return $this->select($this->request);
|
|
}
|
|
|
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
|
$table = strtolower($this->model->getTable());
|
|
$mainShort = $alias[$table] ?? '';
|
|
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
|
$where[] = ['user.admin_id', 'in', $this->scopedAdminIds()];
|
|
}
|
|
|
|
$res = $this->model
|
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
|
->with($this->withJoinTable)
|
|
->visible([
|
|
'user' => ['username', 'phone'],
|
|
'channel' => ['name'],
|
|
'gameRecord' => ['period_no', 'status'],
|
|
])
|
|
->alias($alias)
|
|
->where($where)
|
|
->order($order)
|
|
->paginate($limit);
|
|
|
|
return $this->success('', [
|
|
'list' => $res->items(),
|
|
'total' => $res->total(),
|
|
'remark' => get_route_remark(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return int[]
|
|
*/
|
|
private function scopedAdminIds(): array
|
|
{
|
|
if (!$this->auth) {
|
|
return [0];
|
|
}
|
|
if ($this->auth->isSuperAdmin()) {
|
|
return [];
|
|
}
|
|
$groupIds = $this->auth->getAdminChildGroups();
|
|
$adminIds = $groupIds ? $this->auth->getGroupAdmins($groupIds) : [];
|
|
$adminIds[] = $this->auth->id;
|
|
$adminIds = array_map(static fn($id) => intval(strval($id)), $adminIds);
|
|
$adminIds = array_values(array_unique(array_filter($adminIds, static fn($id) => $id > 0)));
|
|
return $adminIds === [] ? [0] : $adminIds;
|
|
}
|
|
}
|
|
|