Commit ae00a568 by mushishixian

tj

parent 60c30781
......@@ -9,8 +9,7 @@ import (
"sync"
)
const goods_slice_count = 10 //每多少个型号id开启一个协程
const goodsSliceCount = 10 //每多少个型号id开启一个协程
/*
查询商品详情(自营或者联营)
......@@ -30,67 +29,65 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
*/
func Synchronization(c *gin.Context) {
common.PrintDebugHeader() //开启debug调试
common.PrintDebugHeader() //开启debug调试
zyService := service.ZiyingService{} //实例化自营查询
lyService := service.LyService{} //实例化自营查询
lyService := service.LyService{} //实例化自营查询
//抽取自营 或者联营 goods_id
GoodsIdStr := middleware.REQUEST["goods_id"]
GoodsIdStr := middleware.REQUEST["goods_id"]
if GoodsIdStr == "" {
common.Output(1001,"查询型号ID不得为空","")
common.Output(1001, "查询型号ID不得为空", "")
}
GoodsRes := make(map[string]interface{}, 0) //接收算好的数据
goodsIdArr := php2go.Explode(",",GoodsIdStr)
goodsIdArr := php2go.Explode(",", GoodsIdStr)
wg := sync.WaitGroup{}
zyGoodsId := make([]string,0)
lyGoodsId := make([]string,0)
for _,goods_id := range goodsIdArr {
if len(goods_id) < 19 { //自营
zyGoodsId = append(zyGoodsId,goods_id)
if len(zyGoodsId) >= goods_slice_count {
zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0)
for _, goodsId := range goodsIdArr {
if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId, &GoodsRes, &wg)
zyGoodsId = zyGoodsId[:0:0]
}
}else{ //联营
lyGoodsId = append(lyGoodsId,goods_id)
if len(lyGoodsId) >= goods_slice_count {
}
} else { //联营
lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml("ly增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg)
go lyService.LyGoodsDetail(lyGoodsId, &GoodsRes, &wg)
lyGoodsId = lyGoodsId[:0:0]
}
}
}
if len(zyGoodsId) >0 {
if len(zyGoodsId) > 0 {
common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId, &GoodsRes, &wg)
}
if len(lyGoodsId) >= goods_slice_count {
//if len(lyGoodsId) >= goodsSliceCount {
if len(lyGoodsId) >= 0 {
common.PrintDebugHtml("ly增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg)
go lyService.LyGoodsDetail(lyGoodsId, &GoodsRes, &wg)
}
wg.Wait()
common.Output(0,"查询成功",GoodsRes)
common.Output(0, "查询成功", GoodsRes)
}
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) {
func (qs *LyService) LyGoodsDetail(goodsIds []string, goodsRes *map[string]interface{}, 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