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

+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

@@ -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,