Commit adb8b41f by mushishixian
parents 5bab8b4d b4b87eda
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
...@@ -130,8 +130,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c ...@@ -130,8 +130,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c
A.Set("packing", gjson.Get(info, "packing").Int()) // A.Set("packing", gjson.Get(info, "packing").Int()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) // A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) //
A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) // A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) //
A.Set("moq", gjson.Get(info, "moq").Int()) //
A.Set("mpq", gjson.Get(info, "mpq").Int()) // moq := gjson.Get(info, "moq").Int()
mpq := gjson.Get(info, "mpq").Int()
//自营递增量
Multiple := gjson.Get(info, "multiple").Int()
if Multiple > 0 {
Multiple = Multiple
} else {
if mpq > moq {
Multiple = moq
} else {
Multiple = mpq
}
}
A.Set("moq", moq) //
A.Set("mpq", mpq) //
A.Set("multiple", Multiple) //
A.Set("update_time", gjson.Get(info, "update_time").Int()) // A.Set("update_time", gjson.Get(info, "update_time").Int()) //
A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String(), " ")) // A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String(), " ")) //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment