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 {
ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
//活动信息
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
ActivityInfo map[string]interface{} `json:"activity_info,omitempty"`
Content interface{} `json:"content"`
HasGiftActivity int `json:"has_gift_activity"`
GiftActivity GiftActivity `json:"gift_activity"`
}
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存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String()
......
......@@ -7,7 +7,7 @@ poolskuSave 返回是这样的格式
"errmsg": "ok",
"goods_id": 1160699091498808475
}
*/
*/
type LySaveResponse struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
......@@ -15,34 +15,33 @@ type LySaveResponse struct {
}
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
}
func (L *LySaveResponse)GetErrorCode() int {
func (L *LySaveResponse) GetErrorCode() int {
return L.ErrCode
}
func ResponseError(opts ...interface{}) LySaveResponse {
var ErrMsg string;
Code:=1001;
var ErrMsg string
Code := 1001
for num,opt:=range opts{
for num, opt := range opts {
if(num>1){
break;
if num > 1 {
break
}
switch num {
case 0:
ErrMsg=opt.(string)
ErrMsg = opt.(string)
case 1:
Code=opt.(int)
Code = opt.(int)
break
}
}
return LySaveResponse{ErrCode: Code, ErrMsg: ErrMsg}
}
......@@ -14,20 +14,27 @@ func InitRouter() *gin.Engine {
//联营参数选择搜索
r.GET("synchronization", controller.Synchronization)
r.POST("synchronization",controller.Synchronization)
r.POST("synchronization", controller.Synchronization)
//联营参数选择搜索
r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization)
r.POST("Synchronization", controller.Synchronization)
//心跳
r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata",controller.Hbsdata)
r.POST("hbsdata", controller.Hbsdata)
//测试redis
r.POST("testr",controller.Testr)
r.POST("testr", controller.Testr)
//自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
r.POST("SkuEdit",controller.Error_Middleware(),controller.SkuEdit)
r.POST("SaveSku", controller.Error_Middleware(), controller.SaveSku)
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
}
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
import (
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort"
"sync"
)
......@@ -30,24 +32,24 @@ type Power struct {
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r")
defer func() {
//wg.Done()
redisConn.Close()
}()
fast := ctx.Request.FormValue("power[fast]")
isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
power := Power{
UserId: ctx.Request.FormValue("power[user_id]"),
Mobile: ctx.Request.FormValue("power[mobile]"),
Email: ctx.Request.FormValue("power[email]"),
Member: ctx.Request.FormValue("power[member]"),
Invoice: ctx.Request.FormValue("power[invoice]"),
SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
}
//isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
//power := Power{
// UserId: ctx.Request.FormValue("power[user_id]"),
// Mobile: ctx.Request.FormValue("power[mobile]"),
// Email: ctx.Request.FormValue("power[email]"),
// Member: ctx.Request.FormValue("power[member]"),
// Invoice: ctx.Request.FormValue("power[invoice]"),
// SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
// VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
//}
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息
spuList := ls.getSpuList(skuArr)
var spuService SpuService
spuList := spuService.getSpuList(skuArr)
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr {
......@@ -56,7 +58,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
continue
}
//初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr)
sku.GoodsId = goodsId
spu := spuList[sku.SpuId]
......@@ -117,35 +118,28 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1
sku.BrandId = brandId
//活动标识
hasActivity := false
//判断是否有新客价权利
if isNewCustomer == "true" || isNewCustomer == "1" {
//获取新客价
sku = ls.GetActivityPrice(sku, "_NewCustomer", power)
if sku.AcType > 0 {
hasActivity = true
}
//去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId,
Canal: sku.Canal,
ClassId: sku.ClassID2,
}
//获取活动价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power)
if sku.AcType > 0 {
hasActivity = true
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
}
//获取会员价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "_Member", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
//排序
sort.Sort(LadderPriceSorter(sku.LadderPrice))
sort.Sort(sorter.LadderPriceSorter(sku.LadderPrice))
//取出第一个阶梯价
purchases := sku.LadderPrice[0].Purchases
if purchases > sku.Moq {
......@@ -194,14 +188,3 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
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
import (
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
_ "github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
......@@ -12,12 +10,8 @@ import (
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mongo"
_ "go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
_ "gopkg.in/mgo.v2/bson"
"strconv"
"strings"
)
......@@ -95,38 +89,6 @@ type SpuAttr struct {
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获取供应链标准品牌
func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
......@@ -279,7 +241,6 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
}
if !hasCoefficient && !hasDefault {
logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId))
sku.Content = "系数获取异常,供应商:"+common.ToString(sku.SupplierId)
return sku
}
......
......@@ -13,6 +13,7 @@ import (
"go_sku_server/pkg/e"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mysql"
"go_sku_server/service/sorter"
"reflect"
"sort"
"time"
......@@ -43,51 +44,52 @@ sku基本数据增加和修改
Pdf int `json:"pdf" `
SpuBrief int `json:"spu_brief" `
Attrs int `json:"attrs" `
*/
*/
var skuCache SkuCacheService
func (S *LySaveService)SaveSku(lySaveRequest saveModel.LySaveRequest,ctx *gin.Context) (error,string) {
lySkuEntity:=lySaveRequest.ToLySkuEntity()//sku实体
func (S *LySaveService) SaveSku(lySaveRequest saveModel.LySaveRequest, ctx *gin.Context) (error, string) {
lySkuEntity := lySaveRequest.ToLySkuEntity() //sku实体
//供应商处理(处理后,将[新增/修改sku]所需供应商相关字段 赋值给 &lySkuEntity)
err:=S.supplierHandle(lySaveRequest.SupplierId,lySkuEntity.Canal,&lySkuEntity)
if(err!=nil){
return e.NewApiError("供应商处理失败"+err.Error()),""
err := S.supplierHandle(lySaveRequest.SupplierId, lySkuEntity.Canal, &lySkuEntity)
if err != nil {
return e.NewApiError("供应商处理失败" + err.Error()), ""
}
//阶梯价格处理
err=S.ladderPriceHandle(lySaveRequest.LadderPrice,&lySkuEntity)
if(err!=nil){
return e.NewApiError("阶梯价格处理失败"+err.Error()),""
err = S.ladderPriceHandle(lySaveRequest.LadderPrice, &lySkuEntity)
if err != nil {
return e.NewApiError("阶梯价格处理失败" + err.Error()), ""
}
//上下架状态处理
S.statusHandle(&lySkuEntity)
//spu处理(请求spu_server saveSpu接口,将spuId赋值给 &lySkuEntity)
lySpuRequest:=lySaveRequest.ToLySpuRequest()
err=S.spuHandle(lySpuRequest,&lySkuEntity)
if(err!=nil){
return err,""
lySpuRequest := lySaveRequest.ToLySpuRequest()
err = S.spuHandle(lySpuRequest, &lySkuEntity)
if err != nil {
return err, ""
}
//mongoDb 获取sku 唯一信息
err,mongoSkuInfo:=skuCache.MongoGetOnlySkuInfo(lySkuEntity.SpuId,lySkuEntity.SupplierId,lySkuEntity.Moq,lySkuEntity.Encoded,lySkuEntity.Canal)
if(err!=nil){
return e.NewApiError("mongo 获取sku唯一信息失败"+err.Error()),""
err, mongoSkuInfo := skuCache.MongoGetOnlySkuInfo(lySkuEntity.SpuId, lySkuEntity.SupplierId, lySkuEntity.Moq, lySkuEntity.Encoded, lySkuEntity.Canal)
if err != nil {
return e.NewApiError("mongo 获取sku唯一信息失败" + err.Error()), ""
}
if(mongoSkuInfo.GoodsId!=0){//更新
if mongoSkuInfo.GoodsId != 0 { //更新
lySkuEntity.GoodsId=gconv.String(mongoSkuInfo.GoodsId)
err:=S.update(lySkuEntity,lySaveRequest)
if(err!=nil){
return e.NewApiError("skuSave 修改sku失败"+err.Error()),""
lySkuEntity.GoodsId = gconv.String(mongoSkuInfo.GoodsId)
err := S.update(lySkuEntity, lySaveRequest)
if err != nil {
return e.NewApiError("skuSave 修改sku失败" + err.Error()), ""
}
return nil,lySkuEntity.GoodsId
}else{//插入sku
err,skuId:=S.insert(lySkuEntity,lySaveRequest)
if(err!=nil){
return e.NewApiError("skuSave insert sku失败"+err.Error()),""
return nil, lySkuEntity.GoodsId
} else { //插入sku
err, skuId := S.insert(lySkuEntity, lySaveRequest)
if err != nil {
return e.NewApiError("skuSave insert sku失败" + err.Error()), ""
}
logger.Select("lysku_save").Info("新增完成:brand_name:"+lySaveRequest.BrandName+";sku_id:"+skuId+";good_name:"+lySaveRequest.GoodsName)
logger.Select("lysku_save").Info("新增完成:brand_name:" + lySaveRequest.BrandName + ";sku_id:" + skuId + ";good_name:" + lySaveRequest.GoodsName)
return nil, skuId
}
......@@ -98,41 +100,41 @@ func (S *LySaveService)SaveSku(lySaveRequest saveModel.LySaveRequest,ctx *gin.Co
1.判断供应商是否存在,是否被禁用
2.如果供应商为专卖,参数 cannal(供应商编码)是必传的
3.得到 新增sku所需的 TypeId 和 Encoded(渠道员内部编码)
*/
func (S *LySaveService) supplierHandle(SupplierId int,Canal string,lySkuEntity *saveModel.LySkuEntity) (error) {
*/
func (S *LySaveService) supplierHandle(SupplierId int, Canal string, lySkuEntity *saveModel.LySkuEntity) error {
lySupplier:= LySupplier{}
lySupplier := LySupplier{}
has,err,supplierInfo:=lySupplier.GetSupplirInfo(SupplierId)
if(err!=nil){
return e.NewApiError("获取基石供应商详情失败"+err.Error())
has, err, supplierInfo := lySupplier.GetSupplirInfo(SupplierId)
if err != nil {
return e.NewApiError("获取基石供应商详情失败" + err.Error())
}
if(!has){
fmt.Sprintf("没有在基石获取到此供应商,供应商ID为:%s",SupplierId)
if !has {
fmt.Sprintf("没有在基石获取到此供应商,供应商ID为:%s", SupplierId)
}
if(supplierInfo.Status!=1){
if supplierInfo.Status != 1 {
return e.NewApiError("供应商被禁用")
}
//专卖处理(供应商系统)
if(supplierInfo.TypeId==2){
if(Canal==""){
if supplierInfo.TypeId == 2 {
if Canal == "" {
return e.NewApiError("专卖 cannal参数为必传")
}
has,err,poolSupplierInfo:=lySupplier.GetPoolSupplirInfo(Canal)
has, err, poolSupplierInfo := lySupplier.GetPoolSupplirInfo(Canal)
if(err!=nil){
return e.NewApiError("获取联营供应商详情失败"+err.Error())
if err != nil {
return e.NewApiError("获取联营供应商详情失败" + err.Error())
}
if(!has){
if !has {
errmsg:=fmt.Sprintf("没有获取到渠道%s的内部编码",Canal)
errmsg := fmt.Sprintf("没有获取到渠道%s的内部编码", Canal)
return e.NewApiError(errmsg)
}
lySkuEntity.Encoded=poolSupplierInfo.ChannelUid//渠道编码赋值给sku
lySkuEntity.Encoded = poolSupplierInfo.ChannelUid //渠道编码赋值给sku
}
lySkuEntity.GoodsType=supplierInfo.TypeId
lySkuEntity.GoodsType = supplierInfo.TypeId
return nil
}
......@@ -142,33 +144,32 @@ func (S *LySaveService) supplierHandle(SupplierId int,Canal string,lySkuEntity *
1.对阶梯价格排序
2.获取 ladderPrice
3.获取最便宜的价格
*/
func (S *LySaveService) ladderPriceHandle(ladderPrice []model.LadderPrice,lySkuEntity *saveModel.LySkuEntity) error {
*/
func (S *LySaveService) ladderPriceHandle(ladderPrice []model.LadderPrice, lySkuEntity *saveModel.LySkuEntity) error {
num:=len(ladderPrice)
num := len(ladderPrice)
if(len(ladderPrice)>0){//有传阶梯价
if len(ladderPrice) > 0 { //有传阶梯价
//获取最便宜的价格
sort.Sort(LadderPriceSorter(ladderPrice))//按照购买数量,小到大排序,数量越大优惠越多,所以[num-1]是最便宜的
sort.Sort(sorter.LadderPriceSorter(ladderPrice)) //按照购买数量,小到大排序,数量越大优惠越多,所以[num-1]是最便宜的
if(ladderPrice[num-1].PriceUs>=0){//如果有最低美元价,就直接读最低美元价
lySkuEntity.SinglePrice=ladderPrice[num-1].PriceUs//获取最便宜的价钱
}else{//没有美元价,就将最低人民币折算成美元
lySkuEntity.SinglePrice=php2go.Round(ladderPrice[num-1].PriceCn/6.8)
if ladderPrice[num-1].PriceUs >= 0 { //如果有最低美元价,就直接读最低美元价
lySkuEntity.SinglePrice = ladderPrice[num-1].PriceUs //获取最便宜的价钱
} else { //没有美元价,就将最低人民币折算成美元
lySkuEntity.SinglePrice = php2go.Round(ladderPrice[num-1].PriceCn / 6.8)
}
//将阶梯json字符串给到sku实体里,sku只需要字符串阶梯 存数据库
priceBytes,err:=json.Marshal(ladderPrice)
if(err!=nil){
return e.NewApiError("阶梯价格json化报错"+err.Error())
}else{
lySkuEntity.LadderPrice=string(priceBytes)
priceBytes, err := json.Marshal(ladderPrice)
if err != nil {
return e.NewApiError("阶梯价格json化报错" + err.Error())
} else {
lySkuEntity.LadderPrice = string(priceBytes)
} //状态处理
}
return nil
}
/**
spu处理(内部方法)
1.调用spu_server saveSpu接口,获取到spuId
......@@ -180,20 +181,20 @@ spu处理(内部方法)
| data | | 返回的data |
*/
func (S *LySaveService) spuHandle(lySpuRequest saveModel.LySpuRequest,lySkuEntity *saveModel.LySkuEntity) (error) {
func (S *LySaveService) spuHandle(lySpuRequest saveModel.LySpuRequest, lySkuEntity *saveModel.LySkuEntity) error {
lySpuResponse:=saveModel.LySpuResponse{}
lySpuResponse := saveModel.LySpuResponse{}
//err:=gout.POST(config.Get("spu_server.api_domain").String()+"/saveSpu1").Debug(false).SetJSON(&lySpuRequest).BindJSON(&lySpuResponse).Do()
err:=gout.POST("http://192.168.1.237:8005/saveSpu").Debug(false).SetJSON(&lySpuRequest).BindJSON(&lySpuResponse).Do()
err := gout.POST("http://192.168.1.237:8005/saveSpu").Debug(false).SetJSON(&lySpuRequest).BindJSON(&lySpuResponse).Do()
if(err!=nil){
return e.NewApiError("调用spu server saveSpu接口报错"+err.Error())
if err != nil {
return e.NewApiError("调用spu server saveSpu接口报错" + err.Error())
}
if(lySpuResponse.ErrorCode==0){
lySkuEntity.SpuId=lySpuResponse.Data.SpuId
}else{
return e.NewApiError("spu Throw out"+lySpuResponse.ErrMsg)
if lySpuResponse.ErrorCode == 0 {
lySkuEntity.SpuId = lySpuResponse.Data.SpuId
} else {
return e.NewApiError("spu Throw out" + lySpuResponse.ErrMsg)
}
return nil
}
......@@ -207,58 +208,59 @@ func (S *LySaveService) spuHandle(lySpuRequest saveModel.LySpuRequest,lySkuEntit
处理流程
满足 字段 moq stock ladder_price都有值 ,并且 moq > stock ; 那么 sku状态 就是 审核通过(status=1)
否则 就是下架状态(status=3)
*/
*/
func (S *LySaveService) statusHandle(lySkuEntity *saveModel.LySkuEntity) {
lySkuEntity.GoodsStatus=1
lySkuEntity.GoodsStatus = 1
if(lySkuEntity.LadderPrice==""){
lySkuEntity.GoodsStatus=3//下架
if lySkuEntity.LadderPrice == "" {
lySkuEntity.GoodsStatus = 3 //下架
}
if(lySkuEntity.Moq==0 || lySkuEntity.Stock==0 || lySkuEntity.Moq>lySkuEntity.Stock){
lySkuEntity.GoodsStatus=3//下架
if lySkuEntity.Moq == 0 || lySkuEntity.Stock == 0 || lySkuEntity.Moq > lySkuEntity.Stock {
lySkuEntity.GoodsStatus = 3 //下架
}
}
//更新
func (S *LySaveService) update(lySkuEntity saveModel.LySkuEntity,lySaveRequest saveModel.LySaveRequest)error{
db,table:=common.ResolveSpu(lySkuEntity.GoodsId)//解析skuID,返回对应的表和库,应该在生成skuID的时候返回表和库
func (S *LySaveService) update(lySkuEntity saveModel.LySkuEntity, lySaveRequest saveModel.LySaveRequest) error {
db, table := common.ResolveSpu(lySkuEntity.GoodsId) //解析skuID,返回对应的表和库,应该在生成skuID的时候返回表和库
//修改数据库
affected, err := mysql.Conn(db).Table(table).Where("goods_id=?",lySkuEntity.GoodsId).Update(lySkuEntity)
if (err != nil) {
return e.NewApiError("修改sku mysql数据失败 msg:"+err.Error())
affected, err := mysql.Conn(db).Table(table).Where("goods_id=?", lySkuEntity.GoodsId).Update(lySkuEntity)
if err != nil {
return e.NewApiError("修改sku mysql数据失败 msg:" + err.Error())
}
if(affected<=0){//没有什么可以修改的,直接完成就好了
if affected <= 0 { //没有什么可以修改的,直接完成就好了
fmt.Println("没什么可以修改的")
logger.Select("lysku_save").Info("不需要修改:brand_name:"+lySaveRequest.BrandName+";sku_id:"+lySkuEntity.GoodsId+";good_name:"+lySaveRequest.GoodsName)
logger.Select("lysku_save").Info("不需要修改:brand_name:" + lySaveRequest.BrandName + ";sku_id:" + lySkuEntity.GoodsId + ";good_name:" + lySaveRequest.GoodsName)
return nil
}else{
err=S.skuCacheSave(false,lySkuEntity.GoodsId,lySkuEntity,lySaveRequest)
if (err != nil) {
logger.Select("lysku_save").Info("修改完成:brand_name:"+lySaveRequest.BrandName+";sku_id:"+lySkuEntity.GoodsId+";good_name:"+lySaveRequest.GoodsName)
return e.NewApiError("缓存处理失败"+err.Error())
} else {
err = S.skuCacheSave(false, lySkuEntity.GoodsId, lySkuEntity, lySaveRequest)
if err != nil {
logger.Select("lysku_save").Info("修改完成:brand_name:" + lySaveRequest.BrandName + ";sku_id:" + lySkuEntity.GoodsId + ";good_name:" + lySaveRequest.GoodsName)
return e.NewApiError("缓存处理失败" + err.Error())
}
}
return nil
}
//插入
func (S *LySaveService) insert(lySkuEntity saveModel.LySkuEntity,lySaveRequest saveModel.LySaveRequest) (error,string) {
func (S *LySaveService) insert(lySkuEntity saveModel.LySkuEntity, lySaveRequest saveModel.LySaveRequest) (error, string) {
skuId:=common.StructureNumber("sku")//生成skuID
lySkuEntity.GoodsId=skuId
db,table:=common.ResolveSpu(lySkuEntity.GoodsId)//解析skuID,返回对应的表和库,应该在生成skuID的时候返回表和库
skuId := common.StructureNumber("sku") //生成skuID
lySkuEntity.GoodsId = skuId
db, table := common.ResolveSpu(lySkuEntity.GoodsId) //解析skuID,返回对应的表和库,应该在生成skuID的时候返回表和库
//插入到数据库
_, err := mysql.Conn(db).Table(table).Insert(lySkuEntity);
if (err != nil) {
return e.NewApiError("sku插入数据库失败"+err.Error()),""
_, err := mysql.Conn(db).Table(table).Insert(lySkuEntity)
if err != nil {
return e.NewApiError("sku插入数据库失败" + err.Error()), ""
}
err=S.skuCacheSave(true,skuId,lySkuEntity,lySaveRequest)
if(err!=nil){
return e.NewApiError("缓存处理失败"+err.Error()),""
err = S.skuCacheSave(true, skuId, lySkuEntity, lySaveRequest)
if err != nil {
return e.NewApiError("缓存处理失败" + err.Error()), ""
}
return nil,skuId
return nil, skuId
}
/**
......@@ -266,26 +268,26 @@ func (S *LySaveService) insert(lySkuEntity saveModel.LySkuEntity,lySaveRequest s
1.更新 redis skuinfo (1.新增直接插入,2.修改需要将老的redis sku数据合并新的)
2.插入mongoDB sku唯一(修改不需要动)
3.推送(就是插入redis list update_list_sku)
*/
func (S *LySaveService) skuCacheSave(isAdd bool,skuId string,lySkuEntity saveModel.LySkuEntity,lySaveRequest saveModel.LySaveRequest)error{
*/
func (S *LySaveService) skuCacheSave(isAdd bool, skuId string, lySkuEntity saveModel.LySkuEntity, lySaveRequest saveModel.LySaveRequest) error {
//插入redis,redis修改和新增代码量有点大,单独封装一个函数
err:=S.saveRedisSkuInfo(isAdd,skuId,lySkuEntity,lySaveRequest)
if(err!=nil){
return e.NewApiError("插入redis失败"+err.Error())
err := S.saveRedisSkuInfo(isAdd, skuId, lySkuEntity, lySaveRequest)
if err != nil {
return e.NewApiError("插入redis失败" + err.Error())
}
if(isAdd){
if isAdd {
//插入到mongo
skuMongo:=lySkuEntity.ToMongoSku()
err=skuCache.MongoInsertOnlySkuInfo(skuMongo)
if(err!=nil){
return e.NewApiError("插入redis失败"+err.Error())
skuMongo := lySkuEntity.ToMongoSku()
err = skuCache.MongoInsertOnlySkuInfo(skuMongo)
if err != nil {
return e.NewApiError("插入redis失败" + err.Error())
}
}
//实时推送(插入到 redis list update_list_sku )
err=skuCache.RedisPushEsList(skuId)
if(err!=nil){
return e.NewApiError("实时推送失败"+err.Error())
err = skuCache.RedisPushEsList(skuId)
if err != nil {
return e.NewApiError("实时推送失败" + err.Error())
}
return nil
}
......@@ -298,58 +300,59 @@ func (S *LySaveService) skuCacheSave(isAdd bool,skuId string,lySkuEntity saveMod
2.修改
读取之前(老的)的redis数据,跟新的redisSku合并
合并规则:需要修改的,覆盖之前的,不需要修改的保持原样
*/
func (S *LySaveService) saveRedisSkuInfo(isAdd bool,skuId string,lySkuEntity saveModel.LySkuEntity,lySaveRequest saveModel.LySaveRequest) error {
redisSkuInfo:=lySkuEntity.ToRedisSku()//组装需要更新的redisSku数据
redisSkuInfo.GoodsImages=lySaveRequest.GoodsImages
redisSkuInfo.Canal=lySaveRequest.Canal
redisSkuInfo.UpdateTime=int(time.Now().Unix())
redisSkuInfo.LadderPrice=lySaveRequest.LadderPrice//LadderPrice 如果已经是字符串,json处理会有斜划线,所以再赋值一次
if(isAdd){
oldByte,err:=json.Marshal(redisSkuInfo)
if(err!=nil){
*/
func (S *LySaveService) saveRedisSkuInfo(isAdd bool, skuId string, lySkuEntity saveModel.LySkuEntity, lySaveRequest saveModel.LySaveRequest) error {
redisSkuInfo := lySkuEntity.ToRedisSku() //组装需要更新的redisSku数据
redisSkuInfo.GoodsImages = lySaveRequest.GoodsImages
redisSkuInfo.Canal = lySaveRequest.Canal
redisSkuInfo.UpdateTime = int(time.Now().Unix())
redisSkuInfo.LadderPrice = lySaveRequest.LadderPrice //LadderPrice 如果已经是字符串,json处理会有斜划线,所以再赋值一次
if isAdd {
oldByte, err := json.Marshal(redisSkuInfo)
if err != nil {
return nil
}
return skuCache.RedisInsertSkuInfo(skuId,string(oldByte))
}else{
return skuCache.RedisInsertSkuInfo(skuId, string(oldByte))
} else {
//将老的redis的数据转成map
var oldSkuInfoMap map[string]interface{}
oldSkuInfoStr,err:=skuCache.RedisGetSkuInfo(skuId)//获取老的sku数据
json.Unmarshal([]byte(oldSkuInfoStr),&oldSkuInfoMap)
if(err!=nil){
oldSkuInfoStr, err := skuCache.RedisGetSkuInfo(skuId) //获取老的sku数据
json.Unmarshal([]byte(oldSkuInfoStr), &oldSkuInfoMap)
if err != nil {
return nil
}
//is_expire 给清理掉
if _, ok := oldSkuInfoMap["is_expire"];ok{
delete(oldSkuInfoMap,"is_expire")
if _, ok := oldSkuInfoMap["is_expire"]; ok {
delete(oldSkuInfoMap, "is_expire")
}
//合并,得到新的map
err,newMap:=S.structMerageMap(redisSkuInfo,oldSkuInfoMap)
if(err!=nil){
return e.NewApiError("结构和map合并失败"+err.Error())
err, newMap := S.structMerageMap(redisSkuInfo, oldSkuInfoMap)
if err != nil {
return e.NewApiError("结构和map合并失败" + err.Error())
}
//转化成json字符串
newMapbytes,err:=json.Marshal(newMap)
if(err!=nil){
newMapbytes, err := json.Marshal(newMap)
if err != nil {
return err
}
//插入redisSku
err=skuCache.RedisInsertSkuInfo(skuId,string(newMapbytes))
if(err!=nil){
err = skuCache.RedisInsertSkuInfo(skuId, string(newMapbytes))
if err != nil {
return nil
}
}
return nil
}
/**
struct 跟map Map合并,返回一个新的map(后续可以整理成公共函数)
*/
func (S *LySaveService) structMerageMap(redisSkuInfo model.SkuRedisInfo,oldSkuInfoMap map[string]interface{})(error,map[string]interface{}) {
func (S *LySaveService) structMerageMap(redisSkuInfo model.SkuRedisInfo, oldSkuInfoMap map[string]interface{}) (error, map[string]interface{}) {
//将新的redisSku数据struct 和 老的redis的数据map 合并成map并转换成json返回
GetValue:= func(fieldValue reflect.Value) interface{}{
GetValue := func(fieldValue reflect.Value) interface{} {
switch fieldValue.Kind() {
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int, reflect.Int64:
return fieldValue.Int()
......@@ -368,63 +371,63 @@ func (S *LySaveService) structMerageMap(redisSkuInfo model.SkuRedisInfo,oldSkuI
}
//组装需要更新的redisSku数据 struct
var newMap =make(map[string]interface{})
v:=reflect.ValueOf(redisSkuInfo)
t:=reflect.TypeOf(redisSkuInfo)
for i:=0;i<v.NumField();i++ {
name:=t.Field(i).Tag.Get("json")
fieldValue:=v.Field(i)
var newMap = make(map[string]interface{})
v := reflect.ValueOf(redisSkuInfo)
t := reflect.TypeOf(redisSkuInfo)
for i := 0; i < v.NumField(); i++ {
name := t.Field(i).Tag.Get("json")
fieldValue := v.Field(i)
//name:=v.Type().Name()
_, ok := oldSkuInfoMap[name];
_, ok := oldSkuInfoMap[name]
if(v.Field(i).IsZero() && ok){// struct 有些字段为0值,还是要用老的redis的数据
newMap[name]=oldSkuInfoMap[name]
}else{
if(name=="ladder_price"){
newMap[name]=redisSkuInfo.LadderPrice //ladder_price 单独处理
}else{
mapValue:=GetValue(fieldValue)
newMap[name]=mapValue
if v.Field(i).IsZero() && ok { // struct 有些字段为0值,还是要用老的redis的数据
newMap[name] = oldSkuInfoMap[name]
} else {
if name == "ladder_price" {
newMap[name] = redisSkuInfo.LadderPrice //ladder_price 单独处理
} else {
mapValue := GetValue(fieldValue)
newMap[name] = mapValue
}
}
delete(oldSkuInfoMap,name)//删除老的数据已经合并的字段
delete(oldSkuInfoMap, name) //删除老的数据已经合并的字段
}
//将老数据独有的字段,放进newMap
if(len(oldSkuInfoMap)>0){
for oldk,oldv:=range oldSkuInfoMap{
newMap[oldk]=oldv
if len(oldSkuInfoMap) > 0 {
for oldk, oldv := range oldSkuInfoMap {
newMap[oldk] = oldv
}
}
return nil,newMap
return nil, newMap
}
/**
修改
先写的SkuSave ,SkuEdit 基本是调用 SkuSave 之前写好的方法
*/
func (S *LySaveService)SkuEdit(lyEditRequest saveModel.LyEditRequest) (error,string){
*/
func (S *LySaveService) SkuEdit(lyEditRequest saveModel.LyEditRequest) (error, string) {
lySkuEntity:=lyEditRequest.ToLySkuEntity()//sku实体
lySkuEntity.GoodsId=lyEditRequest.GoodsId
lySkuEntity := lyEditRequest.ToLySkuEntity() //sku实体
lySkuEntity.GoodsId = lyEditRequest.GoodsId
lySaveRequest:=lyEditRequest.ToLySaveRequest()//转换成lySaveRequest 因为公用 savesku封装的的方法,公用方法需要传lySaveRequest(后续参数改成接口)
lySaveRequest := lyEditRequest.ToLySaveRequest() //转换成lySaveRequest 因为公用 savesku封装的的方法,公用方法需要传lySaveRequest(后续参数改成接口)
//阶梯价格处理
err:=S.ladderPriceHandle(lySaveRequest.LadderPrice,&lySkuEntity)
if(err!=nil){
return e.NewApiError("SkuEdit 阶梯价格处理失败"+err.Error()),""
err := S.ladderPriceHandle(lySaveRequest.LadderPrice, &lySkuEntity)
if err != nil {
return e.NewApiError("SkuEdit 阶梯价格处理失败" + err.Error()), ""
}
oldRedisStr,err:=skuCache.RedisGetSkuInfo(lyEditRequest.GoodsId)
if(err!=nil){
return e.NewApiError("修改sku:查询redis sku失败"+err.Error()),""
oldRedisStr, err := skuCache.RedisGetSkuInfo(lyEditRequest.GoodsId)
if err != nil {
return e.NewApiError("修改sku:查询redis sku失败" + err.Error()), ""
}
if(oldRedisStr==""){//判断是否存在
return e.NewApiError("sku不存在,skuID:"+lyEditRequest.GoodsId+err.Error()),""
if oldRedisStr == "" { //判断是否存在
return e.NewApiError("sku不存在,skuID:" + lyEditRequest.GoodsId + err.Error()), ""
}
err=S.update(lySkuEntity,lySaveRequest)
if(err!=nil){
return e.NewApiError("SkuEdit 修改sku失败"+err.Error()),""
err = S.update(lySkuEntity, lySaveRequest)
if err != nil {
return e.NewApiError("SkuEdit 修改sku失败" + err.Error()), ""
}
return nil,lySkuEntity.GoodsId
return nil, lySkuEntity.GoodsId
}
......@@ -163,27 +163,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
activityType := gjson.Get(activityInfo, "activity_type").Int()
if suffix == "" && blacklistType != 0 && hasActivity && activityId != "" && activityType == 2 &&
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
if allowNotLogin == 0 {
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
}
break
......@@ -233,7 +205,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
allCoupon = 1
}
sku.AllowCoupon = int(allCoupon)
sku.ActivityEndTime = endTime
return sku
}
......@@ -253,18 +224,3 @@ func getMouserActivityPrice(sku model.LySku) model.LySku {
}
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
import (
"fmt"
"github.com/syyongx/php2go"
"go_sku_server/service"
)
func main() {
var a = []string{"3923"}
var b = 3923
fmt.Println(php2go.InArray(b,a))
ly := service.LyService{}
ly.GetActivityData()
}
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