From 080285770ec2a5bcf5504c7b74af429737ee7820 Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 21 Jul 2022 16:35:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0rpc=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 29 +++++++++++++++++++++++++++++ supply/interface/order.go | 37 +++++++++++++++++++++++++++++++++++++ supply/interface/sku.go | 31 +++++++++++++++++++++++++++++++ supply/sku.go | 29 +++++++++++++++++++++++++++-- supply/skuAudit.go | 5 +++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 supply/interface/order.go create mode 100644 supply/interface/sku.go diff --git a/client/client.go b/client/client.go index 581569d..9153441 100644 --- a/client/client.go +++ b/client/client.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "git.oa00.com/supply-chain/service/config" "github.com/smallnest/rpcx/client" "log" @@ -41,3 +42,31 @@ func GetClient(s interface{}) client.XClient { } return xClient.(client.XClient) } + +// GetClientName @Title 根据服务名获取客户端 +func GetClientName(base, service string) client.XClient { + key := fmt.Sprintf("%s.%s", base, service) + xClient, ok := mClient.Load(key) + if !ok { + mutex.Lock() + xClient, ok = mClient.Load(key) + if !ok { + servicePath := strings.ToUpper(service[0:1]) + service[1:] + + d, err := client.NewConsulDiscovery(base, servicePath, config.RpcConfig.RegistryServer, nil) + if err != nil { + log.Println(err) + return nil + } + option := client.DefaultOption + option.Retries = 3 + option.GenBreaker = func() client.Breaker { + return client.NewConsecCircuitBreaker(2, 30*time.Second) + } + xClient = client.NewXClient(servicePath, client.Failover, client.RoundRobin, d, option) + mClient.Store(key, xClient) + } + mutex.Unlock() + } + return xClient.(client.XClient) +} diff --git a/supply/interface/order.go b/supply/interface/order.go new file mode 100644 index 0000000..bd97851 --- /dev/null +++ b/supply/interface/order.go @@ -0,0 +1,37 @@ +package _interface + +import ( + "context" + "github.com/shopspring/decimal" +) + +type OrderInterface interface { + // FreightFee 获取运费 + FreightFee(ctx context.Context, args ArgsOrderFreightFee, freightFee *decimal.Decimal) error + // Submit 下单 + Submit(ctx context.Context, args ArgsOrderSubmit, sourceOrderSn *string) error +} +type ArgsOrderFreightFee struct { + Skus []OrderFreightFeeSkuItem // 商品信息 + Address string // 地址 +} + +type OrderFreightFeeSkuItem struct { + SourceSkuId string // 源skuId + SourceSkuPrice decimal.Decimal // 采购价 + Quantity uint // 数量 +} + +type ArgsOrderSubmit struct { + OrderSn string // 订单号 + Skus []OrderFreightFeeSkuItem // 商品信息 + Address string // 地址 + FreightFee decimal.Decimal // 运费 +} + +type OrderReceiver struct { + Name string // 姓名 + Phone string // 手机号 + Email string // 邮件 + ZipCode string // 邮编 +} diff --git a/supply/interface/sku.go b/supply/interface/sku.go new file mode 100644 index 0000000..359cf9a --- /dev/null +++ b/supply/interface/sku.go @@ -0,0 +1,31 @@ +package _interface + +import ( + "context" +) + +type skuState uint + +const ( + SkuStateIn = 1 // 有货 + SkuStateOut = 2 // 无货 +) + +type Sku interface { + // Stock 库存查询 + Stock(ctx context.Context, args ArgsSkuStock, reply *[]ReplySkuStock) error +} + +type ArgsSkuStock struct { + Address string // 地址 + Skus []SkuStockItem // sku信息 +} + +type SkuStockItem struct { + SourceSkuId string // 源skuId + Quantity uint // 数量 +} +type ReplySkuStock struct { + SourceSkuId string `json:"sourceSkuId"` // 源skuId + State uint `json:"state"` // 库存状态 +} diff --git a/supply/sku.go b/supply/sku.go index 4ada021..c4a53f5 100644 --- a/supply/sku.go +++ b/supply/sku.go @@ -9,9 +9,13 @@ import ( type sku struct { } +type source uint + const ( - SkuSourceJd = 1 // 京东开普勒渠道 + SkuSourceJd source = 1 // 京东开普勒渠道 +) +const ( SkuAdjustTypeRate = 1 // 加价比例 SkuAdjustTypeAmount = 2 // 加价金额 @@ -42,7 +46,7 @@ type ArgsSkuAdd struct { Tax string // 税率 Unit string // 销售单位 UpcCode string // 商品条码 - Source uint // 商品来源 + Source source // 商品来源 Content string // 商品详情 Imgs []SkuImg // 商品图片 第一张主图 Specifications []SkuSpecification // 商品参数信息 @@ -81,3 +85,24 @@ func (s *sku) Adjust(ctx context.Context, args ArgsSkuAdjust) error { reply := 0 return client.GetClient(s).Call(ctx, "Adjust", args, &reply) } + +type ArgsSkuStock struct { + Address string // 地址 + Skus []SkuStockItem // sku信息 +} + +type SkuStockItem struct { + SkuId uint // 源skuId + Quantity uint // 数量 +} + +type ReplySkuStock struct { + SkuId uint `json:"skuId"` // skuId + State uint `json:"state"` // 库存状态 +} + +// Stock @Title 库存查询 +func (s *sku) Stock(ctx context.Context, args ArgsSkuStock) (reply []ReplySkuStock, err error) { + err = client.GetClient(s).Call(ctx, "Stock", args, &reply) + return +} diff --git a/supply/skuAudit.go b/supply/skuAudit.go index e76b674..162e0ca 100644 --- a/supply/skuAudit.go +++ b/supply/skuAudit.go @@ -52,3 +52,8 @@ func (s *skuAudit) Reject(ctx context.Context, args ArgsSkuAuditReject) error { reply := 0 return client.GetClient(s).Call(ctx, "Reject", args, &reply) } + +// Stock @Title 库存查询 +func (s *skuAudit) Stock() { + +} From 138a9c44acd4a1dd93f44bc717b76015a716fbdf Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 21 Jul 2022 16:49:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supply/sku.go | 1 + 1 file changed, 1 insertion(+) diff --git a/supply/sku.go b/supply/sku.go index c4a53f5..11175b0 100644 --- a/supply/sku.go +++ b/supply/sku.go @@ -36,6 +36,7 @@ const ( type ArgsSkuAdd struct { SourceSkuId string // 源skuId + SourceStatus uint // 源状态 Name string // 商品名称 BrandId uint // 品牌id ThirdCategoryId uint // 三级分类id From 07e4350f78df6451658e7492dfa2e3b6710a29c8 Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 21 Jul 2022 17:35:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd/sku.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jd/sku.go b/jd/sku.go index b4ef845..2189032 100644 --- a/jd/sku.go +++ b/jd/sku.go @@ -14,6 +14,9 @@ const ( SkuHandleNone = 1 // 未处理 SkuHandleStart = 2 // 开始处理 + + SkuJdStatusUp = 1 // 京东上架 + SkuJdStatusDown = 2 // 京东下架 ) type sku struct { @@ -131,8 +134,15 @@ func (s *sku) Discard(ctx context.Context, skuIds []uint) error { return client.GetClient(s).Call(ctx, "Discard", skuIds, &reply) } +type AdoptItem struct { + Id uint `json:"id"` + JdSkuId uint64 `json:"jdSkuId"` + Name string `json:"name"` + Error string `json:"error"` +} + // Adopt @Title 入库 -func (s *sku) Adopt(ctx context.Context, skuIds []uint) error { - reply := 0 - return client.GetClient(s).Call(ctx, "Adopt", skuIds, &reply) +func (s *sku) Adopt(ctx context.Context, skuIds []uint) (reply AdoptItem, err error) { + err = client.GetClient(s).Call(ctx, "Adopt", skuIds, &reply) + return } From 17452dfd0dc9722e6a4d59b9df8ba376d69b56c3 Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 21 Jul 2022 17:43:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supply/sku.go | 1 - 1 file changed, 1 deletion(-) diff --git a/supply/sku.go b/supply/sku.go index 11175b0..25bf258 100644 --- a/supply/sku.go +++ b/supply/sku.go @@ -54,7 +54,6 @@ type ArgsSkuAdd struct { } type SkuImg struct { - Id uint `json:"id"` Path string `json:"path"` }