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
796fd5f3
authored
Mar 28, 2023
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
递增量
parent
be38dbb1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
260 additions
and
534 deletions
doc/test3/gjson.go
model/ly_sku.go
doc/test3/gjson.go
deleted
100644 → 0
View file @
be38dbb1
package
main
import
(
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/tidwall/gjson"
"go_sku_server/pkg/common"
)
func
main
()
{
a
:=
"123"
fmt
.
Println
(
gconv
.
Int
(
a
))
ladderprice
()
}
func
ladderprice
()
error
{
jsonStr
:=
jsonStr
()
goodsId
:=
"1160551099531105977"
costly
:=
1
//
var
num
int64
num
=
94
var
data
=
make
(
map
[
string
]
interface
{})
goodsResult
:=
gjson
.
Get
(
jsonStr
,
goodsId
)
if
(
goodsResult
.
Exists
()){
ladderPriceS
:=
goodsResult
.
Get
(
"ladder_price"
)
if
(
len
(
ladderPriceS
.
Array
())
>
0
){
var
price
=
gjson
.
Result
{}
for
k
,
item
:=
range
ladderPriceS
.
Array
(){
purchases
:=
item
.
Get
(
"purchases"
)
.
Int
()
if
(
k
==
0
){
price
=
item
//默认最小数量
if
(
purchases
>
num
){
num
=
purchases
//如果小于最小的,J
break
}
}
if
(
costly
==
1
){
//人民币就使用最小数量的阶梯价
break
}
if
(
purchases
<=
num
){
price
=
item
}
}
if
(
price
.
Exists
()
==
false
){
fmt
.
Println
(
"这个SKU没有阶梯价 504003"
)
}
data
[
"price_cn"
]
=
price
.
Get
(
"price_cn"
)
.
Float
()
price_cn_total
:=
gconv
.
Float64
(
data
[
"price_cn"
])
*
gconv
.
Float64
(
num
)
data
[
"price_cn_total"
]
=
common
.
MyRound
(
price_cn_total
,
4
)
data
[
"ladder_price"
]
=
price
.
Get
(
"price_cn"
)
.
Int
()
data
[
"num"
]
=
num
/*if(price.Get("price_ac").Exists()){
data["price_ac"]
}*/
}
else
{
fmt
.
Println
(
"这个SKU没有阶梯价 104002"
)
}
}
else
{
fmt
.
Println
(
"未找到对应SKU 20001"
)
}
return
nil
}
func
GetLadderPrice
(
goodsId
string
,
num
int64
,
costly
int
)
(
gjson
.
Result
,
error
){
jsonStr
:=
jsonStr
()
goodsResult
:=
gjson
.
Get
(
jsonStr
,
goodsId
)
if
(
goodsResult
.
Exists
()){
ladderPriceS
:=
goodsResult
.
Get
(
"ladder_price"
)
if
(
len
(
ladderPriceS
.
Array
())
>
0
){
var
price
=
gjson
.
Result
{}
for
k
,
item
:=
range
ladderPriceS
.
Array
(){
purchases
:=
item
.
Get
(
"purchases"
)
.
Int
()
if
(
k
==
0
){
price
=
item
//默认最小数量
if
(
purchases
>
num
){
num
=
purchases
//如果小于最小的,J
break
}
}
if
(
costly
==
1
){
//人民币就使用最小数量的阶梯价
break
}
if
(
purchases
<=
num
){
price
=
item
}
}
if
(
price
.
Exists
()
==
false
){
fmt
.
Println
(
"这个SKU没有阶梯价 504003"
)
}
}
else
{
fmt
.
Println
(
"这个SKU没有阶梯价 104002"
)
}
}
else
{
fmt
.
Println
(
"未找到对应SKU 20001"
)
}
}
func
jsonStr
()
string
{
/*
data["price_cn"]=price.Get("price_cn").Float()
price_cn_total:=gconv.Float64(data["price_cn"])*gconv.Float64(num)
data["price_cn_total"]=common.MyRound(price_cn_total,4)
data["ladder_price"]=price.Get("price_cn").Int()
data["num"]=num
*/
str
:=
`{
"1160551099531105977": {
"spu_id": "2160551099534657107",
"old_goods_id": 15000000037,
"update_time": 1607657661,
"cp_time": 0,
"goods_status": 1,
"goods_type": 1,
"supplier_id": 7,
"encoded": "",
"batch_sn": "",
"moq": 95,
"mpq": 1,
"stock": 9999999,
"hk_delivery_time": "2-3个工作日",
"cn_delivery_time": "1-3个工作日",
"ladder_price": [
{
"purchases": 95,
"price_us": 1.2431,
"price_cn": 10.1276
},
{
"purchases": 190,
"price_us": 1.0584,
"price_cn": 8.6231
},
{
"purchases": 950,
"price_us": 0.8384,
"price_cn": 6.8304
}
],
"goods_images": "//media.digikey.com/Photos/Rohm%20Photos/RPM871-H14E2_sml.JPG",
"canal": "",
"packing": "",
"goods_id": "1160551099531105977",
"goods_name": "RPM871-H14E2",
"brand_name": "ROHM",
"supplier_name": "digikey",
"attrs": [
{
"attr_name": "25°C 时待机电流,典型值",
"attr_value": "73µA"
},
{
"attr_name": "产品族",
"attr_value": "IrDA 收发器模块"
},
{
"attr_name": "关断",
"attr_value": "-"
},
{
"attr_name": "其它名称",
"attr_value": "RPM871-H14E2-ND\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tRPM871-H14E2TR\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tRPM871H14E2"
},
{
"attr_name": "包装",
"attr_value": "标准卷带"
},
{
"attr_name": "尺寸",
"attr_value": "8.00mm x 2.90mm x 2.40mm"
},
{
"attr_name": "工作温度",
"attr_value": "-20°C ~ 85°C"
},
{
"attr_name": "数据速率",
"attr_value": "115.2kbs(SIR)"
},
{
"attr_name": "方向",
"attr_value": "侧视图"
},
{
"attr_name": "标准",
"attr_value": "IrDA 1.2"
},
{
"attr_name": "标准包装",
"attr_value": "1,000"
},
{
"attr_name": "电压 - 供电",
"attr_value": "2.6V ~ 3.6V"
},
{
"attr_name": "类别",
"attr_value": "传感器,变送器"
},
{
"attr_name": "系列",
"attr_value": "-"
},
{
"attr_name": "链路范围,低功耗",
"attr_value": "20cm,60cm"
}
],
"scm_brand": [],
"ac_type": 0,
"allow_coupon": 1,
"brand_id": 1749,
"coefficient": {
"cn": 1.03,
"hk": 1,
"extra_ratio": 1,
"ratio": 7,
"tax": 1.13
},
"original_price": [
{
"purchases": 95,
"price_us": 1.243068,
"price_cn": 9.4233255876,
"cost_price": 0
},
{
"purchases": 190,
"price_us": 1.058397,
"price_cn": 8.0233901379,
"cost_price": 0
},
{
"purchases": 950,
"price_us": 0.838368,
"price_cn": 6.3554162976,
"cost_price": 0
}
],
"supp_extend_fee": {
"cn": {
"max": "10000",
"price": "20"
},
"hk": {
"max": 69000,
"price": 138
}
},
"is_buy": 1,
"class_id1": 13287,
"class_id2": 13288,
"class_id3": 0,
"spu_name": "RPM871-H14E2",
"status": 1,
"images_l": "//media.digikey.com/Photos/Rohm%20Photos/RPM871-H14E2_sml.JPG",
"encap": "",
"pdf": "//media.digikey.com/pdf/Data%20Sheets/Rohm%20PDFs/RPM871-H14.pdf",
"spu_brief": "MODULE IRDA 115.2KBPS 8SMD",
"class_name": "其他",
"erp_tax": false,
"goods_sn": "",
"goods_details": "",
"content": null
}
}`
return
str
}
\ No newline at end of file
model/ly_sku.go
View file @
796fd5f3
package
model
import
(
"strings"
"github.com/tidwall/gjson"
)
//联营sku结构体
type
LySku
struct
{
LadderPrice
[]
LadderPrice
`json:"-"`
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"`
GoodsType
int64
`json:"goods_type"`
SupplierId
int64
`json:"supplier_id"`
Encoded
string
`json:"encoded"`
BatchSn
string
`json:"batch_sn"`
Moq
int64
`json:"moq"`
Mpq
int64
`json:"mpq"`
Stock
int64
`json:"stock"`
HkDeliveryTime
string
`json:"hk_delivery_time"`
CnDeliveryTime
string
`json:"cn_delivery_time"`
LadderPriceResult
interface
{}
`json:"ladder_price"`
GoodsImages
string
`json:"goods_images"`
Canal
string
`json:"canal"`
IsExpire
int
`json:"is_expire,omitempty"`
Packing
string
`json:"packing"`
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"`
AllowCoupon
int
`json:"allow_coupon"`
BrandId
int64
`json:"brand_id"`
//系数相关
Coefficient
interface
{}
`json:"coefficient,omitempty"`
Original
interface
{}
`json:"original_price,omitempty"`
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"`
SpuName
string
`json:"spu_name"`
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"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
AcType
int
`json:"ac_type"`
//活动信息
HasGiftActivity
int
`json:"has_gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
ActivityInfo
PriceActivity
`json:"activity_info"`
StandardBrand
StandardBrand
`json:"standard_brand"`
GoodsTag
GoodsTag
`json:"goods_tag"`
StockInfo
interface
{}
`json:"stock_info"`
Eccn
string
`json:"eccn"`
DiscountRatio
DiscountRatio
`json:"discount_ratio"`
PriceRatioSort
int
`json:"price_ratio_sort"`
PriceRatio
[]
PriceRatio
`json:"price_ratio"`
}
type
DiscountRatio
struct
{
Ratio
float64
`json:"ratio"`
RatioUsd
float64
`json:"ratio_usd"`
}
type
PriceRatio
struct
{
Ratio
float64
`json:"ratio"`
RatioUsd
float64
`json:"ratio_usd"`
}
type
PriceActivity
struct
{
ActivityCommon
Ratio
float64
`json:"ratio,omitempty"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SignText
string
`json:"sign_text,omitempty"`
Sign
string
`json:"sign,omitempty"`
ShowName
string
`json:"show_name,omitempty"`
}
type
GiftActivity
struct
{
ActivityCommon
CanAdminOrder
interface
{}
`json:"can_admin_order"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
}
type
ActivityCommon
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
UserScope
int
`json:"user_scope,omitempty"`
}
type
StandardBrand
struct
{
StandardBrandId
int
`json:"standard_brand_id,omitempty"`
BrandName
string
`json:"brand_name,omitempty"`
BrandLogo
string
`json:"brand_logo,omitempty"`
}
type
GoodsTag
struct
{
GoodsLabel
int
`json:"goods_label,omitempty"`
GoodsLabelName
string
`json:"goods_label_name,omitempty"`
GoodsTag
[]
int
`json:"goods_tag,omitempty"`
GoodsTagNames
[]
string
`json:"goods_tag_names,omitempty"`
}
type
StockInfo
struct
{
Period
string
`json:"period" bson:"period"`
PeriodTime
int
`json:"-" bson:"period_time"`
PeriodTimeFormat
string
`json:"period_time"`
Stock
int
`json:"stock" bson:"stock"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
data
.
GoodsSn
=
goodsSn
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
goodsStatus
:=
gjson
.
Get
(
sku
,
"goods_status"
)
.
Int
()
data
.
GoodsStatus
=
goodsStatus
goodsName
:=
gjson
.
Get
(
sku
,
"goods_name"
)
.
String
()
data
.
GoodsName
=
goodsName
goodsType
:=
gjson
.
Get
(
sku
,
"goods_type"
)
.
Int
()
data
.
GoodsType
=
goodsType
supplierId
:=
gjson
.
Get
(
sku
,
"supplier_id"
)
.
Int
()
data
.
SupplierId
=
supplierId
encoded
:=
gjson
.
Get
(
sku
,
"encoded"
)
.
String
()
data
.
Encoded
=
encoded
batchSn
:=
gjson
.
Get
(
sku
,
"batch_sn"
)
.
String
()
data
.
BatchSn
=
batchSn
moq
:=
gjson
.
Get
(
sku
,
"moq"
)
.
Int
()
data
.
Moq
=
moq
mpq
:=
gjson
.
Get
(
sku
,
"mpq"
)
.
Int
()
data
.
Mpq
=
mpq
stock
:=
gjson
.
Get
(
sku
,
"stock"
)
.
Int
()
data
.
Stock
=
stock
eccn
:=
gjson
.
Get
(
sku
,
"eccn"
)
.
String
()
data
.
Eccn
=
eccn
isExpire
:=
gjson
.
Get
(
sku
,
"is_expire"
)
.
Int
()
data
.
IsExpire
=
int
(
isExpire
)
hkDeliveryTime
:=
gjson
.
Get
(
sku
,
"hk_delivery_time"
)
.
String
()
data
.
HkDeliveryTime
=
hkDeliveryTime
cnDeliveryTime
:=
gjson
.
Get
(
sku
,
"cn_delivery_time"
)
.
String
()
data
.
CnDeliveryTime
=
cnDeliveryTime
goodsDetail
:=
gjson
.
Get
(
sku
,
"goods_details"
)
.
String
()
data
.
GoodsDetails
=
goodsDetail
goodsImages
:=
gjson
.
Get
(
sku
,
"goods_images"
)
.
String
()
goodsImages
=
strings
.
Replace
(
goodsImages
,
"http://img.ichunt.com"
,
"https://img.ichunt.com"
,
1
)
data
.
GoodsImages
=
goodsImages
canal
:=
gjson
.
Get
(
sku
,
"canal"
)
.
String
()
data
.
Canal
=
canal
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if
data
.
Canal
==
"L0001175"
{
data
.
Encoded
=
"10142-L"
}
cpTime
:=
gjson
.
Get
(
sku
,
"cp_time"
)
.
Int
()
data
.
CpTime
=
cpTime
LadderPriceStr
:=
gjson
.
Get
(
sku
,
"ladder_price"
)
.
String
()
data
.
LadderPrice
=
getLadderPrice
(
LadderPriceStr
)
data
.
Original
=
getOriginPrice
(
LadderPriceStr
)
return
}
//获取联营商品的阶梯价
func
getLadderPrice
(
ladderPriceStr
string
)
(
ladderPrice
[]
LadderPrice
)
{
ladderPriceArr
:=
gjson
.
Parse
(
ladderPriceStr
)
.
Array
()
for
_
,
price
:=
range
ladderPriceArr
{
ladderPrice
=
append
(
ladderPrice
,
LadderPrice
{
Purchases
:
price
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
price
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
price
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
price
.
Get
(
"price_ac"
)
.
Float
(),
CostPrice
:
price
.
Get
(
"cost_price"
)
.
Float
(),
})
}
if
len
(
ladderPrice
)
==
0
{
ladderPrice
=
[]
LadderPrice
{}
return
}
return
}
//获取原始价格
func
getOriginPrice
(
ladderPriceStr
string
)
(
ladderPrice
[]
OriginPrice
)
{
ladderPriceArr
:=
gjson
.
Parse
(
ladderPriceStr
)
.
Array
()
for
_
,
price
:=
range
ladderPriceArr
{
ladderPrice
=
append
(
ladderPrice
,
OriginPrice
{
Purchases
:
price
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
price
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
price
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
price
.
Get
(
"price_ac"
)
.
Float
(),
CostPrice
:
price
.
Get
(
"cost_price"
)
.
Float
(),
})
}
if
len
(
ladderPrice
)
==
0
{
ladderPrice
=
[]
OriginPrice
{}
return
}
return
}
package
model
import
(
"strings"
"github.com/tidwall/gjson"
)
//联营sku结构体
type
LySku
struct
{
LadderPrice
[]
LadderPrice
`json:"-"`
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"`
GoodsType
int64
`json:"goods_type"`
SupplierId
int64
`json:"supplier_id"`
Encoded
string
`json:"encoded"`
BatchSn
string
`json:"batch_sn"`
Moq
int64
`json:"moq"`
Mpq
int64
`json:"mpq"`
Multiple
int64
`json:"multiple"`
Stock
int64
`json:"stock"`
HkDeliveryTime
string
`json:"hk_delivery_time"`
CnDeliveryTime
string
`json:"cn_delivery_time"`
LadderPriceResult
interface
{}
`json:"ladder_price"`
GoodsImages
string
`json:"goods_images"`
Canal
string
`json:"canal"`
IsExpire
int
`json:"is_expire,omitempty"`
Packing
string
`json:"packing"`
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"`
AllowCoupon
int
`json:"allow_coupon"`
BrandId
int64
`json:"brand_id"`
//系数相关
Coefficient
interface
{}
`json:"coefficient,omitempty"`
Original
interface
{}
`json:"original_price,omitempty"`
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"`
SpuName
string
`json:"spu_name"`
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"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
AcType
int
`json:"ac_type"`
//活动信息
HasGiftActivity
int
`json:"has_gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
ActivityInfo
PriceActivity
`json:"activity_info"`
StandardBrand
StandardBrand
`json:"standard_brand"`
GoodsTag
GoodsTag
`json:"goods_tag"`
StockInfo
interface
{}
`json:"stock_info"`
Eccn
string
`json:"eccn"`
DiscountRatio
DiscountRatio
`json:"discount_ratio"`
PriceRatioSort
int
`json:"price_ratio_sort"`
PriceRatio
[]
PriceRatio
`json:"price_ratio"`
}
type
DiscountRatio
struct
{
Ratio
float64
`json:"ratio"`
RatioUsd
float64
`json:"ratio_usd"`
}
type
PriceRatio
struct
{
Ratio
float64
`json:"ratio"`
RatioUsd
float64
`json:"ratio_usd"`
}
type
PriceActivity
struct
{
ActivityCommon
Ratio
float64
`json:"ratio,omitempty"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SignText
string
`json:"sign_text,omitempty"`
Sign
string
`json:"sign,omitempty"`
ShowName
string
`json:"show_name,omitempty"`
}
type
GiftActivity
struct
{
ActivityCommon
CanAdminOrder
interface
{}
`json:"can_admin_order"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
}
type
ActivityCommon
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
UserScope
int
`json:"user_scope,omitempty"`
}
type
StandardBrand
struct
{
StandardBrandId
int
`json:"standard_brand_id,omitempty"`
BrandName
string
`json:"brand_name,omitempty"`
BrandLogo
string
`json:"brand_logo,omitempty"`
}
type
GoodsTag
struct
{
GoodsLabel
int
`json:"goods_label,omitempty"`
GoodsLabelName
string
`json:"goods_label_name,omitempty"`
GoodsTag
[]
int
`json:"goods_tag,omitempty"`
GoodsTagNames
[]
string
`json:"goods_tag_names,omitempty"`
}
type
StockInfo
struct
{
Period
string
`json:"period" bson:"period"`
PeriodTime
int
`json:"-" bson:"period_time"`
PeriodTimeFormat
string
`json:"period_time"`
Stock
int
`json:"stock" bson:"stock"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
data
.
GoodsSn
=
goodsSn
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
goodsStatus
:=
gjson
.
Get
(
sku
,
"goods_status"
)
.
Int
()
data
.
GoodsStatus
=
goodsStatus
goodsName
:=
gjson
.
Get
(
sku
,
"goods_name"
)
.
String
()
data
.
GoodsName
=
goodsName
goodsType
:=
gjson
.
Get
(
sku
,
"goods_type"
)
.
Int
()
data
.
GoodsType
=
goodsType
supplierId
:=
gjson
.
Get
(
sku
,
"supplier_id"
)
.
Int
()
data
.
SupplierId
=
supplierId
encoded
:=
gjson
.
Get
(
sku
,
"encoded"
)
.
String
()
data
.
Encoded
=
encoded
batchSn
:=
gjson
.
Get
(
sku
,
"batch_sn"
)
.
String
()
data
.
BatchSn
=
batchSn
moq
:=
gjson
.
Get
(
sku
,
"moq"
)
.
Int
()
data
.
Moq
=
moq
mpq
:=
gjson
.
Get
(
sku
,
"mpq"
)
.
Int
()
data
.
Mpq
=
mpq
//递增量
Multiple
:=
gjson
.
Get
(
sku
,
"Multiple"
)
.
Int
()
if
Multiple
>
0
{
data
.
Multiple
=
Multiple
}
else
{
if
mpq
>
moq
{
data
.
Multiple
=
moq
}
else
{
data
.
Multiple
=
mpq
}
}
stock
:=
gjson
.
Get
(
sku
,
"stock"
)
.
Int
()
data
.
Stock
=
stock
eccn
:=
gjson
.
Get
(
sku
,
"eccn"
)
.
String
()
data
.
Eccn
=
eccn
isExpire
:=
gjson
.
Get
(
sku
,
"is_expire"
)
.
Int
()
data
.
IsExpire
=
int
(
isExpire
)
hkDeliveryTime
:=
gjson
.
Get
(
sku
,
"hk_delivery_time"
)
.
String
()
data
.
HkDeliveryTime
=
hkDeliveryTime
cnDeliveryTime
:=
gjson
.
Get
(
sku
,
"cn_delivery_time"
)
.
String
()
data
.
CnDeliveryTime
=
cnDeliveryTime
goodsDetail
:=
gjson
.
Get
(
sku
,
"goods_details"
)
.
String
()
data
.
GoodsDetails
=
goodsDetail
goodsImages
:=
gjson
.
Get
(
sku
,
"goods_images"
)
.
String
()
goodsImages
=
strings
.
Replace
(
goodsImages
,
"http://img.ichunt.com"
,
"https://img.ichunt.com"
,
1
)
data
.
GoodsImages
=
goodsImages
canal
:=
gjson
.
Get
(
sku
,
"canal"
)
.
String
()
data
.
Canal
=
canal
//加上紧急判断,如果是立创(L0001175)的商品,就修改内部编码
if
data
.
Canal
==
"L0001175"
{
data
.
Encoded
=
"10142-L"
}
cpTime
:=
gjson
.
Get
(
sku
,
"cp_time"
)
.
Int
()
data
.
CpTime
=
cpTime
LadderPriceStr
:=
gjson
.
Get
(
sku
,
"ladder_price"
)
.
String
()
data
.
LadderPrice
=
getLadderPrice
(
LadderPriceStr
)
data
.
Original
=
getOriginPrice
(
LadderPriceStr
)
return
}
//获取联营商品的阶梯价
func
getLadderPrice
(
ladderPriceStr
string
)
(
ladderPrice
[]
LadderPrice
)
{
ladderPriceArr
:=
gjson
.
Parse
(
ladderPriceStr
)
.
Array
()
for
_
,
price
:=
range
ladderPriceArr
{
ladderPrice
=
append
(
ladderPrice
,
LadderPrice
{
Purchases
:
price
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
price
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
price
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
price
.
Get
(
"price_ac"
)
.
Float
(),
CostPrice
:
price
.
Get
(
"cost_price"
)
.
Float
(),
})
}
if
len
(
ladderPrice
)
==
0
{
ladderPrice
=
[]
LadderPrice
{}
return
}
return
}
//获取原始价格
func
getOriginPrice
(
ladderPriceStr
string
)
(
ladderPrice
[]
OriginPrice
)
{
ladderPriceArr
:=
gjson
.
Parse
(
ladderPriceStr
)
.
Array
()
for
_
,
price
:=
range
ladderPriceArr
{
ladderPrice
=
append
(
ladderPrice
,
OriginPrice
{
Purchases
:
price
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
price
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
price
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
price
.
Get
(
"price_ac"
)
.
Float
(),
CostPrice
:
price
.
Get
(
"cost_price"
)
.
Float
(),
})
}
if
len
(
ladderPrice
)
==
0
{
ladderPrice
=
[]
OriginPrice
{}
return
}
return
}
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