From 080285770ec2a5bcf5504c7b74af429737ee7820 Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 21 Jul 2022 16:35:46 +0800 Subject: [PATCH] =?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() { + +}