Browse Source

修改消息推送方式

rdluck 3 years ago
parent
commit
200901044d
5 changed files with 69 additions and 167 deletions
  1. 7 22
      controllers/sms.go
  2. 22 5
      models/sms_record.go
  3. 38 0
      services/sms_send.go
  4. 2 137
      utils/constants.go
  5. 0 3
      utils/email.go

+ 7 - 22
controllers/sms.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"hongze/hongze_robot/models"
+	"hongze/hongze_robot/services"
 	"hongze/hongze_robot/utils"
 	"strconv"
 	"time"
@@ -44,33 +45,16 @@ func (this *SmsController) SmsSend() {
 	}
 	//判断记录是否存在
 	if count <= 0 {
-		var dingToken = []string{"5f9ae772343b20af806e1f8a6c27a3d8c1b57d8c36f468ab0a12d7eca1cf423c"}
-		var smsDateTime string
+		var tm time.Time
 		if date != "" {
 			smsDateInt64, _ := strconv.ParseInt(date, 10, 64)
-			tm := time.Unix(smsDateInt64/1e3, 0)
-			smsDateTime = tm.Format(utils.FormatDateTime)
-		}
-
-		if smsDateTime == "" {
-			smsDateTime = date
-		}
-		msg := []string{
-			"### " + address,
-			"---",
-			"- <font color=#00ff00 size=6>" + body + "</font>",
-			"- " + smsDateTime,
-		}
-		cli := dingtalk.InitDingTalk(dingToken, "hongze")
-		//cli.SendTextMessage("content", dingtalk.WithAtAll())
-		err = cli.SendMarkDownMessageBySlice("华瑞信息", msg)
-		if err != nil {
-			br.Msg = "失败,请联系技术"
-			br.ErrMsg = "发送钉钉消息失败;Err:" + err.Error()
-			return
+			tm = time.Unix(smsDateInt64/1e3, 0)
 		}
 		record := new(models.SmsRecord)
 		record.CreateTime = time.Now()
+		record.ModifyTime = time.Now()
+		record.IsSend = 0
+		record.SmsDateTime = tm
 		record.Mobile = address
 		record.SmsDate = date
 		record.Body = body
@@ -81,6 +65,7 @@ func (this *SmsController) SmsSend() {
 			return
 		}
 	}
+	go services.SendSms()
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "发送成功"

+ 22 - 5
models/sms_record.go

@@ -6,11 +6,14 @@ import (
 )
 
 type SmsRecord struct {
-	Id         int `orm:"column(id);pk"`
-	Body       string
-	Mobile     string
-	SmsDate    string
-	CreateTime time.Time
+	Id          int `orm:"column(id);pk"`
+	Body        string
+	Mobile      string
+	SmsDate     string
+	IsSend      int
+	CreateTime  time.Time
+	ModifyTime  time.Time
+	SmsDateTime time.Time
 }
 
 //新增视频
@@ -28,3 +31,17 @@ func GetSmsRecordCount(mobile, smsDate string) (count int, err error) {
 	err = o.Raw(sql, mobile, smsDate).QueryRow(&count)
 	return
 }
+
+func ModifySmsRecordIsSend(mobile, smsDate string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE sms_record SET is_send=1,modify_time=NOW() WHERE mobile=? AND sms_date=? `
+	_, err = o.Raw(sql, mobile, smsDate).Exec()
+	return
+}
+
+func GetSmsRecord() (items []*SmsRecord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM  sms_record  WHERE is_send=0 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 38 - 0
services/sms_send.go

@@ -0,0 +1,38 @@
+package services
+
+import (
+	"github.com/blinkbean/dingtalk"
+	"hongze/hongze_robot/models"
+	"hongze/hongze_robot/utils"
+	"time"
+)
+
+func SendSms() {
+	time.Sleep(time.Second)
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "SendSms Err:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	items, err := models.GetSmsRecord()
+	if err != nil {
+		return
+	}
+	var dingToken = []string{"5f9ae772343b20af806e1f8a6c27a3d8c1b57d8c36f468ab0a12d7eca1cf423c"}
+	for _, v := range items {
+		smsDateTime := v.SmsDateTime.Format(utils.FormatDateTime)
+		msg := []string{
+			"### " + v.Mobile,
+			"---",
+			"- <font color=#00ff00 size=6>" + v.Body + "</font>",
+			"- " + smsDateTime,
+		}
+		cli := dingtalk.InitDingTalk(dingToken, "hongze")
+		//cli.SendTextMessage("content", dingtalk.WithAtAll())
+		err = cli.SendMarkDownMessageBySlice("华瑞信息", msg)
+		if err != nil {
+			return
+		}
+	}
+}

+ 2 - 137
utils/constants.go

@@ -19,141 +19,6 @@ const (
 )
 
 const (
-	APPNAME          = "弘则-日度点评-管理后台"
+	APPNAME          = "弘则-短信机器人"
 	EmailSendToUsers = "glji@hzinsights.com;pyan@hzinsights.com"
-)
-
-//手机号,电子邮箱正则
-const (
-	RegularMobile = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
-	RegularEmail  = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
-)
-
-//验证码code
-const (
-	REGISTER_CODE = iota + 1 //注册
-	LOGIN_CODE               //登录
-)
-
-//聚合短信
-var (
-	JhGnTplId  = "65692"                            //聚合国内模板编码
-	JhGjTplId  = "10054"                            //聚合国内模板编码
-	JhGnAppKey = "4c8504c49dd335e99cfd7b6a3a9e2415" //聚合国内AppKey
-	JhGjAppKey = "3326ad2c1047a4cd92ace153e6044ca3"
-)
-
-//科大讯飞--语音合成
-const (
-	XfSTATUS_FIRST_FRAME    = 0 //第一帧标识
-	XfSTATUS_CONTINUE_FRAME = 1 //中间帧标识
-	XfSTATUS_LAST_FRAME     = 2 //最后一帧标识
-	XfAPPID                 = "5ed70e9d"
-	XfAPIKey                = "d580509ca262e9586fb65a7064d5ce77"
-	XfAPISecret             = "a085720dc55850c720fa5576335f847a"
-	XfHostUrl               = "wss://tts-api.xfyun.cn/v2/tts"
-	XfOrigin                = "http://tts-api.xfyun.cn/"
-	XfHost                  = "tts-api.xfyun.cn"
-	XfMaxFontSize           = 8000
-	XfVcn                   = "x2_chaoge" //发言人
-)
-
-//OSS
-/*var (
-	Endpoint   string = "oss-cn-shanghai.aliyuncs.com"
-	Bucketname string = "hongze"
-
-	Imghost          string = "http://hongze.oss-cn-shanghai.aliyuncs.com/"
-	Upload_dir       string = "static/images/"
-	Upload_Audio_Dir string = "static/audio/"
-
-	AccessKeyId     string = "LTAIFMZYQhS2BTvW"
-	AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
-)
-*/
-
-//baidu
-const (
-	BdAppID     = "23047694"
-	BdApiKey    = "RlisEen1Imd8haXx5Tqirstd"
-	BdSecretKey = "tT75bhMW5UlmoA0flyQsjgurZzSWfuB9"
-)
-
-//客户状态
-const (
-	COMPANY_STATUS_TRY_OUT       = "试用"
-	COMPANY_STATUS_FOREVER       = "永续"
-	COMPANY_STATUS_FREEZE        = "冻结"
-	COMPANY_STATUS_LOSE          = "流失"
-	COMPANY_STATUS_FORMAL        = "正式"
-	COMPANY_STATUS_POTENTIAL     = "潜在"
-	COMPANY_STATUS_TRY_OUT_COUNT = 30
-
-	COMPANY_APPROVE_STATUS = "待审批"
-)
-
-//管理员,ficc管理员,ficc销售,权益管理员,权益销售。
-//角色类型/类型编码
-const (
-	ROLE_TYPE_ADMIN       = "管理员"
-	ROLE_TYPE_FICC_ADMIN  = "ficc管理员"
-	ROLE_TYPE_FICC_SELLER = "ficc销售"
-	ROLE_TYPE_RAI_ADMIN   = "权益管理员"
-	ROLE_TYPE_RAI_SELLER  = "权益销售"
-
-	ROLE_TYPE_FICC_GROUP      = "ficc组长"
-	ROLE_TYPE_RAI_GROUP       = "权益组长"
-	ROLE_TYPE_FICC_DEPARTMENT = "ficc部门经理"
-	ROLE_TYPE_RAI_DEPARTMENT  = "权益部门经理"
-	ROLE_TYPE_FICC_RESEARCHR  = "ficc研究员"
-	ROLE_TYPE_RAI_RESEARCHR   = "权益研究员"
-
-	ROLE_TYPE_CODE_ADMIN           = "admin"           //管理员
-	ROLE_TYPE_CODE_FICC_ADMIN      = "ficc_admin"      //ficc管理员
-	ROLE_TYPE_CODE_FICC_SELLER     = "ficc_seller"     //ficc销售
-	ROLE_TYPE_CODE_RAI_ADMIN       = "rai_admin"       //权益管理员
-	ROLE_TYPE_CODE_RAI_SELLER      = "rai_seller"      //权益销售
-	ROLE_TYPE_CODE_FICC_GROUP      = "ficc_group"      //ficc组长
-	ROLE_TYPE_CODE_RAI_GROUP       = "rai_group"       //ficc组长
-	ROLE_TYPE_CODE_FICC_DEPARTMENT = "ficc_department" //ficc部门经理
-	ROLE_TYPE_CODE_RAI_DEPARTMENT  = "rai_department"  //权益部门经理
-	ROLE_TYPE_CODE_FICC_RESEARCHR  = "ficc_researcher" //ficc研究员
-	ROLE_TYPE_CODE_RAI_RESEARCHR   = "rai_researcher"  //权益研究员
-
-	ROLE_TYPE_SELLERS = "'ficc_admin','ficc_seller','rai_admin','rai_seller','ficc_group','rai_group','ficc_department','rai_department'"
-)
-
-//客户类型
-const (
-	COMPANY_CLASSIFY_FICC    = "ficc"
-	COMPANY_CLASSIFY_RAI     = "权益"
-	COMPANY_CLASSIFY_PARTNER = "合作伙伴"
-)
-
-const (
-	COMPANY_PRODUCT_FICC_ID   = 1
-	COMPANY_PRODUCT_FICC_NAME = "ficc"
-	COMPANY_PRODUCT_RAI_ID    = 2
-	COMPANY_PRODUCT_RAI_NAME  = "权益"
-)
-
-var PermissionFiccClassifyArr = [...]string{"宏观经济", "化工产业", "黑色产业", "有色产业"}
-var PermissionAllClassifyArr = [...]string{"宏观经济", "化工产业", "黑色产业", "有色产业", "权益"}
-
-//apply_method:申请类型:1:试用->正式,2:冻结—>试用,3:流失—>正式,4:试用延期,5:原销售申请领取流失客户,6:正式客户申请服务更新
-
-//数据来源渠道
-const (
-	DATA_SOURCE_THS  = iota + 1 //同花顺
-	DATA_SOURCE_WIND            //wind
-)
-
-//数据缓存
-const (
-	CATCH_EDB_DATA = "EDB_DATA_"
-)
-
-const (
-	DATA_PREFIX="hz_data"
-)
-
+)

+ 0 - 3
utils/email.go

@@ -7,9 +7,6 @@ import (
 
 //发送邮件
 func SendEmail(title, content string, touser string)bool {
-	if RunMode == "debug" {
-		return false
-	}
 	var arr []string
 	sub := strings.Index(touser, ";")
 	if sub >= 0 {