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/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 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 = cms.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, 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 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 []int var timeList []time.Time if err = jxutils.Strings2Objs(params.MsgIDs, &msgIDs, params.StoreIDs, &storeIDs); 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, params.FromReadCount, params.ToReadCount, timeList[0], timeList[1], params.Keyword, params.Offset, params.PageSize) return retVal, "", err }) }