Compare commits
1 Commits
a964fe4d69
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 982cbb4cab |
@@ -762,6 +762,7 @@ create table product_sku (
|
||||
price_min decimal not null,
|
||||
status int not null default 1,
|
||||
sort int not null default 0,
|
||||
count_min int not null default 1,
|
||||
created_at timestamptz default current_timestamp,
|
||||
updated_at timestamptz default current_timestamp,
|
||||
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.status is 'SKU状态:0-禁用,1-正常';
|
||||
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.updated_at is '更新时间';
|
||||
comment on column product_sku.deleted_at is '删除时间';
|
||||
|
||||
@@ -182,6 +182,9 @@ func TradeCreate(c *fiber.Ctx) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if authCtx.User.IDType == m.UserIDTypeUnverified {
|
||||
return core.NewBizErr("请先实名认证后再购买")
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(TradeCreateReq)
|
||||
|
||||
@@ -17,6 +17,7 @@ type ProductSku struct {
|
||||
PriceMin decimal.Decimal `json:"price_min" gorm:"column:price_min"` // 最低价格
|
||||
Status SkuStatus `json:"status" gorm:"column:status"` // SKU 状态:0-禁用,1-正常
|
||||
Sort int32 `json:"sort" gorm:"column:sort"` // 排序
|
||||
CountMin int32 `json:"count_min" gorm:"column:count_min"` // 最小购买数量
|
||||
|
||||
Product *Product `json:"product,omitempty" gorm:"foreignKey:ProductID"`
|
||||
Discount *ProductDiscount `json:"discount,omitempty" gorm:"foreignKey:DiscountId"`
|
||||
|
||||
@@ -39,6 +39,7 @@ func newProductSku(db *gorm.DB, opts ...gen.DOOption) productSku {
|
||||
_productSku.PriceMin = field.NewField(tableName, "price_min")
|
||||
_productSku.Status = field.NewInt32(tableName, "status")
|
||||
_productSku.Sort = field.NewInt32(tableName, "sort")
|
||||
_productSku.CountMin = field.NewInt32(tableName, "count_min")
|
||||
_productSku.Product = productSkuBelongsToProduct{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
@@ -93,6 +94,7 @@ type productSku struct {
|
||||
PriceMin field.Field
|
||||
Status field.Int32
|
||||
Sort field.Int32
|
||||
CountMin field.Int32
|
||||
Product productSkuBelongsToProduct
|
||||
|
||||
Discount productSkuBelongsToDiscount
|
||||
@@ -124,6 +126,7 @@ func (p *productSku) updateTableName(table string) *productSku {
|
||||
p.PriceMin = field.NewField(table, "price_min")
|
||||
p.Status = field.NewInt32(table, "status")
|
||||
p.Sort = field.NewInt32(table, "sort")
|
||||
p.CountMin = field.NewInt32(table, "count_min")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
@@ -140,7 +143,7 @@ func (p *productSku) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
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["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
@@ -153,6 +156,7 @@ func (p *productSku) fillFieldMap() {
|
||||
p.fieldMap["price_min"] = p.PriceMin
|
||||
p.fieldMap["status"] = p.Status
|
||||
p.fieldMap["sort"] = p.Sort
|
||||
p.fieldMap["count_min"] = p.CountMin
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ func (s *productService) AllProductSaleInfos() ([]*m.Product, error) {
|
||||
q.ProductSku.Name,
|
||||
q.ProductSku.Code,
|
||||
q.ProductSku.Price,
|
||||
q.ProductSku.CountMin,
|
||||
).
|
||||
Where(
|
||||
q.ProductSku.ProductID.In(pids...),
|
||||
|
||||
@@ -47,6 +47,11 @@ func (s *productSkuService) Create(create CreateProductSkuData) (err error) {
|
||||
return core.NewBizErr("产品最低价格的格式不正确", err)
|
||||
}
|
||||
|
||||
countMin := int32(1)
|
||||
if create.CountMin != nil {
|
||||
countMin = *create.CountMin
|
||||
}
|
||||
|
||||
return q.ProductSku.Create(&m.ProductSku{
|
||||
ProductID: create.ProductID,
|
||||
DiscountId: create.DiscountID,
|
||||
@@ -54,6 +59,8 @@ func (s *productSkuService) Create(create CreateProductSkuData) (err error) {
|
||||
Name: create.Name,
|
||||
Price: price,
|
||||
PriceMin: priceMin,
|
||||
Sort: create.Sort,
|
||||
CountMin: countMin,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -64,6 +71,8 @@ type CreateProductSkuData struct {
|
||||
Name string `json:"name"`
|
||||
Price string `json:"price"`
|
||||
PriceMin string `json:"price_min"`
|
||||
Sort int32 `json:"sort"`
|
||||
CountMin *int32 `json:"count_min"`
|
||||
}
|
||||
|
||||
func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
@@ -95,6 +104,12 @@ func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
if update.Status != nil {
|
||||
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...)
|
||||
return err
|
||||
@@ -108,6 +123,8 @@ type UpdateProductSkuData struct {
|
||||
Price *string `json:"price"`
|
||||
PriceMin string `json:"price_min"`
|
||||
Status *int32 `json:"status"`
|
||||
Sort *int32 `json:"sort"`
|
||||
CountMin *int32 `json:"count_min"`
|
||||
}
|
||||
|
||||
func (s *productSkuService) Delete(id int32) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user