Commit 8e8a68f6 by 杨树贤

Merge branch 'ysx-商品活动价逻辑修改-20230823' into dev

parents 91d78a1e 77976452
...@@ -44,6 +44,7 @@ type Activity struct { ...@@ -44,6 +44,7 @@ type Activity struct {
ExcludeStandardBrandIdList []string ExcludeStandardBrandIdList []string
CurrencyRmb int `json:"currency_rmb"` CurrencyRmb int `json:"currency_rmb"`
CurrencyUs int `json:"currency_us"` CurrencyUs int `json:"currency_us"`
UseType int `json:"use_type"`
} }
type ActivityItem struct { type ActivityItem struct {
...@@ -58,9 +59,10 @@ type ActivityItem struct { ...@@ -58,9 +59,10 @@ type ActivityItem struct {
AddTime int `json:"add_time"` AddTime int `json:"add_time"`
} }
//用于检查是否有活动情况的结构体 // 用于检查是否有活动情况的结构体
type ActivityCheckData struct { type ActivityCheckData struct {
SupplierId int SupplierId int
GoodsName string
BrandId int BrandId int
StandardBrandId int StandardBrandId int
GoodsId string GoodsId string
......
package service package service
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"strings" "strconv"
"time" "strings"
"time"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis" "github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go" "github.com/gomodule/redigo/redis"
) "github.com/syyongx/php2go"
)
type ActivityService struct {
} type ActivityService struct {
}
//获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) { // 获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
supplierId := checkData.SupplierId func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
redisCon := gredis.Conn("default_r") supplierId := checkData.SupplierId
defer redisCon.Close() redisCon := gredis.Conn("default_r")
//处理单品促销活动(打折活动) defer redisCon.Close()
activityStr, _ := redis.String(redisCon.Do("hget", "lie_price_activity", supplierId)) //处理单品促销活动(打折活动)
if activityStr != "" { activityStr, _ := redis.String(redisCon.Do("hget", "lie_price_activity", supplierId))
var activities []model.Activity if activityStr != "" {
err := json.Unmarshal([]byte(activityStr), &activities) var activities []model.Activity
if err != nil { err := json.Unmarshal([]byte(activityStr), &activities)
fmt.Println(err) if err != nil {
} fmt.Println(err)
if len(activities) != 0 { }
priceActivity = as.GetPriceActivity(checkData, activities) if len(activities) != 0 {
} priceActivity = as.GetPriceActivity(checkData, activities)
} }
return }
} return
}
//获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) { // 获取满赠活动信息
var hasActivity bool func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
nowTimestamp := int(time.Now().Unix()) var hasActivity bool
for _, activity := range activities { nowTimestamp := int(time.Now().Unix())
if activity.Status != 1 { for _, activity := range activities {
continue if activity.Status != 1 {
} continue
//判断时间是否过期 }
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp { //判断时间是否过期
continue if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
} continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity { //如果是整个供应商搞活动,则直接返回系数
hasActivity = true if activity.EntireSupplierActivity {
goto INFO hasActivity = true
} goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) { //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
continue if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
} continue
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) { //判断是否是搞活动的品牌
hasActivity = true if as.CheckBrand(checkData.BrandId, activity) {
goto INFO hasActivity = true
} goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 { //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if as.CheckCanal(checkData.Canal, activity) { if checkData.SupplierId == 17 {
hasActivity = true if as.CheckCanal(checkData.Canal, activity) {
goto INFO hasActivity = true
} goto INFO
} else { }
if as.CheckClass(checkData.ClassId, activity) { } else {
hasActivity = true if as.CheckClass(checkData.ClassId, activity) {
goto INFO hasActivity = true
} goto INFO
} }
INFO: }
if hasActivity { INFO:
for key, item := range activity.ItemList { if hasActivity {
activity.ItemList[key].Content = "订单满" + gconv.String(item.Amount) + "元赠" + for key, item := range activity.ItemList {
gconv.String(item.ItemName) + "X" + gconv.String(item.Num) + "" + item.Remark activity.ItemList[key].Content = "订单满" + gconv.String(item.Amount) + "元赠" +
} gconv.String(item.ItemName) + "X" + gconv.String(item.Num) + "" + item.Remark
giftActivity.ActivityName = activity.ActivityName }
giftActivity.ActivityId = activity.ActivityId giftActivity.ActivityName = activity.ActivityName
giftActivity = model.GiftActivity{ giftActivity.ActivityId = activity.ActivityId
CanAdminOrder: activity.CanAdminOrder, giftActivity = model.GiftActivity{
ItemList: activity.ItemList, CanAdminOrder: activity.CanAdminOrder,
ActivityCommon: model.ActivityCommon{ ItemList: activity.ItemList,
HasActivity: hasActivity, ActivityCommon: model.ActivityCommon{
ActivityId: activity.ActivityId, HasActivity: hasActivity,
ActivityName: activity.ActivityName, ActivityId: activity.ActivityId,
AllowCoupon: activity.AllowCoupon, ActivityName: activity.ActivityName,
UserScope: activity.UserScope, AllowCoupon: activity.AllowCoupon,
}, UserScope: activity.UserScope,
} },
break }
} break
} }
}
return
} return
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
nowTimestamp := int(time.Now().Unix()) redisConn := gredis.Conn("default_r")
for _, activity := range activities { defer redisConn.Close()
if activity.Status != 1 { var hasActivity bool
continue nowTimestamp := int(time.Now().Unix())
} for _, activity := range activities {
//判断时间是否过期 if activity.Status != 1 {
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp { continue
continue }
} //判断时间是否过期
//如果是整个供应商搞活动,则直接返回系数 if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
if activity.EntireSupplierActivity { continue
hasActivity = true }
goto INFO //如果是整个供应商搞活动,则直接返回系数
} if activity.EntireSupplierActivity {
hasActivity = true
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动 goto INFO
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) { }
continue
} //判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) {
//如果是专卖,则要去判断canal,如果是自营,则去判断分类 continue
if checkData.SupplierId == 17 { }
if as.CheckCanal(checkData.Canal, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系 //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if activity.StandardBrandIds != "" { if checkData.SupplierId == 17 {
//判断是否是搞活动的品牌 if checkData.Canal != "" {
if as.CheckStandardBrand(checkData.StandardBrandId, activity) { if !as.CheckCanal(checkData.Canal, activity) {
hasActivity = true continue
goto INFO }
} }
} else { if activity.UseType == 2 {
hasActivity = true //判断商品名称是否在redis
goto INFO redisKey := "lie_activity_and_coupon_sku_" + strconv.Itoa(activity.ActivityId)
} exists, _ := redis.Bool(redisConn.Do("hexists", redisKey, checkData.GoodsName))
} if exists {
} else if checkData.SupplierId == 10000 { hasActivity = true
//自营活动特殊判断 goto INFO
//判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了 }
if activity.StandardBrandIds == "" && activity.ClassIds == "" { } else {
hasActivity = true //不等于2都是根据品牌来,因为老数据以前也只有品牌,0和1都是品牌
goto INFO //品牌不为空,还要去判断品牌,是同时满足的关系
} if activity.StandardBrandIds != "" {
if as.CheckClass(checkData.ClassId, activity) { //判断是否是搞活动的品牌
//品牌不为空,还要去判断品牌,是同时满足的关系 if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
if activity.StandardBrandIds != "" { hasActivity = true
//判断是否是搞活动的品牌 goto INFO
if as.CheckStandardBrand(checkData.StandardBrandId, activity) { }
hasActivity = true } else {
goto INFO hasActivity = true
} goto INFO
} else { }
hasActivity = true }
goto INFO
} } else if checkData.SupplierId == 10000 {
} //自营活动特殊判断
} else { //判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
//判断是否是搞活动的品牌 if activity.StandardBrandIds == "" && activity.ClassIds == "" {
if as.CheckStandardBrand(checkData.StandardBrandId, activity) { hasActivity = true
hasActivity = true goto INFO
goto INFO }
} if as.CheckClass(checkData.ClassId, activity) {
} //品牌不为空,还要去判断品牌,是同时满足的关系
INFO: if activity.StandardBrandIds != "" {
if hasActivity { //判断是否是搞活动的品牌
priceActivity.ActivityName = activity.ActivityName if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
priceActivity.ActivityId = activity.ActivityId hasActivity = true
priceActivity = model.PriceActivity{ goto INFO
Ratio: activity.Ratio, }
SignText: activity.SignText, } else {
Sign: activity.Sign, hasActivity = true
ShowName: activity.ShowName, goto INFO
ActivityCommon: model.ActivityCommon{ }
HasActivity: hasActivity, }
ActivityId: activity.ActivityId, } else {
ActivityName: activity.ActivityName, //这是针对代购的
AllowCoupon: activity.AllowCoupon, //判断是否是搞活动的品牌
UserScope: activity.UserScope, if activity.UseType == 2 {
}, //判断商品名称是否在redis
} redisKey := "lie_activity_and_coupon_sku_" + strconv.Itoa(activity.ActivityId)
if activity.CurrencyRmb == 1 { exists, _ := redis.Bool(redisConn.Do("hexists", redisKey, checkData.GoodsName))
priceActivity.Ratio = activity.Ratio if exists {
} else { hasActivity = true
priceActivity.Ratio = 0 goto INFO
} }
if activity.CurrencyUs == 1 { } else {
priceActivity.RatioUs = activity.RatioUs //不等于2都是根据品牌来,因为老数据以前也只有品牌,0和1都是品牌
} else { //品牌不为空,还要去判断品牌,是同时满足的关系
priceActivity.RatioUs = 0 if activity.StandardBrandIds != "" {
} //判断是否是搞活动的品牌
break if as.CheckStandardBrand(checkData.StandardBrandId, activity) {
} hasActivity = true
} goto INFO
}
priceActivity.HasActivity = hasActivity } else {
return hasActivity = true
} goto INFO
}
//检查是否属于被排除的品牌 }
func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool { }
if brandId == 0 { INFO:
return false if hasActivity {
} priceActivity.ActivityName = activity.ActivityName
//先去判断品牌 priceActivity.ActivityId = activity.ActivityId
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",") priceActivity = model.PriceActivity{
brandIdStr := gconv.String(brandId) Ratio: activity.Ratio,
//如果存在于有活动价的品牌,就是有折扣活动了 SignText: activity.SignText,
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) { Sign: activity.Sign,
return true ShowName: activity.ShowName,
} ActivityCommon: model.ActivityCommon{
return false HasActivity: hasActivity,
} ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
//检查是否属于被排除的标准品牌 AllowCoupon: activity.AllowCoupon,
func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activity model.Activity) bool { UserScope: activity.UserScope,
if standardBrandId == 0 { },
return false }
} if activity.CurrencyRmb == 1 {
//先去判断品牌 priceActivity.Ratio = activity.Ratio
activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",") } else {
standardBrandIdStr := gconv.String(standardBrandId) priceActivity.Ratio = 0
//如果存在于有活动价的品牌,就是有折扣活动了 }
if php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList) { if activity.CurrencyUs == 1 {
return true priceActivity.RatioUs = activity.RatioUs
} } else {
return false priceActivity.RatioUs = 0
} }
break
//检查是否属于被排除的sku }
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool { }
if skuId == "" {
return false priceActivity.HasActivity = hasActivity
} return
//先去判断品牌 }
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了 // 检查是否属于被排除的品牌
if php2go.InArray(skuId, activity.ExcludeSkuIdList) { func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool {
return true if brandId == 0 {
} return false
return false }
} //先去判断品牌
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
//检查是否属于活动分类(只有自营需要判断) brandIdStr := gconv.String(brandId)
func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool { //如果存在于有活动价的品牌,就是有折扣活动了
if classId == 0 { if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
return false return true
} }
//先去判断品牌 return false
activity.ClassIdList = strings.Split(activity.ClassIds, ",") }
classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了 // 检查是否属于被排除的标准品牌
if php2go.InArray(classIdStr, activity.ClassIdList) { func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activity model.Activity) bool {
return true if standardBrandId == 0 {
} return false
return false }
} //先去判断品牌
activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",")
//检查是否属于活动品牌 standardBrandIdStr := gconv.String(standardBrandId)
func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool { //如果存在于有活动价的品牌,就是有折扣活动了
if brandId == 0 { if php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList) {
return false return true
} }
//先去判断品牌 return false
activity.BrandIdList = strings.Split(activity.BrandIds, ",") }
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了 // 检查是否属于被排除的sku
if php2go.InArray(brandIdStr, activity.BrandIdList) { func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
return true if skuId == "" {
} return false
return false }
} //先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//检测是否属于活动标准品牌 //如果存在于有活动价的品牌,就是有折扣活动了
func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity model.Activity) bool { if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
if standardBrandId == 0 { return true
return false }
} return false
//先去判断品牌 }
activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId) // 检查是否属于活动分类(只有自营需要判断)
//如果存在于有活动价的品牌,就是有折扣活动了 func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool {
if php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList) { if classId == 0 {
return true return false
} }
return false //先去判断品牌
} activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId)
//检查是否属于供应商渠道 //如果存在于有活动价的品牌,就是有折扣活动了
func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool { if php2go.InArray(classIdStr, activity.ClassIdList) {
if canal == "" { return true
return false }
} return false
//先去判断品牌 }
activity.CanalList = strings.Split(activity.Canals, ",")
//如果存在于有活动价的品牌,就是有折扣活动了 // 检查是否属于活动品牌
if php2go.InArray(canal, activity.CanalList) { func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool {
return true if brandId == 0 {
} return false
return false }
} //先去判断品牌
activity.BrandIdList = strings.Split(activity.BrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.BrandIdList) {
return true
}
return false
}
// 检测是否属于活动标准品牌
func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity model.Activity) bool {
if standardBrandId == 0 {
return false
}
//先去判断品牌
activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList) {
return true
}
return false
}
// 检查是否属于供应商渠道
func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool {
if canal == "" {
return false
}
//先去判断品牌
activity.CanalList = strings.Split(activity.Canals, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(canal, activity.CanalList) {
return true
}
return false
}
...@@ -58,7 +58,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -58,7 +58,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.GoodsId = goodsId sku.GoodsId = goodsId
spu := spuList[sku.SpuId] spu := spuList[sku.SpuId]
//读取包装字段的缓存 //读取包装字段的缓存
if sku.SupplierId == 7 || sku.SupplierId == 13 { if sku.SupplierId == 7 || sku.SupplierId == 13 || sku.SupplierId == 1688 {
//sku_raw_map哪里写入(成意写的) //sku_raw_map哪里写入(成意写的)
packing, _ := redis.String(redisConnSpu.Do("HGET", "sku_raw_map", goodsId)) packing, _ := redis.String(redisConnSpu.Do("HGET", "sku_raw_map", goodsId))
sku.Packing = gjson.Get(packing, "pack").String() sku.Packing = gjson.Get(packing, "pack").String()
...@@ -211,6 +211,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku { ...@@ -211,6 +211,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
GoodsId: sku.GoodsId, GoodsId: sku.GoodsId,
Canal: sku.Canal, Canal: sku.Canal,
ClassId: sku.ClassID2, ClassId: sku.ClassID2,
GoodsName: sku.GoodsName,
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData) priceActivity, giftActivity := activityService.GetActivityData(checkData)
......
...@@ -2,7 +2,6 @@ package service ...@@ -2,7 +2,6 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "github.com/iancoleman/orderedmap" _ "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
...@@ -277,7 +276,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -277,7 +276,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 { if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 {
sku = priceService.GenerateLadderPrice(sku) sku = priceService.GenerateLadderPrice(sku)
ladderPrice = sku.LadderPrice ladderPrice = sku.LadderPrice
fmt.Println(ladderPrice) //fmt.Println(ladderPrice)
} }
} }
//获取折扣系数 //获取折扣系数
...@@ -433,7 +432,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -433,7 +432,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
priceCostUs := c.MulFloat(price.PriceUs, sku.DiscountRatio.RatioUsd) priceCostUs := c.MulFloat(price.PriceUs, sku.DiscountRatio.RatioUsd)
priceCostUs = c.MyRound(priceCostUs, 4) priceCostUs = c.MyRound(priceCostUs, 4)
//美金售价 //美金售价
fmt.Println("计算美金价的系数", priceRatio.RatioUsd) //fmt.Println("计算美金价的系数", priceRatio.RatioUsd)
priceUs := c.MulFloat(priceCostUs, priceRatio.RatioUsd) priceUs := c.MulFloat(priceCostUs, priceRatio.RatioUsd)
//人民币成本价,mro只有人民币,所以人民币价格不是从美金来的,而且人民币是含税的.就它要特殊处理 //人民币成本价,mro只有人民币,所以人民币价格不是从美金来的,而且人民币是含税的.就它要特殊处理
var priceCostCn float64 var priceCostCn float64
...@@ -503,7 +502,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku { ...@@ -503,7 +502,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
sku.LadderPrice = data sku.LadderPrice = data
} }
fmt.Println(sku.PriceRatio, sku.PriceRatioSort) //fmt.Println(sku.PriceRatio, sku.PriceRatioSort)
return sku return sku
} }
...@@ -94,6 +94,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -94,6 +94,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if brandIds != "" { if brandIds != "" {
hasSpecialCheck = true hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",") standardBrandIdList := strings.Split(brandIds, ",")
fmt.Println(standardBrandIdList)
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId) standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了 //找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) { if php2go.InArray(standardBrandId, standardBrandIdList) {
...@@ -156,7 +157,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -156,7 +157,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} }
//找不到特定的系数,那就去找全局的 //找不到特定的系数,那就去找全局的
if !foundRatio { if !foundRatio {
fmt.Println("去找默认系数") //fmt.Println("去找默认系数")
priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_v2_default")) priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_v2_default"))
priceRatioArr := gjson.Get(priceRatioCache, ratioDataKey).Array() priceRatioArr := gjson.Get(priceRatioCache, ratioDataKey).Array()
priceRatioList = nil priceRatioList = nil
...@@ -174,16 +175,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -174,16 +175,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式 //这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯 //是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
var ladderPriceMiniProfitLevel int var ladderPriceMiniProfitLevel int
fmt.Println("是否找到系数", foundRatio) //fmt.Println("是否找到系数", foundRatio)
//fmt.Println("系数redis数据为 : ", priceRatioCache) //fmt.Println("系数redis数据为 : ", priceRatioCache)
fmt.Println("具体系数为 : ", priceRatioList) //fmt.Println("具体系数为 : ", priceRatioList)
if foundRatio { if foundRatio {
priceRatioSortStr := strconv.Itoa(priceRatioSort) priceRatioSortStr := strconv.Itoa(priceRatioSort)
ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level."+priceRatioSortStr).Int()) ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level."+priceRatioSortStr).Int())
} else { } else {
ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level").Int()) ladderPriceMiniProfitLevel = int(gjson.Get(priceRatioCache, "ladder_price_mini_profit_level").Int())
} }
fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel) //fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel)
var generatedLadderPrice []model.LadderPrice var generatedLadderPrice []model.LadderPrice
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成 //先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases := sku.LadderPrice[0].Purchases firstLadderPurchases := sku.LadderPrice[0].Purchases
...@@ -191,7 +192,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -191,7 +192,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价 //判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
//如果有阶梯价,就要跳过设置的成本价(假设有设置的话) //如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
if isCostPrice { if isCostPrice {
fmt.Println("成本价") //fmt.Println("成本价")
costPriceCn := sku.LadderPrice[0].PriceCn costPriceCn := sku.LadderPrice[0].PriceCn
costPriceUs := sku.LadderPrice[0].PriceUs costPriceUs := sku.LadderPrice[0].PriceUs
//fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs) //fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
...@@ -279,8 +280,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -279,8 +280,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
} }
costLadderCount++ costLadderCount++
} }
fmt.Println("阶梯数量为 : ", costLadderCount) //fmt.Println("阶梯数量为 : ", costLadderCount)
fmt.Println("设置的利润阶梯为 : ", ladderPriceMiniProfitLevel) //fmt.Println("设置的利润阶梯为 : ", ladderPriceMiniProfitLevel)
if costLadderCount <= ladderPriceMiniProfitLevel { if costLadderCount <= ladderPriceMiniProfitLevel {
for i := 0; i < costLadderCount; i++ { for i := 0; i < costLadderCount; i++ {
priceRatioAndPurchases := priceRatioList[i] priceRatioAndPurchases := priceRatioList[i]
...@@ -296,7 +297,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -296,7 +297,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的 //如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i //最小利润点层级 - 库存满足多少个阶梯 + i
costMapIndex := ladderPriceMiniProfitLevel - costLadderCount + i costMapIndex := ladderPriceMiniProfitLevel - costLadderCount + i
fmt.Println(costMapIndex) //fmt.Println(costMapIndex)
if costMapIndex <= 0 { if costMapIndex <= 0 {
costMapIndex = 0 costMapIndex = 0
} }
...@@ -363,7 +364,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku { ...@@ -363,7 +364,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
priceCnRatio := priceRatio.Ratio priceCnRatio := priceRatio.Ratio
priceUsRatio := priceRatio.RatioUsd priceUsRatio := priceRatio.RatioUsd
// 阶梯价格系数正序取 // 阶梯价格系数正序取
fmt.Println("价格:",c.MulFloat(ladder.PriceCn, priceCnRatio)) //fmt.Println("价格:",c.MulFloat(ladder.PriceCn, priceCnRatio))
generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{ generatedLadderPrice = append(generatedLadderPrice, model.LadderPrice{
Purchases: ladder.Purchases, Purchases: ladder.Purchases,
PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 5), PriceCn: c.MyRound(c.MulFloat(ladder.PriceCn, priceCnRatio), 5),
...@@ -653,13 +654,13 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f ...@@ -653,13 +654,13 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f
} else { } else {
currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.Canal)) currency, _ = redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", sku.Canal))
} }
fmt.Println("进来的美金价格:", priceUs) //fmt.Println("进来的美金价格:", priceUs)
if currency > 0 { if currency > 0 {
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要 //这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率 //先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency)) rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency))
fmt.Println("特殊转换", rmbRatio) //fmt.Println("特殊转换", rmbRatio)
fmt.Println(rmbRatio, usRatio) //fmt.Println(rmbRatio, usRatio)
//人民币汇率转美金汇率 //人民币汇率转美金汇率
usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 6) usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 6)
......
...@@ -38,7 +38,7 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 { ...@@ -38,7 +38,7 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 {
} }
/* /*
获取自营活动价 获取自营活动价
*/ */
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap { func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap {
data := qs.HDActivityPrice(SkuInfo) data := qs.HDActivityPrice(SkuInfo)
...@@ -48,7 +48,7 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *ordere ...@@ -48,7 +48,7 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *ordere
return nil return nil
} }
//获取活动相关信息 // 获取活动相关信息
func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) { func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
//去判断是否有活动(促销打折活动和满赠活动) //去判断是否有活动(促销打折活动和满赠活动)
var standardBrandId int var standardBrandId int
...@@ -72,6 +72,7 @@ func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceA ...@@ -72,6 +72,7 @@ func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceA
StandardBrandId: standardBrandId, StandardBrandId: standardBrandId,
GoodsId: gjson.Get(skuInfo, "goods_id").String(), GoodsId: gjson.Get(skuInfo, "goods_id").String(),
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()), ClassId: int(gjson.Get(skuInfo, "class_id2").Int()),
GoodsName: gjson.Get(skuInfo, "goods_name").String(),
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity = activityService.GetActivityData(checkData) priceActivity, giftActivity = activityService.GetActivityData(checkData)
...@@ -79,13 +80,12 @@ func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceA ...@@ -79,13 +80,12 @@ func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceA
} }
/* /*
计算活动价 计算活动价
ac_type说明: 0 没有活动 ac_type说明: 0 没有活动
活动名称 ac_type 类型 活动名称 ac_type 类型
自营系数 6 自营 自营系数 6 自营
折扣(系数)活动 10 自营/联营 折扣(系数)活动 10 自营/联营
*/ */
func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap { func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
priceActivity, giftActivity := qs.GetActivity(SkuInfo) priceActivity, giftActivity := qs.GetActivity(SkuInfo)
...@@ -132,7 +132,7 @@ func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap ...@@ -132,7 +132,7 @@ func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap
} }
/* /*
获取当前锁住的库存 获取当前锁住的库存
*/ */
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 {
......
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