商品列表sku价格

This commit is contained in:
范俊成 2023-09-20 15:32:51 +08:00
parent 2baf62d990
commit e19dd2e368
3 changed files with 42 additions and 5 deletions

View File

@ -60,6 +60,24 @@ func GoodsList(c *gin.Context) {
app.Error(c, http.StatusInternalServerError, errors.New("goods list err"), msg)
return
}
var ids []uint32
for _, goods := range goodsList {
ids = append(ids, goods.GoodsId)
}
if len(ids) > 0 {
cm := models.GetGoodsFirstSkuCombo(ids)
if cm != nil {
for _, combo := range cm {
for i, goods := range goodsList {
if combo.GoodsId == goods.GoodsId {
goodsList[i].Combo = &combo
}
}
}
}
}
ret := map[string]interface{}{
"count": totalCount,
"list": goodsList,

View File

@ -67,10 +67,12 @@ type Goods struct {
PriceVm uint32 `json:"price_vm"` // 积分价格
PriceRm uint32 `json:"price_rm"` // 人民币价格
//Stock uint32 `json:"stock"` // 库存
ShowDiscount int `json:"show_discount"` //是否展示折扣价
GoodsCat *GoodsCat `json:"goods_cat" gorm:"-"`
GoodsDiscount *GoodsDiscount `json:"goods_discount" gorm:"-"`
Attributes []GoodsAttribute `json:"attributes" gorm:"-"`
GoodsCat *GoodsCat `json:"goods_cat" gorm:"-"`
GoodsDiscount *GoodsDiscount `json:"goods_discount" gorm:"-"`
Attributes []GoodsAttribute `json:"attributes" gorm:"-"`
Combo *GoodsAttributeCombo `json:"combo" gorm:"-"`
}
func (*Goods) TableName() string {
@ -120,6 +122,7 @@ type GoodsAttribute struct {
Stock uint32 `json:"stock"` // 库存
SoldCount uint32 `json:"sold_count"` // 已销售数量
Sort int `json:"sort"` //排序
//PriceRm uint32 `json:"price_rm"` // 人民币价格
PriceOriginal uint32 `json:"price_original"` // 市场价
@ -525,7 +528,9 @@ func (m *Goods) GetDetail() error {
return err
}
var goodsAttributes []GoodsAttribute
err = orm.Eloquent.Table("goods_attribute").Where("goods_id=?", m.GoodsId).
err = orm.Eloquent.Table("goods_attribute").
Where("goods_id=?", m.GoodsId).
Order("sort desc").
Find(&goodsAttributes).Error
if err != nil {
log.Error().Msgf("goods attribute err:%#v", err)
@ -1395,3 +1400,17 @@ func (o *GoodsOrder) SetDeliverStore() error {
o.DeliverStore = store
return nil
}
func GetGoodsFirstSkuCombo(goodsId []uint32) []GoodsAttributeCombo {
var list []GoodsAttributeCombo
err := orm.Eloquent.
Raw("SELECT b.* FROM (SELECT goods_id, MAX(sort) FROM goods_attribute GROUP BY goods_id) AS a INNER JOIN goods_attribute_combo b ON a.goods_id = b.goods_id where a.goods_id in (?) GROUP BY b.goods_id", goodsId).
Scan(&list).
Error
if err != nil {
logger.Error("get goods first sku failed", err)
return nil
}
return list
}

View File

@ -32,7 +32,7 @@ settings:
enabledjob: false
jwt:
# token 密钥,生产环境时及的修改
secret: adminqYrhCcQRvVNAaEo4h4osoW
secret: go-admin
# token 过期时间 单位:秒
timeout: 3600
database: