'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) ->whereLike('void_reason', 'system_recover:%') ->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'] : ''); $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' => (string) ($row['void_reason'] ?? ''), ]; } 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 ($reason === '' || str_starts_with($reason, 'system_recover:') === false) { return $meta; } $payload = substr($reason, strlen('system_recover:')); $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; } }