From 2ea1ff7c3ca0e98144c35eec1df7c9c4595aa52e Mon Sep 17 00:00:00 2001 From: gukai <gukai@stbz.net> Date: Thu, 20 Apr 2023 15:21:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B2=BE=E9=80=891688?= =?UTF-8?q?=E6=B8=A0=E9=81=93=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upstream/aliNew/ali_address.go | 79 +++++++++ upstream/aliNew/ali_goods.go | 294 +++++++++++++++++++++++++++++++ upstream/aliNew/ali_logistics.go | 113 ++++++++++++ upstream/aliNew/ali_new.go | 97 ++++++++++ upstream/aliNew/ali_order.go | 275 +++++++++++++++++++++++++++++ upstream/aliNew/ali_refund.go | 274 ++++++++++++++++++++++++++++ upstream/upstream.go | 7 + 7 files changed, 1139 insertions(+) create mode 100644 upstream/aliNew/ali_address.go create mode 100644 upstream/aliNew/ali_goods.go create mode 100644 upstream/aliNew/ali_logistics.go create mode 100644 upstream/aliNew/ali_new.go create mode 100644 upstream/aliNew/ali_order.go create mode 100644 upstream/aliNew/ali_refund.go diff --git a/upstream/aliNew/ali_address.go b/upstream/aliNew/ali_address.go new file mode 100644 index 0000000..1eff6e1 --- /dev/null +++ b/upstream/aliNew/ali_address.go @@ -0,0 +1,79 @@ +package aliNew + +import ( + "context" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" +) + +type addressAli struct { +} + +var Address = addressAli{} + +type AddressParseRes struct { + Result struct { + Address string `json:"address"` + AddressCode string `json:"addressCode"` + IsDefault bool `json:"isDefault"` + Latest bool `json:"latest"` + PostCode string `json:"postCode"` + } `json:"result"` +} + +type AddressGetRes struct { + CommonRes + Result struct { + Code string `json:"code"` + Name string `json:"name"` + ParentCode string `json:"parentCode"` + Post string `json:"post"` + Children []string `json:"children"` + } `json:"result"` +} +type AddressGetChildRes struct { + CommonRes + Result []struct { + Code string `json:"code"` + Name string `json:"name"` + ParentCode string `json:"parentCode"` + } `json:"result"` +} + +//Parse æ ¹æ®åœ°å€è§£æžåœ°åŒºç +func (s *addressAli) Parse(ctx context.Context, req string) (res *AddressParseRes, err error) { + method := "com.alibaba.trade/alibaba.trade.addresscode.parse" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "addressInfo": req, + }) + _ = gjson.New(result).Scan(&res) + return +} + +//Get 获å–交易地å€ä»£ç 表详情 +func (s *addressAli) Get(ctx context.Context, Code string) (res *AddressGetRes, err error) { + method := "com.alibaba.trade/alibaba.trade.addresscode.get" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "areaCode": Code, + "webSite": WebSite, + }) + _ = gjson.New(result).Scan(&res) + return +} + +//GetChild 获å–交易地å€çš„ä¸‹ä¸€çº§ä¿¡æ¯ +func (s *addressAli) GetChild(ctx context.Context, Code string) (res *AddressGetChildRes, err error) { + method := "com.alibaba.trade/alibaba.trade.addresscode.getchild" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "areaCode": Code, + "webSite": WebSite, + }) + _ = gjson.New(result).Scan(&res) + return +} diff --git a/upstream/aliNew/ali_goods.go b/upstream/aliNew/ali_goods.go new file mode 100644 index 0000000..d29b58d --- /dev/null +++ b/upstream/aliNew/ali_goods.go @@ -0,0 +1,294 @@ +package aliNew + +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 { + RuleId string `json:"ruleId,omitempty"` //选å“规划id + CategoryId string `json:"postCategoryId,omitempty"` //分类ID + KeyWords string `json:"keyWords,omitempty"` //æœç´¢å…³é”®è¯ + PageNo int `json:"pageNo"` //页ç + PageSize int `json:"pageSize"` //页颿•°é‡;最大20 + TopOfferIds string `json:"topOfferIds,omitempty"` //商å“置顶,åªä¼šåœ¨ç¬¬ä¸€é¡µç½®é¡¶ï¼Œå’Œåˆ†é¡µå¤§å°ç›¸åŒæœ€å¤š50个 + AccessToken string `json:"access_token"` +} + +type GoodsListRes struct { + Result struct { + CommonRes + Result struct { + PageIndex int `json:"pageIndex"` + TotalRecords int `json:"totalRecords"` + SizePerPage int `json:"sizePerPage"` + ResultList []struct { + ItemId int64 `json:"itemId"` + ImgUrl string `json:"imgUrl"` + Title string `json:"title"` + SalesCnt90D int `json:"salesCnt90d"` + MaxPrice int `json:"maxPrice,omitempty"` + MinPrice int `json:"minPrice,omitempty"` + ServiceList []struct { + Code string `json:"code"` + Name string `json:"name"` + } `json:"serviceList"` + } `json:"resultList"` + } `json:"result"` + } `json:"result"` +} + +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"` + SupplierLoginId string `json:"supplierLoginId"` + MainVedio string `json:"mainVedio"` + CategoryID int `json:"categoryID"` + Subject string `json:"subject"` + Description string `json:"description"` + PictureAuth bool `json:"pictureAuth"` + IntelligentInfo IntelligentInfo `json:"intelligentInfo"` //商å“算法智能改写信æ¯ï¼ŒåŒ…å«ç®—法优化åŽçš„商哿 ‡é¢˜å’Œå›¾ç‰‡ä¿¡æ¯ï¼Œæœªæ”¹å†™çš„åˆ™ç›´æŽ¥è¿”å›žåŽŸæ ‡é¢˜å’ŒåŽŸå›¾ç‰‡ + Image struct { + Images []string `json:"images"` + } `json:"productImage"` + 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"` + Retailprice float64 `json:"retailprice"` + ChannelPrice float64 `json:"channelPrice"` + } `json:"productSkuInfos"` + 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"` + Retailprice float64 `json:"retailprice"` + ConsignPrice float64 `json:"consignPrice"` + ChannelPrice float64 `json:"channelPrice"` + } `json:"productSaleInfo"` + 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:"productAttribute"` + Status string `json:"status"` + } `json:"productInfo"` +} + +type IntelligentInfo struct { + Title string `json:"title"` //算法优化åŽçš„商哿 ‡é¢˜ + Images []string `json:"images"` //主图列表,使用相对路径,需è¦å¢žåŠ åŸŸå:https://cbu01.alicdn.com/ + SkuImages []struct { //算法优化åŽçš„è§„æ ¼å›¾ç‰‡ + SkuId int64 `json:"skuId"` //è§„æ ¼ID + ImageUrl string `json:"imageUrl"` //图片 + } `json:"skuImages"` + DescriptionImages []string `json:"descriptionImages"` //算法优化åŽçš„详情图片 +} + +type GoodsFollowRes struct { + Success bool `json:"success"` + Data interface{} `json:"data"` + ErrorCode int `json:"errorCode"` + ErrorMessage int `json:"errorMessage"` +} + +type RelationRes struct { + Success bool `json:"success"` + Data interface{} `json:"data"` + ErrorCode int `json:"errorCode"` + ErrorMessage int `json:"errorMessage"` +} + +type OutshopAddRes struct { + Code int `json:"code"` + Message int `json:"message"` +} + + +type RelationInfoReq struct { + Channel string `json:"channel"` // ä¸‹æ¸¸æ¸ é“代ç + OutShopCode string `json:"outShopCode"` // 下游店铺code + OfferId string `json:"offerId"` //上游1688商å“id + OutItemCode string `json:"outItemCode"` //下游外部商å“ç + AccessToken string `json:"access_token"` +} + +type GoodsCategoryReq struct { + CategoryID int64 `json:"categoryID"` + AccessToken string `json:"access_token"` +} + +type GoodsCategoryRes struct { + Succes string `json:"succes"` + 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.fenxiao/alibaba.pifatuan.product.list" + + 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 interface{}) (res *GoodsInfoRes, err error) { + method := "com.alibaba.fenxiao/alibaba.fenxiao.productInfo.get" + request := g.Map{ + "offerId": gconv.Int64(req), + "needCpsSuggestPrice": true, + "needIntelligentInfo": true, + "access_token": server.AccessToken, + } + + result, err := server.Post(ctx, method, request) + _ = 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" + + _, err = server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "productId": GoodsID, + }) + + result, err := server.Post(ctx, "com.alibaba.fenxiao/alibaba.fenxiao.buyer.outproduct.relation.add", g.Map{ + "channel": "other", + "outShopCode": "1", + "offerId": GoodsID, + "outItemCode": GoodsID, + "access_token": server.AccessToken, + }) + + _ = 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" + + _, err = server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "productId": GoodsID, + }) + + result, err := server.Post(ctx, "com.alibaba.fenxiao/alibaba.fenxiao.buyer.outproduct.relation.delete", g.Map{ + "channel": "other", + "outShopCode": "1", + "offerId": GoodsID, + "outItemCode": GoodsID, + "access_token": server.AccessToken, + }) + _ = 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 +} diff --git a/upstream/aliNew/ali_logistics.go b/upstream/aliNew/ali_logistics.go new file mode 100644 index 0000000..f6a0f4e --- /dev/null +++ b/upstream/aliNew/ali_logistics.go @@ -0,0 +1,113 @@ +package aliNew + +import ( + "context" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" +) + +type logisticsAli struct { +} + +var Logistics = logisticsAli{} + +type LogisticsInfosRes struct { + CommonRes + Result []struct { + Sender struct { + SenderName string `json:"senderName"` + SenderMobile string `json:"senderMobile"` + Encrypt string `json:"encrypt"` + SenderProvinceCode string `json:"senderProvinceCode"` + SenderCityCOde string `json:"senderCityC ode"` + SenderCountyCode string `json:"senderCountyCode"` + SenderAddress string `json:"senderAddress"` + SenderProvince string `json:"senderProvince"` + SenderCity string `json:"senderCity"` + SenderCounty string `json:"senderCounty"` + } `json:"sender"` + OrderEntryIds string `json:"orderEntryIds"` + LogisticsBillNo string `json:"logisticsBillNo"` + LogisticsId string `json:"logisticsId "` + Receiver struct { + ReceiverName string `json:"receiverName"` + ReceiverPhone string `json:"receiverPhone"` + ReceiverMobile string `json:"receiverMobile"` + Encrypt string `json:"encrypt"` + ReceiverProvinceCode string `json:"receiverProvinceCode"` + ReceiverCityCode string `json:"receiverCityCode"` + ReceiverCountyCode string `json:"receiverCountyCode"` + ReceiverAddresS string `json:"receiverAddres s"` + ReceiverProvince string `json:"receiverProvince"` + ReceiverCity string `json:"receiverCity"` + ReceiverCounty string `json:"receiverCounty"` + } `json:"receiver"` + LogisticsCompanyName string `json:"logisticsCompanyName"` + Status string `json:"status"` + SendGoods []struct { + GoodName string `json:"goodName"` + Quantity string `json:"quantity"` + Unit string `json:"unit"` + } `json:"sendGoods"` + Remarks string `json:"remarks"` + LogisticsCompanyId string `json:"logisticsCompanyId"` + } `json:"result"` +} + +type LogisticsTraceRes struct { + CommonRes + LogisticsTrace []struct { + LogisticsId string `json:"logisticsId"` + OrderId int64 `json:"orderId"` + LogisticsBillNo string `json:"logisticsBillNo"` + LogisticsSteps []struct { + AcceptTime string `json:"acceptTime"` + Remark string `json:"remark"` + } `json:"logisticsSteps"` + } `json:"logisticsTrace"` +} + +//Info 物æµè¯¦æƒ… +func (*logisticsAli) Info(ctx context.Context, orderSn string) (res *LogisticsInfosRes, err error) { + method := "com.alibaba.logistics/alibaba.trade.getLogisticsInfos.buyerView" + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "webSite": WebSite, + "orderId": orderSn, + }) + _ = gjson.New(result).Scan(&res) + return +} + +//Trace 物æµè½¨è¿¹ +func (*logisticsAli) Trace(ctx context.Context, orderSn string) (res *LogisticsTraceRes, err error) { + method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView" + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "webSite": WebSite, + "orderId": orderSn, + }) + _ = gjson.New(result).Scan(&res) + return +} + +type LogisticsCompanyRes struct { + CommonRes + Result []LogisticsCompanyItem `json:"result"` //result +} + +type LogisticsCompanyItem struct { + Id int64 `json:"id"` + CompanyName string `json:"companyName"` //物æµå…¬å¸åç§° + CompanyNo string `json:"companyNo"` // 物æµå…¬å¸ç¼–å· +} + +//Company 物æµå…¬å¸ +func (s *logisticsAli) Company(ctx context.Context) (res *LogisticsCompanyRes, err error) { + method := "com.alibaba.logistics/alibaba.logistics.OpQueryLogisticCompanyList" + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + }) + _ = gjson.New(result).Scan(&res) + return +} diff --git a/upstream/aliNew/ali_new.go b/upstream/aliNew/ali_new.go new file mode 100644 index 0000000..4f5f890 --- /dev/null +++ b/upstream/aliNew/ali_new.go @@ -0,0 +1,97 @@ +package aliNew + +import ( + "context" + "crypto/hmac" + "crypto/sha1" + "encoding/hex" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/util/gconv" + "sort" + "strings" + "time" +) + +type Config struct { + Wsurl string + ApiUrl string + AppKey string + AppSecret string + AccessToken string +} + +type CommonRes struct { + Success bool `json:"success"` + ErrorCode string `json:"errorCode"` + ErrorMessage string `json:"errorMessage"` +} + +var server *Config + +const PkgName = "aliNew" +const WebSite = "1688" + +func New(config *Config) { + server = config + return +} + +func (s *Config) CreateSign(signStr string) (sign string) { + //æ‹¼æŽ¥å‚æ•° + appSecret := []byte(s.AppSecret) + mac := hmac.New(sha1.New, appSecret) + mac.Write([]byte(signStr)) + mdStr := hex.EncodeToString(mac.Sum(nil)) + sign = strings.ToUpper(mdStr) + return +} + +func (s *Config) sign(method string, param g.Map) g.Map { + var keys []string + + mewparam := param + for k := range mewparam { + keys = append(keys, k) + } + + sort.Strings(keys) + + var signStr string + for _, v := range keys { + if v != "_aop_signature" { + signStr += v + signStr += gconv.String(mewparam[v]) + } + } + //æ‹¼æŽ¥å‚æ•° + signStr = "param2/1/" + method + "/" + s.AppKey + signStr + + param["_aop_signature"] = s.CreateSign(signStr) + + return param +} + +func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) { + Start := gtime.TimestampMilli() + allparams := s.sign(method, params) + Url := s.ApiUrl + method + "/" + s.AppKey + Request := g.Client() + Request.SetHeader("Content-Type", "application/x-www-form-urlencoded") + resp, err := Request.Timeout(time.Second*5).Post(Url, allparams) + defer func() { + _ = resp.Close() + paramStr := gjson.New(params).MustToJsonString() + ctx = context.WithValue(ctx, "Method", "POST") + ctx = context.WithValue(ctx, "URI", Url) + if err != nil { + g.Log().Cat(PkgName).Ctx(ctx).Infof("傿•°ã€%v】错误ã€%v】å“应时间ã€%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) + } else { + g.Log().Cat(PkgName).Ctx(ctx).Infof("傿•°ã€%v】å“应ã€%v】å“应时间ã€%v】", paramStr,str, gtime.TimestampMilli()-Start) + } + }() + str = resp.ReadAllString() + return + +} diff --git a/upstream/aliNew/ali_order.go b/upstream/aliNew/ali_order.go new file mode 100644 index 0000000..33ebc1c --- /dev/null +++ b/upstream/aliNew/ali_order.go @@ -0,0 +1,275 @@ +package aliNew + +import ( + "context" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/util/gconv" +) + +type orderAli struct { +} + +var Order = orderAli{} + +type OrderCommonReq struct { + AddressParam OrderAddress + CargoParam []OrderCargo + OuterOrderInfo OuterOrderInfo +} + +type OrderAddress struct { + FullName string `json:"fullName"` + Mobile string `json:"mobile"` + Phone string `json:"phone"` + PostCode string `json:"postCode"` + CityText string `json:"cityText"` + ProvinceText string `json:"provinceText"` + AreaText string `json:"areaText"` + TownText string `json:"townText"` + Address string `json:"address"` +} + +type OrderCargo struct { + SpecId string `json:"specId"` + OfferId int64 `json:"offerId"` + Quantity int `json:"quantity"` + OutShopCode string `json:"outShopCode"` + OutItemCode string `json:"outItemCode"` + Channel string `json:"channel"` +} + +type OuterOrderInfo struct { + MediaOrderId string `json:"mediaOrderId"` + Phone string `json:"phone"` + Offers []OrderOffer `json:"offers"` +} + +type OrderOffer struct { + SpecId string `json:"specId"` + Id int64 `json:"id"` + Num int `json:"num"` + Price int64 `json:"price"` +} + +type OrderCreateRes struct { + CommonRes + Result struct { + TotalSuccessAmount int64 `json:"totalSuccessAmount"` //䏋啿ˆåŠŸçš„è®¢å•æ€»é‡‘é¢ï¼Œå•ä½ï¼šåˆ† + OrderId string `json:"orderId"` //䏋啿ˆåŠŸåŽçš„订å•id + PostFee int64 `json:"postFee"` //原始è¿è´¹ï¼Œå•ä½ï¼šåˆ†ã€‚注æ„:下å•åŽå–å®¶å¯èƒ½è°ƒæ•´ï¼Œå› æ¤è¯¥å€¼å¯èƒ½ä¸ç‰äºŽæœ€ç»ˆæ”¯ä»˜è¿è´¹ + } `json:"result,omitempty"` +} + +//Create ä¸‹å• +func (s *orderAli) Create(ctx context.Context, req *OrderCommonReq) (res *OrderCreateRes, err error) { + method := "com.alibaba.trade/alibaba.trade.fastCreateOrder" + //æ·»åŠ åˆ†é”€å…³ç³» + for k, v := range req.CargoParam { + req.CargoParam[k].OutShopCode = "1" + req.CargoParam[k].OutItemCode = gconv.String(v.OfferId) + req.CargoParam[k].Channel = "other" + } + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "addressParam": gjson.New(req.AddressParam).MustToJsonString(), + "cargoParamList": gjson.New(req.CargoParam).MustToJsonString(), + "outerOrderInfo": gjson.New(req.OuterOrderInfo).MustToJsonString(), + "flow": "ttpft", + }) + _ = gjson.New(result).Scan(&res) + return +} + +type OrderDetailRes struct { + CommonRes + Result struct { + BaseInfo struct { + PayTime string `json:"payTime"` + Discount int `json:"discount"` + AlipayTradeID string `json:"alipayTradeId"` + SumProductPayment float64 `json:"sumProductPayment"` + FlowTemplateCode string `json:"flowTemplateCode"` + SellerOrder bool `json:"sellerOrder"` + BuyerLoginID string `json:"buyerLoginId"` + ModifyTime string `json:"modifyTime"` + ID int64 `json:"id"` + BuyerContact struct { + Phone string `json:"phone"` + ImInPlatform string `json:"imInPlatform"` + Name string `json:"name"` + CompanyName string `json:"companyName"` + } `json:"buyerContact"` + SellerLoginID string `json:"sellerLoginId"` + BuyerID string `json:"buyerID"` + CloseOperateType string `json:"closeOperateType"` + TotalAmount float64 `json:"totalAmount"` + SellerID string `json:"sellerID"` + ShippingFee float64 `json:"shippingFee"` + Refund int `json:"refund"` + Status string `json:"status"` + RefundPayment int `json:"refundPayment"` + SellerContact struct { + Phone string `json:"phone"` + Email string `json:"email"` + ImInPlatform string `json:"imInPlatform"` + Name string `json:"name"` + Mobile string `json:"mobile"` + CompanyName string `json:"companyName"` + } `json:"sellerContact"` + CouponFee int `json:"couponFee"` + ReceiverInfo struct { + ToFullName string `json:"toFullName"` + ToDivisionCode string `json:"toDivisionCode"` + ToMobile string `json:"toMobile"` + ToPhone string `json:"toPhone"` + ToPost string `json:"toPost"` + ToArea string `json:"toArea"` + } `json:"receiverInfo"` + TradeType string `json:"tradeType"` + IDOfStr string `json:"idOfStr"` + StepPayAll bool `json:"stepPayAll"` + CreateTime string `json:"createTime"` + BusinessType string `json:"businessType"` + OverSeaOrder bool `json:"overSeaOrder"` + TradeTypeDesc string `json:"tradeTypeDesc"` + PayChannelList []string `json:"payChannelList"` + TradeTypeCode string `json:"tradeTypeCode"` + PayTimeout int `json:"payTimeout"` + PayTimeoutType int `json:"payTimeoutType"` + } `json:"baseInfo"` + OrderBizInfo struct { + OdsCyd bool `json:"odsCyd"` + CreditOrder bool `json:"creditOrder"` + } `json:"orderBizInfo"` + TradeTerms []struct { + Phase int64 `json:"phase"` + PayWayDesc string `json:"payWayDesc"` + ExpressPay bool `json:"expressPay"` + PayTime string `json:"payTime"` + PayStatusDesc string `json:"payStatusDesc"` + PayWay string `json:"payWay"` + CardPay bool `json:"cardPay"` + PayStatus string `json:"payStatus"` + PhasAmount float64 `json:"phasAmount"` + } `json:"tradeTerms"` + ProductItems []struct { + ItemAmount float64 `json:"itemAmount"` + Name string `json:"name"` + Price float64 `json:"price"` + ProductID int64 `json:"productID"` + ProductImgURL []string `json:"productImgUrl"` + ProductSnapshotURL string `json:"productSnapshotUrl"` + Quantity int `json:"quantity"` + Refund int `json:"refund"` + SkuID int64 `json:"skuID"` + Status string `json:"status"` + SubItemID int64 `json:"subItemID"` + Type string `json:"type"` + Unit string `json:"unit"` + GuaranteesTerms []struct { + AssuranceInfo string `json:"assuranceInfo"` + AssuranceType string `json:"assuranceType"` + QualityAssuranceType string `json:"qualityAssuranceType"` + } `json:"guaranteesTerms"` + ProductCargoNumber string `json:"productCargoNumber"` + SkuInfos []struct { + Name string `json:"name"` + Value string `json:"value"` + } `json:"skuInfos"` + EntryDiscount int `json:"entryDiscount"` + SpecID string `json:"specId"` + QuantityFactor int `json:"quantityFactor"` + StatusStr string `json:"statusStr"` + LogisticsStatus int `json:"logisticsStatus"` + GmtCreate string `json:"gmtCreate"` + GmtModified string `json:"gmtModified"` + GmtPayExpireTime string `json:"gmtPayExpireTime"` + SubItemIDString string `json:"subItemIDString"` + } `json:"productItems"` + NativeLogistics struct { + Address string `json:"address"` + Area string `json:"area"` + AreaCode string `json:"areaCode"` + City string `json:"city"` + ContactPerson string `json:"contactPerson"` + Mobile string `json:"mobile"` + Province string `json:"province"` + Telephone string `json:"telephone"` + Zip string `json:"zip"` + } `json:"nativeLogistics"` + GuaranteesTerms struct { + AssuranceInfo string `json:"assuranceInfo"` + AssuranceType string `json:"assuranceType"` + QualityAssuranceType string `json:"qualityAssuranceType"` + } `json:"guaranteesTerms"` + OrderRateInfo struct { + BuyerRateStatus int `json:"buyerRateStatus"` + SellerRateStatus int `json:"sellerRateStatus"` + } `json:"orderRateInfo"` + ExtAttributes []interface{} `json:"extAttributes"` + } `json:"result"` +} + +//Detail 订å•详情 +func (s *orderAli) Detail(ctx context.Context, orderSn string) (res *OrderDetailRes, err error) { + method := "com.alibaba.trade/alibaba.trade.get.buyerView" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "webSite": WebSite, + "orderId": orderSn, + }) + _ = gjson.New(result).Scan(&res) + return +} + +//Pay 支付 +func (s *orderAli) Pay(ctx context.Context, orderSn string) (res *CommonRes, err error) { + method := "com.alibaba.trade/alibaba.trade.pay.protocolPay.preparePay" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "tradeWithholdPreparePayParam":gjson.New(g.Map{"orderId":orderSn}).MustToJsonString(), + }) + _ = gjson.New(result).Scan(&res) + + return +} + + +type OrderBeforeRes struct { + CommonRes + OrderPreviewResuslt []OrderBeforeItem `json:"orderPreviewResuslt"` +} + +type OrderBeforeItem struct { + SumPayment int64 `json:"sumPayment"` //è®¢å•æ€»è´¹ç”¨, å•ä½ä¸ºåˆ† + SumPaymentNoCarriage int64 `json:"sumPaymentNoCarriage"` //ä¸åŒ…å«è¿è´¹çš„è´§å“æ€»è´¹ç”¨, å•ä½ä¸ºåˆ†. + SumCarriage int64 `json:"sumCarriage"` //总è¿è´¹ä¿¡æ¯, å•ä½ä¸ºåˆ†. + Status bool `json:"status"` // + ShopPromotionList []struct { //å¯ç”¨åº—é“ºçº§åˆ«ä¼˜æƒ åˆ—è¡¨ + PromotionId int64 `json:"promotionId"` //ä¼˜æƒ åˆ¸ID + } `json:"shopPromotionList"` //è§„æ ¼ä¿¡æ¯ + Message string `json:"message"` //è¿”å›žä¿¡æ¯ + CargoList []struct { + FinalUnitPrice float64 `json:"finalUnitPrice"` //最终å•ä»· + SpecId string `json:"specId"` //è§„æ ¼ID,offer内唯一 + OfferId string `json:"offerId"` //商å“ID + SkuId int64 `json:"skuId"` //è§„æ ¼ID + } `json:"cargoList"` //è§„æ ¼ä¿¡æ¯ +} + +//Before 验è¯è®¢å•å•†å“ +func (s *orderAli) Before(ctx context.Context, req *OrderCommonReq) (res *OrderBeforeRes, err error) { + method := "com.alibaba.trade/alibaba.createOrder.preview" + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "addressParam": gjson.New(req.AddressParam).MustToJsonString(), + "cargoParamList": gjson.New(req.CargoParam).MustToJsonString(), + "flow": "ttpft", + }) + _ = gjson.New(result).Scan(&res) + return +} diff --git a/upstream/aliNew/ali_refund.go b/upstream/aliNew/ali_refund.go new file mode 100644 index 0000000..c4d8e22 --- /dev/null +++ b/upstream/aliNew/ali_refund.go @@ -0,0 +1,274 @@ +package aliNew + +import ( + "context" + "encoding/base64" + "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/util/gconv" +) + +type refundAli struct { +} + +var Refund = refundAli{} + +type RefundApplyReq struct { + OrderId string `json:"orderId"` //ä¸»è®¢å• + OrderEntryIds string `json:"orderEntryIds"` //åè®¢å• + DisputeRequest string `json:"disputeRequest"` //退款/é€€æ¬¾é€€è´§ã€‚åªæœ‰å·²æ”¶åˆ°è´§ï¼Œæ‰å¯ä»¥é€‰æ‹©é€€æ¬¾é€€è´§[退款:"refund"; 退款退货:"returnRefund"] + ApplyPayment string `json:"applyPayment"` //退款金é¢ï¼ˆå•ä½ï¼šåˆ†ï¼‰ + ApplyCarriage string `json:"applyCarriage"` //退è¿è´¹é‡‘é¢ï¼ˆå•ä½ï¼šåˆ†ï¼‰ + ApplyReasonId string `json:"applyReasonId"` //é€€æ¬¾åŽŸå› id + Description string `json:"description"` //退款申请ç†ç”±ï¼Œ2-150å— + GoodsStatus string `json:"goodsStatus"` //货物状æ€[å”®ä¸ç‰å¾…å–å®¶å‘è´§:"refundWaitSellerSend"; å”®ä¸ç‰å¾…ä¹°å®¶æ”¶è´§:"refundWaitBuyerReceive"; å”®ä¸å·²æ”¶è´§ï¼ˆæœªç¡®è®¤å®Œæˆäº¤æ˜“):"refundBuyerReceived" å”®åŽæœªæ”¶è´§:"aftersaleBuyerNotReceived"; å”®åŽå·²æ”¶åˆ°è´§:"aftersaleBuyerReceived"] + Vouchers []string `json:"vouchers"` //å‡è¯å›¾ç‰‡URLs。1-5å¼ ï¼Œå¿…é¡»ä½¿ç”¨API uploadRefundVoucher返回的“图片域å/相对路径†+ OrderEntryCountList string `json:"orderEntryCountList"` //å订å•退款数é‡ã€‚仅在售ä¸ä¹°å®¶å·²æ”¶è´§ï¼ˆé€€æ¬¾é€€è´§ï¼‰æ—¶ï¼Œå¯æŒ‡å®šé€€è´§æ•°é‡ï¼›é»˜è®¤ï¼Œå…¨éƒ¨é€€è´§ã€‚ + AccessToken string `json:"access_token"` +} + +type RefundApplyItem struct { + Id int64 `json:"id"` //å订å•id + Count int64 `json:"count"` //å订å•è´ä¹°å•†å“æ•°é‡ +} + +type RefundApplyRes struct { + Result struct { + Success bool `json:"success"` + Code string `json:"code"` + Message string `json:"message"` + Result struct { + RefundId string `json:"refundId"` // 创建æˆåŠŸï¼Œé€€æ¬¾id + } `json:"result"` + } `json:"result"` +} + +type RefundReasonReq struct { + OrderId string `json:"orderId"` //主订å•id + OrderEntryIds []string `json:"orderEntryIds"` //å订å•id + GoodsStatus string `json:"goodsStatus"` //è´§ç‰©çŠ¶æ€ å”®ä¸ç‰å¾…ä¹°å®¶å‘è´§:â€refundWaitSellerSend"; å”®ä¸ç‰å¾…ä¹°å®¶æ”¶è´§:"refundWaitBuyerReceive"; å”®ä¸å·²æ”¶è´§ï¼ˆæœªç¡®è®¤å®Œæˆäº¤æ˜“):"refundBuyerReceived" å”®åŽæœªæ”¶è´§:"aftersaleBuyerNotReceived"; å”®åŽå·²æ”¶åˆ°è´§:"aftersaleBuyerReceived" + AccessToken string `json:"access_token"` +} + +type RefundReasonRes struct { + Result struct { + CommonRes + Result struct { + Reasons []struct { + ID int `json:"id"` //åŽŸå› id + Name string `json:"name"` //åŽŸå› + NeedVoucher bool `json:"needVoucher"` //å‡è¯æ˜¯å¦å¿…é¡»ä¸Šä¼ + NoRefundCarriage bool `json:"noRefundCarriage"` //æ˜¯å¦æ”¯æŒé€€è¿è´¹ + Tip string `json:"tip,omitempty"` //æç¤º + } `json:"reasons"` + } `json:"result"` + } `json:"result"` +} + +type RefundUploadRes struct { + Result struct { + CommonRes + Result struct { + ImageDomain string `json:"imageDomain"` + ImageRelativeURL string `json:"imageRelativeUrl"` + } `json:"result"` + } `json:"result"` +} +type RefundInfoReq struct { + RefundId string `json:"refundId"` + NeedTimeOutInfo bool `json:"needTimeOutInfo"` + NeedOrderRefundOperation bool `json:"needOrderRefundOperation"` + AccessToken string `json:"access_token"` +} + +type RefundInfoRes struct { + CommonRes + Result struct { + OpOrderRefundModelDetail struct { + AlipayPaymentId string `json:"alipayPaymentId"` + ApplyCarriage int `json:"applyCarriage"` + ApplyPayment int `json:"applyPayment"` + ApplyReason string `json:"applyReason"` + ApplyReasonId int `json:"applyReasonId"` + ApplySubReasonId int `json:"applySubReasonId"` + BuyerMemberId string `json:"buyerMemberId"` + BuyerSendGoods bool `json:"buyerSendGoods"` + BuyerUserId int `json:"buyerUserId"` + CanRefundPayment int `json:"canRefundPayment"` + CrmModifyRefund bool `json:"crmModifyRefund"` + DisputeRequest int `json:"disputeRequest"` + DisputeType int `json:"disputeType"` + ExtInfo struct { + Enfunddetail string `json:"enfunddetail"` + BizCode string `json:"bizCode"` + LastOrder string `json:"lastOrder"` + Tod string `json:"tod"` + NewRefund string `json:"newRefund"` + BFsc string `json:"b_fsc"` + AgreeReturnMsg string `json:"agree_return_msg"` + OpRole string `json:"opRole"` + B2BBuyerMId string `json:"b2b_buyer_mId"` + ApplyReasonText string `json:"apply_reason_text"` + ApplyInitRefundFee string `json:"apply_init_refund_fee"` + ItemBuyAmount string `json:"itemBuyAmount"` + UserCredit string `json:"userCredit"` + SdkCode string `json:"sdkCode"` + InterceptItemListResult string `json:"interceptItemListResult"` + InterceptStatus string `json:"interceptStatus"` + SellerBatch string `json:"seller_batch"` + RestartForXiaoer string `json:"restartForXiaoer"` + CljZeroSecondRefund string `json:"clj_zero_second_refund"` + Tos string `json:"tos"` + BsSync string `json:"bs_sync"` + OlTf string `json:"ol_tf"` + BPf string `json:"b_pf"` + Sgr string `json:"sgr"` + PartRefund string `json:"part_refund"` + Bgmtc string `json:"bgmtc"` + PayMode string `json:"payMode"` + AppName string `json:"appName"` + SellerDoRefundNick string `json:"sellerDoRefundNick"` + WorkflowName string `json:"workflowName"` + Ttid string `json:"ttid"` + SellerAudit string `json:"seller_audit"` + Rp3 string `json:"rp3"` + SellerAgreedRefundFee string `json:"seller_agreed_refund_fee"` + B2BBt string `json:"b2b_bt"` + B2BExchange string `json:"b2b_exchange"` + ItemPrice string `json:"itemPrice"` + IsVirtual string `json:"isVirtual"` + EXmrf string `json:"EXmrf"` + B2BSellerMId string `json:"b2b_seller_mId"` + BCfRsc string `json:"b_cf_rsc"` + } `json:"extInfo"` + FrozenFund int `json:"frozenFund"` + GmtApply string `json:"gmtApply"` + GmtCompleted string `json:"gmtCompleted"` + GmtCreate string `json:"gmtCreate"` + GmtModified string `json:"gmtModified"` + GmtTimeOut string `json:"gmtTimeOut"` + GoodsReceived bool `json:"goodsReceived"` + GoodsStatus int `json:"goodsStatus"` + Id int64 `json:"id"` + NewRefundReturn bool `json:"newRefundReturn"` + OnlyRefund bool `json:"onlyRefund"` + OrderEntryIdList []int64 `json:"orderEntryIdList"` + OrderId int64 `json:"orderId"` + ProductName string `json:"productName"` + RefundCarriage int `json:"refundCarriage"` + RefundGoods bool `json:"refundGoods"` + RefundId string `json:"refundId"` + RefundPayment int `json:"refundPayment"` + RejectReasonId int `json:"rejectReasonId"` + RejectReason string `json:"rejectReason"` // æ‹’ç»åŽŸå› + RejectTimes int `json:"rejectTimes"` + SellerDelayDisburse bool `json:"sellerDelayDisburse"` + SellerMemberId string `json:"sellerMemberId"` + SellerMobile string `json:"sellerMobile"` + SellerRealName string `json:"sellerRealName"` + SellerReceiveAddress string `json:"sellerReceiveAddress"` + SellerUserId int64 `json:"sellerUserId"` + Status string `json:"status"` + SupportNewSteppay bool `json:"supportNewSteppay"` + TimeOutFreeze bool `json:"timeOutFreeze"` + TradeTypeStr string `json:"tradeTypeStr"` + RefundOperationList []struct { + AfterOperateStatus string `json:"afterOperateStatus,omitempty"` + BeforeOperateStatus string `json:"beforeOperateStatus,omitempty"` + CloseRefundStepId int `json:"closeRefundStepId"` + CrmModifyRefund bool `json:"crmModifyRefund"` + Discription string `json:"discription"` + GmtCreate string `json:"gmtCreate"` + GmtModified string `json:"gmtModified"` + Id int64 `json:"id"` + MessageStatus int `json:"messageStatus"` + MsgType int `json:"msgType"` + OperateRemark string `json:"operateRemark"` + OperateTypeInt int `json:"operateTypeInt"` + OperatorLoginId string `json:"operatorLoginId"` + OperatorRoleId int `json:"operatorRoleId"` + OperatorUserId int64 `json:"operatorUserId"` + RefundId string `json:"refundId"` + } `json:"refundOperationList"` + BuyerLoginId string `json:"buyerLoginId"` + SellerLoginId string `json:"sellerLoginId"` + } `json:"opOrderRefundModelDetail"` + } `json:"result"` +} + +type RefundSubmitReq struct { + RefundId string `json:"refundId"` //退款å•å·ï¼ŒTQ开头 + CompanyNo string `json:"logisticsCompanyNo"` //物æµå…¬å¸ç¼–ç ,调用alibaba.logistics.OpQueryLogisticCompanyList.offlineæŽ¥å£æŸ¥è¯¢ + ExpressSn string `json:"freightBill"` //物æµå…¬å¸è¿å•å·ï¼Œè¯·å‡†ç¡®å¡«å†™ï¼Œå¦åˆ™å–å®¶æœ‰æƒæ‹’ç»é€€æ¬¾ + Description string `json:"description"` //å‘货说明,内容在2-200个å—之间 + Vouchers []string `json:"vouchers,omitempty"` //å‡è¯å›¾ç‰‡URLs,必须使用API alibaba.trade.uploadRefundVoucher返回的“图片域å/相对路径â€ï¼Œæœ€å¤šå¯ä¸Šä¼ 10 å¼ å›¾ç‰‡ ï¼›å•å¼ å¤§å°ä¸è¶…过1M;支æŒjpgã€gifã€jpegã€pngã€å’Œbmpæ ¼å¼ã€‚ è¯·ä¸Šä¼ å‡è¯ï¼Œä»¥ä¾¿ä»¥åŽç»èµ”所需(ä¸ä¸Šä¼ å°†æ— æ³•ç†èµ”) + AccessToken string `json:"access_token"` +} + +type RefundSubmitRes struct { + Result struct { + CommonRes + } `json:"result"` +} + +//Apply 创建退款退货申请 +func (refundAli) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes, err error) { + method := "com.alibaba.trade/alibaba.trade.createRefund" + + req.AccessToken = server.AccessToken + result, err := server.Post(ctx, method, gconv.Map(req)) + _ = gjson.New(result).Scan(&res) + return +} + +//Reason 获å–退æ¢è´§åŽŸå› +func (*refundAli) Reason(ctx context.Context, req *RefundReasonReq) (res *RefundReasonRes, err error) { + method := "com.alibaba.trade/alibaba.trade.getRefundReasonList" + + req.AccessToken = server.AccessToken + result, err := server.Post(ctx, method, gconv.Map(req)) + _ = gjson.New(result).Scan(&res) + return +} + +// Upload ä¸Šä¼ é€€æ¬¾é€€è´§å‡è¯ +func (*refundAli) Upload(ctx context.Context, ImgBase64 string) (res *RefundUploadRes, err error) { + method := "com.alibaba.trade/alibaba.trade.uploadRefundVoucher" + dist, _ := base64.StdEncoding.DecodeString(ImgBase64) + + var imgArr = garray.New() + for i := range dist { + imgArr.Append(dist[i]) + } + + result, err := server.Post(ctx, method, g.Map{ + "access_token": server.AccessToken, + "imageData": "[" + imgArr.Join(",") + "]", + }) + _ = gjson.New(result).Scan(&res) + return +} + +//Info 查询退款å•详情-æ ¹æ®é€€æ¬¾å•ID +func (*refundAli) Info(ctx context.Context, refundId string) (res *RefundInfoRes, err error) { + method := "com.alibaba.trade/alibaba.trade.refund.OpQueryOrderRefund" + + var req = &RefundInfoReq{ + RefundId: refundId, + NeedOrderRefundOperation: true, + AccessToken: server.AccessToken, + } + result, err := server.Post(ctx, method, gconv.Map(req)) + _ = gjson.New(result).Scan(&res) + return +} + +//Submit æäº¤é€€æ¬¾è´§ä¿¡æ¯ +func (*refundAli) Submit(ctx context.Context, req *RefundSubmitReq) (res *RefundSubmitRes, err error) { + method := "com.alibaba.trade/alibaba.trade.refund.returnGoods" + req.AccessToken = server.AccessToken + result, err := server.Post(ctx, method, gconv.Map(req)) + _ = gjson.New(result).Scan(&res) + return +} diff --git a/upstream/upstream.go b/upstream/upstream.go index a87143c..a923fb2 100644 --- a/upstream/upstream.go +++ b/upstream/upstream.go @@ -18,6 +18,7 @@ const ( Itao = 15 //淘特 Hdh = 16 //会订货 TmNew = 17 //新版天猫 + AliNew = 18//精选1688 ) var ( @@ -91,6 +92,10 @@ func GetUpstreamList() (res interface{}, err error) { "key": TmNew, "name": GetUpstreamName(TmNew), }, + g.Map{ + "key": AliNew, + "name": GetUpstreamName(AliNew), + }, } return } @@ -123,6 +128,8 @@ func GetUpstreamName(source int) string { return "会订货" case TmNew: return "天猫精选" + case AliNew: + return "厂家直供" default: return "æœªçŸ¥æ¥æº" } -- 2.18.1