到家商城的订单发通知消息

+Store.LinkStoreID
This commit is contained in:
gazebo
2020-02-04 16:20:09 +08:00
parent b76404d31d
commit f118cd8331
14 changed files with 249 additions and 185 deletions

View File

@@ -0,0 +1,56 @@
package orderman
import (
"fmt"
"strings"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
func (c *OrderManager) OnNewFakeJdOrder(vendorOrderID string) (err error) {
orderInfo, err := api.FakeJdAPI.FakeQuerySingleOrder(vendorOrderID)
if err == nil {
err = c.notifyNewFakeJdOrder(orderInfo)
}
return err
}
func (c *OrderManager) notifyNewFakeJdOrder(orderInfo *jdapi.OrderInfo) (err error) {
vendorStoreID := orderInfo.DeliveryStationNo
db := dao.GetDB()
storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, model.VendorIDJD)
if err != nil {
return err
}
realStoreID := storeDetail.ID
if storeDetail.LinkStoreID != 0 {
realStoreID = storeDetail.LinkStoreID
}
notifyWxNewFakeJdOrder(orderInfo, realStoreID)
return err
}
func notifyWxNewFakeJdOrder(order *jdapi.OrderInfo, storeID int) (err error) {
globals.SugarLogger.Debugf("notifyWxNewFakeJdOrder orderID:%s", order.SrcOrderID)
sb := new(strings.Builder)
sb.WriteString("老板,你有新订单了\n")
sb.WriteString(fmt.Sprintf("订单号:%s\n", order.SrcOrderID))
sb.WriteString(fmt.Sprintf("买家:%s\n", order.BuyerFullName))
sb.WriteString(fmt.Sprintf("电话:%s\n", order.BuyerMobile))
sb.WriteString(fmt.Sprintf("收货地址:%s\n", order.BuyerFullAddress))
sb.WriteString("商品详情:\n")
for _, product := range order.Product {
sb.WriteString(fmt.Sprintf("\t%s*%d\n", product.SkuName, product.SkuCount))
}
title := fmt.Sprintf("你有到家菜市新订单%d", order.OrderNum)
context := sb.String()
_, err = weixinmsg.SendStoreMessage(jxcontext.AdminCtx, title, context, []int{storeID}, true, true)
return err
}

View File

@@ -0,0 +1,14 @@
package orderman
import (
"testing"
"time"
)
func TestOnNewFakeJdOrder(t *testing.T) {
err := FixedOrderManager.OnNewFakeJdOrder("2002984074001021")
if err != nil {
t.Fatal(err)
}
time.Sleep(3 * time.Second)
}

View File

@@ -0,0 +1,17 @@
package orderman
import (
"git.rosy.net.cn/jx-callback/globals/api2"
"git.rosy.net.cn/jx-callback/globals/testinit"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/elm"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/weimob/wsc"
)
func init() {
testinit.Init()
api2.Init()
}

View File

@@ -6,11 +6,8 @@ import (
"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/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
)
type MessageStatusExt struct {
@@ -19,57 +16,6 @@ type MessageStatusExt struct {
Title string `json:"title"`
}
func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
dao.Begin(db)
defer dao.Rollback(db)
msg := &model.Message{
Title: title,
Content: content,
Type: model.MessageTypeStore,
}
dao.WrapAddIDCULDEntity(msg, ctx.GetUserName())
if err = dao.CreateEntity(db, msg); err != nil {
return "", err
}
msgStatusList := make([]*model.MessageStatus, len(storeIDs))
for k, storeID := range storeIDs {
msgStatus := &model.MessageStatus{
MessageID: msg.ID,
StoreID: storeID,
Status: model.MessageStatusNew,
}
dao.WrapAddIDCULDEntity(msgStatus, ctx.GetUserName())
if err = dao.CreateEntity(db, msgStatus); err != nil {
return "", err
}
msgStatusList[k] = msgStatus
}
dao.Commit(db)
rootTask := tasksch.NewParallelTask("SendStoreMessage", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
db := dao.GetDB()
msgStatus := batchItemList[0].(*model.MessageStatus)
if err = weixinmsg.NotifyStoreMessage(msgStatus.StoreID, msgStatus.MessageID, msgStatus.ID, msg.Title, msg.Content); err == nil {
msgStatus.Status = model.MessageStatusSendAllSuccess
} else {
msgStatus.Status = model.MessageStatusSendAllFailed
}
dao.WrapUpdateULEntity(msgStatus, ctx.GetUserName())
globals.SugarLogger.Debug(utils.Format4Output(msgStatus, false))
_, err = dao.UpdateEntity(db, msgStatus)
return nil, err
}, msgStatusList)
tasksch.ManageTask(rootTask).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
} else {
hint = rootTask.ID
}
return "", err
}
func ReadStoreMessage(ctx *jxcontext.Context, msgID, msgStatusID int) (redirectURL string, err error) {
msgStatus := &model.MessageStatus{}
msgStatus.ID = msgStatusID

View File

@@ -1,14 +1 @@
package cms
import (
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
)
func TestSendStoreMessage(t *testing.T) {
_, err := SendStoreMessage(jxcontext.AdminCtx, "title", "content", []int{1}, false, true)
if err != nil {
t.Fatal(err)
}
}

View File

@@ -730,7 +730,7 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
store.Name = valid["name"].(string)
syncStatus |= model.SyncFlagStoreName
}
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
printerVendorID := int(utils.Interface2Int64WithDefault(valid["printerVendorID"], 0))
if printerVendorID == 0 {
printerVendorID = store.PrinterVendorID
@@ -775,6 +775,13 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
handler.UnregisterPrinter(ctx, store.PrinterSN, store.PrinterKey)
}
}
if linkStoreID, ok := valid["linkStoreID"].(int); ok {
linkStoreID, err = getRealLinkStoreID(linkStoreID)
if err != nil {
return 0, err
}
valid["linkStoreID"] = linkStoreID
}
for _, v := range []string{
"lng",
@@ -1010,6 +1017,12 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
return 0, err
}
}
realLinkStoreID, err := getRealLinkStoreID(storeExt.LinkStoreID)
if err != nil {
return 0, err
}
storeExt.LinkStoreID = realLinkStoreID
existingID := store.ID
store.Lng = jxutils.StandardCoordinate2Int(storeExt.FloatLng)
store.Lat = jxutils.StandardCoordinate2Int(storeExt.FloatLat)
@@ -1048,6 +1061,21 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
return 0, err
}
func getRealLinkStoreID(linkStoreID int) (realLinkStoreID int, err error) {
if linkStoreID != 0 {
store := &model.Store{}
store.ID = linkStoreID
if err = dao.GetEntity(dao.GetDB(), store); err == nil {
if store.LinkStoreID != 0 {
realLinkStoreID = store.LinkStoreID
} else {
realLinkStoreID = linkStoreID
}
}
}
return realLinkStoreID, err
}
func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*model.StoreMap, err error) {
cond := map[string]interface{}{
model.FieldStoreID: storeID,

View File

@@ -52,18 +52,7 @@ func SendSMSMsg(mobileList []string, signName, templateCode string, templatePara
}
func getOrderNotifyPhone(order *model.GoodsOrder) (phoneList []string) {
store := &model.Store{}
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
if err := dao.GetEntity(dao.GetDB(), store); err == nil {
if store.SMSNotify != 0 {
for _, v := range []string{store.Tel1, store.Tel2} {
if v != "" {
phoneList = append(phoneList, v)
}
}
}
}
return phoneList
return dao.GetOrderNotifyPhones(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order))
}
func NotifyNewOrder(order *model.GoodsOrder) (err error) {

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -30,8 +31,8 @@ const (
WX_MINI_TO_ORDER_PAGE_URL = "pages/order-manager/main"
WX_MINI_TO_STORE_SKU_PAGE_URL = "pages/goods-manager/main"
WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL = "pages/store-comment/main"
WX_MINI_TO_SHOW_MSG = "pages/msg-page/main?msgID=%d&msgStatusID=%d"
WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL = "pages/pagesStore/store-comment/main"
WX_MINI_TO_SHOW_MSG = "pages/pagesStore/msg-page/main?msgID=%d&msgStatusID=%d"
//新订单模板消息文字颜色
WX_NEW_ORDER_TEMPLATE_COLOR = "#173177"
@@ -54,7 +55,7 @@ const (
WX_SALE_BILL_TEMPLATE_ID = "eTUuFZMWH7IsVBfcxNMpmaHYaxRkUaD6zG8wSGJDcic"
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "UlLvTMXDPIX9Ztyu3MMb84Zu-cCFo7trvQI8YRrAFjc" //"7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
// WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
// WX_CHANGE_REJECTED_TEMPLATE_ID = "tn2QXWi4HtSIwaztmtN6Bb2uzNL-jBxWltCZTDNJuYE"
WX_ORDER_APPLY_CANCEL_TEMPLATE_ID = "e6urTtcm4PL0rgDMG_1qWNOwrE3Qxqcm_dx0kWWCmEI"
@@ -69,7 +70,7 @@ const (
)
var (
venderColors = map[int]string{
VendorColors = map[int]string{
model.VendorIDJD: WX_TEMPLATE_VENDERCOLOR_JDDJ,
model.VendorIDMTWM: WX_TEMPLATE_VENDERCOLOR_MT,
model.VendorIDELM: WX_TEMPLATE_VENDERCOLOR_ELM,
@@ -92,33 +93,6 @@ var (
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
db := dao.GetDB()
openIDMap := make(map[string]int)
// if !globals.DisableWXAuth1 {
// var openIDList []string
// sql := `
// SELECT openid
// FROM weixins t1
// JOIN
// (SELECT id
// FROM weixins
// WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
// WHERE openid IS NOT NULL
// UNION
// SELECT openid
// FROM weixins
// WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL`
// sqlParams := []interface{}{
// storeID,
// storeID,
// }
// err := dao.GetRows(db, &openIDList, sql, sqlParams...)
// if err != nil || len(openIDList) == 0 {
// globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, len(openIDList), err)
// return retVal
// }
// for _, v := range openIDList {
// openIDMap[v] = 1
// }
// }
if globals.EnableWXAuth2 {
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewStoreBossRole(storeID)); err2 == nil {
for _, v := range userIDList {
@@ -147,7 +121,7 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
func SendMsgToStore(storeID int, templateID, downloadURL, miniPageURL string, data interface{}) (err error) {
globals.SugarLogger.Debugf("SendMsgToStore storeID:%d, templateID:%s, downloadURL:%s, miniPageURL:%s", storeID, templateID, downloadURL, miniPageURL)
if storeID == 0 { // 测试,只发给我
//SmartMessageTemplateSend("oYN_usk0AeGc_C6VEZfmFQP5VHMQ", templateID, downloadURL, miniPageURL, data)
// SmartMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", templateID, downloadURL, miniPageURL, data)
} else {
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
successCount := 0
@@ -233,7 +207,7 @@ func NotifyNewOrder(order *model.GoodsOrder) (err error) {
},
"orderType": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单", model.VendorChineseNames[order.VendorID], order.OrderSeq),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"customerName": map[string]interface{}{
"value": order.ConsigneeName,
@@ -283,7 +257,7 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder, isBillAlr
} else if bill.WaybillVendorID == model.VendorIDDada {
templateID = WX_DADA_DELIVERY_DONE_TEMPLATE_ID
}
titleColor = venderColors[bill.OrderVendorID]
titleColor = VendorColors[bill.OrderVendorID]
title = fmt.Sprintf("%s 第%d号订单的配送完成", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq)
}
if templateID != "" {
@@ -333,7 +307,7 @@ func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err er
},
"keyword1": map[string]interface{}{ // 订单编号
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"keyword2": map[string]interface{}{ // 订单日期
"value": utils.Time2Str(order.OrderCreatedAt),
@@ -384,7 +358,7 @@ func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
},
"orderName": map[string]interface{}{
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": order.ConsigneeMobile,
@@ -546,11 +520,7 @@ func NotifyStoreMessage(storeID, msgID, msgStatusID int, title, content string)
"color": "#2E408E",
},
"keyword2": map[string]interface{}{
"value": "无",
"color": "#2E408E",
},
"keyword3": map[string]interface{}{
"value": "无",
"value": utils.GetCurTimeStr(),
"color": "#2E408E",
},
"remark": map[string]interface{}{
@@ -596,7 +566,7 @@ func NotifyAfsOrderStatus(afsOrder *model.AfsOrder) (err error) {
},
"keyword3": map[string]interface{}{
"value": utils.Time2Str(afsOrder.AfsCreatedAt),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": comment,
@@ -690,3 +660,61 @@ func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err
}
return err
}
func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
msg := &model.Message{
Title: title,
Content: content,
Type: model.MessageTypeStore,
}
dao.WrapAddIDCULDEntity(msg, ctx.GetUserName())
if err = dao.CreateEntity(db, msg); err != nil {
dao.Rollback(db)
return "", err
}
msgStatusList := make([]*model.MessageStatus, len(storeIDs))
for k, storeID := range storeIDs {
msgStatus := &model.MessageStatus{
MessageID: msg.ID,
StoreID: storeID,
Status: model.MessageStatusNew,
}
dao.WrapAddIDCULDEntity(msgStatus, ctx.GetUserName())
if err = dao.CreateEntity(db, msgStatus); err != nil {
dao.Rollback(db)
return "", err
}
msgStatusList[k] = msgStatus
}
dao.Commit(db)
rootTask := tasksch.NewParallelTask("SendStoreMessage", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
db := dao.GetDB()
msgStatus := batchItemList[0].(*model.MessageStatus)
if err = NotifyStoreMessage(msgStatus.StoreID, msgStatus.MessageID, msgStatus.ID, msg.Title, msg.Content); err == nil {
msgStatus.Status = model.MessageStatusSendAllSuccess
} else {
msgStatus.Status = model.MessageStatusSendAllFailed
}
dao.WrapUpdateULEntity(msgStatus, ctx.GetUserName())
globals.SugarLogger.Debug(utils.Format4Output(msgStatus, false))
_, err = dao.UpdateEntity(db, msgStatus)
return nil, err
}, msgStatusList)
tasksch.ManageTask(rootTask).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
} else {
hint = rootTask.ID
}
return "", err
}

View File

@@ -3,6 +3,7 @@ package weixinmsg
import (
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/globals/api2"
"git.rosy.net.cn/baseapi/utils"
@@ -18,3 +19,10 @@ func TestGetWeixinOpenIDsFromStoreID(t *testing.T) {
openIDs := GetWeixinOpenIDsFromStoreID(100118)
t.Log(utils.Format4Output(openIDs, false))
}
func TestSendStoreMessage(t *testing.T) {
_, err := SendStoreMessage(jxcontext.AdminCtx, "title", "content", []int{1}, false, true)
if err != nil {
t.Fatal(err)
}
}

View File

@@ -5,6 +5,7 @@ import (
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals"
)
@@ -664,3 +665,20 @@ func SetStoreMapSyncStatus(db *DaoDB, vendorIDs, storeIDs []int, syncStatus int)
}
return ExecuteSQL(db, sql, sqlParams...)
}
func GetOrderNotifyPhones(db *DaoDB, storeID int) (phoneList []string) {
store := &model.Store{}
store.ID = storeID
if err := GetEntity(db, store); err == nil {
if store.SMSNotify != 0 {
telMap := make(map[string]int)
for _, v := range []string{store.Tel1, store.Tel2} {
if v != "" {
telMap[v] = 1
}
}
phoneList = jxutils.StringMap2List(telMap)
}
}
return phoneList
}

View File

@@ -272,10 +272,11 @@ type Store struct {
DeliveryRangeType int8 `json:"deliveryRangeType"` // 参见相关常量定义
DeliveryRange string `orm:"type(text)" json:"deliveryRange"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon则为逗号分隔坐标分号分隔的坐标点坐标与Lng和Lat一样都是整数比如 121361504,31189308;121420555,31150238。否则为半径单位为米
Status int `json:"status"`
AutoEnableAt *time.Time `orm:"type(datetime);null" json:"autoEnableAt"` // 自动营业时间(临时休息用)
ChangePriceType int8 `json:"changePriceType"` // 修改价格类型,即是否需要审核
SMSNotify int8 `orm:"column(sms_notify);" json:"smsNotify"` // 是否通过短信接收订单消息
AutoReplyType int8 `json:"autoReplyType"` // 订单评价自动回复类型
AutoEnableAt *time.Time `orm:"type(datetime);null" json:"autoEnableAt"` // 自动营业时间(临时休息用)
ChangePriceType int8 `json:"changePriceType"` // 修改价格类型,即是否需要审核
SMSNotify int8 `orm:"column(sms_notify);" json:"smsNotify"` // 是否通过短信接收订单消息
AutoReplyType int8 `json:"autoReplyType"` // 订单评价自动回复类型
LinkStoreID int `orm:"column(link_store_id);default(0)" json:"linkStoreID"` // 关联门店ID
PrinterDisabled int8 `orm:"default(0)" json:"printerDisabled"` // 是否禁用网络打印机
PrinterFontSize int8 `orm:"default(0)" json:"printerFontSize"` // 打印字体-10正常1

View File

@@ -217,7 +217,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
}
}
freightParams.IsFullFree = len(freightParams.FreeFreightInfoList) > 0
globals.SugarLogger.Debug(utils.Format4Output(freightParams, false))
// globals.SugarLogger.Debug(utils.Format4Output(freightParams, false))
if globals.EnableJdStoreWrite {
errList.AddErr(a.UpdateStoreFreightConfigNew(freightParams))
}

View File

@@ -6,6 +6,7 @@ import (
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
"git.rosy.net.cn/jx-callback/business/model"
"github.com/astaxie/beego"
)
@@ -31,7 +32,7 @@ func (c *MsgController) SendStoreMessage() {
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err != nil {
return retVal, "", err
}
retVal, err = cms.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, params.IsAsync, params.IsContinueWhenError)
retVal, err = weixinmsg.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, params.IsAsync, params.IsContinueWhenError)
return retVal, "", err
})
}

View File

@@ -5,8 +5,10 @@ import (
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego"
)
@@ -16,25 +18,21 @@ type Djsw2Controller struct {
}
func (c *Djsw2Controller) handleMsg(handler func(*jdapi.API, interface{}) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) {
// callbackMsg, mapData, callbackResponse := jdapi.GetCallbackMsg(getUsefulRequest(c.Ctx))
// globals.SugarLogger.Debug(utils.Format4Output(callbackMsg, true))
// if callbackResponse == nil {
// if jdAPI := jd.GetAPI(jd.AppKey2OrgCode(callbackMsg.AppKey)); jdAPI != nil {
// if callbackResponse = jdAPI.CheckCallbackValidation(mapData, callbackMsg.Sign); callbackResponse == nil {
// callbackResponse = handler(jdAPI, callbackMsg.Param)
// }
// } else {
// callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的appKey,非法请求"), "")
// }
// }
callbackMsg, _, callbackResponse := jdapi.GetCallbackMsg(getUsefulRequest(c.Ctx))
globals.SugarLogger.Debug(utils.Format4Output(callbackMsg, true))
if callbackResponse == nil {
callbackResponse = handler(api.FakeJdAPI, callbackMsg.Param)
}
return callbackResponse
}
func (c *Djsw2Controller) orderStatus() {
if c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
callbackResponse = jd.OnOrderMsg(obj.(*jdapi.CallbackOrderMsg))
return callbackResponse
if orderMsg, ok := obj.(*jdapi.CallbackOrderMsg); ok {
orderman.FixedOrderManager.OnNewFakeJdOrder(orderMsg.BillID)
}
return nil
})
c.Data["json"] = c.transferResponse("orderStatus", callbackResponse)
c.ServeJSON()
@@ -48,43 +46,43 @@ func (c *Djsw2Controller) NewOrder() {
}
func (c *Djsw2Controller) OrderAdjust() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) OrderWaitOutStore() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) PickFinishOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) DeliveryOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) FinishOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) LockOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) UnlockOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) UserCancelOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) ApplyCancelOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) VenderAuditApplyCancelOrder() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) PushDeliveryStatus() {
@@ -101,7 +99,7 @@ func (c *Djsw2Controller) PushDeliveryStatus() {
}
func (c *Djsw2Controller) OrderCommentPush() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) Token() {
@@ -114,42 +112,15 @@ func (c *Djsw2Controller) Token() {
}
func (c *Djsw2Controller) StockIsHave() {
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
if c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
return callbackResponse
})
c.Data["json"] = c.transferResponse("StockIsHave", callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
c.nullOperation()
}
func (c *Djsw2Controller) SinglePromoteCreate() {
if c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
callbackResponse = jd.OnActMsg(obj.(*jdapi.CallbackOrderMsg))
return callbackResponse
})
c.Data["json"] = c.transferResponse("SinglePromoteCreate", callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
c.nullOperation()
}
func (c *Djsw2Controller) StoreCrud() {
if c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) {
callbackResponse = jd.OnStoreMsg(obj.(*jdapi.CallbackOrderMsg))
return callbackResponse
})
c.Data["json"] = c.transferResponse("StoreCrud", callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
c.nullOperation()
}
func (c *Djsw2Controller) transferResponse(funcName string, inCallbackResponse *jdapi.CallbackResponse) (outCallbackResponse *jdapi.CallbackResponse) {
@@ -188,11 +159,11 @@ func (c *Djsw2Controller) NewAfterSaleBill() {
}
func (c *Djsw2Controller) AfterSaleBillStatus() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) OrderAccounting() {
c.orderStatus()
c.nullOperation()
}
func (c *Djsw2Controller) nullOperation() {
@@ -205,5 +176,5 @@ func (c *Djsw2Controller) UpdateSku() {
}
func (c *Djsw2Controller) OrderAddTips() {
c.orderStatus()
c.nullOperation()
}