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