From ce361989e5dc7ffec9b330ef5943aa7670393f86 Mon Sep 17 00:00:00 2001 From: kanade Date: Mon, 25 Jul 2022 18:26:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9clent=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 19 ++++-- supply/customer/customer.go | 5 ++ supply/customer/sku.go | 129 ++++++++++++++++++++++++++++++++++++ supply/setting/rate.go | 22 ++++++ supply/sku.go | 21 ------ supply/supply.go | 3 + 6 files changed, 174 insertions(+), 25 deletions(-) create mode 100644 supply/customer/customer.go create mode 100644 supply/customer/sku.go create mode 100644 supply/setting/rate.go diff --git a/client/client.go b/client/client.go index 9153441..105e776 100644 --- a/client/client.go +++ b/client/client.go @@ -13,19 +13,30 @@ import ( var mClient = sync.Map{} var mutex = sync.Mutex{} +var basePkgPath string + +type empty int + +func init() { + pkgPath := reflect.TypeOf(empty(0)).PkgPath() + basePkgPath = pkgPath[:len(pkgPath)-6] +} // GetClient @Title 获取RPC客户的 func GetClient(s interface{}) client.XClient { - key := reflect.ValueOf(s).Elem().Type().String() + path := strings.TrimPrefix(reflect.ValueOf(s).Elem().Type().PkgPath(), basePkgPath) + actionName := reflect.ValueOf(s).Elem().Type().Name() + key := path + "/" + actionName xClient, ok := mClient.Load(key) if !ok { mutex.Lock() xClient, ok = mClient.Load(key) if !ok { - split := strings.Split(reflect.ValueOf(s).Elem().Type().String(), ".") - servicePath := strings.ToUpper(split[1][0:1]) + split[1][1:] + split := strings.SplitN(key, "/", 2) + basePath := split[0] + servicePath := split[1] - d, err := client.NewConsulDiscovery(split[0], servicePath, config.RpcConfig.RegistryServer, nil) + d, err := client.NewConsulDiscovery(basePath, servicePath, config.RpcConfig.RegistryServer, nil) if err != nil { log.Println(err) return nil diff --git a/supply/customer/customer.go b/supply/customer/customer.go new file mode 100644 index 0000000..1e7b1a0 --- /dev/null +++ b/supply/customer/customer.go @@ -0,0 +1,5 @@ +package customer + +type Customer struct { + Sku sku +} diff --git a/supply/customer/sku.go b/supply/customer/sku.go new file mode 100644 index 0000000..bd90352 --- /dev/null +++ b/supply/customer/sku.go @@ -0,0 +1,129 @@ +package customer + +import ( + "context" + "git.oa00.com/supply-chain/service/client" + "git.oa00.com/supply-chain/service/lib/bean" + "github.com/shopspring/decimal" +) + +type sku struct { +} + +type SkuSearch struct { + Status uint // 1=上架 2=下架 + SkuName string // 商品名称 +} +type ArgsSkuList struct { + CustomerId uint // 客户id + Search SkuSearch + Page bean.Page +} + +type SkuItem struct { + Id uint `json:"id"` + Name string `json:"name"` + BrandId uint `json:"brandId"` + BrandName string `json:"brandName"` + FirstCategoryId uint `json:"firstCategoryId"` + FirstCategoryName string `json:"firstCategoryName"` + SecondCategoryId uint `json:"secondCategoryId"` + SecondCategoryName string `json:"secondCategoryName"` + ThirdCategoryId uint `json:"thirdCategoryId"` + ThirdCategoryName string `json:"thirdCategoryName"` + Price decimal.Decimal `json:"price"` + GuidePrice decimal.Decimal `json:"guidePrice"` + ImgUrl string `json:"imgUrl"` + Profit decimal.Decimal `json:"profit"` + Size string `json:"size"` + Color string `json:"color"` + Tax string `json:"tax"` + Unit string `json:"unit"` + UpcCode string `json:"upcCode"` + Status uint `json:"status"` + CreatedAt int64 `json:"createdAt"` + UpdatedAt int64 `json:"updatedAt"` +} +type ReplySkuList struct { + Lists []SkuItem `json:"lists"` + Total int64 `json:"total"` +} + +// Lists @Title 商品列表 +func (s *sku) Lists(ctx context.Context, args ArgsSkuList) (reply ReplySkuList, err error) { + err = client.GetClient(s).Call(ctx, "Lists", args, &reply) + return +} + +type ArgsSkuDetails struct { + CustomerId uint // 客户id + SkuIds []uint // sku数组 +} + +type SkuDetailItem struct { + Id uint `json:"id"` + Name string `json:"name"` + BrandId uint `json:"brandId"` + BrandName string `json:"brandName"` + FirstCategoryId uint `json:"firstCategoryId"` + FirstCategoryName string `json:"firstCategoryName"` + SecondCategoryId uint `json:"secondCategoryId"` + SecondCategoryName string `json:"secondCategoryName"` + ThirdCategoryId uint `json:"thirdCategoryId"` + ThirdCategoryName string `json:"thirdCategoryName"` + Price decimal.Decimal `json:"price"` + GuidePrice decimal.Decimal `json:"guidePrice"` + ImgUrl string `json:"imgUrl"` + Profit decimal.Decimal `json:"profit"` + Size string `json:"size"` + Color string `json:"color"` + Tax string `json:"tax"` + Unit string `json:"unit"` + UpcCode string `json:"upcCode"` + Status uint `json:"status"` + CreatedAt int64 `json:"createdAt"` + UpdatedAt int64 `json:"updatedAt"` + Content string `json:"content"` + Imgs []SkuImg `json:"imgs"` + Specifications []SkuSpecification `json:"specifications"` +} +type SkuImg struct { + Path string `json:"path"` +} + +type SkuSpecification struct { + Name string `json:"name"` + Attributes []SkuAttribute `json:"attributes"` +} + +type SkuAttribute struct { + Name string `json:"name"` + Value []string `json:"value"` +} + +// Details @Title 获取sku详情 +func (s *sku) Details(ctx context.Context, args ArgsSkuDetails) (reply []SkuDetailItem, err error) { + err = client.GetClient(s).Call(ctx, "Details", args, &reply) + return +} + +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/setting/rate.go b/supply/setting/rate.go new file mode 100644 index 0000000..f9038b2 --- /dev/null +++ b/supply/setting/rate.go @@ -0,0 +1,22 @@ +package setting + +import ( + "context" + "git.oa00.com/supply-chain/service/client" + "github.com/shopspring/decimal" +) + +type rate struct { +} + +type RateItem struct { + Id uint `json:"id"` + Name string `json:"name"` + Rate decimal.Decimal `json:"rate"` +} + +// All @Title 全部利率 +func (r *rate) All(ctx context.Context) (result []RateItem, err error) { + err = client.GetClient(r).Call(ctx, "All", 0, &result) + return +} diff --git a/supply/sku.go b/supply/sku.go index 25bf258..1feb9f6 100644 --- a/supply/sku.go +++ b/supply/sku.go @@ -85,24 +85,3 @@ 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/supply.go b/supply/supply.go index b5924e0..a05ae9f 100644 --- a/supply/supply.go +++ b/supply/supply.go @@ -1,8 +1,11 @@ package supply +import "git.oa00.com/supply-chain/service/supply/customer" + type Supply struct { Brand brand Category category Sku sku SkuAudit skuAudit + Customer customer.Customer }