feat: 迭代
This commit is contained in:
+4
-4
@@ -159,11 +159,11 @@ source database/migrations/001_init_schema.sql;
|
||||
|
||||
# 方式3:初始化系统总账户和平台账户
|
||||
USE your_database_name;
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn)
|
||||
VALUES ('系统总账户', 0.00, 0.00, 0.00, 0.00);
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn, status)
|
||||
VALUES ('SYSTEM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
|
||||
INSERT INTO platform_accounts (account_name, balance, total_income, total_expense)
|
||||
VALUES ('主账户', 0.00, 0.00, 0.00);
|
||||
INSERT INTO platform_accounts (account_name, balance, frozen_balance, total_income, total_expense, status)
|
||||
VALUES ('PLATFORM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -434,7 +434,7 @@ try {
|
||||
|
||||
```typescript
|
||||
const account = await queryRunner.manager.findOne(SystemAccount, {
|
||||
where: { account_name: '系统总账户' },
|
||||
where: { account_name: 'SYSTEM_MAIN' },
|
||||
lock: { mode: 'pessimistic_write' },
|
||||
});
|
||||
```
|
||||
@@ -497,12 +497,12 @@ mysql -u root -p < database/migrations/001_init_schema.sql
|
||||
# 2. 初始化系统总账户
|
||||
mysql -u root -p
|
||||
USE your_database_name;
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn)
|
||||
VALUES ('系统总账户', 0.00, 0.00, 0.00, 0.00);
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn, status)
|
||||
VALUES ('SYSTEM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
|
||||
# 3. 初始化平台账户
|
||||
INSERT INTO platform_accounts (account_name, balance, total_income, total_expense)
|
||||
VALUES ('主账户', 0.00, 0.00, 0.00);
|
||||
INSERT INTO platform_accounts (account_name, balance, frozen_balance, total_income, total_expense, status)
|
||||
VALUES ('PLATFORM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
```
|
||||
|
||||
### 3. 自动创建的数据
|
||||
|
||||
@@ -44,6 +44,43 @@
|
||||
|
||||
## 账户体系
|
||||
|
||||
### 账户名称常量说明
|
||||
|
||||
为了提高代码可维护性和国际化支持,系统账户名称采用英文常量存储,前端显示时映射为中文。
|
||||
|
||||
**账户名称映射表:**
|
||||
|
||||
| 英文常量 (数据库存储) | 中文显示名称 | 说明 |
|
||||
|---------------------|------------|------|
|
||||
| `SYSTEM_MAIN` | 系统总账户 | 记录整个系统的资金流入流出,用于资金守恒验证 |
|
||||
| `PLATFORM_MAIN` | 平台主账户 | 平台的主要收益账户,记录服务费收入和邀请返现支出 |
|
||||
| `PLATFORM_BACKUP` | 平台备用账户 | 平台的备用账户(可选) |
|
||||
|
||||
**后端使用:**
|
||||
```typescript
|
||||
// 导入常量
|
||||
import { ACCOUNT_NAMES } from '@/constants/account.constant';
|
||||
|
||||
// 使用常量查询
|
||||
const systemAccount = await this.systemAccountRepo.findOne({
|
||||
where: { account_name: ACCOUNT_NAMES.SYSTEM_MAIN }
|
||||
});
|
||||
|
||||
const platformAccount = await this.platformAccountRepo.findOne({
|
||||
where: { account_name: ACCOUNT_NAMES.PLATFORM_MAIN }
|
||||
});
|
||||
```
|
||||
|
||||
**前端使用:**
|
||||
```typescript
|
||||
// 导入映射工具
|
||||
import { getAccountDisplayName } from '@/utils/accountNameMap';
|
||||
|
||||
// 将英文常量转换为中文显示
|
||||
const displayName = getAccountDisplayName('SYSTEM_MAIN'); // 返回:系统总账户
|
||||
const displayName2 = getAccountDisplayName('PLATFORM_MAIN'); // 返回:平台主账户
|
||||
```
|
||||
|
||||
### 四层账户结构
|
||||
|
||||
系统采用四层账户结构,确保资金流转清晰、职责明确:
|
||||
@@ -955,14 +992,19 @@ mysql -u root -p < database/migrations/001_init_schema.sql
|
||||
|
||||
2. 初始化系统总账户:
|
||||
```sql
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn)
|
||||
VALUES ('系统总账户', 0.00, 0.00, 0.00, 0.00);
|
||||
INSERT INTO system_accounts (account_name, balance, total_income, total_refund, total_withdrawn, status)
|
||||
VALUES ('SYSTEM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
```
|
||||
|
||||
3. 初始化平台账户:
|
||||
```sql
|
||||
INSERT INTO platform_accounts (account_name, balance, total_income, total_expense)
|
||||
VALUES ('主账户', 0.00, 0.00, 0.00);
|
||||
INSERT INTO platform_accounts (account_name, balance, frozen_balance, total_income, total_expense, status)
|
||||
VALUES ('PLATFORM_MAIN', 0.00, 0.00, 0.00, 0.00, 'active');
|
||||
```
|
||||
|
||||
或者直接执行种子数据脚本:
|
||||
```bash
|
||||
mysql -u root -p rent_platform < database/seeds/001_init_data.sql
|
||||
```
|
||||
|
||||
### 服务启动
|
||||
|
||||
Reference in New Issue
Block a user