feat: align ids to int64
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -47,15 +46,14 @@ func (s *order) ListUserOrders(ctx context.Context, userID int64, status string)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s *order) GetUserOrder(ctx context.Context, userID int64, id string) (*user_dto.Order, error) {
|
||||
func (s *order) GetUserOrder(ctx context.Context, userID int64, id int64) (*user_dto.Order, error) {
|
||||
if userID == 0 {
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
oid := cast.ToInt64(id)
|
||||
|
||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||
item, err := q.Where(tbl.ID.Eq(oid), tbl.UserID.Eq(uid)).First()
|
||||
item, err := q.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid)).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
@@ -79,7 +77,7 @@ func (s *order) Create(
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
cid := cast.ToInt64(form.ContentID)
|
||||
cid := form.ContentID
|
||||
|
||||
// 1. Fetch Content & Price
|
||||
content, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).First()
|
||||
@@ -100,15 +98,14 @@ func (s *order) Create(
|
||||
var couponID int64 = 0
|
||||
|
||||
// Validate Coupon
|
||||
if form.UserCouponID != "" {
|
||||
ucid := cast.ToInt64(form.UserCouponID)
|
||||
discount, err := Coupon.Validate(ctx, uid, ucid, amountOriginal)
|
||||
if form.UserCouponID > 0 {
|
||||
discount, err := Coupon.Validate(ctx, uid, form.UserCouponID, amountOriginal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
amountDiscount = discount
|
||||
|
||||
uc, err := models.UserCouponQuery.WithContext(ctx).Where(models.UserCouponQuery.ID.Eq(ucid)).First()
|
||||
uc, err := models.UserCouponQuery.WithContext(ctx).Where(models.UserCouponQuery.ID.Eq(form.UserCouponID)).First()
|
||||
if err == nil {
|
||||
couponID = uc.CouponID
|
||||
}
|
||||
@@ -150,8 +147,8 @@ func (s *order) Create(
|
||||
}
|
||||
|
||||
// Mark Coupon Used
|
||||
if form.UserCouponID != "" {
|
||||
if err := Coupon.MarkUsed(ctx, tx, cast.ToInt64(form.UserCouponID), order.ID); err != nil {
|
||||
if form.UserCouponID > 0 {
|
||||
if err := Coupon.MarkUsed(ctx, tx, form.UserCouponID, order.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -166,25 +163,24 @@ func (s *order) Create(
|
||||
}
|
||||
|
||||
return &transaction_dto.OrderCreateResponse{
|
||||
OrderID: cast.ToString(order.ID),
|
||||
OrderID: order.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *order) Pay(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
id string,
|
||||
id int64,
|
||||
form *transaction_dto.OrderPayForm,
|
||||
) (*transaction_dto.OrderPayResponse, error) {
|
||||
if userID == 0 {
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
oid := cast.ToInt64(id)
|
||||
|
||||
// Fetch Order
|
||||
o, err := models.OrderQuery.WithContext(ctx).
|
||||
Where(models.OrderQuery.ID.Eq(oid), models.OrderQuery.UserID.Eq(uid)).
|
||||
Where(models.OrderQuery.ID.Eq(id), models.OrderQuery.UserID.Eq(uid)).
|
||||
First()
|
||||
if err != nil {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
@@ -204,9 +200,8 @@ func (s *order) Pay(
|
||||
}
|
||||
|
||||
// ProcessExternalPayment handles callback from payment gateway
|
||||
func (s *order) ProcessExternalPayment(ctx context.Context, orderID, externalID string) error {
|
||||
oid := cast.ToInt64(orderID)
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
|
||||
func (s *order) ProcessExternalPayment(ctx context.Context, orderID int64, externalID string) error {
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(orderID)).First()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
@@ -347,20 +342,30 @@ func (s *order) settleOrder(ctx context.Context, o *models.Order, method, extern
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *order) Status(ctx context.Context, id string) (*transaction_dto.OrderStatusResponse, error) {
|
||||
return nil, nil
|
||||
func (s *order) Status(ctx context.Context, id int64) (*transaction_dto.OrderStatusResponse, error) {
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
}
|
||||
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||
}
|
||||
|
||||
return &transaction_dto.OrderStatusResponse{
|
||||
Status: string(o.Status),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.Order, error) {
|
||||
dto := user_dto.Order{
|
||||
ID: cast.ToString(o.ID),
|
||||
ID: o.ID,
|
||||
Type: string(o.Type),
|
||||
TypeDescription: o.Type.Description(),
|
||||
Status: string(o.Status),
|
||||
StatusDescription: o.Status.Description(),
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
CreateTime: o.CreatedAt.Format(time.RFC3339),
|
||||
TenantID: cast.ToString(o.TenantID),
|
||||
TenantID: o.TenantID,
|
||||
}
|
||||
|
||||
// Fetch Tenant Name
|
||||
@@ -385,10 +390,10 @@ func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.
|
||||
|
||||
if err == nil {
|
||||
ci := transaction_dto.ContentItem{
|
||||
ID: cast.ToString(c.ID),
|
||||
ID: c.ID,
|
||||
Title: c.Title,
|
||||
Genre: c.Genre,
|
||||
AuthorID: cast.ToString(c.UserID),
|
||||
AuthorID: c.UserID,
|
||||
Price: float64(item.AmountPaid) / 100.0, // Use actual paid amount
|
||||
}
|
||||
// Cover logic (simplified from content service)
|
||||
@@ -408,7 +413,7 @@ func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.
|
||||
|
||||
func (s *order) toUserOrderDTO(o *models.Order) user_dto.Order {
|
||||
return user_dto.Order{
|
||||
ID: cast.ToString(o.ID),
|
||||
ID: o.ID,
|
||||
Status: string(o.Status), // Need cast for DTO string field if DTO field is string
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
CreateTime: o.CreatedAt.Format(time.RFC3339),
|
||||
|
||||
Reference in New Issue
Block a user