Commit 54e5adb5 by 杨树贤

特殊供应商原币种逻辑

parent ad99e605
......@@ -5,7 +5,6 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort"
"strings"
"sync"
"github.com/gin-gonic/gin"
......@@ -65,16 +64,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.Packing = gjson.Get(packing, "pack").String()
}
sku = ls.GetGoodsImages(sku, spu)
//pdf
pdf := gjson.Get(spu, "pdf").String()
if pdf != "" {
pdf = strings.Replace(pdf, "http://img.ichunt.com", "https://img.ichunt.com", 1)
//还要针对如果是自己的上传服务的pdf文件,还要补上类型用于预览
if (strings.Contains(pdf, "files.ichunt.net") || strings.Contains(pdf, "file.liexindev.net")) && !strings.Contains(pdf, "fileType=pdf") {
pdf += "?fileType=pdf"
}
sku.Pdf = pdf
}
sku = ls.GetPdf(sku, spu)
//获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
......
......@@ -2,7 +2,6 @@ package service
import (
"encoding/json"
"fmt"
"go_sku_server/model"
c "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
......@@ -40,6 +39,20 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
return sku
}
// 获取图片信息
func (ls *LyService) GetPdf(sku model.LySku, spu string) model.LySku {
pdf := gjson.Get(spu, "pdf").String()
if pdf != "" {
pdf = strings.Replace(pdf, "http://img.ichunt.com", "https://img.ichunt.com", 1)
//还要针对如果是自己的上传服务的pdf文件,还要补上类型用于预览
if (strings.Contains(pdf, "files.ichunt.net") || strings.Contains(pdf, "file.liexindev.net")) && !strings.Contains(pdf, "fileType=pdf") {
pdf += "?fileType=pdf"
}
sku.Pdf = pdf
}
return sku
}
// 获取分类信息
func (ls *LyService) GetGoodsClass(sku model.LySku, spu string) model.LySku {
//仅提供价格和库存
......@@ -198,13 +211,10 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if len(ladderPrice) > 0 {
if ladderPrice[0].PriceCostUs == 0 && ladderPrice[0].PriceCostCn == 0 {
var priceService PriceService
generatedLadderPrice, priceRatio := priceService.GenerateLadderPrice(sku)
generatedLadderPrice, priceRatio := priceService.GenerateCostLadderPrice(sku)
ladderPrice = generatedLadderPrice
//sku.Original = ladderPrice
sku.PriceRatio = priceRatio
sku.PriceRatioSort = -1
} else {
fmt.Println("不走成本价生成")
}
}
data = make([]model.LadderPrice, len(ladderPrice))
......@@ -340,7 +350,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//这个就是最终要获取到的价格系数
var priceRatioList []model.PriceRatio
//是否找到系数的标志位
findedRatio := false
ratioFinded := false
//如果只有默认系数,那么就去找默认系数
if isDefaultPriceRatio {
} else {
......@@ -377,7 +387,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
goodsNameList := strings.Split(goodsNames, "@€@")
//找到有对应的商品名称,那么优先级肯定是最高的了
if php2go.InArray(sku.GoodsName, goodsNameList) {
findedRatio = true
ratioFinded = true
break
}
}
......@@ -390,7 +400,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
findedRatio = true
ratioFinded = true
break
}
}
......@@ -413,27 +423,27 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.Contains(sku.Eccn, eccn) {
findedRatio = true
ratioFinded = true
break outerLoop
}
}
if hasPrefix && !hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasSuffix(sku.Eccn, eccn) {
findedRatio = true
ratioFinded = true
break outerLoop
}
}
if !hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasPrefix(sku.Eccn, eccn) {
findedRatio = true
ratioFinded = true
break outerLoop
}
}
} else {
if sku.Eccn == eccn {
findedRatio = true
ratioFinded = true
break outerLoop
}
}
......@@ -443,12 +453,12 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if hasSpecialCheck {
continue
}
findedRatio = true
ratioFinded = true
break
}
}
//找不到特定的系数,那就去找全局的
if !findedRatio {
if !ratioFinded {
priceRatioCache, _ = redis.String(redisCon.Do("GET", "magic_cube_price_rule_channel_default"))
priceRatioArr := gjson.Get(priceRatioCache, "ladder_price").Array()
priceRatioList = nil
......@@ -515,7 +525,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax := 1.13
for key, price := range sku.LadderPrice {
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
......
......@@ -14,32 +14,27 @@ type PriceService struct {
}
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
// 所以要全部先转成正确的美金价才能显示
func (ls *LyService) TransformSpecialSupplierPrice(supplierId int64, priceUs float64, usRatio float64) float64 {
switch supplierId {
case 6:
customRate := 7.85 //港币转美金
priceUs = c.MyRound(c.DivFloat(priceUs, customRate), 4)
break
case 21:
customRate := usRatio //人民币转美金
priceUs = c.MyRound(c.DivFloat(priceUs, customRate), 4)
priceUs = c.MyRound(c.DivFloat(priceUs, 1.13), 4)
break
case 1676:
customRate := 0.93 //欧元转美金
priceUs = c.MyRound(c.DivFloat(priceUs, customRate), 4)
break
// case 1673:
// customRate := 0.93 //欧元转美金
// priceUs = c.MyRound(c.DivFloat(priceUs, customRate), 4)
// break
//去redis获取价格
redisCon := gredis.Conn("default_r")
defer func() {
redisCon.Close()
}()
currency, _ := redis.Int(redisCon.Do("HGET", "magic_cube_supplier_currency", supplierId))
if currency > 0 {
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio, _ := redis.Float64(redisCon.Do("HGET", "erp_rate", currency))
//人民币汇率转美金汇率
usRatio = c.MyRound(c.DivFloat(rmbRatio, usRatio), 2)
priceUs = c.MyRound(c.DivFloat(priceUs, usRatio), 4)
}
return priceUs
}
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPrice []model.LadderPrice, showPriceRatio []model.PriceRatio) {
func (ps *PriceService) GenerateCostLadderPrice(sku model.LySku) (generatedLadderPrice []model.LadderPrice, showPriceRatio []model.PriceRatio) {
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases := sku.LadderPrice[0].Purchases
isCostPrice := bool(firstLadderPurchases == 0)
......
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