From 2b4e03661922f8ddafe2f9e6c4ff4a9d8b1ddc8c Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 18 Apr 2019 19:01:12 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E7=BB=91=E5=AE=9A=E8=BE=BE=E8=BE=BE?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=88=B7=E6=96=B0=E9=97=A8=E5=BA=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 62 ++++++++++++++++++++--------------- business/model/dao/store.go | 4 ++- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 19506a607..57b55969a 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -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 } diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 5dcafd6db..56330c70a 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -25,6 +25,7 @@ type StoreDetail struct { type StoreDetail2 struct { model.Store VendorStoreID string `orm:"column(vendor_store_id)` // 这个在GetMissingDadaStores返回中指的是到家的vendorStoreID + DadaStoreID string `orm:"column(dada_store_id)` DistrictName string CityName string } @@ -132,12 +133,13 @@ func GetMissingDadaStores(db *DaoDB, storeID int, isMustHaveJdStore bool) (store SELECT t1.*, t2.vendor_store_id vendor_store_id, city.name city_name, district.name district_name + t3.vendor_store_id dada_store_id FROM store t1 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 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 = ? - WHERE t1.deleted_at = ? AND t3.id IS NULL + WHERE t1.deleted_at = ? ` sqlParams := []interface{}{ model.VendorIDJD,