- 接收门店状态消息,本地同步状态,京东暂时无效
This commit is contained in:
@@ -59,7 +59,7 @@ func (s StatusTimerSlice) Swap(i, j int) {
|
||||
|
||||
func init() {
|
||||
FixedOrderManager = NewOrderManager()
|
||||
partner.Init(FixedOrderManager)
|
||||
partner.InitOrderManager(FixedOrderManager)
|
||||
}
|
||||
|
||||
func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
||||
|
||||
76
business/jxstore/cms/storeman.go
Normal file
76
business/jxstore/cms/storeman.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"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"
|
||||
)
|
||||
|
||||
type StoreManager struct {
|
||||
}
|
||||
|
||||
var (
|
||||
FixedStoreManager *StoreManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
FixedStoreManager = &StoreManager{}
|
||||
partner.InitStoreManager(FixedStoreManager)
|
||||
}
|
||||
|
||||
func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error) {
|
||||
db := dao.GetDB()
|
||||
storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, vendorID)
|
||||
if err == nil {
|
||||
var storeKV, storeMapKV map[string]interface{}
|
||||
if storeStatus == model.StoreStatusOpened {
|
||||
if storeDetail.Status != model.StoreStatusOpened {
|
||||
storeKV = map[string]interface{}{
|
||||
"Status": model.StoreStatusOpened,
|
||||
}
|
||||
}
|
||||
if storeDetail.VendorStatus != model.StoreStatusOpened {
|
||||
storeMapKV = map[string]interface{}{
|
||||
"Status": model.StoreStatusOpened,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if storeDetail.Status == model.StoreStatusOpened && storeDetail.VendorStatus == model.StoreStatusOpened {
|
||||
storeMapKV = map[string]interface{}{
|
||||
"Status": storeStatus,
|
||||
}
|
||||
} else if storeDetail.Status == model.StoreStatusClosed && storeStatus == model.StoreStatusClosed {
|
||||
storeMapKV = map[string]interface{}{
|
||||
"Status": model.StoreStatusOpened,
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil && (storeKV != nil || storeMapKV != nil) {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}()
|
||||
if storeKV != nil {
|
||||
store := &model.Store{}
|
||||
store.ID = storeDetail.Store.ID
|
||||
if _, err = dao.UpdateEntityLogically(db, store, storeKV, "admin", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if storeMapKV != nil {
|
||||
if _, err = dao.UpdateEntityLogically(db, &model.StoreMap{}, storeMapKV, "admin", map[string]interface{}{
|
||||
model.FieldStoreID: storeDetail.Store.ID,
|
||||
model.FieldVendorID: vendorID,
|
||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -90,6 +90,7 @@ var (
|
||||
|
||||
var (
|
||||
CurOrderManager IOrderManager
|
||||
CurStoreManager IStoreManager
|
||||
|
||||
PurchasePlatformHandlers map[int]IPurchasePlatformHandler
|
||||
DeliveryPlatformHandlers map[int]*DeliveryPlatformHandlerInfo
|
||||
@@ -123,6 +124,10 @@ type IOrderManager interface {
|
||||
SaveAfsOrderFinancialInfo(afsOrder *model.AfsOrder) (err error)
|
||||
}
|
||||
|
||||
type IStoreManager interface {
|
||||
OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error)
|
||||
}
|
||||
|
||||
// purchase handler中
|
||||
// 所有Sync,Refresh开头的函数都必须自己清理sync_status标记
|
||||
// 所有非以Sync,Refresh开头的函数不用自己清理sync_status标记(VendorSync统一处理)
|
||||
@@ -151,7 +156,7 @@ type IPurchasePlatformHandler interface {
|
||||
////////
|
||||
// Store
|
||||
ReadStore(vendorStoreID string) (store *model.Store, err error)
|
||||
UpdateStore(db *dao.DaoDB, storeID int, userName string) error
|
||||
UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error)
|
||||
// EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error
|
||||
// OpenStore(vendorStoreID string, userName string) error
|
||||
// CloseStore(vendorStoreID, closeNotice, userName string) error
|
||||
@@ -167,6 +172,7 @@ type IPurchasePlatformHandler interface {
|
||||
|
||||
ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error)
|
||||
UploadImg(ctx *jxcontext.Context, imgURL string, imgData []byte, imgName string) (imgHint string, err error)
|
||||
GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error)
|
||||
}
|
||||
|
||||
// db *dao.DaoDB,
|
||||
@@ -233,10 +239,14 @@ func init() {
|
||||
PrinterPlatformHandlers = make(map[int]IPrinterHandler)
|
||||
}
|
||||
|
||||
func Init(curOrderManager IOrderManager) {
|
||||
func InitOrderManager(curOrderManager IOrderManager) {
|
||||
CurOrderManager = curOrderManager
|
||||
}
|
||||
|
||||
func InitStoreManager(curStoreManager IStoreManager) {
|
||||
CurStoreManager = curStoreManager
|
||||
}
|
||||
|
||||
func RegisterPurchasePlatform(handler IPurchasePlatformHandler) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsPurchaseVendorExist(vendorID)) {
|
||||
|
||||
@@ -8,10 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func OnCallbackMsg(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse) {
|
||||
if msg.Cmd == ebaiapi.CmdOrderCreate ||
|
||||
msg.Cmd == ebaiapi.CmdOrderStatus ||
|
||||
msg.Cmd == ebaiapi.CmdOrderUserCancel {
|
||||
orderID := GetOrderIDFromMsg(msg)
|
||||
if orderID := GetOrderIDFromMsg(msg); orderID != "" {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
switch msg.Cmd {
|
||||
case ebaiapi.CmdOrderCreate, ebaiapi.CmdOrderStatus, ebaiapi.CmdOrderUserCancel:
|
||||
@@ -25,13 +22,18 @@ func OnCallbackMsg(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
} else if msg.Cmd == ebaiapi.CmdShopMsgPush {
|
||||
response = CurPurchaseHandler.onShopMsgPush(msg)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func GetOrderIDFromMsg(msg *ebaiapi.CallbackMsg) string {
|
||||
if tryOrderID, ok := msg.Body["order_id"].(string); ok {
|
||||
return tryOrderID
|
||||
if orderID := msg.Body["order_id"]; orderID != nil {
|
||||
if tryOrderID, ok := orderID.(string); ok {
|
||||
return tryOrderID
|
||||
}
|
||||
return utils.Int64ToStr(utils.MustInterface2Int64(orderID))
|
||||
}
|
||||
return utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["order_id"]))
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
|
||||
}
|
||||
}
|
||||
|
||||
if ebaiStatus, err2 := api.EbaiAPI.ShopBusStatusGet("", baiduShopID, ebaiapi.PlatformFlagBaidu); err2 == nil {
|
||||
if ebaiStatus, err2 := api.EbaiAPI.ShopBusStatusGet("", baiduShopID, ebaiapi.PlatformFlagElm); err2 == nil {
|
||||
retVal.Status = EbaiBusStatus2JxStatus(ebaiStatus)
|
||||
}
|
||||
|
||||
@@ -394,3 +394,31 @@ func genStoreMapFromStore(store *tEbaiStoreInfo) map[string]interface{} {
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error) {
|
||||
ebaiStatus, err := api.EbaiAPI.ShopBusStatusGet("", utils.Str2Int64(vendorStoreID), ebaiapi.PlatformFlagElm)
|
||||
if err == nil {
|
||||
storeStatus = EbaiBusStatus2JxStatus(ebaiStatus)
|
||||
}
|
||||
return storeStatus, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onShopMsgPush(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse) {
|
||||
var err error
|
||||
vendorStoreID := utils.Interface2String(msg.Body["baidu_shop_id"])
|
||||
storeStatus := model.StoreStatusOpened
|
||||
switch utils.Interface2String(msg.Body["msg_type"]) {
|
||||
case "online", "offline":
|
||||
storeStatus, err = c.GetStoreStatus(jxcontext.AdminCtx, vendorStoreID)
|
||||
case "shop_open":
|
||||
if utils.Interface2String(msg.Body["business_ele"]) == "1" {
|
||||
storeStatus = model.StoreStatusOpened
|
||||
} else {
|
||||
storeStatus = model.StoreStatusClosed
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = partner.CurStoreManager.OnStoreStatusChanged(vendorStoreID, model.VendorIDEBAI, storeStatus)
|
||||
}
|
||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, nil)
|
||||
}
|
||||
|
||||
@@ -32,3 +32,7 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
|
||||
// func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error) {
|
||||
return storeStatus, err
|
||||
}
|
||||
|
||||
33
business/partner/purchase/jd/callback.go
Normal file
33
business/partner/purchase/jd/callback.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if retVal = curPurchaseHandler.OnOrderMsg(msg); retVal == nil {
|
||||
retVal = jdapi.Err2CallbackResponse(errors.New("Internal Error"), "")
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if retVal = curPurchaseHandler.OnWaybillMsg(msg); retVal == nil {
|
||||
retVal = jdapi.Err2CallbackResponse(errors.New("Internal Error"), "")
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnStoreMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
return curPurchaseHandler.onStoreMsg(msg)
|
||||
}
|
||||
|
||||
func OnAfterSaleMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
return retVal
|
||||
}
|
||||
@@ -1,14 +1,10 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"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/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,20 +24,6 @@ func (c *PurchaseHandler) GetVendorID() int {
|
||||
return model.VendorIDJD
|
||||
}
|
||||
|
||||
func OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if retVal = curPurchaseHandler.OnOrderMsg(msg); retVal == nil {
|
||||
retVal = jdapi.Err2CallbackResponse(errors.New("Internal Error"), "")
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if retVal = curPurchaseHandler.OnWaybillMsg(msg); retVal == nil {
|
||||
retVal = jdapi.Err2CallbackResponse(errors.New("Internal Error"), "")
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func JdOperationTime2JxOperationTime(value1 interface{}) int16 {
|
||||
value := int16(utils.Interface2Int64WithDefault(value1, 0))
|
||||
return (value/2)*100 + (value%2)*30
|
||||
@@ -73,18 +55,6 @@ func JxStoreStatus2JdStatus(status int) (yn, closeStatus int) {
|
||||
}
|
||||
}
|
||||
|
||||
func OnStoreMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
globals.SugarLogger.Debugf("OnStoreMsg, msg:%s", utils.Format4Output(msg, false))
|
||||
return jdapi.Err2CallbackResponse(nil, "")
|
||||
}
|
||||
|
||||
func OnAfterSaleMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgData []byte, imgName string) (imgHint string, err error) {
|
||||
return imgHint, err
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
@@ -291,3 +292,23 @@ func JdDeliveryType2Jx(deliveryType int) int8 {
|
||||
}
|
||||
return scheduler.StoreDeliveryTypeByPlatform
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error) {
|
||||
result, err := api.JdAPI.GetStoreInfoByStationNo(vendorStoreID)
|
||||
if err == nil {
|
||||
storeStatus = JdStoreStatus2JxStatus(result["yn"], result["closeStatus"])
|
||||
}
|
||||
return storeStatus, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onStoreMsg(msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
||||
var err error
|
||||
if msg.StatusID == jdapi.StatusIDUpdateStore {
|
||||
var storeStatus int
|
||||
vendorStoreID := msg.BillID
|
||||
if storeStatus, err = c.GetStoreStatus(jxcontext.AdminCtx, vendorStoreID); err == nil {
|
||||
err = partner.CurStoreManager.OnStoreStatusChanged(vendorStoreID, model.VendorIDJD, storeStatus)
|
||||
}
|
||||
}
|
||||
return jdapi.Err2CallbackResponse(err, "")
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func OnOrderCallbackMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
if msg.Cmd == mtwmapi.MsgTypePrivateNumberDowngrade {
|
||||
response = mtwmapi.SuccessResponse
|
||||
} else {
|
||||
orderID := GetOrderIDFromMsg(msg)
|
||||
if orderID := GetOrderIDFromMsg(msg); orderID != "" {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
switch msg.Cmd {
|
||||
case mtwmapi.MsgTypeWaybillStatus:
|
||||
@@ -20,11 +17,13 @@ func OnOrderCallbackMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackRes
|
||||
response = curPurchaseHandler.onOrderMsg(msg)
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDMTWM))
|
||||
if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
}
|
||||
}
|
||||
if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
} else if msg.Cmd == mtwmapi.MsgTypeStoreStatusChanged {
|
||||
response = curPurchaseHandler.onStoreStatusChanged(msg)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
@@ -161,3 +161,32 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
|
||||
return "", errors.New("美团外卖不支持此操作")
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) onStoreStatusChanged(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
var err error
|
||||
poiStatus := int(utils.Str2Int64(msg.Data.Get("poi_status")))
|
||||
vendorStoreID := msg.Data.Get("app_poi_code")
|
||||
storeStatus := 0
|
||||
if poiStatus == mtwmapi.MsgPoiStatusOpened {
|
||||
storeStatus = model.StoreStatusOpened
|
||||
} else if poiStatus == mtwmapi.MsgPoiStatusClosed {
|
||||
storeStatus = model.StoreStatusClosed
|
||||
} else if poiStatus == mtwmapi.MsgPoiStatusOffline {
|
||||
storeStatus = model.StoreStatusDisabled
|
||||
} else {
|
||||
storeStatus, err = p.GetStoreStatus(jxcontext.AdminCtx, vendorStoreID)
|
||||
}
|
||||
if err == nil {
|
||||
err = partner.CurStoreManager.OnStoreStatusChanged(vendorStoreID, model.VendorIDMTWM, storeStatus)
|
||||
}
|
||||
response = mtwmapi.Err2CallbackResponse(err, "")
|
||||
return response
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error) {
|
||||
result, err := api.MtwmAPI.PoiGet(vendorStoreID)
|
||||
if err == nil {
|
||||
return bizStatusMtwm2JX(int(utils.MustInterface2Int64(result["open_level"])), int(utils.MustInterface2Int64(result["is_online"]))), nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestSyncStoreCategory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSyncLocalStoreCategory(t *testing.T) {
|
||||
hint, err := new(PurchaseHandler).SyncLocalStoreCategory(jxcontext.AdminCtx, nil, 100077, true)
|
||||
hint, err := new(PurchaseHandler).SyncLocalStoreCategory(jxcontext.AdminCtx, nil, 100077, true, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -20,3 +20,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID string) (storeStatus int, err error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -61,9 +61,13 @@ func (c *MtwmController) OrderCanceled() {
|
||||
}
|
||||
|
||||
func (c *MtwmController) OrderRefund() {
|
||||
c.onCallbackMsg(mtwmapi.MsgTypeOrderCanceled)
|
||||
c.onCallbackMsg(mtwmapi.MsgTypeOrderRefund)
|
||||
}
|
||||
|
||||
func (c *MtwmController) OrderPartialRefund() {
|
||||
c.onCallbackMsg(mtwmapi.MsgTypeOrderCanceled)
|
||||
c.onCallbackMsg(mtwmapi.MsgTypeOrderPartialRefund)
|
||||
}
|
||||
|
||||
func (c *MtwmController) StoreStatusChanged() {
|
||||
c.onCallbackMsg(mtwmapi.MsgTypeStoreStatusChanged)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user