Commit 5003b2fe by mushishixian

Merge branch 'ysx-价格体系修改-20210106' into dev

parents 07aab597 76b494a9
......@@ -35,6 +35,7 @@ type Activity struct {
AdminName string `json:"admin_name"`
ActivityId int `json:"activity_id"`
ItemList []ActivityItem `json:"item_list"`
EntireSupplierActivity bool `json:"entire_supplier_activity"`
}
type ActivityItem struct {
......
......@@ -32,7 +32,6 @@ type LySku struct {
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
......@@ -61,23 +60,32 @@ type LySku struct {
Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
AcType int `json:"ac_type"`
//活动信息
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
ActivityInfo PriceActivity `json:"activity_info"`
}
type PriceActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
Ratio float64 `json:"ratio"`
ActivityCommon
Ratio float64 `json:"ratio"`
}
type GiftActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ItemList []ActivityItem `json:"items,omitempty"`
ActivityCommon
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存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
......
......@@ -9,6 +9,7 @@ import (
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
"time"
)
type ActivityService struct {
......@@ -49,72 +50,142 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
//获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
goto INFO
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
goto INFO
}
}
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
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities {
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
return
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
} else {
hasActivity = true
goto INFO
}
}
} else {
} else if checkData.SupplierId == 10000 {
if as.CheckClass(checkData.ClassId, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
} else {
hasActivity = true
goto INFO
}
}
} else {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
goto INFO
}
}
//判断是否是搞活动的品牌
if as.CheckSkuId(checkData.GoodsId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
INFO:
if hasActivity {
priceActivity.ActivityName = activity.ActivityName
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,
},
}
}
}
priceActivity.HasActivity = hasActivity
return
}
......@@ -191,18 +262,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
}
return false
}
//检查是否属于活动sku_id
func (as *ActivityService) CheckSkuId(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.SkuIdList = strings.Split(activity.SkuIds, ",")
skuIdStr := gconv.String(skuId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuIdStr, activity.SkuIdList) {
return true
}
return false
}
......@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1
sku.BrandId = brandId
//去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId,
Canal: sku.Canal,
ClassId: sku.ClassID2,
}
var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData)
if priceActivity.HasActivity {
sku.AcType = 9
}
if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity
}
sku = ls.GetActivity(sku)
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
......@@ -188,3 +172,32 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
ch <- GoodsRes
}
//获取活动
func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
//去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId,
Canal: sku.Canal,
ClassId: sku.ClassID2,
}
var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData)
if priceActivity.HasActivity {
sku.AcType = 10
sku.Ratio = priceActivity.Ratio
sku.ActivityInfo = priceActivity
}
if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity
}
//获取是否能使用优惠券
if giftActivity.AllowCoupon != 1 || priceActivity.AllowCoupon != 1 {
sku.AllowCoupon = 0
}
return sku
}
......@@ -11,6 +11,9 @@ import (
"time"
)
type PriceService struct {
}
//获取联营活动价
func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Power) model.LySku {
//没价格,直接返回
......
......@@ -31,31 +31,30 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@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")
defer func() {
//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]")
GoodsRes := sync.Map{}
for goods_id,info := range skuArr {
for goodsId, info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" {
//fmt.Print("zy goods_name为空-----",goods_id,skuArr)
GoodsRes.Store(goods_id,false)
continue;
GoodsRes.Store(goodsId, false)
continue
}
//拼接属性
attrJsonArr := gjson.Parse(gjson.Get(info,"attrs").String()).Array()
attrs := make([]model.Attrs,0)
for _,d := range attrJsonArr{
attrJsonArr := gjson.Parse(gjson.Get(info, "attrs").String()).Array()
attrs := make([]model.Attrs, 0)
for _, d := range attrJsonArr {
if d.Get("attr_name").String() == "" {
continue;
continue
}
attrs = append(attrs, model.Attrs{
AttrName: d.Get("attr_name").String(),
......@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
}
//数组
A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id",common.MyInt64(goods_id))
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").Int()) //
other_attrs := gjson.Get(info,"other_attrs").String()
if other_attrs == "" {
A.Set("other_attrs","")
}else{
A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id", common.MyInt64(goodsId))
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").Int()) //
otherAttrs := gjson.Get(info, "other_attrs").String()
if otherAttrs == "" {
A.Set("other_attrs", "")
} else {
B := make(map[string]string)
pick_type := gjson.Get(other_attrs,"pick_type").String()
length := gjson.Get(other_attrs,"length").String()
gross_wegiht := gjson.Get(other_attrs,"gross_wegiht").String()
if pick_type != "" {
B["pick_type"] = pick_type
pickType := gjson.Get(otherAttrs, "pick_type").String()
length := gjson.Get(otherAttrs, "length").String()
grossWegiht := gjson.Get(otherAttrs, "gross_wegiht").String()
if pickType != "" {
B["pick_type"] = pickType
}
B["length"] = length
if gross_wegiht != "" {
B["gross_wegiht"] = gross_wegiht
if grossWegiht != "" {
B["gross_wegiht"] = grossWegiht
}
A.Set("other_attrs",B)
A.Set("other_attrs", B)
}
class_id1 := gjson.Get(info, "class_id1").Int()
class_id2 := gjson.Get(info, "class_id2").Int()
class_id1_name := "";
if class_id1 >0 {
class_id1_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id1))
class_id1_name = gjson.Get(class_id1_info,"class_name").String()
classId1 := gjson.Get(info, "class_id1").Int()
classId2 := gjson.Get(info, "class_id2").Int()
classId1Name := ""
if classId1 > 0 {
classId1Info, _ := gredis.String(redisConn.Do("HGET", "Self_SelfClassInfo", classId1))
classId1Name = gjson.Get(classId1Info, "class_name").String()
}
class_id2_name := "";
if class_id2 >0 {
class_id2_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id2))
class_id2_name = gjson.Get(class_id2_info,"class_name").String()
classId2Name := ""
if classId2 > 0 {
classId2Info, _ := gredis.String(redisConn.Do("HGET", "Self_SelfClassInfo", classId2))
classId2Name = gjson.Get(classId2Info, "class_name").String()
}
A.Set("class_id1", class_id1) //
A.Set("class_id2", class_id2) //
A.Set("class_id1_name", class_id1_name) //
A.Set("class_id2_name", class_id2_name) //
A.Set("goods_name", gjson.Get(info, "goods_name").String()) //
A.Set("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) //
A.Set("encap", gjson.Get(info, "encap").String()) //
A.Set("packing", gjson.Get(info, "packing").Int()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) //
A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) //
A.Set("moq", gjson.Get(info, "moq").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("mpl", gjson.Get(info, "mpl").Int()) //
A.Set("class_id1", classId1) //
A.Set("class_id2", classId2) //
A.Set("class_id1_name", classId1Name) //
A.Set("class_id2_name", classId2Name) //
A.Set("goods_name", gjson.Get(info, "goods_name").String()) //
A.Set("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) //
A.Set("encap", gjson.Get(info, "encap").String()) //
A.Set("packing", gjson.Get(info, "packing").Int()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) //
A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) //
A.Set("moq", gjson.Get(info, "moq").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("mpl", gjson.Get(info, "mpl").Int()) //
//处理库存
A.Set("stock",0) //默认库存为0
dbStock := gjson.Get(info, "stock").Int() //当前db库存
A.Set("stock", 0) //默认库存为0
dbStock := gjson.Get(info, "stock").Int() //当前db库存
if dbStock > 0 {
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存
stockG := dbStock-lockStock //当前可购买库存
if stockG >0 {
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //锁定库存
A.Set("stock",dbStock)
lockStock := qs.skuLockNum(&redisConn, goodsId) //当前锁库库存
stockG := dbStock - lockStock //当前可购买库存
if stockG > 0 {
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //锁定库存
A.Set("stock", dbStock)
}
A.Set("saler_atio", "") //
A.Set("saler_atio", "") //
}
if len(attrs) == 0 {
A.Set("attrs", "") //属性值
}else{
A.Set("attrs", attrs) //
A.Set("attrs", "") //属性值
} else {
A.Set("attrs", attrs) //
}
A.Set("cost", gjson.Get(info, "cost").String()) //
A.Set("new_cost", gjson.Get(info, "new_cost").String()) //
A.Set("supplier_stock", gjson.Get(info, "supplier_stock").Int()) //
A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").Int()) //
A.Set("cost", gjson.Get(info, "cost").String()) //
A.Set("new_cost", gjson.Get(info, "new_cost").String()) //
A.Set("supplier_stock", gjson.Get(info, "supplier_stock").Int()) //
A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").Int()) //
//处理货期
cn_delivery_time := gjson.Get(info, "cn_delivery_time").String()
if cn_delivery_time == "" {
cn_delivery_time = "3-7工作日";
cnDeliveryTime := gjson.Get(info, "cn_delivery_time").String()
if cnDeliveryTime == "" {
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_info,_ := gredis.String(redisConn.Do("HGET","Self_Brand",brand_id))
A.Set("brand_name", gjson.Get(brand_info, "brand_name").String()) //
brand_info, _ := gredis.String(redisConn.Do("HGET", "Self_Brand", brand_id))
A.Set("brand_name", gjson.Get(brand_info, "brand_name").String()) //
if fast != "1" { //不是快速查询
// 供应商名称
supplier_id := gjson.Get(info, "supplier_id").String()
supplier_name := ""
if supplier_id != "" {
supplierInfo,_ := gredis.String(redisConn.Do("HGET","Self_SelfSupplierInfo",supplier_id))
supplier_name = gjson.Get(supplierInfo,"supplier_name").String()
supplierInfo, _ := gredis.String(redisConn.Do("HGET", "Self_SelfSupplierInfo", supplier_id))
supplier_name = gjson.Get(supplierInfo, "supplier_name").String()
}
A.Set("supplier_name", supplier_name)
//商品单位
goods_unit := gjson.Get(info, "goods_unit").String()
goods_unit_name := ""
if goods_unit != "" {
goods_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",goods_unit))
goodsUnit := gjson.Get(info, "goods_unit").String()
goodsUnitName := ""
if goodsUnit != "" {
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_name := ""
packingName := ""
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_unit_name := ""
mpqUnitName := ""
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()
goods_images := ""
goodsImages := ""
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()
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("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))
var PriceAcXi float64 = 0 //系数
ratio, _ := gredis.String(redisConn.Do("HGET", "zy_ratio_sku", goodsId))
var PriceAcXi float64 = 0 //系数
if ratio != "" {
PriceAcXi = gjson.Get(ratio,"price_ac").Float()
PriceAcXi = gjson.Get(ratio, "price_ac").Float()
//获取立创价格
if gjson.Parse("szlc_price").String() == "" {
A.Set("szlc_price",nil)
}else{
ladderPriceLc := make([]model.LadderPriceLc,0)
for _,v := range gjson.Parse("szlc_price").Array(){
if gjson.Parse("szlc_price").String() == "" {
A.Set("szlc_price", nil)
} else {
ladderPriceLc := make([]model.LadderPriceLc, 0)
for _, v := range gjson.Parse("szlc_price").Array() {
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
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_presale",gjson.Get(ratio,"allow_presale").String())
A.Set("ac_type", 6) //系数
A.Set("allow_coupon", gjson.Get(ratio, "allow_coupon").String())
A.Set("allow_presale", gjson.Get(ratio, "allow_presale").String())
A.Set("ac_type", 6) //系数
}
//拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladderPriceArr{
ladderPriceArr := gjson.Get(info, "ladder_price").Array()
ladderPrice := make([]model.LadderPrice, 0)
for _, v := range ladderPriceArr {
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 {
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceCn: price_cn,
PriceCn: priceCn,
})
}else{
} else {
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceCn: price_cn,
PriceAc: PriceAcXi,
PriceCn: priceCn,
PriceAc: PriceAcXi,
})
}
}
if len(ladderPrice) == 0 {
A.Set("ladder_price", "") //
}else{
A.Set("ladder_price", ladderPrice) //
A.Set("ladder_price", "") //
} else {
A.Set("ladder_price", ladderPrice) //
}
//处理限额
goods_quota,_ := gredis.String(redisConn.Do("HGET","Self_goods_quota",goods_id))
if goods_quota != "" {
A.Set("is_quota",1)
A.Set("quota_num",gjson.Get(goods_quota,"num").Int())
goodsQuota, _ := gredis.String(redisConn.Do("HGET", "Self_goods_quota", goodsId))
if goodsQuota != "" {
A.Set("is_quota", 1)
A.Set("quota_num", gjson.Get(goodsQuota, "num").Int())
}
//处理是否能购买
if gjson.Get(info, "status").String() != "1" || len(ladderPriceArr) == 0 {
A.Set("is_buy",0)
}else{
A.Set("is_buy",1)
if gjson.Get(info, "status").String() != "1" || len(ladderPriceArr) == 0 {
A.Set("is_buy", 0)
} else {
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 { //没有系数价格才处理活动价
//处理活动价
A.Set("ac_type",0)
A.Set("allow_coupon",1)
Ac_price := qs.ActivityPrice(ctx,info,&redisConn)
if Ac_price != nil {
keys := Ac_price.Keys()
A.Set("ac_type", 0)
A.Set("allow_coupon", 1)
AcPrice := qs.ActivityPrice(ctx, info)
if AcPrice != nil {
keys := AcPrice.Keys()
for _, k := range keys {
v, _ := Ac_price.Get(k)
A.Set(k,v) //活动价格覆盖
v, _ := AcPrice.Get(k)
A.Set(k, v) //活动价格覆盖
}
}
}
//最后写入sync map
(GoodsRes).Store(goods_id,A)
(GoodsRes).Store(goodsId, A)
}
ch <- GoodsRes
}
......@@ -8,28 +8,28 @@ import (
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
)
//自营公共函数类
/*
计算单个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))
if err != nil {
return 0;
return 0
}
var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil {
return 0;
return 0
}
if len(albums) == 0 {
return 0;
}else{
return 0
} else {
var all int64 = 0
for _,n := range albums {
all = all+n
for _, n := range albums {
all = all + n
}
return all
}
......@@ -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 {
goodsId := gjson.Get(SkuInfo,"goods_id").String()
//团购价
//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)
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap {
data := qs.HDActivityPrice(SkuInfo)
if data != nil {
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
}
//获取活动相关信息
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 类型
限时限量活动 1 自营
活动价 2 自营 and 联营
会员价 3 自营 and 联营
折扣价(废除)4 自营 and 联营
新客价 5 自营 and 联营
自营系数 6 自营
团购价 7 联营
折扣价 8 自营 and 联营
折扣(系数)活动 10 自营/联营
*/
func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice string,SkuInfo string,Actype string) *orderedmap.OrderedMap {
visible_roster := gjson.Get(GoodsActivityPrice,"visible_roster").String()
activity_id := gjson.Get(GoodsActivityPrice,"activity_id").String()
is_part := gjson.Get(GoodsActivityPrice,"is_part").String()
activity_type := gjson.Get(GoodsActivityPrice,"activity_type").String()
Ratio := true //是否符合活动价
if Actype == "5" { //新客价
ratio_goods_id := gjson.Get(GoodsActivityPrice,"goods_id").String() //活动型号id
ratio_brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String() //活动品牌id
ratio_class_id := gjson.Get(GoodsActivityPrice,"class_id").String() //活动分类id
//指定参与新客价型号
if ratio_goods_id != "" {
if php2go.Stripos(","+ratio_goods_id+",",","+gjson.Get(SkuInfo,"goods_id").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
//指定品牌
if ratio_brand_id != "" {
if php2go.Stripos(","+ratio_brand_id+",",","+gjson.Get(SkuInfo,"brand_id").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
//指定分类
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
// }
//}
}
func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
priceActivity, giftActivity := qs.GetActivity(SkuInfo)
ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array()
A := orderedmap.New()
//先去判断价格活动
if priceActivity.HasActivity && len(ladderPriceArr) > 0 {
ratio := priceActivity.Ratio
ladderType := make([]model.LadderPrice, 0)
for _, v := range ladderPriceArr {
priceCn := v.Get("price_cn").Float()
priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: priceCn,
PriceAc: priceAc,
})
}
A.Set("activity_info", priceActivity)
A.Set("ladder_price", ladderType)
A.Set("ratio", ratio)
A.Set("ac_type", 10)
}
End: //最终执行
ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array()
if Ratio && len(ladder_price_arr) > 0 {
discount_type := gjson.Get(GoodsActivityPrice,"discount_type").String()
ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣
A := orderedmap.New();
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" {
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
//再去判断满赠活动
if giftActivity.HasActivity {
A.Set("has_gift_activity", 1)
A.Set("gift_activity", giftActivity)
}
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
var allowCoupon int
if priceActivity.HasActivity && priceActivity.AllowCoupon == 0 {
allowCoupon = 0
A.Set("allow_coupon", allowCoupon)
}
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))
if GoodsLimit == "" {
return nil
}
start_time := gjson.Get(GoodsLimit,"start_time").Int()
end_time := gjson.Get(GoodsLimit,"end_time").Int()
buy_stock := gjson.Get(GoodsLimit,"buy_stock").Float()
ac_stock := gjson.Get(GoodsLimit,"ac_stock").Float()
schedule := gjson.Get(GoodsLimit,"schedule").Float()
allow_coupon := gjson.Get(GoodsLimit,"allow_coupon").Int()
if start_time < php2go.Time() && end_time >php2go.Time() {
buy := buy_stock/ac_stock*100
schedule := common.MyRound(buy+schedule,2)
start_time := gjson.Get(GoodsLimit, "start_time").Int()
end_time := gjson.Get(GoodsLimit, "end_time").Int()
buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float()
ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float()
schedule := gjson.Get(GoodsLimit, "schedule").Float()
allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int()
if start_time < php2go.Time() && end_time > php2go.Time() {
buy := buy_stock / ac_stock * 100
schedule := common.MyRound(buy+schedule, 2)
if schedule < 100 {
A := orderedmap.New();
//拼接梯度价格
ladder_price_arr := gjson.Get(GoodsLimit,"ac_price").Array()
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
A := orderedmap.New()
//拼接梯度价格
ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array()
ladderType := make([]model.LadderPrice, 0)
for _, v := range ladder_price_arr {
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(),
PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(),
})
}
now_stock := ac_stock*((100-schedule)/100)
A.Set("ac_type",1)
A.Set("ac_id",gjson.Get(GoodsLimit,"id").Int())
A.Set("ladder_price",ladderType)
A.Set("ac_stock",ac_stock)
A.Set("stock",now_stock)
A.Set("schedule",schedule)
A.Set("activity_end_time",end_time)
if allow_coupon >0 {
A.Set("allow_coupon",allow_coupon)
}else{
A.Set("allow_coupon",1)
now_stock := ac_stock * ((100 - schedule) / 100)
A.Set("ac_type", 1)
A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("ladder_price", ladderType)
A.Set("ac_stock", ac_stock)
A.Set("stock", now_stock)
A.Set("schedule", schedule)
A.Set("activity_end_time", end_time)
if allow_coupon > 0 {
A.Set("allow_coupon", allow_coupon)
} else {
A.Set("allow_coupon", 1)
}
//活动库存大于当前可售库存,强制结束活动
if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil
return nil
}
return A
return A
}
}
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