|
@@ -33,48 +33,50 @@ namespace MySystem
|
|
|
{
|
|
|
if(DateTime.Now.Hour >= 3)
|
|
|
{
|
|
|
- StatTradeAmountV2();
|
|
|
+ StatTradeAmount();
|
|
|
}
|
|
|
Thread.Sleep(30000);
|
|
|
}
|
|
|
}
|
|
|
- public void StatTradeAmountV2()
|
|
|
+ public void StatTradeAmount()
|
|
|
{
|
|
|
OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
|
|
|
function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计商户和创客交易额日志");
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
+ KxsMainModels.WebCMSEntities maindb = new KxsMainModels.WebCMSEntities();
|
|
|
using (var tran = db.Database.BeginTransaction())
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- string startId = function.ReadInstance("/ConsumerOrders/Id.txt");
|
|
|
- DataTable idsDt = OtherMySqlConn.dtable("select Id from ConsumerOrders where Id>=" + startId + " and QueryCount=0 order by Id limit 50");
|
|
|
+ string start = DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ DataTable idsDt = OtherMySqlConn.dtable("select Id from ConsumerOrders where CreateDate>=" + start + " and Version=0 order by Id limit 50");
|
|
|
if(idsDt.Rows.Count > 0)
|
|
|
{
|
|
|
string ids = "";
|
|
|
foreach (DataRow idsDr in idsDt.Rows)
|
|
|
{
|
|
|
ids += idsDr["Id"].ToString() + ",";
|
|
|
- startId = idsDr["Id"].ToString();
|
|
|
}
|
|
|
- DataTable selfDt = OtherMySqlConn.dtable("select UserId,MerchantId,PayMode,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(PayMoney),count(Id) from ConsumerOrders where Id in (" + ids.TrimEnd(',') + ") group by UserId,MerchantId,PayMode,DATE_FORMAT(CreateDate,'%Y%m%d')");
|
|
|
+ DataTable selfDt = OtherMySqlConn.dtable("select UserId,MerchantId,SnNo,PayMode,IsAct,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(PayMoney),count(Id) from ConsumerOrders where Id in (" + ids.TrimEnd(',') + ") group by UserId,MerchantId,PayMode,IsAct,DATE_FORMAT(CreateDate,'%Y%m%d')");
|
|
|
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();
|
|
|
+ KxsMainModels.Users user = maindb.Users.FirstOrDefault(m => m.Id == UserId) ?? new KxsMainModels.Users();
|
|
|
string ParentNav = user.ParentNav;
|
|
|
int MerchantId = int.Parse(selfDr["MerchantId"].ToString());
|
|
|
int PayMode = int.Parse(selfDr["PayMode"].ToString());
|
|
|
+ int IsAct = int.Parse(selfDr["IsAct"].ToString());
|
|
|
+ string SnNo = selfDr["SnNo"].ToString();
|
|
|
string TradeDate = selfDr[3].ToString();
|
|
|
decimal TradeAmount = decimal.Parse(selfDr[4].ToString());
|
|
|
int TradeCount = int.Parse(selfDr[5].ToString());
|
|
|
string TradeMonth = TradeDate.Substring(0, 6);
|
|
|
|
|
|
//创客交易额
|
|
|
- UserAmountSummary selfStat = db.UserAmountSummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode && m.SeoTitle == "self");
|
|
|
+ UserAmountSummary selfStat = db.UserAmountSummary.FirstOrDefault(m => m.UserId == UserId && m.IsAct == IsAct && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode && m.SeoTitle == "self");
|
|
|
if (selfStat == null)
|
|
|
{
|
|
|
selfStat = db.UserAmountSummary.Add(new UserAmountSummary()
|
|
@@ -83,12 +85,13 @@ namespace MySystem
|
|
|
TradeMonth = TradeMonth,
|
|
|
TradeDate = TradeDate,
|
|
|
PayMode = PayMode,
|
|
|
+ IsAct = IsAct,
|
|
|
SeoTitle = "self",
|
|
|
}).Entity;
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
selfStat.TotalAmount += TradeAmount;
|
|
|
- selfStat.QueryCount += TradeCount;
|
|
|
+ selfStat.TradeCount += TradeCount;
|
|
|
ParentNav += "," + UserId + ",";
|
|
|
if (!string.IsNullOrEmpty(ParentNav))
|
|
|
{
|
|
@@ -96,7 +99,7 @@ namespace MySystem
|
|
|
foreach (string NavUserIdString in ParentNavList)
|
|
|
{
|
|
|
int NavUserId = int.Parse(NavUserIdString);
|
|
|
- UserAmountSummary teamStat = db.UserAmountSummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode && m.SeoTitle == "team");
|
|
|
+ UserAmountSummary teamStat = db.UserAmountSummary.FirstOrDefault(m => m.UserId == UserId && m.IsAct == IsAct && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode && m.SeoTitle == "team");
|
|
|
if (teamStat == null)
|
|
|
{
|
|
|
teamStat = db.UserAmountSummary.Add(new UserAmountSummary()
|
|
@@ -105,18 +108,19 @@ namespace MySystem
|
|
|
TradeMonth = TradeMonth,
|
|
|
TradeDate = TradeDate,
|
|
|
PayMode = PayMode,
|
|
|
+ IsAct = IsAct,
|
|
|
SeoTitle = "team",
|
|
|
}).Entity;
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
teamStat.TotalAmount += TradeAmount;
|
|
|
- teamStat.QueryCount += TradeCount;
|
|
|
+ teamStat.TradeCount += TradeCount;
|
|
|
}
|
|
|
}
|
|
|
db.SaveChanges();
|
|
|
|
|
|
//商户交易额
|
|
|
- MerchantAmountSummay merchantStat = db.MerchantAmountSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode);
|
|
|
+ MerchantAmountSummay merchantStat = db.MerchantAmountSummay.FirstOrDefault(m => m.MerchantId == MerchantId && m.IsAct == IsAct && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode);
|
|
|
if (merchantStat == null)
|
|
|
{
|
|
|
merchantStat = db.MerchantAmountSummay.Add(new MerchantAmountSummay()
|
|
@@ -125,26 +129,51 @@ namespace MySystem
|
|
|
TradeMonth = TradeMonth,
|
|
|
TradeDate = TradeDate,
|
|
|
PayMode = PayMode,
|
|
|
+ IsAct = IsAct,
|
|
|
}).Entity;
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
merchantStat.TradeAmount += TradeAmount;
|
|
|
- merchantStat.QueryCount += TradeCount;
|
|
|
+ merchantStat.TradeCount += TradeCount;
|
|
|
+
|
|
|
+ MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
|
|
|
+ if(merchant != null)
|
|
|
+ {
|
|
|
+ merchant.TotalAmount += TradeAmount;
|
|
|
+ merchant.TotalConsumeCount += TradeCount;
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+
|
|
|
+ //码牌交易额
|
|
|
+ QrCodeAmountSummay qrcode = db.QrCodeAmountSummay.FirstOrDefault(m => m.SnNo == SnNo && m.IsAct == IsAct && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.PayMode == PayMode);
|
|
|
+ if (qrcode == null)
|
|
|
+ {
|
|
|
+ qrcode = db.QrCodeAmountSummay.Add(new QrCodeAmountSummay()
|
|
|
+ {
|
|
|
+ SnNo = SnNo,
|
|
|
+ TradeMonth = TradeMonth,
|
|
|
+ TradeDate = TradeDate,
|
|
|
+ PayMode = PayMode,
|
|
|
+ IsAct = IsAct,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ qrcode.TradeAmount += TradeAmount;
|
|
|
+ qrcode.TradeCount += TradeCount;
|
|
|
}
|
|
|
- OtherMySqlConn.op("update ConsumerOrders set QueryCount=1 where Id in (" + ids.TrimEnd(',') + ")");
|
|
|
- function.WritePage("/ConsumerOrders/", "Id.txt", startId);
|
|
|
+ OtherMySqlConn.op("update ConsumerOrders set Version=1 where Id in (" + ids.TrimEnd(',') + ")");
|
|
|
}
|
|
|
- db.SaveChanges();
|
|
|
}
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计昨天交易额V2异常");
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计昨天交易额异常");
|
|
|
}
|
|
|
}
|
|
|
db.Dispose();
|
|
|
+ maindb.Dispose();
|
|
|
function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "统计商户和创客交易额日志");
|
|
|
}
|
|
|
}
|