Commit 17642664 by mushishixian

活动判断优化

parent 8d333109
Showing with 278 additions and 273 deletions
package service package service
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gogf/gf/util/gconv" "go_sku_server/model"
"github.com/gomodule/redigo/redis" "go_sku_server/pkg/gredis"
"github.com/syyongx/php2go" "strings"
"go_sku_server/model" "time"
"go_sku_server/pkg/gredis"
"strings" "github.com/gogf/gf/util/gconv"
"time" "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_gift_activity", supplierId)) //处理满赠活动
if activityStr != "" { activityStr, _ := redis.String(redisCon.Do("hget", "lie_gift_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 { }
giftActivity = as.GetGiftActivity(checkData, activities) if len(activities) != 0 {
} giftActivity = as.GetGiftActivity(checkData, activities)
} }
}
//处理单品促销活动(打折活动)
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()) 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
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 { //如果是专卖,则要去判断canal,如果是自营,则去判断分类
if as.CheckCanal(checkData.Canal, activity) { if checkData.SupplierId == 17 {
//品牌不为空,还要去判断品牌,是同时满足的关系 if as.CheckCanal(checkData.Canal, activity) {
if activity.BrandIds != "" { //品牌不为空,还要去判断品牌,是同时满足的关系
//判断是否是搞活动的品牌 if activity.BrandIds != "" {
if as.CheckBrand(checkData.BrandId, activity) { //判断是否是搞活动的品牌
hasActivity = true if as.CheckBrand(checkData.BrandId, activity) {
goto INFO hasActivity = true
} goto INFO
} else { }
hasActivity = true } else {
goto INFO hasActivity = true
} goto INFO
} }
} else if checkData.SupplierId == 10000 { }
if as.CheckClass(checkData.ClassId, activity) { } else if checkData.SupplierId == 10000 {
//品牌不为空,还要去判断品牌,是同时满足的关系 //判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
if activity.BrandIds != "" { if len(activity.BrandIdList) == 0 && len(activity.ClassIdList) == 0 {
//判断是否是搞活动的品牌 goto INFO
if as.CheckBrand(checkData.BrandId, activity) { }
hasActivity = true if as.CheckClass(checkData.ClassId, activity) {
goto INFO //品牌不为空,还要去判断品牌,是同时满足的关系
} if activity.BrandIds != "" {
} else { //判断是否是搞活动的品牌
hasActivity = true if as.CheckBrand(checkData.BrandId, activity) {
goto INFO hasActivity = true
} goto INFO
} }
} else { } else {
//判断是否是搞活动的品牌 hasActivity = true
if as.CheckBrand(checkData.BrandId, activity) { goto INFO
hasActivity = true }
goto INFO }
} } else {
} //判断是否是搞活动的品牌
INFO: if as.CheckBrand(checkData.BrandId, activity) {
if hasActivity { hasActivity = true
priceActivity.ActivityName = activity.ActivityName goto INFO
priceActivity.ActivityId = activity.ActivityId }
priceActivity = model.PriceActivity{ }
Ratio: activity.Ratio, INFO:
SignText: activity.SignText, if hasActivity {
Sign: activity.Sign, priceActivity.ActivityName = activity.ActivityName
ShowName: activity.ShowName, priceActivity.ActivityId = activity.ActivityId
ActivityCommon: model.ActivityCommon{ priceActivity = model.PriceActivity{
HasActivity: hasActivity, Ratio: activity.Ratio,
ActivityId: activity.ActivityId, SignText: activity.SignText,
ActivityName: activity.ActivityName, Sign: activity.Sign,
AllowCoupon: activity.AllowCoupon, ShowName: activity.ShowName,
UserScope: activity.UserScope, ActivityCommon: model.ActivityCommon{
}, HasActivity: hasActivity,
} ActivityId: activity.ActivityId,
break ActivityName: activity.ActivityName,
} AllowCoupon: activity.AllowCoupon,
} UserScope: activity.UserScope,
},
priceActivity.HasActivity = hasActivity }
return break
} }
}
//检查是否属于被排除的品牌
func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool { priceActivity.HasActivity = hasActivity
if brandId == 0 { return
return false }
}
//先去判断品牌 //检查是否属于被排除的品牌
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",") func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool {
brandIdStr := gconv.String(brandId) if brandId == 0 {
//如果存在于有活动价的品牌,就是有折扣活动了 return false
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) { }
return true //先去判断品牌
} activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
return false brandIdStr := gconv.String(brandId)
} //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
//检查是否属于被排除的sku return true
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool { }
if skuId == "" { return false
return false }
}
//先去判断品牌 //检查是否属于被排除的sku
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",") func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
//如果存在于有活动价的品牌,就是有折扣活动了 if skuId == "" {
if php2go.InArray(skuId, activity.ExcludeSkuIdList) { return false
return true }
} //先去判断品牌
return false activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
} //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
//检查是否属于活动分类(只有自营需要判断) return true
func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool { }
if classId == 0 { return false
return false }
}
//先去判断品牌 //检查是否属于活动分类(只有自营需要判断)
activity.ClassIdList = strings.Split(activity.ClassIds, ",") func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool {
classIdStr := gconv.String(classId) if classId == 0 {
//如果存在于有活动价的品牌,就是有折扣活动了 return false
if php2go.InArray(classIdStr, activity.ClassIdList) { }
return true //先去判断品牌
} activity.ClassIdList = strings.Split(activity.ClassIds, ",")
return false classIdStr := gconv.String(classId)
} //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) {
//检查是否属于活动品牌 return true
func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool { }
if brandId == 0 { return false
return false }
}
//先去判断品牌 //检查是否属于活动品牌
activity.BrandIdList = strings.Split(activity.BrandIds, ",") func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool {
brandIdStr := gconv.String(brandId) if brandId == 0 {
//如果存在于有活动价的品牌,就是有折扣活动了 return false
if php2go.InArray(brandIdStr, activity.BrandIdList) { }
return true //先去判断品牌
} activity.BrandIdList = strings.Split(activity.BrandIds, ",")
return false brandIdStr := gconv.String(brandId)
} //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.BrandIdList) {
//检查是否属于供应商渠道 return true
func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool { }
if canal == "" { return false
return false }
}
//先去判断品牌 //检查是否属于供应商渠道
activity.CanalList = strings.Split(activity.Canals, ",") func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool {
//如果存在于有活动价的品牌,就是有折扣活动了 if canal == "" {
if php2go.InArray(canal, activity.CanalList) { return false
return true }
} //先去判断品牌
return false activity.CanalList = strings.Split(activity.Canals, ",")
} //如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(canal, activity.CanalList) {
return true
}
return false
}
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