2024-03-21 21:08:45 +08:00
|
|
|
|
package task
|
|
|
|
|
|
|
|
|
|
import (
|
2024-03-29 02:32:26 +08:00
|
|
|
|
"go.uber.org/zap"
|
2024-03-21 21:08:45 +08:00
|
|
|
|
"miniapp/global"
|
|
|
|
|
"miniapp/model/app"
|
2024-03-29 02:32:26 +08:00
|
|
|
|
"miniapp/model/common"
|
2024-03-21 21:08:45 +08:00
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CheckUserSurgeryDate 检查用户是否已到手术日期
|
|
|
|
|
func CheckUserSurgeryDate() {
|
|
|
|
|
var users []app.User
|
|
|
|
|
global.GVA_DB.Model(&app.User{}).Find(&users)
|
|
|
|
|
for _, user := range users {
|
|
|
|
|
parse, _ := time.Parse("2006-01-02", user.SurgeryTime)
|
|
|
|
|
if time.Now().Sub(parse).Hours()/24 == 0 {
|
|
|
|
|
global.GVA_DB.Model(&app.User{}).Where("id = ?", user.ID).Updates(app.User{IsSurgery: 1})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-29 02:32:26 +08:00
|
|
|
|
|
|
|
|
|
func SendMsg2User() {
|
|
|
|
|
WxTask.Clear()
|
|
|
|
|
|
|
|
|
|
var ut []common.UserTodo
|
|
|
|
|
err := global.GVA_DB.Model(&common.UserTodo{}).Find(&ut).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
global.GVA_LOG.Error("定时任务获取用户Todo列表失败:", zap.Error(err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, todo := range ut {
|
|
|
|
|
parse, _ := time.Parse("2006-01-02", todo.RemindDay)
|
|
|
|
|
if time.Now().Sub(parse).Hours()/24 == 0 {
|
|
|
|
|
// 创建定时任务
|
|
|
|
|
//WxTask := gocron.NewScheduler(time.Local)
|
|
|
|
|
//Send(todo.UserId, todo.Content, todo.RemindTime, todo.Frequency)
|
|
|
|
|
user := app.User{}
|
|
|
|
|
err := global.GVA_DB.Model(&app.User{}).Where("id = ?", todo.UserId).Find(&user).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
global.GVA_LOG.Error("定时任务获取用户信息失败:%s", zap.Error(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据用户手术信息 发送提醒消息
|
|
|
|
|
if user.IsSurgery == 0 && todo.RemindPeriod == 0 && todo.IsFinish == 0 {
|
|
|
|
|
// 根据年月日时发送消息
|
|
|
|
|
_, err := WxTask.Every(1).Day().At(todo.RemindTime).Do(MiniappSendMsg, *user.WechatOpenId, todo.Content, todo.RemindPeriod, todo.RemindTime)
|
|
|
|
|
if err != nil {
|
|
|
|
|
global.GVA_LOG.Error("定时任务创建失败:%s", zap.Error(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|