Record subscription message delivery and add admin log page

This commit is contained in:
2026-10-11 10:21:15 +08:00
parent 7854d94e7b
commit c5cab1b945
14 changed files with 416 additions and 62 deletions
+1 -12
View File
@@ -65,7 +65,6 @@ func Run(db *store.DB, wx *wechat.Client, interval time.Duration) {
// Once 执行一次扫描;force=true 时不限时间且忽略重试上限(对应 --force)
func Once(db *store.DB, wx *wechat.Client, force bool) {
now := time.Now().Format("2006-01-02 15:04:05")
ph := strings.TrimSuffix(strings.Repeat("?,", len(actionTypes)), ",")
args := make([]any, 0, len(actionTypes)+1)
for _, a := range actionTypes {
@@ -88,7 +87,7 @@ func Once(db *store.DB, wx *wechat.Client, force bool) {
}
processed, success, fail, skip := 0, 0, 0, 0
for _, a := range activities {
activityID, coupleID, userID, actionType := a.Int("id"), a.Int("couple_id"), a.Int("user_id"), a.Str("action_type")
activityID, userID, actionType := a.Int("id"), a.Int("user_id"), a.Str("action_type")
nickname := a.Str("nickname")
if nickname == "" {
nickname = "你的TA"
@@ -129,16 +128,6 @@ func Once(db *store.DB, wx *wechat.Client, force bool) {
data := map[string]string{"thing1": mbSub(thing1, 20), "thing2": mbSub(thing2, 20), "date3": date, "thing4": "点击查看详情 💕"}
ok = wx.SendSubscribeMessage(partnerID, "notify", data, page, activityID, userID)
status, errMsg := "success", ""
if !ok {
status, errMsg = "failed", "发送失败(可能用户未订阅或微信接口返回错误)"
}
if retry == 0 {
db.Exec("INSERT INTO notify_log (activity_id, couple_id, user_id, action_type, template_type, to_user_id, status, error_msg, sent_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
activityID, coupleID, userID, actionType, "notify", partnerID, status, errMsg, now)
} else {
db.Exec("UPDATE notify_log SET status = ?, error_msg = ?, sent_at = ? WHERE activity_id = ? AND to_user_id = ?", status, errMsg, now, activityID, partnerID)
}
processed++
if ok {
success++