anniversary.go 2.15 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package cp_cron

import (
hujiebin's avatar
hujiebin committed
4
	"git.hilo.cn/hilo-common/_const/enum/msg_e"
hujiebin's avatar
hujiebin committed
5 6 7 8
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/config"
	"github.com/robfig/cron"
	"hilo-user/domain/model/cp_m"
hujiebin's avatar
hujiebin committed
9
	"hilo-user/domain/model/msg_m"
hujiebin's avatar
hujiebin committed
10
	"hilo-user/domain/model/user_m"
hujiebin's avatar
hujiebin committed
11 12 13 14 15 16
)

// 纪念日
type CpAnniversaryNoticeMsg struct {
	Identifier string `json:"identifier"`
	Content    string `json:"content"`
hujiebin's avatar
hujiebin committed
17
	Timestamp  int64  `json:"timestamp"`
hujiebin's avatar
hujiebin committed
18 19 20 21 22 23 24 25 26 27 28 29 30
}

func CpAnniversaryNotice() {
	c := cron.New()
	// 1小时操作一次
	spec := "0 0 */1 * * ?"
	if !config.AppIsRelease() {
		// 测服1分钟
		spec = "0 * * * * ?"
	}
	_ = c.AddFunc(spec, func() {
		var model = domain.CreateModelNil()
		anniversary := cp_m.GetNeedRemindCpAnniversary(model)
hujiebin's avatar
hujiebin committed
31 32 33
		if len(anniversary) <= 0 {
			return
		}
hujiebin's avatar
hujiebin committed
34
		var userIds []uint64
hujiebin's avatar
hujiebin committed
35
		for _, v := range anniversary {
hujiebin's avatar
hujiebin committed
36 37 38 39 40 41 42 43 44 45 46 47
			userIds = append(userIds, v.UserId1)
			userIds = append(userIds, v.UserId2)
		}
		users, err := user_m.GetUserMapByIds(model, userIds)
		if err != nil {
			model.Log.Errorf("GetUserMapByIds fail:%v", err)
		}
		for _, v := range anniversary {
			content1 := cp_m.GetTranslate(285, users[v.UserId1].Language)
			content2 := cp_m.GetTranslate(285, users[v.UserId2].Language)
			record1 := msg_m.NewUserRecord(model, v.UserId1, msg_e.CpAnniversaryNotice, content1, 0, "", "", "", "", "")
			record2 := msg_m.NewUserRecord(model, v.UserId2, msg_e.CpAnniversaryNotice, content2, 0, "", "", "", "", "")
hujiebin's avatar
hujiebin committed
48 49 50 51
			err1, err2 := record1.Persistent(), record2.Persistent()
			if err1 != nil || err2 != nil {
				model.Log.Errorf("NewUserRecord fail:%v-%v", err1, err2)
				return
hujiebin's avatar
hujiebin committed
52
			}
53 54 55 56 57 58
			//if err := tencentyun.BatchSendCustomMsg(model, 1, users[0].ExternalId, []string{users[1].ExternalId}, string(data), "cp纪念日"); err != nil {
			//	model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
			//}
			//if err := tencentyun.BatchSendCustomMsg(model, 1, users[1].ExternalId, []string{users[0].ExternalId}, string(data), "cp纪念日"); err != nil {
			//	model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
			//}
hujiebin's avatar
hujiebin committed
59 60 61 62 63 64 65
			if err := cp_m.UpdateCpAnniversaryReminded(model, v.ID); err != nil {
				model.Log.Errorf("UpdateCpAnniversaryReminded fail:%v", err)
			}
		}
	})
	c.Start()
}