feat: 增加订单筛选功能,添加按金额区间筛选的数据库索引
This commit is contained in:
@@ -396,6 +396,130 @@ func (s *OrderTestSuite) Test_AdminOrderPage() {
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("组合筛选:user_id + status + amount_paid 区间 + content_id", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
statusPaid := consts.OrderStatusPaid
|
||||
userID := int64(7)
|
||||
contentID := int64(777)
|
||||
|
||||
// 命中:user_id=7, status=paid, amount_paid=500, content_id=777
|
||||
oHit := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(oHit.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
OrderID: oHit.ID,
|
||||
ContentID: contentID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
// 不命中:amount_paid 不在区间
|
||||
oNoAmount := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 50,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(oNoAmount.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
OrderID: oNoAmount.ID,
|
||||
ContentID: contentID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 50,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
// 不命中:status 不同
|
||||
oNoStatus := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusCreated,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(oNoStatus.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
OrderID: oNoStatus.ID,
|
||||
ContentID: contentID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
// 不命中:user_id 不同
|
||||
oNoUser := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 8,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(oNoUser.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 8,
|
||||
OrderID: oNoUser.ID,
|
||||
ContentID: contentID,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
min := int64(100)
|
||||
max := int64(900)
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
UserID: &userID,
|
||||
Status: &statusPaid,
|
||||
ContentID: &contentID,
|
||||
AmountPaidMin: &min,
|
||||
AmountPaidMax: &max,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user