Commit ae00a568 by mushishixian

tj

parent 60c30781
...@@ -9,8 +9,7 @@ import ( ...@@ -9,8 +9,7 @@ import (
"sync" "sync"
) )
const goodsSliceCount = 10 //每多少个型号id开启一个协程
const goods_slice_count = 10 //每多少个型号id开启一个协程
/* /*
查询商品详情(自营或者联营) 查询商品详情(自营或者联营)
...@@ -38,59 +37,57 @@ func Synchronization(c *gin.Context) { ...@@ -38,59 +37,57 @@ func Synchronization(c *gin.Context) {
//抽取自营 或者联营 goods_id //抽取自营 或者联营 goods_id
GoodsIdStr := middleware.REQUEST["goods_id"] GoodsIdStr := middleware.REQUEST["goods_id"]
if GoodsIdStr == "" { if GoodsIdStr == "" {
common.Output(1001,"查询型号ID不得为空","") common.Output(1001, "查询型号ID不得为空", "")
} }
GoodsRes := make(map[string]interface{}, 0) //接收算好的数据 GoodsRes := make(map[string]interface{}, 0) //接收算好的数据
goodsIdArr := php2go.Explode(",",GoodsIdStr) goodsIdArr := php2go.Explode(",", GoodsIdStr)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
zyGoodsId := make([]string,0) zyGoodsId := make([]string, 0)
lyGoodsId := make([]string,0) lyGoodsId := make([]string, 0)
for _,goods_id := range goodsIdArr { for _, goodsId := range goodsIdArr {
if len(goods_id) < 19 { //自营 if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId,goods_id) zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= goods_slice_count { if len(zyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml("zy增加协程:") common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId) common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一 wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg) go zyService.ZyGoodsDetail(zyGoodsId, &GoodsRes, &wg)
zyGoodsId = zyGoodsId[:0:0] zyGoodsId = zyGoodsId[:0:0]
} }
}else{ //联营 } else { //联营
lyGoodsId = append(lyGoodsId,goods_id) lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goods_slice_count { if len(lyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml("ly增加协程:") common.PrintDebugHtml("ly增加协程:")
common.PrintDebugHtml(zyGoodsId) common.PrintDebugHtml(zyGoodsId)
wg.Add(1) wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg) go lyService.LyGoodsDetail(lyGoodsId, &GoodsRes, &wg)
lyGoodsId = lyGoodsId[:0:0] lyGoodsId = lyGoodsId[:0:0]
} }
} }
} }
if len(zyGoodsId) >0 { if len(zyGoodsId) > 0 {
common.PrintDebugHtml("zy增加协程:") common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId) common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一 wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg) 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("ly增加协程:")
common.PrintDebugHtml(zyGoodsId) common.PrintDebugHtml(zyGoodsId)
wg.Add(1) wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg) go lyService.LyGoodsDetail(lyGoodsId, &GoodsRes, &wg)
} }
wg.Wait() wg.Wait()
common.Output(0,"查询成功",GoodsRes) common.Output(0, "查询成功", GoodsRes)
} }
package service package service
import ( import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/model" "goods_machining/model"
"goods_machining/pkg/gredis"
"strings"
"sync" "sync"
) )
type LyService struct { 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 return
} }
...@@ -30,23 +30,23 @@ type ZiyingService struct { ...@@ -30,23 +30,23 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司 @param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true @param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true
*/ */
func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]interface{}, wg *sync.WaitGroup) { func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string, goodsRes *map[string]interface{}, wg *sync.WaitGroup) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
defer func() { defer func() {
wg.Done(); wg.Done()
redisConn.Close(); redisConn.Close()
}() }()
skuArr := gredis.HgetPi("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情 skuArr := gredis.HgetPi("search_r", "Self_SelfGoods", goodsIds) //批量获取商品详情
fast := middleware.REQUEST["power[fast]"] fast := middleware.REQUEST["power[fast]"]
for goods_id,info := range skuArr { for goods_id, info := range skuArr {
//拼接梯度价格 //拼接梯度价格
ladder_price_arr := gjson.Get(info,"ladder_price").Array() ladder_price_arr := gjson.Get(info, "ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0) ladderPrice := make([]model.LadderPrice, 0)
for _,v := range ladder_price_arr{ for _, v := range ladder_price_arr {
ladderPrice = append(ladderPrice, model.LadderPrice{ ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(), PriceUs: v.Get("price_us").Float(),
...@@ -56,7 +56,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -56,7 +56,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
//数组 //数组
A := orderedmap.New() //初始化有序map,拼接data 数据 A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id",common.MyInt64(goods_id)) A.Set("goods_id", common.MyInt64(goods_id))
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数 A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数 A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").Int()) // A.Set("brand_id", gjson.Get(info, "brand_id").Int()) //
...@@ -73,14 +73,14 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -73,14 +73,14 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
A.Set("mpq", gjson.Get(info, "mpq").Int()) // A.Set("mpq", gjson.Get(info, "mpq").Int()) //
A.Set("ladder_price", ladderPrice) // A.Set("ladder_price", ladderPrice) //
A.Set("update_time", gjson.Get(info, "update_time").Int()) // A.Set("update_time", gjson.Get(info, "update_time").Int()) //
A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String()," ")) // A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String(), " ")) //
A.Set("mpl", gjson.Get(info, "mpl").Int()) // A.Set("mpl", gjson.Get(info, "mpl").Int()) //
//处理库存 //处理库存
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存 lockStock := qs.skuLockNum(&redisConn, goods_id) //当前锁库库存
dbStock := gjson.Get(info, "stock").Int() //当前db库存 dbStock := gjson.Get(info, "stock").Int() //当前db库存
stock := dbStock-lockStock //当前可购买库存 stock := dbStock - lockStock //当前可购买库存
A.Set("stock",stock) A.Set("stock", stock)
A.Set("attrs", gjson.Get(info, "attrs").String()) // A.Set("attrs", gjson.Get(info, "attrs").String()) //
A.Set("cost", gjson.Get(info, "cost").String()) // A.Set("cost", gjson.Get(info, "cost").String()) //
...@@ -91,7 +91,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -91,7 +91,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
//处理货期 //处理货期
cn_delivery_time := gjson.Get(info, "cn_delivery_time").String() cn_delivery_time := gjson.Get(info, "cn_delivery_time").String()
if cn_delivery_time == "" { if cn_delivery_time == "" {
cn_delivery_time = "3-7工作日"; cn_delivery_time = "3-7工作日"
} }
A.Set("cn_delivery_time", cn_delivery_time) // 货期 A.Set("cn_delivery_time", cn_delivery_time) // 货期
...@@ -102,7 +102,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -102,7 +102,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
supplier_id := gjson.Get(info, "supplier_id").String() supplier_id := gjson.Get(info, "supplier_id").String()
supplier_name := "" supplier_name := ""
if supplier_id != "" { if supplier_id != "" {
supplier_name,_ = gredis.String(redisConn.Do("HGET","Self_SelfSupplierInfo",supplier_id)) supplier_name, _ = gredis.String(redisConn.Do("HGET", "Self_SelfSupplierInfo", supplier_id))
} }
A.Set("supplier_name", supplier_name) A.Set("supplier_name", supplier_name)
...@@ -110,7 +110,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -110,7 +110,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
goods_unit := gjson.Get(info, "goods_unit").String() goods_unit := gjson.Get(info, "goods_unit").String()
goods_unit_name := "" goods_unit_name := ""
if goods_unit != "" { if goods_unit != "" {
goods_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",goods_unit)) goods_unit_name, _ = gredis.String(redisConn.Do("HGET", "Self_Unit", goods_unit))
} }
A.Set("goods_unit_name", goods_unit_name) A.Set("goods_unit_name", goods_unit_name)
...@@ -118,35 +118,33 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -118,35 +118,33 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
packing := gjson.Get(info, "packing").String() packing := gjson.Get(info, "packing").String()
packing_name := "" packing_name := ""
if packing != "" { if packing != "" {
packing_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",packing)) packing_name, _ = gredis.String(redisConn.Do("HGET", "Self_Unit", packing))
} }
A.Set("packing_name",packing_name) // A.Set("packing_name", packing_name) //
//mpq包装名称 //mpq包装名称
mpq_unit_name := "" mpq_unit_name := ""
if packing != "" { if packing != "" {
mpq_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_UnitAlias",packing)) mpq_unit_name, _ = gredis.String(redisConn.Do("HGET", "Self_UnitAlias", packing))
} }
A.Set("mpq_unit_name",mpq_unit_name) // A.Set("mpq_unit_name", mpq_unit_name) //
//图片 //图片
img := gjson.Get(info, "goods_images").String() img := gjson.Get(info, "goods_images").String()
goods_images := "" goods_images := ""
if img != "" { if img != "" {
goods_images,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",img)) goods_images, _ = gredis.String(redisConn.Do("HGET", "Self_SelfGoodsSource", img))
} }
A.Set("goods_images", goods_images) // A.Set("goods_images", goods_images) //
//图片 //图片
pdf := gjson.Get(info, "pdf").String() pdf := gjson.Get(info, "pdf").String()
if pdf != "" { if pdf != "" {
pdf,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",pdf)) pdf, _ = gredis.String(redisConn.Do("HGET", "Self_SelfGoodsSource", pdf))
} }
A.Set("pdf", gjson.Get(info, "pdf").String()) A.Set("pdf", gjson.Get(info, "pdf").String())
} }
A.Set("scm_brand_name", gjson.Get(info, "scm_brand_name").String()) // A.Set("scm_brand_name", gjson.Get(info, "scm_brand_name").String()) //
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) // A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //
A.Set("ac_type", gjson.Get(info, "ac_type").Int()) // A.Set("ac_type", gjson.Get(info, "ac_type").Int()) //
...@@ -155,58 +153,54 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in ...@@ -155,58 +153,54 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
A.Set("class_id2_name", gjson.Get(info, "class_id2_name").String()) // A.Set("class_id2_name", gjson.Get(info, "class_id2_name").String()) //
//处理活动价 //处理活动价
A.Set("ac_type",0) A.Set("ac_type", 0)
A.Set("allow_coupon",1) A.Set("allow_coupon", 1)
Ac_price := qs.ActivityPrice(info,&redisConn) Ac_price := qs.ActivityPrice(info, &redisConn)
if Ac_price != nil { if Ac_price != nil {
keys := Ac_price.Keys() keys := Ac_price.Keys()
for _, k := range keys { for _, k := range keys {
v, _ := Ac_price.Get(k) v, _ := Ac_price.Get(k)
A.Set(k,v) //活动价格覆盖 A.Set(k, v) //活动价格覆盖
} }
} }
//处理系数 //处理系数
ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id)) ratio, _ := gredis.String(redisConn.Do("HGET", "zy_ratio_sku", goods_id))
if ratio != "" { if ratio != "" {
//拼接梯度价格 //拼接梯度价格
for _,v := range ladderPrice{ for _, v := range ladderPrice {
v.PriceAc = gjson.Get(ratio,"price_ac").Float() v.PriceAc = gjson.Get(ratio, "price_ac").Float()
} }
//获取立创价格 //获取立创价格
szlcPriceStr := `{"mykey":`+gjson.Get(ratio,"szlc_price").String()+`}` szlcPriceStr := `{"mykey":` + gjson.Get(ratio, "szlc_price").String() + `}`
ladder_price_arr := gjson.Get(szlcPriceStr,"mykey").Array() ladder_price_arr := gjson.Get(szlcPriceStr, "mykey").Array()
ladderPriceLc := make([]model.LadderPriceLc,0) ladderPriceLc := make([]model.LadderPriceLc, 0)
for _,v := range ladder_price_arr{ for _, v := range ladder_price_arr {
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{ ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
Purchases: v.Get("Purchases").Int(), Purchases: v.Get("Purchases").Int(),
Price: v.Get("price").Float(), Price: v.Get("price").Float(),
}) })
} }
A.Set("allow_coupon",gjson.Get(ratio,"allow_coupon").String()) A.Set("allow_coupon", gjson.Get(ratio, "allow_coupon").String())
A.Set("allow_presale",gjson.Get(ratio,"allow_presale").String()) A.Set("allow_presale", gjson.Get(ratio, "allow_presale").String())
A.Set("szlc_price",ladderPriceLc) A.Set("szlc_price", ladderPriceLc)
} }
//处理限额 //处理限额
goods_quota,_ := gredis.String(redisConn.Do("HGET","Self_goods_quota",goods_id)) goods_quota, _ := gredis.String(redisConn.Do("HGET", "Self_goods_quota", goods_id))
if goods_quota != "" { if goods_quota != "" {
A.Set("is_quota",1) A.Set("is_quota", 1)
A.Set("quota_num",gjson.Get(goods_quota,"num").Int()) A.Set("quota_num", gjson.Get(goods_quota, "num").Int())
} }
//处理是否能购买 //处理是否能购买
if gjson.Get(info, "status").String() != "1" || if gjson.Get(info, "status").String() != "1" ||
len(ladder_price_arr) == 0 { len(ladder_price_arr) == 0 {
A.Set("is_buy",0) A.Set("is_buy", 0)
}else{ } else {
A.Set("is_buy",1) A.Set("is_buy", 1)
} }
(*goodsRes)[goods_id] = A (*goodsRes)[goods_id] = A
} }
} }
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