|
|
@@ -3,11 +3,30 @@ package goods |
|
|
|
import ( |
|
|
|
"applet/app/admin/md" |
|
|
|
"applet/app/db" |
|
|
|
"applet/app/db/model" |
|
|
|
"applet/app/svc" |
|
|
|
"applet/app/utils" |
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func GetSkuScheme(engine *xorm.Engine, EnterpriseId string, gids []string) map[int64]model.SchemeWithSku { |
|
|
|
var skuSchemeMap = make(map[int64]model.SchemeWithSku) |
|
|
|
if utils.StrToInt64(EnterpriseId) > 0 { |
|
|
|
var enterpriseScheme model.SchemeWithEnterprise |
|
|
|
engine.Where("enterprise_id=?", EnterpriseId).Get(&enterpriseScheme) |
|
|
|
if enterpriseScheme.SchemeId > 0 { |
|
|
|
|
|
|
|
var skuScheme []model.SchemeWithSku |
|
|
|
engine.In("goods_id", gids).And("scheme_id=?", enterpriseScheme.SchemeId).Find(&skuScheme) |
|
|
|
for _, v := range skuScheme { |
|
|
|
skuSchemeMap[v.SkuId] = v |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return skuSchemeMap |
|
|
|
} |
|
|
|
|
|
|
|
// 获取列表数据 |
|
|
|
func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, int64, error) { |
|
|
|
var goodsListResp []md.MallGoodListResp |
|
|
@@ -24,7 +43,12 @@ func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, in |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
|
|
|
|
//判断是不是学校下单时的商品列表 计算对应的价格 |
|
|
|
gids := make([]string, 0) |
|
|
|
for _, item := range mallGoodsList { |
|
|
|
gids = append(gids, item["goods_id"]) |
|
|
|
} |
|
|
|
skuSchemeMap := GetSkuScheme(engine, req.EnterpriseId, gids) |
|
|
|
for _, item := range mallGoodsList { |
|
|
|
var goods md.MallGoodListResp |
|
|
|
goods.GoodsId = item["goods_id"] |
|
|
@@ -60,6 +84,11 @@ func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, in |
|
|
|
// sku |
|
|
|
for _, skuItem := range skus { |
|
|
|
if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) { |
|
|
|
//方案的价格 |
|
|
|
skuScheme, ok := skuSchemeMap[skuItem.SkuId] |
|
|
|
if ok { |
|
|
|
skuItem.Price = skuScheme.Price |
|
|
|
} |
|
|
|
goods.SkuList = append(goods.SkuList, skuItem) |
|
|
|
} |
|
|
|
} |
|
|
|