完善定价与套餐关联表结构
This commit is contained in:
@@ -21,6 +21,7 @@ func (s *productSkuService) Page(req *core.PageReq, productId *int32) (result []
|
||||
do = append(do, q.ProductSku.ProductID.Eq(*productId))
|
||||
}
|
||||
return q.ProductSku.
|
||||
Joins(q.ProductSku.Discount).
|
||||
Where(do...).
|
||||
FindByPage(req.GetOffset(), req.GetLimit())
|
||||
}
|
||||
@@ -32,20 +33,20 @@ func (s *productSkuService) Create(create CreateProductSkuData) (err error) {
|
||||
}
|
||||
|
||||
return q.ProductSku.Create(&m.ProductSku{
|
||||
ProductID: create.ProductID,
|
||||
Code: create.Code,
|
||||
Name: create.Name,
|
||||
Price: price,
|
||||
Discount: create.Discount,
|
||||
ProductID: create.ProductID,
|
||||
DiscountId: create.DiscountID,
|
||||
Code: create.Code,
|
||||
Name: create.Name,
|
||||
Price: price,
|
||||
})
|
||||
}
|
||||
|
||||
type CreateProductSkuData struct {
|
||||
ProductID int32 `json:"product_id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Price string `json:"price"`
|
||||
Discount float32 `json:"discount"`
|
||||
ProductID int32 `json:"product_id"`
|
||||
DiscountID int32 `json:"discount_id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Price string `json:"price"`
|
||||
}
|
||||
|
||||
func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
@@ -58,8 +59,8 @@ func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
}
|
||||
do = append(do, q.ProductSku.Price.Value(price))
|
||||
}
|
||||
if update.Discount != nil {
|
||||
do = append(do, q.ProductSku.Discount.Value(*update.Discount))
|
||||
if update.DiscountID != nil {
|
||||
do = append(do, q.ProductSku.DiscountId.Value(*update.DiscountID))
|
||||
}
|
||||
if update.Code != nil {
|
||||
do = append(do, q.ProductSku.Code.Value(*update.Code))
|
||||
@@ -73,14 +74,26 @@ func (s *productSkuService) Update(update UpdateProductSkuData) (err error) {
|
||||
}
|
||||
|
||||
type UpdateProductSkuData struct {
|
||||
ID int32 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
Name *string `json:"name"`
|
||||
Price *string `json:"price"`
|
||||
Discount *float32 `json:"discount"`
|
||||
ID int32 `json:"id"`
|
||||
DiscountID *int32 `json:"discount_id"`
|
||||
Code *string `json:"code"`
|
||||
Name *string `json:"name"`
|
||||
Price *string `json:"price"`
|
||||
}
|
||||
|
||||
func (s *productSkuService) Delete(id int32) (err error) {
|
||||
_, err = q.ProductSku.Where(q.ProductSku.ID.Eq(id)).UpdateColumn(q.ProductSku.DeletedAt, time.Now())
|
||||
return
|
||||
}
|
||||
|
||||
func (s *productSkuService) BatchUpdateDiscount(data BatchUpdateSkuDiscountData) (err error) {
|
||||
_, err = q.ProductSku.Where(q.ProductSku.ProductID.Eq(data.ProductID)).UpdateSimple(
|
||||
q.ProductSku.DiscountId.Value(data.DiscountID),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
type BatchUpdateSkuDiscountData struct {
|
||||
ProductID int32 `json:"product_id"`
|
||||
DiscountID int32 `json:"discount_id"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user