service_ly.go
5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package service
import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"sort"
"sync"
)
type LyService struct {
}
type Power struct {
UserId string `json:"user_id"`
Mobile string `json:"mobile"`
Email string `json:"email"`
Member string `json:"member"`
VerifyBlacklist string `json:"verify_blacklist"`
Invoice string `json:"invoice"`
SpecialInvoice string `json:"special_invoice"`
}
/*
联营数据详情
*/
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r")
defer func() {
//wg.Done()
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的信息
spuList := ls.getSpuList(skuArr)
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr {
if skuStr == "" {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr)
sku.GoodsId = goodsId
spu := spuList[sku.SpuId]
//读取包装字段的缓存
if sku.SupplierId == 7 {
//sku_raw_map哪里写入(成意写的)
packing, _ := redis.String(redisConn.Do("HGET", "sku_raw_map", goodsId))
sku.Packing = gjson.Get(packing, "pack").String()
}
sku = ls.GetGoodsImages(sku, spu)
//pdf
pdf := gjson.Get(spu, "pdf").String()
spuLargeImage := gjson.Get(spu, "images_l").String()
if pdf == "" || (php2go.Strlen(spuLargeImage) < 5) {
sku.Pdf = ""
} else {
sku.Pdf = pdf
}
//处理分类
//fast的参数含义,为了节省开销性能的参数,传1就不会去分类这些参数
if fast != "1" {
sku = ls.GetGoodsClass(sku, spu)
}
//获取商品名称
if sku.GoodsName == "" {
sku.GoodsName = gjson.Get(spu, "spu_name").String()
}
//获取品牌名称
brandId := gjson.Get(spu, "brand_id").Int()
brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId))
sku.BrandName = brandName
//获取税务信息
if fast != "1" { //仅提供价格和库存
if sku.GoodsName != "" && brandId != 0 {
sku.ErpTax = ls.GetErpTax(sku.GoodsName, brandName)
}
sku.SupplierName = ls.GetPoolSupplierName(sku.SupplierId)
//获取属性
sku.Attrs = ls.GetSpuAttr(sku.SpuId)
}
//获取供应链标准品牌
//什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去
//继来那边对接的标准品牌(下单的时候)
sku.ScmBrand = ls.GetScmBrand(brandId)
//处理过期
if gjson.Get(skuStr, "is_expire").Int() != 0 {
sku.LadderPrice = nil
}
//处理活动
sku.AcType = 0
sku.AllowCoupon = 1
sku.BrandId = brandId
//活动标识
hasActivity := false
//判断是否有新客价权利
if isNewCustomer == "true" || isNewCustomer == "1" {
//获取新客价
sku = ls.GetActivityPrice(sku, "_NewCustomer", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//获取活动价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//获取会员价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "_Member", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
//排序
sort.Sort(LadderPriceSorter(sku.LadderPrice))
//取出第一个阶梯价
purchases := sku.LadderPrice[0].Purchases
if purchases > sku.Moq {
sku.Moq = purchases
}
}
//获取系数
sku = ls.GetCoefficient(sku)
//仅提供价格和库存
if fast != "1" {
if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
}
//还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"]
}
if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"]
}
}
//处理是否可以购买
if sku.Mpq == 0 {
sku.Mpq = 1
}
if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice
} else {
sku.LadderPriceResult = []int{}
}
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A
}
ch <- GoodsRes
}
func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
var spuIds []string
for _, skuStr := range skuArr {
spuId := gjson.Get(skuStr, "spu_id").String()
spuIds = append(spuIds, spuId)
}
//批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds)
return
}