|
@@ -0,0 +1,97 @@
|
|
|
+package util
|
|
|
+
|
|
|
+import (
|
|
|
+ . "config"
|
|
|
+ "errors"
|
|
|
+ "log"
|
|
|
+ . "qfw/util/rpc"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+type WxTplMsgCustom struct {
|
|
|
+}
|
|
|
+
|
|
|
+/* 获取自定义模板消息
|
|
|
+ * @Param mysql 数据库实例
|
|
|
+ * @Param tplId 模板消息id
|
|
|
+ * @Param sceneCode 场景代码
|
|
|
+ */
|
|
|
+func (w *WxTplMsgCustom) Get(tplId string, sceneCode ...string) map[string]*TmplItem {
|
|
|
+ param := []interface{}{tplId}
|
|
|
+ wh := []string{}
|
|
|
+ for _, v := range sceneCode {
|
|
|
+ param = append(param, v)
|
|
|
+ wh = append(wh, "?")
|
|
|
+ }
|
|
|
+ list := Mysql.SelectBySql(`select firstdata,sceneCode from scene a
|
|
|
+ inner join template_message b on (a.templateId=b.id and b.id=? and a.sceneCode in (`+strings.Join(wh, ",")+`) and a.state=1 and b.isTest=1)`, param...)
|
|
|
+ m := map[string]*TmplItem{}
|
|
|
+ if list != nil {
|
|
|
+ for _, v := range *list {
|
|
|
+ sceneCode, _ := v["sceneCode"].(string)
|
|
|
+ sceneCode = strings.TrimSpace(sceneCode)
|
|
|
+ //
|
|
|
+ firstdata, _ := v["firstdata"].(string)
|
|
|
+ firstdata = strings.TrimSpace(firstdata)
|
|
|
+ //
|
|
|
+ m[sceneCode] = &TmplItem{
|
|
|
+ Value: firstdata,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return m
|
|
|
+}
|
|
|
+
|
|
|
+//超级订阅试用即将到期、超级订阅试用已到期、超级订阅即将到期、超级订阅已到期
|
|
|
+func (w *WxTplMsgCustom) Expired() error {
|
|
|
+ //试用-微信模板消息自定义
|
|
|
+ onTrial_WxTplMsg := w.Get(MessageConfig.WxTpl_OnTrial_SoonExpire.Id, WxTpl_OnTrial_SoonExpire_SceneCode, WxTpl_OnTrial_Expired_SceneCode)
|
|
|
+ //试用-即将到期
|
|
|
+ if onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode] == nil {
|
|
|
+ return errors.New("试用-即将到期,没有找到微信模板消息")
|
|
|
+ } else if onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value == "" {
|
|
|
+ return errors.New("试用-即将到期,微信模板消息first_data为空")
|
|
|
+ }
|
|
|
+ MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value = onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value
|
|
|
+ log.Println("试用-即将到期,微信模板消息first_data", onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value)
|
|
|
+ //试用-已到期
|
|
|
+ if onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode] == nil {
|
|
|
+ return errors.New("试用-已到期,没有找到微信模板消息")
|
|
|
+ } else if onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value == "" {
|
|
|
+ return errors.New("试用-已到期,微信模板消息first_data为空")
|
|
|
+ }
|
|
|
+ MessageConfig.WxTpl_OnTrial_Expired.First.Value = onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value
|
|
|
+ log.Println("试用-已到期,微信模板消息first_data", onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value)
|
|
|
+ //购买-微信模板消息自定义
|
|
|
+ wxTplMsg := w.Get(MessageConfig.WxTpl_Expired.Id, WxTpl_SoonExpire_SceneCode, WxTpl_Expired_SceneCode)
|
|
|
+ //即将到期
|
|
|
+ if wxTplMsg[WxTpl_SoonExpire_SceneCode] == nil {
|
|
|
+ return errors.New("即将到期,没有找到微信模板消息")
|
|
|
+ } else if wxTplMsg[WxTpl_SoonExpire_SceneCode].Value == "" {
|
|
|
+ return errors.New("即将到期,微信模板消息first_data为空")
|
|
|
+ }
|
|
|
+ MessageConfig.WxTpl_SoonExpire.First.Value = wxTplMsg[WxTpl_SoonExpire_SceneCode].Value
|
|
|
+ log.Println("即将到期,微信模板消息first_data", wxTplMsg[WxTpl_SoonExpire_SceneCode].Value)
|
|
|
+ //已到期
|
|
|
+ if wxTplMsg[WxTpl_Expired_SceneCode] == nil {
|
|
|
+ return errors.New("已到期,没有找到微信模板消息")
|
|
|
+ } else if wxTplMsg[WxTpl_Expired_SceneCode].Value == "" {
|
|
|
+ return errors.New("已到期,微信模板消息first_data为空")
|
|
|
+ }
|
|
|
+ MessageConfig.WxTpl_Expired.First.Value = wxTplMsg[WxTpl_Expired_SceneCode].Value
|
|
|
+ log.Println("已到期,微信模板消息first_data", wxTplMsg[WxTpl_Expired_SceneCode].Value)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//数据报告
|
|
|
+func (w *WxTplMsgCustom) DataReport() error {
|
|
|
+ wxTplMsg := w.Get(MessageConfig.WxTpl_DataReport.Id, WxTpl_DataReport_SceneCode)
|
|
|
+ if wxTplMsg[WxTpl_DataReport_SceneCode] == nil {
|
|
|
+ return errors.New("数据报告,没有找到微信模板消息")
|
|
|
+ } else if wxTplMsg[WxTpl_DataReport_SceneCode].Value == "" {
|
|
|
+ return errors.New("数据报告,微信模板消息first_data为空")
|
|
|
+ }
|
|
|
+ MessageConfig.WxTpl_DataReport.First.Value = wxTplMsg[WxTpl_DataReport_SceneCode].Value
|
|
|
+ log.Println("微信模板消息first_data", wxTplMsg[WxTpl_DataReport_SceneCode].Value)
|
|
|
+ return nil
|
|
|
+}
|