Commit a06f158d by hcy001

专卖没有过期

parent cbf0dbb5
Showing with 216 additions and 216 deletions
package service package service
import ( import (
"fmt" "fmt"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/service/sorter" "go_sku_server/service/sorter"
"sort" "sort"
"sync" "sync"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv" "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"
) )
type LyService struct { type LyService struct {
} }
type Power struct { type Power struct {
UserId string `json:"user_id"` UserId string `json:"user_id"`
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Email string `json:"email"` Email string `json:"email"`
Member string `json:"member"` Member string `json:"member"`
VerifyBlacklist string `json:"verify_blacklist"` VerifyBlacklist string `json:"verify_blacklist"`
Invoice string `json:"invoice"` Invoice string `json:"invoice"`
SpecialInvoice string `json:"special_invoice"` SpecialInvoice string `json:"special_invoice"`
} }
/* /*
联营数据详情 联营数据详情
*/ */
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() {
redisConn.Close() redisConn.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
showAttr := ctx.Request.FormValue("show_attr") showAttr := ctx.Request.FormValue("show_attr")
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
var spuService SpuService var spuService SpuService
spuList := spuService.getSpuList(skuArr) spuList := spuService.getSpuList(skuArr)
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
if skuStr == "" { if skuStr == "" {
GoodsRes.Store(goodsId, false) GoodsRes.Store(goodsId, false)
continue continue
} }
//初始化有序map,拼接data 数据 //初始化有序map,拼接data 数据
sku := model.InitSkuData(skuStr) sku := model.InitSkuData(skuStr)
sku.GoodsId = goodsId sku.GoodsId = goodsId
spu := spuList[sku.SpuId] spu := spuList[sku.SpuId]
//读取包装字段的缓存 //读取包装字段的缓存
if sku.SupplierId == 7 { if sku.SupplierId == 7 {
//sku_raw_map哪里写入(成意写的) //sku_raw_map哪里写入(成意写的)
packing, _ := redis.String(redisConn.Do("HGET", "sku_raw_map", goodsId)) packing, _ := redis.String(redisConn.Do("HGET", "sku_raw_map", goodsId))
sku.Packing = gjson.Get(packing, "pack").String() sku.Packing = gjson.Get(packing, "pack").String()
} }
sku = ls.GetGoodsImages(sku, spu) sku = ls.GetGoodsImages(sku, spu)
//pdf //pdf
pdf := gjson.Get(spu, "pdf").String() pdf := gjson.Get(spu, "pdf").String()
spuLargeImage := gjson.Get(spu, "images_l").String() spuLargeImage := gjson.Get(spu, "images_l").String()
if pdf == "" || (php2go.Strlen(spuLargeImage) < 5) { if pdf == "" || (php2go.Strlen(spuLargeImage) < 5) {
sku.Pdf = "" sku.Pdf = ""
} else { } else {
sku.Pdf = pdf sku.Pdf = pdf
} }
//处理分类 //处理分类
//fast的参数含义,为了节省开销性能的参数,传1就不会去分类这些参数 //fast的参数含义,为了节省开销性能的参数,传1就不会去分类这些参数
if fast != "1" { if fast != "1" {
sku = ls.GetGoodsClass(sku, spu) sku = ls.GetGoodsClass(sku, spu)
} }
//获取商品名称 //获取商品名称
if sku.GoodsName == "" { if sku.GoodsName == "" {
sku.GoodsName = gjson.Get(spu, "spu_name").String() sku.GoodsName = gjson.Get(spu, "spu_name").String()
} }
//获取品牌名称 //获取品牌名称
brandId := gjson.Get(spu, "brand_id").Int() brandId := gjson.Get(spu, "brand_id").Int()
brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId)) brandName, _ := redis.String(redisConn.Do("HGET", "brand", brandId))
sku.BrandName = brandName sku.BrandName = brandName
fmt.Println(showAttr) fmt.Println(showAttr)
//获取税务信息 //获取税务信息
if fast != "1" { //仅提供价格和库存 if fast != "1" { //仅提供价格和库存
if sku.GoodsName != "" && brandId != 0 { if sku.GoodsName != "" && brandId != 0 {
sku.ErpTax = ls.GetErpTax(sku.GoodsName, brandName) sku.ErpTax = ls.GetErpTax(sku.GoodsName, brandName)
} }
sku.SupplierName = ls.GetPoolSupplierName(sku.SupplierId) sku.SupplierName = ls.GetPoolSupplierName(sku.SupplierId)
if showAttr == "1" { if showAttr == "1" {
//获取属性 //获取属性
sku.Attrs = ls.GetSpuAttr(sku.SpuId) sku.Attrs = ls.GetSpuAttr(sku.SpuId)
} }
if sku.Attrs == nil { if sku.Attrs == nil {
sku.Attrs = []interface{}{} sku.Attrs = []interface{}{}
} }
} }
//获取供应链标准品牌 //获取供应链标准品牌
//什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去 //什么是供应链的标准品牌 供应链那边报关的时候要求他们的标准品牌,所以要吧自己的品牌映射上去
//继来那边对接的标准品牌(下单的时候) //继来那边对接的标准品牌(下单的时候)
sku.ScmBrand = ls.GetScmBrand(brandId) sku.ScmBrand = ls.GetScmBrand(brandId)
//获取新版的标准品牌 //获取新版的标准品牌
sku.StandardBrand = ls.GetStandardBrand(brandId) sku.StandardBrand = ls.GetStandardBrand(brandId)
//处理过期 //处理过期,todo 2022.7.13 专卖没有过期
if gjson.Get(skuStr, "is_expire").Int() != 0 { if sku.SupplierId != 17 && gjson.Get(skuStr, "is_expire").Int() != 0 {
sku.LadderPrice = nil sku.LadderPrice = nil
} }
//处理活动 //处理活动
sku.AcType = 0 sku.AcType = 0
sku.AllowCoupon = 1 sku.AllowCoupon = 1
sku.BrandId = brandId sku.BrandId = brandId
sku = ls.GetActivity(sku) sku = ls.GetActivity(sku)
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
//排序 //排序
sort.Sort(sorter.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 {
sku.Moq = purchases sku.Moq = purchases
} }
} }
//获取系数 //获取系数
sku = ls.GetCoefficient(sku) sku = ls.GetCoefficient(sku)
//仅提供价格和库存 //仅提供价格和库存
if fast != "1" { if fast != "1" {
if sku.SupplierId != 0 { if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal) sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
} }
//还要处理货期 //还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal) delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
if delivery["cn_delivery"] != "" { if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"] sku.CnDeliveryTime = delivery["cn_delivery"]
} }
if delivery["hk_delivery"] != "" { if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"] sku.HkDeliveryTime = delivery["hk_delivery"]
} }
} }
//处理是否可以购买 //处理是否可以购买
if sku.Mpq == 0 { if sku.Mpq == 0 {
sku.Mpq = 1 sku.Mpq = 1
} }
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice sku.LadderPriceResult = sku.LadderPrice
} else { } else {
sku.LadderPriceResult = []int{} sku.LadderPriceResult = []int{}
} }
//这边有个临时逻辑,如果供应商id是TI的,就库存为0 //这边有个临时逻辑,如果供应商id是TI的,就库存为0
// if sku.SupplierId == 1679 { // if sku.SupplierId == 1679 {
// sku.Stock = 0 // sku.Stock = 0
// } // }
//判断是否可以购买 //判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku) sku.IsBuy = ls.GetIsBuy(sku)
//过期修改库存为0 //过期修改库存为0
if sku.IsExpire == 1 && sku.SupplierId != 17 { if sku.IsExpire == 1 && sku.SupplierId != 17 {
sku.Stock = 0 sku.Stock = 0
} }
var TagService TagsService var TagService TagsService
sku.GoodsTag = TagService.GetTags(sku.GoodsId, 0) sku.GoodsTag = TagService.GetTags(sku.GoodsId, 0)
//用spuInfo补全信息 //用spuInfo补全信息
sku = ls.CombineSup(sku, spu) sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面 //最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku) GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A //(*goodsRes)[goodsId] = A
} }
ch <- GoodsRes ch <- GoodsRes
} }
//获取活动 //获取活动
func (ls *LyService) GetActivity(sku model.LySku) model.LySku { func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
//去判断是否有活动(促销打折活动和满赠活动) //去判断是否有活动(促销打折活动和满赠活动)
checkData := model.ActivityCheckData{ checkData := model.ActivityCheckData{
SupplierId: int(sku.SupplierId), SupplierId: int(sku.SupplierId),
BrandId: int(sku.BrandId), BrandId: int(sku.BrandId),
GoodsId: sku.GoodsId, GoodsId: sku.GoodsId,
Canal: sku.Canal, Canal: sku.Canal,
ClassId: sku.ClassID2, ClassId: sku.ClassID2,
} }
var activityService ActivityService var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData) priceActivity, giftActivity := activityService.GetActivityData(checkData)
if priceActivity.HasActivity { if priceActivity.HasActivity {
sku.AcType = 10 sku.AcType = 10
sku.Ratio = priceActivity.Ratio sku.Ratio = priceActivity.Ratio
sku.ActivityInfo = priceActivity sku.ActivityInfo = priceActivity
} }
if giftActivity.HasActivity { if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity) sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity sku.GiftActivity = giftActivity
} }
//获取是否能使用优惠券 //获取是否能使用优惠券
if giftActivity.AllowCoupon == 2 || priceActivity.AllowCoupon == 2 { if giftActivity.AllowCoupon == 2 || priceActivity.AllowCoupon == 2 {
sku.AllowCoupon = 2 sku.AllowCoupon = 2
} }
return sku return sku
} }
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