This commit is contained in:
gazebo
2019-07-24 20:10:54 +08:00
parent 94510ff2af
commit 987d205985
4 changed files with 45 additions and 25 deletions

View File

@@ -1100,18 +1100,22 @@ func updateOrCreateCourierStore(ctx *jxcontext.Context, storeDetail *dao.StoreDe
if storeDetail.CityName == "" { if storeDetail.CityName == "" {
return false, fmt.Errorf("门店的城市码有问题,请检查") return false, fmt.Errorf("门店的城市码有问题,请检查")
} }
storeDetail = formalizeStore4Courier(storeDetail) formalizeStore4Courier(storeDetail)
needUpdate := false needUpdate := false
if _, err = handlerInfo.Handler.GetStore(ctx, 0, storeDetail.VendorStoreID); err != nil { remoteStoreDetail, err2 := handlerInfo.Handler.GetStore(ctx, 0, storeDetail.VendorStoreID)
if err = err2; err != nil {
if handlerInfo.Handler.IsErrStoreNotExist(err) { if handlerInfo.Handler.IsErrStoreNotExist(err) {
storeDetail.VendorStoreID, storeDetail.AuditStatus, err = handlerInfo.Handler.CreateStore(ctx, storeDetail) storeDetail.VendorStoreID, storeDetail.AuditStatus, err = handlerInfo.Handler.CreateStore(ctx, storeDetail)
if err == nil { if err == nil {
isCreated = true isCreated = true
} else if handlerInfo.Handler.IsErrStoreExist(err) { } else if handlerInfo.Handler.IsErrStoreExist(err) {
storeDetail.AuditStatus = model.StoreAuditStatusCreated
err = nil err = nil
} }
} }
} else { } else {
storeDetail.CourierStatus = remoteStoreDetail.CourierStatus
storeDetail.AuditStatus = remoteStoreDetail.AuditStatus
needUpdate = true needUpdate = true
} }
if err == nil && needUpdate { if err == nil && needUpdate {
@@ -1161,7 +1165,6 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd
if isNeedAdd { if isNeedAdd {
storeDetail.VendorID = vendorID storeDetail.VendorID = vendorID
storeDetail.VendorStoreID = utils.Int2Str(storeDetail.ID) storeDetail.VendorStoreID = utils.Int2Str(storeDetail.ID)
storeDetail.AuditStatus = model.StoreAuditStatusCreated
} }
if _, err = updateOrCreateCourierStore(ctx, storeDetail); err == nil && isNeedAdd { if _, err = updateOrCreateCourierStore(ctx, storeDetail); err == nil && isNeedAdd {
storeCourier := &model.StoreCourierMap{ storeCourier := &model.StoreCourierMap{
@@ -1196,14 +1199,12 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd
return hint, err return hint, err
} }
func formalizeStore4Courier(storeDetail *dao.StoreDetail2) (newStoreDetail *dao.StoreDetail2) { func formalizeStore4Courier(storeDetail *dao.StoreDetail2) *dao.StoreDetail2 {
tmp := *storeDetail storeDetail.Name = storeDetail.Name + "-" + storeDetail.VendorStoreID
newStoreDetail = &tmp if storeDetail.PayeeName == "" {
newStoreDetail.Name = storeDetail.Name + "-" + storeDetail.VendorStoreID storeDetail.PayeeName = "店主"
if newStoreDetail.PayeeName == "" {
newStoreDetail.PayeeName = "店主"
} }
return newStoreDetail return storeDetail
} }
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {

View File

@@ -146,12 +146,15 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) { func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
if globals.EnableStoreWrite { if globals.EnableStoreWrite {
_, err = api.DadaAPI.ShopAdd(StoreDetail2ShopInfo(storeDetail)) vendorStoreID, err = api.DadaAPI.ShopAdd(StoreDetail2ShopInfo(storeDetail))
}
if err == nil { if err == nil {
status = model.StoreAuditStatusOnline status = model.StoreAuditStatusOnline
} }
return "", status, err } else {
vendorStoreID = utils.Int64ToStr(jxutils.GenFakeID())
status = model.StoreAuditStatusOnline
}
return vendorStoreID, status, err
} }
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) { func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
@@ -161,6 +164,13 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
return err return err
} }
func dadaStatus2Jx(dadaStatus int) int {
if dadaStatus == dadaapi.ShopStatusOnline {
return model.StoreStatusOpened
}
return model.StoreStatusDisabled
}
func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) { func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
shopInfo, err := api.DadaAPI.ShopDetail(vendorStoreID) shopInfo, err := api.DadaAPI.ShopDetail(vendorStoreID)
if err == nil { if err == nil {
@@ -175,6 +185,8 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt
}, },
VendorID: model.VendorIDDada, VendorID: model.VendorIDDada,
VendorStoreID: shopInfo.OriginShopID, VendorStoreID: shopInfo.OriginShopID,
CourierStatus: dadaStatus2Jx(shopInfo.Status),
AuditStatus: model.StoreAuditStatusOnline,
CityName: shopInfo.CityName, CityName: shopInfo.CityName,
DistrictName: shopInfo.AreaName, DistrictName: shopInfo.AreaName,
} }

View File

@@ -3,6 +3,7 @@ package mtps
import ( import (
"git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
@@ -13,10 +14,10 @@ import (
var ( var (
auditStatusMap = map[int]int{ auditStatusMap = map[int]int{
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated, mtpsapi.ShopStatusAuditCreated: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected, mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated, mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusOnline: model.StoreAuditStatusOnline, mtpsapi.ShopStatusAuditOnline: model.StoreAuditStatusOnline,
} }
) )
@@ -58,14 +59,18 @@ func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.S
CoordinateType: mtpsapi.CoordinateTypeMars, CoordinateType: mtpsapi.CoordinateTypeMars,
BusinessHours: string(utils.MustMarshal(businessHours)), BusinessHours: string(utils.MustMarshal(businessHours)),
} }
shopStatus := mtpsapi.ShopStatusCreateSuccess shopStatus := mtpsapi.ShopStatusAuditCreated
if globals.EnableStoreWrite { if globals.EnableStoreWrite {
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo) shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
}
if err == nil { if err == nil {
vendorStoreID = shopInfo.ShopID
status = getAuditStatus(shopStatus) status = getAuditStatus(shopStatus)
} }
return "", status, err } else {
vendorStoreID = utils.Int64ToStr(jxutils.GenFakeID())
status = model.StoreAuditStatusOnline
}
return vendorStoreID, status, err
} }
func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) { func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
@@ -83,6 +88,8 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt
}, },
VendorID: model.VendorIDMTPS, VendorID: model.VendorIDMTPS,
VendorStoreID: shopInfo.ShopID, VendorStoreID: shopInfo.ShopID,
CourierStatus: model.StoreStatusOpened,
AuditStatus: model.StoreAuditStatusOnline,
} }
} }
return storeDetail, err return storeDetail, err

View File

@@ -12,11 +12,11 @@ import (
) )
const ( const (
testShopBaiduID = "2233976901" // testShopBaiduID = "2233976901"
testShopID = 100077 // testShopID = 100077
// testShopBaiduID = "2267254343" testShopBaiduID = "2267254343"
// testShopID = 2 testShopID = 2
) )
func init() { func init() {