Commit 756df35c by mushishixian

联营满赠

parent 7a48b6ee
package model
type Activity struct {
Id int64 `json:"id"`
SupplierIds string `json:"supplier_ids"`
SupplierIdList []string
SupplierType int `json:"supplier_type"`
UserScope int `json:"user_scope"`
SignText string `json:"sign_text"`
BrandIds string `json:"brand_ids"`
BrandIdList []string
ClassIds string `json:"class_ids"`
ClassIdList []string
Canals string `json:"canals"`
CanalList []string
Ratio float64 `json:"ratio"`
StartTime int `json:"start_time"`
EndTime int `json:"end_time"`
AddTime int `json:"add_time"`
UpdateTime int `json:"update_time"`
Status int `json:"status"`
AllowCoupon int `json:"allow_coupon"`
ActivityName string `json:"activity_name"`
ShowName string `json:"show_name"`
Sign string `json:"sign"`
ActivityType int `json:"activity_type"`
GoodsScope int `json:"goods_scope"`
ExcludeBrandIds string `json:"exclude_brand_ids"`
ExcludeBrandIdList []string
ExcludeSkuIds string `json:"exclude_sku_ids"`
ExcludeSkuIdList []string
SkuIds string `json:"sku_ids"`
SkuIdList []string
AdminId int `json:"admin_id"`
AdminName string `json:"admin_name"`
ActivityId int `json:"activity_id"`
ItemList []ActivityItem `json:"item_list"`
}
type ActivityItem struct {
ActivityId int `json:"activity_id"`
Amount float64 `json:"amount"`
Num int `json:"num"`
ItemName string `json:"item_name"`
Pic string `json:"pic"`
Remark string `json:"remark"`
AddTime int `json:"add_time"`
}
//用于检查是否有活动情况的结构体
type ActivityCheckData struct {
SupplierId int
BrandId int
GoodsId string
Canal string
ClassId int
}
...@@ -60,12 +60,25 @@ type LySku struct { ...@@ -60,12 +60,25 @@ type LySku struct {
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail,omitempty"`
//活动信息 //活动信息
ActivityEndTime int64 `json:"activity_end_time,omitempty"` HasGiftActivity int `json:"has_gift_activity"`
ActivityInfo map[string]interface{} `json:"activity_info,omitempty"` GiftActivity GiftActivity `json:"gift_activity"`
Content interface{} `json:"content"` }
type PriceActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
Ratio float64 `json:"ratio"`
} }
type GiftActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ItemList []ActivityItem `json:"items,omitempty"`
}
//为什么不直接映射到结构,而要用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()
......
...@@ -7,42 +7,41 @@ poolskuSave 返回是这样的格式 ...@@ -7,42 +7,41 @@ poolskuSave 返回是这样的格式
"errmsg": "ok", "errmsg": "ok",
"goods_id": 1160699091498808475 "goods_id": 1160699091498808475
} }
*/ */
type LySaveResponse struct { type LySaveResponse struct {
ErrCode int `json:"errcode"` ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`
GoodsId int64 `json:"goods_id"` GoodsId int64 `json:"goods_id"`
} }
func ResponseSucess(GoodsId int64) LySaveResponse { func ResponseSucess(GoodsId int64) LySaveResponse {
return LySaveResponse{0,"ok",GoodsId} return LySaveResponse{0, "ok", GoodsId}
} }
func (L *LySaveResponse)GetErrorMsg() string { func (L *LySaveResponse) GetErrorMsg() string {
return L.ErrMsg return L.ErrMsg
} }
func (L *LySaveResponse)GetErrorCode() int { func (L *LySaveResponse) GetErrorCode() int {
return L.ErrCode return L.ErrCode
} }
func ResponseError(opts ...interface{}) LySaveResponse { func ResponseError(opts ...interface{}) LySaveResponse {
var ErrMsg string; var ErrMsg string
Code:=1001; Code := 1001
for num,opt:=range opts{ for num, opt := range opts {
if(num>1){ if num > 1 {
break; break
} }
switch num { switch num {
case 0: case 0:
ErrMsg=opt.(string) ErrMsg = opt.(string)
case 1: case 1:
Code=opt.(int) Code = opt.(int)
break break
} }
} }
return LySaveResponse{ErrCode: Code, ErrMsg: ErrMsg} return LySaveResponse{ErrCode: Code, ErrMsg: ErrMsg}
} }
...@@ -14,20 +14,27 @@ func InitRouter() *gin.Engine { ...@@ -14,20 +14,27 @@ func InitRouter() *gin.Engine {
//联营参数选择搜索 //联营参数选择搜索
r.GET("synchronization", controller.Synchronization) r.GET("synchronization", controller.Synchronization)
r.POST("synchronization",controller.Synchronization) r.POST("synchronization", controller.Synchronization)
//联营参数选择搜索 //联营参数选择搜索
r.GET("Synchronization", controller.Synchronization) r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization) r.POST("Synchronization", controller.Synchronization)
//心跳 //心跳
r.GET("hbsdata", controller.Hbsdata) r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata",controller.Hbsdata) r.POST("hbsdata", controller.Hbsdata)
//测试redis //测试redis
r.POST("testr",controller.Testr) r.POST("testr", controller.Testr)
//自营SaveSku //自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku) r.POST("SaveSku", controller.Error_Middleware(), controller.SaveSku)
r.POST("SkuEdit",controller.Error_Middleware(),controller.SkuEdit) r.POST("SkuEdit", controller.Error_Middleware(), controller.SkuEdit)
//ly := service.LyService{}
//sku := model.ActivityCheckData{
// SupplierId: 2,
// BrandId: 1,
// GoodsId: "1",
// Canal: "lmxs",
//}
//ly.GetActivityData(sku)
return r return r
} }
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"
)
type ActivityService struct {
}
//获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
supplierId := checkData.SupplierId
redisCon := gredis.Conn("default_r")
//处理满赠活动
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
for _, activity := range activities {
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
}
}
giftActivity.HasActivity = hasActivity
return
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool
for _, activity := range activities {
//判断是否是排除的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
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
}
//判断是否是搞活动的品牌
if as.CheckSkuId(checkData.GoodsId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
}
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
}
//检查是否属于活动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
}
package service
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger"
"go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"strconv"
)
//获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr
var attrsList []interface{}
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
spuIdInt, _ := strconv.Atoi(spuId)
err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if err != nil && err != mgo.ErrNotFound {
fmt.Println("mongodb连接错误:")
fmt.Println(err)
}
if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil {
logger.Error("%s", err)
}
for _, value := range o.Keys() {
data := make(map[string]interface{})
data["attr_name"] = value
data["attr_value"], _ = o.Get(value)
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
}
return false
}
...@@ -2,11 +2,13 @@ package service ...@@ -2,11 +2,13 @@ package service
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort" "sort"
"sync" "sync"
) )
...@@ -30,24 +32,24 @@ type Power struct { ...@@ -30,24 +32,24 @@ type Power struct {
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) { func (ls *LyService) LyGoodsDetail(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()
redisConn.Close() redisConn.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
isNewCustomer := ctx.Request.FormValue("power[newCustomer]") //isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
power := Power{ //power := Power{
UserId: ctx.Request.FormValue("power[user_id]"), // UserId: ctx.Request.FormValue("power[user_id]"),
Mobile: ctx.Request.FormValue("power[mobile]"), // Mobile: ctx.Request.FormValue("power[mobile]"),
Email: ctx.Request.FormValue("power[email]"), // Email: ctx.Request.FormValue("power[email]"),
Member: ctx.Request.FormValue("power[member]"), // Member: ctx.Request.FormValue("power[member]"),
Invoice: ctx.Request.FormValue("power[invoice]"), // Invoice: ctx.Request.FormValue("power[invoice]"),
SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"), // SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"), // VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
} //}
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
spuList := ls.getSpuList(skuArr) var spuService SpuService
spuList := spuService.getSpuList(skuArr)
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
...@@ -56,7 +58,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -56,7 +58,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
continue continue
} }
//初始化有序map,拼接data 数据 //初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr) sku := model.InitSkuData(skuStr)
sku.GoodsId = goodsId sku.GoodsId = goodsId
spu := spuList[sku.SpuId] spu := spuList[sku.SpuId]
...@@ -117,35 +118,28 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -117,35 +118,28 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1 sku.AllowCoupon = 1
sku.BrandId = brandId sku.BrandId = brandId
//活动标识 //去判断是否有活动(促销打折活动和满赠活动)
hasActivity := false checkData := model.ActivityCheckData{
//判断是否有新客价权利 SupplierId: int(sku.SupplierId),
if isNewCustomer == "true" || isNewCustomer == "1" { BrandId: int(sku.BrandId),
//获取新客价 GoodsId: sku.GoodsId,
sku = ls.GetActivityPrice(sku, "_NewCustomer", power) Canal: sku.Canal,
if sku.AcType > 0 { ClassId: sku.ClassID2,
hasActivity = true
}
} }
//获取活动价 var activityService ActivityService
if !hasActivity { priceActivity, giftActivity := activityService.GetActivityData(checkData)
sku = ls.GetActivityPrice(sku, "", power) if priceActivity.HasActivity {
if sku.AcType > 0 { sku.AcType = 9
hasActivity = true
}
} }
if giftActivity.HasActivity {
//获取会员价 sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
if !hasActivity { sku.GiftActivity = giftActivity
sku = ls.GetActivityPrice(sku, "_Member", power)
if sku.AcType > 0 {
hasActivity = true
}
} }
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
//排序 //排序
sort.Sort(LadderPriceSorter(sku.LadderPrice)) sort.Sort(sorter.LadderPriceSorter(sku.LadderPrice))
//取出第一个阶梯价 //取出第一个阶梯价
purchases := sku.LadderPrice[0].Purchases purchases := sku.LadderPrice[0].Purchases
if purchases > sku.Moq { if purchases > sku.Moq {
...@@ -194,14 +188,3 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -194,14 +188,3 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
ch <- GoodsRes ch <- GoodsRes
} }
func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
var spuIds []string
for _, skuStr := range skuArr {
spuId := gjson.Get(skuStr, "spu_id").String()
spuIds = append(spuIds, spuId)
}
//批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds)
return
}
...@@ -2,9 +2,7 @@ package service ...@@ -2,9 +2,7 @@ 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/iancoleman/orderedmap"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
...@@ -12,12 +10,8 @@ import ( ...@@ -12,12 +10,8 @@ import (
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/mongo"
_ "go_sku_server/pkg/mongo" _ "go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
_ "gopkg.in/mgo.v2/bson" _ "gopkg.in/mgo.v2/bson"
"strconv"
"strings" "strings"
) )
...@@ -95,38 +89,6 @@ type SpuAttr struct { ...@@ -95,38 +89,6 @@ type SpuAttr struct {
Attrs string `bson:"attrs"` Attrs string `bson:"attrs"`
} }
//获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr
var attrsList []interface{}
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
spuIdInt, _ := strconv.Atoi(spuId)
err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if err != nil && err != mgo.ErrNotFound {
fmt.Println("mongodb连接错误:")
fmt.Println(err)
}
if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil {
logger.Error("%s", err)
}
for _, value := range o.Keys() {
data := make(map[string]interface{})
data["attr_name"] = value
data["attr_value"], _ = o.Get(value)
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
}
return false
}
//H获取供应链标准品牌 //H获取供应链标准品牌
func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) { func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
...@@ -279,7 +241,6 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -279,7 +241,6 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
} }
if !hasCoefficient && !hasDefault { if !hasCoefficient && !hasDefault {
logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId)) logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId))
sku.Content = "系数获取异常,供应商:"+common.ToString(sku.SupplierId)
return sku return sku
} }
......
...@@ -163,27 +163,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -163,27 +163,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
activityType := gjson.Get(activityInfo, "activity_type").Int() activityType := gjson.Get(activityInfo, "activity_type").Int()
if suffix == "" && blacklistType != 0 && hasActivity && activityId != "" && activityType == 2 && if suffix == "" && blacklistType != 0 && hasActivity && activityId != "" && activityType == 2 &&
power.VerifyBlacklist == "true" { power.VerifyBlacklist == "true" {
////_1 是用来区分活动价和折扣价,活动和折扣价(折扣价有黑名单,活动价没有黑名单)
//blackList, _ := redis.String(redisCon.Do("HGET", "activity_roster", activityId+"_1"))
////拼接是为了方便判断是否包含在黑名单内
//blackList = "," + blackList + ","
//blacklistTypeList := make(map[int]string)
//blacklistTypeList = map[int]string{
// 1: "invoice",
// 2: "special_invoice",
// 3: "user_id",
// 4: "mobile",
// 5: "email",
//}
//遍历黑名单类型
//黑名单就不显示折扣价吗,黑名单只针对折扣价
//activityBlackListTypes := gjson.Get(activityInfo, "blacklist_type").Array()
//for _, value := range activityBlackListTypes {
// //验证是否有对应的黑名单类型
// blackListType := blacklistTypeList[int(value.Int())]
// blackListItem :=
//
//}
} }
} }
//判断是否有活动 //判断是否有活动
...@@ -215,13 +194,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -215,13 +194,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
if allowNotLogin == 0 { if allowNotLogin == 0 {
allowNotLogin = 2 allowNotLogin = 2
} }
sku.ActivityInfo = map[string]interface{}{
"activity_ad": gjson.Get(activityInfo, "activity_ad").String(),
"sign_name": gjson.Get(activityInfo, "sign_name").String(),
"id": gjson.Get(activityInfo, "id").String(),
"activity_name": gjson.Get(activityInfo, "activity_name").String(),
"allow_not_login": allowNotLogin,
}
sku.AcType = 8 sku.AcType = 8
} }
break break
...@@ -233,7 +205,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -233,7 +205,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
allCoupon = 1 allCoupon = 1
} }
sku.AllowCoupon = int(allCoupon) sku.AllowCoupon = int(allCoupon)
sku.ActivityEndTime = endTime
return sku return sku
} }
...@@ -253,18 +224,3 @@ func getMouserActivityPrice(sku model.LySku) model.LySku { ...@@ -253,18 +224,3 @@ func getMouserActivityPrice(sku model.LySku) model.LySku {
} }
return sku return sku
} }
//阶梯价格排序算法
type LadderPriceSorter []model.LadderPrice
func (a LadderPriceSorter) Len() int {
return len(a)
}
func (a LadderPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a LadderPriceSorter) Less(i, j int) bool {
return a[j].Purchases > a[i].Purchases
}
package service
import (
"github.com/tidwall/gjson"
"go_sku_server/pkg/gredis"
)
type SpuService struct {
}
func (ss *SpuService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
var spuIds []string
for _, skuStr := range skuArr {
spuId := gjson.Get(skuStr, "spu_id").String()
spuIds = append(spuIds, spuId)
}
//批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds)
return
}
package sorter
import "go_sku_server/model"
//阶梯价格排序算法
type LadderPriceSorter []model.LadderPrice
func (a LadderPriceSorter) Len() int {
return len(a)
}
func (a LadderPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a LadderPriceSorter) Less(i, j int) bool {
return a[j].Purchases > a[i].Purchases
}
\ No newline at end of file
package transformer
import (
"go_sku_server/model"
"strings"
)
func TransformActivity(activities []model.Activity) []model.Activity {
for key, activity := range activities {
activities[key].ClassIdList = strings.Split(activity.ClassIds, ",")
activities[key].BrandIdList = strings.Split(activity.BrandIds, ",")
activities[key].SkuIdList = strings.Split(activity.SkuIds, ",")
activities[key].ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
activities[key].ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
activities[key].CanalList = strings.Split(activity.Canals, ",")
}
return activities
}
package main package main
import ( import (
"fmt" "go_sku_server/service"
"github.com/syyongx/php2go"
) )
func main() { func main() {
var a = []string{"3923"} ly := service.LyService{}
var b = 3923 ly.GetActivityData()
fmt.Println(php2go.InArray(b,a))
} }
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