5阶段任务

This commit is contained in:
zpc 2026-01-02 20:38:29 +08:00
parent a1e457db06
commit d728b97c9e
3 changed files with 1029 additions and 0 deletions

View File

@ -0,0 +1,486 @@
# Design Document: 订单系统迁移
## Overview
本设计文档描述将PHP订单系统迁移到.NET 8的技术方案。订单系统是抽奖盲盒平台的核心业务模块涉及订单金额计算、订单创建支付、订单查询管理、仓库/盒柜管理等功能。
## Architecture
### 系统架构
```
┌─────────────────────────────────────────────────────────────┐
│ API Layer │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ OrderController │ │WarehouseController│ │
│ └────────┬────────┘ └────────┬────────┘ │
└───────────┼─────────────────────┼───────────────────────────┘
│ │
┌───────────┼─────────────────────┼───────────────────────────┐
│ ▼ ▼ Service Layer │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ OrderService │ │WarehouseService │ │
│ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │
│ ┌────────┴────────┐ ┌────────┴────────┐ │
│ │OrderCalculation │ │ PrizeService │ │
│ │ Service │ │ │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│ │
┌───────────┼─────────────────────┼───────────────────────────┐
│ ▼ ▼ Data Layer │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ HoneyBoxDbContext │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌───────────┐ │ │
│ │ │ Orders │ │OrderList│ │Delivery │ │ Recovery │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └───────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
## Components and Interfaces
### 1. OrderController
```csharp
[ApiController]
[Route("api")]
public class OrderController : ControllerBase
{
// 一番赏订单金额计算
[HttpPost("ordermoney")]
Task<ApiResponse<OrderCalculationDto>> CalculateOrderMoney(OrderMoneyRequest request);
// 一番赏订单创建
[HttpPost("orderbuy")]
Task<ApiResponse<OrderBuyResponseDto>> CreateOrder(OrderBuyRequest request);
// 无限赏订单金额计算
[HttpPost("infinite_ordermoney")]
Task<ApiResponse<OrderCalculationDto>> CalculateInfiniteOrderMoney(InfiniteOrderMoneyRequest request);
// 无限赏订单创建
[HttpPost("infinite_orderbuy")]
Task<ApiResponse<OrderBuyResponseDto>> CreateInfiniteOrder(InfiniteOrderBuyRequest request);
// 商城订单金额计算
[HttpPost("mall_ordermoney")]
Task<ApiResponse<OrderCalculationDto>> CalculateMallOrderMoney(MallOrderMoneyRequest request);
// 订单列表
[HttpPost("order_list")]
Task<ApiResponse<PageResponse<OrderListDto>>> GetOrderList(OrderListRequest request);
// 订单详情
[HttpPost("order_detail")]
Task<ApiResponse<OrderDetailDto>> GetOrderDetail(OrderDetailRequest request);
// 一番赏抽奖结果
[HttpPost("prizeorderlog")]
Task<ApiResponse<List<PrizeOrderLogDto>>> GetPrizeOrderLog(PrizeOrderLogRequest request);
// 无限赏抽奖结果
[HttpPost("infinite_prizeorderlog")]
Task<ApiResponse<List<PrizeOrderLogDto>>> GetInfinitePrizeOrderLog(PrizeOrderLogRequest request);
}
```
### 2. WarehouseController
```csharp
[ApiController]
[Route("api")]
public class WarehouseController : ControllerBase
{
// 仓库首页
[HttpPost("warehouse_index")]
Task<ApiResponse<PageResponse<WarehouseItemDto>>> GetWarehouseIndex(WarehouseIndexRequest request);
// 奖品回收
[HttpPost("warehouse_recovery")]
Task<ApiResponse<RecoveryResultDto>> RecoveryPrizes(RecoveryRequest request);
// 奖品发货
[HttpPost("warehouse_send")]
Task<ApiResponse<SendResultDto>> SendPrizes(SendRequest request);
// 确认发货
[HttpPost("warehouse_send_confirm")]
Task<ApiResponse> ConfirmSend(ConfirmSendRequest request);
// 发货记录
[HttpPost("warehouse_send_record")]
Task<ApiResponse<PageResponse<SendRecordDto>>> GetSendRecords(SendRecordRequest request);
// 发货记录详情
[HttpPost("warehouse_send_record_detail")]
Task<ApiResponse<SendRecordDetailDto>> GetSendRecordDetail(SendRecordDetailRequest request);
// 回收记录
[HttpPost("warehouse_recovery_record")]
Task<ApiResponse<PageResponse<RecoveryRecordDto>>> GetRecoveryRecords(RecoveryRecordRequest request);
// 物流信息
[HttpPost("warehouse_order_logistics")]
Task<ApiResponse<LogisticsDto>> GetLogistics(LogisticsRequest request);
}
```
### 3. IOrderService
```csharp
public interface IOrderService
{
// 订单金额计算
Task<OrderCalculationDto> CalculateOrderMoneyAsync(int userId, OrderMoneyRequest request);
Task<OrderCalculationDto> CalculateInfiniteOrderMoneyAsync(int userId, InfiniteOrderMoneyRequest request);
Task<OrderCalculationDto> CalculateMallOrderMoneyAsync(int userId, MallOrderMoneyRequest request);
// 订单创建
Task<OrderBuyResponseDto> CreateOrderAsync(int userId, OrderBuyRequest request);
Task<OrderBuyResponseDto> CreateInfiniteOrderAsync(int userId, InfiniteOrderBuyRequest request);
// 订单查询
Task<PageResponse<OrderListDto>> GetOrderListAsync(int userId, OrderListRequest request);
Task<OrderDetailDto> GetOrderDetailAsync(int userId, string orderNum);
// 抽奖结果
Task<List<PrizeOrderLogDto>> GetPrizeOrderLogAsync(int userId, string orderNum);
Task<List<PrizeOrderLogDto>> GetInfinitePrizeOrderLogAsync(int userId, string orderNum);
}
```
### 4. IWarehouseService
```csharp
public interface IWarehouseService
{
// 仓库查询
Task<PageResponse<WarehouseItemDto>> GetWarehouseIndexAsync(int userId, int page, int status);
// 奖品回收
Task<RecoveryResultDto> RecoveryPrizesAsync(int userId, string orderListIds);
// 奖品发货
Task<SendResultDto> SendPrizesAsync(int userId, SendRequest request);
Task<bool> ConfirmSendAsync(int userId, int id);
// 记录查询
Task<PageResponse<SendRecordDto>> GetSendRecordsAsync(int userId, int page);
Task<SendRecordDetailDto> GetSendRecordDetailAsync(int userId, int id);
Task<PageResponse<RecoveryRecordDto>> GetRecoveryRecordsAsync(int userId, int page);
// 物流查询
Task<LogisticsDto> GetLogisticsAsync(int userId, int id);
}
```
## Data Models
### Request Models
```csharp
// 一番赏订单金额计算请求
public class OrderMoneyRequest
{
[JsonPropertyName("goods_id")]
public int GoodsId { get; set; }
[JsonPropertyName("num")]
public int Num { get; set; }
[JsonPropertyName("prize_num")]
public int PrizeNum { get; set; }
[JsonPropertyName("coupon_id")]
public string? CouponId { get; set; }
[JsonPropertyName("use_money_is")]
public int UseMoneyIs { get; set; } = 2;
[JsonPropertyName("use_integral_is")]
public int UseIntegralIs { get; set; } = 2;
[JsonPropertyName("use_money2_is")]
public int UseMoney2Is { get; set; } = 2;
}
// 无限赏订单金额计算请求
public class InfiniteOrderMoneyRequest
{
[JsonPropertyName("goods_id")]
public int GoodsId { get; set; }
[JsonPropertyName("prize_num")]
public int PrizeNum { get; set; }
[JsonPropertyName("use_money_is")]
public int UseMoneyIs { get; set; } = 2;
[JsonPropertyName("use_integral_is")]
public int UseIntegralIs { get; set; } = 2;
[JsonPropertyName("use_money2_is")]
public int UseMoney2Is { get; set; } = 2;
[JsonPropertyName("coupon_id")]
public string? CouponId { get; set; }
}
// 商城订单金额计算请求
public class MallOrderMoneyRequest
{
[JsonPropertyName("goods_id")]
public int GoodsId { get; set; }
[JsonPropertyName("prize_num")]
public int PrizeNum { get; set; }
[JsonPropertyName("goods_num")]
public int GoodsNum { get; set; }
[JsonPropertyName("use_money_is")]
public int UseMoneyIs { get; set; } = 2;
[JsonPropertyName("use_integral_is")]
public int UseIntegralIs { get; set; } = 2;
[JsonPropertyName("use_money2_is")]
public int UseMoney2Is { get; set; } = 2;
}
// 仓库首页请求
public class WarehouseIndexRequest
{
[JsonPropertyName("page")]
public int Page { get; set; } = 1;
[JsonPropertyName("status")]
public int Status { get; set; } = 0;
}
// 发货请求
public class SendRequest
{
[JsonPropertyName("order_list_ids")]
public string OrderListIds { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("mobile")]
public string Mobile { get; set; } = string.Empty;
[JsonPropertyName("address")]
public string Address { get; set; } = string.Empty;
[JsonPropertyName("message")]
public string? Message { get; set; }
}
```
### Response Models
```csharp
// 订单金额计算响应
public class OrderCalculationDto
{
[JsonPropertyName("order_total")]
public string OrderTotal { get; set; } = "0.00";
[JsonPropertyName("price")]
public string Price { get; set; } = "0.00";
[JsonPropertyName("goods_info")]
public GoodsInfoDto? GoodsInfo { get; set; }
[JsonPropertyName("goodsExtend")]
public GoodsExtendDto? GoodsExtend { get; set; }
[JsonPropertyName("user_money")]
public string UserMoney { get; set; } = "0.00";
[JsonPropertyName("user_integral")]
public string UserIntegral { get; set; } = "0.00";
[JsonPropertyName("user_money2")]
public string UserMoney2 { get; set; } = "0.00";
}
// 订单创建响应
public class OrderBuyResponseDto
{
[JsonPropertyName("status")]
public int Status { get; set; }
[JsonPropertyName("order_num")]
public string OrderNum { get; set; } = string.Empty;
[JsonPropertyName("res")]
public WechatPayParamsDto? Res { get; set; }
}
// 微信支付参数
public class WechatPayParamsDto
{
[JsonPropertyName("appId")]
public string AppId { get; set; } = string.Empty;
[JsonPropertyName("timeStamp")]
public string TimeStamp { get; set; } = string.Empty;
[JsonPropertyName("nonceStr")]
public string NonceStr { get; set; } = string.Empty;
[JsonPropertyName("package")]
public string Package { get; set; } = string.Empty;
[JsonPropertyName("signType")]
public string SignType { get; set; } = "RSA";
[JsonPropertyName("paySign")]
public string PaySign { get; set; } = string.Empty;
}
// 订单列表项
public class OrderListDto
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("order_num")]
public string OrderNum { get; set; } = string.Empty;
[JsonPropertyName("goods_title")]
public string GoodsTitle { get; set; } = string.Empty;
[JsonPropertyName("goods_imgurl")]
public string GoodsImgUrl { get; set; } = string.Empty;
[JsonPropertyName("order_total")]
public string OrderTotal { get; set; } = "0.00";
[JsonPropertyName("price")]
public string Price { get; set; } = "0.00";
[JsonPropertyName("prize_num")]
public int PrizeNum { get; set; }
[JsonPropertyName("status")]
public int Status { get; set; }
[JsonPropertyName("addtime")]
public long AddTime { get; set; }
[JsonPropertyName("pay_time")]
public long? PayTime { get; set; }
}
// 仓库物品
public class WarehouseItemDto
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("goodslist_title")]
public string GoodsListTitle { get; set; } = string.Empty;
[JsonPropertyName("goodslist_imgurl")]
public string GoodsListImgUrl { get; set; } = string.Empty;
[JsonPropertyName("goodslist_price")]
public string GoodsListPrice { get; set; } = "0.00";
[JsonPropertyName("goodslist_money")]
public string GoodsListMoney { get; set; } = "0.00";
[JsonPropertyName("status")]
public int Status { get; set; }
[JsonPropertyName("addtime")]
public long AddTime { get; set; }
}
```
## Correctness Properties
*A property is a characteristic or behavior that should hold true across all valid executions of a system-essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
### Property 1: 订单金额计算正确性
*For any* order calculation request with valid goods_id and prize_num, the calculated order_total should equal price * prize_num minus any applicable discounts (coupon, balance, integral, money2).
**Validates: Requirements 1.1, 1.2, 1.3, 1.4, 1.5**
### Property 2: 订单创建数据完整性
*For any* successfully created order, the order record should contain all required fields (order_num, goods_id, user_id, order_total, status) and the order_num should be unique.
**Validates: Requirements 2.1, 2.2**
### Property 3: 仓库物品状态一致性
*For any* warehouse item, after recovery operation, the item status should be updated to recovered (status=1) and the user's balance should increase by the recovery amount.
**Validates: Requirements 11.2, 11.3**
### Property 4: 发货记录完整性
*For any* delivery request with valid order_list_ids and address info, a delivery record should be created with all items linked and status set to pending.
**Validates: Requirements 12.1, 12.2, 12.3, 12.4**
### Property 5: 订单列表分页正确性
*For any* order list request, the returned data should be correctly paginated and the last_page value should accurately reflect the total number of pages.
**Validates: Requirements 6.1, 6.3, 6.4**
## Error Handling
### 订单相关错误
| 错误场景 | 错误码 | 错误消息 |
|---------|--------|---------|
| 商品不存在 | 0 | 商品不存在 |
| 库存不足 | 0 | 库存不足 |
| 超出购买限制 | 0 | 超出购买限制 |
| 订单不存在 | 0 | 订单不存在 |
| 无权访问订单 | 0 | 无权访问该订单 |
| 优惠券无效 | 0 | 优惠券无效或已过期 |
### 仓库相关错误
| 错误场景 | 错误码 | 错误消息 |
|---------|--------|---------|
| 奖品不存在 | 0 | 奖品不存在 |
| 奖品不可回收 | 0 | 该奖品不可回收 |
| 奖品不可发货 | 0 | 该奖品不可发货 |
| 地址信息不完整 | 0 | 请填写完整的收货信息 |
| 发货记录不存在 | 0 | 发货记录不存在 |
## Testing Strategy
### 单元测试
- 测试订单金额计算逻辑的各种场景
- 测试优惠券、余额、积分抵扣逻辑
- 测试仓库物品状态转换逻辑
- 测试分页逻辑
### 属性测试
使用xUnit和FsCheck进行属性测试
- Property 1: 订单金额计算正确性
- Property 2: 订单创建数据完整性
- Property 3: 仓库物品状态一致性
- Property 4: 发货记录完整性
- Property 5: 订单列表分页正确性
### 集成测试
- 测试完整的订单创建流程
- 测试仓库回收和发货流程
- 测试API响应格式兼容性

View File

@ -0,0 +1,208 @@
# Requirements Document
## Introduction
本文档定义了将PHP订单系统迁移到.NET 8的需求规范。订单系统是抽奖盲盒平台的核心业务模块包括订单金额计算、订单创建支付、订单查询管理、仓库/盒柜管理等功能。
## Glossary
- **Order_System**: 订单系统,负责处理用户下单、支付、订单管理等业务
- **Order_Service**: 订单服务,提供订单相关的业务逻辑处理
- **Warehouse_Service**: 仓库服务,提供奖品回收、发货等功能
- **Order_Controller**: 订单控制器处理订单相关的HTTP请求
- **Warehouse_Controller**: 仓库控制器处理仓库相关的HTTP请求
- **一番赏**: 一种抽奖商品类型,有固定奖池
- **无限赏**: 一种抽奖商品类型,奖池无限
- **商城订单**: 直接购买商品的订单类型
- **盒柜**: 用户的奖品仓库,存放中奖的奖品
## Requirements
### Requirement 1: 一番赏订单金额计算
**User Story:** As a user, I want to calculate the order amount before placing an order, so that I can know the final payment amount after applying discounts.
#### Acceptance Criteria
1. WHEN a user requests order calculation with goods_id, num, prize_num, THE Order_Service SHALL return the calculated order amount
2. WHEN use_money_is is 1, THE Order_Service SHALL deduct available balance from the order total
3. WHEN use_integral_is is 1, THE Order_Service SHALL deduct available integral from the order total
4. WHEN use_money2_is is 1, THE Order_Service SHALL deduct available money2 (哈尼券) from the order total
5. WHEN a valid coupon_id is provided, THE Order_Service SHALL apply the coupon discount to the order
6. THE Order_Service SHALL return goods_info, calculation details, user_assets, and available_coupons in the response
### Requirement 2: 一番赏订单创建
**User Story:** As a user, I want to create an order and pay for it, so that I can participate in the lottery.
#### Acceptance Criteria
1. WHEN a user submits an order with valid parameters, THE Order_Service SHALL create an order record
2. WHEN the order is created successfully, THE Order_Service SHALL return order_num and payment info
3. WHEN using WeChat payment, THE Order_Service SHALL return WeChat pay parameters (appId, timeStamp, nonceStr, package, signType, paySign)
4. WHEN the order total is 0 (fully paid by balance/integral), THE Order_Service SHALL mark the order as paid immediately
5. IF the goods stock is insufficient, THEN THE Order_Service SHALL return an error message
6. IF the user exceeds purchase limits, THEN THE Order_Service SHALL return an error message
### Requirement 3: 无限赏订单金额计算
**User Story:** As a user, I want to calculate the infinite lottery order amount, so that I can know the payment details.
#### Acceptance Criteria
1. WHEN a user requests infinite order calculation, THE Order_Service SHALL return the calculated amount
2. THE Order_Service SHALL support the same discount options as regular orders (balance, integral, money2, coupon)
3. THE Order_Service SHALL validate the goods type is infinite lottery (type=2)
### Requirement 4: 无限赏订单创建
**User Story:** As a user, I want to create an infinite lottery order, so that I can participate in the infinite lottery.
#### Acceptance Criteria
1. WHEN a user submits an infinite order, THE Order_Service SHALL create the order with order_type=2
2. THE Order_Service SHALL handle the infinite lottery specific logic
3. THE Order_Service SHALL return order_num and payment info
### Requirement 5: 商城订单金额计算
**User Story:** As a user, I want to calculate the mall order amount, so that I can purchase products directly.
#### Acceptance Criteria
1. WHEN a user requests mall order calculation, THE Order_Service SHALL return the calculated amount
2. THE Order_Service SHALL support goods_num parameter for quantity
3. THE Order_Service SHALL validate the goods is available for direct purchase
### Requirement 6: 订单列表查询
**User Story:** As a user, I want to view my order list, so that I can track my purchase history.
#### Acceptance Criteria
1. WHEN a user requests order list, THE Order_Service SHALL return paginated order records
2. THE Order_Service SHALL return order details including order_num, goods_title, goods_imgurl, order_total, status, prize_num
3. THE Order_Service SHALL support pagination with page and page_size parameters
4. THE Order_Service SHALL return last_page for pagination
### Requirement 7: 订单详情查询
**User Story:** As a user, I want to view order details, so that I can see the complete order information.
#### Acceptance Criteria
1. WHEN a user requests order detail with order_num, THE Order_Service SHALL return complete order information
2. THE Order_Service SHALL return order_info, prize_list, and payment_records
3. IF the order does not exist or belong to another user, THEN THE Order_Service SHALL return an error
### Requirement 8: 抽奖结果查询(一番赏)
**User Story:** As a user, I want to view my lottery results, so that I can see what prizes I won.
#### Acceptance Criteria
1. WHEN a user requests prize order log with order_num, THE Order_Service SHALL return the prize list
2. THE Order_Service SHALL return prize details including goodslist_title, goodslist_imgurl, goodslist_price, goodslist_money, status
3. THE Order_Service SHALL return luck_no for each prize
### Requirement 9: 抽奖结果查询(无限赏)
**User Story:** As a user, I want to view my infinite lottery results, so that I can see what prizes I won.
#### Acceptance Criteria
1. WHEN a user requests infinite prize order log, THE Order_Service SHALL return the prize list
2. THE Order_Service SHALL handle infinite lottery specific prize display
### Requirement 10: 仓库首页查询
**User Story:** As a user, I want to view my warehouse (盒柜), so that I can manage my prizes.
#### Acceptance Criteria
1. WHEN a user requests warehouse index, THE Warehouse_Service SHALL return paginated prize list
2. THE Warehouse_Service SHALL support status filter (0=待选择, 1=回收, 2=发货, 3=集市)
3. THE Warehouse_Service SHALL return prize details including goodslist_title, goodslist_imgurl, goodslist_price, goodslist_money, status
### Requirement 11: 奖品回收
**User Story:** As a user, I want to recycle my prizes for balance, so that I can get money back.
#### Acceptance Criteria
1. WHEN a user requests prize recovery with order_list_ids, THE Warehouse_Service SHALL process the recovery
2. THE Warehouse_Service SHALL add the recovery amount to user's balance
3. THE Warehouse_Service SHALL update the prize status to recovered
4. THE Warehouse_Service SHALL return the total recovery amount
5. IF any prize is not eligible for recovery, THEN THE Warehouse_Service SHALL return an error
### Requirement 12: 奖品发货申请
**User Story:** As a user, I want to request delivery for my prizes, so that I can receive the physical items.
#### Acceptance Criteria
1. WHEN a user requests prize delivery with order_list_ids and address info, THE Warehouse_Service SHALL create a delivery record
2. THE Warehouse_Service SHALL validate the address information (name, mobile, address)
3. THE Warehouse_Service SHALL update the prize status to pending delivery
4. THE Warehouse_Service SHALL return the delivery_id
5. IF any prize is not eligible for delivery, THEN THE Warehouse_Service SHALL return an error
### Requirement 13: 确认发货
**User Story:** As a user, I want to confirm the delivery, so that the delivery process can proceed.
#### Acceptance Criteria
1. WHEN a user confirms delivery with id, THE Warehouse_Service SHALL update the delivery status
2. IF the delivery does not exist or belong to another user, THEN THE Warehouse_Service SHALL return an error
### Requirement 14: 发货记录查询
**User Story:** As a user, I want to view my delivery records, so that I can track my shipments.
#### Acceptance Criteria
1. WHEN a user requests delivery records, THE Warehouse_Service SHALL return paginated delivery list
2. THE Warehouse_Service SHALL return delivery details including name, mobile (masked), address, status
3. THE Warehouse_Service SHALL support pagination
### Requirement 15: 发货记录详情
**User Story:** As a user, I want to view delivery details, so that I can see the complete shipment information.
#### Acceptance Criteria
1. WHEN a user requests delivery detail with id, THE Warehouse_Service SHALL return complete delivery information
2. THE Warehouse_Service SHALL return items list and logistics information
3. IF the delivery does not exist or belong to another user, THEN THE Warehouse_Service SHALL return an error
### Requirement 16: 回收记录查询
**User Story:** As a user, I want to view my recovery records, so that I can track my recycled prizes.
#### Acceptance Criteria
1. WHEN a user requests recovery records, THE Warehouse_Service SHALL return paginated recovery list
2. THE Warehouse_Service SHALL support pagination
### Requirement 17: 物流信息查询
**User Story:** As a user, I want to view logistics information, so that I can track my package.
#### Acceptance Criteria
1. WHEN a user requests logistics info with id, THE Warehouse_Service SHALL return logistics details
2. THE Warehouse_Service SHALL return company, tracking_no, status, and traces
3. IF the delivery does not exist or belong to another user, THEN THE Warehouse_Service SHALL return an error
### Requirement 18: API响应格式兼容性
**User Story:** As a developer, I want the new API to be compatible with the existing frontend, so that the migration is seamless.
#### Acceptance Criteria
1. THE Order_Controller SHALL return responses in the same format as PHP API (status, msg, data)
2. THE Order_Controller SHALL use snake_case for JSON field names
3. THE Warehouse_Controller SHALL return responses in the same format as PHP API
4. THE Warehouse_Controller SHALL use snake_case for JSON field names

View File

@ -0,0 +1,335 @@
# Implementation Plan: 订单系统迁移
## Overview
本任务列表将PHP订单系统迁移到.NET 8按照接口优先级逐个迁移。每迁移一个接口前需要先查看PHP代码了解详细业务逻辑迁移完成后需要在API接口文档.md中标记迁移状态。
## Tasks
- [ ] 1. 基础设施准备
- [ ] 1.1 创建订单相关的DTO和Request/Response模型
- 在HoneyBox.Model/Models/Order目录下创建相关模型
- 包括OrderMoneyRequest、OrderBuyRequest、OrderListDto、OrderDetailDto等
- 包括WarehouseIndexRequest、WarehouseItemDto、SendRequest、RecoveryResultDto等
- _Requirements: 1.1-18.4_
- [ ] 1.2 创建服务接口定义
- 在HoneyBox.Core/Interfaces目录下创建IOrderService、IWarehouseService接口
- _Requirements: 1.1-18.4_
- [ ] 1.3 创建数据库实体模型(如果尚未存在)
- 确认Order、OrderList、Delivery、Recovery等实体存在
- 配置EF Core映射
- _Requirements: 1.1-18.4_
- [ ] 1.4 注册服务到DI容器
- 在ServiceModule.cs中注册OrderService、WarehouseService
- _Requirements: 1.1-18.4_
- [ ] 2. 一番赏订单金额计算服务实现
- [ ] 2.1 查看PHP代码了解一番赏订单金额计算业务逻辑
- 阅读server/php/app/api/controller/Order.php中的ordermoney方法
- 理解优惠券抵扣、余额抵扣、积分抵扣、哈尼券抵扣逻辑
- 理解商品扩展配置对支付方式的影响
- _Requirements: 1.1-1.6_
- [ ] 2.2 实现OrderService - 一番赏订单金额计算
- 实现CalculateOrderMoneyAsync方法
- 实现优惠券验证和抵扣逻辑
- 实现余额、积分、哈尼券抵扣逻辑
- 实现购买限制验证
- _Requirements: 1.1-1.6_
- [ ]* 2.3 编写订单金额计算属性测试
- **Property 1: 订单金额计算正确性**
- **Validates: Requirements 1.1, 1.2, 1.3, 1.4, 1.5**
- [ ] 3. 一番赏订单创建服务实现
- [ ] 3.1 查看PHP代码了解一番赏订单创建业务逻辑
- 阅读server/php/app/api/controller/Order.php中的orderbuy方法
- 理解订单创建、库存扣减、资产扣减、微信支付调用逻辑
- _Requirements: 2.1-2.6_
- [ ] 3.2 实现OrderService - 一番赏订单创建
- 实现CreateOrderAsync方法
- 实现库存验证和扣减逻辑
- 实现用户资产扣减逻辑
- 实现订单记录创建
- 实现微信支付参数生成调用现有WechatService
- _Requirements: 2.1-2.6_
- [ ]* 3.3 编写订单创建属性测试
- **Property 2: 订单创建数据完整性**
- **Validates: Requirements 2.1, 2.2**
- [ ] 4. 无限赏订单服务实现
- [ ] 4.1 查看PHP代码了解无限赏订单业务逻辑
- 阅读server/php/app/api/controller/Order.php中的infinite_ordermoney、infinite_orderbuy方法
- 理解无限赏特有的业务逻辑
- _Requirements: 3.1-3.3, 4.1-4.3_
- [ ] 4.2 实现OrderService - 无限赏订单金额计算
- 实现CalculateInfiniteOrderMoneyAsync方法
- _Requirements: 3.1-3.3_
- [ ] 4.3 实现OrderService - 无限赏订单创建
- 实现CreateInfiniteOrderAsync方法
- _Requirements: 4.1-4.3_
- [ ] 5. 商城订单金额计算服务实现
- [ ] 5.1 查看PHP代码了解商城订单业务逻辑
- 阅读server/php/app/api/controller/Order.php中的mall_ordermoney方法
- 理解商城订单特有的业务逻辑
- _Requirements: 5.1-5.3_
- [ ] 5.2 实现OrderService - 商城订单金额计算
- 实现CalculateMallOrderMoneyAsync方法
- _Requirements: 5.1-5.3_
- [ ] 6. Checkpoint - 订单计算和创建服务测试验证
- 确保订单金额计算、订单创建服务测试通过
- 如有问题请询问用户
- [ ] 7. 订单查询服务实现
- [ ] 7.1 查看PHP代码了解订单查询业务逻辑
- 阅读server/php/app/api/controller/Order.php中的order_list、order_detail方法
- 理解订单列表查询、订单详情查询逻辑
- _Requirements: 6.1-6.4, 7.1-7.3_
- [ ] 7.2 实现OrderService - 订单列表查询
- 实现GetOrderListAsync方法
- 实现分页逻辑
- _Requirements: 6.1-6.4_
- [ ] 7.3 实现OrderService - 订单详情查询
- 实现GetOrderDetailAsync方法
- 实现订单权限验证
- _Requirements: 7.1-7.3_
- [ ]* 7.4 编写订单列表属性测试
- **Property 5: 订单列表分页正确性**
- **Validates: Requirements 6.1, 6.3, 6.4**
- [ ] 8. 抽奖结果查询服务实现
- [ ] 8.1 查看PHP代码了解抽奖结果查询业务逻辑
- 阅读server/php/app/api/controller/Order.php中的prizeorderlog、infinite_prizeorderlog方法
- 理解抽奖结果查询逻辑
- _Requirements: 8.1-8.3, 9.1-9.2_
- [ ] 8.2 实现OrderService - 一番赏抽奖结果查询
- 实现GetPrizeOrderLogAsync方法
- _Requirements: 8.1-8.3_
- [ ] 8.3 实现OrderService - 无限赏抽奖结果查询
- 实现GetInfinitePrizeOrderLogAsync方法
- _Requirements: 9.1-9.2_
- [ ] 9. Checkpoint - 订单查询服务测试验证
- 确保订单列表、订单详情、抽奖结果查询服务测试通过
- 如有问题请询问用户
- [ ] 10. 仓库首页服务实现
- [ ] 10.1 查看PHP代码了解仓库首页业务逻辑
- 阅读server/php/app/api/controller/Warehouse.php中的warehouse_index方法
- 理解仓库物品查询、状态筛选逻辑
- _Requirements: 10.1-10.3_
- [ ] 10.2 实现WarehouseService - 仓库首页查询
- 实现GetWarehouseIndexAsync方法
- 实现状态筛选逻辑
- 实现分页逻辑
- _Requirements: 10.1-10.3_
- [ ] 11. 奖品回收服务实现
- [ ] 11.1 查看PHP代码了解奖品回收业务逻辑
- 阅读server/php/app/api/controller/Warehouse.php中的warehouse_recovery方法
- 理解回收金额计算、余额增加、状态更新逻辑
- _Requirements: 11.1-11.5_
- [ ] 11.2 实现WarehouseService - 奖品回收
- 实现RecoveryPrizesAsync方法
- 实现回收金额计算
- 实现用户余额增加
- 实现奖品状态更新
- _Requirements: 11.1-11.5_
- [ ]* 11.3 编写奖品回收属性测试
- **Property 3: 仓库物品状态一致性**
- **Validates: Requirements 11.2, 11.3**
- [ ] 12. 奖品发货服务实现
- [ ] 12.1 查看PHP代码了解奖品发货业务逻辑
- 阅读server/php/app/api/controller/Warehouse.php中的warehouse_send、warehouse_send_confirm方法
- 理解发货申请、确认发货逻辑
- _Requirements: 12.1-12.5, 13.1-13.2_
- [ ] 12.2 实现WarehouseService - 奖品发货申请
- 实现SendPrizesAsync方法
- 实现地址信息验证
- 实现发货记录创建
- 实现奖品状态更新
- _Requirements: 12.1-12.5_
- [ ] 12.3 实现WarehouseService - 确认发货
- 实现ConfirmSendAsync方法
- _Requirements: 13.1-13.2_
- [ ]* 12.4 编写发货服务属性测试
- **Property 4: 发货记录完整性**
- **Validates: Requirements 12.1, 12.2, 12.3, 12.4**
- [ ] 13. 发货和回收记录查询服务实现
- [ ] 13.1 查看PHP代码了解记录查询业务逻辑
- 阅读server/php/app/api/controller/Warehouse.php中的warehouse_send_record、warehouse_send_record_detail、warehouse_recovery_record方法
- 理解记录查询逻辑
- _Requirements: 14.1-14.3, 15.1-15.3, 16.1-16.2_
- [ ] 13.2 实现WarehouseService - 发货记录查询
- 实现GetSendRecordsAsync方法
- _Requirements: 14.1-14.3_
- [ ] 13.3 实现WarehouseService - 发货记录详情
- 实现GetSendRecordDetailAsync方法
- _Requirements: 15.1-15.3_
- [ ] 13.4 实现WarehouseService - 回收记录查询
- 实现GetRecoveryRecordsAsync方法
- _Requirements: 16.1-16.2_
- [ ] 14. 物流信息查询服务实现
- [ ] 14.1 查看PHP代码了解物流查询业务逻辑
- 阅读server/php/app/api/controller/Warehouse.php中的warehouse_order_logistics方法
- 理解物流信息查询逻辑
- _Requirements: 17.1-17.3_
- [ ] 14.2 实现WarehouseService - 物流信息查询
- 实现GetLogisticsAsync方法
- _Requirements: 17.1-17.3_
- [ ] 15. Checkpoint - 仓库服务测试验证
- 确保所有仓库服务测试通过
- 如有问题请询问用户
- [ ] 16. 控制器实现 - OrderController
- [ ] 16.1 实现一番赏订单金额计算接口 POST /ordermoney
- 调用OrderService.CalculateOrderMoneyAsync
- 更新API接口文档标记迁移状态
- _Requirements: 1.1-1.6_
- [ ] 16.2 实现一番赏订单创建接口 POST /orderbuy
- 调用OrderService.CreateOrderAsync
- 更新API接口文档标记迁移状态
- _Requirements: 2.1-2.6_
- [ ] 16.3 实现无限赏订单金额计算接口 POST /infinite_ordermoney
- 调用OrderService.CalculateInfiniteOrderMoneyAsync
- 更新API接口文档标记迁移状态
- _Requirements: 3.1-3.3_
- [ ] 16.4 实现无限赏订单创建接口 POST /infinite_orderbuy
- 调用OrderService.CreateInfiniteOrderAsync
- 更新API接口文档标记迁移状态
- _Requirements: 4.1-4.3_
- [ ] 16.5 实现商城订单金额计算接口 POST /mall_ordermoney
- 调用OrderService.CalculateMallOrderMoneyAsync
- 更新API接口文档标记迁移状态
- _Requirements: 5.1-5.3_
- [ ] 16.6 实现订单列表接口 POST /order_list
- 调用OrderService.GetOrderListAsync
- 更新API接口文档标记迁移状态
- _Requirements: 6.1-6.4_
- [ ] 16.7 实现订单详情接口 POST /order_detail
- 调用OrderService.GetOrderDetailAsync
- 更新API接口文档标记迁移状态
- _Requirements: 7.1-7.3_
- [ ] 16.8 实现一番赏抽奖结果接口 POST /prizeorderlog
- 调用OrderService.GetPrizeOrderLogAsync
- 更新API接口文档标记迁移状态
- _Requirements: 8.1-8.3_
- [ ] 16.9 实现无限赏抽奖结果接口 POST /infinite_prizeorderlog
- 调用OrderService.GetInfinitePrizeOrderLogAsync
- 更新API接口文档标记迁移状态
- _Requirements: 9.1-9.2_
- [ ] 17. 控制器实现 - WarehouseController
- [ ] 17.1 实现仓库首页接口 POST /warehouse_index
- 调用WarehouseService.GetWarehouseIndexAsync
- 更新API接口文档标记迁移状态
- _Requirements: 10.1-10.3_
- [ ] 17.2 实现奖品回收接口 POST /warehouse_recovery
- 调用WarehouseService.RecoveryPrizesAsync
- 更新API接口文档标记迁移状态
- _Requirements: 11.1-11.5_
- [ ] 17.3 实现奖品发货接口 POST /warehouse_send
- 调用WarehouseService.SendPrizesAsync
- 更新API接口文档标记迁移状态
- _Requirements: 12.1-12.5_
- [ ] 17.4 实现确认发货接口 POST /warehouse_send_confirm
- 调用WarehouseService.ConfirmSendAsync
- 更新API接口文档标记迁移状态
- _Requirements: 13.1-13.2_
- [ ] 17.5 实现发货记录接口 POST /warehouse_send_record
- 调用WarehouseService.GetSendRecordsAsync
- 更新API接口文档标记迁移状态
- _Requirements: 14.1-14.3_
- [ ] 17.6 实现发货记录详情接口 POST /warehouse_send_record_detail
- 调用WarehouseService.GetSendRecordDetailAsync
- 更新API接口文档标记迁移状态
- _Requirements: 15.1-15.3_
- [ ] 17.7 实现回收记录接口 POST /warehouse_recovery_record
- 调用WarehouseService.GetRecoveryRecordsAsync
- 更新API接口文档标记迁移状态
- _Requirements: 16.1-16.2_
- [ ] 17.8 实现物流信息接口 POST /warehouse_order_logistics
- 调用WarehouseService.GetLogisticsAsync
- 更新API接口文档标记迁移状态
- _Requirements: 17.1-17.3_
- [ ] 18. Checkpoint - 控制器测试验证
- 确保所有控制器接口可正常访问
- 使用Postman或HTTP文件测试各接口
- 如有问题请询问用户
- [ ] 19. API响应格式验证
- [ ] 19.1 验证所有接口响应格式
- 确保status、msg、data结构一致
- 确保字段命名与PHP API一致snake_case
- _Requirements: 18.1-18.4_
- [ ]* 19.2 编写API格式属性测试
- **Property 6: API响应格式一致性**
- **Validates: Requirements 18.1-18.4**
- [ ] 20. 集成测试
- [ ] 20.1 编写订单金额计算集成测试
- 测试完整的订单金额计算流程
- 测试各种抵扣组合
- _Requirements: 1.1-1.6_
- [ ] 20.2 编写订单创建集成测试
- 测试订单创建流程
- 测试库存扣减
- _Requirements: 2.1-2.6_
- [ ] 20.3 编写仓库功能集成测试
- 测试奖品回收流程
- 测试奖品发货流程
- _Requirements: 10.1-17.3_
- [ ] 21. 文档更新和最终验证
- [ ] 21.1 更新API接口文档
- 确认所有迁移接口都已标记
- 记录新接口地址
- _Requirements: 18.1-18.4_
- [ ] 21.2 创建HTTP测试文件
- 在HoneyBox.Api目录下创建order-system.http测试文件
- 包含所有订单系统相关接口的测试请求
- [ ] 22. Final Checkpoint - 完整功能验证
- 确保所有测试通过
- 确保API文档已更新
- 确保与前端兼容性
- 如有问题请询问用户
## Notes
- Tasks marked with `*` are optional and can be skipped for faster MVP
- Each task references specific requirements for traceability
- Checkpoints ensure incremental validation
- Property tests validate universal correctness properties
- Unit tests validate specific examples and edge cases
- 每迁移完成一个接口都需要在docs/API接口文档.md中标记迁移状态和新接口地址
- 迁移前必须先查看PHP代码了解详细业务逻辑确保功能一致性
- 订单系统涉及支付,需要特别注意数据一致性和事务处理
- 仓库系统涉及用户资产变更,需要确保金额计算准确
## 接口迁移清单
| 序号 | PHP接口 | 新接口地址 | 状态 |
|------|---------|-----------|------|
| 1 | POST /ordermoney | POST /api/ordermoney | ⬜ |
| 2 | POST /orderbuy | POST /api/orderbuy | ⬜ |
| 3 | POST /infinite_ordermoney | POST /api/infinite_ordermoney | ⬜ |
| 4 | POST /infinite_orderbuy | POST /api/infinite_orderbuy | ⬜ |
| 5 | POST /mall_ordermoney | POST /api/mall_ordermoney | ⬜ |
| 6 | POST /order_list | POST /api/order_list | ⬜ |
| 7 | POST /order_detail | POST /api/order_detail | ⬜ |
| 8 | POST /prizeorderlog | POST /api/prizeorderlog | ⬜ |
| 9 | POST /infinite_prizeorderlog | POST /api/infinite_prizeorderlog | ⬜ |
| 10 | POST /warehouse_index | POST /api/warehouse_index | ⬜ |
| 11 | POST /warehouse_recovery | POST /api/warehouse_recovery | ⬜ |
| 12 | POST /warehouse_send | POST /api/warehouse_send | ⬜ |
| 13 | POST /warehouse_send_confirm | POST /api/warehouse_send_confirm | ⬜ |
| 14 | POST /warehouse_send_record | POST /api/warehouse_send_record | ⬜ |
| 15 | POST /warehouse_send_record_detail | POST /api/warehouse_send_record_detail | ⬜ |
| 16 | POST /warehouse_recovery_record | POST /api/warehouse_recovery_record | ⬜ |
| 17 | POST /warehouse_order_logistics | POST /api/warehouse_order_logistics | ⬜ |