You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
service/otosaas/commodity.go

185 lines
5.3 KiB

package otosaas
import (
"context"
"git.oa00.com/supply-chain/service/client"
"git.oa00.com/supply-chain/service/lib/bean"
"github.com/shopspring/decimal"
)
const (
CommodityStatusNone = 1 // 待处理
CommodityStatusAdopt = 2 // 同步入库
CommodityStatusReject = 3 // 废弃商品
CommodityHandleNone = 1 // 未处理
CommodityHandleStart = 2 // 开始处理
CommoditySaasSkuStatusUp = 1 // 商品上架
CommoditySaasSkuStatusDown = 2 // 商品下架
)
type commodity struct {
}
type CommoditySearch struct {
Name string // 商品名称
CategoryIds []uint // 类目id
SkuCode string // 商品条码
Handle uint // 处理状态 1=待处理 2=入库 3=废弃
CommodityCode string // 商品编码
MinSupplyPrice decimal.Decimal // 最小采购价
MaxSupplyPrice decimal.Decimal // 最大采购价
}
type ArgsCommodityList struct {
Search CommoditySearch
Page bean.Page
}
type CommodityItem struct {
Id uint `json:"id"`
Name string `json:"name"`
CommodityCode string `json:"commodityCode"`
Img string `json:"img"`
CategoryId uint `json:"categoryId"`
CategoryNames string `json:"categoryNames"`
Skus []CommoditySkuItem `json:"skus"`
GuidePrices []decimal.Decimal `json:"guidePrices"`
SupplyPrices []decimal.Decimal `json:"supplyPrices"`
Status uint `json:"status"`
CreatedAt int64 `json:"createdAt"`
}
type CommoditySkuItem struct {
Id uint `json:"id"`
Img string `json:"img"`
SupplyPrice decimal.Decimal `json:"supplyPrice"`
SpecValue string `json:"specValue"`
SkuCode string `json:"skuCode"`
}
type ReplyCommodityLists struct {
List []CommodityItem `json:"list"`
Total int64 `json:"total"`
}
// Lists @Title 获取商品列表
func (c *commodity) Lists(ctx context.Context, args ArgsCommodityList) (reply ReplyCommodityLists, err error) {
xClient, err := client.GetClient(c)
if err != nil {
return
}
err = xClient.Call(ctx, "Lists", args, &reply)
return
}
type ReplyCommodityInfo struct {
Id uint `json:"id"`
CommodityCode string `json:"commodityCode"`
Name string `json:"name"`
ImgUrl string `json:"imgUrl"`
FirstCategoryName string `json:"firstCategoryName"`
SecondCategoryName string `json:"secondCategoryName"`
ThirdCategoryName string `json:"thirdCategoryName"`
SupplyCategoryId uint `json:"supplyCategoryId"`
Handle uint `json:"handle"`
Status uint `json:"status"`
Skus []SkuItem `json:"skus"`
Imgs []CommodityImgItem `json:"imgs"`
Content string `json:"content"`
}
type CommodityImgItem struct {
Id uint `json:"id"`
Path string `json:"path"`
ReplacePath string `json:"replacePath"`
}
type SkuItem struct {
Id uint `json:"id"`
SkuCode string `json:"skuCode"`
SpecName string `json:"specName"`
SpecValue string `json:"specValue"`
SupplyPrice decimal.Decimal `json:"supplyPrice"`
GuidePrice decimal.Decimal `json:"guidePrice"`
ImgUrl string `json:"imgUrl"`
}
// Info @Title 商品详情
func (c *commodity) Info(ctx context.Context, goodsId uint) (reply ReplyCommodityInfo, err error) {
xClient, err := client.GetClient(c)
if err != nil {
return
}
err = xClient.Call(ctx, "Info", goodsId, &reply)
return
}
type ReplyImgs struct {
GoodsId uint `json:"goodsId"`
Imgs []string `json:"imgs"`
}
// GetImgs @Title 获取商品主图
func (c *commodity) GetImgs(ctx context.Context, goodsIds []uint) (reply []ReplyImgs, err error) {
xClient, err := client.GetClient(c)
if err != nil {
return
}
err = xClient.Call(ctx, "GetImgs", goodsIds, &reply)
return
}
type AdoptItem struct {
Id uint `json:"id"`
Name string `json:"name"`
Error string `json:"error"`
}
// Adopt @Title 批量入库
func (c *commodity) Adopt(ctx context.Context, goodsIds []uint) (reply []AdoptItem, err error) {
xClient, err := client.GetClient(c)
if err != nil {
return
}
err = xClient.Call(ctx, "Adopt", goodsIds, &reply)
return
}
// Discard @Title 批量废弃
func (c *commodity) Discard(ctx context.Context, goodsIds []uint) (err error) {
xClient, err := client.GetClient(c)
if err != nil {
return
}
reply := 0
err = xClient.Call(ctx, "Discard", goodsIds, &reply)
return
}
type ArgsCommodityReplaceImg struct {
CommodityId uint // 商品id
ImgId uint // 图片id
ImgPath string // 图片路径
}
// ReplaceImg @Title 替换图片
func (c *commodity) ReplaceImg(ctx context.Context, args ArgsCommodityReplaceImg) error {
reply := 0
xClient, err := client.GetClient(c)
if err != nil {
return err
}
return xClient.Call(ctx, "ReplaceImg", args, &reply)
}
//
//// ReHandle @Title 重新处理商品
//func (c *commodity) ReHandle(ctx context.Context, goodsIds []uint) (reply []AdoptItem, err error) {
// xClient, err := client.GetClient(c)
// if err != nil {
// return nil, err
// }
// err = xClient.Call(ctx, "ReHandle", goodsIds, &reply)
// return
//}