提交 29eff638 authored 作者: gukai's avatar gukai

Merge branch 'aliNew'

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
}
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
}
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
}
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
}
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
}
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
}
......@@ -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 "未知来源"
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论