商品列表sku价格

This commit is contained in:
范俊成 2023-09-20 16:37:06 +08:00
parent fc5fe71c2e
commit 3676b41f33

View File

@ -1403,8 +1403,18 @@ func (o *GoodsOrder) SetDeliverStore() error {
func GetGoodsFirstSkuCombo(goodsId []uint32) []GoodsAttributeCombo {
var list []GoodsAttributeCombo
//查询每个商品按sort字端排序的最大的一个sku的价格
err := orm.Eloquent.
Raw("SELECT b.* FROM goods_attribute 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).
Raw(`
SELECT b.*
FROM (SELECT id
FROM goods_attribute d
INNER JOIN (SELECT goods_id, MAX(sort) AS max_sort FROM goods_attribute GROUP BY goods_id) c
ON c.goods_id = d.goods_id AND c.max_sort = d.sort) AS a
INNER JOIN goods_attribute_combo b ON a.id = b.goods_attribute_id
WHERE b.goods_id IN (?)
GROUP BY b.goods_id
`, goodsId).
Scan(&list).
Error
if err != nil {