Commit 9f88f381 by hcy

京东库存

parent db02deb2
......@@ -22,6 +22,7 @@ type LySku struct {
Mpq int64 `json:"mpq"`
Multiple int64 `json:"multiple"`
Stock int64 `json:"stock"`
StockJd int64 `json:"stock_jd"` //京东可售库存
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"`
......
......@@ -313,7 +313,7 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, go
sku.LadderPriceResult = []int{}
}
sku.Stock = ls.GetStock(sku)
sku.Stock, sku.StockJd = ls.GetStock(sku)
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
......
......@@ -2,6 +2,7 @@ package service
import (
"encoding/json"
"github.com/gogf/gf/util/gconv"
"go_sku_server/model"
c "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
......@@ -258,26 +259,32 @@ func (ls *LyService) GetIsBuy(sku model.LySku) (isBuy int) {
}
// 获取库存
func (ls *LyService) GetStock(sku model.LySku) (stock int64) {
func (ls *LyService) GetStock(sku model.LySku) (stock_all, jd_stock int64) {
//过期修改库存为0
if sku.IsExpire == 1 && sku.SupplierId != 17 {
sku.Stock = 0
}
stock_all_t := sku.Stock
jd_stock_t := int64(0)
//这里还有一个逻辑
//如果是寄售的数据(source=12),获取的库存还要减去锁库的库存
if sku.Source == 12 || php2go.InArray(sku.Canal, []string{"L0018319", "L0013521", "L0018562", "L0017764", "L0003270", "L0012413", "L0013521"}) {
//获取锁库库存
//获取锁库库存
redisCon := gredis.Conn("spu")
defer redisCon.Close()
stockStr, _ := redis.String(redisCon.Do("HGET", "sku_lock_stock", sku.GoodsId))
lockStock, _ := strconv.ParseInt(stockStr, 10, 64)
if sku.Stock < lockStock {
return 0
stock_all_t = 0
} else {
return sku.Stock - lockStock
stock_all_t = sku.Stock - lockStock
}
//获取京东库存
jdStockShiwuStr, _ := redis.String(redisCon.Do("HGET", "sku_jd_stock", sku.GoodsId)) // 京东单个sku实物总数量
jdStockLockStr, _ := redis.String(redisCon.Do("HGET", "sku_lock_stock_jd", sku.GoodsId)) //京东锁库数量
jd_stock_t = gconv.Int64(jdStockShiwuStr) - gconv.Int64(jdStockLockStr)
}
return sku.Stock
return stock_all_t, jd_stock_t
}
// 合并spu的信息
......
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