123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- using System.Data;
- using MySystem;
- using MySystem.PxcModels;
- using Library;
- public class TestHelper
- {
- public readonly static TestHelper Instance = new TestHelper();
- private TestHelper()
- {
- }
-
- public void Start()
- {
- Thread th = new Thread(StartEverDay);
- th.IsBackground = true;
- th.Start();
- }
- public void StartEverDay()
- {
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
- DateTime end = DateTime.Parse("2022-04-19 00:00:00");
- DateTime check = DateTime.Parse("2022-03-11");
- while (check <= end)
- {
- StatMerchantTrade(check.ToString("yyyy-MM-dd"));
- check = check.AddDays(1);
- }
- }
- private void StatMerchantTrade(string date)
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "执行商户交易额日志");
- WebCMSEntities db = new WebCMSEntities();
- try
- {
- DataTable selfdt = OtherMySqlConn.dtable("select MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') as TradeDate,sum(TradeAmount) as TradeAmount from TradeRecord group by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d') order by MerchantId,BrandId,DATE_FORMAT(CreateDate,'%Y-%m-%d')");
- foreach (DataRow selfDr in selfdt.Rows)
- {
- int BrandId = int.Parse(selfDr["BrandId"].ToString());
- int MerchantId = int.Parse(selfDr["MerchantId"].ToString());
- string TradeDate = selfDr["TradeDate"].ToString();
- TradeDate = TradeDate.Replace("-", "");
- string TradeMonth = TradeDate.Substring(0, 6);
- decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString());
- PosMerchantTradeSummay merStat = db.PosMerchantTradeSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId);
- if (merStat == null)
- {
- merStat = db.PosMerchantTradeSummay.Add(new PosMerchantTradeSummay()
- {
- MerchantId = MerchantId,
- TradeMonth = TradeMonth,
- TradeDate = TradeDate,
- BrandId = BrandId,
- }).Entity;
- db.SaveChanges();
- }
- merStat.TradeAmount += TradeAmount;
- db.SaveChanges();
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额");
- }
- db.Dispose();
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行商户交易额日志");
- }
- //统计团队交易额(小市场)
- public void teamTrade()
- {
- Dictionary<int, decimal> userdic = new Dictionary<int, decimal>();
- WebCMSEntities db = new WebCMSEntities();
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
- function.WriteLog("start:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
- DataTable dt = OtherMySqlConn.dtable("select UserId,sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectDebitTradeAmt+NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where TradeMonth='202208' and SeoTitle='team' group by UserId");
- function.WriteLog("ready:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
- foreach(DataRow dr in dt.Rows)
- {
- int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
- decimal TradeAmount = decimal.Parse(function.CheckNum(dr[1].ToString()));
- userdic.Add(UserId, TradeAmount);
- }
- function.WriteLog("1:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
- Dictionary<int, decimal> userdic1 = userdic.Where(m => m.Value >= 3000000 && m.Value <= 10000000).ToDictionary(m => m.Key, m => m.Value);
- function.WriteLog("3000000:" + userdic1.Count(), "团队交易额名单");
- foreach(int UserId in userdic1.Keys)
- {
- decimal curTotal = userdic1[UserId];
- List<int> ids = new List<int>();
- Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(self.ParentNav))
- {
- string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
- string[] uidlist = uidstring.Split(',');
- if (uidlist.Length > 1)
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[1]));
- }
- else
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[0]));
- }
- }
- Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
- foreach(var user in users)
- {
- ids.Add(user.Id);
- }
- int index = 0;
- decimal totalAmt = 0;
- decimal maxAmt = 0;
- Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
- foreach(int key in dic.Keys)
- {
- index += 1;
- if(index > 1)
- {
- totalAmt += dic[key];
- }
- else
- {
- maxAmt = dic[key];
- }
- }
- if(totalAmt >= 1200000)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于120万的名单");
- }
- if(totalAmt >= curTotal * 0.4M)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额300万-1000万且小市场大于40%的名单");
- }
- function.WriteLog(UserId.ToString(), "团队交易额名单");
- }
- Dictionary<int, decimal> userdic2 = userdic.Where(m => m.Value >= 10000000 && m.Value <= 100000000).ToDictionary(m => m.Key, m => m.Value);
- function.WriteLog("10000000:" + userdic2.Count(), "团队交易额名单");
- foreach(int UserId in userdic2.Keys)
- {
- decimal curTotal = userdic2[UserId];
- List<int> ids = new List<int>();
- Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(self.ParentNav))
- {
- string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
- string[] uidlist = uidstring.Split(',');
- if (uidlist.Length > 1)
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[1]));
- }
- else
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[0]));
- }
- }
- Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
- foreach(var user in users)
- {
- ids.Add(user.Id);
- }
- int index = 0;
- decimal totalAmt = 0;
- decimal maxAmt = 0;
- Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
- foreach(int key in dic.Keys)
- {
- index += 1;
- if(index > 1)
- {
- totalAmt += dic[key];
- }
- else
- {
- maxAmt = dic[key];
- }
- }
- if(totalAmt >= 4000000)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于400万的名单");
- }
- if(totalAmt >= curTotal * 0.4M)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1000万-1亿且小市场大于40%的名单");
- }
- function.WriteLog(UserId.ToString(), "团队交易额名单");
- }
- Dictionary<int, decimal> userdic3 = userdic.Where(m => m.Value >= 100000000).ToDictionary(m => m.Key, m => m.Value);
- function.WriteLog("100000000:" + userdic3.Count(), "团队交易额名单");
- foreach(int UserId in userdic3.Keys)
- {
- decimal curTotal = userdic3[UserId];
- List<int> ids = new List<int>();
- Users self = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(self.ParentNav))
- {
- string uidstring = self.ParentNav.Trim(',').Replace(",,", ",");
- string[] uidlist = uidstring.Split(',');
- if (uidlist.Length > 1)
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[1]));
- }
- else
- {
- TopUserId = int.Parse(function.CheckInt(uidlist[0]));
- }
- }
- Users top = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- var users = db.Users.Select(m => new { m.Id, m.ParentUserId }).Where(m => m.ParentUserId == UserId).ToList();
- foreach(var user in users)
- {
- ids.Add(user.Id);
- }
- int index = 0;
- decimal totalAmt = 0;
- decimal maxAmt = 0;
- Dictionary<int, decimal> dic = userdic.Where(m => ids.Contains(m.Key)).OrderByDescending(m => m.Value).ToDictionary(m => m.Key, m => m.Value);
- foreach(int key in dic.Keys)
- {
- index += 1;
- if(index > 1)
- {
- totalAmt += dic[key];
- }
- else
- {
- maxAmt = dic[key];
- }
- }
- if(totalAmt >= 40000000)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于4000万的名单");
- }
- if(totalAmt >= curTotal * 0.4M)
- {
- function.WriteLog(self.MakerCode + "--" + self.RealName + "--" + self.Mobile + "--" + top.MakerCode + "--" + top.RealName + "--" + top.Mobile + "--" + curTotal + "--" + maxAmt + "--" + totalAmt, "团队交易额1亿以上且小市场大于40%的名单");
- }
- function.WriteLog(UserId.ToString(), "团队交易额名单");
- }
- db.Dispose();
- function.WriteLog("end:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "团队交易额名单");
- }
- }
|