提交 cb1f462f authored 作者: 张立波's avatar 张立波

log

上级 84d6686c
......@@ -203,7 +203,7 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) {
err = NsqProducers.Publish(notifyMsg, gjson.New(notifyMessage).MustToJsonString())
if err != nil {
g.Log().Cat("NotifyMessage").Cat("error").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyMessage).MustToJsonString(), err.Error())
g.Log().Cat("NotifyMessage").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyMessage).MustToJsonString(), err.Error())
} else {
g.Log().Cat("NotifyMessage").Infof(`消息内容【%v】`, gjson.New(notifyMessage).MustToJsonString())
}
......@@ -219,7 +219,7 @@ func (p *NsqProducer) NotifyApiLog(notifyApiLog *NotifyApiLog) (err error) {
jsonBytes, _ := json.Marshal(notifyApiLog)
err = NsqProducers.Publish(ApiRequestTopic, string(jsonBytes))
if err != nil {
g.Log().Cat("NotifyApiLog").Cat("error").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyApiLog).MustToJsonString(), err.Error())
g.Log().Cat("NotifyApiLog").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyApiLog).MustToJsonString(), err.Error())
} else {
g.Log().Cat("NotifyApiLog").Infof(`消息内容【%v】`, gjson.New(notifyApiLog).MustToJsonString())
}
......
......@@ -41,7 +41,7 @@ func InitProducer(config *NsqConfig) {
}
//Publish 发布消息
// Publish 发布消息
func (p *NsqProducer) Publish(topic string, message string) (err error) {
InitProducer(nsqConfig)
......@@ -51,9 +51,9 @@ func (p *NsqProducer) Publish(topic string, message string) (err error) {
}
err = NsqProducers.producer.Publish(topic, []byte(message)) // 发布消息
if err != nil {
g.Log().Cat("Producer").Cat("error").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
g.Log().Cat("producer").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
} else {
g.Log().Cat("Producer").Infof(`消息内容【%v】`, message)
g.Log().Cat("producer").Infof(`消息内容【%v】`, message)
}
return
}
......@@ -61,7 +61,7 @@ func (p *NsqProducer) Publish(topic string, message string) (err error) {
return fmt.Errorf("producer is nil", err)
}
//DeferredPublish 发布延迟消息
// DeferredPublish 发布延迟消息
func (p *NsqProducer) DeferredPublish(topic string, delay time.Duration, message string) (err error) {
InitProducer(nsqConfig)
if NsqProducers.producer != nil {
......@@ -70,9 +70,9 @@ func (p *NsqProducer) DeferredPublish(topic string, delay time.Duration, message
}
err = NsqProducers.producer.DeferredPublish(topic, delay, []byte(message)) // 发布消息
if err != nil {
g.Log().Cat("Producer").Cat("error").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
g.Log().Cat("producer").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
} else {
g.Log().Cat("Producer").Infof(`消息内容【%v】`, message)
g.Log().Cat("producer").Infof(`消息内容【%v】`, message)
}
return err
}
......
......@@ -86,7 +86,7 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
}
......
......@@ -93,7 +93,7 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes,
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start)
}
......
package gome
import (
"context"
"errors"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gutil"
"time"
)
type Config struct {
ApiUrl string
AppKey string
AppSecret string
Version string
}
type Client struct {
*Config
AccessToken string
RefreshToken string
}
type CommonReq struct {
AppKey string `json:"app_key"`
Version string `json:"version"`
Method string `json:"method"`
AccessToken string `json:"access_token"`
Timestamp string `json:"timestamp"`
Param interface{} `json:"param"`
Sign string `json:"sign,omitempty"`
}
type CommonPageReq struct {
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
}
type CommonPageRes struct {
PageSize int `json:"pageSize"`
PageNo int `json:"pageNo"`
TotalPage int `json:"totalPage"`
TotalCount int `json:"totalCount"`
}
type CommonRes struct {
Code string `json:"code"`
Message string `json:"message"`
SubCode string `json:"sub_code"`
SubMsg string `json:"sub_msg"`
}
var server *Client
const PkgName = "gome"
const CacheKey = "gome:token"
func New(config *Config) {
_ = gconv.Struct(config, &server)
return
}
func (s *Client) sign(req g.Map) string {
data := gjson.New(req)
_ = data.Remove("sign")
return gstr.ToUpper(gmd5.MustEncryptString(server.AppSecret + data.MustToJsonString() + server.AppSecret))
}
func (s *Client) post(ctx context.Context, method string, req interface{}) (str string, err error) {
Start := gtime.TimestampMilli()
allparams := &CommonReq{
AppKey: server.AppKey,
Version: server.Version,
Method: method,
AccessToken: server.AccessToken,
Timestamp: gtime.Now().String(),
Param: req,
}
allparams.Sign = s.sign(gconv.Map(allparams))
Request := g.Client()
Request.SetHeader("Content-Type", "application/json")
resp, err := Request.Timeout(time.Second*5).Post(server.ApiUrl, allparams)
defer func() {
_ = resp.Close()
paramStr := gjson.New(req).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
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
}
func (s *Client) requestApi(ctx context.Context, method string, req interface{}) (str string, err error) {
err = s.getAccessToken(ctx)
if err != nil {
return
}
str, err = s.post(ctx, method, req)
return
}
type accessToken struct {
AppKey string `json:"appKey"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresInSeconds int64 `json:"expiresInSeconds"`
CreateTime string `json:"createTime"`
}
//getAccessToken 获取token
func (s *Client) getAccessToken(ctx context.Context) (err error) {
var token *accessToken
cache, _ := g.Redis().DoVar("HGETALL", CacheKey)
if !cache.IsEmpty() {
_ = cache.Scan(&token)
if gtime.NewFromStr(token.CreateTime).Timestamp()+token.ExpiresInSeconds > gtime.Timestamp()-3600 {
s.AccessToken = token.AccessToken
return
}
return s.refreshToken(ctx, token)
}
res, err := Token.Get(ctx)
if err != nil {
return
}
if res.Code != "4000" {
err = errors.New(res.Message)
return
}
_, _ = g.Redis().Do("HMSET", append(g.Slice{CacheKey}, gutil.MapToSlice(gconv.Map(res.Data))...)...)
s.AccessToken = res.Data.AccessToken
return
}
//refreshToken 刷新token
func (s *Client) refreshToken(ctx context.Context, req *accessToken) (err error) {
if gtime.NewFromStr(req.CreateTime).Timestamp()+req.ExpiresInSeconds < gtime.Timestamp() {
_, err = g.Redis().DoVar("DEL", CacheKey)
return s.getAccessToken(ctx)
}
res, err := Token.Refresh(ctx, req.RefreshToken)
if err != nil {
return
}
if res.Code != "4000" {
err = errors.New(res.Message)
return
}
_, _ = g.Redis().Do("HMSET", append(g.Slice{CacheKey}, gutil.MapToSlice(gconv.Map(res.Data))...)...)
s.AccessToken = res.Data.AccessToken
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type addressGome struct {
}
var Address = addressGome{}
type AddressCommonRes struct {
*CommonRes
Data struct {
AreaDtoList []struct {
AreaCode string `json:"areaCode"`
AreaLevel int `json:"areaLevel"`
ParentCode string `json:"parentCode"`
AreaName string `json:"areaName"`
Status int `json:"status"`
} `json:"areaDtoList"`
} `json:"data"`
}
//Province 省
func (addressGome) Province(ctx context.Context) (res *AddressCommonRes, err error) {
method := "alamein.basic.get.province"
req := g.Map{}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
func (addressGome) City(ctx context.Context, pid string) (res *AddressCommonRes, err error) {
method := "alamein.basic.get.city"
req := g.Map{
"parentCode": pid,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
func (addressGome) County(ctx context.Context, pid string) (res *AddressCommonRes, err error) {
method := "alamein.basic.get.county"
req := g.Map{
"parentCode": pid,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
func (addressGome) Town(ctx context.Context, pid string) (res *AddressCommonRes, err error) {
method := "alamein.basic.get.town"
req := g.Map{
"parentCode": pid,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
)
type brandGome struct {
}
var Brand = brandGome{}
type BrandRes struct {
*CommonRes
Data struct {
*CommonPageRes
Result []struct {
Code string `json:"code"`
Name string `json:"name"`
} `json:"result"`
} `json:"data"`
}
//Get 品牌列表
func (brandGome) Get(ctx context.Context, req *CommonPageReq) (res *BrandRes, err error) {
method := "alemein.basic.get.brand"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type categoryGome struct {
}
var Category = categoryGome{}
type CategoryRes struct {
*CommonRes
Data []struct {
Code string `json:"code"`
Level int `json:"level"`
ParentCode string `json:"parentCode"`
Name string `json:"name"`
} `json:"data"`
}
type CategoryPropertyRes struct {
*CommonRes
Data struct {
SaleProperties []struct {
PropertyID int `json:"propertyId"`
PropertyName string `json:"propertyName"`
PropertyType string `json:"propertyType"`
Required int `json:"required"`
} `json:"saleProperties"`
PropertyGroups []struct {
GroupID int `json:"groupId"`
GroupName string `json:"groupName"`
SpecProperties []struct {
PropertyID int `json:"propertyId"`
PropertyName string `json:"propertyName"`
PropertyType string `json:"propertyType"`
} `json:"specProperties"`
} `json:"propertyGroups"`
} `json:"data"`
}
//Get 分类列表
func (categoryGome) Get(ctx context.Context, pid ...interface{}) (res *CategoryRes, err error) {
method := "alemein.basic.get.category"
req := g.Map{}
if len(pid) > 0 {
req["parentCode"] = pid[0]
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Property 获取品类商品属性
//`categoryId` 平台三级分类代码
func (goodsGome) Property(ctx context.Context, categoryId string) (res *CategoryPropertyRes, err error) {
method := "alamein.supplier.product.cat.get.property"
req := g.Map{
"categoryId": categoryId,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
差异被折叠。
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type logisticsGome struct {
}
var Logistics = logisticsGome{}
type GetLogisticsRes struct {
*CommonRes
Data struct {
LogisticsDtoList []struct {
LogisticsCode string `json:"logisticsCode"`
LogisticsName string `json:"logisticsName"`
} `json:"logisticsDtoList"`
} `json:"data"`
}
func (logisticsGome) Get(ctx context.Context) (res *GetLogisticsRes, err error) {
method := "alemein.basic.get.logistics"
req := g.Map{}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type orderGome struct {
}
var Order = orderGome{}
type CreateOrderReq struct {
OuterOrderId string `json:"outerOrderId"`
OnlinePayAmount int `json:"onlinePayAmount"`
ConsigneeInfo struct {
ReceiverName string `json:"receiverName"`
ReceiverMobile int64 `json:"receiverMobile"`
County int `json:"county"`
Town int `json:"town"`
StateName string `json:"stateName"`
CityName string `json:"cityName"`
CountyName string `json:"countyName"`
TownName string `json:"townName"`
DetailAddress string `json:"detailAddress"`
} `json:"consigneeInfo"`
SkuItems []struct {
OuterSkuItemId string `json:"outerSkuItemId"`
MchSkuId int `json:"mchSkuId"`
Quantity int `json:"quantity"`
DealPrice int `json:"dealPrice"`
MchWhseCode string `json:"mchWhseCode"`
} `json:"skuItems"`
}
type CreateOrderRes struct {
*CommonRes
Data bool `json:"data"`
}
type OrderInfoRes struct {
*CommonRes
Data struct {
OuterOrderId string `json:"outerOrderId"`
Finished string `json:"finished"`
DeliveryOrderList []struct {
DeliveryId string `json:"deliveryId"`
DeliveryStatus string `json:"deliveryStatus"`
SkuItemList []struct {
SkuItemId string `json:"skuItemId"`
OuterSkuItemId string `json:"outerSkuItemId"`
MchSkuId string `json:"mchSkuId"`
Quantity int `json:"quantity"`
} `json:"skuItemList"`
} `json:"deliveryOrderList"`
} `json:"data"`
}
type OrderStatusRes struct {
*CommonRes
Data struct {
DeliveryId string `json:"deliveryId"`
CurrentStatus string `json:"currentStatus"`
CurrentStatusTime string `json:"currentStatusTime"`
PastStatuses []struct {
Status string `json:"status"`
StatusTime string `json:"statusTime"`
} `json:"pastStatuses"`
} `json:"data"`
}
type OrderLogisticsRes struct {
*CommonRes
Data struct {
DeliveryId string `json:"deliveryId"`
CompanyCode string `json:"companyCode"`
CompanyName string `json:"companyName"`
CompanyPhone string `json:"companyPhone"`
WaybillCode string `json:"waybillCode"`
CourierName string `json:"courierName"`
CourierPhone string `json:"courierPhone"`
Tracks []struct {
TrackTime string `json:"trackTime"`
Description string `json:"description"`
} `json:"tracks"`
} `json:"data"`
}
type OrderCancelReq struct {
DeliveryId string `json:"deliveryId"`
OuterOrderId string `json:"outerOrderId"`
CancelTime string `json:"cancelTime"`
}
//Create 提交订单
func (orderGome) Create(ctx context.Context, req *CreateOrderReq) (res *CreateOrderRes, err error) {
method := "alamein.order.write.submitAndConfirm"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Info 订单详情
func (orderGome) Info(ctx context.Context, sn string) (res *OrderInfoRes, err error) {
method := "alamein.order.read.querySubmitAndConfirmResult"
var req = g.Map{
"outerOrderId": sn,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Status 订单关键状态查询
func (orderGome) Status(ctx context.Context, deliveryId string) (res *OrderStatusRes, err error) {
method := "alamein.order.read.queryKeyStatus"
var req = g.Map{
"deliveryId": deliveryId,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Logistics 物流
func (orderGome) Logistics(ctx context.Context, deliveryId string) (res *OrderLogisticsRes, err error) {
method := "alamein.order.read.queryLogisticsTrack"
var req = g.Map{
"deliveryId": deliveryId,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Cancel 支付后取消申请
func (orderGome) Cancel(ctx context.Context, req *OrderCancelReq) (res *CommonRes, err error) {
method := "alamein.order.read.queryLogisticsTrack"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type refundGome struct {
}
var Refund = refundGome{}
type ReturnCountReq struct {
DeliveryId string `json:"deliveryId"`
OuterOrderId string `json:"outerOrderId"`
SkuItemId string `json:"skuItemId"`
MchSkuId string `json:"mchSkuId"`
}
type ReturnCountRes struct {
*CommonRes
Data struct {
ReturnableQuantity int `json:"returnableQuantity"`
} `json:"data"`
}
type ServiceTypeReq struct {
DeliveryId string `json:"deliveryId"`
AddrCode string `json:"addrCode"`
SkuItemId string `json:"skuItemId"`
MchSkuId string `json:"mchSkuId"`
OuterOrderId string `json:"outerOrderId"`
}
type ServiceTypeRes struct {
*CommonRes
Data struct {
AfterServiceTypes []struct {
Code int `json:"code"`
Name string `json:"name"`
} `json:"afterServiceTypes"`
ReturnWareTypes []struct {
Code int `json:"code"`
Name string `json:"name"`
} `json:"returnWareTypes"`
} `json:"data"`
}
type RefundCreateReq struct {
AfterServiceType string `json:"afterServiceType"`
OuterAfterServiceId string `json:"outerAfterServiceId"`
SubmitTime string `json:"submitTime"`
OriginalOuterOrderId string `json:"originalOuterOrderId"`
OuterOrderId string `json:"outerOrderId"`
OriginalDeliveryId string `json:"originalDeliveryId"`
ReturnType string `json:"returnType"`
ReturnWareType string `json:"returnWareType"`
RefundAmount string `json:"refundAmount"`
PickWareInfo string `json:"pickWareInfo"`
PickWareTime string `json:"pickWareTime"`
Name string `json:"name"`
Phone string `json:"phone"`
Address string `json:"address"`
AddressCode string `json:"addressCode"`
AddressDetail string `json:"addressDetail"`
Address1 string `json:"address1"`
Address2 string `json:"address2"`
Address3 string `json:"address3"`
Address4 string `json:"address4"`
SkuItems struct {
OuterSkuItemId string `json:"outerSkuItemId"`
OriginalSkuItemId string `json:"originalSkuItemId"`
MchSkuId string `json:"mchSkuId"`
SkuQuantity string `json:"skuQuantity"`
SkuName string `json:"skuName"`
DealPrice string `json:"dealPrice"`
} `json:"skuItems"`
AfterSaleImages struct {
ImageInx string `json:"imageInx"`
ImageType string `json:"imageType"`
ImageUrl string `json:"imageUrl"`
} `json:"afterSaleImages"`
}
type RefundCreateRes struct {
*CommonRes
Data struct {
AfterServiceId string `json:"afterServiceId"`
} `json:"data"`
}
type RefundCancelReq struct {
AfterServiceType string `json:"afterServiceType"`
OutOrderId string `json:"outOrderId"`
CancelTime string `json:"cancelTime"`
CancelReasonType string `json:"cancelReasonType"`
CancelReasonDesc string `json:"cancelReasonDesc"`
}
type RefundAuditResultReq struct {
}
type RefundAuditResultRes struct {
*CommonRes
Data struct {
GomeAfterServiceId string `json:"gomeAfterServiceId"`
AuditPassed int `json:"auditPassed"`
AuditTime string `json:"auditTime"`
RejectedReasonType string `json:"rejectedReasonType"`
RejectedReasonDesc string `json:"rejectedReasonDesc"`
ReturnWareType string `json:"returnWareType"`
ServiceAddressInfo struct {
Address string `json:"address"`
Linkman string `json:"linkman"`
Phone string `json:"phone"`
} `json:"serviceAddressInfo"`
} `json:"data"`
}
type RefundSendReq struct {
AfterServiceId string `json:"afterServiceId"`
OuterOrderId string `json:"outerOrderId"`
DeliveryCompanyCode string `json:"deliveryCompanyCode"`
DeliveryCompanyName string `json:"deliveryCompanyName"`
WaybillCode string `json:"waybillCode"`
}
type RefundStatusRes struct {
*CommonRes
Data struct {
AfterServiceId string `json:"afterServiceId"`
CurrentStatus string `json:"currentStatus"`
CurrentStatusTime interface{} `json:"currentStatusTime"`
PastStatuses []struct {
Status string `json:"status"`
StatusTime string `json:"statusTime"`
} `json:"pastStatuses"`
} `json:"data"`
}
type RefundLogisticsRes struct {
*CommonRes
Data struct {
AfterServiceId string `json:"afterServiceId"`
CompanyCode string `json:"companyCode"`
CompanyName string `json:"companyName"`
CompanyPhone string `json:"companyPhone"`
WaybillCode string `json:"waybillCode"`
CourierName string `json:"courierName"`
CourierPhone string `json:"courierPhone"`
Tracks []struct {
TrackTime string `json:"trackTime"`
Description string `json:"description"`
} `json:"tracks"`
} `json:"data"`
}
//ReturnCount 商品可退货数量
func (refundGome) ReturnCount(ctx context.Context, req *ReturnCountReq) (res *ReturnCountRes, err error) {
method := "alamein.afterSale.read.queryCanReturnCount"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//ServiceType 查询可服务类型及退回方式
func (refundGome) ServiceType(ctx context.Context, req *ServiceTypeReq) (res *ServiceTypeRes, err error) {
method := "alamein.afterSale.read.queryCanServiceTypeAndReturnType"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Create 申请
func (refundGome) Create(ctx context.Context, req *RefundCreateReq) (res *RefundCreateRes, err error) {
method := "alamein.afterSale.write.submit"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Cancel 取消售后订单
func (refundGome) Cancel(ctx context.Context, req *RefundCancelReq) (res *CommonRes, err error) {
method := "alamein.afterSale.write.cancel"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
func (refundGome) AuditResult(ctx context.Context, refundSn string) (res *RefundAuditResultRes, err error) {
method := "alamein.afterSale.read.queryAuditResult"
var req = g.Map{
"afterServiceId": refundSn,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Send 顾客邮寄运单信息填写
func (refundGome) Send(ctx context.Context, req *RefundSendReq) (res *RefundSendReq, err error) {
method := "alamein.afterSale.write.deliveryByCustomer"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Status 状态查询
func (refundGome) Status(ctx context.Context, refundSn string) (res *RefundStatusRes, err error) {
method := "alamein.afterSale.read.queryKeyStatus"
var req = g.Map{
"afterServiceId": refundSn,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//Logistics 接收售后订单商品验货信息
func (refundGome) Logistics(ctx context.Context, refundSn string) (res *RefundLogisticsRes, err error) {
method := "alamein.afterSale.read.queryLogisticsTrack"
var req = g.Map{
"afterServiceId": refundSn,
}
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
)
type stockGome struct {
}
var Stock = stockGome{}
type GetWarehouseRes struct {
*CommonRes
Data struct {
*CommonPageRes
Data []struct {
MchWhseCode string `json:"mchWhseCode"`
MchWhseName string `json:"mchWhseName"`
IsNationWide int `json:"isNationWide"`
Status int `json:"status"`
LastUpateTime string `json:"lastUpateTime"`
} `json:"data"`
} `json:"data"`
}
type CoverAreaReq struct {
MchWhseCode string `json:"mchWhseCode"`
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
}
type SaleAbleReq struct {
WhseSkuList []*SaleAbleItem `json:"whseSkuList"`
}
type SaleAbleItem struct {
MchWhseCode string `json:"mchWhseCode"`
MchSkuId string `json:"mchSkuId"`
}
type SaleAbleRes struct {
*CommonRes
Data []struct {
MchWhseCode string `json:"mchWhseCode"`
MchSkuId string `json:"mchSkuId"`
SaleableQty string `json:"saleableQty"`
} `json:"data"`
}
//GetWarehouse 分页查询商户仓库信息
func (stockGome) GetWarehouse(ctx context.Context, req *CommonPageReq) (res *GetWarehouseRes, err error) {
method := "alamein.stock.read.pageQueryWarehouse"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//CoverArea 分页查询仓市关系列表-按仓 todo
func (stockGome) CoverArea(ctx context.Context, req *CoverAreaReq) (res *CommonRes, err error) {
method := "alamein.stock.read.queryCoverArea"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//ForbidCoverArea todo
func (stockGome) ForbidCoverArea(ctx context.Context, req *CoverAreaReq) (res *CommonRes, err error) {
method := "alamein.stock.read.queryForbidCoverArea"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
//SaleAble 查询可卖数列表
func (stockGome) SaleAble(ctx context.Context, req *SaleAbleReq) (res *SaleAbleRes, err error) {
method := "alamein.stock.read.querySaleableQty"
result, err := server.requestApi(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
package gome
import (
"context"
"github.com/gogf/gf/encoding/gjson"
)
type tokenGome struct {
}
var Token = tokenGome{}
type GetTokenReq struct {
GrantType string `json:"grant_type"`
}
type TokenCommonRes struct {
*CommonRes
Data struct {
AppKey string `json:"appKey"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresInSeconds int64 `json:"expiresInSeconds"`
CreateTime string `json:"createTime"`
} `json:"data"`
}
type RefreshTokenReq struct {
GrantType string `json:"grant_type"`
RefreshToken string `json:"refresh_token"`
}
func (tokenGome) Get(ctx context.Context) (res *TokenCommonRes, err error) {
method := "token.create"
req := &GetTokenReq{GrantType: "authorization_secret"}
result, err := server.post(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
func (tokenGome) Refresh(ctx context.Context, refreshToken string) (res *TokenCommonRes, err error) {
method := "token.refresh"
req := &RefreshTokenReq{
GrantType: "authorization_code",
RefreshToken: refreshToken,
}
result, err := server.post(ctx, method, req)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
return
}
......@@ -172,7 +172,7 @@ func (s *HcwClient) post(ctx context.Context, method string, req interface{}) (r
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
......
......@@ -48,7 +48,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
......
......@@ -49,7 +49,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Async(true).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Async(true).Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
......
......@@ -186,7 +186,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
......
package itao
import (
"context"
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"net/url"
"sort"
"strings"
"time"
)
type Config struct {
ApiUrl string
AppKey string
AppSecret string
DB int
}
var server *Config
const PkgName = "itao"
const CacheKey = "itao:token"
const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/"
func New(req *Config) {
server = req
if server.DB == 0 {
server.DB = 10
}
return
}
type CommonRes struct {
Success bool `json:"success"`
ErrCode string `json:"errCode"`
ErrMsg string `json:"errMsg"`
}
func generate(req string) (res string) {
//拼接参数
mac := hmac.New(sha1.New, []byte(server.AppSecret))
mac.Write([]byte(req))
mdStr := hex.EncodeToString(mac.Sum(nil))
res = strings.ToUpper(mdStr)
return
}
func sign(method string, req g.Map) (err error) {
var keys []string
req["_aop_timestamp"] = gtime.Now().TimestampMilliStr()
for k := range req {
keys = append(keys, k)
}
sort.Strings(keys)
var signStr string
for _, v := range keys {
if v != "_aop_signature" {
signStr += v
signStr += gconv.String(req[v])
}
}
//拼接参数
signStr = "param2/1/com.huoju6.open/" + method + "/" + server.AppKey + signStr
req["_aop_signature"] = generate(signStr)
return
}
func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
str, err = Post(ctx, method, params)
return
}
func Post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
err = sign(method, params)
if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Request := g.Client()
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second*5).Get(Url, params)
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】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
str, err = Get(ctx, method, params)
return
}
func Get(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
err = sign(method, params)
if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Request := g.Client()
Values := url.Values{}
for k, v := range params {
Values.Add(k, gconv.String(v))
}
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second * 5).Get(Url + "?" + Values.Encode())
defer func() {
_ = resp.Close()
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "GET")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
func AccessToken(ctx context.Context) (res string, err error) {
var conn = g.Redis().Conn()
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
var result *AuthTokenRes
_ = gjson.New(cache).Scan(&result)
if result == nil {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
if result.AccessToken == "" || result.AccessTokenExpireTime < gtime.TimestampMilli() {
result, err = RefreshToken(ctx)
}
res = result.AccessToken
return
}
// RefreshToken 刷新
func RefreshToken(ctx context.Context) (res *AuthTokenRes, err error) {
var conn = g.Redis().Conn()
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
_ = gjson.New(cache).Scan(&res)
if res.AccessTokenExpireTime > gtime.Now().Add(time.Hour).TimestampMilli() {
return
}
res, err = Auth.Token(ctx, res.RefreshToken, 2)
if err != nil {
return
}
if res.Code != "success" {
g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return
}
_, _ = conn.Do("HMSET", CacheKey, "accessToken", res.AccessToken, "accessTokenExpireTime", res.AccessTokenExpireTime)
return
}
func CheckResult(req interface{}) (err error) {
if req == nil {
err = gerror.New("result is null")
}
return err
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type addressItao struct {
}
var Address = addressItao{}
type AddressDivisionReq struct {
Province string `json:"prov,omitempty"`
City string `json:"city,omitempty"`
Area string `json:"distinct,omitempty"`
Town string `json:"town,omitempty"`
Page int `json:"pageIndex"`
Size int `json:"pageSize"`
}
type AddressDivisionRes struct {
Result struct {
Result struct {
Divisions []struct {
DivisionId int `json:"divisionId"`
DivisionLeaf bool `json:"divisionLeaf"`
DivisionToken string `json:"divisionToken"`
Level int `json:"level"`
Names struct {
EN string `json:"EN"`
CN string `json:"CN"`
} `json:"names"`
} `json:"divisions"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
ParentToken string `json:"parentToken"`
TotalCount int `json:"totalCount"`
TotalPage int `json:"totalPage"`
} `json:"result"`
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
} `json:"result"`
}
// Division 行政区划
func (s addressItao) Division(ctx context.Context, req AddressDivisionReq) (res *AddressDivisionRes, err error) {
method := "tt.order.queryDivision"
result, err := server.Post(ctx, method, g.Map{
"param": req,
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
type AddressParseReq struct {
Province string `json:"prov"`
City string `json:"city"`
Detail string `json:"addressDetail"`
}
type AddressParseRes struct {
Result struct {
City string `json:"city"`
CityId int `json:"cityId"`
District string `json:"district"`
DistrictId int `json:"districtId"`
Prov string `json:"prov"`
ProvId int `json:"provId"`
Town string `json:"town"`
TownId int `json:"townId"`
} `json:"result"`
Success bool `json:"success"`
}
// Parse 地址解析
// 省、市必传
func (s addressItao) Parse(ctx context.Context, req AddressParseReq) (res *AddressParseRes, err error) {
method := "tt.address.validate"
result, err := server.Post(ctx, method, g.Map{
"param": req,
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type auth struct {
}
var Auth = auth{}
type AuthStatusRes struct {
Code string `json:"code"`
Message string `json:"message"`
}
// Status 授权状态
func (s auth) Status(ctx context.Context) (res *AuthStatusRes, err error) {
method := "tt.authority.checkAuthStatus"
result, err := server.Get(ctx, method, g.Map{
"bId": server.AppKey,
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
type AuthQrCodeRes struct {
Code string `json:"code"`
Message string `json:"message"`
TempCode string `json:"tempCode"`
TempCodeExpireTime string `json:"tempCodeExpireTime"`
QrCodeUrl string `json:"qrCodeUrl"`
}
// QrCode 二维码
func (s auth) QrCode(ctx context.Context) (res *AuthQrCodeRes, err error) {
method := "tt.authority.generateQrCode"
result, err := Get(ctx, method, g.Map{
"bId": server.AppKey,
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
type AuthTokenRes struct {
Code string `json:"code"`
Message string `json:"message"`
RefreshToken string `json:"refreshToken"`
AccessToken string `json:"accessToken"`
AccessTokenExpireTime int64 `json:"accessTokenExpireTime"`
RefreshTokenExpireTime int64 `json:"refreshTokenExpireTime"`
TaoteId string `json:"taoteId"`
TaoteNickName string `json:"taoteNickName"`
Feature string `json:"feature"`
GwTraceId string `json:"gw_trace_id"`
}
// Token 授权
func (s auth) Token(ctx context.Context, code string, Type int) (res *AuthTokenRes, err error) {
method := "tt.auth.getAccessToken"
var request = g.Map{
"bId": server.AppKey,
}
if Type == 1 {
request["code"] = code //临时令牌
request["grantType"] = "code"
} else {
request["refreshToken"] = code //刷新令牌
request["grantType"] = "refreshToken"
}
result, err := Get(ctx, method, request)
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
// Unbind 注销授权
func (s auth) Unbind(ctx context.Context) (res *AuthTokenRes, err error) {
method := "tt.authority.unbind"
result, err := server.Get(ctx, method, g.Map{
"bId": server.AppKey,
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
差异被折叠。
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type logistics struct {
}
var Logistics = logistics{}
type LogisticsTraceRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
Result []struct {
CompanyList []struct {
BrandCode string `json:"brandCode"`
CompanyName string `json:"companyName"`
} `json:"companyList"`
DetailList []struct {
Action string `json:"action"`
GmtCreate string `json:"gmtCreate"`
StanderdDesc string `json:"standerdDesc"`
Status string `json:"status"`
Time string `json:"time"`
MailNo string `json:"mailNo,omitempty"`
TpName string `json:"tpName,omitempty"`
} `json:"detailList"`
GoodsList []interface{} `json:"goodsList"`
MailNo string `json:"mailNo"`
Receiver struct {
Adr string `json:"adr"`
CityName string `json:"cityName"`
DistrictName string `json:"districtName"`
Name string `json:"name"`
ProvinceName string `json:"provinceName"`
Telphone string `json:"telphone"`
} `json:"receiver"`
Status struct {
StatusCode string `json:"statusCode"`
StatusDesc string `json:"statusDesc"`
} `json:"status"`
} `json:"result"`
}
// Trace 物流轨迹
func (logistics) Trace(ctx context.Context, req string) (res *LogisticsTraceRes, err error) {
method := "tt.logistics.detail"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"tradeId": req,
},
})
if err != nil {
return
}
_ = gjson.New(result).Scan(&res)
err = CheckResult(res)
return
}
type LogisticsCompanyRes struct {
Result []LogisticsCompanyItem `json:"result"`
Success bool `json:"success"`
}
type LogisticsCompanyItem struct {
Code string `json:"code"`
Name string `json:"name"`
Id int64 `json:"id"`
Type int `json:"type"`
}
type LogisticsCompany struct {
Result map[string][]interface{} `json:"result"`
Success bool `json:"success"`
}
// Company 物流公司
func (logistics) Company(ctx context.Context, req string) (res *LogisticsCompanyRes, err error) {
method := "tt.refund.queryLogisticList"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
var data *LogisticsCompany
if err != nil {
return
}
_ = gjson.New(result).Scan(&data)
err = CheckResult(data)
res = new(LogisticsCompanyRes)
res.Success = data.Success
for _, item := range data.Result {
for _, val := range item {
var value []LogisticsCompanyItem
_ = gjson.New(val).Scan(&value)
res.Result = append(res.Result, value...)
}
}
return
}
差异被折叠。
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type pay struct {
}
var Pay = pay{}
type PayAuthRes struct {
}
func (s pay) Auth(ctx context.Context) (res *PayAuthRes, err error) {
method := "tt.agreementpay.genersignurl"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{},
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type refund struct {
}
var Refund = refund{}
type RefundPic struct {
MessagePic string `json:"messagePic"`
}
type RefundBeforeRes struct {
CommonRes
Result struct {
BizClaimTypeVOList []struct {
BizClaimType string `json:"bizClaimType"` //refund 仅退款 return_and_refund 退货退款
RefundTypeTitle string `json:"refundTypeTitle"`
} `json:"bizClaimTypeVOList"`
} `json:"result"`
}
// Before 退款类型
func (s refund) Before(ctx context.Context, req string) (res *RefundBeforeRes, err error) {
method := "tt.refund.refundApplyType"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
type RefundReasonReq struct {
BizOrderId string `json:"bizOrderId"`
BizClaimType string `json:"bizClaimType"`
GoodsStatus string `json:"goodsStatus,omitempty"`
BuyerApplyTextId int `json:"buyerApplyTextId,omitempty"`
}
type RefundReasonRes struct {
CommonRes
Result struct {
MaxRefundFee int `json:"maxRefundFee"`
MinRefundFee int `json:"minRefundFee"`
MustProof bool `json:"mustProof"`
RefundTextWrapperVOList []struct {
Name string `json:"name"`
ReasonGroup int `json:"reasonGroup"`
TextId int `json:"textId"`
} `json:"refundTextWrapperVOList"`
} `json:"result"`
}
// Reason 原因
func (s refund) Reason(ctx context.Context, req RefundReasonReq) (res *RefundReasonRes, err error) {
method := "tt.refund.refundApplyInit"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
type RefundCreateReq struct {
BizOrderId string `json:"bizOrderId"` //子订单号
BizClaimType string `json:"bizClaimType"` //refund 仅退款 return_and_refund 退货退款
GoodsStatus string `json:"goodsStatus,omitempty"` //"1":未收到货 "2":未已收到货 未发货情况下,千万不要传
RefundFee int `json:"refundFee"` //退款金额,单位是分
ApplyRefundTextId string `json:"applyRefundTextId"` //原因ID
LeaveMessageContent string `json:"leaveMessageContent,omitempty"` //退款说明
LeaveMessagePics []RefundPic `json:"leaveMessagePics,omitempty"`
}
type RefundCreateRess struct {
CommonRes
Result struct {
DisputeId string `json:"disputeId"`
} `json:"result"`
}
// Create 申请
func (s refund) Create(ctx context.Context, req RefundCreateReq, image ...string) (res *RefundCreateRess, err error) {
method := "tt.refund.refundSubmit"
if len(image) > 0 {
for _, item := range image {
req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item})
}
}
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
// Cancel 取消售后
// `bizOrderId` 子订单号
// `disputeId` 售后单号
func (s refund) Cancel(ctx context.Context, bizOrderId, disputeId string) (res *CommonRes, err error) {
method := "tt.refund.refundRevoke"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": bizOrderId,
"disputeId": disputeId,
},
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
type RefundSubmitReq struct {
DisputeId string `json:"disputeId"`
BizOrderId string `json:"bizOrderId"`
CompanyCode string `json:"logisticsCompanyCode"`
CompanyId string `json:"logisticsCompanyId"`
CompanyName string `json:"logisticsCompanyName"`
LogisticsNo string `json:"logisticsNo"`
MobileNum string `json:"mobileNum"`
LeaveMessagePics []RefundPic `json:"leaveMessagePics"`
}
type RefundSubmitRes struct {
CommonRes
Result struct {
DisputeStatus string `json:"disputeStatus"`
//REFUND_WAIT_SELLER_AGREE:"买家已经申请退款,等待卖家同意";
//REFUND_WAIT_BUYER_RETURN_GOODS:"卖家已经同意退款,等待买家退货";
//REFUND_WAIT_SELLER_CONFIRM_GOODS:"买家已经退货,等待卖家确认收货";
//REFUND_CLOSED:"退款关闭";
//REFUND_SUCCESS:"退款成功";
//REFUND_SELLER_REFUSE_BUYER:"卖家拒绝退款";
//REFUND_WAIT_BUYER_CONFIRM_REDO_SEND_GOODS:"等待买家确认重新邮寄的货物";
//REFUND_WAIT_SELLER_CONFIRM_RETURN_ADDRESS:"等待卖家确认退货地址"
} `json:"result"`
}
// Submit 提交物流信息
func (s refund) Submit(ctx context.Context, req RefundSubmitReq, image ...string) (res *CommonRes, err error) {
method := "tt.refund.submitLogisticInfo.v1"
if len(image) > 0 {
for _, item := range image {
req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item})
}
}
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
type RefundDetailRes struct {
CommonRes
Result struct {
DisputeId int64 `json:"disputeId"` //退款编号
DisputeStatus string `json:"disputeStatus"`
//退款状态
//REFUND_WAIT_SELLER_AGREE:"买家已经申请退款,等待卖家同意";
//REFUND_WAIT_BUYER_RETURN_GOODS:"卖家已经同意退款,等待买家退货";
//REFUND_WAIT_SELLER_CONFIRM_GOODS:"买家已经退货,等待卖家确认收货";
//REFUND_CLOSED:"退款关闭";
//REFUND_SUCCESS:"退款成功";
//REFUND_SELLER_REFUSE_BUYER:"卖家拒绝退款";
//REFUND_WAIT_BUYER_CONFIRM_REDO_SEND_GOODS:"等待买家确认重新邮寄的货物";
//REFUND_WAIT_SELLER_CONFIRM_RETURN_ADDRESS:"等待卖家确认退货地址"
DisputeTimeOut struct {
Duration int `json:"duration"`
GmtCreate int64 `json:"gmtCreate"`
Running bool `json:"running"`
TimeoutActionType string `json:"timeoutActionType"`
} `json:"disputeTimeOut"`
ReasonName string `json:"reasonName"` //退款原因名称
RefundFee int `json:"refundFee"` //退款金额,单位分
ShippingAddressWrapperDTO struct {
AddressDetail string `json:"addressDetail"`
AreaName string `json:"areaName"`
CityName string `json:"cityName"`
ConsigneeFullName string `json:"consigneeFullName"`
DivisionCode string `json:"divisionCode"`
Mobile string `json:"mobile"`
PostCode string `json:"postCode"`
ProvinceName string `json:"provinceName"`
TownName string `json:"townName"`
} `json:"shippingAddressWrapperDTO"`
} `json:"result"`
}
// Detail 详情
func (s refund) Detail(ctx context.Context, bizOrderId, disputeId string) (res *RefundDetailRes, err error) {
method := "tt.refund.queryRefundDetail"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": bizOrderId,
"disputeId": disputeId,
},
})
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"net/url"
"time"
)
type upload struct {
}
var Upload = upload{}
type UploadImageReq struct {
FileName string `json:"fileName"`
FileContent string `json:"fileContent"`
ImageData string `json:"imageData"`
}
type UploadImageRes struct {
Code string `json:"code"`
Message string `json:"message"`
FileUrl string `json:"fileUrl"`
}
func (s upload) Image(ctx context.Context, req UploadImageReq) (res *UploadImageRes, err error) {
method := "tt.upload.image"
if req.FileContent == "" {
req.FileContent = "base64"
}
var request = g.Map{}
request["access_token"], err = AccessToken(ctx)
if err != nil {
return
}
result, err := s.post(ctx, method, request, gconv.Map(req))
if err != nil {
return
}
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
err = CheckResult(res)
return
}
func (upload) post(ctx context.Context, method string, params, req g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
err = sign(method, params)
if err != nil {
return
}
Url := Host + method + "/" + server.AppKey
Values := url.Values{}
for k, v := range params {
Values.Add(k, gconv.String(v))
}
resp, err := g.Client().ContentJson().Timeout(time.Second*5).Post(Url+"?"+Values.Encode(), req)
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】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
......@@ -64,7 +64,7 @@ func (s *client) post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
}
......
......@@ -57,7 +57,7 @@ func (s *Config) Post(ctx context.Context, URL string, bodyMap g.Map) (result st
defer func() {
ctx = context.WithValue(ctx, "URI", URL)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").
g.Log().Ctx(ctx).Cat(pkgName).
Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).
......
......@@ -13,7 +13,7 @@ import (
var server *Config
//苏宁
// 苏宁
const pkgName = "suning"
type Config struct {
......@@ -58,7 +58,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】错误【%v】响应时间【%v ms】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
......
package tm
import (
"context"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/grand"
"net/url"
"reflect"
"sort"
"strings"
"time"
)
type Config struct {
AppKey string
AppSecret string
BizUid string
}
var server *Config
const PkgName = "tm"
const (
apiUrl string = "http://linkedmall.aliyuncs.com/"
regionId string = "cn-hangzhou"
bizId string = "LMALL201912050002"
signatureVersion string = "1.0"
signatureMethod string = "HMAC-SHA1"
version string = "2018-01-16"
format string = "JSON"
typeAnony string = "ANONY"
typeEp string = "EP"
)
func New(req *Config) {
server = req
return
}
func specialUrlEncode(req string) (res string) {
req = url.QueryEscape(req)
req = strings.Replace(req, "+", "%20", -1)
req = strings.Replace(req, "*", "%2A", -1)
req = strings.Replace(req, "*7E", "~", -1)
res = req
return
}
func sign(param map[string]string) {
var keys []string
mewparam := param
for k := range mewparam {
keys = append(keys, k)
}
sort.Strings(keys)
var signStr string
u := url.Values{}
for _, v := range keys {
u.Set(v, mewparam[v])
}
signStr += specialUrlEncode(u.Encode())
signStr = "POST&" + specialUrlEncode("/") + "&" + signStr
param["Signature"] = hmacsha1Base64(signStr)
return
}
func hmacsha1Base64(str string) string {
appSecret := []byte(server.AppSecret + "&")
mac := hmac.New(sha1.New, appSecret)
mac.Write([]byte(str))
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
}
func post(ctx context.Context, method string, params map[string]string) (str string, err error) {
Start := gtime.TimestampMilli()
curtime := time.Now().UTC()
params["Action"] = method
params["AccessKeyId"] = server.AppKey
params["BizId"] = bizId
params["RegionId"] = regionId
params["SignatureMethod"] = signatureMethod
params["SignatureVersion"] = signatureVersion
params["Version"] = version
params["Format"] = format
params["SignatureNonce"] = grand.S(32)
params["Timestamp"] = curtime.Format("2006-01-02T15:04:05Z")
sign(params)
Request := g.Client()
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
Request.Timeout(3 * time.Second)
resp, err := Request.Post(apiUrl, params)
defer func() {
_ = resp.Close()
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"])
if err != nil {
g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v ms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
func convert(pre string, req []map[string]interface{}) (res map[string]string) {
res = make(map[string]string)
for k, v := range req {
for key, val := range v {
if reflect.TypeOf(val).String() == "[]string" {
for key2, val2 := range gconv.Strings(val) {
res[pre+"."+gconv.String(k+1)+"."+key+"."+gconv.String(key2+1)] = gconv.String(val2)
}
} else {
res[pre+"."+gconv.String(k+1)+"."+key] = gconv.String(val)
}
}
}
return
}
type CommonRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
}
package tm
import (
"context"
"encoding/json"
)
type accountTm struct {
}
var Account = accountTm{}
//Regist 注册单个淘宝账号接口(同步)
func (s *accountTm) Regist(ctx context.Context, UserId string) (res *CommonRes, err error) {
method := "RegistAnonymousTbAccount"
result, err := post(ctx, method, map[string]string{
"BizUid": server.BizUid,
"ThirdPartyUserId": UserId,
})
_ = json.Unmarshal([]byte(result), &res)
return
}
package tm
import (
"context"
"github.com/gogf/gf/encoding/gjson"
)
type category struct {
}
var Category = category{}
type CategoryDetailRes struct {
Code string `json:"Code"` //成功 0000
Message string `json:"Message"`
RequestId string `json:"RequestId"`
CategoryList []struct {
CategoryId int `json:"CategoryId"`
Name string `json:"Name"`
} `json:"CategoryList"`
}
func (category) Detail(ctx context.Context, req string) (res *CategoryDetailRes, err error) {
method := "GetCategoryChain"
request := map[string]string{
"BizUid": server.BizUid,
"CategoryId": req,
}
result, err := post(ctx, method, request)
err = gjson.New(result).Scan(&res)
return
}
type CategoryListRes struct {
Code string `json:"Code"` //成功 0000
Message string `json:"Message"`
RequestId string `json:"RequestId"`
CategoryList struct {
Category []struct {
CategoryId int `json:"CategoryId"`
Name string `json:"Name"`
} `json:"Category"`
} `json:"CategoryList"`
}
func (category) List(ctx context.Context, req string) (res *CategoryListRes, err error) {
method := "GetCategoryList"
request := map[string]string{
"CategoryId": req,
}
result, err := post(ctx, method, request)
err = gjson.New(result).Scan(&res)
return
}
package tm
import (
"context"
"encoding/json"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type goodsTm struct {
}
var Goods = goodsTm{}
type GoodsInventoryReq struct {
ItemId string `json:"ItemId"`
SkuIdList []string `json:"SkuIdList"`
}
type GoodsInventoryRes struct {
Code string `json:"Code"`
Success bool `json:"Success"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
ItemList struct {
Item []struct {
ItemId int `json:"ItemId"`
SkuList struct {
Sku []struct {
SkuId int `json:"SkuId"`
Inventory struct {
Quantity int `json:"Quantity"`
} `json:"Inventory"`
} `json:"Sku"`
} `json:"SkuList"`
} `json:"Item"`
} `json:"ItemList"`
}
//Inventory 查询库存
func (s *goodsTm) Inventory(ctx context.Context, DivisionCode string, req []GoodsInventoryReq) (res *GoodsInventoryRes, err error) {
method := "queryItemInventory"
request := convert("ItemList", gconv.Maps(req))
request["DivisionCode"] = DivisionCode
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type GoodsDetailRes struct {
Code string `json:"Code"`
Success bool `json:"Success"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Item struct {
ItemId int `json:"ItemId"`
ItemTitle string `json:"ItemTitle"`
CanSell bool `json:"IsCanSell"`
ReservePrice int `json:"ReservePrice"` //
Quantity int `json:"Quantity"`
MinPrice int `json:"MinPrice"`
TotalSoldQuantity int `json:"TotalSoldQuantity"` //销量
DescOption string `json:"DescOption"`
SellerId int `json:"SellerId"`
CategoryId int `json:"CategoryId"`
MainPicUrl string `json:"MainPicUrl"`
TbShopName string `json:"TbShopName"`
SellerPayPostfee bool `json:"SellerPayPostfee"` //是否包邮
PropertiesJson string `json:"PropertiesJson"` //属性
Properties map[string][]string `json:"Properties"` //属性
Skus struct {
Sku []struct {
ItemId int `json:"ItemId"`
Quantity int `json:"Quantity"`
ReservePrice int `json:"ReservePrice"`
CanSell bool `json:"CanSell"`
SkuId int `json:"SkuId"`
PriceCent int `json:"PriceCent"` //售价
SkuProperties map[string]string `json:"SkuProperties"`
SkuPropertiesJson string `json:"SkuPropertiesJson"`
SkuPicUrl string `json:"SkuPicUrl"`
} `json:"Sku"`
} `json:"Skus"`
ItemImages struct {
ItemImage []string `json:"ItemImage"`
} `json:"ItemImages"`
} `json:"Item"`
}
//Detail 详情
func (*goodsTm) Detail(ctx context.Context, req interface{}) (res *GoodsDetailRes, err error) {
method := "QueryItemDetail"
request := g.MapStrStr{
"ItemId": gconv.String(req),
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
package tm
import (
"context"
"github.com/gogf/gf/encoding/gjson"
)
type logisticsTm struct {
}
var Logistics = logisticsTm{}
type LogisticsTraceRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Data struct {
Data []struct {
DataProvider string `json:"DataProvider"`
LogisticsCompanyName string `json:"LogisticsCompanyName"` //物流公司名称
MailNo string `json:"MailNo"` //运单号
LogisticsCompanyCode string `json:"LogisticsCompanyCode"` //物流公司Code
LogisticsDetailList struct {
LogisticsDetailList []struct {
StanderdDesc string `json:"StanderdDesc"`
OcurrTimeStr string `json:"OcurrTimeStr"`
} `json:"LogisticsDetailList"`
} `json:"LogisticsDetailList"`
DataProviderTitle string `json:"DataProviderTitle"`
} `json:"Data"`
} `json:"Data"`
}
//Trace 物流查询接口
func (s *logisticsTm) Trace(ctx context.Context, UserId, LmOrderId string) (res *LogisticsTraceRes, err error) {
method := "queryLogistics"
request := map[string]string{
"BizUid": server.BizUid,
"LmOrderId": LmOrderId,
"AccountType": "ANONY",
"ThirdPartyUserId": UserId,
}
result, err := post(ctx, method, request)
err = gjson.New(result).Scan(&res)
return
}
package tm
import (
"context"
"encoding/json"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/util/gconv"
)
type orderTm struct {
}
var Order = orderTm{}
type OrderGoodsItem struct {
ItemId string `json:"ItemId"`
Quantity string `json:"Quantity"`
SkuId string `json:"SkuId"`
}
type OrderAddress struct {
AddressDetail string `json:"AddressDetail"`
DivisionCode string `json:"DivisionCode"`
FullName string `json:"FullName"`
Mobile string `json:"Mobile"`
}
type OrderBeforeRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Model struct {
RenderOrderInfos struct {
RenderOrderInfos []struct {
LmItemInfos struct {
LmItemInfos []struct {
ItemId int64 `json:"ItemId"`
Quantity int `json:"Quantity"`
CanSell bool `json:"CanSell"`
SkuId int64 `json:"SkuId"`
Message string `json:"Message"`
ItemName string `json:"ItemName"`
} `json:"LmItemInfos"`
} `json:"LmItemInfos"`
DeliveryInfos struct {
DeliveryInfos []struct {
ServiceType int `json:"ServiceType"`
Id string `json:"Id"`
PostFee int64 `json:"PostFee"`
DisplayName string `json:"string"`
} `json:"DeliveryInfos"`
} `json:"DeliveryInfos"`
} `json:"RenderOrderInfos"`
} `json:"RenderOrderInfos"`
} `json:"Model"`
}
//Before 验证订单商品
func (s *orderTm) Before(ctx context.Context, addr OrderAddress, itemLists []OrderGoodsItem) (res *OrderBeforeRes, err error) {
method := "renderOrder"
request := convert("ItemList", gconv.Maps(itemLists))
request["DeliveryAddress"] = gjson.New(addr).MustToJsonString()
request["BizUid"] = server.BizUid
request["AccountType"] = typeEp
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type OrderCreateReq struct {
UserId string
ChannelOrder string
Address OrderAddress
ItemLists []OrderGoodsItem
}
type OrderCreateRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Model struct {
OrderIds struct {
OrderIds []string `json:"OrderIds"`
} `json:"OrderIds"`
PayTradeIds struct {
PayTradeIds []string `json:"PayTradeIds"`
} `json:"PayTradeIds"`
LmOrderList struct {
LmOrderList []struct {
LmOrderId string `json:"LmOrderId"`
} `json:"LmOrderList"`
} `json:"LmOrderList"`
} `json:"Model"`
}
//Create 下单接口
func (s *orderTm) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "createOrderV2"
request := convert("ItemList", gconv.Maps(req.ItemLists))
request["DeliveryAddress"] = gjson.New(req.Address).MustToJsonString()
request["BizUid"] = server.BizUid
request["OutTradeId"] = req.ChannelOrder
request["AccountType"] = typeAnony
request["ThirdPartyUserId"] = req.UserId
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type OrderPayReq struct {
UserId string
ChannelOrder string
LmOrderId string
}
//Pay 订单支付
func (s *orderTm) Pay(ctx context.Context, req OrderPayReq) (res *OrderCreateRes, err error) {
method := "enableOrder"
result, err := post(ctx, method, map[string]string{
"BizUid": server.BizUid,
"LmOrderId": req.LmOrderId,
"OutTradeId": req.ChannelOrder,
"AccountType": typeAnony,
"ThirdPartyUserId": req.UserId,
})
_ = json.Unmarshal([]byte(result), &res)
return
}
type OrderListReq struct {
UserId string
ChannelOrder string
LmOrderId string
LogisticsStatus string
OrderStatus string
EnableStatus string //0生效 1无效 -1都查 不填默认0
}
type OrderFilter struct {
LmOrderList []string `json:"lmOrderList,omitempty"`
ChannelOrder []string `json:"channelOrderIdList,omitempty"`
LogisticsStatus string `json:"LogisticsStatus,omitempty"`
OrderStatus string `json:"OrderStatus,omitempty"`
EnableStatus string `json:"enableStatus,omitempty"`
}
type OrderListRes struct {
PostFee struct {
FundAmount int `json:"FundAmount"`
FundType string `json:"FundType"`
FundAmountMoney int `json:"FundAmountMoney"`
} `json:"PostFee"`
RequestId string `json:"RequestId"`
Message string `json:"Message"`
PageSize int `json:"PageSize"`
PageNumber int `json:"PageNumber"`
LmOrderList struct {
LmOrderList []struct {
PostFee struct {
FundAmount int `json:"FundAmount"`
FundType string `json:"FundType"`
FundAmountMoney int `json:"FundAmountMoney"`
} `json:"PostFee"`
ExtJson string `json:"ExtJson"`
OrderStatus int `json:"OrderStatus"` //12=待⽀付,2=已⽀付,4=已退款关闭,6=交易成功,8=被淘宝关闭
ShopName string `json:"ShopName"`
EnableStatus int `json:"EnableStatus"`
TbOrderId int64 `json:"TbOrderId"` //淘宝单号
OrderAmount int `json:"OrderAmount"`
FundStructureModels struct {
FundStructureModels []struct {
FundAmount int `json:"FundAmount"`
FundType string `json:"FundType"`
FundAmountMoney int `json:"FundAmountMoney"`
} `json:"FundStructureModels"`
} `json:"FundStructureModels"`
CreateDate string `json:"CreateDate"`
LmOrderId int64 `json:"LmOrderId"` //天猫单号
LogisticsStatus int `json:"LogisticsStatus"` //1=未发货 -> 等待卖家发货 2=已发货 -> 等待买家确认收货 3=已收货 -> 交易成功 4=已经退货 -> 交易失败 5=部分收货 -> 交易成功 6=部分发货中 8=还 未创建物流订单
SubOrderList struct {
SubOrderList []struct {
ItemPriceList struct {
ItemPriceList []struct {
FundAmount int `json:"FundAmount"`
FundType string `json:"FundType"`
FundAmountMoney int `json:"FundAmountMoney"`
} `json:"ItemPriceList"`
} `json:"ItemPriceList"`
OrderStatus int `json:"OrderStatus"` //12=待⽀付,2=已⽀付,4=已退款关闭,6=交易成功,8=被淘宝关闭
Number int `json:"Number"`
EnableStatus int `json:"EnableStatus"`
TbOrderId int64 `json:"TbOrderId"` //淘宝单号
ItemTitle string `json:"ItemTitle"`
SkuName string `json:"SkuName"`
ItemPic string `json:"ItemPic"`
SkuId string `json:"SkuId"`
ItemId int64 `json:"ItemId"`
LmOrderId int `json:"LmOrderId"` //天猫单号
} `json:"SubOrderList"`
} `json:"SubOrderList"`
} `json:"LmOrderList"`
} `json:"LmOrderList"`
Code string `json:"Code"`
}
//List 列表
func (s *orderTm) List(ctx context.Context, req OrderListReq) (res *OrderListRes, err error) {
method := "queryOrderList"
var filterOption = OrderFilter{
LogisticsStatus: req.LogisticsStatus,
OrderStatus: req.OrderStatus,
EnableStatus: "-1",//默认-1 全选
}
if req.LmOrderId != "" {
filterOption.LmOrderList = garray.NewStrArray().Append(req.LmOrderId).Slice()
}
if req.ChannelOrder != "" {
filterOption.ChannelOrder = garray.NewStrArray().Append(req.ChannelOrder).Slice()
}
if req.EnableStatus != "" {
filterOption.EnableStatus = req.EnableStatus
}
request := map[string]string{
"BizUid": server.BizUid,
"FilterOption": gjson.New(filterOption).MustToJsonString(),
"PageNumber": "1",
"PageSize": "20",
"AccountType": typeAnony,
"ThirdPartyUserId": req.UserId,
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type OrderCancelReq struct {
UserId string
LmOrderId string
}
//Cancel 仅适⽤下单[Create]未⽀付[Pay]的订单
func (s *orderTm) Cancel(ctx context.Context, req OrderCancelReq) (res *OrderListRes, err error) {
method := "cancelOrder"
result, err := post(ctx, method, map[string]string{
"BizUid": server.BizUid,
"LmOrderId": req.LmOrderId,
"AccountType": typeAnony,
"ThirdPartyUserId": req.UserId,
})
_ = json.Unmarshal([]byte(result), &res)
return
}
package tm
import (
"context"
"encoding/json"
"github.com/gogf/gf/util/gconv"
)
type refundTm struct {
}
var Refund = refundTm{}
type RefundSubmitReq struct {
UserId string
SubLmOrderId string //子订单号
DisputeId string //售后ID
CpCode string //物流编码
LogisticsNo string //物流单号
}
//Submit 提交退货物流信息接口
func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *CommonRes, err error) {
method := "submitReturnGoodLogistics"
request := map[string]string{
"BizUid": server.BizUid,
"SubLmOrderId": req.SubLmOrderId,
"DisputeId": req.DisputeId,
"CpCode": req.CpCode,
"LogisticsNo": req.LogisticsNo,
"ThirdPartyUserId": req.UserId,
"AccountType": typeAnony,
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
//Cancel 取消退款申请接口
func (s *refundTm) Cancel(ctx context.Context, UserId, subLmOrderId, disputeId string) (res *CommonRes, err error) {
method := "cancelRefund"
request := map[string]string{
"BizUid": server.BizUid,
"SubLmOrderId": subLmOrderId,
"DisputeId": disputeId,
"ThirdPartyUserId": UserId,
"AccountType": typeAnony,
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type RefundBeforeReq struct {
UserId string
ChannelOrder string
SubLmOrderId string
BizClaimType string
GoodsStatus string
}
type RefundBeforeRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
InitApplyRefundData struct {
RefundReasonList struct {
RefundReasonList []struct {
ReasonTextId int64 `json:"ReasonTextId"`
ReasonTips string `json:"ReasonTips"`
RefundDescRequired bool `json:"RefundDescRequired"` //是否要求留言
ProofRequired bool `json:"ProofRequired"` //是否要求上传凭证
} `json:"RefundReasonList"`
} `json:"RefundReasonList"`
MaxRefundFeeData struct {
MaxRefundFee int64 `json:"MaxRefundFee"` //本单最大可退款金额
MinRefundFee int64 `json:"MinRefundFee"` //本单最小可退款金额
} `json:"MaxRefundFeeData"`
BizClaimType int `json:"BizClaimType"` // 支持的订单退货方式,1, 标识仅退款,3,标识退货退款
} `json:"InitApplyRefundData"`
}
// Before 前置
func (s *refundTm) Before(ctx context.Context, req RefundBeforeReq) (res *RefundBeforeRes, err error) {
method := "initApplyRefund"
request := map[string]string{
"BizUid": server.BizUid,
"SubLmOrderId": req.SubLmOrderId,
"GoodsStatus": req.GoodsStatus,
"BizClaimType": req.BizClaimType,
"ThirdPartyUserId": req.UserId,
"AccountType": typeAnony,
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type RefundApplyReq struct {
UserId string
SubLmOrderId string //子订单号
BizClaimType string //退款类型
ApplyRefundFee string //申请退款金额
ApplyRefundCount string //退货数量
ApplyReasonTextId string //退款原因ID
LeaveMessage string //留言
LeavePictureList []*RefundApplyPicture //凭证,某些原因要求必须有凭证。
GoodsStatus string //当退款类型:仅退款时,货物状态:为4未 发货。所有状态:4: 未发货, 6: 已发货, 1: 未收到货, 2: 已收到货, 3:已寄回, 5: 卖家确 认收货
}
type RefundApplyPicture struct {
Picture string `json:"Picture"` //图片地址
Desc string `json:"Desc"` //图片描述
}
type RefundApplyRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
RefundApplicationData struct {
SubLmOrderId string `json:"SubLmOrderId"` //当前发起逆向的子订单号
DisputeStatus int `json:"DisputeStatus"` //逆向的状态
DisputeType int `json:"DisputeType"` //任意退款类型
DisputeId int64 `json:"DisputeId"` //shou
} `json:"RefundApplicationData"`
}
//Apply 申请
func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes, err error) {
method := "applyRefund"
request := convert("LeavePictureList", gconv.Maps(req.LeavePictureList))
request["SubLmOrderId"] = req.SubLmOrderId
request["BizClaimType"] = req.BizClaimType
request["ApplyRefundFee"] = req.ApplyRefundFee
request["ApplyRefundCount"] = req.ApplyRefundCount
request["ApplyReasonTextId"] = req.ApplyReasonTextId
request["LeaveMessage"] = req.LeaveMessage
request["GoodsStatus"] = req.GoodsStatus
request["BizUid"] = server.BizUid
request["AccountType"] = typeAnony
request["ThirdPartyUserId"] = req.UserId
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
type RefundInfoRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
RefundApplicationDetail struct {
SubLmOrderId string `json:"SubLmOrderId"` //当前发起逆向的子订单号
RealRefundFee int64 `json:"RealRefundFee"` // 实际买家收到的金额
DisputeCreateTime string `json:"DisputeCreateTime"` //"逆向发起时间"
DisputeDesc string `json:"DisputeDesc"` //申请逆向描述
BizClaimType int `json:"BizClaimType"` // 支持的订单退货方式,1, 标识仅退款,3,标识退货退款
ApplyDisputeDesc string `json:"ApplyDisputeDesc"` //当前买家申请退款说明
DisputeType int `json:"DisputeType"` //逆向发生的类型 0: "任意退款类型" 1: "售中退款"2: "售后退款"
SellerAgreeMsg string `json:"SellerAgreeMsg"` //卖家同意退货说明,真实的退货地址会在这个字段进行返 回。
ApplyReasonText struct { //买家申请的逆向原因
ReasonTextId int64 `json:"ReasonTextId"`
ReasonTips string `json:"ReasonTips"`
} `json:"ApplyReasonText"`
RefundFee int64 `json:"RefundFee"` // 退款金额(含退平台补贴的金额)
SellerRefuseReason string `json:"SellerRefuseReason"` // 卖家拒绝的留言说明
RefunderTel string `json:"RefunderTel"` //退货联系方式,卖家同意退货后才显示
LmOrderId string `json:"LmOrderId"` //对应的主订单号
DisputeEndTime string `json:"DisputeEndTime"` //逆向发起时间
RefunderName string `json:"RefunderName"` //退货收货人,卖家同意退货后才显示
RefunderZipCode string `json:"RefunderZipCode"` //退货地址邮编,卖家同意退货后才显示
RefunderAddress string `json:"RefunderAddress"` //商家退货地址,卖家同意退货后才显示
DisputeStatus int `json:"DisputeStatus"` // 逆向的状态
//1: "买家已经申请退款,等待卖家同意"
//2: "卖家已经同意退款,等待买家退货"
//3: "买家已经退货,等待卖家确认收货"
//4: "退款关闭"
//5: "退款成功"
//6: "卖家拒绝退款"
//7: "等待买家确认重新邮寄的货物"
//8: "等待卖家确认退货地址"
//9: "没有申请退款"
//10: "有活动的退款"
//11: "退款结束"
//12: "卖家确认收货,等待卖家发货"
//14: "换货关闭,转退货退款"
//13: "卖家已发货,等待卖家和买家确认收货"
//15: "邮费单已创建,待激活"
ReturnGoodLogisticsStatus int `json:"ReturnGoodLogisticsStatus"` // 退货物流状态
//0: "未退货"
//1: "等待揽收"
//2: "快件已揽收"
//3: "物流⾛件中"
//4: "派送中"
//5: "已签收"
//6: "签收失败"
SelleAgreementMessage string `json:"SelleAgreementMessage"`
SellerRefuseAgreementMessage string `json:"SellerRefuseAgreementMessage"` //// 卖家拒绝的留言说明
ReturnGoodCount int `json:"ReturnGoodCount"` //退货数量
DisputeId int64 `json:"DisputeId"` //纠纷ID
} `json:"RefundApplicationDetail"`
}
//Info 详情
func (s *refundTm) Info(ctx context.Context, UserId, subLmOrderId string) (res *RefundInfoRes, err error) {
method := "queryRefundApplicationDetail"
request := map[string]string{
"BizUid": server.BizUid,
"SubLmOrderId": subLmOrderId,
"ThirdPartyUserId": UserId,
"AccountType": typeAnony,
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
package tm
import (
"context"
"encoding/json"
"github.com/gogf/gf/util/gconv"
)
// serviceTm 客服
type serviceTm struct {
}
var Service = serviceTm{}
type ServiceUrlRes struct {
Message string `json:"Message"`
UrlData struct {
ReturnUrl string `json:"ReturnUrl"`
} `json:"UrlData"`
Code string `json:"Code"`
}
// Url 客服链接
func (s *serviceTm) Url(ctx context.Context, SellerId, UserId interface{}) (res *ServiceUrlRes, err error) {
method := "getCustomServiceUrl"
request := map[string]string{
"BizUid": server.BizUid,
"SellerId": gconv.String(SellerId),
"AccountType": "ANONY",
"ThirdPartyUserId": gconv.String(UserId),
}
result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res)
return
}
package tm
import (
"context"
"encoding/json"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
link "github.com/alibabacloud-go/linkedmall-20220531/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
)
type Config struct {
AppKey string
AppSecret string
TenantId string
DistributorId string
DistributionMallId string
DistributionSupplierId string
}
var server *Config
const PkgName = "tm"
const (
apiUrl string = "http://linkedmall.aliyuncs.com/"
regionId string = "cn-hangzhou"
bizId string = "LMALL201912050002"
signatureVersion string = "1.0"
signatureMethod string = "HMAC-SHA1"
version string = "2022-05-31"
format string = "JSON"
typeAnony string = "ANONY"
typeEp string = "EP"
logName string = "tmNew"
)
func New(req *Config) {
server = req
return
}
func initClient() (client *link.Client, err error) {
config := &openapi.Config{
AccessKeyId: tea.String(server.AppKey),
AccessKeySecret: tea.String(server.AppSecret),
}
// 访问的域名
config.Endpoint = tea.String("linkedmall.aliyuncs.com")
client, err = link.NewClient(config)
return
}
func log(ctx context.Context, param string, res interface{}, err error) {
start := gtime.TimestampMilli()
resString, _ := json.Marshal(res)
if err != nil {
g.Log().Ctx(ctx).Cat(logName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", param, err.Error(), gtime.TimestampMilli()-start)
} else {
g.Log().Ctx(ctx).Cat(logName).Infof("参数【%v】响应【%v】响应时间【%v ms】", param, string(resString), gtime.TimestampMilli()-start)
}
return
}
// todo 部分接口验签通过,部分不通过天猫技术不支持对接,后续有时间再自己写
//func specialUrlEncode(req string) (res string) {
// req = url.QueryEscape(req)
// req = strings.Replace(req, "+", "%20", -1)
// req = strings.Replace(req, "*", "%2A", -1)
// req = strings.Replace(req, "*7E", "~", -1)
// res = req
// return
//}
//
//func sign(param map[string]string) {
// var keys []string
//
// mewparam := param
// for k := range mewparam {
// keys = append(keys, k)
// }
//
// sort.Strings(keys)
//
// var signStr string
//
// u := url.Values{}
// for _, v := range keys {
// u.Set(v, mewparam[v])
// }
// signStr += specialUrlEncode(u.Encode())
// signStr = "POST&" + specialUrlEncode("/") + "&" + signStr
//
// param["Signature"] = hmacsha1Base64(signStr)
//
// return
//}
//
//func hmacsha1Base64(str string) string {
// appSecret := []byte(server.AppSecret + "&")
// mac := hmac.New(sha1.New, appSecret)
// mac.Write([]byte(str))
// return base64.StdEncoding.EncodeToString(mac.Sum(nil))
//}
//
//func post(ctx context.Context, method string, params map[string]string) (str string, err error) {
// Start := gtime.TimestampMilli()
// curtime := time.Now().UTC()
// params["Action"] = method
// params["AccessKeyId"] = server.AppKey
// params["RegionId"] = regionId
// params["SignatureMethod"] = signatureMethod
// params["SignatureVersion"] = signatureVersion
// params["Version"] = version
// params["Format"] = format
// params["SignatureNonce"] = grand.S(32)
// params["Timestamp"] = curtime.Format("2006-01-02T15:04:05Z")
// params["Style"] = "RPC"
// params["ReqBodyType"] = "formData"
// params["BodyType"] = "json"
//
// sign(params)
//
// Request := g.Client()
// Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
// Request.Timeout(3 * time.Second)
// resp, err := Request.Post(apiUrl, params)
// defer func() {
// _ = resp.Close()
// paramStr := gjson.New(params).MustToJsonString()
// ctx = context.WithValue(ctx, "Method", "POST")
// ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"])
// if err != nil {
// g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
// } else {
// g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
// }
// }()
// str = resp.ReadAllString()
// return
//
//}
//
//func convert(pre string, req []map[string]interface{}) (res map[string]string) {
// res = make(map[string]string)
// for k, v := range req {
// for key, val := range v {
// if reflect.TypeOf(val).String() == "[]string" {
// for key2, val2 := range gconv.Strings(val) {
// res[pre+"."+gconv.String(k+1)+"."+key+"."+gconv.String(key2+1)] = gconv.String(val2)
// }
// } else {
// res[pre+"."+gconv.String(k+1)+"."+key] = gconv.String(val)
// }
// }
// }
// return
//}
//
//type CommonRes struct {
// Code string `json:"Code"`
// Message string `json:"Message"`
// RequestId string `json:"RequestId"`
//}
package tm
type accountTm struct {
}
var Account = accountTm{}
//Regist 注册单个淘宝账号接口(同步)
//func (s *accountTm) Regist(ctx context.Context, UserId string) (res *CommonRes, err error) {
// method := "RegistAnonymousTbAccount"
// result, err := post(ctx, method, map[string]string{
// "BizUid": server.BizUid,
// "ThirdPartyUserId": UserId,
// })
// _ = json.Unmarshal([]byte(result), &res)
// return
//}
package tm
import (
"context"
"encoding/json"
link "github.com/alibabacloud-go/linkedmall-20220531/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/gogf/gf/encoding/gjson"
)
type category struct {
}
var Category = category{}
type QueryMallCategoryListRes struct {
RequestId string `json:"RequestId"`
Message string `json:"Message"`
Model []struct {
CategoryId int `json:"CategoryId"`
ParentId int `json:"ParentId"`
Leaf bool `json:"Leaf"`
Name string `json:"Name"`
} `json:"Model"`
Code string `json:"Code"`
Success bool `json:"Success"`
}
//区域库存商品详情
func (s *category) QueryMallCategoryList(ctx context.Context,item int64) (res *QueryMallCategoryListRes, err error) {
client,err :=initClient()
if err!=nil{
return
}
if client==nil{
return
}
result ,err :=client.QueryMallCategoryList(&link.QueryMallCategoryListRequest{
DistributionMallId: tea.String(server.DistributionMallId),
DistributorId: tea.String(server.DistributorId),
CategoryId: tea.Int64(item),
TenantId: tea.String(server.TenantId),
})
if result==nil{
return
}
log(ctx,gjson.New(item).MustToJsonString(),result.Body,err)
if err!=nil{
return
}
a,_ :=json.Marshal(result.Body)
if err = json.Unmarshal([]byte(a), &res); err != nil {
return
}
return
}
type CategoryListRes struct {
Code string `json:"Code"` //成功 0000
Message string `json:"Message"`
RequestId string `json:"RequestId"`
CategoryList struct {
Category []struct {
CategoryId int `json:"CategoryId"`
Name string `json:"Name"`
} `json:"Category"`
} `json:"CategoryList"`
}
//func (category) List(ctx context.Context, req string) (res *CategoryListRes, err error) {
// method := "GetCategoryList"
//
// request := map[string]string{
// "CategoryId": req,
// }
//
// result, err := post(ctx, method, request)
// err = gjson.New(result).Scan(&res)
// return
//}
差异被折叠。
package tm
import (
"context"
"encoding/json"
link "github.com/alibabacloud-go/linkedmall-20220531/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/gogf/gf/encoding/gjson"
)
type logisticsTmNew struct {
}
var Logistics = logisticsTmNew{}
type LogisticsTraceRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Model []struct{
MailNo string `json:"MailNo"`
DataProvIDer string `json:"DataProvIDer"`
DataProvIDerTitle string `json:"DataProvIDerTitle"`
LogisticsCompanyCode string `json:"LogisticsCompanyCode"`
LogisticsCompanyName string `json:"LogisticsCompanyName"`
LogisticsDetailList []struct {
OcurrTimeStr string `json:"OcurrTimeStr"`
StanderdDesc string `json:"StanderdDesc"`
} `json:"LogisticsDetailList"`
Goods []struct {
GoodName string `json:"GoodName"`
Quantity interface{} `json:"Quantity"`
ItemID string `json:"ItemID"`
} `json:"Goods"`
} `json:"Model"`
}
//Trace 物流查询接口
func (s *logisticsTmNew) QueryLogistics4Distribution(ctx context.Context,orderSn string) (res *LogisticsTraceRes, err error) {
client,err :=initClient()
if err!=nil{
return
}
if client==nil{
return
}
result ,err :=client.QueryLogistics4Distribution(&link.QueryLogistics4DistributionRequest{
DistributorId: tea.String(server.DistributorId),
MainDistributionOrderId: tea.String(orderSn),
TenantId: tea.String(server.TenantId),
})
if result==nil{
return
}
log(ctx,gjson.New(orderSn).MustToJsonString(),result.Body,err)
if err!=nil{
return
}
a,_:=json.Marshal(result.Body)
err =json.Unmarshal([]byte(a),&res)
return
}
\ No newline at end of file
差异被折叠。
package tm
import (
"context"
"encoding/json"
link "github.com/alibabacloud-go/linkedmall-20220531/v2/client"
"github.com/alibabacloud-go/tea/tea"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/util/gconv"
)
type refundTm struct {
}
var Refund = refundTm{}
type RefundSubmitReq struct {
UserId string
SubLmOrderId string //子订单号
DisputeId string //售后ID
CpCode string //物流编码
LogisticsNo string //物流单号
}
type RefundCancelRes struct {
Code string `json:" Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Model struct {
SubDistributionOrderId string `json:"SubDistributionOrderId"`
DisputeStatus int `json:"DisputeStatus"`
DisputeType int `json:"DisputeType"`
} `json:"Model"`
}
type CommonRes struct {
Code string `json:" Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
}
type RefundBeforeReq struct {
SubDistributionOrderId string `json:"SubDistributionOrderId"`
BizClaimType int32 `json:"BizClaimType"`
GoodsStatus string `json:"GoodsStatus"`
}
type RefundBeforeRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Model struct {
SubDistributionOrderId string `json:"SubDistributionOrderId"`
BizClaimType int `json:"BizClaimType"`
MainOrderRefund bool `json:"MainOrderRefund"`
MaxRefundFeeData struct {
MaxRefundFee int `json:"MaxRefundFee"`
MinRefundFee int `json:"MinRefundFee"`
} `json:"MaxRefundFeeData"`
RefundReasonList []struct {
ReasonTextId string `json:"ReasonTextId"`
ReasonTips string `json:"ReasonTips"`
ProofRequired bool `json:"ProofRequired"`
RefundDescRequired bool `json:"RefundDescRequired"`
} `json:"RefundReasonList"`
}
}
type RefundApplyReq struct {
UserId string
SubLmOrderId string //子订单号
BizClaimType string //退款类型
ApplyRefundFee int64 //申请退款金额
ApplyRefundCount int32 //退货数量
ApplyReasonTextId int64 //退款原因ID
LeaveMessage string //留言
LeavePictureList []*RefundApplyPicture //凭证,某些原因要求必须有凭证。
GoodsStatus int32 //当退款类型:仅退款时,货物状态:为4未 发货。所有状态:4: 未发货, 6: 已发货, 1: 未收到货, 2: 已收到货, 3:已寄回, 5: 卖家确 认收货
}
type RefundApplyPicture struct {
Picture string `json:"Picture"` //图片地址
Desc string `json:"Desc"` //图片描述
}
type RefundApplyRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Model struct {
SubDistributionOrderId string `json:"SubDistributionOrderId"` //当前发起逆向的子订单号
DisputeStatus int `json:"DisputeStatus"` //逆向的状态
DisputeType int `json:"DisputeType"` //任意退款类型
DisputeId int64 `json:"DisputeId"` //shou
} `json:"Model"`
}
//Before 前置
func (s *refundTm) Before(ctx context.Context, req *RefundBeforeReq) (res *RefundBeforeRes, err error) {
client, err := initClient()
if err != nil {
return
}
if client == nil {
return
}
result, err := client.InitApplyRefund4Distribution(&link.InitApplyRefund4DistributionRequest{
BizClaimType: tea.Int32(req.BizClaimType),
DistributorId: tea.String(server.DistributorId),
SubDistributionOrderId: tea.String(req.SubDistributionOrderId),
TenantId: tea.String(server.TenantId),
GoodsStatus: tea.Int32(gconv.Int32(req.GoodsStatus)),
})
if result == nil {
return
}
ctx = context.WithValue(ctx, "URI", "InitApplyRefund4Distribution")
log(ctx, gjson.New(req).MustToJsonString(), result.Body, err)
a, _ := json.Marshal(result.Body)
err = json.Unmarshal([]byte(a), &res)
return
}
//Apply 申请
func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes, err error) {
client, err := initClient()
if err != nil {
return
}
if client == nil {
return
}
result, err := client.ApplyRefund4Distribution(&link.ApplyRefund4DistributionRequest{
ApplyReasonTextId: tea.Int64(req.ApplyReasonTextId),
ApplyRefundCount: tea.Int32(req.ApplyRefundCount),
ApplyRefundFee: tea.Int64(req.ApplyRefundFee),
BizClaimType: tea.Int32(gconv.Int32(req.BizClaimType)), //gconv.Int32(req.BizClaimType)
DistributorId: tea.String(server.DistributorId),
GoodsStatus: tea.Int32(req.GoodsStatus),
//LeaveMessage: tea.String("测试退款"),
LeavePictureLists: nil,
SubDistributionOrderId: tea.String(req.SubLmOrderId),
TenantId: tea.String(server.TenantId),
})
if result == nil {
return
}
ctx = context.WithValue(ctx, "URI", "ApplyRefund4Distribution")
log(ctx, gjson.New(req).MustToJsonString(), result.Body, err)
a, _ := json.Marshal(result.Body)
err = json.Unmarshal([]byte(a), &res)
return
}
type RefundInfoRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Model struct {
DistributionOrderId string `json:"DistributionOrderId"`
SubDistributionOrderId string `json:"SubDistributionOrderId"`
BizClaimType int `json:"BizClaimType"`
OrderLogisticsStatus int `json:"OrderLogisticsStatus"`
DisputeStatus int `json:"DisputeStatus"`
ReturnGoodLogisticsStatus int `json:"ReturnGoodLogisticsStatus"`
DisputeType int `json:"DisputeType"`
RefundFeeData struct {
MaxRefundFee int `json:"MaxRefundFee"`
MinRefundFee int `json:"MinRefundFee"`
} `json:"RefundFeeData"`
SellerRefuseReason string `json:"SellerRefuseReason"`
RefundFee int `json:"RefundFee"`
RealRefundFee int `json:"RealRefundFee"`
DisputeDesc string `json:"DisputeDesc"`
SellerAgreeMsg string `json:"SellerAgreeMsg"`
SellerRefuseAgreementMessage string `json:"SellerRefuseAgreementMessage"`
ApplyReason struct {
ReasonTextId int `json:"ReasonTextId"`
ReasonTips string `json:"ReasonTips"`
} `json:"ApplyReason"`
ApplyDisputeDesc string `json:"ApplyDisputeDesc"`
DisputeCreateTime string `json:"DisputeCreateTime"`
DisputeEndTime string `json:"DisputeEndTime"`
DisputeId int `json:"DisputeId"`
RefunderAddress string `json:"RefunderAddress"`
RefunderName string `json:"RefunderName"`
RefunderTel string `json:"RefunderTel"`
RefunderZipCode string `json:"RefunderZipCode"`
} `json:"Model"`
}
//Submit 提交退货物流信息接口
func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *CommonRes, err error) {
client, err := initClient()
if err != nil {
return
}
if client == nil {
return
}
result, err := client.SubmitReturnGoodLogistics4Distribution(&link.SubmitReturnGoodLogistics4DistributionRequest{
DisputeId: tea.Int64(gconv.Int64(req.DisputeId)),
DistributorId: tea.String(server.DistributorId),
SubDistributionOrderId: tea.String(req.SubLmOrderId),
TenantId: tea.String(server.TenantId),
LogisticsNo: tea.String(req.LogisticsNo),
CpCode: tea.String(req.CpCode),
})
if result == nil {
return
}
ctx = context.WithValue(ctx, "URI", "SubmitReturnGoodLogistics4Distribution")
log(ctx, gjson.New(req).MustToJsonString(), result.Body, err)
a, _ := json.Marshal(result.Body)
err = json.Unmarshal([]byte(a), &res)
return
}
//Cancel 取消退款申请接口
func (s *refundTm) Cancel(ctx context.Context, UserId, subLmOrderId, disputeId string) (res *RefundCancelRes, err error) {
client, err := initClient()
if err != nil {
return
}
if client == nil {
return
}
result, err := client.CancelRefund4Distribution(&link.CancelRefund4DistributionRequest{
DisputeId: tea.Int64(gconv.Int64(disputeId)),
DistributorId: tea.String(server.DistributorId),
SubDistributionOrderId: tea.String(subLmOrderId),
TenantId: tea.String(server.TenantId),
})
if result == nil {
return
}
ctx = context.WithValue(ctx, "URI", "CancelRefund4Distribution")
log(ctx, gjson.New(disputeId).MustToJsonString(), result.Body, err)
a, _ := json.Marshal(result.Body)
err = json.Unmarshal([]byte(a), &res)
return
}
//Info 详情
func (s *refundTm) Detail(ctx context.Context, subOrderId string) (res *RefundInfoRes, err error) {
client, err := initClient()
if err != nil {
return
}
if client == nil {
return
}
result, err := client.QueryRefundApplicationDetail4Distribution(&link.QueryRefundApplicationDetail4DistributionRequest{
DistributorId: tea.String(server.DistributorId),
SubDistributionOrderId: tea.String(subOrderId),
TenantId: tea.String(server.TenantId),
})
if result == nil {
return
}
ctx = context.WithValue(ctx, "URI", "QueryRefundApplicationDetail4Distribution")
log(ctx, gjson.New(subOrderId).MustToJsonString(), result.Body, err)
a, _ := json.Marshal(result.Body)
err = json.Unmarshal([]byte(a), &res)
return
}
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论