Commit 17642664 by mushishixian

活动判断优化

parent 8d333109
Showing with 278 additions and 273 deletions
package service
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
"time"
)
type ActivityService struct {
}
//获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
supplierId := checkData.SupplierId
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
//处理满赠活动
activityStr, _ := redis.String(redisCon.Do("hget", "lie_gift_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
giftActivity = as.GetGiftActivity(checkData, activities)
}
}
//处理单品促销活动(打折活动)
activityStr, _ = redis.String(redisCon.Do("hget", "lie_price_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
priceActivity = as.GetPriceActivity(checkData, activities)
}
}
return
}
//获取满赠活动信息
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.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
goto INFO
}
}
INFO:
if hasActivity {
for key, item := range activity.ItemList {
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 = model.GiftActivity{
CanAdminOrder: activity.CanAdminOrder,
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
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.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
} else {
hasActivity = true
goto INFO
}
}
} 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
goto INFO
}
}
INFO:
if hasActivity {
priceActivity.ActivityName = activity.ActivityName
priceActivity.ActivityId = activity.ActivityId
priceActivity = model.PriceActivity{
Ratio: activity.Ratio,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
priceActivity.HasActivity = hasActivity
return
}
//检查是否属于被排除的品牌
func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
return false
}
//先去判断品牌
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
return true
}
return false
}
//检查是否属于被排除的sku
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
return true
}
return false
}
//检查是否属于活动分类(只有自营需要判断)
func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool {
if classId == 0 {
return false
}
//先去判断品牌
activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) {
return true
}
return false
}
//检查是否属于活动品牌
func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
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) 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
}
package service
import (
"encoding/json"
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
"time"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
)
type ActivityService struct {
}
//获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
supplierId := checkData.SupplierId
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
//处理满赠活动
activityStr, _ := redis.String(redisCon.Do("hget", "lie_gift_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
giftActivity = as.GetGiftActivity(checkData, activities)
}
}
//处理单品促销活动(打折活动)
activityStr, _ = redis.String(redisCon.Do("hget", "lie_price_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
priceActivity = as.GetPriceActivity(checkData, activities)
}
}
return
}
//获取满赠活动信息
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.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
goto INFO
}
}
INFO:
if hasActivity {
for key, item := range activity.ItemList {
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 = model.GiftActivity{
CanAdminOrder: activity.CanAdminOrder,
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
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.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
//品牌不为空,还要去判断品牌,是同时满足的关系
if activity.BrandIds != "" {
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
} else {
hasActivity = true
goto INFO
}
}
} else if checkData.SupplierId == 10000 {
//判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
if len(activity.BrandIdList) == 0 && len(activity.ClassIdList) == 0 {
goto INFO
}
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
goto INFO
}
}
INFO:
if hasActivity {
priceActivity.ActivityName = activity.ActivityName
priceActivity.ActivityId = activity.ActivityId
priceActivity = model.PriceActivity{
Ratio: activity.Ratio,
SignText: activity.SignText,
Sign: activity.Sign,
ShowName: activity.ShowName,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
priceActivity.HasActivity = hasActivity
return
}
//检查是否属于被排除的品牌
func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
return false
}
//先去判断品牌
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
return true
}
return false
}
//检查是否属于被排除的sku
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
return true
}
return false
}
//检查是否属于活动分类(只有自营需要判断)
func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool {
if classId == 0 {
return false
}
//先去判断品牌
activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) {
return true
}
return false
}
//检查是否属于活动品牌
func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
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) 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
}
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