- 重构配送门店管理

This commit is contained in:
gazebo
2019-07-23 14:29:58 +08:00
parent 79d81fdd73
commit 22737c7681
13 changed files with 325 additions and 159 deletions

View File

@@ -130,7 +130,7 @@ func StoreDetail2ShopInfo(storeDetail *dao.StoreDetail2) (shopInfo *dadaapi.Shop
}
}
shopInfo = &dadaapi.ShopInfo{
OriginShopID: utils.Int2Str(storeDetail.ID),
OriginShopID: storeDetail.VendorStoreID,
StationName: storeDetail.CourierStoreName,
CityName: cityName,
AreaName: districtName,
@@ -160,6 +160,31 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
return err
}
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 {
storeDetail = &dao.StoreDetail2{
Store: model.Store{
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,
}
}
return storeDetail, err
}
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
return dadaapi.IsErrShopNotExist(err)
}
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
db := dao.GetDB()
deliveryFeeInfo = &partner.WaybillFeeInfo{}

View File

@@ -0,0 +1,86 @@
package mtps
import (
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/utils"
"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"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
var (
auditStatusMap = map[int]int{
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusOnline: model.StoreAuditStatusOnline,
}
)
func OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
return curDeliveryHandler.OnStoreStatus(msg)
}
func (c *DeliveryHandler) OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
auditStatus := auditStatusMap[msg.Status]
err := partner.CurStoreManager.OnCourierStoreStatusChanged(jxcontext.AdminCtx, msg.ShopID, model.VendorIDMTPS, auditStatus)
retVal = mtpsapi.Err2CallbackResponse(err, "mtps OnStoreStatus")
return retVal
}
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
businessHours := []*mtpsapi.BusinessHour{
&mtpsapi.BusinessHour{
BeginTime: "06:00",
EndTime: "22:00",
},
}
shopInfo := &mtpsapi.ShopInfo{
ShopID: storeDetail.VendorStoreID,
ShopName: storeDetail.CourierStoreName,
Category: mtpsapi.ShopCategoryFruit,
SecondCategory: mtpsapi.ShopCategoryFruitFruit,
ContactName: storeDetail.PayeeName,
ContactPhone: storeDetail.Tel1,
ShopAddress: storeDetail.Address,
ShopLng: storeDetail.Lng,
ShopLat: storeDetail.Lat,
CoordinateType: mtpsapi.CoordinateTypeMars,
BusinessHours: string(utils.MustMarshal(businessHours)),
}
shopStatus := mtpsapi.ShopStatusCreateSuccess
if globals.EnableStoreWrite {
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
}
if err == nil {
status = auditStatusMap[shopStatus]
}
return "", status, err
}
func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) {
shopInfo, err := api.MtpsAPI.ShopQuery(vendorStoreID)
if err == nil {
storeDetail = &dao.StoreDetail2{
Store: model.Store{
CityCode: shopInfo.City,
PayeeName: shopInfo.ContactName,
Tel1: shopInfo.ContactPhone,
Address: shopInfo.ShopAddress,
Lng: shopInfo.ShopLng,
Lat: shopInfo.ShopLat,
},
VendorID: model.VendorIDMTPS,
VendorStoreID: shopInfo.ShopID,
CourierStoreName: shopInfo.ShopName,
}
}
return storeDetail, err
}
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
return mtpsapi.IsErrShopNotExist(err)
}

View File

@@ -8,7 +8,6 @@ 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"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -31,12 +30,6 @@ var (
var (
curDeliveryHandler *DeliveryHandler
auditStatusMap = map[int]int{
mtpsapi.ShopStatusCreateSuccess: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
mtpsapi.ShopStatusOnline: model.StoreAuditStatusOnline,
}
)
type DeliveryHandler struct {
@@ -121,36 +114,6 @@ func (c *DeliveryHandler) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (re
return retVal
}
func (c *DeliveryHandler) CreateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (vendorStoreID string, status int, err error) {
businessHours := []*mtpsapi.BusinessHour{
&mtpsapi.BusinessHour{
BeginTime: "06:00",
EndTime: "22:00",
},
}
shopInfo := &mtpsapi.ShopInfo{
ShopID: utils.Int2Str(storeDetail.ID),
ShopName: storeDetail.CourierStoreName,
Category: mtpsapi.ShopCategoryFruit,
SecondCategory: mtpsapi.ShopCategoryFruitFruit,
ContactName: storeDetail.PayeeName,
ContactPhone: storeDetail.Tel1,
ShopAddress: storeDetail.Address,
ShopLng: storeDetail.Lng,
ShopLat: storeDetail.Lat,
CoordinateType: mtpsapi.CoordinateTypeMars,
BusinessHours: string(utils.MustMarshal(businessHours)),
}
shopStatus := mtpsapi.ShopStatusCreateSuccess
if globals.EnableStoreWrite {
shopStatus, err = api.MtpsAPI.ShopCreate(shopInfo)
}
if err == nil {
status = auditStatusMap[shopStatus]
}
return "", status, err
}
func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *partner.WaybillFeeInfo, err error) {
db := dao.GetDB()
deliveryFeeInfo = &partner.WaybillFeeInfo{}