2.2 KiB
2.2 KiB
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
CentsToPointsto(cents * rate) / 100. - Updated
PointsToCentsto(points * 100) / rate. - Added unit tests to verify 100 Cents = 1 Point.
- Updated
- Service Layer (
internal/service/user):- Updated
points_convert.goto usepoints_exchange_rateconfig key. - Added
PointsToCentsmethod for reverse calculation. - Updated
lottery_app.goto usePointsToCentsfor accurate deduction calculation.
- Updated
- DB Config:
- Expects
points_exchange_rate(default 1) instead ofpoints_exchange_per_cent.
- Expects
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.vuepages-user/orders/detail.vuepages-user/tasks/index.vuepages/shop/index.vue(Fixed/ 100division for points)pages-shop/shop/detail.vue(Fixed/ 100division for points)
- Changes:
- Removed incorrect
/ 100division for Points display while keeping it for Money (Yuan) display. - formated points to use
.toFixed(0)to remove decimal places.
- Removed incorrect
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:
TestCentsToPointsconfirmed 100 Cents -> 1 Point.TestRefundPointsAmountconfirmed proportional refund works with integer points.
4. Next Steps for User
- Backup Database.
- Deploy Backend & Admin.
- Run Migration Script (
docs/standardize_points_ratio/migration.sql). - Deploy Mini Program.