|
@@ -29,7 +29,7 @@ public class ResetSmallStoreHelper
|
|
|
{
|
|
|
function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算小分仓额度日志");
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
|
|
|
+ string connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
|
|
|
try
|
|
|
{
|
|
|
string content = RedisDbconn.Instance.RPop<string>("ResetSmallStoreQueue");
|
|
@@ -41,69 +41,14 @@ public class ResetSmallStoreHelper
|
|
|
if(string.IsNullOrEmpty(check))
|
|
|
{
|
|
|
function.WritePage("/ResetSmallStore/", Month + ".txt", DateTime.Now.ToString());
|
|
|
- OtherMySqlConn.op("update UserAccount set ThisMonthPreAmount=0,ValidPreAmount=0 where ThisMonthPreAmount>0");
|
|
|
+ CustomerSqlConn.op("update UserAccount set ThisMonthPreAmount=0,ValidPreAmount=0 where ThisMonthPreAmount>0", connstr);
|
|
|
string minId = "0";
|
|
|
- DataTable minIdDt = OtherMySqlConn.dtable("select min(Id) from ProfitRewardRecord where TradeMonth='" + PreMonth + "'");
|
|
|
+ DataTable minIdDt = CustomerSqlConn.dtable("select min(Id) from ProfitRewardRecord where TradeMonth='" + PreMonth + "'", connstr);
|
|
|
if(minIdDt.Rows.Count > 0)
|
|
|
{
|
|
|
minId = minIdDt.Rows[0][0].ToString();
|
|
|
}
|
|
|
- DataTable dt = OtherMySqlConn.dtable("select UserId,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord where Id>=" + minId + " and UserId>0 and TradeMonth='" + PreMonth + "' group by UserId");
|
|
|
- function.WriteLog("总数" + dt.Rows.Count, "计算小分仓额度日志");
|
|
|
- int index = 0;
|
|
|
- foreach(DataRow dr in dt.Rows)
|
|
|
- {
|
|
|
- index += 1;
|
|
|
- int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
|
|
|
- decimal ProfitAmount = decimal.Parse(function.CheckNum(dr[1].ToString()));
|
|
|
- decimal PreProfitAmount = ProfitAmount;
|
|
|
- var prelist = db.PreSendStockDetail.Select(m => new { m.Id, m.BrandId, m.ToUserId, m.Status, m.ApplyFlag }).Where(m => m.ToUserId == UserId && m.Status == 1 && m.ApplyFlag == 0).ToList();
|
|
|
- foreach(var prepos in prelist)
|
|
|
- {
|
|
|
- if(prepos.BrandId == 1 || prepos.BrandId == 2 || prepos.BrandId == 4 || prepos.BrandId == 6 || prepos.BrandId == 7 || prepos.BrandId == 8)
|
|
|
- {
|
|
|
- if(ProfitAmount > 200)
|
|
|
- {
|
|
|
- ProfitAmount -= 200;
|
|
|
- PreSendStockDetail edit = db.PreSendStockDetail.FirstOrDefault(m => m.Id == prepos.Id);
|
|
|
- if(edit != null)
|
|
|
- {
|
|
|
- edit.AuthFlag = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if(prepos.BrandId == 3 || prepos.BrandId == 5 || prepos.BrandId == 9)
|
|
|
- {
|
|
|
- if(ProfitAmount > 300)
|
|
|
- {
|
|
|
- ProfitAmount -= 300;
|
|
|
- PreSendStockDetail edit = db.PreSendStockDetail.FirstOrDefault(m => m.Id == prepos.Id);
|
|
|
- if(edit != null)
|
|
|
- {
|
|
|
- edit.AuthFlag = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
- if (account == null)
|
|
|
- {
|
|
|
- account = db.UserAccount.Add(new UserAccount()
|
|
|
- {
|
|
|
- Id = UserId,
|
|
|
- UserId = UserId,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- account.ThisMonthPreAmount = PreProfitAmount;
|
|
|
- account.ValidPreAmount = ProfitAmount;
|
|
|
- if(index % 200 == 0)
|
|
|
- {
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- function.WriteLog(index.ToString(), "计算小分仓额度日志");
|
|
|
- }
|
|
|
- db.SaveChanges();
|
|
|
+ DoMethod(db, PreMonth, minId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -116,4 +61,106 @@ public class ResetSmallStoreHelper
|
|
|
Thread.Sleep(60000);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void StartReset()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(DoWorksReset);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoWorksReset()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string content = RedisDbconn.Instance.RPop<string>("ResetSmallStoreByUserIdQueue");
|
|
|
+ if(!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
|
|
|
+ string PreMonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
|
|
|
+ string minId = "0";
|
|
|
+ DoMethod(db, PreMonth, minId, content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "重置小分仓额度异常");
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ Thread.Sleep(60000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DoMethod(WebCMSEntities db, string PreMonth, string minId = "0", string UId = "")
|
|
|
+ {
|
|
|
+ string sql = "";
|
|
|
+ if(string.IsNullOrEmpty(UId))
|
|
|
+ {
|
|
|
+ sql = "select UserId,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord where Id>=" + minId + " and UserId>0 and TradeMonth='" + PreMonth + "' group by UserId";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql = "select UserId,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord where UserId=" + UId + " and TradeMonth='" + PreMonth + "' group by UserId";
|
|
|
+ }
|
|
|
+ string connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
|
|
|
+ DataTable dt = CustomerSqlConn.dtable(sql, connstr);
|
|
|
+ function.WriteLog("总数" + dt.Rows.Count, "计算小分仓额度日志");
|
|
|
+ int index = 0;
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ index += 1;
|
|
|
+ int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
|
|
|
+ decimal ProfitAmount = decimal.Parse(function.CheckNum(dr[1].ToString()));
|
|
|
+ decimal PreProfitAmount = ProfitAmount;
|
|
|
+ var prelist = db.PreSendStockDetail.Select(m => new { m.Id, m.BrandId, m.ToUserId, m.Status, m.ApplyFlag, m.AuthFlag }).Where(m => m.ToUserId == UserId && m.Status == 1 && m.ApplyFlag == 0 && m.AuthFlag == 1).ToList();
|
|
|
+ foreach (var prepos in prelist)
|
|
|
+ {
|
|
|
+ if (prepos.BrandId == 1 || prepos.BrandId == 2 || prepos.BrandId == 4 || prepos.BrandId == 6 || prepos.BrandId == 7 || prepos.BrandId == 8)
|
|
|
+ {
|
|
|
+ if (ProfitAmount > 200)
|
|
|
+ {
|
|
|
+ ProfitAmount -= 200;
|
|
|
+ PreSendStockDetail edit = db.PreSendStockDetail.FirstOrDefault(m => m.Id == prepos.Id);
|
|
|
+ if (edit != null)
|
|
|
+ {
|
|
|
+ edit.AuthFlag = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (prepos.BrandId == 3 || prepos.BrandId == 5 || prepos.BrandId == 9)
|
|
|
+ {
|
|
|
+ if (ProfitAmount > 300)
|
|
|
+ {
|
|
|
+ ProfitAmount -= 300;
|
|
|
+ PreSendStockDetail edit = db.PreSendStockDetail.FirstOrDefault(m => m.Id == prepos.Id);
|
|
|
+ if (edit != null)
|
|
|
+ {
|
|
|
+ edit.AuthFlag = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
+ if (account == null)
|
|
|
+ {
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
+ {
|
|
|
+ Id = UserId,
|
|
|
+ UserId = UserId,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ account.ThisMonthPreAmount = PreProfitAmount;
|
|
|
+ account.ValidPreAmount = ProfitAmount;
|
|
|
+ if (index % 200 == 0)
|
|
|
+ {
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ function.WriteLog(index.ToString(), "计算小分仓额度日志");
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
}
|