133 lines
5.4 KiB
Go
133 lines
5.4 KiB
Go
package pointsmall
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"hfb_sys/backend/internal/model"
|
|
)
|
|
|
|
var (
|
|
ErrDependencyUnavailable = errors.New("points mall dependency unavailable")
|
|
ErrInvalidInput = errors.New("invalid points mall input")
|
|
ErrProductUnavailable = errors.New("points mall product unavailable")
|
|
ErrInsufficientPoints = errors.New("insufficient points")
|
|
ErrRedeemLimitExceeded = errors.New("redeem limit exceeded")
|
|
ErrRedemptionNotPending = errors.New("redemption not pending")
|
|
)
|
|
|
|
type SummaryDTO struct {
|
|
AvailablePoints int64 `json:"available_points"`
|
|
LifetimePoints int64 `json:"lifetime_points"`
|
|
LevelCode string `json:"level_code"`
|
|
LevelName string `json:"level_name"`
|
|
PointsPerYuan int64 `json:"points_per_yuan"`
|
|
PointsMultiplierBps int `json:"points_multiplier_bps"`
|
|
}
|
|
|
|
type ProductDTO struct {
|
|
ID uint64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Subtitle string `json:"subtitle"`
|
|
Description string `json:"description"`
|
|
CoverURL string `json:"cover_url"`
|
|
RedemptionInstructions string `json:"redemption_instructions"`
|
|
PointsPrice int64 `json:"points_price"`
|
|
Stock int64 `json:"stock"`
|
|
RedeemedCount int64 `json:"redeemed_count"`
|
|
PerUserLimit int `json:"per_user_limit"`
|
|
Status string `json:"status"`
|
|
SortOrder int `json:"sort_order"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ProductRequest struct {
|
|
Title string `json:"title" binding:"required,max=128"`
|
|
Subtitle string `json:"subtitle" binding:"max=255"`
|
|
Description string `json:"description" binding:"required"`
|
|
CoverURL string `json:"cover_url"`
|
|
RedemptionInstructions string `json:"redemption_instructions" binding:"required"`
|
|
PointsPrice int64 `json:"points_price" binding:"required,min=1"`
|
|
Stock int64 `json:"stock" binding:"min=0"`
|
|
PerUserLimit int `json:"per_user_limit" binding:"required,min=1,max=100"`
|
|
Status string `json:"status" binding:"required,oneof=online offline"`
|
|
SortOrder int `json:"sort_order"`
|
|
}
|
|
|
|
type RedeemRequest struct {
|
|
Quantity int `json:"quantity" binding:"required,min=1,max=10"`
|
|
ContactName string `json:"contact_name" binding:"required,max=32"`
|
|
ContactPhone string `json:"contact_phone" binding:"required,len=11,numeric"`
|
|
CustomerRemark string `json:"customer_remark" binding:"max=500"`
|
|
}
|
|
|
|
type CompleteRedemptionRequest struct {
|
|
Remark string `json:"remark" binding:"max=255"`
|
|
}
|
|
|
|
type RedemptionDTO struct {
|
|
ID uint64 `json:"id"`
|
|
RedemptionNo string `json:"redemption_no"`
|
|
UserID uint64 `json:"user_id"`
|
|
UserPhone string `json:"user_phone,omitempty"`
|
|
UserNickname string `json:"user_nickname,omitempty"`
|
|
ProductID uint64 `json:"product_id"`
|
|
ProductTitle string `json:"product_title"`
|
|
ProductCoverURL string `json:"product_cover_url"`
|
|
RedemptionInstructions string `json:"redemption_instructions"`
|
|
ContactName string `json:"contact_name"`
|
|
ContactPhone string `json:"contact_phone"`
|
|
CustomerRemark string `json:"customer_remark"`
|
|
PointsPrice int64 `json:"points_price"`
|
|
Quantity int `json:"quantity"`
|
|
TotalPoints int64 `json:"total_points"`
|
|
Status string `json:"status"`
|
|
AdminRemark string `json:"admin_remark"`
|
|
CompletedBy *uint64 `json:"completed_by,omitempty"`
|
|
CompletedAt *time.Time `json:"completed_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func toProductDTO(item model.PointsMallProduct) ProductDTO {
|
|
return ProductDTO{
|
|
ID: item.ID,
|
|
Title: item.Title,
|
|
Subtitle: item.Subtitle,
|
|
Description: item.Description,
|
|
CoverURL: item.CoverURL,
|
|
RedemptionInstructions: item.RedemptionInstructions,
|
|
PointsPrice: item.PointsPrice,
|
|
Stock: item.Stock,
|
|
RedeemedCount: item.RedeemedCount,
|
|
PerUserLimit: item.PerUserLimit,
|
|
Status: item.Status,
|
|
SortOrder: item.SortOrder,
|
|
CreatedAt: item.CreatedAt,
|
|
UpdatedAt: item.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func toRedemptionDTO(item model.PointsMallRedemption) RedemptionDTO {
|
|
return RedemptionDTO{
|
|
ID: item.ID,
|
|
RedemptionNo: item.RedemptionNo,
|
|
UserID: item.UserID,
|
|
ProductID: item.ProductID,
|
|
ProductTitle: item.ProductTitle,
|
|
ProductCoverURL: item.ProductCoverURL,
|
|
RedemptionInstructions: item.RedemptionInstructions,
|
|
ContactName: item.ContactName,
|
|
ContactPhone: item.ContactPhone,
|
|
CustomerRemark: item.CustomerRemark,
|
|
PointsPrice: item.PointsPrice,
|
|
Quantity: item.Quantity,
|
|
TotalPoints: item.TotalPoints,
|
|
Status: item.Status,
|
|
AdminRemark: item.AdminRemark,
|
|
CompletedBy: item.CompletedBy,
|
|
CompletedAt: item.CompletedAt,
|
|
CreatedAt: item.CreatedAt,
|
|
}
|
|
}
|