---
phase: 01
plan: 01
subsystem: admin
tags: [lottery, missing-number, backend]
dependency_graph:
  requires: []
  provides: [missingNum endpoint, getMissingNumbers model method, i18n keys]
  affects: [application/admin/model/History.php, application/admin/controller/History.php, application/admin/lang/zh-cn/history.php]
tech-stack:
  added: []
  patterns: [FastAdmin Backend controller, ThinkPHP 5.x Model, Db facade]
key-files:
  created:
    - application/admin/model/History.php
    - application/admin/controller/History.php
    - application/admin/lang/zh-cn/history.php
  modified: []
decisions:
  - Used $noNeedRight = ['missingNum'] instead of ['*'] for minimal permission bypass
  - Model queries up to 500 historical records for true omission count calculation
  - Color fallback uses '—' string when fa_num table has no mapping for a number
metrics:
  duration: ~5min
  completed: "2026-04-21"
---

# Phase 01 Plan 01: Backend Missing Number Logic Summary

Backend missing number calculation logic and AJAX endpoint — History model with `getMissingNumbers()` + `calcOmitCount()` methods, History controller with `missingNum()` endpoint, and i18n language keys for the missing number feature.

## Tasks Completed

| # | Task | Commit | Files |
|---|------|--------|-------|
| 1 | Add getMissingNumbers() and calcOmitCount() to History model | 6386a40 | application/admin/model/History.php |
| 2 | Add missingNum() AJAX endpoint to History controller | 15bb870 | application/admin/controller/History.php |
| 3 | Add i18n text keys to language file | 96d5e78 | application/admin/lang/zh-cn/history.php |

## One-liner

History model `getMissingNumbers()` computes missing lottery numbers (1-49) with true omission counts from up to 500 historical records, controller `missingNum()` validates periods (1-100) and returns JSON, i18n file provides Chinese translations.

## Key Decisions

- **$noNeedRight minimal scope**: Only `missingNum` method is exempted from permission checks (not `['*']`), following least-privilege principle.
- **500-record limit for omission calculation**: Queries up to 500 historical records to calculate true omission counts (last appearance distance), not just "appeared/not appeared" in the query window.
- **Color fallback**: Returns `'—'` when fa_num table lacks a wave color mapping for a given number.

## Deviations from Plan

None - plan executed exactly as written.

## Known Stubs

None.

## Threat Flags

None beyond what was identified in the plan's threat model (T-01-01 through T-01-04).

## Self-Check

- Model file exists with both methods: PASS
- Controller file exists with missingNum endpoint: PASS
- Lang file exists with all i18n keys: PASS
- All 3 commits present in git log: PASS

## Self-Check: PASSED
