递增量

parent be38dbb1
Showing with 13 additions and 287 deletions
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
......@@ -20,6 +20,7 @@ type LySku struct {
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"`
......@@ -168,6 +169,18 @@ func InitSkuData(sku string) (data LySku) {
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
......
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