|
|
@@ -38,7 +38,7 @@ namespace MySystem
|
|
|
string SysUserName = data[3];
|
|
|
if (OpType == 0)
|
|
|
{
|
|
|
- // DoTradeProfit(BrandId, date, SysUserName);
|
|
|
+ DoTradeProfit(BrandId, date, SysUserName);
|
|
|
DoSubsidyProfit(BrandId, date);
|
|
|
}
|
|
|
else if (OpType == 1)
|
|
|
@@ -75,18 +75,8 @@ namespace MySystem
|
|
|
decimal ProfitMoney = decimal.Parse(dr[1].ToString());
|
|
|
try
|
|
|
{
|
|
|
- string IdBrand = UserId + "_" + BrandId;
|
|
|
- UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
- if (MachineData == null)
|
|
|
- {
|
|
|
- MachineData = db.UserMachineData.Add(new UserMachineData()
|
|
|
- {
|
|
|
- IdBrand = IdBrand,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- MachineData.TradeProfit += ProfitMoney;
|
|
|
- db.SaveChanges();
|
|
|
+ string content = UserId + "|" + BrandId + "|" + ProfitMoney + "|" + index;
|
|
|
+ RedisDbconn.Instance.AddList("DoTradeProfitQueue", content);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -95,8 +85,12 @@ namespace MySystem
|
|
|
function.WriteLog(index.ToString(), "同步分润数据");
|
|
|
}
|
|
|
OtherMySqlConn.op("update ProfitRewardRecord set CheckStatus=1 where CheckStatus=0 and BrandId=" + BrandId + " and UserId>0 and TradeMonth='" + date + "'");
|
|
|
-
|
|
|
+
|
|
|
db.Dispose();
|
|
|
+ dt.Dispose();
|
|
|
+
|
|
|
+ RedisDbconn.Instance.AddList("DoTradeProfitQueue", "end");
|
|
|
+ SycnProfitServiceV2.Instance.StartProfit();
|
|
|
}
|
|
|
private void DoTradeProfit2(int BrandId, string date, string SysUserName)
|
|
|
{
|
|
|
@@ -205,6 +199,10 @@ namespace MySystem
|
|
|
OtherMySqlConn.dtable("update ProfitSubsidyDetail set Status=1 where Status=0 and BrandId=" + BrandId + " and TradeMonth='" + date + "'");
|
|
|
|
|
|
db.Dispose();
|
|
|
+ dt.Dispose();
|
|
|
+
|
|
|
+ RedisDbconn.Instance.AddList("DoSubsidyProfitQueue", "end");
|
|
|
+ SycnProfitServiceV2.Instance.StartSubsidy();
|
|
|
}
|
|
|
|
|
|
private void DoSubsidyProfit2(int BrandId, string date)
|
|
|
@@ -215,7 +213,7 @@ namespace MySystem
|
|
|
bool op = true;
|
|
|
while(op)
|
|
|
{
|
|
|
- DataTable dt = OtherMySqlConn.dtable("select Id,UserId,ProfitAmount from SubsidyRecord where Id>" + startid + " and BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0 order by Id limit 200");
|
|
|
+ DataTable dt = OtherMySqlConn.dtable("select Id,UserId,ProfitAmount from SubsidyRecord where Id>" + startid + " and BrandId=" + BrandId + " and SeoTitle='" + date + "' and Status=0 and UserId>0 order by Id limit 200");
|
|
|
if(dt.Rows.Count > 0)
|
|
|
{
|
|
|
function.WriteLog("补贴:" + BrandId + ":" + dt.Rows.Count, "同步补贴数据");
|
|
|
@@ -280,7 +278,7 @@ namespace MySystem
|
|
|
op = false;
|
|
|
}
|
|
|
}
|
|
|
- OtherMySqlConn.dtable("update SubsidyRecord set Version=1 where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Version=0 and UserId>0");
|
|
|
+ OtherMySqlConn.dtable("update SubsidyRecord set Status=1 where BrandId=" + BrandId + " and SeoTitle='" + date + "' and Status=0 and UserId>0");
|
|
|
|
|
|
db.Dispose();
|
|
|
}
|
|
|
@@ -378,7 +376,64 @@ namespace MySystem
|
|
|
|
|
|
|
|
|
|
|
|
+ public void StartProfit()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(StartProfitDo);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void StartProfitDo()
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ bool op = true;
|
|
|
+ while (op)
|
|
|
+ {
|
|
|
+ string content = RedisDbconn.Instance.RPop<string>("DoTradeProfitQueue");
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ if(content == "end")
|
|
|
+ {
|
|
|
+ op = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string[] data = content.Split('|');
|
|
|
+ int UserId = int.Parse(data[0]);
|
|
|
+ int BrandId = int.Parse(data[1]);
|
|
|
+ decimal ProfitMoney = decimal.Parse(data[2]);
|
|
|
+ int index = int.Parse(data[3]);
|
|
|
+
|
|
|
+ string IdBrand = UserId + "_" + BrandId;
|
|
|
+ UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
+ if (MachineData == null)
|
|
|
+ {
|
|
|
+ MachineData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ MachineData.TradeProfit += ProfitMoney;
|
|
|
+ db.SaveChanges();
|
|
|
|
|
|
+ function.WriteLog(index.ToString() + "--" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "同步分润队列数据");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "同步分润队列数据异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
|
|
|
public void StartSubsidy()
|
|
|
{
|
|
|
@@ -389,37 +444,46 @@ namespace MySystem
|
|
|
|
|
|
public void StartSubsidyDo()
|
|
|
{
|
|
|
- while (true)
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ bool op = true;
|
|
|
+ while (op)
|
|
|
{
|
|
|
string content = RedisDbconn.Instance.RPop<string>("DoSubsidyProfitQueue");
|
|
|
if (!string.IsNullOrEmpty(content))
|
|
|
{
|
|
|
- try
|
|
|
+ if(content == "end")
|
|
|
+ {
|
|
|
+ op = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- string[] data = content.Split('|');
|
|
|
- int UserId = int.Parse(data[0]);
|
|
|
- int BrandId = int.Parse(data[1]);
|
|
|
- decimal ProfitMoney = decimal.Parse(data[2]);
|
|
|
- int index = int.Parse(data[3]);
|
|
|
- WebCMSEntities db = new WebCMSEntities();
|
|
|
- Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
|
|
|
- string IdBrand = UserId + "_" + BrandId;
|
|
|
- UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
- if (MachineData == null)
|
|
|
+ try
|
|
|
{
|
|
|
- MachineData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ string[] data = content.Split('|');
|
|
|
+ int UserId = int.Parse(data[0]);
|
|
|
+ int BrandId = int.Parse(data[1]);
|
|
|
+ decimal ProfitMoney = decimal.Parse(data[2]);
|
|
|
+ int index = int.Parse(data[3]);
|
|
|
+
|
|
|
+ string IdBrand = UserId + "_" + BrandId;
|
|
|
+ UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
+ if (MachineData == null)
|
|
|
{
|
|
|
- IdBrand = IdBrand,
|
|
|
- }).Entity;
|
|
|
+ MachineData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ MachineData.OtherProfit += ProfitMoney;
|
|
|
db.SaveChanges();
|
|
|
+
|
|
|
+ function.WriteLog(index.ToString() + "--" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "同步补贴队列数据");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "同步补贴队列数据异常");
|
|
|
}
|
|
|
- MachineData.OtherProfit += ProfitMoney;
|
|
|
- db.SaveChanges();
|
|
|
- function.WriteLog(index.ToString() + "--" + DateTime.Now.ToString(), "同步补贴数据");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "同步补贴队列数据异常");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -427,6 +491,7 @@ namespace MySystem
|
|
|
Thread.Sleep(1000);
|
|
|
}
|
|
|
}
|
|
|
+ db.Dispose();
|
|
|
}
|
|
|
}
|
|
|
}
|