Commit 672be618 by hcy001
parents 6e649394 bb5a0cbc
......@@ -18,4 +18,5 @@ cmd.exe~
/cmd/http
/doc/spuTest
/doc/test3
/.history
package controller
import (
"github.com/gin-gonic/gin"
"go_sku_server/pkg/common"
"go_sku_server/service"
)
//获取样片分类列表
func SampleClassList(ctx *gin.Context) {
var sampleClassService service.SampleClassService
classList, err := sampleClassService.GetSampleClassList()
if err != nil {
common.Output(ctx, 0, "success", err.Error())
return
}
common.Output(ctx, 0, "success", classList)
return
}
//获取样片列表
func SampleList(ctx *gin.Context) {
var sampleClassService service.SampleService
sampleList, err := sampleClassService.GetSampleList(ctx)
if err != nil {
common.Output(ctx, 0, "success", err.Error())
return
}
common.Output(ctx, 0, "success", sampleList)
return
}
......@@ -33,12 +33,12 @@ const goodsSliceCount = 10 //每多少个型号id开启一个协程
*/
func CommonController(ctx *gin.Context) map[string]interface{} {
GoodsIdStr := ctx.Request.FormValue("goods_id")
common.PrintDebugHeader(ctx) //开启debug调试
//抽取自营 或者联营 goods_id
zyService := service.ZiyingService{} //实例化自营查询
lyService := service.LyService{} //实例化自营查询
var goodsIdArr []string
//抽取自营 或者联营 goods_id
GoodsIdStr := ctx.Request.FormValue("goods_id")
if GoodsIdStr == "" {
goodsIdMap := ctx.PostFormMap("goods_id")
for _, goodsId := range goodsIdMap {
......@@ -52,7 +52,6 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
return nil
}
//wg := sync.WaitGroup{} //协程
ch := make(chan sync.Map) //管道
p := 0 //总共协程
zyGoodsId := make([]string, 0)
......@@ -95,11 +94,9 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
if len(lyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "ly增加协程1004:")
common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p++
}
//wg.Wait()
//异步map最后转成map
temp := make(map[string]interface{})
......@@ -124,11 +121,6 @@ func Synchronization(ctx *gin.Context) {
res := CommonController(ctx)
common.Output(ctx, 0, "success", res)
}
func Synchronization1(ctx *gin.Context) {
res := CommonController(ctx)
common.Output(ctx, 0, "success", res)
}
/*
健康监测
......
......@@ -13,7 +13,7 @@ func PushMsg(listName string, data string) {
listName,
"",
"direct",
"amqp://guest:guest@192.168.2.232:5672/",
"amqp://guest:guest@192.168.1.252:5672/",
}
rabbitmq.Send(queueExchange, data)
}
\ No newline at end of file
......@@ -65,6 +65,8 @@ type LySku struct {
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
StandardBrand StandardBrand `json:"standard_brand"`
GoodsTag GoodsTag `json:"goods_tag"`
}
type PriceActivity struct {
......@@ -77,7 +79,7 @@ type PriceActivity struct {
type GiftActivity struct {
ActivityCommon
CanAdminOrder interface{} `json:"can_admin_order"`
CanAdminOrder interface{} `json:"can_admin_order"`
ItemList []ActivityItem `json:"items,omitempty"`
}
......@@ -89,6 +91,19 @@ type ActivityCommon struct {
UserScope int `json:"user_scope,omitempty"`
}
type StandardBrand struct {
StandardBrandId int `json:"standard_brand_id,omitempty"`
BrandName string `json:"brand_name,omitempty"`
BrandLogo string `json:"brand_logo,omitempty"`
}
type GoodsTag struct {
GoodsLabel int `json:"goods_label,omitempty"`
GoodsLabelName string `json:"goods_label_name,omitempty"`
GoodsTag []int `json:"goods_tag,omitempty"`
GoodsTagNames []string `json:"goods_tag_names,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String()
......@@ -148,6 +163,11 @@ func InitSkuData(sku string) (data LySku) {
canal := gjson.Get(sku, "canal").String()
data.Canal = canal
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if data.Canal == "L0001175" {
data.Encoded = "10142-L"
}
cpTime := gjson.Get(sku, "cp_time").Int()
data.CpTime = cpTime
......
package model
type Sample struct {
GoodsId int `json:"goods_id"`
Id int `json:"id"`
ClassId int `json:"class_id"`
MaxNumber int `json:"max_number"`
Quota int `json:"quota"`
ClassName string `xorm:"-" json:"class_name"`
GoodsInfo interface{} `xorm:"-" json:"goods_info"`
}
package model
type SampleClass struct {
Id int `json:"id"`
ClassName string `json:"class_name"`
ParentId int `json:"parent_id"`
Sort int `json:"sort"`
ClassIcon string `json:"class_icon"`
Status int `json:"status"`
}
package vars
//商品类型字段
var GoodsLabel = map[int]string{
1: "国内现货",
2: "猎芯期货",
3: "国际现货",
}
//商品标签对应的展示
//1精选,2原厂直供,3认证,4当天发货
var GoodsTags = map[int]string{
1: "精选",
2: "原厂直供",
3: "认证",
4: "当天发货",
}
......@@ -31,6 +31,10 @@ func InitRouter() *gin.Engine {
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
r.POST("SkuEdit",controller.Error_Middleware(),controller.SkuEdit)
//样片相关
r.POST("/self/sample/class/list",controller.SampleClassList)
r.POST("/self/sample/list",controller.SampleList)
return r
}
......@@ -2,6 +2,7 @@ package service
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
......@@ -23,7 +24,11 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
if spuAttr.Attrs != "" {
fmt.Println(spuAttr.AttrsExtend)
//如果有attrs_extend,就去取attrs_extend
if len(spuAttr.AttrsExtend) != 0 {
return spuAttr.AttrsExtend
} else if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil {
......
......@@ -10,11 +10,6 @@ import (
)
type LadderPriceService struct {
}
func adderprice() {
}
/**
......@@ -24,100 +19,100 @@ func adderprice() {
* @param integer $currency 币种 1人民币 2美元
* @return [type]
*/
func (LP *LadderPriceService) GetPriceInfoByNum(ladderPriceRequest model.LadderPriceRequest, goodsInfo map[string]interface{}) (map[string]interface{},*e.ApiError) {
func (LP *LadderPriceService) GetPriceInfoByNum(ladderPriceRequest model.LadderPriceRequest, goodsInfo map[string]interface{}) (map[string]interface{}, *e.ApiError) {
//此service 对 商详数据的操作都是使用的 gjson包
res:=make(map[string]interface{})
res := make(map[string]interface{})
goodsJsonResult,err:=LP.getGoodsInfo(goodsInfo,ladderPriceRequest.GoodsId)
if(err!=nil){
return res,err
goodsJsonResult, err := LP.getGoodsInfo(goodsInfo, ladderPriceRequest.GoodsId)
if err != nil {
return res, err
}
costly:=ladderPriceRequest.Costly//这个字段暂时不知道什么意思
costly := ladderPriceRequest.Costly //这个字段暂时不知道什么意思
//根据num 从 多个阶梯价数组 获取到对应的阶梯价
ladderPriceOne,err:=LP.getLadderPrice(goodsJsonResult,ladderPriceRequest.GoodsId,ladderPriceRequest.Num,costly)
ladderPriceOne, err := LP.getLadderPrice(goodsJsonResult, ladderPriceRequest.GoodsId, ladderPriceRequest.Num, costly)
num:=ladderPriceRequest.Num
purchases:=ladderPriceOne.Get("purchases").Int();
if purchases>ladderPriceRequest.Num{
num=purchases
num := ladderPriceRequest.Num
purchases := ladderPriceOne.Get("purchases").Int()
if purchases > ladderPriceRequest.Num {
num = purchases
}
goodsType:=goodsJsonResult.Get("goods_type").Int()
acType:=goodsJsonResult.Get("ac_type").Int()
if((goodsType==1 || goodsType==2) && acType!=1 && ladderPriceRequest.Currency!=1){//美元
res["price_us"]=ladderPriceOne.Get("price_us").Float()
res["price_us_total"]=common.MyRound(gconv.Float64(res["price_us"])*gconv.Float64(num),4)
goodsInfo["ac_type"]=0
}else{//人民币
res["price_cn"]=ladderPriceOne.Get("price_cn").Float()
res["price_cn_total"]=common.MyRound(gconv.Float64(res["price_cn"])*gconv.Float64(num),4)//人民币原价总价
priceAc:=ladderPriceOne.Get("price_ac").Float()
if priceAc != 0{
res["price_ac"]=priceAc
res["price_ac_total"]=common.MyRound(priceAc*gconv.Float64(num),4)
goodsType := goodsJsonResult.Get("goods_type").Int()
acType := goodsJsonResult.Get("ac_type").Int()
if (goodsType == 1 || goodsType == 2) && acType != 1 && ladderPriceRequest.Currency != 1 { //美元
res["price_us"] = ladderPriceOne.Get("price_us").Float()
res["price_us_total"] = common.MyRound(gconv.Float64(res["price_us"])*gconv.Float64(num), 4)
goodsInfo["ac_type"] = 0
} else { //人民币
res["price_cn"] = ladderPriceOne.Get("price_cn").Float()
res["price_cn_total"] = common.MyRound(gconv.Float64(res["price_cn"])*gconv.Float64(num), 4) //人民币原价总价
priceAc := ladderPriceOne.Get("price_ac").Float()
if priceAc != 0 {
res["price_ac"] = priceAc
res["price_ac_total"] = common.MyRound(priceAc*gconv.Float64(num), 4)
}
}
ladder:=make([]map[string]interface{},0)
a:=goodsJsonResult.Get("ladder_price").String()
err1:=json.Unmarshal([]byte(a),&ladder)//json Unmarshal一下,为了让返回格式没那么多斜划线
if(err1!=nil){
return res,e.NewApiError("json.Unmarshal ladder_price 报错"+err1.Error())
ladder := make([]map[string]interface{}, 0)
a := goodsJsonResult.Get("ladder_price").String()
err1 := json.Unmarshal([]byte(a), &ladder) //json Unmarshal一下,为了让返回格式没那么多斜划线
if err1 != nil {
return res, e.NewApiError("json.Unmarshal ladder_price 报错" + err1.Error())
}
res["ladder_price"]=ladder
res["goods_info"]=goodsInfo[ladderPriceRequest.GoodsId]
res["num"]=num
return res,nil
res["ladder_price"] = ladder
res["goods_info"] = goodsInfo[ladderPriceRequest.GoodsId]
res["num"] = num
return res, nil
}
func (LP *LadderPriceService)getGoodsInfo(goodsInfo map[string]interface{}, goodsId string) (gjson.Result, *e.ApiError) {
func (LP *LadderPriceService) getGoodsInfo(goodsInfo map[string]interface{}, goodsId string) (gjson.Result, *e.ApiError) {
var info gjson.Result
goodsInfoJson:=""
goodsInfoJson := ""
//把商品详情数据转化为json,方便用gjson处理
if byteS,err:=json.Marshal(goodsInfo);err!=nil{
if byteS, err := json.Marshal(goodsInfo); err != nil {
return info, e.NewApiError(err.Error())
}else{
goodsInfoJson=string(byteS)
} else {
goodsInfoJson = string(byteS)
}
goodsResult:=gjson.Get(goodsInfoJson,goodsId)
if(goodsResult.Exists()!=true){
goodsResult := gjson.Get(goodsInfoJson, goodsId)
if goodsResult.Exists() != true {
return info, e.NewApiError("未找到对应SKU", 20001)
}
return goodsResult, nil
}
func (LP *LadderPriceService )getLadderPrice(goodsJsonResult gjson.Result,goodsId string,num int64,costly int) (gjson.Result,*e.ApiError){
func (LP *LadderPriceService) getLadderPrice(goodsJsonResult gjson.Result, goodsId string, num int64, costly int) (gjson.Result, *e.ApiError) {
var res gjson.Result
ladderPriceS:=goodsJsonResult.Get("ladder_price")
if(len(ladderPriceS.Array())>0){
var price =gjson.Result{}
for k,item:=range ladderPriceS.Array(){
purchases:=item.Get("purchases").Int()
if(k==0){
price=item//默认最小数量
var res gjson.Result
ladderPriceS := goodsJsonResult.Get("ladder_price")
if len(ladderPriceS.Array()) > 0 {
var price = gjson.Result{}
for k, item := range ladderPriceS.Array() {
purchases := item.Get("purchases").Int()
if k == 0 {
price = item //默认最小数量
}
if(gconv.Int(costly)==1){//这一句没懂 Costly 代表什么意思
if gconv.Int(costly) == 1 { //这一句没懂 Costly 代表什么意思
break
}
if(purchases<=num){
price=item
if purchases <= num {
price = item
}
}
if(price.Exists()==false){
return res,e.NewApiError("这个SKU没有阶梯价",504003)
if price.Exists() == false {
return res, e.NewApiError("这个SKU没有阶梯价", 504003)
}
return price,nil
return price, nil
}else{
return res,e.NewApiError("这个SKU没有阶梯价",104002)
} else {
return res, e.NewApiError("这个SKU没有阶梯价", 104002)
}
}
func NewLadderPriceService() *LadderPriceService{
func NewLadderPriceService() *LadderPriceService {
return &LadderPriceService{}
}
\ No newline at end of file
}
......@@ -35,16 +35,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConn.Close()
}()
fast := ctx.Request.FormValue("power[fast]")
//isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
//power := Power{
// UserId: ctx.Request.FormValue("power[user_id]"),
// Mobile: ctx.Request.FormValue("power[mobile]"),
// Email: ctx.Request.FormValue("power[email]"),
// Member: ctx.Request.FormValue("power[member]"),
// Invoice: ctx.Request.FormValue("power[invoice]"),
// SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
// VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
//}
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息
......@@ -108,6 +98,9 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//继来那边对接的标准品牌(下单的时候)
sku.ScmBrand = ls.GetScmBrand(brandId)
//获取新版的标准品牌
sku.StandardBrand = ls.GetStandardBrand(brandId)
//处理过期
if gjson.Get(skuStr, "is_expire").Int() != 0 {
sku.LadderPrice = nil
......@@ -167,6 +160,9 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
// sku.Stock = 0
//}
var TagService TagsService
sku.GoodsTag = TagService.GetTags(sku.GoodsId)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面
......
......@@ -85,10 +85,16 @@ func (ls *LyService) GetCacheClass(classId int64) string {
type SpuAttr struct {
SpuId string `bson:"spu_id"`
AttrsExtend string `bson:"attrs_extend"`
AttrsExtend []AttrsExtend `bson:"attrs_extend"`
Attrs string `bson:"attrs"`
}
type AttrsExtend struct {
AttrName string `bson:"attr_name" json:"attr_name"`
AttrValue string `bson:"attr_value" json:"attr_value"`
AttrUnit string `bson:"attr_unit" json:"attr_unit,omitempty"`
}
//H获取供应链标准品牌
func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
redisCon := gredis.Conn("default_r")
......@@ -109,6 +115,23 @@ func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
}
}
//获取新版标准品牌
func (ls *LyService) GetStandardBrand(brandId int64) (standardBrand model.StandardBrand) {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
standardBrandId, _ := redis.Int(redisCon.Do("HGET", "standard_brand_mapping", brandId))
if standardBrandId != 0 {
standardBrandStr, err := redis.String(redisCon.Do("HGET", "standard_brand", standardBrandId))
if err != nil {
logger.Select("sku_query").Error(err.Error())
}
standardBrand.BrandName = gjson.Get(standardBrandStr, "brand_name").String()
standardBrand.StandardBrandId = int(gjson.Get(standardBrandStr, "standard_brand_id").Int())
standardBrand.BrandLogo = gjson.Get(standardBrandStr, "brandLogo").String()
}
return standardBrand
}
type ExtendFee struct {
Cn struct {
Max interface{} `json:"max"`
......@@ -323,12 +346,12 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s
//为了兼容供应商修改的问题
if cnDeliveryTime != "周" && cnDeliveryTime != "天" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String()
}else{
} else {
delivery["cn_delivery"] = ""
}
if usDeliveryTime != "周" && usDeliveryTime != "天" {
delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String()
}else{
} else {
delivery["hk_delivery"] = ""
}
}
......
package service
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-xorm/xorm"
"github.com/gogf/gf/util/gconv"
"go_sku_server/model"
"go_sku_server/pkg/mysql"
"sync"
"time"
)
type SampleService struct {
}
//获取分类列表
func (ss *SampleService) GetSampleList(ctx *gin.Context) (data map[string]interface{}, err error) {
id := gconv.Int(ctx.Request.FormValue("id"))
goodsId := gconv.Int(ctx.Request.FormValue("goods_id"))
classId := gconv.Int(ctx.Request.FormValue("class_id"))
page := gconv.Int(ctx.Request.FormValue("page"))
limit := gconv.Int(ctx.Request.FormValue("limit"))
if limit == 0 {
limit = 10
}
var start int
if page == 0 || page == 1 {
page = 1
start = 0
} else {
start = (page - 1) * limit
}
query := mysql.Conn("liexin_data").Table("lie_sample").Where("status = ?", 1)
if id != 0 {
query.Where("id = ?", id)
}
if goodsId != 0 {
query.Where("goods_id = ?", goodsId)
}
if classId != 0 {
query.Where("class_id = ?", classId)
}
var sampleList []model.Sample
query.OrderBy("update_time DESC").Limit(limit, start)
err = query.Find(&sampleList)
if err != nil && err != xorm.ErrNotExist {
return nil, err
}
//构建和之前接口的数据一样的格式,有点操蛋
data = make(map[string]interface{})
goodsMap := make(map[string]interface{})
var goodsIdsSlice []string
sampleGoodsMap := make(map[string]model.Sample)
for _, sample := range sampleList {
goodsIdStr := gconv.String(sample.GoodsId)
goodsIdsSlice = append(goodsIdsSlice, goodsIdStr)
}
goodsMap = ss.GetGoods(ctx, goodsIdsSlice)
for _, sample := range sampleList {
classService := SampleClassService{}
class, _ := classService.GetSampleClass(sample.ClassId)
sample.ClassName = class.ClassName
sample.GoodsInfo = goodsMap[gconv.String(sample.GoodsId)]
sampleGoodsMap[gconv.String(sample.GoodsId)] = sample
}
data["data"] = sampleGoodsMap
return data, err
}
func (ss *SampleService) GetGoods(ctx *gin.Context, goodsIds []string) map[string]interface{} {
//抽取自营 或者联营 goods_id
zyService := ZiyingService{} //实例化自营查询
lyService := LyService{} //实例化自营查询
ch := make(chan sync.Map) //管道
p := 0 //总共协程
zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0)
for _, goodsId := range goodsIds {
if goodsId == "" {
continue
}
if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= 10 {
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
zyGoodsId = zyGoodsId[:0:0]
p++
}
} else { //联营
lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= 10 {
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
lyGoodsId = lyGoodsId[:0:0]
p++
}
}
}
if len(zyGoodsId) > 0 {
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
p++
}
if len(lyGoodsId) > 0 {
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p++
}
//异步map最后转成map
temp := make(map[string]interface{})
for i := 0; i < p; i++ {
select {
case GoodsRes := <-ch:
GoodsRes.Range(func(k, v interface{}) bool {
s, _ := k.(string)
temp[s] = v
return true
})
case <-time.After(time.Second * 20):
fmt.Println("协程超时", "sku", 1)
}
}
return temp
}
package service
import (
"encoding/json"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mysql"
)
type SampleClassService struct {
}
//获取分类列表
func (ls *SampleClassService) GetSampleClassList() (classList []model.SampleClass, err error) {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
//var class model.SampleClass
classListStr, err := redis.String(redisCon.Do("GET", "Self_sample_class_list_web"))
if classListStr == "" {
err = mysql.Conn("liexin_data").Table("lie_sample_class").
Select("id,class_name,class_icon,parent_id,status,sort").
Where("status = ?", 1).OrderBy("sort DESC").Find(&classList)
if err != nil {
return
}
str, err := json.Marshal(&classList)
if err != nil {
return nil, err
}
_, err = redisCon.Do("SET", "Self_sample_class_list_web", str)
if err != nil {
return nil, err
}
_, err = redisCon.Do("EXPIRE", "Self_sample_class_list_web", 60)
if err != nil {
return nil, err
}
} else {
err := json.Unmarshal([]byte(classListStr), &classList)
if err != nil {
return nil, err
}
}
return classList, err
}
//获取分类信息
func (ls *SampleClassService) GetSampleClass(classId int) (class model.SampleClass, err error) {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
classStr, err := redis.String(redisCon.Do("HGET", "Self_sample_class_list", classId))
if err != nil {
return
}
class.Id = gconv.Int(classId)
class.ClassName = gjson.Get(classStr, "class_name").String()
class.Status = int(gjson.Get(classStr, "status").Int())
class.Sort = int(gjson.Get(classStr, "sort").Int())
return class, err
}
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/vars"
)
//标签相关服务,包括goods_label
type TagsService struct {
}
//当天发货标签
const TagZiyingSku = 4
//获取Spu的属性
func (ts *TagsService) GetTags(skuId string) (goodsTags model.GoodsTag) {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
goodsTagsStr, _ := redis.String(redisCon.Do("HGET", "goods_tag", skuId))
goodsLabel := ""
//goods_tag
var tags []int
var tagNames []string
if goodsTagsStr != "" {
//goods_label
goodsLabelType := int(gjson.Get(goodsTagsStr, "goods_label").Int())
goodsLabelMap := vars.GoodsLabel
goodsLabel = goodsLabelMap[goodsLabelType]
goodsTags.GoodsLabelName = goodsLabel
goodsTags.GoodsLabel = goodsLabelType
for _, tagResult := range gjson.Get(goodsTagsStr, "tags").Array() {
tagName := vars.GoodsTags[int(tagResult.Int())]
tagNames = append(tagNames, tagName)
tags = append(tags, int(tagResult.Int()))
}
}
//如果是自营商品Id,就写死当天发货标签
if len(skuId) < 10 {
if !php2go.InArray(TagZiyingSku, tags) {
tags = append(tags, TagZiyingSku)
tagNames = append(tagNames, vars.GoodsTags[TagZiyingSku])
}
}
goodsTags.GoodsTagNames = tagNames
goodsTags.GoodsTag = tags
return goodsTags
}
......@@ -289,6 +289,10 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c
}
}
//获取标签信息
var tagService TagsService
A.Set("goods_tag", tagService.GetTags(goodsId))
//最后写入sync map
(GoodsRes).Store(goodsId, 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