提交 8be3512b authored 作者: zhanglibo's avatar zhanglibo

爱库存

上级 1b1697b4
package ikc
import (
"context"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/encoding/gbase64"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/text/gstr"
"time"
)
type Config struct {
ApiUrl string
AppKey string
AppSecret string
}
var server *Config
const version = "1.0"
const pkgName = "aikucun"
func New(config *Config) {
server = config
return
}
type CommonRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
}
func post(ctx context.Context, method string, req interface{}) (res string, err error) {
Start := gtime.TimestampMilli()
param := gjson.New(req)
Url := server.ApiUrl + method
_ = param.Set("appKey", server.AppKey)
_ = param.Set("timestamp", gtime.TimestampMilliStr())
_ = param.Set("version", version)
_ = param.Set("sign", sign(param))
Request := g.Client()
Request.SetHeader("Content-Type", "application/json")
resp, err := Request.Timeout(time.Second*5).Post(Url, param.MustToJsonString())
defer func() {
_ = resp.Close()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method)
if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
}
}()
res = resp.ReadAllString()
return
}
func sign(req *gjson.Json) string {
param := req.MustToJsonString() + server.AppSecret
param = gbase64.EncodeString(param)
return gstr.ToUpper(gmd5.MustEncryptString(param))
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type activityIkc struct {
}
//Activity 活动
var Activity = activityIkc{}
type ActivityListReq struct {
ActiveModel int `json:"activeModel,omitempty"`
CategoryId string `json:"categoryId,omitempty"`
ActiveIds []string `json:"activeIds,omitempty"`
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
}
type ActivityListRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Total int `json:"total"`
Data []struct {
Activity struct {
Id string `json:"id"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Name string `json:"name"`
Description string `json:"description"`
Banner []string `json:"banner"`
Brand string `json:"brand"`
BrandLogoUrl string `json:"brandLogoUrl"`
StatementByDay string `json:"statementByDay"`
CategoryId string `json:"categoryId"`
Category string `json:"category"`
DeliverTime string `json:"deliverTime"`
Content string `json:"content"`
ActiveModel int `json:"activeModel"`
AftersaleEndTime string `json:"aftersaleEndTime"`
PreviewInformation string `json:"previewInformation"`
RefundInsurance bool `json:"refundInsurance"`
IsExchangeRefundGoods int `json:"isExchangeRefundGoods"`
ActiveType int `json:"activeType"`
Status int `json:"status"`
} `json:"activity"`
} `json:"data"`
}
//List 列表
func (*activityIkc) List(ctx context.Context, req ActivityListReq) (res *ActivityListRes, err error) {
method := "activity/v2/list/filter"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type ActivityDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Activity struct {
Id string `json:"id"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Name string `json:"name"`
Description string `json:"description"`
Banner []string `json:"banner"`
Brand string `json:"brand"`
BrandLogoUrl string `json:"brandLogoUrl"`
StatementByDay string `json:"statementByDay"`
CategoryId string `json:"categoryId"`
Category string `json:"category"`
DeliverTime string `json:"deliverTime"`
Content string `json:"content"`
ActiveModel int `json:"activeModel"`
AftersaleEndTime string `json:"aftersaleEndTime"`
PreviewInformation string `json:"previewInformation"`
RefundInsurance bool `json:"refundInsurance"`
IsExchangeRefundGoods int `json:"isExchangeRefundGoods"`
ActiveType int `json:"activeType"`
WaterMarkLicense string `json:"waterMarkLicense"`
IsSuppotVatInvoice int `json:"isSuppotVatInvoice"`
Status int `json:"status"`
} `json:"activity"`
} `json:"data"`
}
//Detail 详情
func (*activityIkc) Detail(ctx context.Context, req string) (res *ActivityDetailRes, err error) {
method := "activity/detail"
result, err := post(ctx, method, g.Map{
"liveId": req,
})
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type addressIkc struct {
}
//Address 地址
var Address = addressIkc{}
type AddressProvinceRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
ProvinceCode string `json:"provinceCode"`
ProvinceName string `json:"provinceName"`
} `json:"data"`
}
//Province 省
func (addressIkc) Province(ctx context.Context) (res *AddressProvinceRes, err error) {
method := "address/v2/queryProvince"
result, err := post(ctx, method, g.Map{})
_ = gjson.New(result).Scan(&res)
return
}
type AddressCityRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
CityName string `json:"cityName"`
CityCode string `json:"cityCode"`
} `json:"data"`
}
//City 市
func (addressIkc) City(ctx context.Context, code string) (res *AddressCityRes, err error) {
method := "address/v2/queryCity"
result, err := post(ctx, method, g.Map{
"provinceCode": code,
})
_ = gjson.New(result).Scan(&res)
return
}
type AddressAreaRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
AreaCode string `json:"areaCode"`
AreaName string `json:"areaName"`
} `json:"data"`
}
//Area 区
func (addressIkc) Area(ctx context.Context, code string) (res *AddressAreaRes, err error) {
method := "address/v2/queryArea"
result, err := post(ctx, method, g.Map{
"cityCode": code,
})
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type categoryIkc struct {
}
//Category 品类
var Category = categoryIkc{}
type CategoryListRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
Id string `json:"id"`
Name string `json:"name"`
Sort int `json:"sort"`
} `json:"data"`
}
//List 列表
func (*categoryIkc) List(ctx context.Context) (res *CategoryListRes, err error) {
method := "category/frontCategory"
result, err := post(ctx, method, g.Map{})
_ = gjson.New(result).Scan(&res)
return
}
type CategoryTreeRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
Pid string `json:"pid"`
ParentId string `json:"parentId"`
CategoryCode string `json:"categoryCode"`
CategoryName string `json:"categoryName"`
CategoryNameEn string `json:"categoryNameEn,omitempty"`
CategoryLevel int `json:"categoryLevel"`
OrderNo int `json:"orderNo"`
} `json:"data"`
}
//Tree 类目树
func (*categoryIkc) Tree(ctx context.Context, level interface{}) (res *CategoryTreeRes, err error) {
method := "category/getTree"
result, err := post(ctx, method, g.Map{
"level": gconv.Int(level),
})
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type couponIkc struct {
}
//Coupon 优惠券
var Coupon = couponIkc{}
type CouponListRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
Id string `json:"id"`
Name string `json:"name"`
CouponDesc string `json:"couponDesc"`
Amount float64 `json:"amount"`
ThresholdAmount float64 `json:"thresholdAmount"`
LiveId string `json:"liveId"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
CurrentNum int `json:"currentNum"`
RestrictNum int `json:"restrictNum"`
} `json:"data"`
}
//List 列表
func (*couponIkc) List(ctx context.Context, liveIds string) (res *CouponListRes, err error) {
method := "coupon/list"
result, err := post(ctx, method, g.Map{
"liveIds": liveIds,
})
_ = gjson.New(result).Scan(&res)
return
}
type CouponDrawRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
CouponUsedId string `json:"couponUsedId"`
Id string `json:"id"`
Name string `json:"name"`
Type int `json:"type"`
CouponDesc string `json:"couponDesc"`
Time string `json:"time"`
OverTime int64 `json:"overTime"`
Amount string `json:"amount"`
ThresholdAmount string `json:"thresholdAmount"`
} `json:"data"`
}
//Draw 领取
//`UserId` 外部渠道商用户ID
//`couponId` 优惠券ID
func (*couponIkc) Draw(ctx context.Context, UserId, couponId string) (res *CouponDrawRes, err error) {
method := "coupon/draw"
result, err := post(ctx, method, g.Map{
"outerUserId": UserId,
"couponId": couponId,
})
_ = gjson.New(result).Scan(&res)
return
}
type CouponRecommendReq struct {
UserId string `json:"outerUserId"` //外部渠道商用户ID
ProductList []CouponRecommendItem `json:"productList"`
}
type CouponRecommendItem struct {
LiveId string `json:"liveId"` //活动 ID
ProductId string `json:"productId"` //商品 ID
Count int `json:"count"` //数量
}
type CouponRecommendRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
Id string `json:"id"`
CouponId string `json:"couponId"`
Amount float64 `json:"amount"`
Name string `json:"name"`
CouponDesc string `json:"couponDesc"`
ThresholdAmount float64 `json:"thresholdAmount"`
Time string `json:"time"`
IsDefRecommend int `json:"isDefRecommend"`
} `json:"data"`
}
//Recommend 已领推荐优惠券
func (*couponIkc) Recommend(ctx context.Context, req CouponRecommendReq) (res *CouponRecommendRes, err error) {
method := "coupon/recommends"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type CouponHadReq struct {
UserId string `json:"outerUserId"` //外部渠道商用户ID
Status string `json:"status"` //优惠券状态 0-未使用 2-已使用或者已失效
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
}
type CouponHadRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Total int `json:"total"`
UserCouponList []struct {
Id string `json:"id"`
UseId string `json:"useId"`
Name string `json:"name"`
CouponDesc string `json:"couponDesc"`
Amount float64 `json:"amount"`
ThresholdAmount float64 `json:"thresholdAmount"`
OverTime string `json:"overTime"`
Status int `json:"status"`
Time string `json:"time"`
Type int `json:"type"`
} `json:"userCouponList"`
} `json:"data"`
}
//Had 已领优惠券查询
func (*couponIkc) Had(ctx context.Context, req CouponHadReq) (res *CouponHadRes, err error) {
method := "coupon/user-had"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type deliverIkc struct {
}
var Deliver = deliverIkc{}
type DeliverDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
OrderId string `json:"orderId"`
ShipmentList []struct {
OrderDetailId string `json:"orderDetailId"`
ShipmentNo string `json:"shipmentNo"`
LogisticsCompany string `json:"logisticsCompany"`
LogisticsCompanyName string `json:"logisticsCompanyName"`
LogisticsCode string `json:"logisticsCode"`
} `json:"shipmentList"`
} `json:"data"`
}
func (*deliverIkc) Detail(ctx context.Context, orderId string) (res *DeliverDetailRes, err error) {
method := "order/queryLogistics"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
type DeliverTrackRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
LogisticsNo string `json:"logisticsNo"`
LogisticsCompany string `json:"logisticsCompany"`
ExpressCompanyNo int `json:"expressCompanyNo,omitempty"`
TraceItemList []struct {
Time string `json:"time"`
Content string `json:"content"`
} `json:"traceItemList"`
} `json:"data"`
}
//Track 物流轨迹
func (*deliverIkc) Track(ctx context.Context, orderId string) (res *DeliverTrackRes, err error) {
method := "delivery/order/track"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type goodsIkc struct {
}
//Goods 商品
var Goods = goodsIkc{}
type GoodsListReq struct {
LiveId string `json:"liveId"`
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
SortedType int `json:"sortedType"` //顺序 1:正序,2倒序 默认2
SortedModel int `json:"sortedModel"` //排序模式 1:默认(售罄沉底、运营指定顺序、上架次数、播号) 3:销量(累计30天) 6:上新次数 7:销售价 9:折扣 10:开始时间 默认排序模式只有倒序
}
type goodsListRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Total int `json:"total"`
ProductList []struct {
ActivityId string `json:"activityId"`
ProductId string `json:"productId"`
Status int `json:"status"`
Brand string `json:"brand"`
BrandUrl string `json:"brandUrl"`
TagPrice float64 `json:"tagPrice"`
CategoryCode string `json:"categoryCode"`
Category string `json:"category"`
Picture []string `json:"picture"`
BrandSizeUrl string `json:"brandSizeUrl"`
Price float64 `json:"price"`
Name string `json:"name"`
SettlementPrice float64 `json:"settlementPrice"`
Profit float64 `json:"profit"`
Description string `json:"description"`
Pinlei1 string `json:"pinlei1"`
Pinlei1Name string `json:"pinlei1name"`
Pinlei2 string `json:"pinlei2"`
Pinlei2Name string `json:"pinlei2name"`
VideoUrl string `json:"videoUrl"`
VideoCoverUrl string `json:"videoCoverUrl"`
StyleNo string `json:"styleNo"`
MerStyleNo string `json:"merStyleNo"`
ProductNum string `json:"productNum"`
SupportExchange int `json:"supportExchange"`
Color string `json:"color"`
BaseProperties []interface{} `json:"baseProperties"`
MeasureProperties []interface{} `json:"measureProperties"`
ProductMateria []interface{} `json:"productMateria"`
SkuList []struct {
SkuId string `json:"skuId"`
AttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"attributeList"`
LeftStoreNum int `json:"leftStoreNum"`
} `json:"skuList"`
SkusAttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"skusAttributeList"`
ProfitAdditional struct {
MarketId string `json:"marketId"`
ProfitAdditional float64 `json:"profitAdditional"`
} `json:"profitAdditional"`
PromoTags []struct {
Code string `json:"code"`
Name string `json:"name"`
Type int `json:"type"`
} `json:"promoTags"`
RefundInsurance bool `json:"refundInsurance"`
IsExchangeRefundGoods int `json:"isExchangeRefundGoods"`
} `json:"productList"`
} `json:"data"`
}
//List 列表
func (*goodsIkc) List(ctx context.Context, req GoodsListReq) (res *goodsListRes, err error) {
method := "product/list"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type GoodsDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Product struct {
ActivityId string `json:"activityId"`
ProductId string `json:"productId"`
Status int `json:"status"`
Brand string `json:"brand"`
BrandUrl string `json:"brandUrl"`
TagPrice float64 `json:"tagPrice"`
CategoryCode string `json:"categoryCode"`
Category string `json:"category"`
Picture []string `json:"picture"`
BrandSizeUrl string `json:"brandSizeUrl"`
Price float64 `json:"price"`
Name string `json:"name"`
SettlementPrice float64 `json:"settlementPrice"`
Profit float64 `json:"profit"`
Description string `json:"description"`
Pinlei1 string `json:"pinlei1"`
Pinlei1Name string `json:"pinlei1name"`
Pinlei2 string `json:"pinlei2"`
Pinlei2Name string `json:"pinlei2name"`
VideoUrl string `json:"videoUrl"`
VideoCoverUrl string `json:"videoCoverUrl"`
StyleNo string `json:"styleNo"`
MerStyleNo string `json:"merStyleNo"`
ProductNum string `json:"productNum"`
SupportExchange int `json:"supportExchange"`
Color string `json:"color"`
BaseProperties []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"baseProperties"`
MeasureProperties []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"measureProperties"`
ProductMateria []interface{} `json:"productMateria"`
SkuList []struct {
SkuId string `json:"skuId"`
AttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"attributeList"`
LeftStoreNum int `json:"leftStoreNum"`
} `json:"skuList"`
SkusAttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"skusAttributeList"`
Weight string `json:"weight"`
Volume string `json:"volume"`
ProfitAdditional struct {
MarketId string `json:"marketId"`
ProfitAdditional float64 `json:"profitAdditional"`
} `json:"profitAdditional"`
PromoTags []struct {
Code string `json:"code"`
Name string `json:"name"`
Type int `json:"type"`
} `json:"promoTags"`
RefundInsurance bool `json:"refundInsurance"`
IsExchangeRefundGoods int `json:"isExchangeRefundGoods"`
} `json:"product"`
} `json:"data"`
}
//Detail 详情
func (*goodsIkc) Detail(ctx context.Context, GoodsID, activeId string) (res *GoodsDetailRes, err error) {
method := "product/detail"
result, err := post(ctx, method, g.Map{
"productId": GoodsID,
"activeId": activeId,
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodsStockReq struct {
LiveId string `json:"liveId"`
SkuIds []string `json:"skuIds"`
}
type GoodsStockRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
LiveId string `json:"liveId"`
InventoryList []struct {
SkuId string `json:"skuId"`
CurrentStock string `json:"currentStock"`
} `json:"inventoryList"`
} `json:"data"`
}
//Stock 库存
func (*goodsIkc) Stock(ctx context.Context, req GoodsStockReq) (res *GoodsStockRes, err error) {
method := "inventory/query"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type GoodsBatchReq struct {
Params []GoodsBatchItem `json:"params"`
}
type GoodsBatchItem struct {
GoodsID string `json:"productId"`
ActivityId string `json:"activityId"`
}
type GoodsBatchRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Products []struct {
ActivityId string `json:"activityId"`
ProductId string `json:"productId"`
Status int `json:"status"`
Brand string `json:"brand"`
BrandUrl string `json:"brandUrl"`
TagPrice float64 `json:"tagPrice"`
CategoryCode string `json:"categoryCode"`
Category string `json:"category"`
Price float64 `json:"price"`
Name string `json:"name"`
SettlementPrice float64 `json:"settlementPrice"`
Profit float64 `json:"profit"`
Description string `json:"description"`
Pinlei1 string `json:"pinlei1"`
Pinlei1Name string `json:"pinlei1name"`
Pinlei2 string `json:"pinlei2"`
Pinlei2Name string `json:"pinlei2name"`
StyleNo string `json:"styleNo"`
MerStyleNo string `json:"merStyleNo"`
ProductNum string `json:"productNum"`
SupportExchange int `json:"supportExchange"`
Color string `json:"color"`
SkuList []struct {
SkuId string `json:"skuId"`
AttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"attributeList"`
LeftStoreNum int `json:"leftStoreNum"`
} `json:"skuList"`
SkusAttributeList []struct {
AttributeName string `json:"attributeName"`
AttributeValue string `json:"attributeValue"`
} `json:"skusAttributeList"`
ProfitAdditional struct {
MarketId string `json:"marketId"`
ProfitAdditional float64 `json:"profitAdditional"`
} `json:"profitAdditional"`
PromoTags []struct {
Code string `json:"code"`
Name string `json:"name"`
Type int `json:"type"`
} `json:"promoTags"`
RefundInsurance bool `json:"refundInsurance"`
IsExchangeRefundGoods int `json:"isExchangeRefundGoods"`
} `json:"products"`
} `json:"data"`
}
//Batch 批量查询
func (*goodsIkc) Batch(ctx context.Context, req GoodsBatchReq) (res *GoodsBatchRes, err error) {
method := "product/listByIds"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type GoodsFreightReq struct {
Province string `json:"province"`
City string `json:"city"`
Area string `json:"area"`
List []GoodsFreightItem `json:"productList"`
}
type GoodsFreightItem struct {
LiveId string `json:"liveId"` //活动 ID
ProductId string `json:"productId"` //商品 ID
Count string `json:"count"` //商品数量
}
type GoodsFreightRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
ProductList []struct {
LiveId string `json:"liveId"`
ProductId string `json:"productId"`
AllowDeliver int `json:"allowDeliver"`
DenyReason string `json:"denyReason,omitempty"`
} `json:"productList"`
FreightList []struct {
Freight float64 `json:"freight"`
ProductList []struct {
LiveId string `json:"liveId"`
ProductId string `json:"productId"`
Count int `json:"count"`
} `json:"productList"`
} `json:"freightList"`
} `json:"data"`
}
//Freight 查询运费
func (*goodsIkc) Freight(ctx context.Context, req GoodsFreightReq) (res *GoodsFreightRes, err error) {
method := "freight/query"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type orderIkc struct {
}
//Order 订单
var Order = orderIkc{}
type OrderCreateReq struct {
OrderSn string `json:"externalOrderNo"`
Address OrderCreateAddr `json:"address"`
OuterUserId string `json:"outerUserId,omitempty"`
CouponIds []string `json:"couponIds,omitempty"`
List []OrderCreateItem `json:"productList"`
}
type OrderCreateAddr struct {
Name string `json:"name"` //收货人名称
Mobile string `json:"mobile"`
Province string `json:"province"`
City string `json:"city"`
Area string `json:"area"`
Street string `json:"street"`
}
type OrderCreateItem struct {
LiveId string `json:"liveId"` //活动 ID
ProductId string `json:"productId"` //商品 ID
SkuId string `json:"skuId"` //SKU ID
Amount string `json:"amount"` //数量
Price string `json:"settlementPrice"` //商品结算金额 单位分
}
type OrderCreateRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
PaymentOrder struct {
PaymentNo string `json:"paymentNo"`
TotalAmount int `json:"totalAmount"`
ShipmentAmount int `json:"shipmentAmount"`
DiscountAmount int `json:"discountAmount"`
ProductsAmount int `json:"productsAmount"`
OrderList []struct {
OrderId string `json:"orderId"`
TotalAmount int `json:"totalAmount"`
ShipmentAmount int `json:"shipmentAmount"`
DiscountAmount int `json:"discountAmount"`
OrderStatus interface{} `json:"orderStatus"`
ProductsAmount int `json:"productsAmount"`
PaymentStatus interface{} `json:"paymentStatus"`
OrderDetailList []struct {
OrderDetailId string `json:"orderDetailId"`
SkuId string `json:"skuId"`
ProductId string `json:"productId"`
Price int `json:"price"`
Amount int `json:"amount"`
OrderDetailStatus interface{} `json:"orderDetailStatus"`
AfterSaleStatus interface{} `json:"afterSaleStatus"`
ProductStatus interface{} `json:"productStatus"`
} `json:"orderDetailList"`
} `json:"orderList"`
} `json:"paymentOrder"`
} `json:"data"`
}
//Create 下单
func (*orderIkc) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "order/create"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
//Cancel 支付前整单取消
//`orderId` 订单号
func (*orderIkc) Cancel(ctx context.Context, orderId string) (res *CommonRes, err error) {
method := "order/before/cancel"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
//Pay 支付
//`orderId` 订单号
func (*orderIkc) Pay(ctx context.Context, orderId string) (res *CommonRes, err error) {
method := "order/before/cancel"
result, err := post(ctx, method, g.Map{
"orderPaymentNo": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
//PayCancel 支付后整单取消
//`orderId` 订单号
func (*orderIkc) PayCancel(ctx context.Context, orderId string) (res *CommonRes, err error) {
method := "order/after/cancelByOrder"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
//GoodsCancel 支付后商品取消
//`orderId` 订单号
//`DetailId` 三级单号
func (*orderIkc) GoodsCancel(ctx context.Context, orderId, DetailId string) (res *CommonRes, err error) {
method := "order/after/cancel"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
"orderDetailId": DetailId,
})
_ = gjson.New(result).Scan(&res)
return
}
type OrderDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
Order struct {
OrderId string `json:"orderId"`
LiveId string `json:"liveId"`
TotalAmount int `json:"totalAmount"`
ShipmentAmount int `json:"shipmentAmount"`
DiscountAmount int `json:"discountAmount"`
OrderStatus int `json:"orderStatus"`
ProductsAmount int `json:"productsAmount"`
PaymentStatus int `json:"paymentStatus"`
RefundInsurance bool `json:"refundInsurance"`
OrderDetailList []struct {
OrderDetailId string `json:"orderDetailId"`
LiveId string `json:"liveId"`
SkuId string `json:"skuId"`
ProductId string `json:"productId"`
Price int `json:"price"`
Amount int `json:"amount"`
OrderDetailStatus int `json:"orderDetailStatus"`
AfterSaleStatus int `json:"afterSaleStatus"`
ProductStatus int `json:"productStatus"`
AftersaleDeadline string `json:"aftersaleDeadline"`
} `json:"orderDetailList"`
} `json:"order"`
} `json:"data"`
}
//Detail 详情
//`orderId` 订单号
func (*orderIkc) Detail(ctx context.Context, orderId string) (res *OrderDetailRes, err error) {
method := "order/queryByOrderId"
result, err := post(ctx, method, g.Map{
"orderId": orderId,
})
_ = gjson.New(result).Scan(&res)
return
}
type OrderReflectDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
PaymentOrder struct {
PaymentNo string `json:"paymentNo"`
TotalAmount int `json:"totalAmount"`
ShipmentAmount int `json:"shipmentAmount"`
DiscountAmount int `json:"discountAmount"`
ProductsAmount int `json:"productsAmount"`
RefundInsurance bool `json:"refundInsurance"`
OrderList []struct {
OrderId string `json:"orderId"`
LiveId string `json:"liveId"`
TotalAmount int `json:"totalAmount"`
ShipmentAmount int `json:"shipmentAmount"`
DiscountAmount int `json:"discountAmount"`
OrderStatus int `json:"orderStatus"`
ProductsAmount int `json:"productsAmount"`
PaymentStatus int `json:"paymentStatus"`
OrderDetailList []struct {
OrderDetailId string `json:"orderDetailId"`
LiveId string `json:"liveId"`
SkuId string `json:"skuId"`
ProductId string `json:"productId"`
Price int `json:"price"`
Amount int `json:"amount"`
DiscountAmount float64 `json:"discountAmount"`
SettlementAmount float64 `json:"settlementAmount"`
OrderDetailStatus int `json:"orderDetailStatus"`
AfterSaleStatus int `json:"afterSaleStatus"`
ProductStatus int `json:"productStatus"`
AftersaleDeadline string `json:"aftersaleDeadline"`
} `json:"orderDetailList"`
} `json:"orderList"`
} `json:"paymentOrder"`
} `json:"data"`
}
//ReflectDetail 详情[按外部订单号查询]
func (*orderIkc) ReflectDetail(ctx context.Context, OrderSn string) (res *OrderReflectDetailRes, err error) {
method := "order/queryByExternalOrderNo"
result, err := post(ctx, method, g.Map{
"externalOrderNo": OrderSn,
})
_ = gjson.New(result).Scan(&res)
return
}
package ikc
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type refundIkc struct {
}
//Refund 售后
var Refund = refundIkc{}
type RefundCreateReq struct {
OrderId string `json:"orderId"` //二级单号
DetatilId string `json:"orderDetatilId"` //三级订单号
PicUrls string `json:"picUrls"` //图片, 逗号隔开, 最多三张
Description string `json:"description"` //描述(100字内)
RefundReason string `json:"refundReason"` //退货原因: 0- 不想要了(无理由) 1- 商品漏发 2-质量问题 3-发错款号 4-发错颜色 5-发错尺码
Type string `json:"applicationType"` //服务类型: 2-漏发退款 4-退货退款
IsReceived string `json:"isReceived"` //漏发退款是否收货标识 0-未收货(整件漏发) 1-已收货(部分漏发)
Amount string `json:"amount"` //申请退款金额 单位:元
}
type RefundCreateRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data []struct {
OrderId string `json:"orderId"`
OrderDetailId string `json:"orderDetailId"`
ApprovalType int `json:"approvalType"`
AuditResult string `json:"auditResult"`
AuditType int `json:"auditType"`
ApplyTime string `json:"applyTime"`
} `json:"data"`
}
//Create 申请
func (*refundIkc) Create(ctx context.Context, req RefundCreateReq) (res *RefundCreateRes, err error) {
method := "after-sale/new/create"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type RefundSubmitReq struct {
ApplicationNo string `json:"applicationNo"` //申请编号
LogisticsCompany string `json:"logisticsCompany"` //物流公司名
ShipmentNo string `json:"shipmentNo"` //物流单号
ReturnAddress string `json:"returnAddress"` //用户收货地址
ReturnName string `json:"returnName"` //退回联系人
ReturnPhone string `json:"returnPhone"` //退回人电话
LogisticsCode string `json:"logisticsCode"` //物流公司code
}
type RefundSubmitRes struct {
ResultCode int `json:"resultCode"`
Data struct {
ApplicationNo string `json:"applicationNo"`
} `json:"data"`
}
//Submit 上传快递单
func (*refundIkc) Submit(ctx context.Context, req RefundSubmitReq) (res *RefundSubmitRes, err error) {
method := "after-sale/new/uploadlogistics"
result, err := post(ctx, method, req)
_ = gjson.New(result).Scan(&res)
return
}
type RefundDetailRes struct {
ResultCode int `json:"resultCode"`
ResultMessage string `json:"resultMessage"`
Data struct {
ApplicationNo string `json:"applicationNo"`
ApplicationType string `json:"applicationType"`
LogisticsCompany string `json:"logisticsCompany"`
ShipmentNo string `json:"shipmentNo"`
ReturnAddress string `json:"returnAddress"`
ReturnName string `json:"returnName"`
ReturnPhone string `json:"returnPhone"`
Amount string `json:"amount"`
Profit string `json:"profit"`
Freight string `json:"freight"`
AuditStatus string `json:"auditStatus"`
FirstAuditTime string `json:"firstAuditTime"`
WarehouseAuditTime string `json:"warehouseAuditTime"`
Style string `json:"style"`
Barcode string `json:"barcode"`
Size string `json:"size"`
Price string `json:"price"`
ApplicationReasonFirLevel string `json:"applicationReasonFirLevel"`
ApplicationReasonFirLevelName string `json:"applicationReasonFirLevelName"`
ProblemDescription string `json:"problemDescription"`
ApplicationTime string `json:"applicationTime"`
ProductPicUrls []string `json:"productPicUrls"`
FreightInsuranceInfo struct {
ClaimAmount string `json:"claimAmount"`
ClaimRemark string `json:"claimRemark"`
RefundInsurance bool `json:"refundInsurance"`
} `json:"freightInsuranceInfo"`
} `json:"data"`
}
//Detail 查询售后单
//`applicationNo` 申请单号
func (*refundIkc) Detail(ctx context.Context, applicationNo string) (res *RefundDetailRes, err error) {
method := "after-sale/new/query"
result, err := post(ctx, method, g.Map{
"applicationNo": applicationNo,
})
_ = gjson.New(result).Scan(&res)
return
}
//Cancel 取消
//`applicationNo` 申请单号
//`DetailId` 三级单号
func (*refundIkc) Cancel(ctx context.Context, applicationNo, DetailId string) (res *CommonRes, err error) {
method := "after-sale/new/cancel"
result, err := post(ctx, method, g.Map{
"applicationNo": applicationNo,
"orderDetailId": DetailId,
})
_ = gjson.New(result).Scan(&res)
return
}
type RefundAddressRes struct {
ResultCode int `json:"resultCode"`
Data struct {
LiveId string `json:"liveId"`
Phone string `json:"phone"`
Address string `json:"address"`
Name string `json:"name"`
Type string `json:"type"`
} `json:"data"`
}
func (*refundIkc) Address(ctx context.Context, liveId string) (res *RefundAddressRes, err error) {
method := "after-sale/new/queryAfterSaleAdd"
result, err := post(ctx, method, g.Map{
"liveId": liveId,
})
_ = gjson.New(result).Scan(&res)
return
}
...@@ -13,6 +13,7 @@ const ( ...@@ -13,6 +13,7 @@ const (
Gome = 10 //国美 Gome = 10 //国美
Schl = 11 //盛创汇联 Schl = 11 //盛创汇联
Wpc = 12 //唯品会 Wpc = 12 //唯品会
Ikc = 13 //爱库存
) )
var ( var (
...@@ -65,6 +66,10 @@ func GetUpstreamList() (res interface{}, err error) { ...@@ -65,6 +66,10 @@ func GetUpstreamList() (res interface{}, err error) {
"key": Wpc, "key": Wpc,
"name": GetUpstreamName(Wpc), "name": GetUpstreamName(Wpc),
}, },
g.Map{
"key": Ikc,
"name": GetUpstreamName(Ikc),
},
} }
return return
} }
...@@ -86,7 +91,9 @@ func GetUpstreamName(source int) string { ...@@ -86,7 +91,9 @@ func GetUpstreamName(source int) string {
case Schl: case Schl:
return "盛创汇联" return "盛创汇联"
case Wpc: case Wpc:
return "特卖专场" return "特卖一仓"
case Ikc:
return "特卖二仓"
default: default:
return "未知来源" return "未知来源"
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论