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
dcf5b8be
authored
Aug 16, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
价格体系继续修改
parent
c8399857
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
80 deletions
service/service_ly_common.go
service/service_price.go
service/service_ly_common.go
View file @
dcf5b8be
...
...
@@ -2,18 +2,17 @@ package service
import
(
"encoding/json"
"github.com/gomodule/redigo/redis"
_
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
c
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
_
"go_sku_server/pkg/mongo"
"strings"
"github.com/gomodule/redigo/redis"
_
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
_
"gopkg.in/mgo.v2/bson"
"strings"
)
// 获取图片信息
...
...
@@ -37,7 +36,7 @@ func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
return
sku
}
// 获取
图片
信息
// 获取
PDF
信息
func
(
ls
*
LyService
)
GetPdf
(
sku
model
.
LySku
,
spu
string
)
model
.
LySku
{
pdf
:=
gjson
.
Get
(
spu
,
"pdf"
)
.
String
()
if
pdf
!=
""
{
...
...
@@ -192,7 +191,73 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
}
}
// 获取系数和总体价格
// 获取供应商货期
func
(
ls
*
LyService
)
GetDelivery
(
supplierId
int64
,
canal
string
)
(
delivery
map
[
string
]
string
)
{
delivery
=
make
(
map
[
string
]
string
)
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
if
canal
!=
""
{
supplierRatio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"supp_ratio"
,
canal
))
if
supplierRatio
!=
""
{
cnDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
usDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
//为了兼容供应商修改的问题
if
cnDeliveryTime
!=
"周"
&&
cnDeliveryTime
!=
"天"
{
delivery
[
"cn_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
}
else
{
delivery
[
"cn_delivery"
]
=
""
}
if
usDeliveryTime
!=
"周"
&&
usDeliveryTime
!=
"天"
{
delivery
[
"hk_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
}
else
{
delivery
[
"hk_delivery"
]
=
""
}
}
return
}
info
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"SUPPLIER_REDIS_INFO_"
,
supplierId
))
cnDelivery
:=
gjson
.
Get
(
info
,
"cn_delivery"
)
.
String
()
hkDelivery
:=
gjson
.
Get
(
info
,
"hk_delivery"
)
.
String
()
if
cnDelivery
!=
""
||
hkDelivery
!=
""
{
delivery
[
"cn_delivery"
]
=
cnDelivery
delivery
[
"hk_delivery"
]
=
hkDelivery
return
}
return
}
// 判断能否购买
func
(
ls
*
LyService
)
GetIsBuy
(
sku
model
.
LySku
)
(
isBuy
int
)
{
if
sku
.
GoodsStatus
!=
1
{
return
}
if
sku
.
Moq
>
sku
.
Stock
{
return
}
if
len
(
sku
.
LadderPrice
)
==
0
{
return
}
if
sku
.
Stock
==
0
{
return
}
return
1
}
// 合并spu的信息
func
(
ls
*
LyService
)
CombineSup
(
sku
model
.
LySku
,
spuStr
string
)
model
.
LySku
{
sku
.
UpdateTime
=
gjson
.
Get
(
spuStr
,
"update_time"
)
.
Int
()
sku
.
ClassID1
=
int
(
gjson
.
Get
(
spuStr
,
"class_id1"
)
.
Int
())
sku
.
ClassID2
=
int
(
gjson
.
Get
(
spuStr
,
"class_id2"
)
.
Int
())
sku
.
SpuName
=
gjson
.
Get
(
spuStr
,
"spu_name"
)
.
String
()
sku
.
SpuBrief
=
gjson
.
Get
(
spuStr
,
"spu_brief"
)
.
String
()
sku
.
SpuDetail
=
gjson
.
Get
(
spuStr
,
"spu_detail"
)
.
String
()
sku
.
Status
=
int
(
gjson
.
Get
(
spuStr
,
"status"
)
.
Int
())
sku
.
Encap
=
gjson
.
Get
(
spuStr
,
"encap"
)
.
String
()
return
sku
}
// 获取系数和总体价格,生成和处理价格的方法,很重要
func
(
ls
*
LyService
)
GetCoefficientAndPrice
(
sku
model
.
LySku
)
model
.
LySku
{
if
len
(
sku
.
LadderPrice
)
==
0
{
//sku.Original = nil
...
...
@@ -213,17 +278,25 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
ladderPrice
=
sku
.
LadderPrice
}
}
//获取折扣系数
sku
=
priceService
.
GetDiscountRatio
(
sku
)
data
=
make
([]
model
.
LadderPrice
,
len
(
ladderPrice
))
for
key
,
price
:=
range
ladderPrice
{
if
price
.
Purchases
==
0
{
continue
}
data
[
key
]
.
Purchases
=
price
.
Purchases
//下面的价格,还要乘于折扣系数
if
price
.
PriceUs
!=
0
{
data
[
key
]
.
PriceUs
=
c
.
MyRound
(
price
.
PriceUs
,
4
)
priceUs
:=
c
.
MyRound
(
price
.
PriceUs
,
4
)
priceUs
=
c
.
MyRound
(
c
.
MulFloat
(
price
.
PriceUs
,
sku
.
DiscountRatio
.
RatioUsd
),
4
)
data
[
key
]
.
PriceUs
=
priceUs
}
if
price
.
PriceCn
!=
0
{
data
[
key
]
.
PriceCn
=
c
.
MyRound
(
price
.
PriceCn
,
4
)
priceCn
:=
c
.
MyRound
(
price
.
PriceCn
,
4
)
priceCn
=
c
.
MyRound
(
c
.
MulFloat
(
price
.
PriceCn
,
sku
.
DiscountRatio
.
Ratio
),
4
)
data
[
key
]
.
PriceCn
=
priceCn
}
//专卖成本价
...
...
@@ -420,69 +493,3 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
}
return
sku
}
// 获取供应商货期
func
(
ls
*
LyService
)
GetDelivery
(
supplierId
int64
,
canal
string
)
(
delivery
map
[
string
]
string
)
{
delivery
=
make
(
map
[
string
]
string
)
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
if
canal
!=
""
{
supplierRatio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"supp_ratio"
,
canal
))
if
supplierRatio
!=
""
{
cnDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
usDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
//为了兼容供应商修改的问题
if
cnDeliveryTime
!=
"周"
&&
cnDeliveryTime
!=
"天"
{
delivery
[
"cn_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
}
else
{
delivery
[
"cn_delivery"
]
=
""
}
if
usDeliveryTime
!=
"周"
&&
usDeliveryTime
!=
"天"
{
delivery
[
"hk_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
}
else
{
delivery
[
"hk_delivery"
]
=
""
}
}
return
}
info
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"SUPPLIER_REDIS_INFO_"
,
supplierId
))
cnDelivery
:=
gjson
.
Get
(
info
,
"cn_delivery"
)
.
String
()
hkDelivery
:=
gjson
.
Get
(
info
,
"hk_delivery"
)
.
String
()
if
cnDelivery
!=
""
||
hkDelivery
!=
""
{
delivery
[
"cn_delivery"
]
=
cnDelivery
delivery
[
"hk_delivery"
]
=
hkDelivery
return
}
return
}
// 判断能否购买
func
(
ls
*
LyService
)
GetIsBuy
(
sku
model
.
LySku
)
(
isBuy
int
)
{
if
sku
.
GoodsStatus
!=
1
{
return
}
if
sku
.
Moq
>
sku
.
Stock
{
return
}
if
len
(
sku
.
LadderPrice
)
==
0
{
return
}
if
sku
.
Stock
==
0
{
return
}
return
1
}
// 合并spu的信息
func
(
ls
*
LyService
)
CombineSup
(
sku
model
.
LySku
,
spuStr
string
)
model
.
LySku
{
sku
.
UpdateTime
=
gjson
.
Get
(
spuStr
,
"update_time"
)
.
Int
()
sku
.
ClassID1
=
int
(
gjson
.
Get
(
spuStr
,
"class_id1"
)
.
Int
())
sku
.
ClassID2
=
int
(
gjson
.
Get
(
spuStr
,
"class_id2"
)
.
Int
())
sku
.
SpuName
=
gjson
.
Get
(
spuStr
,
"spu_name"
)
.
String
()
sku
.
SpuBrief
=
gjson
.
Get
(
spuStr
,
"spu_brief"
)
.
String
()
sku
.
SpuDetail
=
gjson
.
Get
(
spuStr
,
"spu_detail"
)
.
String
()
sku
.
Status
=
int
(
gjson
.
Get
(
spuStr
,
"status"
)
.
Int
())
sku
.
Encap
=
gjson
.
Get
(
spuStr
,
"encap"
)
.
String
()
return
sku
}
service/service_price.go
View file @
dcf5b8be
...
...
@@ -17,7 +17,7 @@ import (
type
PriceService
struct
{
}
//
GenerateLadderPrice
构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
model
.
LySku
{
//先去找到对应的价格系数
var
ratioDataKey
string
...
...
@@ -31,7 +31,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
defer
redisCon
.
Close
()
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio
:=
false
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_v2"
,
sku
.
SupplierId
))
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_v2"
,
sku
.
Canal
))
//判断是否是空
checkNullRation
:=
gjson
.
Get
(
priceRatioCache
,
ratioDataKey
)
.
String
()
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
...
...
@@ -154,13 +154,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
//找不到特定的系数,那就去找全局的
if
!
foundRatio
{
fmt
.
Println
(
"去找默认系数"
)
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_v2_default"
))
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
ratioDataKey
)
.
Array
()
priceRatioList
=
nil
for
_
,
value
:=
range
priceRatioArr
{
var
priceRatio
model
.
PriceRatio
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"ratio"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"ratio_usd"
)
.
Float
()
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"price"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"price_usd"
)
.
Float
()
priceRatio
.
Purchases
=
gjson
.
Get
(
value
.
String
(),
"purchases"
)
.
Int
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
priceRatioSort
=
-
1
...
...
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