package goods import ( "applet/app/admin/md" "applet/app/db" "applet/app/svc" "applet/app/utils" "github.com/gin-gonic/gin" ) // 获取列表数据 func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, int64, error) { var goodsListResp []md.MallGoodListResp // 获取分库链接 engine := db.Db // 查询goods数据表获取数据 mallGoodsList, skus, total, err := db.GetMallGoodsListLeftOnMallSku(engine, req) if err != nil { return nil, 0, err } var tmpMap interface{} scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c) if err != nil { return nil, 0, err } //判断是不是学校下单时的商品列表 计算对应的价格 gids := make([]string, 0) for _, item := range mallGoodsList { gids = append(gids, item["goods_id"]) } for _, item := range mallGoodsList { var goods md.MallGoodListResp goods.GoodsId = item["goods_id"] goods.SaleState = utils.StrToInt(item["sale_state"]) goods.Sales = utils.StrToInt(item["sales"]) goods.CreateAt = item["create_at"] // 商品主图 if item["image_list"] != "" { utils.Unserialize([]byte(item["image_list"]), &tmpMap) var imageListUrlTmp []string for _, v := range tmpMap.([]interface{}) { imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string))) } if imageListUrlTmp != nil { goods.Image = imageListUrlTmp[0] } } goods.UpdateAt = item["update_at"] goods.Title = item["title"] // 状态 switch utils.StrToInt64(item["sale_state"]) { case 1.00: goods.SaleStateText = "銷售中" break case 2.00: goods.SaleStateText = "下架" break } // sku for _, skuItem := range skus { if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) { goods.SkuList = append(goods.SkuList, skuItem) } } // 获取价格、库存、重量范围、利润空间 goods.Price = item["price"] // spe var spe []map[string]interface{} var speTmp []map[string]interface{} utils.Unserialize([]byte(item["spe"]), &spe) for _, itemSpe := range spe { tmp := make(map[string]interface{}) tmp["type"] = "text" tmp["name"] = itemSpe["name"] subTmp := make([]map[string]interface{}, 0) for i, v := range itemSpe["values"].([]interface{}) { subTmp = append(subTmp, map[string]interface{}{ "key": i, "name": v, }) } tmp["values"] = subTmp speTmp = append(speTmp, tmp) } goods.Spe = speTmp goodsListResp = append(goodsListResp, goods) } return goodsListResp, total, err } // 获取列表数据(给方案用) //func GetMallGoodsListForScheme(c *gin.Context, req *md.MallGoodsListReq, schemeId int) (interface{}, int64, error) { // schemeDb := db.SchemeDb{} // schemeDb.Set() // schemeInfo, err := schemeDb.GetScheme(schemeId) // if err != nil { // return nil, 0, err // } // if schemeInfo == nil { // return nil, 0, errors.New("未查询到相应方案记录") // } // // var goodsListResp []md.MallGoodListResp // // 获取分库链接 // engine := db.Db // // 查询goods数据表获取数据 // mallGoodsList, skus, total, err := db.GetMallGoodsListLeftOnMallSku(engine, req) // if err != nil { // return nil, 0, err // } // var tmpMap interface{} // scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c) // if err != nil { // return nil, 0, err // } // // //获取方案中sku的价格 // var skuIds []string // for _, v := range skus { // skuIds = append(skuIds, utils.Int64ToStr(v.SkuId)) // } // // var schemeWithSkusMap = map[int]*model.SchemeWithSku{} // if len(skuIds) > 0 { // var schemeWithSkus []*model.SchemeWithSku // err = engine.Where("1 = 1").And(fmt.Sprintf("sku_id In (%s)", strings.Join(skuIds, ","))).Find(&schemeWithSkus) // if err != nil { // return nil, 0, err // } // for _, v := range schemeWithSkus { // schemeWithSkusMap[v.SkuId] = v // } // } // // for _, item := range mallGoodsList { // var goods md.MallGoodListResp // goods.GoodsId = item["goods_id"] // goods.SaleState = utils.StrToInt(item["sale_state"]) // goods.Sales = utils.StrToInt(item["sales"]) // goods.CreateAt = item["create_at"] // // // 商品主图 // if item["image_list"] != "" { // utils.Unserialize([]byte(item["image_list"]), &tmpMap) // var imageListUrlTmp []string // for _, v := range tmpMap.([]interface{}) { // imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string))) // } // if imageListUrlTmp != nil { // goods.Image = imageListUrlTmp[0] // } // } // // goods.UpdateAt = item["update_at"] // goods.Title = item["title"] // // // 状态 // switch utils.StrToInt64(item["sale_state"]) { // case 1.00: // goods.SaleStateText = "銷售中" // break // case 2.00: // goods.SaleStateText = "下架" // break // } // // // sku // for _, skuItem := range skus { // if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) { // goods.SkuList = append(goods.SkuList, skuItem) // } // } // // 获取价格、库存、重量范围、利润空间 // goods.Price = item["price"] // goodsListResp = append(goodsListResp, goods) // } // // return goodsListResp, total, err //} func CheckSkuCode(c *gin.Context, skuCode, goodsId string) (bool, error) { engine := db.Db isHas, _, err := db.GetMallSkuBySkuCode(engine, skuCode, goodsId) if err != nil { return false, err } return isHas, nil }