123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.PxcModels;
- namespace MySystem
- {
- public class TradeChangeService
- {
- public readonly static TradeChangeService Instance = new TradeChangeService();
- private TradeChangeService()
- { }
- public void Start()
- {
- Thread th = new Thread(dosomething);
- th.IsBackground = true;
- th.Start();
- }
- public void dosomething()
- {
- while (true)
- {
- string data = RedisDbconn.Instance.RPop<string>("TradeChangeQueue");
- if (!string.IsNullOrEmpty(data))
- {
- try
- {
- JsonData jsonOj = JsonMapper.ToObject(data);
- int Id = int.Parse(function.CheckInt(jsonOj["Id"].ToString()));
- int OldType = int.Parse(function.CheckInt(jsonOj["OldType"].ToString()));
- int NewType = int.Parse(function.CheckInt(jsonOj["NewType"].ToString()));
- StatTradeAmount(Id, OldType, NewType);
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置激活奖励异常");
- }
- }
- else
- {
- Thread.Sleep(500);
- }
- }
- }
- public void StatTradeAmount(int Id, int OldType, int NewType)
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "交易额类型变更");
- WebCMSEntities db = new WebCMSEntities();
- try
- {
- DataTable selfDt = CustomerSqlConn.dtable("select UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),TradeAmount from TradeRecord where Id=" + Id + "", MysqlConn.SqlConnStr);
- if (selfDt.Rows.Count > 0)
- {
- function.WriteLog("统计人数:" + selfDt.Rows.Count + "\n\n", "交易额类型变更");
- foreach (DataRow selfDr in selfDt.Rows)
- {
- int UserId = int.Parse(selfDr["UserId"].ToString());
- Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- string ParentNav = user.ParentNav; //selfDr["ParentNav"].ToString();
- int BrandId = int.Parse(selfDr["BrandId"].ToString());
- int BankCardType = int.Parse(selfDr["BankCardType"].ToString());
- int QrPayFlag = int.Parse(selfDr["QrPayFlag"].ToString());
- int MerHelpFlag = int.Parse(selfDr["MerHelpFlag"].ToString());
- int Version = int.Parse(selfDr["Version"].ToString());
- int CapFlag = int.Parse(selfDr["CapFlag"].ToString());
- int VipFlag = int.Parse(selfDr["VipFlag"].ToString());
- int PayType = int.Parse(selfDr["PayType"].ToString());
- string TradeDate = selfDr[10].ToString();
- decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString());
- string TradeMonth = TradeDate.Substring(0, 6);
- TradeDaySummary selfStat = db.TradeDaySummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId && m.QueryCount == QrPayFlag && m.VipFlag == VipFlag && m.PayType == PayType && m.SeoTitle == "self");
- if (selfStat != null)
- {
- if (BankCardType == 0)
- {
- if(OldType == 2)
- {
- if(selfStat.NotHelpDirectDebitTradeAmt >= TradeAmount)
- {
- selfStat.NotHelpDirectDebitTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- selfStat.HelpDirectDebitTradeAmt += TradeAmount;
- }
- }
- if (CapFlag == 1)
- {
- if(selfStat.NotHelpDirectDebitCapTradeAmt >= TradeAmount)
- {
- selfStat.NotHelpDirectDebitCapTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- selfStat.HelpDirectDebitCapTradeAmt += TradeAmount;
- }
- }
- }
- }
- }
- else if (BankCardType != 0)
- {
- if(OldType == 2)
- {
- if(selfStat.NotHelpDirectTradeAmt >= TradeAmount)
- {
- selfStat.NotHelpDirectTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- selfStat.HelpDirectTradeAmt += TradeAmount;
- }
- }
- }
- }
- ParentNav += "," + UserId + ",";
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- foreach (string NavUserIdString in ParentNavList)
- {
- int NavUserId = int.Parse(NavUserIdString);
- TradeDaySummary teamStat = db.TradeDaySummary.FirstOrDefault(m => m.UserId == NavUserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId && m.QueryCount == QrPayFlag && m.VipFlag == VipFlag && m.PayType == PayType && m.SeoTitle == "team");
- if (teamStat != null)
- {
- if (BankCardType == 0)
- {
- if(OldType == 2)
- {
- if(teamStat.NotHelpNonDirectDebitTradeAmt >= TradeAmount)
- {
- teamStat.NotHelpNonDirectDebitTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- teamStat.HelpNonDirectDebitTradeAmt += TradeAmount;
- }
- }
- if (CapFlag == 1)
- {
- if(teamStat.NotHelpDirectDebitCapTradeAmt >= TradeAmount)
- {
- teamStat.NotHelpDirectDebitCapTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- teamStat.HelpDirectDebitCapTradeAmt += TradeAmount;
- }
- }
- }
- }
- }
- else if (BankCardType != 0)
- {
- if(OldType == 2)
- {
- if(teamStat.NotHelpNonDirectTradeAmt >= TradeAmount)
- {
- teamStat.NotHelpNonDirectTradeAmt -= TradeAmount;
- if(NewType == 1)
- {
- teamStat.HelpNonDirectTradeAmt += 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", "交易额类型变更");
- }
- }
- }
|