Commit 576fd30c by mushishixian

fix

parent bc8f6310
...@@ -64,28 +64,29 @@ type LySku struct { ...@@ -64,28 +64,29 @@ type LySku struct {
//活动信息 //活动信息
HasGiftActivity int `json:"has_gift_activity"` HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"` GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo struct { ActivityInfo PriceActivity `json:"activity_info"`
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
} `json:"activity_info"`
} }
type PriceActivity struct { type PriceActivity struct {
HasActivity bool `json:"-"` ActivityCommon
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
Ratio float64 `json:"ratio"` Ratio float64 `json:"ratio"`
} }
type GiftActivity struct { type GiftActivity struct {
HasActivity bool `json:"-"` ActivityCommon
ActivityId int `json:"activity_id,omitempty"`
ActivityName int `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
ItemList []ActivityItem `json:"items,omitempty"` ItemList []ActivityItem `json:"items,omitempty"`
} }
type ActivityCommon struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ActivityName string `json:"activity_name,omitempty"`
AllowCoupon int `json:"-"`
SignText string `json:"sign_text"`
Sign string `json:"sign"`
ShowName string `json:"show_name"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 //为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) { func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String() goodsSn := gjson.Get(sku, "goods_sn").String()
......
...@@ -61,38 +61,52 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac ...@@ -61,38 +61,52 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac
//如果是整个供应商搞活动,则直接返回系数 //如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity { if activity.EntireSupplierActivity {
hasActivity = true hasActivity = true
giftActivity.ItemList = activity.ItemList goto INFO
giftActivity.ActivityId = activity.ActivityId
} }
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false hasActivity = false
goto INFO
} }
//判断是否是搞活动的品牌 //判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true hasActivity = true
giftActivity.ItemList = activity.ItemList goto INFO
giftActivity.ActivityId = activity.ActivityId
} }
//如果是专卖,则要去判断canal,如果是自营,则去判断分类 //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 { if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) { if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true hasActivity = true
giftActivity.ItemList = activity.ItemList goto INFO
giftActivity.ActivityId = activity.ActivityId
} }
} else { } else {
if as.CheckClass(checkData.ClassId, activity) { if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true hasActivity = true
giftActivity.ItemList = activity.ItemList goto INFO
giftActivity.ActivityId = activity.ActivityId }
}
INFO:
if hasActivity {
giftActivity.ActivityName = activity.ActivityName
giftActivity.ActivityId = activity.ActivityId
giftActivity = model.GiftActivity{
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
},
} }
} }
} }
giftActivity.HasActivity = hasActivity
return return
} }
...@@ -108,36 +122,49 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a ...@@ -108,36 +122,49 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//如果是整个供应商搞活动,则直接返回系数 //如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity { if activity.EntireSupplierActivity {
hasActivity = true hasActivity = true
priceActivity.Ratio = activity.Ratio goto INFO
} }
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false hasActivity = false
goto INFO
} }
//判断是否是搞活动的品牌 //判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true hasActivity = true
priceActivity.Ratio = activity.Ratio goto INFO
} }
//如果是专卖,则要去判断canal,如果是自营,则去判断分类 //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 { if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) { if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true hasActivity = true
priceActivity.Ratio = activity.Ratio goto INFO
} }
} else { } else {
if as.CheckClass(checkData.ClassId, activity) { if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true hasActivity = true
priceActivity.Ratio = activity.Ratio goto INFO
} }
} }
INFO:
if hasActivity { if hasActivity {
priceActivity.AllowCoupon = activity.AllowCoupon
priceActivity.ActivityName = activity.ActivityName priceActivity.ActivityName = activity.ActivityName
priceActivity.ActivityId = activity.ActivityId priceActivity.ActivityId = activity.ActivityId
priceActivity = model.PriceActivity{
Ratio: activity.Ratio,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
},
}
} }
} }
......
...@@ -188,8 +188,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku { ...@@ -188,8 +188,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
if priceActivity.HasActivity { if priceActivity.HasActivity {
sku.AcType = 10 sku.AcType = 10
sku.Ratio = priceActivity.Ratio sku.Ratio = priceActivity.Ratio
sku.ActivityInfo.ActivityId = priceActivity.ActivityId sku.ActivityInfo = priceActivity
sku.ActivityInfo.ActivityName = priceActivity.ActivityName
} }
if giftActivity.HasActivity { if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity) sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
......
...@@ -31,31 +31,30 @@ type ZiyingService struct { ...@@ -31,31 +31,30 @@ 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(ctx *gin.Context,goodsIds []string, ch chan sync.Map) { func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
defer func() { defer func() {
//wg.Done(); //wg.Done();
redisConn.Close(); redisConn.Close()
}() }()
skuArr := gredis.Hmget("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情 skuArr := gredis.Hmget("search_r", "Self_SelfGoods", goodsIds) //批量获取商品详情
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goods_id,info := range skuArr { for goodsId, info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" { if gjson.Get(info, "goods_name").String() == "" {
//fmt.Print("zy goods_name为空-----",goods_id,skuArr) //fmt.Print("zy goods_name为空-----",goods_id,skuArr)
GoodsRes.Store(goods_id,false) GoodsRes.Store(goodsId, false)
continue; continue
} }
//拼接属性 //拼接属性
attrJsonArr := gjson.Parse(gjson.Get(info,"attrs").String()).Array() attrJsonArr := gjson.Parse(gjson.Get(info, "attrs").String()).Array()
attrs := make([]model.Attrs,0) attrs := make([]model.Attrs, 0)
for _,d := range attrJsonArr{ for _, d := range attrJsonArr {
if d.Get("attr_name").String() == "" { if d.Get("attr_name").String() == "" {
continue; continue
} }
attrs = append(attrs, model.Attrs{ attrs = append(attrs, model.Attrs{
AttrName: d.Get("attr_name").String(), AttrName: d.Get("attr_name").String(),
...@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch ...@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
} }
//数组 //数组
A := orderedmap.New() //初始化有序map,拼接data 数据 A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id",common.MyInt64(goods_id)) A.Set("goods_id", common.MyInt64(goodsId))
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()) //
other_attrs := gjson.Get(info,"other_attrs").String() otherAttrs := gjson.Get(info, "other_attrs").String()
if other_attrs == "" { if otherAttrs == "" {
A.Set("other_attrs","") A.Set("other_attrs", "")
}else{ } else {
B := make(map[string]string) B := make(map[string]string)
pick_type := gjson.Get(other_attrs,"pick_type").String() pickType := gjson.Get(otherAttrs, "pick_type").String()
length := gjson.Get(other_attrs,"length").String() length := gjson.Get(otherAttrs, "length").String()
gross_wegiht := gjson.Get(other_attrs,"gross_wegiht").String() grossWegiht := gjson.Get(otherAttrs, "gross_wegiht").String()
if pick_type != "" { if pickType != "" {
B["pick_type"] = pick_type B["pick_type"] = pickType
} }
B["length"] = length B["length"] = length
if gross_wegiht != "" { if grossWegiht != "" {
B["gross_wegiht"] = gross_wegiht B["gross_wegiht"] = grossWegiht
} }
A.Set("other_attrs",B) A.Set("other_attrs", B)
} }
class_id1 := gjson.Get(info, "class_id1").Int() classId1 := gjson.Get(info, "class_id1").Int()
class_id2 := gjson.Get(info, "class_id2").Int() classId2 := gjson.Get(info, "class_id2").Int()
class_id1_name := ""; classId1Name := ""
if class_id1 >0 { if classId1 > 0 {
class_id1_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id1)) classId1Info, _ := gredis.String(redisConn.Do("HGET", "Self_SelfClassInfo", classId1))
class_id1_name = gjson.Get(class_id1_info,"class_name").String() classId1Name = gjson.Get(classId1Info, "class_name").String()
} }
class_id2_name := ""; classId2Name := ""
if class_id2 >0 { if classId2 > 0 {
class_id2_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id2)) classId2Info, _ := gredis.String(redisConn.Do("HGET", "Self_SelfClassInfo", classId2))
class_id2_name = gjson.Get(class_id2_info,"class_name").String() classId2Name = gjson.Get(classId2Info, "class_name").String()
} }
A.Set("class_id1", class_id1) // A.Set("class_id1", classId1) //
A.Set("class_id2", class_id2) // A.Set("class_id2", classId2) //
A.Set("class_id1_name", class_id1_name) // A.Set("class_id1_name", classId1Name) //
A.Set("class_id2_name", class_id2_name) // A.Set("class_id2_name", classId2Name) //
A.Set("goods_name", gjson.Get(info, "goods_name").String()) // A.Set("goods_name", gjson.Get(info, "goods_name").String()) //
A.Set("status", gjson.Get(info, "status").Int()) // A.Set("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) // A.Set("encoded", gjson.Get(info, "encoded").String()) //
A.Set("encap", gjson.Get(info, "encap").String()) // A.Set("encap", gjson.Get(info, "encap").String()) //
A.Set("packing", gjson.Get(info, "packing").Int()) // A.Set("packing", gjson.Get(info, "packing").Int()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) // A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) //
A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) // A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) //
A.Set("moq", gjson.Get(info, "moq").Int()) // A.Set("moq", gjson.Get(info, "moq").Int()) //
A.Set("mpq", gjson.Get(info, "mpq").Int()) // A.Set("mpq", gjson.Get(info, "mpq").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("update_time", gjson.Get(info, "update_time").Int()) // A.Set("mpl", gjson.Get(info, "mpl").Int()) //
A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String()," ")) //
A.Set("mpl", gjson.Get(info, "mpl").Int()) //
//处理库存 //处理库存
A.Set("stock",0) //默认库存为0 A.Set("stock", 0) //默认库存为0
dbStock := gjson.Get(info, "stock").Int() //当前db库存 dbStock := gjson.Get(info, "stock").Int() //当前db库存
if dbStock > 0 { if dbStock > 0 {
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存 lockStock := qs.skuLockNum(&redisConn, goodsId) //当前锁库库存
stockG := dbStock-lockStock //当前可购买库存 stockG := dbStock - lockStock //当前可购买库存
if stockG >0 { if stockG > 0 {
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //锁定库存 A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //锁定库存
A.Set("stock",dbStock) A.Set("stock", dbStock)
} }
A.Set("saler_atio", "") // A.Set("saler_atio", "") //
} }
if len(attrs) == 0 { if len(attrs) == 0 {
A.Set("attrs", "") //属性值 A.Set("attrs", "") //属性值
}else{ } else {
A.Set("attrs", attrs) // A.Set("attrs", attrs) //
} }
A.Set("cost", gjson.Get(info, "cost").String()) // A.Set("cost", gjson.Get(info, "cost").String()) //
A.Set("new_cost", gjson.Get(info, "new_cost").String()) // A.Set("new_cost", gjson.Get(info, "new_cost").String()) //
A.Set("supplier_stock", gjson.Get(info, "supplier_stock").Int()) // A.Set("supplier_stock", gjson.Get(info, "supplier_stock").Int()) //
A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").Int()) // A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").Int()) //
//处理货期 //处理货期
cn_delivery_time := gjson.Get(info, "cn_delivery_time").String() cnDeliveryTime := gjson.Get(info, "cn_delivery_time").String()
if cn_delivery_time == "" { if cnDeliveryTime == "" {
cn_delivery_time = "3-7工作日"; cnDeliveryTime = "3-7工作日"
} }
A.Set("cn_delivery_time", cn_delivery_time) // 货期 A.Set("cn_delivery_time", cnDeliveryTime) // 货期
//查询品牌名称 //查询品牌名称
brand_id := gjson.Get(info, "brand_id").Int() brand_id := gjson.Get(info, "brand_id").Int()
brand_info,_ := gredis.String(redisConn.Do("HGET","Self_Brand",brand_id)) brand_info, _ := gredis.String(redisConn.Do("HGET", "Self_Brand", brand_id))
A.Set("brand_name", gjson.Get(brand_info, "brand_name").String()) // A.Set("brand_name", gjson.Get(brand_info, "brand_name").String()) //
if fast != "1" { //不是快速查询 if fast != "1" { //不是快速查询
// 供应商名称 // 供应商名称
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 != "" {
supplierInfo,_ := gredis.String(redisConn.Do("HGET","Self_SelfSupplierInfo",supplier_id)) supplierInfo, _ := gredis.String(redisConn.Do("HGET", "Self_SelfSupplierInfo", supplier_id))
supplier_name = gjson.Get(supplierInfo,"supplier_name").String() supplier_name = gjson.Get(supplierInfo, "supplier_name").String()
} }
A.Set("supplier_name", supplier_name) A.Set("supplier_name", supplier_name)
//商品单位 //商品单位
goods_unit := gjson.Get(info, "goods_unit").String() goodsUnit := gjson.Get(info, "goods_unit").String()
goods_unit_name := "" goodsUnitName := ""
if goods_unit != "" { if goodsUnit != "" {
goods_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",goods_unit)) goodsUnitName, _ = gredis.String(redisConn.Do("HGET", "Self_Unit", goodsUnit))
} }
A.Set("goods_unit_name", goods_unit_name) A.Set("goods_unit_name", goodsUnitName)
//包装名称 //包装名称
packing := gjson.Get(info, "packing").String() packing := gjson.Get(info, "packing").String()
packing_name := "" packingName := ""
if packing != "" { if packing != "" {
packing_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",packing)) packingName, _ = gredis.String(redisConn.Do("HGET", "Self_Unit", packing))
} }
A.Set("packing_name",packing_name) // A.Set("packing_name", packingName) //
//mpq包装名称 //mpq包装名称
mpq_unit_name := "" mpqUnitName := ""
if packing != "" { if packing != "" {
mpq_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_UnitAlias",packing)) mpqUnitName, _ = gredis.String(redisConn.Do("HGET", "Self_UnitAlias", packing))
} }
A.Set("mpq_unit_name",mpq_unit_name) // A.Set("mpq_unit_name", mpqUnitName) //
//图片 //图片
img := gjson.Get(info, "goods_images").String() img := gjson.Get(info, "goods_images").String()
goods_images := "" goodsImages := ""
if img != "" { if img != "" {
goods_images,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",img)) goodsImages, _ = gredis.String(redisConn.Do("HGET", "Self_SelfGoodsSource", img))
} }
A.Set("goods_images", gjson.Get(goods_images,"url").String()) A.Set("goods_images", gjson.Get(goodsImages, "url").String())
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(pdf, "url").String()) A.Set("pdf", gjson.Get(pdf, "url").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()) //
//处理系数 //处理系数
ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id)) ratio, _ := gredis.String(redisConn.Do("HGET", "zy_ratio_sku", goodsId))
var PriceAcXi float64 = 0 //系数 var PriceAcXi float64 = 0 //系数
if ratio != "" { if ratio != "" {
PriceAcXi = gjson.Get(ratio,"price_ac").Float() PriceAcXi = gjson.Get(ratio, "price_ac").Float()
//获取立创价格 //获取立创价格
if gjson.Parse("szlc_price").String() == "" { if gjson.Parse("szlc_price").String() == "" {
A.Set("szlc_price",nil) A.Set("szlc_price", nil)
}else{ } else {
ladderPriceLc := make([]model.LadderPriceLc,0) ladderPriceLc := make([]model.LadderPriceLc, 0)
for _,v := range gjson.Parse("szlc_price").Array(){ for _, v := range gjson.Parse("szlc_price").Array() {
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("szlc_price",ladderPriceLc) A.Set("szlc_price", ladderPriceLc)
} }
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("ac_type", 6) //系数 A.Set("ac_type", 6) //系数
} }
//拼接梯度价格 //拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array() ladderPriceArr := gjson.Get(info, "ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0) ladderPrice := make([]model.LadderPrice, 0)
for _,v := range ladderPriceArr{ for _, v := range ladderPriceArr {
if v.Get("purchases").String() == "" { if v.Get("purchases").String() == "" {
continue; continue
} }
price_cn := php2go.Round(v.Get("price_cn").Float()*10000)/10000 priceCn := php2go.Round(v.Get("price_cn").Float()*10000) / 10000
if PriceAcXi == 0 { if PriceAcXi == 0 {
ladderPrice = append(ladderPrice, model.LadderPrice{ ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: price_cn, PriceCn: priceCn,
}) })
}else{ } else {
ladderPrice = append(ladderPrice, model.LadderPrice{ ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: price_cn, PriceCn: priceCn,
PriceAc: PriceAcXi, PriceAc: PriceAcXi,
}) })
} }
} }
if len(ladderPrice) == 0 { if len(ladderPrice) == 0 {
A.Set("ladder_price", "") // A.Set("ladder_price", "") //
}else{ } else {
A.Set("ladder_price", ladderPrice) // A.Set("ladder_price", ladderPrice) //
} }
//处理限额 //处理限额
goods_quota,_ := gredis.String(redisConn.Do("HGET","Self_goods_quota",goods_id)) goodsQuota, _ := gredis.String(redisConn.Do("HGET", "Self_goods_quota", goodsId))
if goods_quota != "" { if goodsQuota != "" {
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(goodsQuota, "num").Int())
} }
//处理是否能购买 //处理是否能购买
if gjson.Get(info, "status").String() != "1" || len(ladderPriceArr) == 0 { if gjson.Get(info, "status").String() != "1" || len(ladderPriceArr) == 0 {
A.Set("is_buy",0) A.Set("is_buy", 0)
}else{ } else {
A.Set("is_buy",1) A.Set("is_buy", 1)
} }
//提前设置活动信息的默认值
A.Set("activity_info", map[string]interface{}{})
A.Set("has_gift_activity", 0)
A.Set("gift_activity", map[string]interface{}{})
if PriceAcXi == 0 { //没有系数价格才处理活动价 if PriceAcXi == 0 { //没有系数价格才处理活动价
//处理活动价 //处理活动价
A.Set("ac_type",0) A.Set("ac_type", 0)
A.Set("allow_coupon",1) A.Set("allow_coupon", 1)
Ac_price := qs.ActivityPrice(ctx,info,&redisConn) AcPrice := qs.ActivityPrice(ctx, info)
if Ac_price != nil { if AcPrice != nil {
keys := Ac_price.Keys() keys := AcPrice.Keys()
for _, k := range keys { for _, k := range keys {
v, _ := Ac_price.Get(k) v, _ := AcPrice.Get(k)
A.Set(k,v) //活动价格覆盖 A.Set(k, v) //活动价格覆盖
} }
} }
} }
//最后写入sync map //最后写入sync map
(GoodsRes).Store(goods_id,A) (GoodsRes).Store(goodsId, A)
} }
ch <- GoodsRes ch <- GoodsRes
} }
...@@ -8,28 +8,28 @@ import ( ...@@ -8,28 +8,28 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
) )
//自营公共函数类 //自营公共函数类
/* /*
计算单个sku总锁库数量 计算单个sku总锁库数量
*/ */
func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{ func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 {
reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId)) reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId))
if err != nil { if err != nil {
return 0; return 0
} }
var albums []int64 var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil { if err := redis.ScanSlice(reply, &albums); err != nil {
return 0; return 0
} }
if len(albums) == 0 { if len(albums) == 0 {
return 0; return 0
}else{ } else {
var all int64 = 0 var all int64 = 0
for _,n := range albums { for _, n := range albums {
all = all+n all = all + n
} }
return all return all
} }
...@@ -38,269 +38,133 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{ ...@@ -38,269 +38,133 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
/* /*
获取自营活动价 获取自营活动价
*/ */
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context,SkuInfo string,c *redis.Conn) *orderedmap.OrderedMap { func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap {
goodsId := gjson.Get(SkuInfo,"goods_id").String() data := qs.HDActivityPrice(SkuInfo)
//团购价
//assemble := ctx.Request.FormValue("power[assemble]")
//if php2go.InArray(assemble,[]string{"true","1",""}) {
// teamAc,_ := gredis.String((*c).Do("get","Self_activity_assemble_list"))
// if teamAc != "" && goodsId == gjson.Get(teamAc,"goods_id").String() {
// data := qs.HDActivityPrice(ctx,teamAc,SkuInfo,"7")
// if data != nil {
// return data
// }
// }
//}
//新客价处理
if ctx.Request.FormValue("power[newCustomer]") == "true" || ctx.Request.FormValue("power[newCustomer]") == "1" {
goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer"))
if goodsActivityPrice != "" {
data := qs.HDActivityPrice(ctx,goodsActivityPrice,SkuInfo,"5")
if data != nil {
return data
}
}
}
//团购限制
data := qs.HDGoodsLimit(goodsId,gjson.Get(SkuInfo,"stock").String(),c)
common.PrintDebugHtml(ctx,data)
if data != nil { if data != nil {
return data return data
} }
//活动价
GoodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000"))
if GoodsActivityPrice != "" {
data := qs.HDActivityPrice(ctx,GoodsActivityPrice,SkuInfo,"2")
if data != nil {
return data
}
}
//会员价
GoodsActivityPrice,_ = gredis.String((*c).Do("get","Self_ActivityPrice_10000_Member"))
if GoodsActivityPrice != "" {
data := qs.HDActivityPrice(ctx,GoodsActivityPrice,SkuInfo,"3")
if data != nil {
return data
}
}
return nil return nil
} }
//获取活动相关信息
func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
//去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{
SupplierId: 10000,
BrandId: int(gjson.Get(skuInfo, "brand_id").Int()),
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()),
}
var activityService ActivityService
priceActivity, giftActivity = activityService.GetActivityData(checkData)
return
}
/* /*
计算活动价 计算活动价
ac_type说明: 0 没有活动 ac_type说明: 0 没有活动
活动名称 ac_type 类型 活动名称 ac_type 类型
限时限量活动 1 自营
活动价 2 自营 and 联营
会员价 3 自营 and 联营
折扣价(废除)4 自营 and 联营
新客价 5 自营 and 联营
自营系数 6 自营 自营系数 6 自营
团购价 7 联营 折扣(系数)活动 10 自营/联营
折扣价 8 自营 and 联营
*/ */
func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice string,SkuInfo string,Actype string) *orderedmap.OrderedMap { func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
visible_roster := gjson.Get(GoodsActivityPrice,"visible_roster").String() priceActivity, giftActivity := qs.GetActivity(SkuInfo)
activity_id := gjson.Get(GoodsActivityPrice,"activity_id").String() ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array()
is_part := gjson.Get(GoodsActivityPrice,"is_part").String() A := orderedmap.New()
activity_type := gjson.Get(GoodsActivityPrice,"activity_type").String() //先去判断价格活动
if priceActivity.HasActivity && len(ladderPriceArr) > 0 {
Ratio := true //是否符合活动价 ratio := priceActivity.Ratio
if Actype == "5" { //新客价 ladderType := make([]model.LadderPrice, 0)
ratio_goods_id := gjson.Get(GoodsActivityPrice,"goods_id").String() //活动型号id for _, v := range ladderPriceArr {
ratio_brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String() //活动品牌id priceCn := v.Get("price_cn").Float()
ratio_class_id := gjson.Get(GoodsActivityPrice,"class_id").String() //活动分类id priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000
ladderType = append(ladderType, model.LadderPrice{
//指定参与新客价型号 Purchases: v.Get("purchases").Int(),
if ratio_goods_id != "" { PriceUs: v.Get("price_us").Float(),
if php2go.Stripos(","+ratio_goods_id+",",","+gjson.Get(SkuInfo,"goods_id").String()+",",0) == -1 { PriceCn: priceCn,
Ratio = false; //不符合新客价 PriceAc: priceAc,
goto End })
} }
}
//指定品牌 A.Set("activity_info", priceActivity)
if ratio_brand_id != "" {
if php2go.Stripos(","+ratio_brand_id+",",","+gjson.Get(SkuInfo,"brand_id").String()+",",0) == -1 { A.Set("ladder_price", ladderType)
Ratio = false; //不符合新客价 A.Set("ratio", ratio)
goto End A.Set("ac_type", 10)
}
}
//指定分类
if ratio_class_id != "" {
if php2go.Stripos(","+ratio_class_id+",",","+gjson.Get(SkuInfo,"class_id2").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
}else{
//fmt.Println(GoodsActivityPrice,SkuInfo)
brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String()
class_id := gjson.Get(GoodsActivityPrice,"class_id").String()
if brand_id != "" {
if !common.GInArray(GoodsActivityPrice,"brand_id",gjson.Get(SkuInfo,"brand_id").String()) {
Ratio = false; //不符合活动价
//fmt.Println("不符合活动价1")
goto End
}
}
if class_id != "" {
if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) {
Ratio = false; //不符合活动价
//fmt.Println("不符合活动价2")
goto End
}
}
//会员价处理
if Actype == "3" && is_part == "1" && visible_roster != "" {
Ratio = false; //
visible_roster = ","+visible_roster+","
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[user_id]")+",",0) != -1 {
Ratio = true;
}
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[mobile]")+",",0) != -1 {
Ratio = true;
}
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[email]")+",",0) != -1 {
Ratio = true;
}
//fmt.Println("不符合活动价3")
}
//处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug
if Ratio == true && Actype == "2" && activity_id != "" && activity_type == "2" && ctx.Request.FormValue("power[verify_blacklist]") == "true" {
//redisConn := gredis.Conn("search_r")
//defer redisConn.Close();
//
//blacklist, _ := redis.String(redisConn.Do("hget", "activity_roster",activity_id+"_1"))
//blacklist_type := config.Cfg.Section("blacklist_type").KeysHash()
//
//blacklistArr := php2go.Explode(",",blacklist)
//for p,d := range blacklist_type {
//
// //backval,ok := blacklist_type[d]
//
// if php2go.Stripos(visible_roster,","+middleware.REQUEST["power[user_id]"]+",",0) == -1 {
// Ratio = false; //不符合新客价
// goto End
// }
//}
}
} }
End: //最终执行 //再去判断满赠活动
ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array() if giftActivity.HasActivity {
if Ratio && len(ladder_price_arr) > 0 { A.Set("has_gift_activity", 1)
discount_type := gjson.Get(GoodsActivityPrice,"discount_type").String() A.Set("gift_activity", giftActivity)
ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣 }
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
A := orderedmap.New(); var allowCoupon int
ladderType := make([]model.LadderPrice,0) if priceActivity.HasActivity && priceActivity.AllowCoupon == 0 {
for _,v := range ladder_price_arr{ allowCoupon = 0
if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" { A.Set("allow_coupon", allowCoupon)
price_cn := v.Get("price_cn").Float()
price_ac := php2go.Round(price_cn*ratio/100*10000)/10000
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: price_cn,
PriceAc: price_ac,
})
}
}
allow_not_login := gjson.Get(GoodsActivityPrice,"allow_not_login").Int()
if allow_not_login == 0 {
allow_not_login = 2
}
A.Set("activity_info",map[string]interface{}{
"activity_ad":gjson.Get(GoodsActivityPrice,"activity_ad").String(),
"sign_name":gjson.Get(GoodsActivityPrice,"sign_name").String(),
"allow_not_login":allow_not_login,
})
A.Set("ladder_price",ladderType)
A.Set("ratio",ratio)
A.Set("ac_type",Actype)
if gjson.Get(GoodsActivityPrice,"activity_type").Int() == 2 {
A.Set("ac_type",8)
}
allow_coupon := gjson.Get(GoodsActivityPrice,"allow_coupon").Int()
if gjson.Get(GoodsActivityPrice,"allow_coupon").Int() == 0 {
allow_coupon = 1
}
A.Set("allow_coupon",allow_coupon)
A.Set("activity_end_time",gjson.Get(GoodsActivityPrice,"end_time").Int())
return A
} }
return nil if giftActivity.HasActivity && giftActivity.AllowCoupon == 0 {
allowCoupon = 0
A.Set("allow_coupon", allowCoupon)
}
return A
} }
/* /*
获取当前锁住的库存 获取当前锁住的库存
*/ */
func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn) *orderedmap.OrderedMap { func (qs *ZiyingService) HDGoodsLimit(SkuID string, Stock string, c *redis.Conn) *orderedmap.OrderedMap {
GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID)) GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID))
if GoodsLimit == "" { if GoodsLimit == "" {
return nil return nil
} }
start_time := gjson.Get(GoodsLimit,"start_time").Int() start_time := gjson.Get(GoodsLimit, "start_time").Int()
end_time := gjson.Get(GoodsLimit,"end_time").Int() end_time := gjson.Get(GoodsLimit, "end_time").Int()
buy_stock := gjson.Get(GoodsLimit,"buy_stock").Float() buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float()
ac_stock := gjson.Get(GoodsLimit,"ac_stock").Float() ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float()
schedule := gjson.Get(GoodsLimit,"schedule").Float() schedule := gjson.Get(GoodsLimit, "schedule").Float()
allow_coupon := gjson.Get(GoodsLimit,"allow_coupon").Int() allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int()
if start_time < php2go.Time() && end_time >php2go.Time() { if start_time < php2go.Time() && end_time > php2go.Time() {
buy := buy_stock/ac_stock*100 buy := buy_stock / ac_stock * 100
schedule := common.MyRound(buy+schedule,2) schedule := common.MyRound(buy+schedule, 2)
if schedule < 100 { if schedule < 100 {
A := orderedmap.New(); A := orderedmap.New()
//拼接梯度价格 //拼接梯度价格
ladder_price_arr := gjson.Get(GoodsLimit,"ac_price").Array() ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array()
ladderType := make([]model.LadderPrice,0) ladderType := make([]model.LadderPrice, 0)
for _,v := range ladder_price_arr{ for _, v := range ladder_price_arr {
ladderType = append(ladderType, model.LadderPrice{ ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(), PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(), PriceAc: v.Get("price_ac").Float(),
}) })
} }
now_stock := ac_stock*((100-schedule)/100) now_stock := ac_stock * ((100 - schedule) / 100)
A.Set("ac_type",1) A.Set("ac_type", 1)
A.Set("ac_id",gjson.Get(GoodsLimit,"id").Int()) A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("ladder_price",ladderType) A.Set("ladder_price", ladderType)
A.Set("ac_stock",ac_stock) A.Set("ac_stock", ac_stock)
A.Set("stock",now_stock) A.Set("stock", now_stock)
A.Set("schedule",schedule) A.Set("schedule", schedule)
A.Set("activity_end_time",end_time) A.Set("activity_end_time", end_time)
if allow_coupon >0 { if allow_coupon > 0 {
A.Set("allow_coupon",allow_coupon) A.Set("allow_coupon", allow_coupon)
}else{ } else {
A.Set("allow_coupon",1) A.Set("allow_coupon", 1)
} }
//活动库存大于当前可售库存,强制结束活动 //活动库存大于当前可售库存,强制结束活动
if now_stock > common.MyFloat64(Stock) || now_stock == 0 { if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil return nil
} }
return A return A
} }
} }
return nil return nil
} }
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