Files
jx-callback/controllers/cms_msg.go
苏尹岚 47d4a11d1d aa
2021-02-24 10:06:55 +08:00

158 lines
7.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package controllers
import (
"net/http"
"time"
"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"
)
type MsgController struct {
beego.Controller
}
// @Title 发送微信消息
// @Description 发送微信消息
// @Param token header string true "认证token"
// @Param storeIDs formData string true "门店 ID列表"
// @Param title formData string true "消息标题"
// @Param content formData string true "消息内容"
// @Param messageType formData int true "消息类型1为普通给商家发的消息3为活动内容通知"
// @Param actInfo formData string false "如果是活动内容通知需传"
// @Param isAsync formData bool false "是否异步操作,缺省否"
// @Param isContinueWhenError formData bool false "单个失败是否继续缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SendStoreMessage [post]
func (c *MsgController) SendStoreMessage() {
c.callSendStoreMessage(func(params *tMsgSendStoreMessageParams) (retVal interface{}, errCode string, err error) {
var storeIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err != nil {
return retVal, "", err
}
retVal, err = weixinmsg.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, params.ActInfo, params.MessageType, params.IsAsync, params.IsContinueWhenError)
return retVal, "", err
})
}
// @Title 发送用户微信消息
// @Description 发送用户微信消息
// @Param token header string true "认证token"
// @Param userIDs formData string true "用户 ID列表"
// @Param title formData string true "消息标题"
// @Param content formData string true "消息内容"
// @Param isAsync formData bool false "是否异步操作,缺省否"
// @Param isContinueWhenError formData bool false "单个失败是否继续缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SendUserMessage [post]
func (c *MsgController) SendUserMessage() {
c.callSendUserMessage(func(params *tMsgSendUserMessageParams) (retVal interface{}, errCode string, err error) {
var userIDs []string
if err = jxutils.Strings2Objs(params.UserIDs, &userIDs); err != nil {
return retVal, "", err
}
retVal, err = weixinmsg.SendUserMessage(params.Ctx, params.Title, params.Content, userIDs, params.IsAsync, params.IsContinueWhenError)
return retVal, "", err
})
}
// @Title 门店读微信消息
// @Description 门店读微信消息此API是自动调用的
// @Param token header string true "认证token"
// @Param msgID formData int true "消息ID"
// @Param msgStatusID formData int true "消息状态ID"
// @Param redirectURL formData string false "重定向URL"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ReadStoreMessage [put]
func (c *MsgController) ReadStoreMessage() {
redirectURL := ""
c.callReadStoreMessage(func(params *tMsgReadStoreMessageParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.ReadStoreMessage(params.Ctx, params.MsgID, params.MsgStatusID)
retRedirectURL := retVal.(string)
if retRedirectURL != "" {
redirectURL = retRedirectURL
} else {
redirectURL = params.RedirectURL
}
if redirectURL != "" {
errCode = model.ErrorCodeIgnore
}
return retVal, errCode, err
})
if redirectURL != "" {
c.Redirect(redirectURL, http.StatusTemporaryRedirect)
}
}
// @Title 得到发送的微信消息列表
// @Description 得到发送的微信消息列表
// @Param token header string true "认证token"
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
// @Param msgIDs query string false "msg IDs列表"
// @Param storeIDs query string false "门店 ID列表"
// @Param types query string false "类型列表,当前只有一个类型,写死[1]"
// @Param fromTime query string false "创建起始时间"
// @Param toTime query string false "创建结束时间"
// @Param offset query int false "门店列表起始序号以0开始缺省为0"
// @Param pageSize query int false "门店列表页大小缺省为50-1表示全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStoreMessages [get]
func (c *MsgController) GetStoreMessages() {
c.callGetStoreMessages(func(params *tMsgGetStoreMessagesParams) (retVal interface{}, errCode string, err error) {
var msgIDs, storeIDs, types []int
var timeList []time.Time
if err = jxutils.Strings2Objs(params.MsgIDs, &msgIDs, params.StoreIDs, &storeIDs, params.Types, &types); err != nil {
return retVal, "", err
}
if timeList, err = jxutils.BatchStr2Time(params.FromTime, params.ToTime); err != nil {
return retVal, "", err
}
retVal, err = cms.GetStoreMessages(params.Ctx, msgIDs, storeIDs, types, timeList[0], timeList[1], params.Keyword, params.Offset, params.PageSize)
return retVal, "", err
})
}
// @Title 得到发送的微信消息状态列表
// @Description 得到发送的微信消息状态列表
// @Param token header string true "认证token"
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
// @Param msgIDs query string false "msg IDs列表"
// @Param storeIDs query string false "门店 ID列表"
// @Param fromTime query string false "创建起始时间"
// @Param toTime query string false "创建结束时间"
// @Param confirmStatuss query string false "确认状态0表示没点1表示确认-1表示拒绝"
// @Param fromReadCount query int false "已读次数开始"
// @Param toReadCount query int false "已读次数结束"
// @Param offset query int false "消息状态列表起始序号以0开始缺省为0"
// @Param pageSize query int false "消息状态列表页大小缺省为50-1表示全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetStoreMessageStatuses [get]
func (c *MsgController) GetStoreMessageStatuses() {
c.callGetStoreMessageStatuses(func(params *tMsgGetStoreMessageStatusesParams) (retVal interface{}, errCode string, err error) {
var msgIDs, storeIDs, confirmStatuss []int
var timeList []time.Time
if err = jxutils.Strings2Objs(params.MsgIDs, &msgIDs, params.StoreIDs, &storeIDs, params.ConfirmStatuss, &confirmStatuss); err != nil {
return retVal, "", err
}
if timeList, err = jxutils.BatchStr2Time(params.FromTime, params.ToTime); err != nil {
return retVal, "", err
}
if _, ok := params.MapData["fromReadCount"]; !ok {
params.FromReadCount = -1
}
if _, ok := params.MapData["toReadCount"]; !ok {
params.ToReadCount = -1
}
retVal, err = cms.GetStoreMessageStatuses(params.Ctx, msgIDs, storeIDs, confirmStatuss, params.FromReadCount, params.ToReadCount, timeList[0], timeList[1], params.Keyword, params.Offset, params.PageSize)
return retVal, "", err
})
}