Sfoglia il codice sorgente

整理逻辑、必要的队列、redis写法的清理

lcl 1 anno fa
parent
commit
c07bfefa05

BIN
.DS_Store


+ 2 - 17
AppStart/Helper/AlipayPayBackService.cs

@@ -13,30 +13,15 @@ namespace MySystem
         private AlipayPayBackService()
         { }
 
-        public void Start(JobMqMsg jobInfo)
+        public void Start()
         {
-            string content = "";
             try
             {
                 dosomething();
-                // string Msg = "success";
-                // jobInfo.Status = Msg == "success" ? 1 : 0;
-                // jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
-                // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
             }
             catch (Exception ex)
             {
-                if (!string.IsNullOrEmpty(content))
-                {
-                    Dictionary<string, string> data = new Dictionary<string, string>();
-                    data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
-                    data.Add("ErrMsg", ex.ToString());
-                    function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
-                }
-                else
-                {
-                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
-                }
+                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "支付回调异常");
             }
         }
 

+ 84 - 82
AppStart/Helper/CheckAlipaySignService.cs

@@ -5,6 +5,7 @@ using MySystem.PxcModels;
 using Library;
 using LitJson;
 using System.Text.RegularExpressions;
+using System.Threading;
 
 namespace MySystem
 {
@@ -14,109 +15,110 @@ namespace MySystem
         private CheckAlipaySignService()
         { }
 
-        public void Start(JobMqMsg jobInfo)
+        public void Start()
+        {
+            Thread th = new Thread(StartListen);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartListen()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("AlipaySignQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    StartDo(Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantSign>(content));
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        public void StartDo(MerchantSign sign)
         {
             try
             {
                 PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-                List<MerchantSign> deletes = new List<MerchantSign>();
-                List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("AlipaySignList", 1, 10000000); // TODO: 换成mysql存储遍历
-                foreach (MerchantSign sign in signs)
+                string content = new AlipayFunction().QuerySignStatus(sign.BusinessCode);
+                JsonData dic = JsonMapper.ToObject(content);
+                if (dic["alipay_open_agent_order_query_response"]["code"].ToString() == "10000")
                 {
-                    string content = new AlipayFunction().QuerySignStatus(sign.BusinessCode);
-                    JsonData dic = JsonMapper.ToObject(content);
-                    if (dic["alipay_open_agent_order_query_response"]["code"].ToString() == "10000")
+                    if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM")
                     {
-                        if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM")
+                        string sign_url = dic["alipay_open_agent_order_query_response"]["confirm_url"].ToString();
+                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount == 0);
+                        if (merchantadd != null)
                         {
-                            string sign_url = dic["alipay_open_agent_order_query_response"]["confirm_url"].ToString();
-                            PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount == 0);
-                            if (merchantadd != null)
+                            merchantadd.QueryCount = 1;
+                            string confirm_url = "/static/alipay_confirm_url/";
+                            string fileName = function.MD5_16(Guid.NewGuid().ToString());
+                            function.CreateQRCode2(sign_url, fileName, "/bsserver_com" + confirm_url);
+                            string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
+                            if (string.IsNullOrEmpty(SignUrlList))
                             {
-                                merchantadd.QueryCount = 1;
-                                string confirm_url = "/static/alipay_confirm_url/";
-                                string fileName = function.MD5_16(Guid.NewGuid().ToString());
-                                function.CreateQRCode2(sign_url, fileName, "/bsserver_com" + confirm_url);
-                                string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
-                                if (string.IsNullOrEmpty(SignUrlList))
-                                {
-                                    SignUrlList = "Alipay:" + confirm_url + ";";
-                                }
-                                else
-                                {
-                                    SignUrlList = "Alipay:" + confirm_url+ ";" + SignUrlList;
-                                }
-                                merchantadd.SeoKeyword = SignUrlList;
-                                merchantadd.SeoTitle = dic["alipay_open_agent_order_query_response"]["merchant_pid"].ToString();
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
+                                SignUrlList = "Alipay:" + confirm_url + ";";
                             }
-                        }
-                        else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM_SUCCESS")
-                        {
-                            PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount < 2);
-                            if (merchantadd != null)
+                            else
                             {
-                                merchantadd.QueryCount = 2;
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
-                                if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
-                                {
-                                    PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                                    List<PxcModels.MerchantInfo> merchants = RedisDbconn.Instance.GetList<PxcModels.MerchantInfo>("TmpMerchantInfo:" + merchant.UserId, 1, 1000000);
-                                    PxcModels.MerchantInfo check = merchants.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                                    if (check != null)
-                                    {
-                                        merchants.Remove(check);
-                                        RedisDbconn.Instance.Clear("TmpMerchantInfo:" + merchant.UserId);
-                                        RedisDbconn.Instance.AddList("TmpMerchantInfo:" + merchant.UserId, merchants.ToArray());
-                                    }
-                                }
-                                deletes.Add(sign);
+                                SignUrlList = "Alipay:" + confirm_url+ ";" + SignUrlList;
                             }
+                            merchantadd.SeoKeyword = SignUrlList;
+                            merchantadd.SeoTitle = dic["alipay_open_agent_order_query_response"]["merchant_pid"].ToString();
+                            db.SaveChanges();
                         }
-                        else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_APPLY_ORDER_CANCELED")
-                        { 
-                            PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                            if (merchantadd != null)
+                    }
+                    else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM_SUCCESS")
+                    {
+                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount < 2);
+                        if (merchantadd != null)
+                        {
+                            merchantadd.QueryCount = 2;
+                            db.SaveChanges();
+                            RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
+                            if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
                             {
-                                string Season = function.CheckNull(merchantadd.SeoDescription);
-                                if (string.IsNullOrEmpty(Season))
-                                {
-                                    Season = "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";";
-                                }
-                                else
-                                {
-                                    Season = Regex.Replace(Season, "Alipay:.*?;", "");
-                                    Season += "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";";
-                                }
-                                merchantadd.SeoDescription = Season;
-                                merchantadd.QueryCount = -1;
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
                                 PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                                if (merchant != null)
+                                List<PxcModels.MerchantInfo> merchants = RedisDbconn.Instance.GetList<PxcModels.MerchantInfo>("TmpMerchantInfo:" + merchant.UserId, 1, 1000000);
+                                PxcModels.MerchantInfo check = merchants.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                                if (check != null)
                                 {
-                                    merchant.Status = -1;
-                                    RedisDbconn.Instance.Set("MerchantInfo:" + sign.MerchantAddInfoId, merchant);
+                                    merchants.Remove(check);
+                                    RedisDbconn.Instance.Clear("TmpMerchantInfo:" + merchant.UserId);
+                                    RedisDbconn.Instance.AddList("TmpMerchantInfo:" + merchant.UserId, merchants.ToArray());
                                 }
-                                deletes.Add(sign);
                             }
                         }
                     }
-                }
-                if (deletes.Count > 0)
-                {
-                    foreach (MerchantSign delete in deletes)
-                    {
-                        signs.Remove(delete);
+                    else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_APPLY_ORDER_CANCELED")
+                    { 
+                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchantadd != null)
+                        {
+                            string Season = function.CheckNull(merchantadd.SeoDescription);
+                            if (string.IsNullOrEmpty(Season))
+                            {
+                                Season = "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";";
+                            }
+                            else
+                            {
+                                Season = Regex.Replace(Season, "Alipay:.*?;", "");
+                                Season += "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";";
+                            }
+                            merchantadd.SeoDescription = Season;
+                            merchantadd.QueryCount = -1;
+                            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                            if (merchant != null)
+                            {
+                                merchant.Status = -1;
+                            }
+                            db.SaveChanges();
+                        }
                     }
-                    RedisDbconn.Instance.Clear("AliaySignList");
-                    RedisDbconn.Instance.AddList("AliaySignList", signs.ToArray());
                 }
-                // jobInfo.Status = 1;
-                // jobInfo.Msg = "执行完成";
-                // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
             }
             catch (Exception ex)
             {

+ 97 - 93
AppStart/Helper/CheckWeChatSignService.cs

@@ -5,6 +5,7 @@ using MySystem.PxcModels;
 using Library;
 using LitJson;
 using System.Text.RegularExpressions;
+using System.Threading;
 
 namespace MySystem
 {
@@ -14,129 +15,132 @@ namespace MySystem
         private CheckWeChatSignService()
         { }
 
-        public void Start(JobMqMsg jobInfo)
+        public void Start()
+        {
+            Thread th = new Thread(StartListen);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartListen()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("WeChatSignQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    StartDo(Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantSign>(content));
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        public void StartDo(MerchantSign sign)
         {
             try
             {
                 PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
                 List<MerchantSign> deletes = new List<MerchantSign>();
-                List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("WeChatSignList", 1, 10000000); // TODO: 换成mysql存储遍历
-                foreach (MerchantSign sign in signs)
+                Dictionary<string, object> dic = new WeChatFunction().QueryMerchant(sign.BusinessCode);
+                if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_SIGNED")
                 {
-                    Dictionary<string, object> dic = new WeChatFunction().QueryMerchant(sign.BusinessCode);
-                    if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_SIGNED")
+                    string sign_url = dic["sign_url"].ToString();
+                    PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 0);
+                    if (merchantadd != null)
                     {
-                        string sign_url = dic["sign_url"].ToString();
-                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 0);
-                        if (merchantadd != null)
+                        merchantadd.Status = 1;
+                        string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
+                        if (string.IsNullOrEmpty(SignUrlList))
                         {
-                            merchantadd.Status = 1;
-                            string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
-                            if (string.IsNullOrEmpty(SignUrlList))
-                            {
-                                SignUrlList = "WeChat:" + sign_url + ";";
-                            }
-                            else
-                            {
-                                SignUrlList += "WeChat:" + sign_url+ ";";
-                            }
-                            merchantadd.SeoKeyword = SignUrlList;
-                            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                            if (merchantadd.Status > 0 && merchantadd.QueryCount > 0)
-                            {
-                                merchant.Status = 1;
-                            }
-                            db.SaveChanges();
-                            RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
+                            SignUrlList = "WeChat:" + sign_url + ";";
                         }
-                    }
-                    else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_FINISHED")
-                    { 
-                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 1);
-                        if (merchantadd != null)
+                        else
                         {
-                            merchantadd.Status = 2;
-                            RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
-                            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                            if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
-                            {
-                                merchant.Status = 2;
-                            }
-                            db.SaveChanges();
-                            if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
-                            {
-                                List<MerchantInfo> merchants = RedisDbconn.Instance.GetList<MerchantInfo>("TmpMerchantInfo:" + merchant.UserId, 1, 1000000);
-                                MerchantInfo check = merchants.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                                if (check != null)
-                                {
-                                    merchants.Remove(check);
-                                    RedisDbconn.Instance.Clear("TmpMerchantInfo:" + merchant.UserId);
-                                    RedisDbconn.Instance.AddList("TmpMerchantInfo:" + merchant.UserId, merchants.ToArray());
-                                }
-                            }
-                            deletes.Add(sign);
+                            SignUrlList += "WeChat:" + sign_url+ ";";
+                        }
+                        merchantadd.SeoKeyword = SignUrlList;
+                        PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchantadd.Status > 0 && merchantadd.QueryCount > 0)
+                        {
+                            merchant.Status = 1;
                         }
+                        db.SaveChanges();
                     }
-                    else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
+                }
+                else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_FINISHED")
+                { 
+                    PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 1);
+                    if (merchantadd != null)
                     {
-                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                        if (merchantadd != null)
+                        merchantadd.Status = 2;
+                        RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
+                        PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
                         {
-                            string Season = function.CheckNull(merchantadd.SeoDescription);
-                            if (string.IsNullOrEmpty(Season))
-                            {
-                                Season = "WeChat:" + dic["reject_reason"].ToString() + ";";
-                            }
-                            else
-                            {
-                                Season = Regex.Replace(Season, "WeChat:.*?;", "");
-                                Season += "WeChat:" + dic["reject_reason"].ToString() + ";";
-                            }
-                            merchantadd.SeoDescription = Season;
-                            merchantadd.Status = -1;
-                            db.SaveChanges();
-                            RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
-                            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                            if (merchant != null)
+                            merchant.Status = 2;
+                        }
+                        db.SaveChanges();
+                        if (merchantadd.Status == 2 && merchantadd.QueryCount == 2)
+                        {
+                            List<MerchantInfo> merchants = RedisDbconn.Instance.GetList<MerchantInfo>("TmpMerchantInfo:" + merchant.UserId, 1, 1000000);
+                            MerchantInfo check = merchants.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                            if (check != null)
                             {
-                                merchant.Status = -1;
-                                RedisDbconn.Instance.Set("MerchantInfo:" + sign.MerchantAddInfoId, merchant);
+                                merchants.Remove(check);
+                                RedisDbconn.Instance.Clear("TmpMerchantInfo:" + merchant.UserId);
+                                RedisDbconn.Instance.AddList("TmpMerchantInfo:" + merchant.UserId, merchants.ToArray());
                             }
-                            deletes.Add(sign);
                         }
+                        deletes.Add(sign);
                     }
-                    else
+                }
+                else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
+                {
+                    PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                    if (merchantadd != null)
                     {
-                        string sub_mchid = "";
-                        if (dic.ContainsKey("sub_mchid"))
+                        string Season = function.CheckNull(merchantadd.SeoDescription);
+                        if (string.IsNullOrEmpty(Season))
                         {
-                            sub_mchid = dic["sub_mchid"].ToString();
-                            PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
-                            if (merchantadd != null)
-                            {
-                                merchantadd.SubMchid = sub_mchid;
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
-                            }
+                            Season = "WeChat:" + dic["reject_reason"].ToString() + ";";
                         }
+                        else
+                        {
+                            Season = Regex.Replace(Season, "WeChat:.*?;", "");
+                            Season += "WeChat:" + dic["reject_reason"].ToString() + ";";
+                        }
+                        merchantadd.SeoDescription = Season;
+                        merchantadd.Status = -1;
+                        PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchant != null)
+                        {
+                            merchant.Status = -1;
+                        }
+                        db.SaveChanges();
+                        deletes.Add(sign);
                     }
                 }
-                if (deletes.Count > 0)
+                else
                 {
-                    foreach (MerchantSign delete in deletes)
+                    string sub_mchid = "";
+                    if (dic.ContainsKey("sub_mchid"))
                     {
-                        signs.Remove(delete);
+                        sub_mchid = dic["sub_mchid"].ToString();
+                        PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
+                        if (merchantadd != null)
+                        {
+                            merchantadd.SubMchid = sub_mchid;
+                            db.SaveChanges();
+                        }
                     }
-                    RedisDbconn.Instance.Clear("WeChatSignList");
-                    RedisDbconn.Instance.AddList("WeChatSignList", signs.ToArray());
                 }
-                // jobInfo.Status = 1;
-                // jobInfo.Msg = "执行完成";
-                // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
             }
             catch (Exception ex)
             {
-                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public:merchant:signerr");
+                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "微信进件回调队列异常");
             }
         }
     }

+ 156 - 183
AppStart/Helper/MerchantConfirmService.cs

@@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
 using MySystem.PxcModels;
 using Library;
 using LitJson;
+using System.Threading;
 
 namespace MySystem
 {
@@ -14,169 +15,161 @@ namespace MySystem
         private MerchantConfirmService()
         { }
 
-        public void Start(string MerchantIdString, int Kind = 0)
+        public void Start()
         {
-            try
+            Thread th = new Thread(StartListen);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartListen()
+        {
+            while (true)
             {
-                int MerchantId = int.Parse(function.CheckInt(MerchantIdString));
-                PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-                PxcModels.MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
-                PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
-                if (AddInfo != null && merchant != null)
-                {
-                    string BusinessCode = AddInfo.BusinessCode;
-                    if (string.IsNullOrEmpty(BusinessCode))
-                    { 
-                        BusinessCode = "KXS" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
-                        AddInfo.BusinessCode = BusinessCode;
+                string content = RedisDbconn.Instance.RPop<string>("MerchantConfirmQueue");
+                if (!string.IsNullOrEmpty(content))
+                {                    
+                    try
+                    {
+                        JsonData jsonObj = JsonMapper.ToObject(content);
+                        int MerchantId = int.Parse(jsonObj["MerchantId"].ToString());
+                        int Kind = int.Parse(jsonObj["Kind"].ToString());
+                        StartDo(MerchantId, Kind);
                     }
-                    merchant.LoginPwd = function.MD532(AddInfo.MobilePhone.Substring(5));
-                    PxcModels.MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
-                    if (query == null)
+                    catch (Exception ex)
                     {
-                        query = new PxcModels.MerchantParamSet();
-                        query.IsAll = 1;
-                        db.MerchantParamSet.Add(query);
-                        db.SaveChanges();
-                        RedisDbconn.Instance.Set("MerchantParamSet:" + MerchantId, query);
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
                     }
-                    PxcModels.MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
-                    if (merchantForMobile == null)
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        public void StartDo(int MerchantId, int Kind = 0)
+        {
+            PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+            PxcModels.MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
+            PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
+            if (AddInfo != null && merchant != null)
+            {
+                string BusinessCode = AddInfo.BusinessCode;
+                if (string.IsNullOrEmpty(BusinessCode))
+                { 
+                    BusinessCode = "KXS" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
+                    AddInfo.BusinessCode = BusinessCode;
+                }
+                merchant.LoginPwd = function.MD532(AddInfo.MobilePhone.Substring(5));
+                PxcModels.MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
+                if (query == null)
+                {
+                    query = new PxcModels.MerchantParamSet();
+                    query.IsAll = 1;
+                    db.MerchantParamSet.Add(query);
+                    db.SaveChanges();
+                    RedisDbconn.Instance.Set("MerchantParamSet:" + MerchantId, query);
+                }
+                PxcModels.MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
+                if (merchantForMobile == null)
+                {
+                    merchantForMobile = db.MerchantForMobile.Add(new PxcModels.MerchantForMobile()
                     {
-                        merchantForMobile = db.MerchantForMobile.Add(new PxcModels.MerchantForMobile()
+                        Mobile = AddInfo.MobilePhone,
+                    }).Entity;
+                    db.SaveChanges();
+                }
+                merchantForMobile.MerchantId = MerchantId;
+                db.SaveChanges();
+                //微信
+                if (Kind == 0 || Kind == 2)
+                {
+                    string result = new WeChatFunction().MerchantCreate(AddInfo, merchant);
+                    if (result.Contains("\"applyment_id\":"))
+                    {
+                        JsonData jsonObj = JsonMapper.ToObject(result);
+                        AddInfo.ApplymentId = jsonObj["applyment_id"].ToString();
+                        AddInfo.Status = 0;
+                        db.SaveChanges();
+                        List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
+                        bool op = signs.Any(m => m.BusinessCode == BusinessCode);
+                        if (!op)
                         {
-                            Mobile = AddInfo.MobilePhone,
-                        }).Entity;
+                            RedisDbconn.Instance.AddList("WeChatSignQueue", new MerchantSign()
+                            {
+                                BusinessCode = BusinessCode,
+                                MerchantAddInfoId = MerchantId,
+                                Status = ""
+                            });
+                        }
+                        signs.Clear();
+                        AddInfo.ApplymentId = AddInfo.ApplymentId;
+                        AddInfo.Status = AddInfo.Status;
                         db.SaveChanges();
                     }
-                    merchantForMobile.MerchantId = MerchantId;
-                    db.SaveChanges();
-                    List<MerchantInfo> merchants = RedisDbconn.Instance.GetList<MerchantInfo>("MerchantList:" + merchant.UserId, 1, 10000000);
-
-                    //微信
-                    if (Kind == 0 || Kind == 2)
+                    else if (result.Contains("\"message\":"))
                     {
-                        string result = new WeChatFunction().MerchantCreate(AddInfo, merchant);
-                        if (result.Contains("\"applyment_id\":"))
+                        JsonData jsonObj = JsonMapper.ToObject(result);
+                        AddInfo.Status = -1;
+                        merchant.Status = -1;
+                        string Season = function.CheckNull(AddInfo.SeoDescription);
+                        if (string.IsNullOrEmpty(Season))
                         {
-                            JsonData jsonObj = JsonMapper.ToObject(result);
-                            AddInfo.ApplymentId = jsonObj["applyment_id"].ToString();
-                            AddInfo.Status = 0;
-                            db.SaveChanges();
-                            List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
-                            bool op = signs.Any(m => m.BusinessCode == BusinessCode);
-                            if (!op)
-                            {
-                                RedisDbconn.Instance.AddList("WeChatSignList", new MerchantSign()
-                                {
-                                    BusinessCode = BusinessCode,
-                                    MerchantAddInfoId = MerchantId,
-                                    Status = ""
-                                });
-                            }
-                            signs.Clear();
-                            if (merchants.Any(m => m.Id == merchant.Id) == false)
-                            {
-                                RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
-                            }
-                            else
-                            {
-                                PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
-                                if (merchantAddInfo != null)
-                                {
-                                    merchantAddInfo.ApplymentId = AddInfo.ApplymentId;
-                                    merchantAddInfo.Status = AddInfo.Status;
-                                    RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
-                                }
-                            }
+                            Season = "WeChat:" + jsonObj["message"].ToString() + ";";
                         }
-                        else if (result.Contains("\"message\":"))
+                        else
                         {
-                            JsonData jsonObj = JsonMapper.ToObject(result);
-                            AddInfo.Status = -1;
-                            merchant.Status = -1;
-                            string Season = function.CheckNull(AddInfo.SeoDescription);
-                            if (string.IsNullOrEmpty(Season))
-                            {
-                                Season = "WeChat:" + jsonObj["message"].ToString() + ";";
-                            }
-                            else
-                            {
-                                Season = Regex.Replace(Season, "WeChat:.*?;", "");
-                                Season += "WeChat:" + jsonObj["message"].ToString() + ";";
-                            }
-                            AddInfo.SeoDescription = Season;
-                            db.SaveChanges();
-                            if (merchants.Any(m => m.Id == merchant.Id) == false)
-                            {
-                                RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
-                            }
-                            else
-                            {
-                                PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
-                                if (merchantAddInfo != null)
-                                {
-                                    merchantAddInfo.SeoDescription = AddInfo.SeoDescription;
-                                    merchantAddInfo.Status = AddInfo.Status;
-                                    RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
-                                }
-                            }
-                            List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("WeChatSignList", 1, 10000000);
-                            MerchantSign sign = signs.FirstOrDefault(m => m.BusinessCode == BusinessCode);
-                            if (sign != null)
-                            {
-                                signs.Remove(sign);
-                                RedisDbconn.Instance.Clear("WeChatSignList");
-                                RedisDbconn.Instance.AddList("WeChatSignList", signs.ToArray());
-                            }
+                            Season = Regex.Replace(Season, "WeChat:.*?;", "");
+                            Season += "WeChat:" + jsonObj["message"].ToString() + ";";
                         }
+                        AddInfo.SeoDescription = Season;
+                        AddInfo.SeoDescription = AddInfo.SeoDescription;
+                        AddInfo.Status = AddInfo.Status;
+                        db.SaveChanges();
                     }
+                }
 
-                    //支付宝
-                    if (Kind == 0 || Kind == 1)
+                //支付宝
+                if (Kind == 0 || Kind == 1)
+                {
+                    bool checkAlipay = true;
+                    string content = new AlipayFunction().GetBatchNo(AddInfo.CreateMan, AddInfo.IdCardName, AddInfo.MobilePhone, AddInfo.ContactEmail);
+                    JsonData json = JsonMapper.ToObject(content);
+                    if (json["alipay_open_agent_create_response"]["code"].ToString() == "10000")
                     {
-                        bool checkAlipay = true;
-                        string content = new AlipayFunction().GetBatchNo(AddInfo.CreateMan, AddInfo.IdCardName, AddInfo.MobilePhone, AddInfo.ContactEmail);
-                        JsonData json = JsonMapper.ToObject(content);
-                        if (json["alipay_open_agent_create_response"]["code"].ToString() == "10000")
+                        string batch_no = json["alipay_open_agent_create_response"]["batch_no"].ToString();
+                        string Qualifications = AddInfo.Qualifications;
+                        if (!string.IsNullOrEmpty(Qualifications))
                         {
-                            string batch_no = json["alipay_open_agent_create_response"]["batch_no"].ToString();
-                            string Qualifications = AddInfo.Qualifications;
-                            if (!string.IsNullOrEmpty(Qualifications))
-                            {
-                                Qualifications = function.getPath("/bsserver_com" + Qualifications);
-                            }
-                            content = new AlipayFunction().CommonSign(batch_no, AddInfo.UpdateMan, AddInfo.LicenseNumber, function.getPath("/bsserver_com" + AddInfo.LicenseCopy), Qualifications);
+                            Qualifications = function.getPath("/bsserver_com" + Qualifications);
+                        }
+                        content = new AlipayFunction().CommonSign(batch_no, AddInfo.UpdateMan, AddInfo.LicenseNumber, function.getPath("/bsserver_com" + AddInfo.LicenseCopy), Qualifications);
+                        json = JsonMapper.ToObject(content);
+                        if (json["alipay_open_agent_common_sign_response"]["code"].ToString() == "10000")
+                        {
+                            content = new AlipayFunction().CommonSignConfirm(batch_no);
                             json = JsonMapper.ToObject(content);
-                            if (json["alipay_open_agent_common_sign_response"]["code"].ToString() == "10000")
-                            {
-                                content = new AlipayFunction().CommonSignConfirm(batch_no);
-                                json = JsonMapper.ToObject(content);
-                                if (json["alipay_open_agent_commonsign_confirm_response"]["code"].ToString() == "10000")
+                            if (json["alipay_open_agent_commonsign_confirm_response"]["code"].ToString() == "10000")
+                            {
+                                AddInfo.QueryCount = 0;
+                                AddInfo.SeoTitle = batch_no;
+                                db.SaveChanges();
+                                List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
+                                bool op = signs.Any(m => m.BusinessCode == batch_no);
+                                if (!op)
                                 {
-                                    AddInfo.QueryCount = 0;
-                                    AddInfo.SeoTitle = batch_no;
-                                    db.SaveChanges();
-                                    List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("MerchantSignList", 1, 10000000);
-                                    bool op = signs.Any(m => m.BusinessCode == batch_no);
-                                    if (!op)
-                                    {
-                                        RedisDbconn.Instance.AddList("AlipaySignList", new MerchantSign()
-                                        {
-                                            BusinessCode = batch_no,
-                                            MerchantAddInfoId = MerchantId,
-                                            Status = ""
-                                        });
-                                    }
-                                    signs.Clear();
-                                    if (merchants.Any(m => m.Id == merchant.Id) == false)
+                                    RedisDbconn.Instance.AddList("AlipaySignQueue", new MerchantSign()
                                     {
-                                        RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
-                                    }
+                                        BusinessCode = batch_no,
+                                        MerchantAddInfoId = MerchantId,
+                                        Status = ""
+                                    });
                                 }
-                                else
+                                signs.Clear();
+                                if (db.MerchantInfo.Any(m => m.Id == merchant.Id) == false)
                                 {
-                                    checkAlipay = false;
+                                    RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
                                 }
                             }
                             else
@@ -188,54 +181,34 @@ namespace MySystem
                         {
                             checkAlipay = false;
                         }
-                        if (!checkAlipay)
+                    }
+                    else
+                    {
+                        checkAlipay = false;
+                    }
+                    if (!checkAlipay)
+                    {
+                        JsonData jsonObj = JsonMapper.ToObject(content);
+                        AddInfo.QueryCount = -1;
+                        merchant.Status = -1;
+                        string Season = function.CheckNull(AddInfo.SeoDescription);
+                        if (string.IsNullOrEmpty(Season))
                         {
-                            JsonData jsonObj = JsonMapper.ToObject(content);
-                            AddInfo.QueryCount = -1;
-                            merchant.Status = -1;
-                            string Season = function.CheckNull(AddInfo.SeoDescription);
-                            if (string.IsNullOrEmpty(Season))
-                            {
-                                Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";";
-                            }
-                            else
-                            {
-                                Season = Regex.Replace(Season, "Alipay:.*?;", "");
-                                Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";" + Season;
-                            }
-                            AddInfo.SeoDescription = Season;
-                            db.SaveChanges();
-                            if (merchants.Any(m => m.Id == merchant.Id) == false)
-                            {
-                                RedisDbconn.Instance.AddList("MerchantList:" + merchant.UserId, merchant);
-                            }
-                            else
-                            {
-                                PxcModels.MerchantAddInfo merchantAddInfo = RedisDbconn.Instance.Get<PxcModels.MerchantAddInfo>("MerchantAddInfo:" + MerchantId);
-                                if (merchantAddInfo != null)
-                                {
-                                    merchantAddInfo.SeoDescription = AddInfo.SeoDescription;
-                                    merchantAddInfo.QueryCount = AddInfo.QueryCount;
-                                    RedisDbconn.Instance.Set("MerchantAddInfo:" + MerchantId, merchantAddInfo);
-                                }
-                            }
-                            List<MerchantSign> signs = RedisDbconn.Instance.GetList<MerchantSign>("AlipaySignList", 1, 10000000);
-                            MerchantSign sign = signs.FirstOrDefault(m => m.BusinessCode == BusinessCode);
-                            if (sign != null)
-                            {
-                                signs.Remove(sign);
-                                RedisDbconn.Instance.Clear("AlipaySignList");
-                                RedisDbconn.Instance.AddList("AlipaySignList", signs.ToArray());
-                            }
+                            Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";";
+                        }
+                        else
+                        {
+                            Season = Regex.Replace(Season, "Alipay:.*?;", "");
+                            Season = "Alipay:" + jsonObj["alipay_open_agent_create_response"]["sub_msg"].ToString() + ";" + Season;
                         }
+                        AddInfo.SeoDescription = Season;
+                        AddInfo.SeoDescription = AddInfo.SeoDescription;
+                        AddInfo.QueryCount = AddInfo.QueryCount;
+                        db.SaveChanges();
                     }
                 }
-                db.Dispose();
-            }
-            catch (Exception ex)
-            {
-                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
             }
+            db.Dispose();
         }
     }
 }

+ 63 - 116
AppStart/Helper/Profit/ProfitHelper.cs

@@ -72,7 +72,7 @@ namespace MySystem
                         if (merchant != null)
                         {
                             int UserId = merchant.UserId;
-                            List<CustomTagSet> customTagSets = RedisDbconn.Instance.GetList<CustomTagSet>("CustomTagSet", 1, 1000); //获取公用配置参数集和
+                            List<CustomTagSet> customTagSets = db.CustomTagSet.ToList(); //获取公用配置参数集和
                             //获取参数
                             CustomTagSet profitPercentSet = customTagSets.FirstOrDefault(m => m.Tags == "CusumerProfitPercent") ?? new CustomTagSet();
                             decimal profitPercent = decimal.Parse(function.CheckNum(profitPercentSet.Contents)); //基于收款金额的总分润比例;
@@ -216,7 +216,7 @@ namespace MySystem
                                     function.WriteLog("返现金额:" + DiviMoney + ";返现人数:" + DiviPersons + ";返现商户:" + TotalActual + ";返现溢出:" + OtherMoney + ";商户应得金额:" + MerchantGetMoney + ";返现差额:" + DoMoney + ";", "消费者返现日志");
 
                                     //创客分润
-                                    // DoProfit(db, order);
+                                    DoProfit(db, order, true);
 
                                     //代理商分润
                                     // AgentProfit(db, order);
@@ -224,64 +224,59 @@ namespace MySystem
                             }
                             else
                             {
-                                TotalActual = PayMoney * (1 - cusumerFeePercent);
+                                // TotalActual = PayMoney * (1 - cusumerFeePercent);
+                                DoProfit(db, order);
                             }
 
                             //统计商户数据
-                            string MonthString = order.UpdateDate.Value.ToString("yyyyMM");
-                            string DateString = order.UpdateDate.Value.ToString("yyyyMMdd");
-                            TotalActual = PublicFunction.NumberFormat(TotalActual);
-                            function.WriteLog(TotalActual.ToString(), "监控退款队列");
-                            merchant.TotalActual += TotalActual;
-                            db.SaveChanges();
-
-                            List<string> Dates = RedisDbconn.Instance.GetList<string>("ConsumerStat:" + MerchantId + ":" + MonthString, 1, 1000);
-                            if (!Dates.Contains(DateString))
-                            {
-                                RedisDbconn.Instance.AddList("ConsumerStat:" + MerchantId + ":" + MonthString, DateString);
-                            }
-                            MerchantIndexStat DateIndexStat = RedisDbconn.Instance.Get<MerchantIndexStat>("MerchantIndexStat:" + MerchantId + ":" + DateString) ?? new MerchantIndexStat();
-                            DateIndexStat.TotalOrder += 1;
-                            DateIndexStat.TotalAmount += PayMoney;
-                            DateIndexStat.TotalActual += TotalActual;
-                            if (order.PayMode == 1)
-                            {
-                                DateIndexStat.AlipayTotalAmount += PayMoney;
-                                DateIndexStat.AlipayTotalActual += TotalActual;
-                            }
-                            else if (order.PayMode == 2)
-                            {
-                                DateIndexStat.WeChatTotalAmount += PayMoney;
-                                DateIndexStat.WeChatTotalActual += TotalActual;
-                            }
-                            RedisDbconn.Instance.Set("MerchantIndexStat:" + MerchantId + ":" + DateString, DateIndexStat);
-
-                            List<string> Months = RedisDbconn.Instance.GetList<string>("ConsumerStat:" + MerchantId, 1, 1000);
-                            if (!Months.Contains(MonthString))
-                            {
-                                RedisDbconn.Instance.AddList("ConsumerStat:" + MerchantId, MonthString);
-                            }
-                            MerchantIndexStat MonthIndexStat = RedisDbconn.Instance.Get<MerchantIndexStat>("MerchantIndexStat:" + MerchantId + ":" + MonthString) ?? new MerchantIndexStat();
-                            MonthIndexStat.TotalOrder += 1;
-                            MonthIndexStat.TotalAmount += PayMoney;
-                            MonthIndexStat.TotalActual += TotalActual;
-                            if (order.PayMode == 1)
-                            {
-                                MonthIndexStat.AlipayTotalAmount += PayMoney;
-                                MonthIndexStat.AlipayTotalActual += TotalActual;
-                            }
-                            else if (order.PayMode == 2)
-                            {
-                                MonthIndexStat.WeChatTotalAmount += PayMoney;
-                                MonthIndexStat.WeChatTotalActual += TotalActual;
-                            }
-                            RedisDbconn.Instance.Set("MerchantIndexStat:" + MerchantId + ":" + MonthString, MonthIndexStat);
+                            // string MonthString = order.UpdateDate.Value.ToString("yyyyMM");
+                            // string DateString = order.UpdateDate.Value.ToString("yyyyMMdd");
+                            // TotalActual = PublicFunction.NumberFormat(TotalActual);
+                            // function.WriteLog(TotalActual.ToString(), "监控退款队列");
+                            // merchant.TotalActual += TotalActual;
+                            // db.SaveChanges();
+
+                            // List<string> Dates = RedisDbconn.Instance.GetList<string>("ConsumerStat:" + MerchantId + ":" + MonthString, 1, 1000);
+                            // if (!Dates.Contains(DateString))
+                            // {
+                            //     RedisDbconn.Instance.AddList("ConsumerStat:" + MerchantId + ":" + MonthString, DateString);
+                            // }
+                            // MerchantIndexStat DateIndexStat = RedisDbconn.Instance.Get<MerchantIndexStat>("MerchantIndexStat:" + MerchantId + ":" + DateString) ?? new MerchantIndexStat();
+                            // DateIndexStat.TotalOrder += 1;
+                            // DateIndexStat.TotalAmount += PayMoney;
+                            // DateIndexStat.TotalActual += TotalActual;
+                            // if (order.PayMode == 1)
+                            // {
+                            //     DateIndexStat.AlipayTotalAmount += PayMoney;
+                            //     DateIndexStat.AlipayTotalActual += TotalActual;
+                            // }
+                            // else if (order.PayMode == 2)
+                            // {
+                            //     DateIndexStat.WeChatTotalAmount += PayMoney;
+                            //     DateIndexStat.WeChatTotalActual += TotalActual;
+                            // }
+                            // RedisDbconn.Instance.Set("MerchantIndexStat:" + MerchantId + ":" + DateString, DateIndexStat);
 
-                            //统计创客数据
-                            RedisDbconn.Instance.AddNumber("TeamTradeStat:" + UserId + ":" + MonthString, PayMoney);
-                            RedisDbconn.Instance.AddNumber("TeamTradeStat:" + UserId + ":" + DateString, PayMoney);
-                            RedisDbconn.Instance.AddNumber("TeamTradeStat:" + UserId + ":" + PayMode + ":" + DateString, PayMoney);
-                            RedisDbconn.Instance.AddNumber("TeamTradeStat:" + UserId + ":" + PayMode + ":" + DateString, PayMoney);
+                            // List<string> Months = RedisDbconn.Instance.GetList<string>("ConsumerStat:" + MerchantId, 1, 1000);
+                            // if (!Months.Contains(MonthString))
+                            // {
+                            //     RedisDbconn.Instance.AddList("ConsumerStat:" + MerchantId, MonthString);
+                            // }
+                            // MerchantIndexStat MonthIndexStat = RedisDbconn.Instance.Get<MerchantIndexStat>("MerchantIndexStat:" + MerchantId + ":" + MonthString) ?? new MerchantIndexStat();
+                            // MonthIndexStat.TotalOrder += 1;
+                            // MonthIndexStat.TotalAmount += PayMoney;
+                            // MonthIndexStat.TotalActual += TotalActual;
+                            // if (order.PayMode == 1)
+                            // {
+                            //     MonthIndexStat.AlipayTotalAmount += PayMoney;
+                            //     MonthIndexStat.AlipayTotalActual += TotalActual;
+                            // }
+                            // else if (order.PayMode == 2)
+                            // {
+                            //     MonthIndexStat.WeChatTotalAmount += PayMoney;
+                            //     MonthIndexStat.WeChatTotalActual += TotalActual;
+                            // }
+                            // RedisDbconn.Instance.Set("MerchantIndexStat:" + MerchantId + ":" + MonthString, MonthIndexStat);
 
                         }
                     }
@@ -297,7 +292,7 @@ namespace MySystem
         }
 
         //分润算法
-        public void DoProfit(WebCMSEntities dbnew, ConsumerOrders trade_record)
+        public void DoProfit(WebCMSEntities dbnew, ConsumerOrders trade_record, bool IsActive = false)
         {
             MerchantInfo merchant = dbnew.MerchantInfo.FirstOrDefault(m => m.Id == trade_record.MerchantId) ?? new MerchantInfo();
             List<ProfitUsers> users = new List<ProfitUsers>();
@@ -331,9 +326,9 @@ namespace MySystem
             }
             string TradeMonth = trade_record.CreateDate.Value.ToString("yyyyMM");
             List<ProfitResult> list = new List<ProfitResult>();
-            list = StartProft(dbnew, trade_record, GetLevelKindId(1, 0, 1), users);
-            // using (var tran = dbnew.Database.BeginTransaction())
-            // {
+            list = StartProft(dbnew, trade_record, 1, users, IsActive);
+            using (var tran = dbnew.Database.BeginTransaction())
+            {
                 try
                 {
                     foreach (ProfitResult sub in list)
@@ -403,11 +398,11 @@ namespace MySystem
                         }
                     }
                     dbnew.SaveChanges();
-                    // tran.Commit();
+                    tran.Commit();
                 }
                 catch (Exception ex)
                 { 
-                    // tran.Rollback();
+                    tran.Rollback();
                     ErrorMsg msg = new ErrorMsg()
                     {
                         Time = DateTime.Now,
@@ -416,7 +411,7 @@ namespace MySystem
                     };
                     function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(msg), "MainServerProfitError");
                 }
-            // }
+            }
         }
 
         public void DoActives(WebCMSEntities dbnew, TradeRecord trade_record)
@@ -720,12 +715,10 @@ namespace MySystem
 
 
         #region 分润算法
-        public List<ProfitResult> StartProft(WebCMSEntities dbnew, ConsumerOrders trade, int LevelKindId, List<ProfitUsers> users)
+        public List<ProfitResult> StartProft(WebCMSEntities dbnew, ConsumerOrders trade, int LevelKindId, List<ProfitUsers> users, bool IsActive = true)
         {
             int BrandId = 1;
             decimal TradeMoney = trade.PayMoney;
-            int BankCardType = 0; //银行卡类型:贷记卡-0,借记卡-1
-            int MerHelpFlag = 0; //扶持期-1,稳定期=0
             List<UserLevelSet> levels = RedisDbconn.Instance.GetList<UserLevelSet>("pobjlevel");
             List<ProfitResult> result = new List<ProfitResult>();
             ProfitObjects obj = RedisDbconn.Instance.Get<ProfitObjects>("pobj" + BrandId);
@@ -735,7 +728,7 @@ namespace MySystem
                 int maxFloor = obj.MaxFloor; //最大层级
                 int maxContinueFloor = RedisDbconn.Instance.Get<int>("pobjconc" + BrandId); //最大继续分润层级
                 decimal diffLevelProfit = 0;  //等级级差
-                decimal diffDiviProfit = 0; //分红级差
+                // decimal diffDiviProfit = 0; //分红级差
                 int curLevel = 0; //当前层级的会员等级
                 for (int curFloor = 1; curFloor <= users.Count; curFloor++)
                 {
@@ -763,56 +756,10 @@ namespace MySystem
                         {
                             decimal getLevelProfit = 0;  //等级分润
                             UserProfitSet profitSet = new UserProfitSet();
-                            if (objlevel.Percents > 0)
+                            decimal profitPercent = IsActive ? objlevel.DebitPercents : objlevel.Percents;
+                            if (profitPercent > 0)
                             {
-                                //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
-                                decimal profitrate = 0;
-                                profitSet = dbnew.UserProfitSet.FirstOrDefault(m => m.UserId == user.UserId && m.BrandId == BrandId && m.CardType == BankCardType && m.HelpFlag == MerHelpFlag) ?? new UserProfitSet(); //获取创客分润规则-扶持期
-                                profitrate = profitSet.ProfitRate;
-                                profitrate = profitrate / 100;
-                                getLevelProfit += TradeMoney * objlevel.Percents * profitrate;
-                            }
-                            if (objlevel.AddProfitVal > 0)
-                            {
-                                //分红奖励:一个3000万,3000万以下市场总和大于1200万
-                                bool bigMarket = false;
-                                decimal smallMarket = 0;
-                                List<Users> directs = dbnew.Users.Where(m => m.ParentUserId == user.UserId).ToList();
-                                decimal BigMarketTradeAmt = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":Dividends:BigMarketTradeAmt")); //大市场交易额
-                                decimal PassTradeAmt = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":Dividends:PassTradeAmt")); //小市场交易超越额
-                                decimal UnitPrize = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":Dividends:UnitPrize")); //单位奖励基数
-                                foreach (Users direct in directs)
-                                {
-                                    UserData userData = dbnew.UserData.FirstOrDefault(m => m.UserId == direct.Id) ?? new UserData();
-                                    if (userData.TotalOrderMoney >= BigMarketTradeAmt)
-                                    {
-                                        bigMarket = true;
-                                    }
-                                    else
-                                    {
-                                        smallMarket += userData.TotalOrderMoney;
-                                    }
-                                }
-                                if (bigMarket && smallMarket >= PassTradeAmt)
-                                { 
-                                    decimal DiviPrize = objlevel.AddProfitVal * TradeMoney / UnitPrize;
-                                    decimal checkmoney = DiviPrize;
-                                    DiviPrize -= diffDiviProfit;
-                                    if (objlevel.LevelDiff == 1)  //判断是否有级差
-                                    {
-                                        diffDiviProfit = checkmoney;
-                                    }
-                                    if (DiviPrize >= obj.MinProfitVal)
-                                    {
-                                        result.Add(new ProfitResult()
-                                        {
-                                            UserId = user.UserId,
-                                            UserNav = user.UserNav,
-                                            Money = DiviPrize,
-                                            Message = "分红奖励",
-                                        });
-                                    }
-                                }
+                                getLevelProfit += TradeMoney * profitPercent;
                             }
                             decimal money = getLevelProfit;
                             getLevelProfit -= diffLevelProfit;

+ 2 - 2
AppStart/RabbitMQClient.cs

@@ -178,7 +178,7 @@ namespace MySystem
                 else if (QueueName == "AlipayPayBack")
                 {
                     JobMqMsg job = Newtonsoft.Json.JsonConvert.DeserializeObject<JobMqMsg>(MsgContent);
-                    AlipayPayBackService.Instance.Start(job);
+                    // AlipayPayBackService.Instance.Start(job);
                 }
                 else if (QueueName == "AlipayPayBack2")
                 {
@@ -207,7 +207,7 @@ namespace MySystem
                 }
                 else if (QueueName == "MerchantConfirmList")
                 {
-                    MerchantConfirmService.Instance.Start(MsgContent);
+                    // MerchantConfirmService.Instance.Start(MsgContent);
                 }
                 else if (QueueName == "DeleteMySqlData")
                 {

+ 1 - 0
PxcModels/ConsumerOrders.cs

@@ -27,5 +27,6 @@ namespace MySystem.PxcModels
         public int ConsumerId { get; set; }
         public int MerchantId { get; set; }
         public ulong IsAct { get; set; }
+        public int UserId { get; set; }
     }
 }

+ 24 - 0
PxcModels/MerchantAmountSummay.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.PxcModels
+{
+    public partial class MerchantAmountSummay
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int QueryCount { get; set; }
+        public int Status { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string SeoTitle { get; set; }
+        public string SeoKeyword { get; set; }
+        public string SeoDescription { get; set; }
+        public int PayMode { get; set; }
+        public decimal TotalActual { get; set; }
+        public decimal TradeAmount { get; set; }
+        public string TradeDate { get; set; }
+        public string TradeMonth { get; set; }
+        public int MerchantId { get; set; }
+    }
+}

+ 2 - 0
PxcModels/PosMerchantInfoBak.cs

@@ -43,5 +43,7 @@ namespace MySystem.PxcModels
         public string MerchantMobile { get; set; }
         public string MerchantName { get; set; }
         public string MerchantNo { get; set; }
+        public int StandardMonths { get; set; }
+        public int StandardStatus { get; set; }
     }
 }

+ 23 - 0
PxcModels/UserAmountSummary.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+
+namespace MySystem.PxcModels
+{
+    public partial class UserAmountSummary
+    {
+        public int Id { get; set; }
+        public int Sort { get; set; }
+        public int QueryCount { get; set; }
+        public int Status { get; set; }
+        public DateTime? CreateDate { get; set; }
+        public DateTime? UpdateDate { get; set; }
+        public string SeoTitle { get; set; }
+        public string SeoKeyword { get; set; }
+        public string SeoDescription { get; set; }
+        public int PayMode { get; set; }
+        public decimal TotalAmount { get; set; }
+        public string TradeMonth { get; set; }
+        public string TradeDate { get; set; }
+        public int UserId { get; set; }
+    }
+}

+ 105 - 0
PxcModels/WebCMSEntities.cs

@@ -83,6 +83,7 @@ namespace MySystem.PxcModels
         public virtual DbSet<MenuRight> MenuRight { get; set; }
         public virtual DbSet<MerchantAddInfo> MerchantAddInfo { get; set; }
         public virtual DbSet<MerchantAdmin> MerchantAdmin { get; set; }
+        public virtual DbSet<MerchantAmountSummay> MerchantAmountSummay { get; set; }
         public virtual DbSet<MerchantAuth> MerchantAuth { get; set; }
         public virtual DbSet<MerchantClass> MerchantClass { get; set; }
         public virtual DbSet<MerchantCol> MerchantCol { get; set; }
@@ -221,6 +222,7 @@ namespace MySystem.PxcModels
         public virtual DbSet<UserAccount> UserAccount { get; set; }
         public virtual DbSet<UserAccountRecord> UserAccountRecord { get; set; }
         public virtual DbSet<UserAddress> UserAddress { get; set; }
+        public virtual DbSet<UserAmountSummary> UserAmountSummary { get; set; }
         public virtual DbSet<UserAuthRecord> UserAuthRecord { get; set; }
         public virtual DbSet<UserBack> UserBack { get; set; }
         public virtual DbSet<UserBackKind> UserBackKind { get; set; }
@@ -2160,6 +2162,8 @@ namespace MySystem.PxcModels
                     .HasCharSet("utf8")
                     .HasCollation("utf8_general_ci");
 
+                entity.Property(e => e.UserId).HasColumnType("int(11)");
+
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
@@ -5397,6 +5401,54 @@ namespace MySystem.PxcModels
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<MerchantAmountSummay>(entity =>
+            {
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.MerchantId).HasColumnType("int(11)");
+
+                entity.Property(e => e.PayMode).HasColumnType("int(11)");
+
+                entity.Property(e => e.QueryCount).HasColumnType("int(11)");
+
+                entity.Property(e => e.SeoDescription)
+                    .HasColumnType("varchar(500)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoKeyword)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoTitle)
+                    .HasColumnType("varchar(100)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort).HasColumnType("int(11)");
+
+                entity.Property(e => e.Status).HasColumnType("int(11)");
+
+                entity.Property(e => e.TotalActual).HasColumnType("decimal(18,2)");
+
+                entity.Property(e => e.TradeAmount).HasColumnType("decimal(18,2)");
+
+                entity.Property(e => e.TradeDate)
+                    .HasColumnType("varchar(8)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.UpdateDate).HasColumnType("datetime");
+            });
+
             modelBuilder.Entity<MerchantAuth>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");
@@ -8859,6 +8911,9 @@ namespace MySystem.PxcModels
 
             modelBuilder.Entity<PosMerchantInfoBak>(entity =>
             {
+                entity.HasIndex(e => new { e.KqSnNo, e.KqMerNo })
+                    .HasName("PosMerchantInfoBakIndex");
+
                 entity.Property(e => e.Id).HasColumnType("int(11)");
 
                 entity.Property(e => e.ActType).HasColumnType("int(11)");
@@ -8975,6 +9030,10 @@ namespace MySystem.PxcModels
 
                 entity.Property(e => e.Sort).HasColumnType("int(11)");
 
+                entity.Property(e => e.StandardMonths).HasColumnType("int(11)");
+
+                entity.Property(e => e.StandardStatus).HasColumnType("int(11)");
+
                 entity.Property(e => e.Status).HasColumnType("int(11)");
 
                 entity.Property(e => e.TopUserId).HasColumnType("int(11)");
@@ -15041,6 +15100,52 @@ namespace MySystem.PxcModels
                 entity.Property(e => e.Version).HasColumnType("int(11)");
             });
 
+            modelBuilder.Entity<UserAmountSummary>(entity =>
+            {
+                entity.Property(e => e.Id).HasColumnType("int(11)");
+
+                entity.Property(e => e.CreateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.PayMode).HasColumnType("int(11)");
+
+                entity.Property(e => e.QueryCount).HasColumnType("int(11)");
+
+                entity.Property(e => e.SeoDescription)
+                    .HasColumnType("varchar(500)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoKeyword)
+                    .HasColumnType("varchar(200)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.SeoTitle)
+                    .HasColumnType("varchar(100)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.Sort).HasColumnType("int(11)");
+
+                entity.Property(e => e.Status).HasColumnType("int(11)");
+
+                entity.Property(e => e.TotalAmount).HasColumnType("decimal(18,2)");
+
+                entity.Property(e => e.TradeDate)
+                    .HasColumnType("varchar(8)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.TradeMonth)
+                    .HasColumnType("varchar(6)")
+                    .HasCharSet("utf8")
+                    .HasCollation("utf8_general_ci");
+
+                entity.Property(e => e.UpdateDate).HasColumnType("datetime");
+
+                entity.Property(e => e.UserId).HasColumnType("int(11)");
+            });
+
             modelBuilder.Entity<UserAuthRecord>(entity =>
             {
                 entity.Property(e => e.Id).HasColumnType("int(11)");

+ 2 - 0
Startup.cs

@@ -171,6 +171,8 @@ namespace MySystem
             });
 
             //必须打开的
+            MerchantConfirmService.Instance.Start();
+            CheckWeChatSignService.Instance.Start();
             ProfitHelper.Instance.StartListenTrade();
             //必须打开的
         }