Merge branch 'jdshop' of e.coding.net:rosydev/jx-callback into jdshop
This commit is contained in:
@@ -1475,6 +1475,7 @@ func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vend
|
||||
|
||||
// todo 需要对字段做有效性检查
|
||||
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vendorOrgCode string, storeID int, storeMap *model.StoreMap) (outStoreMap *model.StoreMap, err error) {
|
||||
errList := errlist.ErrList{}
|
||||
if storeID == 0 {
|
||||
return nil, fmt.Errorf("storeID不能为0")
|
||||
}
|
||||
@@ -1522,9 +1523,8 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
}
|
||||
if vendorID == model.VendorIDDD { //抖店绑定店铺时 检查并补充创建
|
||||
globals.SugarLogger.Debugf("vendorID ==============%d", vendorID)
|
||||
err2 := tiktok_store.CreateOrUpdateAll(vendorOrgCode, int64(storeMap.StoreID), utils.Str2Int64(storeMap.VendorStoreID))
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
if str, err2 := tiktok_store.CreateOrUpdateAll(vendorOrgCode, int64(storeMap.StoreID), utils.Str2Int64(storeMap.VendorStoreID)); err2 != nil {
|
||||
errList.AddErr(fmt.Errorf("wrongAns=%s,err=%v", str, err2))
|
||||
}
|
||||
}
|
||||
} else if vendorID == model.VendorIDJX {
|
||||
@@ -1594,7 +1594,7 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
}
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, storeMap.VendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.FullSyncStoresSkus(ctx, db, []int{vendorID}, []int{storeID}, true, nil, true, true)
|
||||
return outStoreMap, err
|
||||
return outStoreMap, errors.New(fmt.Sprintf("errList=%s,err=%v", utils.Format4Output(errList, true), err))
|
||||
}
|
||||
|
||||
func DeleteStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
@@ -5871,14 +5871,15 @@ func GetDDScope(ctx *jxcontext.Context, storeID int, vendorStoreID string) (ware
|
||||
return data, errors.New("storeID,vendorStoreID 必填")
|
||||
}
|
||||
storeMap, err := GetVendorOrgCode(ctx, dao.GetDB(), storeID, model.VendorIDDD, vendorStoreID)
|
||||
|
||||
if err != nil {
|
||||
return data, errors.New(fmt.Sprintf("获取vendorOrgCode失败,请检查数据或重试:%v", err))
|
||||
}
|
||||
bindWarehouse, err := tiktok_store.GetWarehouseByStore(storeMap.VendorOrgCode, int64(storeID))
|
||||
bindWarehouse, err := tiktok_store.GetWarehouseByStore(storeMap[0].VendorOrgCode, int64(storeID))
|
||||
if err != nil {
|
||||
return data, errors.New(fmt.Sprintf("获取门店(%d) 绑定fenceID失败:%v", storeID, err))
|
||||
}
|
||||
resp, err := tiktok_store.GetFence(storeMap.VendorOrgCode, bindWarehouse[0][utils.Str2Int(vendorStoreID)].OutFenceIds[0])
|
||||
resp, err := tiktok_store.GetFence(storeMap[0].VendorOrgCode, bindWarehouse[0][utils.Str2Int(vendorStoreID)].OutFenceIds[0])
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
@@ -5886,7 +5887,7 @@ func GetDDScope(ctx *jxcontext.Context, storeID int, vendorStoreID string) (ware
|
||||
}
|
||||
|
||||
//获取 VendorOrgCode
|
||||
func GetVendorOrgCode(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, vendorStoreID string) (storeMap *model.StoreMap, err error) {
|
||||
func GetVendorOrgCode(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, vendorStoreID string) (storeMap []*model.StoreMap, err error) {
|
||||
cond := map[string]interface{}{
|
||||
model.FieldStoreID: storeID,
|
||||
model.FieldVendorStoreID: vendorStoreID,
|
||||
|
||||
@@ -127,7 +127,7 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
return "", err
|
||||
} else {
|
||||
vendorStoreIDs = utils.Int64ToStr(resp.ResultList[0].Store.StoreId)
|
||||
if err := CreateOrUpdateAll(storeDetail.VendorOrgCode, int64(storeDetail.Store.ID), resp.ResultList[0].Store.StoreId); err != nil {
|
||||
if _, err := CreateOrUpdateAll(storeDetail.VendorOrgCode, int64(storeDetail.Store.ID), resp.ResultList[0].Store.StoreId); err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (P *PurchaseHandler) CreateStore2(db *dao.DaoDB, storeID int, userName stri
|
||||
}
|
||||
|
||||
//电子围栏 仓库 运费模板 限售模板 更新与绑定
|
||||
func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error {
|
||||
func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) (string, error) {
|
||||
var (
|
||||
errList = errlist.New()
|
||||
FreightTemplate = &model.FreightTemplate{}
|
||||
@@ -171,7 +171,8 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
if err != nil {
|
||||
errList.AddErr(fmt.Errorf("获取门店(%d) 绑定仓库信息以及电子围栏出错:%v", vendorStoreID, err))
|
||||
}
|
||||
if len(bindWarehouseAndFence) == 0 || utils.IsNil(bindWarehouseAndFence) { //(1)未绑定仓库以及电子围栏
|
||||
if len(bindWarehouseAndFence) == 0 || utils.IsNil(bindWarehouseAndFence) { //未绑定仓库以及电子围栏
|
||||
//(1)创建仓库
|
||||
warehouseID, err := CreateWarehouse(vendorOrgCode, utils.Int64ToStr(storeID))
|
||||
if err != nil || warehouseID == 0 || utils.IsNil(warehouseID) {
|
||||
errList.AddErr(fmt.Errorf("门店(%d) 创建仓库失败:%v", storeID, err))
|
||||
@@ -184,11 +185,11 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
errList.AddErr(fmt.Errorf("仓库ID(%d) 同步到数据库失败:%v", warehouseID, err))
|
||||
}
|
||||
}
|
||||
//检查是否有电子围栏
|
||||
fenceID, err := CreateFenceByStore(vendorOrgCode, storeID)
|
||||
if err != nil || utils.Str2Int(fenceID) == 0 || utils.IsNil(fenceID) { //创建
|
||||
errList.AddErr(fmt.Errorf("门店(%d) 创建电子围栏失败:%v", storeID, err))
|
||||
} //绑定
|
||||
}
|
||||
//(2)创建电子围栏
|
||||
if fenceID, err := CreateFenceByStore(vendorOrgCode, storeID); err != nil || utils.Str2Int(fenceID) == 0 || utils.IsNil(fenceID) { //不管存在与否 直接创建
|
||||
errList.AddErr(fmt.Errorf("门店(%d) 创建电子围栏失败:%v", storeID, err))
|
||||
} else { //绑定
|
||||
if err := BindFenceByStore(vendorOrgCode, vendorStoreID, []string{utils.Int64ToStr(storeID)}); err != nil {
|
||||
errList.AddErr(fmt.Errorf("门店(%d) 绑定电子围栏:%s失败:%v", storeID, fenceID, err))
|
||||
} else {
|
||||
@@ -198,8 +199,9 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //同步信息到本地
|
||||
} else {
|
||||
if len(bindWarehouseAndFence[0][vendorStoreID].OutFenceIds) == 0 || utils.IsNil(bindWarehouseAndFence[0][vendorStoreID].OutFenceIds) { //未绑定电子围栏
|
||||
globals.SugarLogger.Debugf("进入创建电子围栏=========")
|
||||
if fenceID, err := CreateFenceByStore(vendorOrgCode, storeID); err != nil || utils.Str2Int(fenceID) == 0 || utils.IsNil(fenceID) { //创建
|
||||
errList.AddErr(fmt.Errorf("门店(%d) 创建电子围栏失败:%v", storeID, err))
|
||||
} else { //绑定
|
||||
@@ -213,6 +215,9 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
}
|
||||
}
|
||||
}
|
||||
//同步到本地数据库
|
||||
FreightTemplate.FenceID = bindWarehouseAndFence[0][vendorStoreID].OutFenceIds[0]
|
||||
FreightTemplate.WarehouseID = bindWarehouseAndFence[0][vendorStoreID].WarehouseId
|
||||
if _, err = dao.UpdateEntity(db, FreightTemplate, "FenceID"); err != nil {
|
||||
errList.AddErr(fmt.Errorf("电子围栏 同步到本地出错:%v", err))
|
||||
}
|
||||
@@ -240,6 +245,7 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
}
|
||||
}
|
||||
} else { //同步到本地
|
||||
FreightTemplate.TradeLimitID = SaleLimitID
|
||||
if _, err = dao.UpdateEntity(db, FreightTemplate, "TradeLimitID"); err != nil {
|
||||
errList.AddErr(fmt.Errorf("限售模板 同步到本地出错:%v", err))
|
||||
}
|
||||
@@ -251,9 +257,9 @@ func CreateOrUpdateAll(vendorOrgCode string, storeID, vendorStoreID int64) error
|
||||
errList.AddErr(fmt.Errorf("db update storeID,vendorStoreID defeat on :%v", err))
|
||||
}
|
||||
if utils.IsNil(errList) {
|
||||
return errors.New(fmt.Sprintf("%s", utils.Format4Output(errList, true)))
|
||||
return "门店绑定成功,但需要根据提示进行处理", errors.New(fmt.Sprintf("%s", utils.Format4Output(errList, true)))
|
||||
} else {
|
||||
return nil
|
||||
return "门店绑定成功", nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,14 +93,14 @@ func CreateFenceByStore(appOrgCode string, storeID int64) (fenceID string, err e
|
||||
var (
|
||||
db *dao.DaoDB
|
||||
localStore *LocalStore
|
||||
verticeses []warehouse_createFence_request.VerticesItem
|
||||
vertex []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= ? `
|
||||
WHERE s.vendor_id = ? `
|
||||
if storeID != 0 {
|
||||
sqlStr += " AND t.id = ? "
|
||||
sqlParam = append(sqlParam, storeID)
|
||||
@@ -131,9 +131,9 @@ func CreateFenceByStore(appOrgCode string, storeID int64) (fenceID string, err e
|
||||
Longitude: utils.Str2Float64(s2[0]),
|
||||
Latitude: utils.Str2Float64(s2[1]),
|
||||
}
|
||||
verticeses = append(verticeses, vertices)
|
||||
vertex = append(vertex, vertices)
|
||||
}
|
||||
param.FenceInfo.Polygon.Vertices = verticeses
|
||||
param.FenceInfo.Polygon.Vertices = vertex
|
||||
}
|
||||
resp, err := getAPI(appOrgCode, 0, "").CreateFence(param)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user