Merge branch 'jdshop' of e.coding.net:rosydev/jx-callback into jdshop
This commit is contained in:
@@ -1562,3 +1562,20 @@ func GetStoreBrandInfos(storeID int) (date *BrandInfos, err error) {
|
||||
}
|
||||
return detail, err
|
||||
}
|
||||
|
||||
//查询门店绑定的运费模板
|
||||
func QueryStoreBindInfo(storeID int) (*model.FreightTemplate, error) {
|
||||
var (
|
||||
sqlParams = []interface{}{}
|
||||
bindInfo *model.FreightTemplate
|
||||
)
|
||||
sql := "SELECT a.store_id,a.vendor_store_id,a.template_id,a.warehouse_id,a.fence_id FROM freight_template a "
|
||||
if storeID != 0 {
|
||||
sql += "WHERE store_id = ? "
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if err := GetRow(GetDB(), &bindInfo, sql, sqlParams); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bindInfo, nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
address_list_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/address_list/request"
|
||||
address_list_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/address_list/response"
|
||||
freightTemplate_create_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/freightTemplate_create/request"
|
||||
freightTemplate_update_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/freightTemplate_update/request"
|
||||
shop_batchCreateStore_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_batchCreateStore/request"
|
||||
shop_bindStoreFreight_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_bindStoreFreight/request"
|
||||
shop_bindStoreSaleLimit_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/shop_bindStoreSaleLimit/request"
|
||||
@@ -81,7 +82,6 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
var (
|
||||
storeIDs string
|
||||
tempStoreID []int64
|
||||
fences []string
|
||||
lists []shop_batchCreateStore_request.StoreListItem
|
||||
ShopBatchCreateStoreParam *shop_batchCreateStore_request.ShopBatchCreateStoreParam
|
||||
FreightTemplate = &model.FreightTemplate{}
|
||||
@@ -133,8 +133,7 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
}
|
||||
globals.SugarLogger.Debug("Success createStore and return storeID=====", resp.ResultList[0].Store.StoreId, utils.Str2Int(storeIDs))
|
||||
if utils.Str2Int(storeIDs) == 0 {
|
||||
errList.AddErr(fmt.Errorf("storeIDs=0 %v", err))
|
||||
//return "", errors.New(fmt.Sprintf("创建店铺失败原因storeIDs = 0:%v,%v", err, resp.ResultList[0].Msg))
|
||||
return "", errors.New(fmt.Sprintf("创建店铺失败原因storeIDs = 0:%v,%v", err, resp.ResultList[0].Msg))
|
||||
}
|
||||
|
||||
//创建并绑定运费模板
|
||||
@@ -145,7 +144,7 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
} else {
|
||||
if freightTemplateID == 0 {
|
||||
globals.SugarLogger.Debug("freightTemplateID=========", freightTemplateID)
|
||||
errList.AddErr(fmt.Errorf("门店:%d 绑定运费模板:%d 失败原因:%v", int64(storeDetail.Store.ID), freightTemplateID, err))
|
||||
errList.AddErr(fmt.Errorf("创建运费模板失败:%d %d %v", int64(storeDetail.Store.ID), freightTemplateID, err))
|
||||
}
|
||||
err = P.ShopBindStoreFreight(int64(storeDetail.Store.ID), freightTemplateID)
|
||||
if err != nil {
|
||||
@@ -180,24 +179,23 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
if fenceID, err := CreateFenceByStore(int(resp.ResultList[0].Store.StoreId)); err != nil {
|
||||
errList.AddErr(fmt.Errorf("创建电子围栏失败原因:%v", err))
|
||||
} else {
|
||||
fences = append(fences, fenceID)
|
||||
fences := []string{utils.Int2Str(storeDetail.Store.ID)}
|
||||
if err := BindFenceByStore(resp.ResultList[0].Store.StoreId, fences); err != nil {
|
||||
errList.AddErr(fmt.Errorf("门店:%d 绑定电子围栏:%d 失败原因:%v", int64(storeDetail.Store.ID), warehouse, err))
|
||||
} else {
|
||||
FreightTemplate.FenceID = fenceID
|
||||
err := dao.CreateEntity(db, FreightTemplate)
|
||||
//_, err := dao.UpdateEntity(db, FreightTemplate, "FenceID")
|
||||
if err != nil {
|
||||
errList.AddErr(fmt.Errorf("电子围栏ID存入数据库失败原因:%v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
storeIDs = "65312663"
|
||||
//storeIDs = "65312663"
|
||||
globals.SugarLogger.Debug("CreateStore2 return storeIDs, storeDetail.Store.ID==========", storeIDs, storeDetail.Store.ID)
|
||||
FreightTemplate.StoreID = storeDetail.Store.ID
|
||||
FreightTemplate.VendorStoreID = storeIDs
|
||||
FreightTemplate.DeletedAt = utils.DefaultTimeValue
|
||||
err = dao.CreateEntity(db, FreightTemplate)
|
||||
//_, err = dao.UpdateEntity(db, FreightTemplate, "StoreID", "VendorStoreID")
|
||||
if err != nil {
|
||||
errList.AddErr(fmt.Errorf("db update storeID,vendorStoreID defeat on :%v", err))
|
||||
}
|
||||
@@ -268,10 +266,20 @@ func (P *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
globals.SugarLogger.Debug("================mergedStoreStatus", mergedStoreStatus)
|
||||
errList.AddErr(P.UpdateStoreStatus(jxcontext.AdminCtx, storeInfo.VendorOrgCode, storeID, storeInfo.VendorStoreID, mergedStoreStatus))
|
||||
}
|
||||
//TODO 需增加 更新运费模板、电子围栏
|
||||
_, err3 := api.EditStore(params)
|
||||
if err3 != nil {
|
||||
errList.AddErr(err3)
|
||||
} else {
|
||||
//更新运费模板
|
||||
err = UpdateFreightTemplate(storeID)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("更新运费模板失败,原因:%v", err))
|
||||
}
|
||||
//更新电子围栏
|
||||
err = UpdateFenceByStore(storeID)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("更新电子围栏失败,原因:%v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -372,6 +380,43 @@ func CreateFreightTemplate(storeCode int) (int64, error) {
|
||||
return resp.TemplateId, nil
|
||||
}
|
||||
|
||||
// /warehouse/setFence 修改运费模板
|
||||
func UpdateFreightTemplate(storeCode int) error {
|
||||
var (
|
||||
columns []freightTemplate_update_request.ColumnsItem
|
||||
)
|
||||
//获取本地门店信息
|
||||
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeCode, model.VendorIDDD, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
column := freightTemplate_update_request.ColumnsItem{
|
||||
FirstNum: 1,
|
||||
FirstNumPrice: 0.01,
|
||||
AddNum: 1,
|
||||
AddNumPrice: 0.01,
|
||||
IsOverFree: true, //是否包邮
|
||||
OverAmount: int64(storeDetail.DeliveryFeeDeductionSill), //此字段在vendor_id=14时 存储 满x包邮金额
|
||||
}
|
||||
columns = append(columns, column)
|
||||
param := &freightTemplate_update_request.FreightTemplateUpdateParam{
|
||||
Template: &freightTemplate_update_request.Template{
|
||||
TemplateName: "门店编码:" + utils.Int2Str(storeCode) + "的运费模板",
|
||||
ProductProvince: int64(storeDetail.ProvinceCode),
|
||||
ProductCity: int64(storeDetail.CityCode),
|
||||
CalculateType: 2, //模板类型为1-固定运费、2-卖家包邮、3-货到付款 时,计价类型传 2-按数量
|
||||
TransferType: 1,
|
||||
RuleType: 2, //卖家包邮
|
||||
},
|
||||
Columns: columns,
|
||||
}
|
||||
_, err = getAPI(storeDetail.VendorOrgCode, storeCode, storeDetail.VendorStoreID).FreightTemplateUpdate(param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// /freightTemplate/create 创建运费模板
|
||||
func (P *PurchaseHandler) CreateFreightTemplateDirectly(templateInfo freightTemplate_create_request.FreightTemplateCreateParam, storeID, vendorStoreID int64) error {
|
||||
var (
|
||||
|
||||
@@ -26,8 +26,6 @@ func (P *PurchaseHandler) CreateWarehouse(outWarehouseID, appOrgCode string) (wa
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
//todo 存入数据库
|
||||
|
||||
return resp.Data, err
|
||||
}
|
||||
|
||||
@@ -60,10 +58,9 @@ func (P *PurchaseHandler) BatchCreateWarehouse(param warehouse_createBatch_reque
|
||||
|
||||
// /warehouse/bindStore 仓库绑定门店
|
||||
func (P *PurchaseHandler) BindStoreWarehouse(storeIDs []int64, outWarehouseID, appOrgCode string) error {
|
||||
tempWarehouseID := "门店编码:" + outWarehouseID + "的仓库"
|
||||
param := &warehouse_bindStore_request.WarehouseBindStoreParam{
|
||||
StoreIds: storeIDs,
|
||||
OutWarehouseId: tempWarehouseID,
|
||||
OutWarehouseId: outWarehouseID,
|
||||
}
|
||||
if _, err := getAPI(appOrgCode, 0, "").StoreBindWarehouse(param); err != nil {
|
||||
return err
|
||||
@@ -101,7 +98,7 @@ func CreateFenceByStore(storeID int) (fenceID string, err error) {
|
||||
if err = dao.GetRow(db, &localStore, sqlStr, sqlParam...); err == nil {
|
||||
param := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
||||
FenceInfo: &warehouse_createFence_request.FenceInfo{
|
||||
OutFenceId: "京西门店:" + utils.Int2Str(storeID) + " 的电子围栏",
|
||||
OutFenceId: utils.Int2Str(storeID), //绑定基于此id
|
||||
Shape: int32(localStore.DeliveryRangeType),
|
||||
},
|
||||
}
|
||||
@@ -138,7 +135,7 @@ func CreateFenceByStore(storeID int) (fenceID string, err error) {
|
||||
}
|
||||
|
||||
//直接创建电子围栏方式
|
||||
func (P *PurchaseHandler) CreateFenceDirectly(param warehouse_createFence_request.WarehouseCreateFenceParam) (fenceID string, err error) {
|
||||
func CreateFenceDirectly(param warehouse_createFence_request.WarehouseCreateFenceParam) (fenceID string, err error) {
|
||||
info := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
||||
FenceInfo: param.FenceInfo,
|
||||
}
|
||||
@@ -149,6 +146,63 @@ func (P *PurchaseHandler) CreateFenceDirectly(param warehouse_createFence_reques
|
||||
return resp.FenceId, err
|
||||
}
|
||||
|
||||
// 通过门店更新电子围栏
|
||||
func UpdateFenceByStore(storeID int) 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
|
||||
}
|
||||
_, err := getAPI("", 0, "").CreateFence(param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//门店直接绑定围栏
|
||||
func BindFenceByStore(storeID int64, addOutFenceIDs []string) error {
|
||||
param := &warehouse_bindFencesByStore_request.WarehouseBindFencesByStoreParam{
|
||||
|
||||
Reference in New Issue
Block a user