162 lines
5.9 KiB
Go
162 lines
5.9 KiB
Go
package tiktok_store
|
||
|
||
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_create_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/warehouse_create/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"
|
||
"strings"
|
||
)
|
||
|
||
// /warehouse/create 创建单个区域仓
|
||
func (P *PurchaseHandler) CreateWarehouse(outWarehouseID, appOrgCode string) (warehouseID int64, err error) {
|
||
tempName := "门店编码:" + outWarehouseID + "的区域仓"
|
||
req := &warehouse_create_request.WarehouseCreateParam{
|
||
OutWarehouseId: outWarehouseID,
|
||
Name: tempName,
|
||
Intro: "",
|
||
}
|
||
resp, err := getAPI(appOrgCode, 0, "").CreateWarehouse(req)
|
||
if err != nil {
|
||
return 0, err
|
||
}
|
||
//todo 存入数据库
|
||
|
||
return resp.Data, err
|
||
}
|
||
|
||
// /warehouse/createBatch 批量创建区域仓
|
||
func (P *PurchaseHandler) BatchCreateWarehouse(param warehouse_createBatch_request.WarehouseCreateBatchParam, appOrgCode string) 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 := getAPI(appOrgCode, 0, "").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, appOrgCode string) error {
|
||
param := &warehouse_bindStore_request.WarehouseBindStoreParam{
|
||
StoreIds: storeIDs,
|
||
OutWarehouseId: outWarehouseID,
|
||
}
|
||
if _, err := getAPI(appOrgCode, 0, "").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 CreateFenceByStore(storeID int) (fenceID string, err error) {
|
||
var (
|
||
db *dao.DaoDB
|
||
localStore *LocalStore
|
||
verticeses []warehouse_createFence_request.VerticesItem
|
||
)
|
||
sqlParam := []interface{}{
|
||
model.VendorIDDD,
|
||
}
|
||
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 := getAPI("", 0, "").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 := getAPI("", 0, "").CreateFence(info)
|
||
if err != nil {
|
||
return "", err
|
||
}
|
||
return resp.FenceId, err
|
||
}
|
||
|
||
//门店直接绑定围栏
|
||
func BindFenceByStore(storeID int64, addOutFenceIDs []string) error {
|
||
param := &warehouse_bindFencesByStore_request.WarehouseBindFencesByStoreParam{
|
||
StoreId: storeID,
|
||
AddOutFenceIds: addOutFenceIDs,
|
||
}
|
||
if _, err := getAPI("", 0, "").BindFenceByStore(param); err != nil {
|
||
return err
|
||
}
|
||
return nil
|
||
}
|