Commit ba09e550 by mushishixian

修复

parents e82002d5 ae00a568
Showing with 84 additions and 2 deletions
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/model"
"goods_machining/pkg/gredis"
"strings"
"sync"
)
type LyService struct {
}
/*
营数据详情
营数据详情
*/
func (qs *LyService) LyGoodsDetail(goodsIds []string, wg *sync.WaitGroup) (results model.LyResponse) {
redisConn := gredis.Conn("search_r")
defer func() {
wg.Done()
redisConn.Close()
}()
//批量获取商品详情
skuArr := gredis.HgetPi("search_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息
spuList := qs.getSpuList(goodsIds)
fmt.Println(spuList)
for goodsId, info := range skuArr {
A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("packing", "")
//读取包装字段的缓存
if gjson.Get(info, "supplier_id").Int() == 7 {
//sku_raw_map哪里写入(成意写的)
packing, err := redis.String(redisConn.Do("HGET", "SKU_RAW_MAP", goodsId))
if err == nil {
A.Set("packing", gjson.Get(packing, "pack").String())
}
}
A.Set("goods_id", goodsId)
//去获取spu的信息
spuInfo := spuList[goodsId]
spuLargeImage := gjson.Get(spuInfo, "images_l").String()
A.Set("images_l", spuLargeImage)
if spuLargeImage != "" && php2go.Strlen(spuLargeImage) < 5 {
A.Set("images_l", "")
}
pdf := gjson.Get(spuInfo, "pdf").String()
A.Set("pdf", pdf)
if pdf == "" || (php2go.Strlen(spuLargeImage) < 5) {
A.Set("pdf", "")
}
//商品图片不存在用大图代替
goodsImage := gjson.Get(info, "goods_images").String()
A.Set("goods_images", goodsImage)
if goodsImage == "" && spuLargeImage != "" {
goodsImage = spuLargeImage
A.Set("goods_images", spuLargeImage)
}
//加上是否是rocelec图片的判断,如果是的话,就将图片设置为空
if strings.Contains(goodsImage, "rocelec") {
A.Set("goods_images", "")
}
goodsName := gjson.Get(info, "goods_name").String()
A.Set("goods_name", goodsName)
if goodsName == "" {
A.Set("goods_name", gjson.Get(spuInfo, "spu_name"))
}
//获取品牌名称
brandId := gjson.Get(spuInfo, "brand_id").String()
brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId))
A.Set("brand_name", brandName)
//todo 条件判断
//获取税务信息
if true {//仅提供价格和库存
}
//(*goodsRes)[goodsId] = A
}
return
}
func (qs *LyService) getSpuList(goodsIds []string) (spuList map[string]string) {
redisConn := gredis.Conn("search_r")
defer redisConn.Close()
//批量获取spu详情
spuList = gredis.HgetPi("search_r", "sku", goodsIds)
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment