88 lines
3.0 KiB
Go
88 lines
3.0 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/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) {
|
|
globals.SugarLogger.Debugf("mtps OnStoreStatus, msg:%s", utils.Format4Output(msg, true))
|
|
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)
|
|
}
|