using System;
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.Data;
using MySystem;
using MySystem.Models;
using Library;
using LitJson;
///
/// 盟主过期消息推送
///
public class LeaderTimeoutSendMessageService
{
public readonly static LeaderTimeoutSendMessageService Instance = new LeaderTimeoutSendMessageService();
private LeaderTimeoutSendMessageService()
{
}
public void StartEverTime()
{
Thread th = new Thread(StartEverTimeDo);
th.IsBackground = true;
th.Start();
}
private void StartEverTimeDo()
{
while (true)
{
WebCMSEntities db = new WebCMSEntities();
try
{
var leaders = db.Leaders.Select(m => new { m.UserId }).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 userRankWhite = db.UserRankWhite.FirstOrDefault(m => m.Id == item.UserId) ?? new UserRankWhite();
var leaderTimeOutDate = DateTime.Parse(userRankWhite.UpdateDate.Value.ToString("yyyy-MM-dd"));
if (time <= leaderTimeOutDate.AddDays(-5))
{
RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
{
UserId = item.UserId, //创客
Title = "盟主权益即将到期提醒", //标题
Content = "
尊敬的" + user.RealName + "创客您好:
您的盟主即将到期,为保障您的收益持续到账,请尽快续期! div > ",//内容
CreateDate = DateTime.Now,
}));
}
if (time >= leaderTimeOutDate)
{
RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
{
UserId = item.UserId, //创客
Title = "盟主权益到期提醒", //标题
Content = "
尊敬的" + user.RealName + "创客您好:
您的盟主已经过期,重新开通后可恢复相关权益! div > ",//内容
CreateDate = DateTime.Now,
}));
}
}
}
catch (Exception ex)
{
function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "盟主过期消息推送线程异常");
}
db.Dispose();
Thread.Sleep(1000);
}
}
}