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/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 } 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 b03ec0a..6a3810d 100644 --- a/supply/sku.go +++ b/supply/sku.go @@ -33,9 +33,6 @@ const ( ProfitGtZero = 1 // 利润比大于0 ProfitEqZero = 2 // 利润比等于0 ProfitLtZero = 3 // 利润比小于0 - - PlatformStatusOn = 1 // 平台上架状态 - PlatformStatusDown = 2 // 平台下架状态 ) type ArgsSkuAdd struct { @@ -50,14 +47,13 @@ type ArgsSkuAdd struct { Tax string // 税率 Unit string // 销售单位 UpcCode string // 商品条码 - Source uint // 商品来源 + SourceId uint // 商品来源id Content string // 商品详情 Imgs []SkuImg // 商品图片 第一张主图 Specifications []SkuSpecification // 商品参数信息 } type SkuImg struct { - Id uint `json:"id"` Path string `json:"path"` } @@ -128,7 +124,7 @@ type SkuItem struct { GuidePrice decimal.Decimal // 指导价 ImgUrl string // 商品主图 PlatformStatus uint // 平台状态 1=上架 2=下架 - Source uint // 来源 1=京东 + SourceId uint // 来源 1=京东 SourceSkuId string // 源skuId SourceStatus uint // 供应商状态 1=上架 2=下架 CustomerPrice decimal.Decimal // 供货最高价 @@ -160,3 +156,24 @@ func (s *sku) DownShelves(ctx context.Context, args ArgsSkuLists) error { reply := 0 return client.GetClient(s).Call(ctx, "DownShelves", 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..ff7cacd 100644 --- a/supply/skuAudit.go +++ b/supply/skuAudit.go @@ -15,6 +15,9 @@ type ArgsSkuAuditLists struct { } type SkuAuditSearch struct { + SourceId uint // 供应商id + AdjustType uint // 加价类型 + Status uint // 状态 1=未审核 2=通过 3=驳回 } type SkuAuditItem struct { Id uint `json:"id"` @@ -52,3 +55,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() { + +} diff --git a/supply/source.go b/supply/source.go new file mode 100644 index 0000000..96cdc58 --- /dev/null +++ b/supply/source.go @@ -0,0 +1,9 @@ +package supply + +type Source struct { + Id uint `gorm:"primaryKey"` + Name string // 供货商名称 + Base string // rpc服务基础名称 + SkuName string // sku名称 + OrderName string // order名称 +}