# Walkthrough: Standardize Points Ratio

## 1. Goal
Standardize the Points-to-Yuan ratio to **1 Yuan = 1 Point**, and remove the decimal display logic (previous 100 Points = 1 Yuan) across the system.

## 2. Changes

### Backend (`bindbox_game`)
- **Core Logic (`internal/pkg/points/convert.go`)**:
    - Updated `CentsToPoints` to `(cents * rate) / 100`.
    - Updated `PointsToCents` to `(points * 100) / rate`.
    - Added unit tests to verify 100 Cents = 1 Point.
- **Service Layer (`internal/service/user`)**:
    - Updated `points_convert.go` to use `points_exchange_rate` config key.
    - Added `PointsToCents` method for reverse calculation.
    - Updated `lottery_app.go` to use `PointsToCents` for accurate deduction calculation.
- **DB Config**:
    - Expects `points_exchange_rate` (default 1) instead of `points_exchange_per_cent`.

### Admin Frontend (`web/admin`)
- **System Configs**:
    - Added "Points Configuration" section.
    - Allows setting "1 Yuan = N Points" (Default 1).

### Mini-Program Frontend Display Logic
- **Goal**: Ensure Points are displayed as integers and values are consistent.
- **Files Modified**:
    - `pages-user/points/index.vue`
    - `pages-user/orders/detail.vue`
    - `pages-user/tasks/index.vue`
    - `pages/shop/index.vue` (Fixed `/ 100` division for points)
    - `pages-shop/shop/detail.vue` (Fixed `/ 100` division for points)
- **Changes**:
    - Removed incorrect `/ 100` division for Points display while keeping it for Money (Yuan) display.
    - formated points to use `.toFixed(0)` to remove decimal places.

### Database Migration
- **Script**: `docs/standardize_points_ratio/migration.sql`
- **Action Required**: Run this script to shrink existing point values by 100x to match the new 1:1 definition.

## 3. Verification
- **Unit Tests**:
    - `go test internal/pkg/points/...` passed.
- **Manual Check**:
    - `TestCentsToPoints` confirmed 100 Cents -> 1 Point.
    - `TestRefundPointsAmount` confirmed proportional refund works with integer points.

## 4. Next Steps for User
1. **Backup Database**.
2. **Deploy Backend & Admin**.
3. **Run Migration Script** (`docs/standardize_points_ratio/migration.sql`).
4. **Deploy Mini Program**.
