新增最小购买数量控制 & 购买前检查实名

This commit is contained in:
2026-04-20 11:20:44 +08:00
parent a964fe4d69
commit 982cbb4cab
6 changed files with 29 additions and 1 deletions

View File

@@ -762,6 +762,7 @@ create table product_sku (
price_min decimal not null, price_min decimal not null,
status int not null default 1, status int not null default 1,
sort int not null default 0, sort int not null default 0,
count_min int not null default 1,
created_at timestamptz default current_timestamp, created_at timestamptz default current_timestamp,
updated_at timestamptz default current_timestamp, updated_at timestamptz default current_timestamp,
deleted_at timestamptz deleted_at timestamptz
@@ -780,6 +781,7 @@ comment on column product_sku.name is 'SKU 可读名称';
comment on column product_sku.price_min is '最低价格'; comment on column product_sku.price_min is '最低价格';
comment on column product_sku.status is 'SKU状态0-禁用1-正常'; comment on column product_sku.status is 'SKU状态0-禁用1-正常';
comment on column product_sku.sort is '排序'; comment on column product_sku.sort is '排序';
comment on column product_sku.count_min is '最小购买数量';
comment on column product_sku.created_at is '创建时间'; comment on column product_sku.created_at is '创建时间';
comment on column product_sku.updated_at is '更新时间'; comment on column product_sku.updated_at is '更新时间';
comment on column product_sku.deleted_at is '删除时间'; comment on column product_sku.deleted_at is '删除时间';

View File

@@ -182,6 +182,9 @@ func TradeCreate(c *fiber.Ctx) error {
if err != nil { if err != nil {
return err return err
} }
if authCtx.User.IDType == m.UserIDTypeUnverified {
return core.NewBizErr("请先实名认证后再购买")
}
// 解析请求参数 // 解析请求参数
req := new(TradeCreateReq) req := new(TradeCreateReq)

View File

@@ -17,6 +17,7 @@ type ProductSku struct {
PriceMin decimal.Decimal `json:"price_min" gorm:"column:price_min"` // 最低价格 PriceMin decimal.Decimal `json:"price_min" gorm:"column:price_min"` // 最低价格
Status SkuStatus `json:"status" gorm:"column:status"` // SKU 状态0-禁用1-正常 Status SkuStatus `json:"status" gorm:"column:status"` // SKU 状态0-禁用1-正常
Sort int32 `json:"sort" gorm:"column:sort"` // 排序 Sort int32 `json:"sort" gorm:"column:sort"` // 排序
CountMin int32 `json:"count_min" gorm:"column:count_min"` // 最小购买数量
Product *Product `json:"product,omitempty" gorm:"foreignKey:ProductID"` Product *Product `json:"product,omitempty" gorm:"foreignKey:ProductID"`
Discount *ProductDiscount `json:"discount,omitempty" gorm:"foreignKey:DiscountId"` Discount *ProductDiscount `json:"discount,omitempty" gorm:"foreignKey:DiscountId"`

View File

@@ -39,6 +39,7 @@ func newProductSku(db *gorm.DB, opts ...gen.DOOption) productSku {
_productSku.PriceMin = field.NewField(tableName, "price_min") _productSku.PriceMin = field.NewField(tableName, "price_min")
_productSku.Status = field.NewInt32(tableName, "status") _productSku.Status = field.NewInt32(tableName, "status")
_productSku.Sort = field.NewInt32(tableName, "sort") _productSku.Sort = field.NewInt32(tableName, "sort")
_productSku.CountMin = field.NewInt32(tableName, "count_min")
_productSku.Product = productSkuBelongsToProduct{ _productSku.Product = productSkuBelongsToProduct{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
@@ -93,6 +94,7 @@ type productSku struct {
PriceMin field.Field PriceMin field.Field
Status field.Int32 Status field.Int32
Sort field.Int32 Sort field.Int32
CountMin field.Int32
Product productSkuBelongsToProduct Product productSkuBelongsToProduct
Discount productSkuBelongsToDiscount Discount productSkuBelongsToDiscount
@@ -124,6 +126,7 @@ func (p *productSku) updateTableName(table string) *productSku {
p.PriceMin = field.NewField(table, "price_min") p.PriceMin = field.NewField(table, "price_min")
p.Status = field.NewInt32(table, "status") p.Status = field.NewInt32(table, "status")
p.Sort = field.NewInt32(table, "sort") p.Sort = field.NewInt32(table, "sort")
p.CountMin = field.NewInt32(table, "count_min")
p.fillFieldMap() p.fillFieldMap()
@@ -140,7 +143,7 @@ func (p *productSku) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (p *productSku) fillFieldMap() { func (p *productSku) fillFieldMap() {
p.fieldMap = make(map[string]field.Expr, 14) p.fieldMap = make(map[string]field.Expr, 15)
p.fieldMap["id"] = p.ID p.fieldMap["id"] = p.ID
p.fieldMap["created_at"] = p.CreatedAt p.fieldMap["created_at"] = p.CreatedAt
p.fieldMap["updated_at"] = p.UpdatedAt p.fieldMap["updated_at"] = p.UpdatedAt
@@ -153,6 +156,7 @@ func (p *productSku) fillFieldMap() {
p.fieldMap["price_min"] = p.PriceMin p.fieldMap["price_min"] = p.PriceMin
p.fieldMap["status"] = p.Status p.fieldMap["status"] = p.Status
p.fieldMap["sort"] = p.Sort p.fieldMap["sort"] = p.Sort
p.fieldMap["count_min"] = p.CountMin
} }

View File

@@ -50,6 +50,7 @@ func (s *productService) AllProductSaleInfos() ([]*m.Product, error) {
q.ProductSku.Name, q.ProductSku.Name,
q.ProductSku.Code, q.ProductSku.Code,
q.ProductSku.Price, q.ProductSku.Price,
q.ProductSku.CountMin,
). ).
Where( Where(
q.ProductSku.ProductID.In(pids...), q.ProductSku.ProductID.In(pids...),

View File

@@ -47,6 +47,11 @@ func (s *productSkuService) Create(create CreateProductSkuData) (err error) {
return core.NewBizErr("产品最低价格的格式不正确", err) return core.NewBizErr("产品最低价格的格式不正确", err)
} }
countMin := int32(1)
if create.CountMin != nil {
countMin = *create.CountMin
}
return q.ProductSku.Create(&m.ProductSku{ return q.ProductSku.Create(&m.ProductSku{
ProductID: create.ProductID, ProductID: create.ProductID,
DiscountId: create.DiscountID, DiscountId: create.DiscountID,
@@ -54,6 +59,8 @@ func (s *productSkuService) Create(create CreateProductSkuData) (err error) {
Name: create.Name, Name: create.Name,
Price: price, Price: price,
PriceMin: priceMin, PriceMin: priceMin,
Sort: create.Sort,
CountMin: countMin,
}) })
} }
@@ -64,6 +71,8 @@ type CreateProductSkuData struct {
Name string `json:"name"` Name string `json:"name"`
Price string `json:"price"` Price string `json:"price"`
PriceMin string `json:"price_min"` PriceMin string `json:"price_min"`
Sort int32 `json:"sort"`
CountMin *int32 `json:"count_min"`
} }
func (s *productSkuService) Update(update UpdateProductSkuData) (err error) { func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
@@ -95,6 +104,12 @@ func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
if update.Status != nil { if update.Status != nil {
do = append(do, q.ProductSku.Status.Value(*update.Status)) do = append(do, q.ProductSku.Status.Value(*update.Status))
} }
if update.Sort != nil {
do = append(do, q.ProductSku.Sort.Value(*update.Sort))
}
if update.CountMin != nil {
do = append(do, q.ProductSku.CountMin.Value(*update.CountMin))
}
_, err = q.ProductSku.Where(q.ProductSku.ID.Eq(update.ID)).UpdateSimple(do...) _, err = q.ProductSku.Where(q.ProductSku.ID.Eq(update.ID)).UpdateSimple(do...)
return err return err
@@ -108,6 +123,8 @@ type UpdateProductSkuData struct {
Price *string `json:"price"` Price *string `json:"price"`
PriceMin string `json:"price_min"` PriceMin string `json:"price_min"`
Status *int32 `json:"status"` Status *int32 `json:"status"`
Sort *int32 `json:"sort"`
CountMin *int32 `json:"count_min"`
} }
func (s *productSkuService) Delete(id int32) (err error) { func (s *productSkuService) Delete(id int32) (err error) {