170 lines
5.2 KiB
PHP
170 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\game;
|
|
|
|
use app\common\controller\Backend;
|
|
use support\think\Db;
|
|
use support\Response;
|
|
use Webman\Http\Request as WebmanRequest;
|
|
|
|
/**
|
|
* 游戏对局记录
|
|
*/
|
|
class Record extends Backend
|
|
{
|
|
protected ?object $model = null;
|
|
|
|
protected string|array $preExcludeFields = ['id', 'create_time', 'update_time', 'platform_profit_amount', 'winner_user_count'];
|
|
|
|
protected string|array $quickSearchField = ['id', 'period_no'];
|
|
|
|
protected string|array $defaultSortField = ['id' => 'desc'];
|
|
|
|
protected string|array $orderGuarantee = ['id' => 'desc'];
|
|
|
|
protected bool $modelValidate = true;
|
|
|
|
protected bool $modelSceneValidate = true;
|
|
|
|
protected function initController(WebmanRequest $request): ?Response
|
|
{
|
|
$this->model = new \app\common\model\GameRecord();
|
|
return null;
|
|
}
|
|
|
|
public function add(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error('游戏对局记录由系统自动生成,禁止后台手工新增');
|
|
}
|
|
|
|
public function edit(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
if ($request->method() === 'POST') {
|
|
return $this->error('游戏对局记录不可编辑');
|
|
}
|
|
$pk = $this->model->getPk();
|
|
$id = $request->get($pk);
|
|
$row = $this->model->find($id);
|
|
if (!$row) {
|
|
return $this->error(__('Record not found'));
|
|
}
|
|
return $this->success('', ['row' => $row]);
|
|
}
|
|
|
|
public function del(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
return $this->error('游戏对局记录不可删除');
|
|
}
|
|
|
|
public function abnormalList(WebmanRequest $request): Response
|
|
{
|
|
$response = $this->initializeBackend($request);
|
|
if ($response !== null) {
|
|
return $response;
|
|
}
|
|
|
|
$limitRaw = $request->get('limit', 30);
|
|
$limit = is_numeric((string) $limitRaw) ? (int) $limitRaw : 30;
|
|
if ($limit < 1) {
|
|
$limit = 1;
|
|
}
|
|
if ($limit > 200) {
|
|
$limit = 200;
|
|
}
|
|
|
|
$rows = Db::name('game_record')
|
|
->where('status', 5)
|
|
->field(['id', 'period_no', 'void_reason', 'update_time'])
|
|
->order('id', 'desc')
|
|
->limit($limit)
|
|
->select()
|
|
->toArray();
|
|
|
|
$list = [];
|
|
foreach ($rows as $row) {
|
|
$meta = $this->parseRecoverVoidReason(is_string($row['void_reason'] ?? null) ? $row['void_reason'] : '');
|
|
$reason = is_string($row['void_reason'] ?? null) ? $row['void_reason'] : '';
|
|
$isAutoRecover = $this->isSystemRecoverReason($reason);
|
|
$list[] = [
|
|
'id' => (int) ($row['id'] ?? 0),
|
|
'period_no' => (string) ($row['period_no'] ?? ''),
|
|
'abnormal_from_status' => $meta['from_status'],
|
|
'refunded_user_count' => $meta['users'],
|
|
'refunded_order_count' => $meta['orders'],
|
|
'refunded_total_amount' => $meta['amount'],
|
|
'recovered_at' => (int) ($row['update_time'] ?? 0),
|
|
'void_reason' => $reason,
|
|
'is_auto_recover' => $isAutoRecover ? 1 : 0,
|
|
];
|
|
}
|
|
|
|
return $this->success('', [
|
|
'list' => $list,
|
|
'total' => count($list),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array{from_status:int,users:int,orders:int,amount:string}
|
|
*/
|
|
private function parseRecoverVoidReason(string $reason): array
|
|
{
|
|
$meta = [
|
|
'from_status' => -1,
|
|
'users' => 0,
|
|
'orders' => 0,
|
|
'amount' => '0.00',
|
|
];
|
|
if (!$this->isSystemRecoverReason($reason)) {
|
|
return $meta;
|
|
}
|
|
$payload = substr($reason, strlen('system_recover:'));
|
|
if (!str_contains($payload, '=')) {
|
|
return $meta;
|
|
}
|
|
$parts = explode('|', $payload);
|
|
foreach ($parts as $part) {
|
|
$item = trim($part);
|
|
if ($item === '' || !str_contains($item, '=')) {
|
|
continue;
|
|
}
|
|
[$key, $value] = explode('=', $item, 2);
|
|
$key = trim($key);
|
|
$value = trim($value);
|
|
if ($key === 'from' && is_numeric($value)) {
|
|
$meta['from_status'] = (int) $value;
|
|
continue;
|
|
}
|
|
if ($key === 'users' && is_numeric($value)) {
|
|
$meta['users'] = (int) $value;
|
|
continue;
|
|
}
|
|
if ($key === 'orders' && is_numeric($value)) {
|
|
$meta['orders'] = (int) $value;
|
|
continue;
|
|
}
|
|
if ($key === 'amount' && $value !== '') {
|
|
$meta['amount'] = $value;
|
|
}
|
|
}
|
|
return $meta;
|
|
}
|
|
|
|
private function isSystemRecoverReason(string $reason): bool
|
|
{
|
|
return $reason !== '' && str_starts_with($reason, 'system_recover:');
|
|
}
|
|
}
|