Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
54e5adb5
authored
Aug 15, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
特殊供应商原币种逻辑
parent
ad99e605
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
46 deletions
service/service_ly.go
service/service_ly_common.go
service/service_price.go
service/service_ly.go
View file @
54e5adb5
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"go_sku_server/service/sorter"
"sort"
"sort"
"strings"
"sync"
"sync"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -65,16 +64,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -65,16 +64,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
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
sku
=
ls
.
GetPdf
(
sku
,
spu
)
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
}
//获取商品名称
//获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
...
...
service/service_ly_common.go
View file @
54e5adb5
...
@@ -2,7 +2,6 @@ package service
...
@@ -2,7 +2,6 @@ package service
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"go_sku_server/model"
"go_sku_server/model"
c
"go_sku_server/pkg/common"
c
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
...
@@ -40,6 +39,20 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
...
@@ -40,6 +39,20 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
return
sku
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
{
func
(
ls
*
LyService
)
GetGoodsClass
(
sku
model
.
LySku
,
spu
string
)
model
.
LySku
{
//仅提供价格和库存
//仅提供价格和库存
...
@@ -198,13 +211,10 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -198,13 +211,10 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
len
(
ladderPrice
)
>
0
{
if
len
(
ladderPrice
)
>
0
{
if
ladderPrice
[
0
]
.
PriceCostUs
==
0
&&
ladderPrice
[
0
]
.
PriceCostCn
==
0
{
if
ladderPrice
[
0
]
.
PriceCostUs
==
0
&&
ladderPrice
[
0
]
.
PriceCostCn
==
0
{
var
priceService
PriceService
var
priceService
PriceService
generatedLadderPrice
,
priceRatio
:=
priceService
.
GenerateLadderPrice
(
sku
)
generatedLadderPrice
,
priceRatio
:=
priceService
.
Generate
Cost
LadderPrice
(
sku
)
ladderPrice
=
generatedLadderPrice
ladderPrice
=
generatedLadderPrice
//sku.Original = ladderPrice
sku
.
PriceRatio
=
priceRatio
sku
.
PriceRatio
=
priceRatio
sku
.
PriceRatioSort
=
-
1
sku
.
PriceRatioSort
=
-
1
}
else
{
fmt
.
Println
(
"不走成本价生成"
)
}
}
}
}
data
=
make
([]
model
.
LadderPrice
,
len
(
ladderPrice
))
data
=
make
([]
model
.
LadderPrice
,
len
(
ladderPrice
))
...
@@ -340,7 +350,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -340,7 +350,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//这个就是最终要获取到的价格系数
//这个就是最终要获取到的价格系数
var
priceRatioList
[]
model
.
PriceRatio
var
priceRatioList
[]
model
.
PriceRatio
//是否找到系数的标志位
//是否找到系数的标志位
findedRatio
:=
false
ratioFinded
:=
false
//如果只有默认系数,那么就去找默认系数
//如果只有默认系数,那么就去找默认系数
if
isDefaultPriceRatio
{
if
isDefaultPriceRatio
{
}
else
{
}
else
{
...
@@ -377,7 +387,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -377,7 +387,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
goodsNameList
:=
strings
.
Split
(
goodsNames
,
"@€@"
)
goodsNameList
:=
strings
.
Split
(
goodsNames
,
"@€@"
)
//找到有对应的商品名称,那么优先级肯定是最高的了
//找到有对应的商品名称,那么优先级肯定是最高的了
if
php2go
.
InArray
(
sku
.
GoodsName
,
goodsNameList
)
{
if
php2go
.
InArray
(
sku
.
GoodsName
,
goodsNameList
)
{
findedRatio
=
true
ratioFinded
=
true
break
break
}
}
}
}
...
@@ -390,7 +400,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -390,7 +400,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
//找到有对应的品牌,那么优先级肯定是最高的了
//找到有对应的品牌,那么优先级肯定是最高的了
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
findedRatio
=
true
ratioFinded
=
true
break
break
}
}
}
}
...
@@ -413,27 +423,27 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -413,27 +423,27 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
hasPrefix
&&
hasSuffix
{
if
hasPrefix
&&
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
Contains
(
sku
.
Eccn
,
eccn
)
{
if
strings
.
Contains
(
sku
.
Eccn
,
eccn
)
{
findedRatio
=
true
ratioFinded
=
true
break
outerLoop
break
outerLoop
}
}
}
}
if
hasPrefix
&&
!
hasSuffix
{
if
hasPrefix
&&
!
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
HasSuffix
(
sku
.
Eccn
,
eccn
)
{
if
strings
.
HasSuffix
(
sku
.
Eccn
,
eccn
)
{
findedRatio
=
true
ratioFinded
=
true
break
outerLoop
break
outerLoop
}
}
}
}
if
!
hasPrefix
&&
hasSuffix
{
if
!
hasPrefix
&&
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
HasPrefix
(
sku
.
Eccn
,
eccn
)
{
if
strings
.
HasPrefix
(
sku
.
Eccn
,
eccn
)
{
findedRatio
=
true
ratioFinded
=
true
break
outerLoop
break
outerLoop
}
}
}
}
}
else
{
}
else
{
if
sku
.
Eccn
==
eccn
{
if
sku
.
Eccn
==
eccn
{
findedRatio
=
true
ratioFinded
=
true
break
outerLoop
break
outerLoop
}
}
}
}
...
@@ -443,12 +453,12 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -443,12 +453,12 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
hasSpecialCheck
{
if
hasSpecialCheck
{
continue
continue
}
}
findedRatio
=
true
ratioFinded
=
true
break
break
}
}
}
}
//找不到特定的系数,那就去找全局的
//找不到特定的系数,那就去找全局的
if
!
findedRatio
{
if
!
ratioFinded
{
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_channel_default"
))
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_channel_default"
))
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
Array
()
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
Array
()
priceRatioList
=
nil
priceRatioList
=
nil
...
@@ -515,7 +525,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
...
@@ -515,7 +525,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//下面是计算价格
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax
:=
1.13
tax
:=
1.13
for
key
,
price
:=
range
sku
.
LadderPrice
{
for
key
,
price
:=
range
sku
.
LadderPrice
{
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
...
...
service/service_price.go
View file @
54e5adb5
...
@@ -14,32 +14,27 @@ type PriceService struct {
...
@@ -14,32 +14,27 @@ type PriceService struct {
}
}
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示
,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
// 所以要全部先转成正确的美金价才能显示
func
(
ls
*
LyService
)
TransformSpecialSupplierPrice
(
supplierId
int64
,
priceUs
float64
,
usRatio
float64
)
float64
{
func
(
ls
*
LyService
)
TransformSpecialSupplierPrice
(
supplierId
int64
,
priceUs
float64
,
usRatio
float64
)
float64
{
switch
supplierId
{
//去redis获取价格
case
6
:
redisCon
:=
gredis
.
Conn
(
"default_r"
)
customRate
:=
7.85
//港币转美金
defer
func
()
{
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
customRate
),
4
)
redisCon
.
Close
()
break
}()
case
21
:
currency
,
_
:=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_supplier_currency"
,
supplierId
))
customRate
:=
usRatio
//人民币转美金
if
currency
>
0
{
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
customRate
),
4
)
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
1.13
),
4
)
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
break
rmbRatio
,
_
:=
redis
.
Float64
(
redisCon
.
Do
(
"HGET"
,
"erp_rate"
,
currency
))
case
1676
:
//人民币汇率转美金汇率
customRate
:=
0.93
//欧元转美金
usRatio
=
c
.
MyRound
(
c
.
DivFloat
(
rmbRatio
,
usRatio
),
2
)
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
customRate
),
4
)
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
usRatio
),
4
)
break
// case 1673:
// customRate := 0.93 //欧元转美金
// priceUs = c.MyRound(c.DivFloat(priceUs, customRate), 4)
// break
}
}
return
priceUs
return
priceUs
}
}
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
(
generatedLadderPrice
[]
model
.
LadderPrice
,
showPriceRatio
[]
model
.
PriceRatio
)
{
func
(
ps
*
PriceService
)
Generate
Cost
LadderPrice
(
sku
model
.
LySku
)
(
generatedLadderPrice
[]
model
.
LadderPrice
,
showPriceRatio
[]
model
.
PriceRatio
)
{
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases
:=
sku
.
LadderPrice
[
0
]
.
Purchases
firstLadderPurchases
:=
sku
.
LadderPrice
[
0
]
.
Purchases
isCostPrice
:=
bool
(
firstLadderPurchases
==
0
)
isCostPrice
:=
bool
(
firstLadderPurchases
==
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment