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
0c850e87
authored
Jan 12, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
根据数量获取 阶梯价接口完成
parent
13c6a884
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
655 additions
and
10 deletions
controller/sku_controller.go
controller/sku_ladderprice_controller.go
doc/阶梯价格测试结果.md
go.mod
model/ladder_price_request.go
pkg/common/function.go
routes/router.go
service/service_ladder_price.go
controller/sku_controller.go
View file @
0c850e87
...
@@ -29,7 +29,7 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
...
@@ -29,7 +29,7 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
*/
*/
func
Synchronization
(
ctx
*
gin
.
Context
)
{
func
CommonController
(
ctx
*
gin
.
Context
)
map
[
string
]
interface
{}
{
common
.
PrintDebugHeader
(
ctx
)
//开启debug调试
common
.
PrintDebugHeader
(
ctx
)
//开启debug调试
zyService
:=
service
.
ZiyingService
{}
//实例化自营查询
zyService
:=
service
.
ZiyingService
{}
//实例化自营查询
...
@@ -39,7 +39,7 @@ func Synchronization(ctx *gin.Context) {
...
@@ -39,7 +39,7 @@ func Synchronization(ctx *gin.Context) {
GoodsIdStr
:=
ctx
.
Request
.
FormValue
(
"goods_id"
)
GoodsIdStr
:=
ctx
.
Request
.
FormValue
(
"goods_id"
)
if
GoodsIdStr
==
""
{
if
GoodsIdStr
==
""
{
common
.
Output
(
ctx
,
1001
,
"查询型号ID不得为空"
,
""
)
common
.
Output
(
ctx
,
1001
,
"查询型号ID不得为空"
,
""
)
return
return
nil
}
}
goodsIdArr
:=
php2go
.
Explode
(
","
,
GoodsIdStr
)
goodsIdArr
:=
php2go
.
Explode
(
","
,
GoodsIdStr
)
...
@@ -108,7 +108,18 @@ func Synchronization(ctx *gin.Context) {
...
@@ -108,7 +108,18 @@ func Synchronization(ctx *gin.Context) {
logger
.
Log
(
"协程超时"
,
"sku"
,
1
)
logger
.
Log
(
"协程超时"
,
"sku"
,
1
)
}
}
}
}
common
.
Output
(
ctx
,
0
,
"success"
,
temp
)
return
temp
}
func
Synchronization
(
ctx
*
gin
.
Context
)
{
res
:=
CommonController
(
ctx
)
common
.
Output
(
ctx
,
0
,
"success"
,
res
)
}
func
Synchronization1
(
ctx
*
gin
.
Context
)
{
res
:=
CommonController
(
ctx
)
common
.
Output
(
ctx
,
0
,
"success"
,
res
)
}
}
/*
/*
...
...
controller/sku_ladderprice_controller.go
View file @
0c850e87
...
@@ -2,8 +2,44 @@ package controller
...
@@ -2,8 +2,44 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/service"
)
)
/**
请求参数格式如下
(
[goods_id] => 1160551099531105977
[num] => 475
[currency] => 1
[power] => Array
(
[member] => true
[newCustomer] => false
[user_id] => 69797
[email] =>
[mobile] => 13277999723
)
)
必填参数 goods_id num currency
参考业务逻辑:http://119.23.72.7/ymx/GoodsMachining/blob/master/app/Http/Controllers/ServicesController.php#L66
*/
func
SkuLadderprice
(
ctx
*
gin
.
Context
)
{
func
SkuLadderprice
(
ctx
*
gin
.
Context
)
{
//ctx.Request.ParseMultipartForm(32 << 20)
//postForm := ctx.Request.Form
if
ladderPriceRequest
,
err
:=
model
.
NewPriceRequest
(
ctx
);
err
!=
nil
{
common
.
Output
(
ctx
,
err
.
Code
,
err
.
Error
(),
""
)
}
else
{
goodsInfo
:=
CommonController
(
ctx
)
//获取商品详情(调用树贤和黄哥之前写好的Controller)
if
data
,
err
:=
service
.
NewLadderPriceService
()
.
GetPriceInfoByNum
(
ladderPriceRequest
,
goodsInfo
);
err
!=
nil
{
common
.
Output
(
ctx
,
err
.
Code
,
err
.
Error
(),
data
)
}
else
{
common
.
Output
(
ctx
,
0
,
"success"
,
data
)
}
return
}
}
}
\ No newline at end of file
doc/阶梯价格测试结果.md
0 → 100644
View file @
0c850e87
#请求参数
```
json
goods_id
1160557872621762351
num
105
currency
2
costly
1
```
### golang 响应参数
```
json
{
"errcode"
:
0
,
"errmsg"
:
"success"
,
"data"
:
{
"goods_info"
:
{
"1160557872621762351"
:
{
"spu_id"
:
"2160557872644497609"
,
"old_goods_id"
:
532850
,
"update_time"
:
1605578726
,
"cp_time"
:
0
,
"goods_status"
:
1
,
"goods_type"
:
1
,
"supplier_id"
:
17
,
"encoded"
:
""
,
"batch_sn"
:
""
,
"moq"
:
1
,
"mpq"
:
1
,
"stock"
:
9999999
,
"hk_delivery_time"
:
""
,
"cn_delivery_time"
:
""
,
"ladder_price"
:
[
{
"purchases"
:
1
,
"price_us"
:
3.16
,
"price_cn"
:
25.6955
,
"price_ac"
:
10.2782
},
{
"purchases"
:
10
,
"price_us"
:
2.84
,
"price_cn"
:
23.0935
,
"price_ac"
:
9.2374
},
{
"purchases"
:
25
,
"price_us"
:
2.67
,
"price_cn"
:
21.7111
,
"price_ac"
:
8.6844
},
{
"purchases"
:
100
,
"price_us"
:
2.32
,
"price_cn"
:
18.8651
,
"price_ac"
:
7.546
},
{
"purchases"
:
250
,
"price_us"
:
2.17
,
"price_cn"
:
17.6454
,
"price_ac"
:
7.0582
},
{
"purchases"
:
500
,
"price_us"
:
1.87
,
"price_cn"
:
15.2059
,
"price_ac"
:
6.0824
},
{
"purchases"
:
750
,
"price_us"
:
1.6
,
"price_cn"
:
13.0104
,
"price_ac"
:
5.2042
},
{
"purchases"
:
1000
,
"price_us"
:
1.35
,
"price_cn"
:
10.9775
,
"price_ac"
:
4.391
}
],
"goods_images"
:
""
,
"canal"
:
""
,
"packing"
:
""
,
"goods_id"
:
"1160557872621762351"
,
"goods_name"
:
"UC3526DW"
,
"brand_name"
:
"TI"
,
"supplier_name"
:
"猎芯专卖"
,
"attrs"
:
false
,
"scm_brand"
:
[],
"ac_type"
:
2
,
"allow_coupon"
:
2
,
"brand_id"
:
23
,
"original_price"
:
[
{
"purchases"
:
1
,
"price_us"
:
3.16
,
"price_cn"
:
25.6955
,
"cost_price"
:
0
},
{
"purchases"
:
10
,
"price_us"
:
2.84
,
"price_cn"
:
23.0935
,
"cost_price"
:
0
},
{
"purchases"
:
25
,
"price_us"
:
2.67
,
"price_cn"
:
21.7111
,
"cost_price"
:
0
},
{
"purchases"
:
100
,
"price_us"
:
2.32
,
"price_cn"
:
18.8651
,
"cost_price"
:
0
},
{
"purchases"
:
250
,
"price_us"
:
2.17
,
"price_cn"
:
17.6454
,
"cost_price"
:
0
},
{
"purchases"
:
500
,
"price_us"
:
1.87
,
"price_cn"
:
15.2059
,
"cost_price"
:
0
},
{
"purchases"
:
750
,
"price_us"
:
1.6
,
"price_cn"
:
13.0104
,
"cost_price"
:
0
},
{
"purchases"
:
1000
,
"price_us"
:
1.35
,
"price_cn"
:
10.9775
,
"cost_price"
:
0
}
],
"supp_extend_fee"
:
false
,
"is_buy"
:
1
,
"class_id1"
:
0
,
"class_id2"
:
0
,
"class_id3"
:
0
,
"spu_name"
:
"UC3526DW"
,
"status"
:
1
,
"images_l"
:
""
,
"encap"
:
""
,
"pdf"
:
""
,
"spu_brief"
:
"UC3526 稳压脉宽调制器"
,
"class_name"
:
"其他"
,
"erp_tax"
:
false
,
"goods_sn"
:
""
,
"goods_details"
:
""
,
"ratio"
:
40
,
"activity_end_time"
:
1639152000
,
"content"
:
null
},
"ac_type"
:
0
},
"ladder_price"
:
[
{
"price_ac"
:
10.2782
,
"price_cn"
:
25.6955
,
"price_us"
:
3.16
,
"purchases"
:
1
},
{
"price_ac"
:
9.2374
,
"price_cn"
:
23.0935
,
"price_us"
:
2.84
,
"purchases"
:
10
},
{
"price_ac"
:
8.6844
,
"price_cn"
:
21.7111
,
"price_us"
:
2.67
,
"purchases"
:
25
},
{
"price_ac"
:
7.546
,
"price_cn"
:
18.8651
,
"price_us"
:
2.32
,
"purchases"
:
100
},
{
"price_ac"
:
7.0582
,
"price_cn"
:
17.6454
,
"price_us"
:
2.17
,
"purchases"
:
250
},
{
"price_ac"
:
6.0824
,
"price_cn"
:
15.2059
,
"price_us"
:
1.87
,
"purchases"
:
500
},
{
"price_ac"
:
5.2042
,
"price_cn"
:
13.0104
,
"price_us"
:
1.6
,
"purchases"
:
750
},
{
"price_ac"
:
4.391
,
"price_cn"
:
10.9775
,
"price_us"
:
1.35
,
"purchases"
:
1000
}
],
"num"
:
105
,
"price_us"
:
3.16
,
"price_us_total"
:
331.8
}
}
```
### php响应参数
```
json
{
"errcode"
:
0
,
"errmsg"
:
"success"
,
"data"
:
{
"price_us"
:
3.16
,
"price_us_total"
:
331.8
,
"ladder_price"
:
[
{
"purchases"
:
1
,
"price_us"
:
3.16
,
"price_cn"
:
25.6955
,
"price_ac"
:
10.2782
},
{
"purchases"
:
10
,
"price_us"
:
2.84
,
"price_cn"
:
23.0935
,
"price_ac"
:
9.2374
},
{
"purchases"
:
25
,
"price_us"
:
2.67
,
"price_cn"
:
21.7111
,
"price_ac"
:
8.6844
},
{
"purchases"
:
100
,
"price_us"
:
2.32
,
"price_cn"
:
18.8651
,
"price_ac"
:
7.546
},
{
"purchases"
:
250
,
"price_us"
:
2.17
,
"price_cn"
:
17.6454
,
"price_ac"
:
7.0582
},
{
"purchases"
:
500
,
"price_us"
:
1.87
,
"price_cn"
:
15.2059
,
"price_ac"
:
6.0824
},
{
"purchases"
:
750
,
"price_us"
:
1.6
,
"price_cn"
:
13.0104
,
"price_ac"
:
5.2042
},
{
"purchases"
:
1000
,
"price_us"
:
1.35
,
"price_cn"
:
10.9775
,
"price_ac"
:
4.391
}
],
"num"
:
105
,
"goods_info"
:
{
"spu_id"
:
"2160557872644497609"
,
"encoded"
:
""
,
"moq"
:
1
,
"mpq"
:
1
,
"old_goods_id"
:
532850
,
"goods_type"
:
1
,
"goods_status"
:
1
,
"batch_sn"
:
""
,
"stock"
:
9999999
,
"hk_delivery_time"
:
""
,
"cn_delivery_time"
:
""
,
"ladder_price"
:
[
{
"purchases"
:
1
,
"price_us"
:
3.16
,
"price_cn"
:
25.6955
,
"price_ac"
:
10.2782
},
{
"purchases"
:
10
,
"price_us"
:
2.84
,
"price_cn"
:
23.0935
,
"price_ac"
:
9.2374
},
{
"purchases"
:
25
,
"price_us"
:
2.67
,
"price_cn"
:
21.7111
,
"price_ac"
:
8.6844
},
{
"purchases"
:
100
,
"price_us"
:
2.32
,
"price_cn"
:
18.8651
,
"price_ac"
:
7.546
},
{
"purchases"
:
250
,
"price_us"
:
2.17
,
"price_cn"
:
17.6454
,
"price_ac"
:
7.0582
},
{
"purchases"
:
500
,
"price_us"
:
1.87
,
"price_cn"
:
15.2059
,
"price_ac"
:
6.0824
},
{
"purchases"
:
750
,
"price_us"
:
1.6
,
"price_cn"
:
13.0104
,
"price_ac"
:
5.2042
},
{
"purchases"
:
1000
,
"price_us"
:
1.35
,
"price_cn"
:
10.9775
,
"price_ac"
:
4.391
}
],
"update_time"
:
1605578726
,
"goods_images"
:
""
,
"canal"
:
""
,
"supplier_id"
:
17
,
"cp_time"
:
0
,
"packing"
:
""
,
"goods_id"
:
"1160557872621762351"
,
"goods_name"
:
"UC3526DW"
,
"brand_name"
:
"TI"
,
"supplier_name"
:
"猎芯专卖"
,
"attrs"
:
[
{
"attr_name"
:
"属性名称"
,
"attr_value"
:
"属性值3471"
}
],
"scm_brand"
:
[],
"ac_type"
:
0
,
"allow_coupon"
:
2
,
"brand_id"
:
23
,
"ratio"
:
40
,
"activity_end_time"
:
1639152000
,
"original_price"
:
[
{
"purchases"
:
1
,
"price_cn"
:
25.6955
,
"price_us"
:
3.16
},
{
"purchases"
:
10
,
"price_cn"
:
23.0935
,
"price_us"
:
2.84
},
{
"purchases"
:
25
,
"price_cn"
:
21.7111
,
"price_us"
:
2.67
},
{
"purchases"
:
100
,
"price_cn"
:
18.8651
,
"price_us"
:
2.32
},
{
"purchases"
:
250
,
"price_cn"
:
17.6454
,
"price_us"
:
2.17
},
{
"purchases"
:
500
,
"price_cn"
:
15.2059
,
"price_us"
:
1.87
},
{
"purchases"
:
750
,
"price_cn"
:
13.0104
,
"price_us"
:
1.6
},
{
"purchases"
:
1000
,
"price_cn"
:
10.9775
,
"price_us"
:
1.35
}
],
"supp_extend_fee"
:
false
,
"is_buy"
:
1
,
"class_id1"
:
0
,
"class_id2"
:
0
,
"class_id3"
:
0
,
"spu_name"
:
"UC3526DW"
,
"status"
:
1
,
"images_l"
:
""
,
"encap"
:
""
,
"pdf"
:
"http://www.ti.com/general/docs/lit/getliterature.tsp?genericPartNumber=UC2526AM&&fileType=pdf"
,
"spu_brief"
:
"UC3526 稳压脉宽调制器"
,
"class_name"
:
"其他"
,
"erp_tax"
:
false
}
}
}
```
\ No newline at end of file
go.mod
View file @
0c850e87
...
@@ -6,6 +6,7 @@ require (
...
@@ -6,6 +6,7 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/gin-gonic/gin v1.6.3
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
github.com/go-ini/ini v1.57.0
github.com/go-playground/validator/v10 v10.2.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/go-xorm/xorm v0.7.9
github.com/gogf/gf v1.14.5
github.com/gogf/gf v1.14.5
...
...
model/ladder_price_request.go
View file @
0c850e87
package
model
package
model
import
(
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/gogf/gf/util/gconv"
"go_sku_server/pkg/e"
"reflect"
)
type
LadderPriceRequest
struct
{
type
LadderPriceRequest
struct
{
GoodsId
string
`json:"goods_id" form:"goods_id" binding:"required"`
GoodsId
string
`json:"goods_id" form:"goods_id" binding:"required" required_errcode:"104004"`
Num
string
`json:"num" form:"num" binding:"required"`
Num
int64
`json:"num" form:"num" binding:"required" required_errcode:"104005"`
Currency
int
`json:"currency" form:"currency" binding:"required"`
Currency
int
`json:"currency" form:"currency" binding:"required" required_errcode:"104006"`
Costly
int
`json:"costly" form:"costly" `
//暂时不知道是什么意思
}
type
requiredCode
struct
{
msgMap
map
[
string
]
int
}
// 验证并返回 LadderPriceRequest
func
NewPriceRequest
(
ctx
*
gin
.
Context
)
(
LadderPriceRequest
,
*
e
.
ApiError
)
{
ladderPriceRequest
:=
LadderPriceRequest
{}
typeOfLadderPrice
:=
reflect
.
TypeOf
(
ladderPriceRequest
)
if
err
:=
ctx
.
ShouldBind
(
&
ladderPriceRequest
);
err
!=
nil
{
if
fieldError
,
ok
:=
err
.
(
validator
.
ValidationErrors
);
ok
{
if
(
fieldError
[
0
]
.
Tag
()
==
"required"
){
fieldName
:=
fieldError
[
0
]
.
StructField
()
requiredCode
:=
104001
if
field
,
bool
:=
typeOfLadderPrice
.
FieldByName
(
fieldName
);
bool
==
true
{
requiredCode
=
gconv
.
Int
(
field
.
Tag
.
Get
(
"required_errcode"
))
}
return
ladderPriceRequest
,
e
.
NewApiError
(
"缺少参数:"
+
fieldName
,
requiredCode
)
}
}
}
return
ladderPriceRequest
,
nil
}
}
\ No newline at end of file
pkg/common/function.go
View file @
0c850e87
...
@@ -78,8 +78,8 @@ func GetRequestParam(ctx *gin.Context) string {
...
@@ -78,8 +78,8 @@ func GetRequestParam(ctx *gin.Context) string {
}
}
return
BodyJson
return
BodyJson
default
:
default
:
ctx
.
Request
.
Parse
Form
(
)
ctx
.
Request
.
Parse
MultipartForm
(
32
<<
20
)
postForm
:=
ctx
.
Request
.
Post
Form
postForm
:=
ctx
.
Request
.
Form
formData
,
_
:=
json
.
Marshal
(
postForm
)
formData
,
_
:=
json
.
Marshal
(
postForm
)
params
:=
string
(
formData
)
params
:=
string
(
formData
)
return
params
return
params
...
...
routes/router.go
View file @
0c850e87
...
@@ -19,6 +19,9 @@ func InitRouter() *gin.Engine {
...
@@ -19,6 +19,9 @@ func InitRouter() *gin.Engine {
//联营参数选择搜索
//联营参数选择搜索
r
.
GET
(
"Synchronization"
,
controller
.
Synchronization
)
r
.
GET
(
"Synchronization"
,
controller
.
Synchronization
)
r
.
POST
(
"Synchronization"
,
controller
.
Synchronization
)
r
.
POST
(
"Synchronization"
,
controller
.
Synchronization
)
r
.
POST
(
"Ladderprice"
,
controller
.
SkuLadderprice
)
//心跳
//心跳
r
.
GET
(
"hbsdata"
,
controller
.
Hbsdata
)
r
.
GET
(
"hbsdata"
,
controller
.
Hbsdata
)
r
.
POST
(
"hbsdata"
,
controller
.
Hbsdata
)
r
.
POST
(
"hbsdata"
,
controller
.
Hbsdata
)
...
@@ -27,5 +30,6 @@ func InitRouter() *gin.Engine {
...
@@ -27,5 +30,6 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"SaveSku"
,
controller
.
Error_Middleware
(),
controller
.
SaveSku
)
r
.
POST
(
"SaveSku"
,
controller
.
Error_Middleware
(),
controller
.
SaveSku
)
r
.
POST
(
"SkuEdit"
,
controller
.
Error_Middleware
(),
controller
.
SkuEdit
)
r
.
POST
(
"SkuEdit"
,
controller
.
Error_Middleware
(),
controller
.
SkuEdit
)
return
r
return
r
}
}
service/service_ladder_price.go
0 → 100644
View file @
0c850e87
package
service
import
(
"encoding/json"
"github.com/gogf/gf/util/gconv"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/e"
)
type
LadderPriceService
struct
{
}
func
adderprice
()
{
}
/**
* 指定数量从阶梯中选择价格
* @param [type] $ladder 价格阶梯
* @param [type] $num 购买数量
* @param integer $currency 币种 1人民币 2美元
* @return [type]
*/
func
(
LP
*
LadderPriceService
)
GetPriceInfoByNum
(
ladderPriceRequest
model
.
LadderPriceRequest
,
goodsInfo
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
*
e
.
ApiError
)
{
//此service 对 商详数据的操作都是使用的 gjson包
res
:=
make
(
map
[
string
]
interface
{})
goodsJsonResult
,
err
:=
LP
.
getGoodsInfo
(
goodsInfo
,
ladderPriceRequest
.
GoodsId
)
if
(
err
!=
nil
){
return
res
,
err
}
costly
:=
ladderPriceRequest
.
Costly
//这个字段暂时不知道什么意思
//根据num 从 多个阶梯价数组 获取到对应的阶梯价
ladderPriceOne
,
err
:=
LP
.
getLadderPrice
(
goodsJsonResult
,
ladderPriceRequest
.
GoodsId
,
ladderPriceRequest
.
Num
,
costly
)
num
:=
ladderPriceRequest
.
Num
purchases
:=
ladderPriceOne
.
Get
(
"purchases"
)
.
Int
();
if
purchases
>
ladderPriceRequest
.
Num
{
num
=
purchases
}
goodsType
:=
goodsJsonResult
.
Get
(
"goods_type"
)
.
Int
()
acType
:=
goodsJsonResult
.
Get
(
"ac_type"
)
.
Int
()
if
((
goodsType
==
1
||
goodsType
==
2
)
&&
acType
!=
1
&&
ladderPriceRequest
.
Currency
!=
1
){
//美元
res
[
"price_us"
]
=
ladderPriceOne
.
Get
(
"price_us"
)
.
Float
()
res
[
"price_us_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_us"
])
*
gconv
.
Float64
(
num
),
4
)
goodsInfo
[
"ac_type"
]
=
0
}
else
{
//人民币
res
[
"price_cn"
]
=
ladderPriceOne
.
Get
(
"price_cn"
)
.
Float
()
res
[
"price_cn_total"
]
=
common
.
MyRound
(
gconv
.
Float64
(
res
[
"price_cn"
])
*
gconv
.
Float64
(
num
),
4
)
//人民币原价总价
priceAc
:=
ladderPriceOne
.
Get
(
"price_ac"
)
.
Float
()
if
priceAc
!=
0
{
res
[
"price_ac"
]
=
priceAc
res
[
"price_ac_total"
]
=
common
.
MyRound
(
priceAc
*
gconv
.
Float64
(
num
),
4
)
}
}
ladder
:=
make
([]
map
[
string
]
interface
{},
0
)
a
:=
goodsJsonResult
.
Get
(
"ladder_price"
)
.
String
()
err1
:=
json
.
Unmarshal
([]
byte
(
a
),
&
ladder
)
//json Unmarshal一下,为了让返回格式没那么多斜划线
if
(
err1
!=
nil
){
return
res
,
e
.
NewApiError
(
"json.Unmarshal ladder_price 报错"
+
err1
.
Error
())
}
res
[
"ladder_price"
]
=
ladder
res
[
"goods_info"
]
=
goodsInfo
res
[
"num"
]
=
num
return
res
,
nil
}
func
(
LP
*
LadderPriceService
)
getGoodsInfo
(
goodsInfo
map
[
string
]
interface
{},
goodsId
string
)
(
gjson
.
Result
,
*
e
.
ApiError
)
{
var
info
gjson
.
Result
goodsInfoJson
:=
""
//把商品详情数据转化为json,方便用gjson处理
if
byteS
,
err
:=
json
.
Marshal
(
goodsInfo
);
err
!=
nil
{
return
info
,
e
.
NewApiError
(
err
.
Error
())
}
else
{
goodsInfoJson
=
string
(
byteS
)
}
goodsResult
:=
gjson
.
Get
(
goodsInfoJson
,
goodsId
)
if
(
goodsResult
.
Exists
()
!=
true
){
return
info
,
e
.
NewApiError
(
"未找到对应SKU"
,
20001
)
}
return
goodsResult
,
nil
}
func
(
LP
*
LadderPriceService
)
getLadderPrice
(
goodsJsonResult
gjson
.
Result
,
goodsId
string
,
num
int64
,
costly
int
)
(
gjson
.
Result
,
*
e
.
ApiError
){
var
res
gjson
.
Result
ladderPriceS
:=
goodsJsonResult
.
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
(
gconv
.
Int
(
costly
)
==
1
){
//这一句没懂 Costly 代表什么意思
break
}
if
(
purchases
<=
num
){
price
=
item
}
}
if
(
price
.
Exists
()
==
false
){
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
504003
)
}
return
price
,
nil
}
else
{
return
res
,
e
.
NewApiError
(
"这个SKU没有阶梯价"
,
104002
)
}
}
func
NewLadderPriceService
()
*
LadderPriceService
{
return
&
LadderPriceService
{}
}
\ No newline at end of file
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