소스 검색

续费盟主发送消息

lcl 2 년 전
부모
커밋
88e253bb19
6개의 변경된 파일115개의 추가작업 그리고 1개의 파일을 삭제
  1. BIN
      .DS_Store
  2. BIN
      AppStart/.DS_Store
  3. BIN
      AppStart/Helper/.DS_Store
  4. 37 1
      AppStart/Helper/AlipayPayBack2Service.cs
  5. 77 0
      AppStart/Helper/LeaderTimeoutSendMessageService.cs
  6. 1 0
      Startup.cs

BIN
.DS_Store


BIN
AppStart/.DS_Store


BIN
AppStart/Helper/.DS_Store


+ 37 - 1
AppStart/Helper/AlipayPayBack2Service.cs

@@ -410,7 +410,7 @@ namespace MySystem
                                                     coupon.OpId = user.Id;
                                                 }
                                             }
-                                        }
+                                        } 
                                         db.SaveChanges();
                                         //寻找最近储蓄金充足的大盟主
                                         int PUserId = user.Id;
@@ -1181,6 +1181,42 @@ namespace MySystem
                 leader.ExpiredDate = DateTime.Now.AddMonths(Month);
             }
             db.SaveChanges();
+            SendLeaderMsg(db, UserId);
+        }
+
+        #endregion
+
+        #region 盟主续费通知
+
+        public void SendLeaderMsg(WebCMSEntities db, int UserId)
+        {
+            string msg = "";
+            Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+            DateTime now = DateTime.Now;
+            Leaders leader = db.Leaders.FirstOrDefault(m => m.Id == UserId);
+            if(leader != null)
+            {
+                if(leader.ExpiredDate >= now)
+                {
+                    msg = "尊收的" + user.RealName + "创客,恭喜您的盟主已成功开通";
+                }
+                else
+                {
+                    msg = "尊敬的" + user.RealName + "创客,恭喜您重新成为盟主";
+                }
+            }
+            else
+            {
+                msg = "尊收的" + user.RealName + "创客,恭喜您的盟主已成功开通";
+            }
+            RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+            {
+                UserId = Convert.ToInt32(UserId), //创客
+                Title = "开通盟主提醒", //标题
+                Content = msg, //内容
+                Summary = msg,
+                CreateDate = DateTime.Now,
+            }));
         }
 
         #endregion

+ 77 - 0
AppStart/Helper/LeaderTimeoutSendMessageService.cs

@@ -0,0 +1,77 @@
+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"));
+                            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/>您的盟主即将到期,为保障您的收益持续到账,请尽快续期!</ 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);
+        }
+    }
+}

+ 1 - 0
Startup.cs

@@ -229,6 +229,7 @@ namespace MySystem
 
             DepositReturnStatService.Instance.Start(); //每月1号统计达标商户(退押需要的)
             AutoOpOrderService.Instance.StartOrderCancel(); //自动取消超时订单(15分钟)
+            LeaderTimeoutSendMessageService.Instance.Start(); //盟主过期消息提醒
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数