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
9a078044
authored
Nov 25, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复bug
parent
1320a5e2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
42 deletions
model/coefficient.go
model/goods.go
model/ly_sku.go
pkg/gredis/redis.go
service/service_ly.go
service/service_ly_common.go
model/coefficient.go
View file @
9a078044
...
@@ -4,7 +4,7 @@ type Coefficient struct {
...
@@ -4,7 +4,7 @@ type Coefficient struct {
Cn
float64
`json:"cn"`
Cn
float64
`json:"cn"`
Hk
float64
`json:"hk"`
Hk
float64
`json:"hk"`
ExtraRatio
float64
`json:"extra_ratio"`
ExtraRatio
float64
`json:"extra_ratio"`
IsDefault
int64
`json:"
is_default
"`
IsDefault
int64
`json:"
-
"`
Ratio
float64
`json:"ratio"`
Ratio
float64
`json:"ratio"`
Tax
float64
`json:"tax"`
Tax
float64
`json:"tax"`
}
}
model/goods.go
View file @
9a078044
...
@@ -11,9 +11,18 @@ type LadderPrice struct {
...
@@ -11,9 +11,18 @@ type LadderPrice struct {
Purchases
int64
`json:"purchases"`
//购买数量
Purchases
int64
`json:"purchases"`
//购买数量
PriceUs
float64
`json:"price_us"`
//数量对应的英文价格
PriceUs
float64
`json:"price_us"`
//数量对应的英文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceAc
float64
`json:"price_ac"`
PriceAc
float64
`json:"price_ac
,omitempty
"`
CostPrice
float64
`json:"-"`
CostPrice
float64
`json:"-"`
}
}
type
OriginPrice
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
PriceUs
float64
`json:"price_us"`
//数量对应的英文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceAc
float64
`json:"price_ac,omitempty"`
CostPrice
float64
`json:"cost_price"`
}
//立创价格梯度
//立创价格梯度
type
LadderPriceLc
struct
{
type
LadderPriceLc
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
Purchases
int64
`json:"purchases"`
//购买数量
...
...
model/ly_sku.go
View file @
9a078044
...
@@ -6,14 +6,11 @@ import (
...
@@ -6,14 +6,11 @@ import (
//联营sku结构体
//联营sku结构体
type
LySku
struct
{
type
LySku
struct
{
GoodsId
string
`json:"goods_id"`
SpuId
string
`json:"spu_id"`
GoodsSn
string
`json:"goods_sn"`
OldGoodsId
int64
`json:"old_goods_id"`
SpuId
int64
`json:"spu_id"`
BrandId
int64
`json:"brand_id"`
BrandName
string
`json:"brand_name"`
UpdateTime
int64
`json:"update_time"`
UpdateTime
int64
`json:"update_time"`
CpTime
int64
`json:"cp_time"`
GoodsStatus
int64
`json:"goods_status"`
GoodsStatus
int64
`json:"goods_status"`
GoodsName
string
`json:"goods_name"`
GoodsType
int64
`json:"goods_type"`
GoodsType
int64
`json:"goods_type"`
SupplierId
int64
`json:"supplier_id"`
SupplierId
int64
`json:"supplier_id"`
Encoded
string
`json:"encoded"`
Encoded
string
`json:"encoded"`
...
@@ -23,44 +20,47 @@ type LySku struct {
...
@@ -23,44 +20,47 @@ type LySku struct {
Stock
int64
`json:"stock"`
Stock
int64
`json:"stock"`
HkDeliveryTime
string
`json:"hk_delivery_time"`
HkDeliveryTime
string
`json:"hk_delivery_time"`
CnDeliveryTime
string
`json:"cn_delivery_time"`
CnDeliveryTime
string
`json:"cn_delivery_time"`
GoodsDetails
string
`json:"goods_details"`
GoodsImages
string
`json:"goods_images"`
LadderPrice
[]
LadderPrice
`json:"ladder_price"`
LadderPrice
[]
LadderPrice
`json:"ladder_price"`
Original
[]
LadderPrice
`json:"original_price
"`
GoodsImages
string
`json:"goods_images
"`
Canal
string
`json:"canal"`
Canal
string
`json:"canal"`
CpTime
int64
`json:"cp_time"`
Packing
string
`json:"packing"`
Packing
string
`json:"packing"`
ImagesL
string
`json:"images_l"`
GoodsId
string
`json:"goods_id"`
Pdf
string
`json:"pdf"`
GoodsName
string
`json:"goods_name"`
ClassName
string
`json:"class_name,omitempty"`
BrandName
string
`json:"brand_name"`
ClassName1
string
`json:"class_name1,omitempty"`
ClassName2
string
`json:"class_name2,omitempty"`
ClassName3
string
`json:"class_name3,omitempty"`
ErpTax
interface
{}
`json:"erp_tax"`
SupplierName
string
`json:"supplier_name"`
SupplierName
string
`json:"supplier_name"`
Attrs
interface
{}
`json:"attrs"`
Attrs
interface
{}
`json:"attrs"`
ScmBrand
interface
{}
`json:"scm_brand"`
ScmBrand
interface
{}
`json:"scm_brand"`
AcType
int
`json:"ac_type"`
AcType
int
`json:"ac_type"`
AllowCoupon
int
`json:"allow_coupon"`
AllowCoupon
int
`json:"allow_coupon"`
Ratio
float64
`json:"ratio,omitempty"`
BrandId
int64
`json:"brand_id"`
//系数相关
Coefficient
interface
{}
`json:"coefficient,omitempty"`
Original
[]
LadderPrice
`json:"original_price"`
SuppExtendFee
interface
{}
`json:"supp_extend_fee"`
SuppExtendFee
interface
{}
`json:"supp_extend_fee"`
IsBuy
int
`json:"is_buy"`
IsBuy
int
`json:"is_buy"`
//spu信息
//spu信息
ClassID1
int
`json:"class_id1"`
ClassID1
int
`json:"class_id1"`
ClassID2
int
`json:"class_id2"`
ClassID2
int
`json:"class_id2"`
ClassID3
int
`json:"class_id3,omitempty"`
ClassID3
int
`json:"class_id3,omitempty"`
SpuName
string
`json:"spu_name"`
SpuName
string
`json:"spu_name"`
SpuBrief
string
`json:"spu_brief"`
SpuDetail
string
`json:"spu_detail,omitempty"`
Status
int
`json:"status"`
Status
int
`json:"status"`
ImagesL
string
`json:"images_l"`
Encap
string
`json:"encap"`
Encap
string
`json:"encap"`
Pdf
string
`json:"pdf"`
SpuBrief
string
`json:"spu_brief"`
ClassName
string
`json:"class_name,omitempty"`
ErpTax
interface
{}
`json:"erp_tax"`
GoodsSn
string
`json:"goods_sn"`
GoodsDetails
string
`json:"goods_details"`
ClassName1
string
`json:"class_name1,omitempty"`
ClassName2
string
`json:"class_name2,omitempty"`
ClassName3
string
`json:"class_name3,omitempty"`
Ratio
float64
`json:"ratio,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
//活动信息
//活动信息
ActivityEndTime
int64
`json:"activity_end_time,omitempty"`
ActivityEndTime
int64
`json:"activity_end_time,omitempty"`
ActivityInfo
map
[
string
]
interface
{}
`json:"activity_info,omitempty"`
ActivityInfo
map
[
string
]
interface
{}
`json:"activity_info,omitempty"`
//系数相关
Coefficient
interface
{}
`json:"coefficient,omitempty"`
}
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
...
@@ -68,9 +68,12 @@ func InitSkuData(sku string) (data LySku) {
...
@@ -68,9 +68,12 @@ func InitSkuData(sku string) (data LySku) {
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
data
.
GoodsSn
=
goodsSn
data
.
GoodsSn
=
goodsSn
spuId
:=
gjson
.
Get
(
sku
,
"spu_id"
)
.
Int
()
spuId
:=
gjson
.
Get
(
sku
,
"spu_id"
)
.
String
()
data
.
SpuId
=
spuId
data
.
SpuId
=
spuId
oldGoodsId
:=
gjson
.
Get
(
sku
,
"old_goods_id"
)
.
Int
()
data
.
OldGoodsId
=
oldGoodsId
updateTime
:=
gjson
.
Get
(
sku
,
"update_time"
)
.
Int
()
updateTime
:=
gjson
.
Get
(
sku
,
"update_time"
)
.
Int
()
data
.
UpdateTime
=
updateTime
data
.
UpdateTime
=
updateTime
...
...
pkg/gredis/redis.go
View file @
9a078044
...
@@ -64,7 +64,6 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
...
@@ -64,7 +64,6 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
return
return
}
}
/*
/*
批量或者单个查询redis数据,统一返回map[string]string
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
@param hkey string 集合键值,如sku
...
@@ -83,9 +82,9 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
...
@@ -83,9 +82,9 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
skuArr
:=
make
(
map
[
string
]
string
,
0
)
skuArr
:=
make
(
map
[
string
]
string
,
0
)
if
len
(
targetIds
)
==
1
{
if
len
(
targetIds
)
==
1
{
goods_id
:=
targetIds
[
0
]
;
goods_id
:=
targetIds
[
0
]
info
,
err
:=
String
(
redisConn
.
Do
(
"HGET"
,
hkey
,
goods_id
))
info
,
err
:=
String
(
redisConn
.
Do
(
"HGET"
,
hkey
,
goods_id
))
if
err
!=
nil
{
if
err
!=
nil
&&
err
!=
redis
.
ErrNil
{
fmt
.
Print
(
"连接redis错误991:"
,
err
)
fmt
.
Print
(
"连接redis错误991:"
,
err
)
}
}
if
info
==
""
{
if
info
==
""
{
...
@@ -95,14 +94,14 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
...
@@ -95,14 +94,14 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
}
}
//fmt.Println("单个查询")
//fmt.Println("单个查询")
return
skuArr
return
skuArr
}
else
{
//多个查询
}
else
{
//多个查询
param
:=
[]
interface
{}{
hkey
}
param
:=
[]
interface
{}{
hkey
}
for
_
,
goods_id
:=
range
targetIds
{
for
_
,
goods_id
:=
range
targetIds
{
param
=
append
(
param
,
goods_id
)
param
=
append
(
param
,
goods_id
)
}
}
res1
,
err1
:=
redisConn
.
Do
(
"hmget"
,
param
...
)
res1
,
err1
:=
redisConn
.
Do
(
"hmget"
,
param
...
)
reply
,
_
:=
redis
.
Strings
(
res1
,
err1
)
reply
,
_
:=
redis
.
Strings
(
res1
,
err1
)
if
err1
!=
nil
{
if
err1
!=
nil
{
fmt
.
Println
(
err1
)
fmt
.
Println
(
err1
)
}
}
...
@@ -114,6 +113,7 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
...
@@ -114,6 +113,7 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
return
skuArr
return
skuArr
}
}
}
}
/*
/*
批量或者单个查询redis数据,统一返回map[string]string
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
@param hkey string 集合键值,如sku
...
...
service/service_ly.go
View file @
9a078044
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"go_sku_server/model"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"sort"
"sort"
"strconv"
"sync"
"sync"
)
)
...
@@ -56,7 +55,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
...
@@ -56,7 +55,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
//A := orderedmap.New()
//A := orderedmap.New()
sku
:=
model
.
InitSkuData
(
skuStr
)
sku
:=
model
.
InitSkuData
(
skuStr
)
sku
.
GoodsId
=
goodsId
sku
.
GoodsId
=
goodsId
spu
:=
spuList
[
s
trconv
.
Itoa
(
int
(
sku
.
SpuId
))
]
spu
:=
spuList
[
s
ku
.
SpuId
]
//读取包装字段的缓存
//读取包装字段的缓存
if
sku
.
SupplierId
==
7
{
if
sku
.
SupplierId
==
7
{
//sku_raw_map哪里写入(成意写的)
//sku_raw_map哪里写入(成意写的)
...
...
service/service_ly_common.go
View file @
9a078044
...
@@ -14,8 +14,10 @@ import (
...
@@ -14,8 +14,10 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mongo"
"go_sku_server/pkg/mongo"
_
"go_sku_server/pkg/mongo"
_
"go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"gopkg.in/mgo.v2/bson"
_
"gopkg.in/mgo.v2/bson"
_
"gopkg.in/mgo.v2/bson"
"strconv"
"strings"
"strings"
)
)
...
@@ -94,15 +96,17 @@ type SpuAttr struct {
...
@@ -94,15 +96,17 @@ type SpuAttr struct {
}
}
//获取Spu的属性
//获取Spu的属性
func
(
ls
*
LyService
)
GetSpuAttr
(
spuId
int64
)
(
attrsResult
[]
interface
{})
{
func
(
ls
*
LyService
)
GetSpuAttr
(
spuId
string
)
(
attrsResult
interface
{})
{
var
spuAttr
SpuAttr
var
spuAttr
SpuAttr
mongodb
:=
mongo
.
Conn
(
"default"
);
var
attrsList
[]
interface
{}
mongodb
:=
mongo
.
Conn
(
"default"
)
defer
func
()
{
defer
func
()
{
mongodb
.
Close
()
mongodb
.
Close
()
}()
}()
err
:=
mongodb
.
DB
(
"ichunt"
)
.
C
(
"spu_attrs"
)
.
Find
(
bson
.
M
{
"spu_id"
:
spuId
})
.
One
(
&
spuAttr
)
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)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if
err
!=
nil
{
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
fmt
.
Println
(
"mongodb连接错误:"
)
fmt
.
Println
(
"mongodb连接错误:"
)
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
...
@@ -116,11 +120,12 @@ func (ls *LyService) GetSpuAttr(spuId int64) (attrsResult []interface{}) {
...
@@ -116,11 +120,12 @@ func (ls *LyService) GetSpuAttr(spuId int64) (attrsResult []interface{}) {
data
:=
make
(
map
[
string
]
interface
{})
data
:=
make
(
map
[
string
]
interface
{})
data
[
"attr_name"
]
=
value
data
[
"attr_name"
]
=
value
data
[
"attr_value"
],
_
=
o
.
Get
(
value
)
data
[
"attr_value"
],
_
=
o
.
Get
(
value
)
attrsResult
=
append
(
attrsResult
,
data
)
attrsList
=
append
(
attrsList
,
data
)
attrsResult
=
attrsList
}
}
return
attrsResult
return
attrsResult
}
}
return
nil
return
false
}
}
//H获取供应链标准品牌
//H获取供应链标准品牌
...
@@ -218,6 +223,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
...
@@ -218,6 +223,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
redisCon
:=
gredis
.
Conn
(
"default_r"
)
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
defer
redisCon
.
Close
()
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
if
ratio
==
""
{
if
ratio
==
""
{
logger
.
Error
(
"%s"
,
"系数获取异常,供应商:"
+
common
.
ToString
(
sku
.
SupplierId
))
logger
.
Error
(
"%s"
,
"系数获取异常,供应商:"
+
common
.
ToString
(
sku
.
SupplierId
))
return
sku
return
sku
...
@@ -272,6 +278,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
...
@@ -272,6 +278,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
//$tax = config('website.tax');
tax
:=
1.13
tax
:=
1.13
for
key
,
price
:=
range
sku
.
LadderPrice
{
for
key
,
price
:=
range
sku
.
LadderPrice
{
if
price
.
Purchases
==
0
{
if
price
.
Purchases
==
0
{
continue
continue
...
@@ -279,8 +286,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
...
@@ -279,8 +286,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
//根据系数处理美金
//根据系数处理美金
sku
.
LadderPrice
[
key
]
.
PriceUs
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Hk
,
4
)
sku
.
LadderPrice
[
key
]
.
PriceUs
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Hk
,
4
)
//处理人民币
//处理人民币
sku
.
LadderPrice
[
key
]
.
PriceCn
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Cn
*
coefficient
.
Ratio
,
4
)
sku
.
LadderPrice
[
key
]
.
PriceCn
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Cn
*
coefficient
.
Ratio
*
tax
,
4
)
//处理mouser的成本价
//处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价
//mouser成本价是什么,斌哥同步过来的成本价
//price.CostPrice是专门针对贸泽(mouser)的
//price.CostPrice是专门针对贸泽(mouser)的
...
...
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