- 绑定达达时,刷新门店信息
This commit is contained in:
@@ -809,10 +809,16 @@ func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID
|
||||
}()
|
||||
if err = dao.CreateEntity(db, storeCourierMap); err == nil {
|
||||
dao.Commit(db)
|
||||
if vendorID == model.VendorIDDada {
|
||||
storeList, err := dao.GetMissingDadaStores(db, storeID, false)
|
||||
if err != nil && len(storeList) > 0 {
|
||||
storeList[0].DadaStoreID = storeCourierMap.VendorStoreID
|
||||
err = updateOrCreateDadaStore(storeList[0])
|
||||
}
|
||||
}
|
||||
outStoreCourierMap = storeCourierMap
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, storeCourierMap.VendorID, storeID, false, userName)
|
||||
}
|
||||
if err != nil {
|
||||
} else {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
} else {
|
||||
@@ -861,28 +867,7 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
|
||||
task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeDetail := batchItemList[0].(*dao.StoreDetail2)
|
||||
_, err = api.DadaAPI.ShopDetail(utils.Int2Str(storeDetail.ID))
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(utils.Int2Str(storeDetail.ID), composeDadaStoreName(storeDetail), dadaapi.BusinessTypeConvStore, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
||||
}
|
||||
} else {
|
||||
params := map[string]interface{}{
|
||||
"station_name": composeDadaStoreName(storeDetail),
|
||||
"business": dadaapi.BusinessTypeConvStore,
|
||||
"city_name": storeDetail.CityName,
|
||||
"area_name": storeDetail.DistrictName,
|
||||
"station_address": storeDetail.Address,
|
||||
"lng": jxutils.IntCoordinate2Standard(storeDetail.Lng),
|
||||
"lat": jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
"contact_name": storeDetail.Tel1,
|
||||
"phone": storeDetail.Tel1,
|
||||
}
|
||||
err = api.DadaAPI.ShopUpdate(utils.Int2Str(storeDetail.ID), params)
|
||||
}
|
||||
if err == nil {
|
||||
if storeDetail.DadaStoreID == "" {
|
||||
db := dao.GetDB()
|
||||
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
|
||||
VendorStoreID: utils.Int2Str(storeDetail.ID),
|
||||
@@ -899,6 +884,31 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
||||
return storeDetail.Name + "-" + utils.Int2Str(storeDetail.ID)
|
||||
func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
|
||||
_, err = api.DadaAPI.ShopDetail(storeDetail.DadaStoreID)
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok && codeErr.IntCode() == dadaapi.ResponseCodeShopNotExist {
|
||||
_, err = api.DadaAPI.ShopAdd(storeDetail.DadaStoreID, composeDadaStoreName(storeDetail), dadaapi.BusinessTypeConvStore, storeDetail.CityName,
|
||||
storeDetail.DistrictName, storeDetail.Address, jxutils.IntCoordinate2Standard(storeDetail.Lng), jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
storeDetail.Tel1, storeDetail.Tel1, nil)
|
||||
}
|
||||
} else {
|
||||
params := map[string]interface{}{
|
||||
"station_name": composeDadaStoreName(storeDetail),
|
||||
"business": dadaapi.BusinessTypeConvStore,
|
||||
"city_name": storeDetail.CityName,
|
||||
"area_name": storeDetail.DistrictName,
|
||||
"station_address": storeDetail.Address,
|
||||
"lng": jxutils.IntCoordinate2Standard(storeDetail.Lng),
|
||||
"lat": jxutils.IntCoordinate2Standard(storeDetail.Lat),
|
||||
"contact_name": storeDetail.Tel1,
|
||||
"phone": storeDetail.Tel1,
|
||||
}
|
||||
err = api.DadaAPI.ShopUpdate(storeDetail.DadaStoreID, params)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) {
|
||||
return storeDetail.Name + "-" + storeDetail.DadaStoreID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user