Commit f3699e46 by 杨树贤

添加仓库列表

parent 99bee35b
Showing with 80 additions and 17 deletions
......@@ -107,6 +107,7 @@ type LySku struct {
CostUs float64 `json:"cost_us"`
IsZiying int `json:"is_ziying"`
BatchFormat interface{} `json:"batch_format"`
SpotList []Spot `json:"spot_list"`
}
type BatchFormatItem struct {
......@@ -114,6 +115,18 @@ type BatchFormatItem struct {
Value interface{} `json:"value"`
}
type Spot struct {
Id int `json:"id"`
Name string `json:"name"`
// GoodsId string `json:"goods_id"`
// OrgId int `json:"org_id"`
// Currency int `json:"currency"`
// Stock int `json:"stock"`
// BatchSn string `json:"batch_sn"`
// SinglePrice string `json:"single_price"`
// NewCost string `json:"new_cost"`
}
type DiscountRatio struct {
Ratio float64 `json:"ratio"`
RatioUsd float64 `json:"ratio_usd"`
......
......@@ -24,6 +24,13 @@ var batchCodeMap = map[int]string{
6: "5年内",
}
var warehouseIdText = map[string]string{
"7": "深圳仓",
"9": "深圳仓",
"10": "香港仓",
"51": "京东寄售仓",
}
func (ls *LyService) GetSkuBatchFormat(sku *model.LySku) {
if sku.BatchSn != "" {
var items []model.BatchFormatItem
......@@ -43,27 +50,29 @@ func (ls *LyService) GetSkuBatchFormat(sku *model.LySku) {
}
sku.BatchFormat = items
return
}
if sku.SupplierId == 0 {
sku.BatchFormat = []model.BatchFormatItem{}
return
}
} else {
if sku.SupplierId == 0 {
sku.BatchFormat = []model.BatchFormatItem{}
return
}
supplierBatch := ls.getSupplierBatch(sku.SupplierId)
if len(supplierBatch) == 0 {
sku.BatchFormat = []model.BatchFormatItem{}
return
supplierBatch := ls.getSupplierBatch(sku.SupplierId)
if len(supplierBatch) == 0 {
sku.BatchFormat = []model.BatchFormatItem{}
} else {
var items []model.BatchFormatItem
for _, code := range supplierBatch {
if label, ok := batchCodeMap[code]; ok {
items = append(items, model.BatchFormatItem{Name: label, Value: "可供应"})
}
}
sku.BatchFormat = items
}
}
var items []model.BatchFormatItem
for _, code := range supplierBatch {
if label, ok := batchCodeMap[code]; ok {
items = append(items, model.BatchFormatItem{Name: label, Value: "可供应"})
}
if sku.IsZiying == 1 && sku.GoodsId != "" {
sku.SpotList = ls.getSpotList(sku.GoodsId)
}
sku.BatchFormat = items
}
func (ls *LyService) getSupplierBatch(supplierId int64) []int {
......@@ -95,3 +104,44 @@ func (ls *LyService) getSupplierBatch(supplierId int64) []int {
}
return result
}
func (ls *LyService) getSpotList(goodsId string) []model.Spot {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
skuSpotStr, err := redis.String(redisCon.Do("HGET", "sku_spot", goodsId))
if err != nil || skuSpotStr == "" {
return []model.Spot{}
}
skuSpotData := gjson.Parse(skuSpotStr)
if !skuSpotData.IsObject() {
return []model.Spot{}
}
var stockList []model.Spot
skuSpotData.ForEach(func(key, value gjson.Result) bool {
id := key.Int()
idStr := strconv.Itoa(int(id))
name, exists := warehouseIdText[idStr]
if !exists {
name = idStr
}
stockItem := model.Spot{
Id: int(id),
Name: name,
// GoodsId: value.Get("goods_id").String(),
// OrgId: int(value.Get("org_id").Int()),
// Currency: int(value.Get("currency").Int()),
// Stock: int(value.Get("stock").Int()),
// BatchSn: value.Get("batch_sn").String(),
// SinglePrice: value.Get("single_price").String(),
// NewCost: value.Get("new_cost").String(),
}
stockList = append(stockList, stockItem)
return true
})
return stockList
}
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