Order模块:完成分字段重构
核心改造:
1. DTO层全部改为*Cent int64字段(OrderDTO/CheckoutDTO/RefundStatusDTO)
2. 内部结构体orderPricing和checkoutSettlement改为分字段
3. calculateCheckoutSettlement函数改为返回分单位
4. 所有wallet.AppendEntries调用改为AmountCent
5. toAdminDTO/toCheckoutAdminDTO转换函数使用*Cent字段
6. applyOrderPriceView/applyCheckoutPriceView使用分字段
7. buildOrderPricing返回分单位
8. 订单取消/关闭/退款使用分字段计算
技术细节:
- 删除了3处float64金额相加后转分的逻辑
- calculateCheckoutSettlement内部仍用元计算保持兼容性,最后转为分
- 新增effectiveDepositOriginalAmountCent辅助函数
- buildRefundStatusDTO使用TotalAmountCent
- 编译验证通过 ✅
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package adminuser
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDepositFreeQuotaAmountCent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
req DepositFreeQuotaRequest
|
||||
want int64
|
||||
}{
|
||||
{
|
||||
name: "优先使用分字段",
|
||||
req: DepositFreeQuotaRequest{AmountCent: 1234, Amount: 99},
|
||||
want: 1234,
|
||||
},
|
||||
{
|
||||
name: "缺少分字段时回退元字段",
|
||||
req: DepositFreeQuotaRequest{Amount: 12.34},
|
||||
want: 1234,
|
||||
},
|
||||
{
|
||||
name: "负分拒绝",
|
||||
req: DepositFreeQuotaRequest{AmountCent: -1, Amount: 12.34},
|
||||
want: -1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := depositFreeQuotaAmountCent(tt.req); got != tt.want {
|
||||
t.Fatalf("depositFreeQuotaAmountCent() = %d, want %d", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user