1
This commit is contained in:
143
business/partner/purchase/doudian/warehouse.go
Normal file
143
business/partner/purchase/doudian/warehouse.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package doudian
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
warehouse_bindFencesByStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_bindFencesByStore/request"
|
||||
warehouse_bindStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_bindStore/request"
|
||||
warehouse_createBatch_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_createBatch/request"
|
||||
warehouse_createFence_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_createFence/request"
|
||||
"git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// /warehouse/createBatch 批量创建区域仓
|
||||
func (P *PurchaseHandler) BatchCreateWarehouse(param warehouse_createBatch_request.WarehouseCreateBatchParam) error {
|
||||
infos := []warehouse_createBatch_request.OutWarehouseListItem{}
|
||||
for _, v := range param.OutWarehouseList {
|
||||
info := warehouse_createBatch_request.OutWarehouseListItem{
|
||||
OutWarehouseId: v.OutWarehouseId,
|
||||
Name: v.Name,
|
||||
Intro: v.Intro,
|
||||
AddressDetail: v.AddressDetail,
|
||||
WarehouseLocation: v.WarehouseLocation,
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
req := &warehouse_createBatch_request.WarehouseCreateBatchParam{
|
||||
OutWarehouseList: infos,
|
||||
}
|
||||
resp, err := api.DouDianApi.BatchCreateWarehouse(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Data["outWarehouseId"] == false {
|
||||
return fmt.Errorf("outWarehouseId:%v 出错", resp.Data["outWarehouseId"])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// /warehouse/bindStore 仓库绑定门店
|
||||
func (P *PurchaseHandler) BindStoreWarehouse(storeIDs []int64, outWarehouseID string) error {
|
||||
param := &warehouse_bindStore_request.WarehouseBindStoreParam{
|
||||
StoreIds: storeIDs,
|
||||
OutWarehouseId: outWarehouseID,
|
||||
}
|
||||
if _, err := api.DouDianApi.StoreBindWarehouse(param); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type LocalStore struct {
|
||||
Lng int `json:"-"` // 乘了10的6次方
|
||||
Lat int `json:"-"` // 乘了10的6次方
|
||||
DeliveryRangeType int8 `json:"deliveryRangeType"` // 参见相关常量定义
|
||||
DeliveryRange string `json:"deliveryRange"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
VendorStoreID string `json:"vendorStoreID"` // 平台上门店id
|
||||
}
|
||||
|
||||
// /warehouse/createFence 以门店方式创建电子围栏
|
||||
func (P *PurchaseHandler) CreateFenceByStore(storeID int) (fenceID string, err error) {
|
||||
var (
|
||||
db *dao.DaoDB
|
||||
localStore *LocalStore
|
||||
verticeses []warehouse_createFence_request.VerticesItem
|
||||
)
|
||||
sqlParam := []interface{}{
|
||||
model.VendorIDDouDian,
|
||||
}
|
||||
sqlStr := ` SELECT t.lng,t.lat,t.delivery_range_type,t.delivery_range,s.vendor_store_id FROM store t
|
||||
LEFT JOIN store_map s ON t.id = s.store_id
|
||||
WHERE s.vendor_id= ? `
|
||||
if storeID != 0 {
|
||||
sqlStr += " AND t.id = ? "
|
||||
sqlParam = append(sqlParam, storeID)
|
||||
} else {
|
||||
return "", fmt.Errorf("storeID必填")
|
||||
}
|
||||
if err = dao.GetRow(db, &localStore, sqlStr, sqlParam...); err == nil {
|
||||
param := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
||||
FenceInfo: &warehouse_createFence_request.FenceInfo{
|
||||
OutFenceId: "京西门店:" + utils.Int2Str(storeID) + " 的电子围栏",
|
||||
Shape: int32(localStore.DeliveryRangeType),
|
||||
},
|
||||
}
|
||||
if localStore.DeliveryRangeType == tiktok_api.ShapeCircular {
|
||||
circular := &warehouse_createFence_request.Circular{
|
||||
Center: &warehouse_createFence_request.Center{
|
||||
Longitude: utils.Int2Float64(localStore.Lng),
|
||||
Latitude: utils.Int2Float64(localStore.Lat),
|
||||
},
|
||||
Radius: utils.Str2Float64(localStore.DeliveryRange),
|
||||
}
|
||||
param.FenceInfo.Circular = circular
|
||||
} else if localStore.DeliveryRangeType == tiktok_api.ShapePolygon {
|
||||
tempStr := strings.Split(localStore.DeliveryRange, ";")
|
||||
for v := len(tempStr) - 1; v >= 0; v-- {
|
||||
s2 := strings.Split(tempStr[v], ",")
|
||||
vertices := warehouse_createFence_request.VerticesItem{
|
||||
Longitude: utils.Str2Float64(s2[0]),
|
||||
Latitude: utils.Str2Float64(s2[1]),
|
||||
}
|
||||
verticeses = append(verticeses, vertices)
|
||||
}
|
||||
param.FenceInfo.Polygon.Vertices = verticeses
|
||||
}
|
||||
resp, err := api.DouDianApi.CreateFence(param)
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return resp.FenceId, err
|
||||
}
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
//直接创建电子围栏方式
|
||||
func (P *PurchaseHandler) CreateFenceDirectly(param warehouse_createFence_request.WarehouseCreateFenceParam) (fenceID string, err error) {
|
||||
info := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
||||
FenceInfo: param.FenceInfo,
|
||||
}
|
||||
resp, err := api.DouDianApi.CreateFence(info)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.FenceId, err
|
||||
}
|
||||
|
||||
//门店直接绑定围栏
|
||||
func (P *PurchaseHandler) BindFenceByStore(storeID int64, addOutFenceIDs []string) error {
|
||||
param := &warehouse_bindFencesByStore_request.WarehouseBindFencesByStoreParam{
|
||||
StoreId: storeID,
|
||||
AddOutFenceIds: addOutFenceIDs,
|
||||
}
|
||||
if _, err := api.DouDianApi.BindFenceByStore(param); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user