提交 41745c87 authored 作者: 屈传平's avatar 屈传平

hdh

上级 6e661735
package hdh
//会订货
import (
"context"
"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/util/gconv"
"time"
)
var server *Config
const pkgName = "hdh"
type Config struct {
AppId string
AppSecret string
ApiUrl string
}
func New(req *Config) {
server = req
return
}
func sign(req string) string {
res := gmd5.MustEncryptString(req + server.AppSecret)
return res
}
func post(ctx context.Context, method string, req interface{}) (res string, err error) {
Start := gtime.TimestampMilli()
reqMap := gconv.Map(req)
reqMap["appId"] = server.AppId
param := gjson.New(req)
Url := server.ApiUrl + method
Request := g.Client()
Request.SetHeader("Content-Type", "application/json")
Request.SetHeader("sign", sign(param.MustToJsonString()))
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
}
package hdh
import (
"context"
"encoding/json"
)
//品牌
type BrandListReq struct {
AppID string `json:"appId"`
Page int `json:"page"`
Limit int `json:"limit"`
}
//品牌列表
type BrandListRes struct {
Code string `json:"code"`
Data struct {
DataList []struct {
ID string `json:"id"`
Name string `json:"name"` //品牌名称
Desc string `json:"desc,omitempty"` //品牌描述
LogoURL string `json:"logoUrl,omitempty"` //logo
PosterURL string `json:"posterUrl,omitempty"` //海报
} `json:"dataList"`
NextPage int `json:"nextPage"`
Total int `json:"total"`
TotalPage int `json:"totalPage"`
} `json:"data"`
Message string `json:"message"`
Success int `json:"success"`
}
type BrandInfoReq struct {
AppID string `json:"appId"`
Ids []string `json:"ids"`
}
type BrandInfoRes struct {
Code string `json:"code"`
Data []struct {
Desc string `json:"desc,omitempty"` //品牌描述
ID string `json:"id"` //
LogoURL string `json:"logoUrl,omitempty"` //logo
Name string `json:"name"` //品牌名称
PosterURL string `json:"posterUrl,omitempty"` //海报
} `json:"data"`
Message string `json:"message"`
Success int `json:"success"`
}
//获取品牌列表
func GetBrandList(ctx context.Context, page, limit int) (res *BrandListRes, err error) {
params := BrandListReq{
AppID: "",
Page: page,
Limit: limit,
}
result, err := post(ctx, "/brand/get_brand_list.do", params)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
//获取品牌
func GetBrandInfo(ctx context.Context, ids []string) (res *BrandInfoRes, err error) {
params := BrandInfoReq{
AppID: "",
Ids: ids,
}
result, err := post(ctx, "/brand/get_brands.do", params)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
package hdh
import (
"context"
"encoding/json"
"github.com/gogf/gf/frame/g"
)
//分类列表
type CategoryListRes struct {
Code string `json:"code"`
Data []struct {
ID int `json:"id"` //类目id
LogoURL string `json:"logoUrl"` //类目logo图片地址
Name string `json:"name"` //类目名称
SubCategoryList []struct {
ID int `json:"id"` //类目id
LogoURL string `json:"logoUrl"` //类目logo图片地址
Name string `json:"name"` //类目名称
SubCategoryList []struct {
ID int `json:"id"` //
LogoURL string `json:"logoUrl"` //
Name string `json:"name"` //
} `json:"subCategoryList"` //
} `json:"subCategoryList"` //
} `json:"data"`
Message string `json:"message"`
Success int `json:"success"`
}
//获取分类列表
func GetCategoryList(ctx context.Context) (res *CategoryListRes, err error) {
params := g.Map{}
result, err := post(ctx, "/item/get_item_list.do", params)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
package hdh
import (
"context"
"encoding/json"
)
type GoodsNotifyRes struct {
BrandID string `json:"brandId"` //
BrandName string `json:"brandName"` //品牌名称
Currency string `json:"currency"` //货币单位 参考货币字典
FirstCateID int `json:"firstCateId"` //一级类目id
FirstCateName string `json:"firstCateName"` //一级类目名称
Gift int `json:"gift"` //是或赠品( 0不是 1是)
ID string `json:"id"` //
ImageList []string `json:"imageList"` //图片数组
IsDelete int `json:"isDelete"` //
ItemLimitCondition ItemLimitCondition `json:"itemLimitCondition"` //商品限购信息
Name string `json:"name"` //商品名称
Presell int `json:"presell"` //是否预售商品(0不是 1是)
SecondCateID int `json:"secondCateId"` //二级类目id
SecondCateName string `json:"secondCateName"` //二级类目名称
ShelfStatus int `json:"shelfStatus"` //商品上下架状态(0下架 1上架) 下架商品即为不可售
ShopName string `json:"shopName"` //店铺名称
SkuList []SkuList `json:"skuList"` //商品规格信息
SkuNameValues []SkuNameValues `json:"skuNameValues"` //规格信息
ThirdCateID int `json:"thirdCateId"` //
ThirdCateName string `json:"thirdCateName"` //
}
type ItemLimitCondition struct {
CycleLimitQuantity int `json:"cycleLimitQuantity"` //周期限购数量
CycleLimitTime int `json:"cycleLimitTime"` //周期限购时间(默认单位:日)
}
type SkuChannels struct {
ChannelName string `json:"channelName"` //渠道名称
ChannelType string `json:"channelType"` //渠道类型
ItemCode string `json:"itemCode"` //商品编码 如果系统需要在会订货系统导入
OriginalPrice int `json:"originalPrice"` //原价
Price int `json:"price"` //现价
SalesStatus int `json:"salesStatus"` //商品销售状态(0为不可售 1可售)
Stock int `json:"stock"` //当前渠道商品的库存数
}
type SkuValues struct {
SkuName string `json:"skuName"` //规格名
SkuValue string `json:"skuValue"` //规格值
}
type SkuList struct {
ItemID string `json:"itemId"` //商品id 与上面的商品id一致
SkuChannels []SkuChannels `json:"skuChannels"` //对应渠道信息
SkuID string `json:"skuId"` //规格id
SkuValues []SkuValues `json:"skuValues"` //规格信息
TotalStock int `json:"totalStock"` //商品总数量
Unit string `json:"unit"` //单位 例如:件、组、盒、支
UnitQuantity int `json:"unitQuantity"` //单位对应的数量 与单位共用 如:1件、1组、1盒、1支
Upc string `json:"upc"` //
Weight float64 `json:"weight"` //重量
WeightG float64 `json:"weightG"` //
}
type SkuNameValues struct {
SkuName string `json:"skuName"` //
SkuValues []SkuValues `json:"skuValues"` //规格信息
}
//商品请求
type GoodsListReq struct {
AppID string `json:"appId"`
Page int `json:"page"`
Limit int `json:"limit"`
LogNo string `json:"logNo"` //日志编号
PrePageLastID string `json:"prePageLastId"` //上一页最后一个商品ID
CateID1 int `json:"cateId1"` //一级类目ID
CateID2 int `json:"cateId2"` //二级类目ID
CateID3 int `json:"cateId3"` //三级类目ID
ChannelTypes []int `json:"channelTypes"` //品牌ID集合
BrandIds []int64 `json:"brandIds"` //发货方式集合
}
//商品列表
type GoodsListRes struct {
Code string `json:"code"`
Data struct {
ItemList []struct {
BrandID string `json:"brandId"` //品牌ID
BrandName string `json:"brandName"` //品牌名称
Currency string `json:"currency"` //货币单位 参考货币字典
Desc string `json:"desc"` //商品描述
FirstCateID int `json:"firstCateId"` //一级类目id
FirstCateName string `json:"firstCateName"` //
Gift int `json:"gift"` //是或赠品( 0不是 1是)
ID string `json:"id"` //
ImageList []string `json:"imageList"` //图片数组
IsDelete int `json:"isDelete"` //
Name string `json:"name"` //商品名称
Presell int `json:"presell"` //是否预售商品(0不是 1是)
RichDesc string `json:"richDesc"` //图文详情 html片段
SecondCateID int `json:"secondCateId"` //二级类目id
SecondCateName string `json:"secondCateName"` //
ShelfStatus int `json:"shelfStatus"` //商品上下架状态(0下架 1上架) 下架商品即为不可售
ShopName string `json:"shopName"` //店铺名称
SkuList []struct {
ItemID string `json:"itemId"` //商品id 与上面的商品id一致
SkuChannels []struct {
ChannelName string `json:"channelName"` //渠道名称
ChannelType string `json:"channelType"` //渠道类型
ItemCode string `json:"itemCode"` //商品编码 如果系统需要在会订货系统导入订单 需要使用到
OriginalPrice int `json:"originalPrice"` //原价(建议零售价)
Price int `json:"price"` //现价(实际采购价)
SalesStatus int `json:"salesStatus"` //商品销售状态(0为不可售 1可售)
Stock int `json:"stock"` //当前渠道商品的库存数
} `json:"skuChannels"` //对应渠道信息
SkuID string `json:"skuId"` //规格id
SkuValues []struct {
ImageURL string `json:"imageUrl"` //规格对应的图片数组
SkuName string `json:"skuName"` //规格名称
SkuValue string `json:"skuValue"` //规格名对应的规格信息
} `json:"skuValues"` //规格值
TotalStock int `json:"totalStock"` //商品总数量
Unit string `json:"unit"` //单位 例如:件、组、盒、支
UnitQuantity int `json:"unitQuantity"` //单位对应的数量 与单位共用 如:1件、1组、1盒、1支
Upc string `json:"upc"` //
Weight float64 `json:"weight"` //重量
WeightG int `json:"weightG"` //
} `json:"skuList"` //商品规格信息
SkuNameValues []struct {
SkuName string `json:"skuName"` //规格名称
SkuValues []struct { //规格名对应的规格信息
ImageURLList []string `json:"imageUrlList"` //规格对应的图片数组
SkuValue string `json:"skuValue"` //规格值
} `json:"skuValues"`
} `json:"skuNameValues"`
ThirdCateID int `json:"thirdCateId"`
ThirdCateName string `json:"thirdCateName"`
} `json:"itemList"`
Total int `json:"total"`
} `json:"data"`
Message string `json:"message"`
Success int `json:"success"`
}
//商品详情入参
type GoodsInfoReq struct {
AppID string `json:"appId"`
Ids []string `json:"ids"` //商品Id
}
//商品详情
type GoodsInfoRes struct {
Code string `json:"code"`
Data []struct {
BrandID string `json:"brandId"`
BrandName string `json:"brandName"` //品牌名称
Currency string `json:"currency"` //货币单位 参考货币字典
Desc string `json:"desc"` //商品描述
FirstCateID int `json:"firstCateId"` //一级类目id
FirstCateName string `json:"firstCateName"` //
Gift int `json:"gift"` //是或赠品( 0不是 1是)
ID string `json:"id"` //
ImageList []string `json:"imageList"` //图片数组
IsDelete int `json:"isDelete"` //
Name string `json:"name"` //商品名称
Presell int `json:"presell"` //是否预售商品(0不是 1是)
RichDesc string `json:"richDesc"` //图文详情 html片段
SecondCateID int `json:"secondCateId"` //二级类目id
SecondCateName string `json:"secondCateName"` //
ShelfStatus int `json:"shelfStatus"` //商品销售状态(0为不可售 1可售)
ShopName string `json:"shopName"` //店铺名称
SkuList []struct {
ItemID string `json:"itemId"` //商品id 与上面的商品id一致
SkuChannels []struct {
ChannelName string `json:"channelName"` //渠道名称
ChannelType string `json:"channelType"` //渠道类型
ItemCode string `json:"itemCode"` //商品编码 如果系统需要在会订货系统导入订单 需要使用到
OriginalPrice int `json:"originalPrice"` //原价(建议零售价)
Price int `json:"price"` //现价(实际采购价)
SalesStatus int `json:"salesStatus"` //商品销售状态(0为不可售 1可售)
Stock int `json:"stock"` //当前渠道商品的库存数
} `json:"skuChannels"` //对应渠道信息
SkuID string `json:"skuId"` //规格id
SkuValues []struct {
ImageURL string `json:"imageUrl"` //规格对应的图片数组
SkuName string `json:"skuName"` //规格名称
SkuValue string `json:"skuValue"` //规格名对应的规格信息
} `json:"skuValues"` //规格值
TotalStock int `json:"totalStock"` //商品总数量
Unit string `json:"unit"` //单位 例如:件、组、盒、支
UnitQuantity int `json:"unitQuantity"` //单位对应的数量 与单位共用 如:1件、1组、1盒、1支
Upc string `json:"upc"` //
Weight float64 `json:"weight"` //重量
WeightG int `json:"weightG"` //
} `json:"skuList"`
SkuNameValues []struct {
SkuName string `json:"skuName"` //规格名称
SkuValues []struct {
ImageURLList []string `json:"imageUrlList"` //规格对应的图片数组
SkuValue string `json:"skuValue"` //规格值
} `json:"skuValues"` //
} `json:"skuNameValues"` //
ThirdCateID int `json:"thirdCateId"` //
ThirdCateName string `json:"thirdCateName"` //
} `json:"data"` //
Message string `json:"message"`
Success int `json:"success"`
}
//商品列表
func GetGoodsList(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, err error) {
result, err := post(ctx, "/item/get_item_list.do", req)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
//商品详情
func GetGoodsInfo(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, err error) {
result, err := post(ctx, "/item/get_items.do", req)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
package hdh
import (
"context"
"encoding/json"
)
type OerCreateReq struct {
Address string `json:"address"` //具体地址
AppID string `json:"appId"` //
City string `json:"city"` //城市
District string `json:"district"` //地区
IDCardNumber string `json:"idCardNumber"` //身份证号码 非必传
Name string `json:"name"` //收件人名称
Phone string `json:"phone"` //收件人手机
Price float64 `json:"price"` //商品总金额 用于校验创建订单时候 商品价格是否发生变动
Province string `json:"province"` //省份
Desc string `json:"desc"` //购买商品的备注
SkuList []struct {
BuyNum int `json:"buyNum"` //购买数量
ChannelType int `json:"channelType"` //商品渠道类型
ItemID int64 `json:"itemId"` //商品id
SkuID int64 `json:"skuId"` //商品skuId
ItemCode int64 `json:"itemCode"` //商品编码与(itemId,skuId,channelType)必填一项,以上三个参数指定的商品优先
Price float64 `json:"price"` //(当前商品sku的总价)该选项为非必填项 如果填写了 校验出商品金额发生变化 则会返回当前商品的金额发生变化的提示
} `json:"skuList"` //购买商品的信息
UserOrderNum string `json:"userOrderNum"` //用户自定义订单号 非必传
}
type OerCreateRes struct {
Code string `json:"code"`
Message string `json:"message"`
Success int `json:"success"`
}
//订单回调信息
type OrderNotifyRes struct {
OrderNum string `json:"orderNum"` //订单号
OrderStatus string `json:"orderStatus"` //订单状态
OrderStatusCode int `json:"orderStatusCode"` //订单状态code 参考订单状态字典
PkgList []PkgList `json:"pkgList"` //包裹信息情况
UserOrderNum string `json:"userOrderNum"` //用户订单号
}
//该包裹下商品信息
type ItemList struct {
ChannelName string `json:"channelName"` //渠道名称
ChannelType string `json:"channelType"` //渠道类型
ItemID string `json:"itemId"` //商品id
Number int `json:"number"` //商品数量
SkuID string `json:"skuId"` //商品skuId
}
//包裹信息情况
type PkgList struct {
ExpressCompany string `json:"expressCompany"` //物流公司
ExpressNum string `json:"expressNum"` //物流单号
ItemList []ItemList `json:"itemList"` //该包裹下商品信息
OrderStatus string `json:"orderStatus"` //子订单状态 由于包裹存在分包情况 所有不同子订单状态可能不同
OrderStatusCode int `json:"orderStatusCode"` //订单状态code参考订单状态字典
PkgNo string `json:"pkgNo"` //包裹号
}
//物流轨迹回调接口
type ExpressNotifyRes struct {
OrderNum string `json:"orderNum"` //订单号
PkgList []struct {
ExpressCode int `json:"expressCode"` //物流状态code
ExpressList []struct {
ExpressCompany string `json:"expressCompany"` //物流公司
ExpressDetail []struct {
Express string `json:"express"` //物流节点
Time string `json:"time"` //时间
} `json:"expressDetail"` //物流详情
ExpressNum string `json:"expressNum"` //物流单号
} `json:"expressList"` //物流轨迹信息
OrderStatus string `json:"orderStatus"` //子订单状态
OrderStatusCode int `json:"orderStatusCode"` //订单状态code参考订单状态字典
PkgNo string `json:"pkgNo"` //包裹号(一笔订单可能被拆分为多个包裹)
Status string `json:"status"` //包裹物流轨迹状态 参考物流状态字典
} `json:"pkgList"` //包裹信息
UserOrderNum string `json:"userOrderNum"` //用户订单号
}
//创建订单
func OrderCreate(ctx context.Context, req *OerCreateReq) (res *OerCreateRes, err error) {
result, err := post(ctx, "/order/create_order.do", req)
if nil != err {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论