feat: 增加订单过滤功能,支持按内容ID、支付时间范围和支付金额范围筛选
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/samber/lo"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@@ -184,10 +185,11 @@ func (s *OrderTestSuite) Test_AdminTopupUser() {
|
||||
func (s *OrderTestSuite) Test_MyOrderPage() {
|
||||
Convey("Order.MyOrderPage", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
now := time.Now().UTC()
|
||||
tenantID := int64(1)
|
||||
userID := int64(2)
|
||||
|
||||
s.truncate(ctx, models.TableNameOrder, models.TableNameOrderItem)
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
Convey("参数非法应返回错误", func() {
|
||||
_, err := Order.MyOrderPage(ctx, 0, userID, &dto.MyOrderListFilter{})
|
||||
@@ -199,6 +201,64 @@ func (s *OrderTestSuite) Test_MyOrderPage() {
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 0)
|
||||
})
|
||||
|
||||
Convey("按 content_id 过滤", func() {
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
OrderID: o1.ID,
|
||||
ContentID: 111,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now.Add(time.Minute),
|
||||
CreatedAt: now.Add(time.Minute),
|
||||
UpdatedAt: now.Add(time.Minute),
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
OrderID: o2.ID,
|
||||
ContentID: 222,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now.Add(time.Minute),
|
||||
UpdatedAt: now.Add(time.Minute),
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
pager, err := Order.MyOrderPage(ctx, tenantID, userID, &dto.MyOrderListFilter{
|
||||
ContentID: lo.ToPtr(int64(111)),
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -225,9 +285,10 @@ func (s *OrderTestSuite) Test_MyOrderDetail() {
|
||||
func (s *OrderTestSuite) Test_AdminOrderPage() {
|
||||
Convey("Order.AdminOrderPage", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
now := time.Now().UTC()
|
||||
tenantID := int64(1)
|
||||
|
||||
s.truncate(ctx, models.TableNameOrder, models.TableNameOrderItem)
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
Convey("参数非法应返回错误", func() {
|
||||
_, err := Order.AdminOrderPage(ctx, 0, &dto.AdminOrderListFilter{})
|
||||
@@ -239,6 +300,102 @@ func (s *OrderTestSuite) Test_AdminOrderPage() {
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 0)
|
||||
})
|
||||
|
||||
Convey("按 paid_at 时间窗过滤", func() {
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now.Add(-time.Hour),
|
||||
CreatedAt: now.Add(-time.Hour),
|
||||
UpdatedAt: now.Add(-time.Hour),
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
OrderID: o1.ID,
|
||||
ContentID: 333,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now.Add(-time.Hour),
|
||||
UpdatedAt: now.Add(-time.Hour),
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
OrderID: o2.ID,
|
||||
ContentID: 444,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 200,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
from := now.Add(-10 * time.Minute)
|
||||
to := now.Add(10 * time.Minute)
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
PaidAtFrom: &from,
|
||||
PaidAtTo: &to,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("按 content_id 过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
So((&models.OrderItem{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
OrderID: o1.ID,
|
||||
ContentID: 555,
|
||||
ContentUserID: 1,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}).Create(ctx), ShouldBeNil)
|
||||
|
||||
pager, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
ContentID: lo.ToPtr(int64(555)),
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user