TestService.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class TestService
  12. {
  13. public readonly static TestService Instance = new TestService();
  14. private TestService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(ReduceMoreSubsidy);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void ResetTradeRecordUserId()
  23. {
  24. WebCMSEntities db = new WebCMSEntities();
  25. List<int> posids = new List<int>();
  26. posids.Add(13312);
  27. // OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  28. foreach (int posid in posids)
  29. {
  30. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posid);
  31. if (pos != null)
  32. {
  33. // OtherMySqlConn.op("update TradeRecord set UserId=" + pos.UserId + " where SnNo='" + pos.PosSn + "'");
  34. // function.WriteLog(DateTime.Now.ToString() + ":" + pos.UserId + "-" + pos.PosSn, "重置非商户型创客交易记录Id");
  35. RedisDbconn.Instance.AddList("TmpResetUserTradeQueue", pos.UserId + "#cut#2022-04-01 00:00:00#cut#2022-05-11 00:00:00#cut#" + pos.BrandId);
  36. }
  37. }
  38. // // OtherMySqlConn.connstr = ;
  39. db.Dispose();
  40. }
  41. public void StartReset()
  42. {
  43. Thread th = new Thread(doSomething);
  44. th.IsBackground = true;
  45. th.Start();
  46. }
  47. public void doSomething()
  48. {
  49. while (true)
  50. {
  51. string content = RedisDbconn.Instance.RPop<string>("TmpResetUserTradeQueue");
  52. if (!string.IsNullOrEmpty(content))
  53. {
  54. try
  55. {
  56. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  57. WebCMSEntities db = new WebCMSEntities();
  58. string[] datalist = content.Split(new string[] { "#cut#" }, StringSplitOptions.None);
  59. int UserId = int.Parse(datalist[0]);
  60. DateTime sdate = DateTime.Parse(datalist[1]);
  61. DateTime edate = DateTime.Parse(datalist[2]);
  62. int BrandId = int.Parse(datalist[3]);
  63. function.WriteLog(DateTime.Now.ToString(), "重置创客交易额");
  64. List<string> uids = new List<string>();
  65. DataTable userDt = OtherMySqlConn.dtable("select Id,ParentNav from Users where Id=" + UserId);
  66. if (userDt.Rows.Count > 0)
  67. {
  68. while (sdate <= edate)
  69. {
  70. string date = sdate.ToString("yyyy-MM-dd");
  71. string TradeDate = date.Replace("-", "");
  72. string TradeMonth = TradeDate.Substring(0, 6);
  73. string start = date + " 00:00:00";
  74. string end = DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00";
  75. string startId = "0", endId = "9999999999";
  76. DataTable startDt = OtherMySqlConn.dtable("select min(Id) from TradeRecord where CreateDate>='" + start + "'");
  77. if (startDt.Rows.Count > 0)
  78. {
  79. startId = startDt.Rows[0][0].ToString();
  80. }
  81. DataRow userDr = userDt.Rows[0];
  82. string ParentNav = userDr["ParentNav"].ToString();
  83. function.WriteLog(UserId + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行昨天交易额日志");
  84. OtherMySqlConn.op("delete from UserTradeDaySummary where UserId=" + UserId + " and BrandId=" + BrandId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and SeoTitle='self'");
  85. DataTable selfdt = OtherMySqlConn.dtable("select BrandId,BankCardType,QrPayFlag,sum(TradeAmount) from TradeRecord where Id>=" + startId + " and Id<=" + endId + " and CreateDate>='" + start + "' and CreateDate<'" + end + "' and UserId=" + UserId + " and BrandId=" + BrandId + " group by BrandId,BankCardType,QrPayFlag");
  86. function.WriteLog(UserId + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行昨天交易额日志");
  87. foreach (DataRow selfDr in selfdt.Rows)
  88. {
  89. int BankCardType = int.Parse(selfDr["BankCardType"].ToString());
  90. int QrPayFlag = int.Parse(selfDr["QrPayFlag"].ToString());
  91. decimal TradeAmount = decimal.Parse(selfDr[3].ToString());
  92. UserTradeDaySummary selfStat = db.UserTradeDaySummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId && m.QueryCount == QrPayFlag && m.SeoTitle == "self");
  93. if (selfStat == null)
  94. {
  95. selfStat = db.UserTradeDaySummary.Add(new UserTradeDaySummary()
  96. {
  97. UserId = UserId,
  98. TradeMonth = TradeMonth,
  99. TradeDate = TradeDate,
  100. BrandId = BrandId,
  101. QueryCount = QrPayFlag,
  102. SeoTitle = "self",
  103. }).Entity;
  104. db.SaveChanges();
  105. }
  106. if (BankCardType == 0)
  107. {
  108. selfStat.DirectDebitTradeAmt += TradeAmount;
  109. }
  110. else if (BankCardType != 0)
  111. {
  112. selfStat.DirectTradeAmt += TradeAmount;
  113. }
  114. db.SaveChanges();
  115. }
  116. if (!string.IsNullOrEmpty(ParentNav))
  117. {
  118. ParentNav += "," + UserId + ",";
  119. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  120. foreach (string NavUserIdString in ParentNavList)
  121. {
  122. if (!uids.Contains(NavUserIdString + start))
  123. {
  124. uids.Add(NavUserIdString + start);
  125. int NavUserId = int.Parse(NavUserIdString);
  126. function.WriteLog(NavUserId + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行昨天交易额日志");
  127. OtherMySqlConn.op("delete from UserTradeDaySummary where UserId=" + NavUserId + " and BrandId=" + BrandId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and SeoTitle='team'");
  128. DataTable teamDt = OtherMySqlConn.dtable("select BrandId,BankCardType,QrPayFlag,sum(TradeAmount) from TradeRecord where Id>=" + startId + " and Id<=" + endId + " and CreateDate>='" + start + "' and CreateDate<'" + end + "' and UserId in (select Id from Users where ParentNav like '%," + NavUserId + ",%' or Id=" + NavUserId + ") and BrandId=" + BrandId + " group by BrandId,BankCardType,QrPayFlag");
  129. function.WriteLog(NavUserId + ":" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "执行昨天交易额日志");
  130. foreach (DataRow teamDr in teamDt.Rows)
  131. {
  132. int BankCardType = int.Parse(teamDr["BankCardType"].ToString());
  133. int QrPayFlag = int.Parse(teamDr["QrPayFlag"].ToString());
  134. decimal TradeAmount = decimal.Parse(teamDr[3].ToString());
  135. UserTradeDaySummary teamStat = db.UserTradeDaySummary.FirstOrDefault(m => m.UserId == NavUserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId && m.QueryCount == QrPayFlag && m.SeoTitle == "team");
  136. if (teamStat == null)
  137. {
  138. teamStat = db.UserTradeDaySummary.Add(new UserTradeDaySummary()
  139. {
  140. UserId = NavUserId,
  141. TradeMonth = TradeMonth,
  142. TradeDate = TradeDate,
  143. BrandId = BrandId,
  144. QueryCount = QrPayFlag,
  145. SeoTitle = "team",
  146. }).Entity;
  147. db.SaveChanges();
  148. }
  149. if (BankCardType == 0)
  150. {
  151. teamStat.NonDirectDebitTradeAmt += TradeAmount;
  152. }
  153. else if (BankCardType != 0)
  154. {
  155. teamStat.NonDirectTradeAmt += TradeAmount;
  156. }
  157. db.SaveChanges();
  158. }
  159. }
  160. }
  161. }
  162. sdate = sdate.AddDays(1);
  163. Thread.Sleep(200);
  164. }
  165. }
  166. db.Dispose();
  167. function.WriteLog(DateTime.Now.ToString() + "\r\n\r\n", "重置创客交易额");
  168. }
  169. catch (Exception ex)
  170. {
  171. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "重置创客交易额异常");
  172. }
  173. }
  174. else
  175. {
  176. Thread.Sleep(5000);
  177. }
  178. }
  179. }
  180. public void statTrade()
  181. {
  182. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  183. WebCMSEntities db = new WebCMSEntities();
  184. DataTable dt = OtherMySqlConn.dtable("select UserId,BrandId,MerchantId,QrPayFlag,PayType,VipFlag,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(TradeAmount) from TradeRecord where Id>=574439 and UserId>0 and MerchantId in (5962,32731,14396,14,855,2586,2911,1839,6368,2598,79,47,21884,3243,3259,11637,5082,9767,5381,7091,4652,16159,24752,6183,18417,5285,17980,20862,3678,6567,11,21529,2647,10799,9024,24367,17045,14977,17249,847,3901,35077,21982,4496,5121,1383,153,12051,13036,20036,24984,21155,4720,15512,26592,4073,15241,7981,7079,9853,23689,24284,23731,4103,5959,85,31,24936,23781,9566,5658,10898,4929,26997,248,15916,9444,4760,7022,8697,9754,3482,255,793,14351,14149,3049,13390,3796,9209,27862,656,2413,9017,1649,282,8,14112,16313,15545,5639,2809,3733,16717,11541,9774,18000,20341,20273,10047,16151,28510,20193,4650,2498,2597,23242,11325,34592,12362,29281,15165,208,2196,3709,2715,6494,16034,3368,17283,4513,3309,2979,2854,6497,251,17906,7598,2327,6856,2347,2675,4,10991,138,784,350,7961,3385,29349,23533,31893,5036,15382,6934,3778,5922,24357,6222,6755,8887) and CreateDate>='2022-06-01 00:00:00' and MerHelpFlag=1 and BankCardType!=0 and CreateDate<'2022-07-01 00:00:00' group by UserId,BrandId,MerchantId,QrPayFlag,PayType,VipFlag,DATE_FORMAT(CreateDate,'%Y%m%d') order by DATE_FORMAT(CreateDate,'%Y%m%d')");
  185. List<string> IdBrands = new List<string>();
  186. if(dt.Rows.Count > 0)
  187. {
  188. foreach(DataRow dr in dt.Rows)
  189. {
  190. int UserId = int.Parse(dr["UserId"].ToString());
  191. int MerchantId = int.Parse(dr["MerchantId"].ToString());
  192. int BrandId = int.Parse(dr["BrandId"].ToString());
  193. int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
  194. int PayType = int.Parse(dr["PayType"].ToString());
  195. int VipFlag = int.Parse(dr["VipFlag"].ToString());
  196. string TradeDate = dr[6].ToString();
  197. decimal HelpDirectTradeAmt = decimal.Parse(dr[7].ToString());
  198. function.WriteLog("update TradeDaySummary set HelpDirectTradeAmt=HelpDirectTradeAmt-" + HelpDirectTradeAmt + ",NotHelpDirectTradeAmt=NotHelpDirectTradeAmt+" + HelpDirectTradeAmt + " where UserId=" + UserId + " and BrandId=" + BrandId + " and TradeDate='" + TradeDate + "' and QueryCount=" + QrPayFlag + " and PayType=" + PayType + " and VipFlag=" + VipFlag + " and SeoTitle='self';\n", "多余机器分润");
  199. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  200. string ParentNav = user.ParentNav;
  201. ParentNav += "," + UserId + ",";
  202. if (!string.IsNullOrEmpty(ParentNav))
  203. {
  204. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  205. foreach (string NavUserIdString in ParentNavList)
  206. {
  207. function.WriteLog("update TradeDaySummary set HelpNonDirectTradeAmt=HelpNonDirectTradeAmt-" + HelpDirectTradeAmt + ",NotHelpNonDirectTradeAmt=NotHelpNonDirectTradeAmt+" + HelpDirectTradeAmt + " where UserId=" + NavUserIdString + " and BrandId=" + BrandId + " and TradeDate='" + TradeDate + "' and QueryCount=" + QrPayFlag + " and PayType=" + PayType + " and VipFlag=" + VipFlag + " and SeoTitle='team';\n", "多余机器分润");
  208. }
  209. }
  210. List<ProfitResult> results = StartProftForPosByDate(BrandId, UserId, HelpDirectTradeAmt);
  211. foreach(ProfitResult result in results)
  212. {
  213. int DirectFlag = result.DirectFlag;
  214. function.WriteLog("update ProfitRecord set ProfitAmount=ProfitAmount-" + result.Money + " where UserId=" + result.UserId + " and SeoTitle='202206' and DirectFlag=" + DirectFlag + " and BrandId=" + BrandId + ";\n", "多余机器分润");
  215. function.WriteLog("update UserMachineData set TradeProfit=TradeProfit-" + result.Money + " where IdBrand='" + UserId + "_" + BrandId + "';\n", "多余机器分润");
  216. }
  217. if(!IdBrands.Contains(UserId+"-"+MerchantId))
  218. {
  219. IdBrands.Add(UserId + "-" + MerchantId);
  220. DataTable sub = OtherMySqlConn.dtable("select SubsidyProfit from ProfitSubsidyDetail where TradeMonth='202206' and SubsidyUserId=" + UserId + " and MerchantId=" + MerchantId + "");
  221. if(sub.Rows.Count > 0)
  222. {
  223. string SubsidyProfit = sub.Rows[0][0].ToString();
  224. function.WriteLog("delete from ProfitSubsidyDetail where TradeMonth='202206' and SubsidyUserId=" + UserId + " and MerchantId=" + MerchantId + ";\n", "多余机器分润");
  225. function.WriteLog("update UserMachineData set OtherProfit=OtherProfit-" + SubsidyProfit + " where IdBrand='" + UserId + "_" + BrandId + "';\n", "多余机器分润");
  226. }
  227. }
  228. }
  229. }
  230. db.Dispose();
  231. }
  232. public List<ProfitResult> StartProftForPosByDate(int BrandId, int UserId, decimal HelpDirectTradeAmt)
  233. {
  234. List<ProfitResult> result = new List<ProfitResult>();
  235. // ProfitObjects obj = RedisDbconn.Instance.Get<ProfitObjects>("pobj" + BrandId);
  236. // if (obj.Status == 1) //判断分润是否开启
  237. // {
  238. // WebCMSEntities dbnew = new WebCMSEntities();
  239. // try
  240. // {
  241. // List<UserLevelSet> levels = dbnew.UserLevelSet.ToList();
  242. // Users selfUser = dbnew.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  243. // int Days = int.Parse(RedisDbconn.Instance.Get<string>("pobjrule:" + BrandId + ":HelpPolicy:Days")); //天数
  244. // int maxLevel = obj.MaxLevel; //最大等级
  245. // decimal diffLevelProfit = 0; //等级级差
  246. // int curLevel = 0; //当前层级的会员等级
  247. // string ParentNav = selfUser.ParentNav;
  248. // if (string.IsNullOrEmpty(ParentNav))
  249. // {
  250. // ParentNav = ",0,";
  251. // }
  252. // if (!string.IsNullOrEmpty(ParentNav))
  253. // {
  254. // ParentNav += "," + UserId + ",";
  255. // string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  256. // Array.Reverse(ParentNavList); //反转顺序
  257. // int level = 0;
  258. // DateTime now = DateTime.Now;
  259. // if (HelpDirectTradeAmt > 0)
  260. // {
  261. // foreach (string UserIdString in ParentNavList)
  262. // {
  263. // level += 1;
  264. // int uid = int.Parse(UserIdString);
  265. // Users user = dbnew.Users.FirstOrDefault(m => m.Id == uid) ?? new Users();
  266. // int UserLevel = user.UserLevel; //当前会员等级
  267. // UserRankWhite rank = dbnew.UserRankWhite.FirstOrDefault(m => m.Id == user.Id && m.UpdateDate > now);
  268. // if (rank != null)
  269. // {
  270. // if (rank.Rank > UserLevel)
  271. // {
  272. // UserLevel = rank.Rank;
  273. // }
  274. // }
  275. // if (curLevel == maxLevel) //判断当前创客是否有直推的激活机具,并且在活动时间内
  276. // {
  277. // break;
  278. // }
  279. // if (UserLevel <= maxLevel && UserLevel > curLevel)
  280. // {
  281. // int LevelKindId = ProfitHelperV2.Instance.GetLevelKindId(BrandId, 1, 1);
  282. // ProfitObjectLevels objlevel = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId + ":" + UserLevel); //获取当前等级参数
  283. // int LevelKindId2 = ProfitHelperV2.Instance.GetLevelKindId(BrandId, 0, 1);
  284. // ProfitObjectLevels objlevel2 = RedisDbconn.Instance.Get<ProfitObjectLevels>("pobjlv" + LevelKindId2 + ":" + UserLevel); //获取当前等级参数
  285. // if (objlevel != null && objlevel2 != null)
  286. // {
  287. // decimal getLevelProfit = 0; //等级分润
  288. // if (objlevel.Percents > 0 && objlevel2.Percents > 0)
  289. // {
  290. // //获取创客分润规则,注册日开始算起,3个自然月内算扶持期
  291. // getLevelProfit += HelpDirectTradeAmt * (objlevel.Percents - objlevel2.Percents);
  292. // }
  293. // decimal money = getLevelProfit;
  294. // getLevelProfit -= diffLevelProfit;
  295. // diffLevelProfit = money;
  296. // if (getLevelProfit >= obj.MinProfitVal)
  297. // {
  298. // result.Add(new ProfitResult()
  299. // {
  300. // UserId = user.Id,
  301. // UserNav = user.ParentNav,
  302. // Money = PublicFunction.NumberFormat(getLevelProfit),
  303. // ProfitRate = objlevel.Percents,
  304. // Message = "交易分润",
  305. // BankCardType = 1,
  306. // DirectFlag = selfUser.Id == user.Id ? 1 : 0,
  307. // BrandId = BrandId,
  308. // IsSubsidy = 0,
  309. // TradeAmount = HelpDirectTradeAmt,
  310. // HelpFlag = 1,
  311. // });
  312. // }
  313. // }
  314. // }
  315. // curLevel = UserLevel;
  316. // }
  317. // }
  318. // }
  319. // }
  320. // catch (Exception ex)
  321. // {
  322. // function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "每月统计分润异常");
  323. // }
  324. // dbnew.Dispose();
  325. // }
  326. return result;
  327. }
  328. public void helpprofit()
  329. {
  330. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  331. DataTable dt = OtherMySqlConn.dtable("select Id,KqMerNo from PosMerchantInfo where Id in (select MerchantId from HelpProfitMerchantForUser) and BrandId!=1");
  332. foreach(DataRow dr in dt.Rows)
  333. {
  334. int MerchantId = int.Parse(dr["Id"].ToString());
  335. string KqMerNo = dr["KqMerNo"].ToString();
  336. int Id = RedisDbconn.Instance.RPop<int>("HelpProfitMerchantIds");
  337. if(Id > 0)
  338. {
  339. OtherMySqlConn.op("update HelpProfitMerIds set MerchantId=" + Id + " where MerchantId=" + MerchantId + "");
  340. OtherMySqlConn.op("update PosMerchantInfo set SeoKeyword='' where Id=" + MerchantId);
  341. OtherMySqlConn.op("update PosMerchantInfo set SeoKeyword='已被申领为商机' where Id=" + Id);
  342. OtherMySqlConn.op("update PosCoupons set HelpProfitMerchantId=" + Id + " where HelpProfitMerchantId=" + MerchantId + "");
  343. OtherMySqlConn.op("update HelpProfitMerchantForUser set MerchantId=" + Id + ",Sort=1,MerNo='" + KqMerNo + "' where MerchantId=" + MerchantId + "");
  344. }
  345. }
  346. }
  347. #region 每月交易额统计
  348. public void tradeAmt()
  349. {
  350. while(true)
  351. {
  352. if(DateTime.Now.Hour > 4)
  353. {
  354. tradeAmtDo();
  355. }
  356. Thread.Sleep(60000);
  357. }
  358. }
  359. public void tradeAmtDo()
  360. {
  361. function.WriteLog("start:" + DateTime.Now.ToString(), "每月交易额统计");
  362. string month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  363. string html = "<table>";
  364. html += "<tr>";
  365. html += "<td>创客编号</td>";
  366. html += "<td>创客名称</td>";
  367. html += "<td>创客身份证号</td>";
  368. html += "<td>创客手机号</td>";
  369. html += "<td>顶级创客编号</td>";
  370. html += "<td>顶级创客名称</td>";
  371. html += "<td>交易额</td>";
  372. html += "<td>最大市场交易额</td>";
  373. html += "</tr>";
  374. WebCMSEntities db = new WebCMSEntities();
  375. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  376. DataTable dt = OtherMySqlConn.dtable("select UserId,sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectCreditTradeAmt+NotHelpNonDirectCreditTradeAmt) from TradeDaySummary where Id>=2194025 and TradeMonth='" + month + "' and SeoTitle='team' group by UserId having sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectCreditTradeAmt+NotHelpNonDirectCreditTradeAmt)>=3000000 and sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectCreditTradeAmt+NotHelpNonDirectCreditTradeAmt)<10000000");
  377. function.WriteLog("总数:" + dt.Rows.Count, "每月交易额统计");
  378. foreach(DataRow dr in dt.Rows)
  379. {
  380. int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
  381. decimal TradeAmt = decimal.Parse(function.CheckNum(dr[1].ToString()));
  382. decimal MaxTradeAmt = 0;
  383. List<decimal> subTradeAmtList = new List<decimal>();
  384. DataTable subdt = OtherMySqlConn.dtable("select Id from Users where ParentUserId=" + UserId + " and AuthFlag=1");
  385. foreach(DataRow subdr in subdt.Rows)
  386. {
  387. int SubUserId = int.Parse(function.CheckInt(subdr["Id"].ToString()));
  388. decimal subTradeAmt = 0;
  389. DataTable subuserdt = OtherMySqlConn.dtable("select sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectCreditTradeAmt+NotHelpNonDirectCreditTradeAmt) from TradeDaySummary where Id>=2194025 and TradeMonth='" + month + "' and SeoTitle='team' and UserId=" + SubUserId);
  390. if(subuserdt.Rows.Count > 0)
  391. {
  392. subTradeAmt = decimal.Parse(function.CheckNum(subuserdt.Rows[0][0].ToString()));
  393. }
  394. subTradeAmtList.Add(subTradeAmt);
  395. }
  396. if(subTradeAmtList.Count > 0)
  397. {
  398. MaxTradeAmt = subTradeAmtList.Max(m => m);
  399. }
  400. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  401. int TopUserId = 0;
  402. string ParentNav = user.ParentNav;
  403. if (!string.IsNullOrEmpty(ParentNav))
  404. {
  405. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  406. if (ParentNavList.Length > 1)
  407. {
  408. TopUserId = int.Parse(ParentNavList[1]);
  409. }
  410. else if (ParentNavList.Length == 1)
  411. {
  412. TopUserId = int.Parse(ParentNavList[0]);
  413. }
  414. }
  415. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  416. html += "<tr>";
  417. html += "<td>" + user.MakerCode + "</td>";
  418. html += "<td>" + user.RealName + "</td>";
  419. html += "<td>" + user.CertId + "</td>";
  420. html += "<td>" + user.Mobile + "</td>";
  421. html += "<td>" + tuser.MakerCode + "</td>";
  422. html += "<td>" + tuser.RealName + "</td>";
  423. html += "<td>" + TradeAmt + "</td>";
  424. html += "<td>" + MaxTradeAmt + "</td>";
  425. html += "</tr>";
  426. function.WriteLog(DateTime.Now.ToString(), "每月交易额统计");
  427. function.WriteLog(UserId.ToString(), "每月交易额统计");
  428. }
  429. html += "</table>";
  430. db.SaveChanges();
  431. function.WritePage("/htmlfile/", month + ".html", html);
  432. function.WriteLog("end:" + DateTime.Now.ToString(), "每月交易额统计");
  433. }
  434. #endregion
  435. #region 查找8月多余补贴
  436. // public void Subsidy()
  437. // {
  438. // while(true)
  439. // {
  440. // if(DateTime.Now.Hour > 4)
  441. // {
  442. // SubsidyDo();
  443. // }
  444. // Thread.Sleep(60000);
  445. // }
  446. // }
  447. public void SubsidyDo()
  448. {
  449. WebCMSEntities db = new WebCMSEntities();
  450. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  451. DataTable dt = OtherMySqlConn.dtable("select UserId,ProductType,ChangeAmount from UserAccountRecord where ChangeType=111 and CreateDate>='2022-09-01 00:00:00' and CreateDate<'2022-10-01 00:00:00' order by Id");
  452. function.WriteLog("总数:" + dt.Rows.Count, "查找8月多余补贴");
  453. foreach(DataRow dr in dt.Rows)
  454. {
  455. int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
  456. int ProductType = int.Parse(function.CheckInt(dr["ProductType"].ToString()));
  457. decimal ChangeAmount = decimal.Parse(function.CheckNum(dr["ChangeAmount"].ToString()));
  458. decimal CheckAmount = 0;
  459. DataTable checkdt = OtherMySqlConn.dtable("select sum(SubsidyProfit) from ProfitSubsidyExport2 where MakerCode=(select MakerCode from Users where Id=" + UserId + ") and BrandName=(select Name from KqProducts where Id=" + ProductType + ")");
  460. if(checkdt.Rows.Count > 0)
  461. {
  462. CheckAmount = decimal.Parse(function.CheckNum(checkdt.Rows[0][0].ToString()));
  463. if(ChangeAmount - CheckAmount > 1 && CheckAmount > 0)
  464. {
  465. decimal LastAmount = ChangeAmount - CheckAmount;
  466. function.WriteLog("差异分润:UserId:" + UserId + ";ProductType:" + ProductType + ";ChangeAmount:" + ChangeAmount + ";CheckAmount:" + CheckAmount + ";LastAmount:" + LastAmount + ";", "查找8月多余补贴");
  467. }
  468. else
  469. {
  470. function.WriteLog("多余分润:UserId:" + UserId + ";ProductType:" + ProductType + ";ChangeAmount:" + ChangeAmount + ";", "查找8月多余补贴");
  471. }
  472. }
  473. else
  474. {
  475. function.WriteLog("多余分润:UserId:" + UserId + ";ProductType:" + ProductType + ";ChangeAmount:" + ChangeAmount + ";", "查找8月多余补贴");
  476. }
  477. }
  478. db.Dispose();
  479. }
  480. #endregion
  481. #region 重置开机奖励流量分佣
  482. public void resetOpenPrize()
  483. {
  484. string doDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
  485. string flag = function.ReadInstance("/Stat/" + doDate + ".txt");
  486. if (string.IsNullOrEmpty(flag))
  487. {
  488. function.WritePage("/Stat/", doDate + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  489. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  490. // StatService.Instance.StartEverDay(doDate);
  491. // StatService.Instance.StatMerchantTrade(doDate);
  492. // StatService.Instance.dosomething4(doDate);
  493. // StatService.Instance.ListenFluxRecord(doDate);
  494. }
  495. }
  496. #endregion
  497. #region 扣8月多余补贴
  498. public void ReduceMoreSubsidy()
  499. {
  500. WebCMSEntities db = new WebCMSEntities();
  501. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  502. DataTable dt = OtherMySqlConn.dtable("select UserId,sum(MoreMoney) from SubsidyCheck where Status=0 group by UserId");
  503. foreach(DataRow dr in dt.Rows)
  504. {
  505. int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
  506. decimal MoreMoney = decimal.Parse(function.CheckNum(dr[1].ToString()));
  507. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  508. if (account != null)
  509. {
  510. if(account.BalanceAmount >= MoreMoney)
  511. {
  512. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  513. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  514. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  515. account.BalanceAmount -= MoreMoney;
  516. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  517. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  518. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  519. db.SaveChanges();
  520. UserAccountRecord accountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  521. {
  522. CreateDate = DateTime.Now,
  523. UpdateDate = DateTime.Now,
  524. UserId = UserId, //创客
  525. ChangeType = 63, //变动类型
  526. ChangeAmount = MoreMoney, //变更金额
  527. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  528. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  529. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  530. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  531. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  532. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  533. Remark = "9月多发补贴扣减",
  534. }).Entity;
  535. db.SaveChanges();
  536. OtherMySqlConn.op("update SubsidyCheck set Status=1 where UserId=" + UserId);
  537. }
  538. }
  539. }
  540. db.Dispose();
  541. }
  542. #endregion
  543. }
  544. }