123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- using System.Data;
- using MySystem;
- using MySystem.Models;
- using Library;
- using LitJson;
- /// <summary>
- /// 盟主过期消息推送
- /// </summary>
- public class LeaderTimeoutSendMessageService
- {
- public readonly static LeaderTimeoutSendMessageService Instance = new LeaderTimeoutSendMessageService();
- private LeaderTimeoutSendMessageService()
- {
- }
- public void Start()
- {
- Thread th = new Thread(doSomething);
- th.IsBackground = true;
- th.Start();
- }
- private void doSomething()
- {
- while (true)
- {
- if (DateTime.Now.Hour < 8)
- {
- try
- {
- string check = function.ReadInstance("/LeaderTimeoutSendMessage/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
- if (string.IsNullOrEmpty(check))
- {
- function.WritePage("/LeaderTimeoutSendMessage/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
- WebCMSEntities db = new WebCMSEntities();
- var leaders = db.Leaders.Select(m => new { m.UserId, m.ExpiredDate }).ToList();
- var time = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
- foreach (var item in leaders)
- {
- var user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
- var leaderTimeOutDate = DateTime.Parse(item.ExpiredDate.Value.ToString("yyyy-MM-dd"));
- var day = leaderTimeOutDate - time;
- if (time >= leaderTimeOutDate.AddDays(-5) && time <= leaderTimeOutDate)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = item.UserId, //创客
- Title = "盟主权益即将到期提醒", //标题
- Content = "<div class='f16'>尊敬的" + user.RealName + "创客您好:<br/>您的盟主权益将在" + day.Days + "天后到期,为保障您的收益持续到账,请尽快续期!</ div > ",//内容
- CreateDate = DateTime.Now,
- }));
- }
- if (time > leaderTimeOutDate && time <= leaderTimeOutDate.AddMonths(1))
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = item.UserId, //创客
- Title = "盟主权益到期提醒", //标题
- Content = "<div class='f16'>尊敬的" + user.RealName + "创客您好:<br/>您的盟主已经过期,重新开通后可恢复相关权益!</ div > ",//内容
- CreateDate = DateTime.Now,
- }));
- }
- }
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "盟主过期消息推送线程异常");
- }
- }
- Thread.Sleep(1000);
- }
- }
- }
|