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 == "" {
return false, fmt.Errorf("门店的城市码有问题,请检查")
}
storeDetail = formalizeStore4Courier(storeDetail)
formalizeStore4Courier(storeDetail)
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) {
storeDetail.VendorStoreID, storeDetail.AuditStatus, err = handlerInfo.Handler.CreateStore(ctx, storeDetail)
if err == nil {
isCreated = true
} else if handlerInfo.Handler.IsErrStoreExist(err) {
storeDetail.AuditStatus = model.StoreAuditStatusCreated
err = nil
}
}
} else {
storeDetail.CourierStatus = remoteStoreDetail.CourierStatus
storeDetail.AuditStatus = remoteStoreDetail.AuditStatus
needUpdate = true
}
if err == nil && needUpdate {
@@ -1161,7 +1165,6 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd
if isNeedAdd {
storeDetail.VendorID = vendorID
storeDetail.VendorStoreID = utils.Int2Str(storeDetail.ID)
storeDetail.AuditStatus = model.StoreAuditStatusCreated
}
if _, err = updateOrCreateCourierStore(ctx, storeDetail); err == nil && isNeedAdd {
storeCourier := &model.StoreCourierMap{
@@ -1196,14 +1199,12 @@ func UpdateOrCreateCourierStores(ctx *jxcontext.Context, storeID int, isForceUpd
return hint, err
}
func formalizeStore4Courier(storeDetail *dao.StoreDetail2) (newStoreDetail *dao.StoreDetail2) {
tmp := *storeDetail
newStoreDetail = &tmp
newStoreDetail.Name = storeDetail.Name + "-" + storeDetail.VendorStoreID
if newStoreDetail.PayeeName == "" {
newStoreDetail.PayeeName = "店主"
func formalizeStore4Courier(storeDetail *dao.StoreDetail2) *dao.StoreDetail2 {
storeDetail.Name = storeDetail.Name + "-" + storeDetail.VendorStoreID
if storeDetail.PayeeName == "" {
storeDetail.PayeeName = "店主"
}
return newStoreDetail
return storeDetail
}
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) {
if globals.EnableStoreWrite {
_, err = api.DadaAPI.ShopAdd(StoreDetail2ShopInfo(storeDetail))
}
if err == nil {
vendorStoreID, err = api.DadaAPI.ShopAdd(StoreDetail2ShopInfo(storeDetail))
if err == nil {
status = model.StoreAuditStatusOnline
}
} else {
vendorStoreID = utils.Int64ToStr(jxutils.GenFakeID())
status = model.StoreAuditStatusOnline
}
return "", status, err
return vendorStoreID, status, err
}
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
}
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) {
shopInfo, err := api.DadaAPI.ShopDetail(vendorStoreID)
if err == nil {
@@ -175,6 +185,8 @@ func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorSt
},
VendorID: model.VendorIDDada,
VendorStoreID: shopInfo.OriginShopID,
CourierStatus: dadaStatus2Jx(shopInfo.Status),
AuditStatus: model.StoreAuditStatusOnline,
CityName: shopInfo.CityName,
DistrictName: shopInfo.AreaName,
}

View File

@@ -3,6 +3,7 @@ package mtps
import (
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"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/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -13,10 +14,10 @@ import (
var (
auditStatusMap = map[int]int{
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusAuditCreated: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
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,
BusinessHours: string(utils.MustMarshal(businessHours)),
}
shopStatus := mtpsapi.ShopStatusCreateSuccess
shopStatus := mtpsapi.ShopStatusAuditCreated
if globals.EnableStoreWrite {
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
if err == nil {
vendorStoreID = shopInfo.ShopID
status = getAuditStatus(shopStatus)
}
} else {
vendorStoreID = utils.Int64ToStr(jxutils.GenFakeID())
status = model.StoreAuditStatusOnline
}
if err == nil {
status = getAuditStatus(shopStatus)
}
return "", status, err
return vendorStoreID, status, err
}
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,
VendorStoreID: shopInfo.ShopID,
CourierStatus: model.StoreStatusOpened,
AuditStatus: model.StoreAuditStatusOnline,
}
}
return storeDetail, err

View File

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