- 绑定达达时,刷新门店信息

This commit is contained in:
gazebo
2019-04-18 19:01:12 +08:00
parent e5fbdec9ba
commit 2b4e036619
2 changed files with 39 additions and 27 deletions

View File

@@ -809,10 +809,16 @@ func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID
}() }()
if err = dao.CreateEntity(db, storeCourierMap); err == nil { if err = dao.CreateEntity(db, storeCourierMap); err == nil {
dao.Commit(db) 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 outStoreCourierMap = storeCourierMap
_, err = CurVendorSync.SyncStore(ctx, db, storeCourierMap.VendorID, storeID, false, userName) _, err = CurVendorSync.SyncStore(ctx, db, storeCourierMap.VendorID, storeID, false, userName)
} } else {
if err != nil {
dao.Rollback(db) dao.Rollback(db)
} }
} else { } else {
@@ -861,28 +867,7 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, task := tasksch.NewParallelTask("RefreshMissingDadaStores", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeDetail := batchItemList[0].(*dao.StoreDetail2) storeDetail := batchItemList[0].(*dao.StoreDetail2)
_, err = api.DadaAPI.ShopDetail(utils.Int2Str(storeDetail.ID)) if storeDetail.DadaStoreID == "" {
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 {
db := dao.GetDB() db := dao.GetDB()
_, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{ _, err = AddStoreCourierMap(ctx, db, storeDetail.ID, model.VendorIDDada, &model.StoreCourierMap{
VendorStoreID: utils.Int2Str(storeDetail.ID), VendorStoreID: utils.Int2Str(storeDetail.ID),
@@ -899,6 +884,31 @@ func RefreshMissingDadaStores(ctx *jxcontext.Context, storeID int, isAsync, isCo
return hint, err return hint, err
} }
func composeDadaStoreName(storeDetail *dao.StoreDetail2) (storeName string) { func updateOrCreateDadaStore(storeDetail *dao.StoreDetail2) (err error) {
return storeDetail.Name + "-" + utils.Int2Str(storeDetail.ID) _, 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
} }

View File

@@ -25,6 +25,7 @@ type StoreDetail struct {
type StoreDetail2 struct { type StoreDetail2 struct {
model.Store model.Store
VendorStoreID string `orm:"column(vendor_store_id)` // 这个在GetMissingDadaStores返回中指的是到家的vendorStoreID VendorStoreID string `orm:"column(vendor_store_id)` // 这个在GetMissingDadaStores返回中指的是到家的vendorStoreID
DadaStoreID string `orm:"column(dada_store_id)`
DistrictName string DistrictName string
CityName string CityName string
} }
@@ -132,12 +133,13 @@ func GetMissingDadaStores(db *DaoDB, storeID int, isMustHaveJdStore bool) (store
SELECT t1.*, SELECT t1.*,
t2.vendor_store_id vendor_store_id, t2.vendor_store_id vendor_store_id,
city.name city_name, district.name district_name city.name city_name, district.name district_name
t3.vendor_store_id dada_store_id
FROM store t1 FROM store t1
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ? LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
JOIN place city ON city.code = t1.city_code JOIN place city ON city.code = t1.city_code
JOIN place district ON district.code = t1.district_code JOIN place district ON district.code = t1.district_code
LEFT JOIN store_courier_map t3 ON t3.store_id = t1.id AND t3.vendor_id = ? AND t3.deleted_at = ? LEFT JOIN store_courier_map t3 ON t3.store_id = t1.id AND t3.vendor_id = ? AND t3.deleted_at = ?
WHERE t1.deleted_at = ? AND t3.id IS NULL WHERE t1.deleted_at = ?
` `
sqlParams := []interface{}{ sqlParams := []interface{}{
model.VendorIDJD, model.VendorIDJD,