diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index efb7fe52b..809faafac 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -989,7 +989,6 @@ func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID func addStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, isNeedUpdateRemote bool) (outStoreCourierMap *model.StoreCourierMap, err error) { globals.SugarLogger.Debugf("addStoreCourierMap %s, storeID:%d, isNeedUpdateRemote:%t", model.VendorChineseNames[vendorID], storeCourierMap, isNeedUpdateRemote) - userName := ctx.GetUserName() if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil { if db == nil { db = dao.GetDB() @@ -999,31 +998,21 @@ func addStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID if err = err2; err != nil { return nil, err } - if storeDetail.VendorStoreID != "" && storeDetail.VendorStoreID != storeCourierMap.VendorStoreID { + if storeDetail.VendorStoreID != "" { return nil, fmt.Errorf("门店已经绑定了%s, ID:%s, 如需重新绑定, 请先解绑", model.VendorChineseNames[vendorID], storeDetail.VendorStoreID) } - dao.WrapAddIDCULDEntity(storeCourierMap, userName) - storeCourierMap.StoreID = storeID - storeCourierMap.VendorID = vendorID storeDetail.VendorStoreID = storeCourierMap.VendorStoreID if err = updateCourierStore(ctx, storeDetail); err != nil { return nil, err } } - dao.Begin(db) - defer func() { - if r := recover(); r != nil || err != nil { - dao.Rollback(db) - if r != nil { - panic(r) - } - } - }() + dao.WrapAddIDCULDEntity(storeCourierMap, ctx.GetUserName()) + storeCourierMap.StoreID = storeID + storeCourierMap.VendorID = vendorID if err = dao.CreateEntity(db, storeCourierMap); err != nil { return nil, err } outStoreCourierMap = storeCourierMap - dao.Commit(db) } else { err = ErrCanNotFindVendor } @@ -1074,8 +1063,7 @@ func updateCourierStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) ( if handlerInfo := partner.GetDeliveryPlatformFromVendorID(storeDetail.VendorID); handlerInfo != nil && handlerInfo.Use4CreateWaybill { if updateHandler, ok := handlerInfo.Handler.(partner.IDeliveryUpdateStoreHandler); ok { - storeDetail.CourierStoreName = composeCourierStoreName(storeDetail) - err = updateHandler.UpdateStore(ctx, storeDetail) + err = updateHandler.UpdateStore(ctx, formalizeStore4Courier(storeDetail)) } } return err @@ -1110,11 +1098,13 @@ func updateOrCreateCourierStore(ctx *jxcontext.Context, storeDetail *dao.StoreDe if storeDetail.CityName == "" { return false, fmt.Errorf("门店的城市码有问题,请检查") } - storeDetail.CourierStoreName = composeCourierStoreName(storeDetail) + storeDetail = formalizeStore4Courier(storeDetail) if _, err = handlerInfo.Handler.GetStore(ctx, 0, storeDetail.VendorStoreID); err != nil { if handlerInfo.Handler.IsErrStoreNotExist(err) { storeDetail.VendorStoreID, storeDetail.AuditStatus, err = handlerInfo.Handler.CreateStore(ctx, storeDetail) - isCreated = true + if err == nil { + isCreated = true + } } } else { if updateHandler, _ := handlerInfo.Handler.(partner.IDeliveryUpdateStoreHandler); updateHandler != nil { @@ -1183,7 +1173,7 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd } } } - return resultList, err + return resultList, errList.GetErrListAsOne() }, storeIDs) tasksch.HandleTask(task, nil, len(storeIDs) > 1).Run() if !isAsync { @@ -1197,8 +1187,14 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd return hint, err } -func composeCourierStoreName(storeDetail *dao.StoreDetail2) (storeName string) { - return storeDetail.Name + "-" + storeDetail.VendorStoreID +func formalizeStore4Courier(storeDetail *dao.StoreDetail2) (newStoreDetail *dao.StoreDetail2) { + tmp := *storeDetail + newStoreDetail = &tmp + newStoreDetail.Name = storeDetail.Name + "-" + storeDetail.VendorStoreID + if newStoreDetail.PayeeName == "" { + newStoreDetail.PayeeName = "店主" + } + return newStoreDetail } func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { diff --git a/business/model/dao/store.go b/business/model/dao/store.go index dfbfcd904..95ac12072 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -41,9 +41,8 @@ type StoreDetail2 struct { CourierStatus int `json:"courierStatus"` AuditStatus int `json:"auditStatus"` - CourierStoreName string `json:"courierStoreName"` - DistrictName string `json:"districtName"` - CityName string `json:"cityName"` + DistrictName string `json:"districtName"` + CityName string `json:"cityName"` } func (s *StoreDetail) GetPricePerentage(price int) (pricePercentage int) { diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index a2f884583..bb845dbf6 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -131,7 +131,8 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop } shopInfo = &dadaapi.ShopInfo{ OriginShopID: storeDetail.VendorStoreID, - StationName: storeDetail.CourierStoreName, + StationName: storeDetail.Name, + Business: dadaapi.BusinessTypeConvStore, // 故意设置成这个的 CityName: cityName, AreaName: districtName, StationAddress: storeDetail.Address, @@ -165,17 +166,17 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt if err == nil { storeDetail = &dao.StoreDetail2{ Store: model.Store{ + Name: shopInfo.StationName, Address: shopInfo.StationAddress, Lng: jxutils.StandardCoordinate2Int(shopInfo.Lng), Lat: jxutils.StandardCoordinate2Int(shopInfo.Lat), PayeeName: shopInfo.ContactName, Tel1: shopInfo.Phone, }, - VendorID: model.VendorIDDada, - VendorStoreID: shopInfo.OriginShopID, - CourierStoreName: shopInfo.StationName, - CityName: shopInfo.CityName, - DistrictName: shopInfo.AreaName, + VendorID: model.VendorIDDada, + VendorStoreID: shopInfo.OriginShopID, + CityName: shopInfo.CityName, + DistrictName: shopInfo.AreaName, } } return storeDetail, err diff --git a/business/partner/delivery/mtps/store.go b/business/partner/delivery/mtps/store.go index 1ae6c9f2c..44527dd8b 100644 --- a/business/partner/delivery/mtps/store.go +++ b/business/partner/delivery/mtps/store.go @@ -41,7 +41,7 @@ func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.S } shopInfo := &mtpsapi.ShopInfo{ ShopID: storeDetail.VendorStoreID, - ShopName: storeDetail.CourierStoreName, + ShopName: storeDetail.Name, Category: mtpsapi.ShopCategoryFruit, SecondCategory: mtpsapi.ShopCategoryFruitFruit, ContactName: storeDetail.PayeeName, @@ -67,6 +67,7 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt if err == nil { storeDetail = &dao.StoreDetail2{ Store: model.Store{ + Name: shopInfo.ShopName, CityCode: shopInfo.City, PayeeName: shopInfo.ContactName, Tel1: shopInfo.ContactPhone, @@ -74,9 +75,8 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt Lng: shopInfo.ShopLng, Lat: shopInfo.ShopLat, }, - VendorID: model.VendorIDMTPS, - VendorStoreID: shopInfo.ShopID, - CourierStoreName: shopInfo.ShopName, + VendorID: model.VendorIDMTPS, + VendorStoreID: shopInfo.ShopID, } } return storeDetail, err