117 lines
3.8 KiB
Go
117 lines
3.8 KiB
Go
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"
|
|
"git.rosy.net.cn/jx-callback/business/partner"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
const (
|
|
fakeContactEmail = "fakeemail@163.com"
|
|
)
|
|
|
|
var (
|
|
auditStatusMap = map[int]int{
|
|
mtpsapi.ShopStatusAuditCreated: model.StoreAuditStatusCreated,
|
|
mtpsapi.ShopStatusAuditRejected: model.StoreAuditStatusRejected,
|
|
mtpsapi.ShopStatusAuditPassed: model.StoreAuditStatusCreated,
|
|
mtpsapi.ShopStatusAuditOnline: model.StoreAuditStatusOnline,
|
|
}
|
|
)
|
|
|
|
func getAuditStatus(vendorAuditStatus int) int {
|
|
if auditStatus, ok := auditStatusMap[vendorAuditStatus]; ok {
|
|
return auditStatus
|
|
}
|
|
return model.StoreAuditStatusCreated
|
|
}
|
|
|
|
func OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
|
|
return curDeliveryHandler.OnStoreStatus(msg)
|
|
}
|
|
|
|
func (c *DeliveryHandler) OnStoreStatus(msg *mtpsapi.CallbackShopStatusMsg) (retVal *mtpsapi.CallbackResponse) {
|
|
globals.SugarLogger.Debugf("mtps OnStoreStatus, msg:%s", utils.Format4Output(msg, true))
|
|
err := partner.CurStoreManager.OnCourierStoreStatusChanged(jxcontext.AdminCtx, msg.ShopID, model.VendorIDMTPS, getAuditStatus(msg.Status))
|
|
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.Name,
|
|
Category: mtpsapi.ShopCategoryFruit,
|
|
SecondCategory: mtpsapi.ShopCategoryFruitFruit,
|
|
ContactName: storeDetail.PayeeName,
|
|
ContactPhone: storeDetail.Tel1,
|
|
ContactEmail: fakeContactEmail,
|
|
ShopAddress: storeDetail.Address,
|
|
ShopLng: storeDetail.Lng,
|
|
ShopLat: storeDetail.Lat,
|
|
CoordinateType: mtpsapi.CoordinateTypeMars,
|
|
BusinessHours: string(utils.MustMarshal(businessHours)),
|
|
}
|
|
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
|
|
}
|
|
return vendorStoreID, 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{
|
|
Name: shopInfo.ShopName,
|
|
CityCode: shopInfo.City,
|
|
PayeeName: shopInfo.ContactName,
|
|
Tel1: shopInfo.ContactPhone,
|
|
Address: shopInfo.ShopAddress,
|
|
Lng: shopInfo.ShopLng,
|
|
Lat: shopInfo.ShopLat,
|
|
},
|
|
VendorID: model.VendorIDMTPS,
|
|
VendorStoreID: shopInfo.ShopID,
|
|
CourierStatus: model.StoreStatusOpened,
|
|
AuditStatus: model.StoreAuditStatusOnline,
|
|
}
|
|
}
|
|
return storeDetail, err
|
|
}
|
|
|
|
func (c *DeliveryHandler) IsErrStoreNotExist(err error) bool {
|
|
return mtpsapi.IsErrShopNotExist(err)
|
|
}
|
|
|
|
func (c *DeliveryHandler) IsErrStoreExist(err error) bool {
|
|
return mtpsapi.IsErrShopExist(err)
|
|
}
|
|
|
|
func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.StoreDetail2) (err error) {
|
|
if globals.EnableStoreWrite {
|
|
err = api.MtpsAPI.PagePoiUpdate(storeDetail.VendorStoreID, storeDetail.PayeeName, storeDetail.Tel1, fakeContactEmail)
|
|
}
|
|
return err
|
|
}
|