package ali import ( "context" "github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/util/gconv" ) type goodsAli struct { } var Goods = goodsAli{} type GoodsListReq struct { Biztype string `json:"biztype"` //经营模式 【1:生产加工,2:经销批发,3:招商代理,4:商业服务】 BuyerProtection string `json:"buyerProtection"` //买家保障,多个值用逗号分割;【qtbh:7天包换;swtbh:15天包换】 City string `json:"city"` //所在地区- 市 示例:杭州 DeliveryTimeType string `json:"deliveryTimeType"` //发货时间;【1:24小时发货;2:48小时发货;3:72小时发货】 DescendOrder bool `json:"descendOrder"` //是否倒序;【正序: false;倒序:true】 HolidayTagId string `json:"holidayTagId"` //商品售卖类型筛选;枚举,多个值用分号分割;免费赊账:50000114 KeyWords string `json:"keyWords"` //搜索关键词 Page int `json:"page"` //页码 PageSize int `json:"pageSize"` //页面数量;最大20 AccessToken string `json:"access_token"` } type GoodsListRes struct { Result struct { CommonRes TotalCount int `json:"totalCount"` //总数 Result []struct { Title string `json:"title"` //商品标题 ImgURL string `json:"imgUrl"` //商品首图 OfferID int64 `json:"offerId"` //商品id SoldOut int `json:"soldOut"` //销量 Enable bool `json:"enable"` //是否有效 Profit string `json:"profit"` //利润空间; - :表示无 示例 300%-500% CurrentPrice float64 `json:"currentPrice"` //分销价 OfferTags []string `json:"offerTags"` //标签数组 } `json:"result"` } `json:"result"` } type GoodsInfoReq struct { GoodsID int64 `json:"offerId"` //1688商品ID,等同于productId NeedCpsSuggestPrice bool `json:"needCpsSuggestPrice"` //是否需要CPS建议价 NeedIntelligentInfo bool `json:"needIntelligentInfo"` //是否返回算法改写的信息,包括标题、图片和详情图片 AccessToken string `json:"access_token"` } type GoodsInfoRes struct { CommonRes BizGroupInfos []struct { Support bool `json:"support"` Description string `json:"description"` Code string `json:"code"` } `json:"bizGroupInfos"` ProductInfo struct { ProductID int64 `json:"productID"` CategoryID int `json:"categoryID"` Subject string `json:"subject"` Description string `json:"description"` PictureAuth bool `json:"pictureAuth"` Image struct { Images []string `json:"images"` } `json:"image"` SkuInfos []struct { Attributes []struct { AttributeID int `json:"attributeID"` AttributeValue string `json:"attributeValue"` SkuImageURL string `json:"skuImageUrl"` AttributeName string `json:"attributeName"` } `json:"attributes"` CargoNumber string `json:"cargoNumber"` AmountOnSale int `json:"amountOnSale"` Price float64 `json:"price"` SkuID int64 `json:"skuId"` SpecID string `json:"specId"` ConsignPrice float64 `json:"consignPrice"` ChannelPrice float64 `json:"channelPrice"` } `json:"skuInfos"` SaleInfo struct { SupportOnlineTrade bool `json:"supportOnlineTrade"` MixWholeSale bool `json:"mixWholeSale"` PriceAuth bool `json:"priceAuth"` PriceRanges []struct { StartQuantity int `json:"startQuantity"` Price float64 `json:"price"` } `json:"priceRanges"` AmountOnSale float64 `json:"amountOnSale"` Unit string `json:"unit"` MinOrderQuantity int `json:"minOrderQuantity"` QuoteType int `json:"quoteType"` } `json:"saleInfo"` ShippingInfo struct { FreightTemplateID int `json:"freightTemplateID"` UnitWeight float64 `json:"unitWeight"` SendGoodsAddressID int `json:"sendGoodsAddressId"` SendGoodsAddressText string `json:"sendGoodsAddressText"` FreightTemplate []struct { AddressCodeText string `json:"addressCodeText"` FromAreaCode string `json:"fromAreaCode"` ID int `json:"id"` ExpressSubTemplate struct { SubTemplateDTO struct { ChargeType int `json:"chargeType"` IsSysTemplate bool `json:"isSysTemplate"` ServiceType int `json:"serviceType"` Type int `json:"type"` } `json:"subTemplateDTO"` RateList []struct { IsSysRate bool `json:"isSysRate"` ToAreaCodeText string `json:"toAreaCodeText"` RateDTO struct { FirstUnit int `json:"firstUnit"` FirstUnitFee int `json:"firstUnitFee"` NextUnit int `json:"nextUnit"` NextUnitFee int `json:"nextUnitFee"` } `json:"rateDTO"` } `json:"rateList"` } `json:"expressSubTemplate"` LogisticsSubTemplate struct { SubTemplateDTO struct { ChargeType int `json:"chargeType"` IsSysTemplate bool `json:"isSysTemplate"` ServiceType int `json:"serviceType"` Type int `json:"type"` } `json:"subTemplateDTO"` } `json:"logisticsSubTemplate"` } `json:"freightTemplate"` ChannelPriceFreePostage bool `json:"channelPriceFreePostage"` ChannelPriceExcludeAreaCodes []struct { Code string `json:"code"` Name string `json:"name"` } `json:"channelPriceExcludeAreaCodes"` } `json:"shippingInfo"` QualityLevel int `json:"qualityLevel"` SupplierLoginID string `json:"supplierLoginId"` CategoryName string `json:"categoryName"` ReferencePrice string `json:"referencePrice"` Attributes []struct { AttributeID int `json:"attributeID"` AttributeName string `json:"attributeName"` Value string `json:"value"` IsCustom bool `json:"isCustom"` } `json:"attributes"` Status string `json:"status"` } `json:"productInfo"` } type GoodsFollowRes struct { Code int `json:"code"` Message int `json:"message"` } type GoodsGroupReq struct { PageNo int64 `json:"pageNo"` PageSize int64 `json:"pageSize"` AccessToken string `json:"access_token"` } type GoodsGroupRes struct { Result struct { Result []struct { CreateTime string `json:"createTime"` FeedCount int `json:"feedCount"` ID int `json:"id"` Title string `json:"title"` } `json:"result"` CommonRes } `json:"result"` } type GoodsCategoryReq struct { CategoryID int64 `json:"categoryID"` AccessToken string `json:"access_token"` } type GoodsCategoryRes struct { CommonRes CategoryInfo []struct { CategoryID int `json:"categoryID"` Name string `json:"name"` IsLeaf bool `json:"isLeaf"` ParentIDs []int `json:"parentIDs"` MinOrderQuantity int `json:"minOrderQuantity"` FeatureInfos []struct { Key string `json:"key"` Value string `json:"value"` Status int `json:"status"` Hierarchy bool `json:"hierarchy"` } `json:"featureInfos"` CategoryType string `json:"categoryType"` IsSupportProcessing bool `json:"isSupportProcessing"` } `json:"categoryInfo"` } //List 查询商品列表 func (goodsAli) List(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, err error) { method := "com.alibaba.p4p/alibaba.cps.op.searchCybOffers" req.AccessToken = server.AccessToken result, err := server.Post(ctx, method, gconv.Map(req)) _ = gjson.New(result).Scan(&res) return } func (goodsAli) Info(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, err error) { method := "com.alibaba.product/alibaba.cpsMedia.productInfo" req.AccessToken = server.AccessToken result, err := server.Post(ctx, method, gconv.Map(req)) _ = gjson.New(result).Scan(&res) return } //Follow 关注商品 func (goodsAli) Follow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) { method := "com.alibaba.product/alibaba.product.follow" result, err := server.Post(ctx, method, g.Map{ "access_token": server.AccessToken, "productId": GoodsID, }) _ = gjson.New(result).Scan(&res) return } //UnFollow 解除关注商品 func (goodsAli) UnFollow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) { method := "com.alibaba.product/alibaba.product.unfollow.crossborder" result, err := server.Post(ctx, method, g.Map{ "access_token": server.AccessToken, "productId": GoodsID, }) _ = gjson.New(result).Scan(&res) return } //Group 获取我的选品库列表 func (goodsAli) Group(ctx context.Context, req *GoodsGroupReq) (res *GoodsGroupRes, err error) { method := "com.alibaba.p4p/alibaba.cps.op.listCybUserGroup" req.AccessToken = server.AccessToken result, err := server.Post(ctx, method, gconv.Map(req)) _ = gjson.New(result).Scan(&res) return } func (goodsAli) Category(ctx context.Context, CategoryID interface{}) (res *GoodsCategoryRes, err error) { method := "com.alibaba.product/alibaba.category.get" var req = &GoodsCategoryReq{ CategoryID: gconv.Int64(CategoryID), AccessToken: server.AccessToken, } result, err := server.Post(ctx, method, gconv.Map(req)) _ = gjson.New(result).Scan(&res) return }