|
@@ -1,6 +1,7 @@
|
|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"hongze/hongze_robot/cache"
|
|
|
"hongze/hongze_robot/models"
|
|
|
"hongze/hongze_robot/services"
|
|
@@ -30,56 +31,62 @@ func (this *SmsController) SmsSend() {
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
- sign := this.GetString("Sign")
|
|
|
- address := this.GetString("Address")
|
|
|
- body := this.GetString("Body")
|
|
|
- name := this.GetString("Name")
|
|
|
- date := this.GetString("Date")
|
|
|
-
|
|
|
- utils.FileLog.Info("send msg: %s; %s; %s; %s; %s", sign, address, body, name, date)
|
|
|
- count, err := models.GetSmsRecordCount(address, date)
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- br.Msg = "失败,请联系技术"
|
|
|
- br.ErrMsg = "失败;Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- item, err := cache.GetSmsConfigByCache("mobile")
|
|
|
+ reqBody := this.Ctx.Input.RequestBody
|
|
|
+ utils.FileLog.Info("%s", string(reqBody))
|
|
|
+ req := make([]*models.SmsReq, 0)
|
|
|
+ err = json.Unmarshal(reqBody, &req)
|
|
|
if err != nil {
|
|
|
- br.Msg = "失败,请联系技术"
|
|
|
- br.ErrMsg = "获取配置信息失败;Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- if item.ConfigValue == "" {
|
|
|
- br.Msg = "失败,请联系技术"
|
|
|
- br.ErrMsg = "配置信息为空"
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- isAdd := false
|
|
|
-
|
|
|
- if count <= 0 && strings.Contains(item.ConfigValue, address) {
|
|
|
- var tm time.Time
|
|
|
- if date != "" {
|
|
|
- smsDateInt64, _ := strconv.ParseInt(date, 10, 64)
|
|
|
- tm = time.Unix(smsDateInt64/1e3, 0)
|
|
|
+
|
|
|
+ addList := make([]*models.SmsRecord, 0)
|
|
|
+ for _, v := range req {
|
|
|
+ count, err := models.GetSmsRecordCount(v.Address, v.Date)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "失败,请联系技术"
|
|
|
+ br.ErrMsg = "失败;Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, err := cache.GetSmsConfigByCache("mobile")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "失败,请联系技术"
|
|
|
+ br.ErrMsg = "获取配置信息失败;Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.ConfigValue == "" {
|
|
|
+ br.Msg = "失败,请联系技术"
|
|
|
+ br.ErrMsg = "配置信息为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if count <= 0 && strings.Contains(item.ConfigValue, v.Address) {
|
|
|
+ var tm time.Time
|
|
|
+ if v.Date != "" {
|
|
|
+ smsDateInt64, _ := strconv.ParseInt(v.Date, 10, 64)
|
|
|
+ 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 = v.Address
|
|
|
+ record.SmsDate = v.Date
|
|
|
+ record.Body = v.Body
|
|
|
+ addList = append(addList, record)
|
|
|
}
|
|
|
- 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
|
|
|
- _, err = models.AddSmsRecord(record)
|
|
|
+ }
|
|
|
+ if len(addList) > 0 {
|
|
|
+ _, err = models.AddSmsRecordMulti(addList)
|
|
|
if err != nil {
|
|
|
br.Msg = "失败,请联系技术"
|
|
|
br.ErrMsg = "新增记录失败;Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- isAdd = true
|
|
|
- }
|
|
|
- if isAdd {
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
go services.SendSms()
|
|
|
}
|
|
|
br.Ret = 200
|