|
@@ -40,121 +40,7 @@ public class StoreApplyHelper
|
|
|
if(string.IsNullOrEmpty(check))
|
|
|
{
|
|
|
function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
|
|
|
- Dictionary<int, decimal> dataDic = new Dictionary<int, decimal>();
|
|
|
- string pre = DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01 00:00:00";
|
|
|
- string start = DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00";
|
|
|
- string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
- //上月出货额度
|
|
|
- DataTable dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (1,2,4,6,7,8) and TransType in (10,11,2) and StoreId>0 group by StoreId");
|
|
|
- foreach(DataRow dr in dt.Rows)
|
|
|
- {
|
|
|
- int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
|
|
|
- int Count = int.Parse(function.CheckInt(dr[1].ToString()));
|
|
|
- decimal AmountMore = Count * 200;
|
|
|
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
|
|
|
- if(!dataDic.ContainsKey(store.UserId))
|
|
|
- {
|
|
|
- dataDic.Add(store.UserId, AmountMore);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dataDic[store.UserId] += AmountMore;
|
|
|
- }
|
|
|
- }
|
|
|
- dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (3,5,9) and TransType in (10,11,2) and StoreId>0 group by StoreId");
|
|
|
- foreach(DataRow dr in dt.Rows)
|
|
|
- {
|
|
|
- int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
|
|
|
- int Count = int.Parse(function.CheckInt(dr[1].ToString()));
|
|
|
- decimal AmountMore = Count * 300;
|
|
|
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
|
|
|
- if(!dataDic.ContainsKey(store.UserId))
|
|
|
- {
|
|
|
- dataDic.Add(store.UserId, AmountMore);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dataDic[store.UserId] += AmountMore;
|
|
|
- }
|
|
|
- }
|
|
|
- //上月没出货的创库
|
|
|
- string ids = "0";
|
|
|
- foreach(int UserId in dataDic.Keys)
|
|
|
- {
|
|
|
- ids += "," + UserId;
|
|
|
- }
|
|
|
- DataTable dts = OtherMySqlConn.dtable("select distinct UserId from StoreHouse where UserId not in (" + ids + ") and Status>-1");
|
|
|
- foreach(DataRow dr in dts.Rows)
|
|
|
- {
|
|
|
- int UserId = int.Parse(function.CheckInt(dr[0].ToString()));
|
|
|
- if(!dataDic.ContainsKey(UserId))
|
|
|
- {
|
|
|
- dataDic.Add(UserId, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- foreach(int UserId in dataDic.Keys)
|
|
|
- {
|
|
|
- decimal Amount = dataDic[UserId];
|
|
|
- //上月出货额度与保底额度之间取较高值
|
|
|
- if(Amount < 10000 && SpecialUsers10000().Contains(UserId))
|
|
|
- {
|
|
|
- Amount = 10000;
|
|
|
- }
|
|
|
- else if(Amount < 20000 && !SpecialUsers0().Contains(UserId))
|
|
|
- {
|
|
|
- Amount = 20000;
|
|
|
- }
|
|
|
- //被担保额度
|
|
|
- decimal PromissAmount = 0;
|
|
|
- dt = OtherMySqlConn.dtable("select PromissAmount from StoreHouseAmountPromiss where ToUserId=" + UserId + " and Status=1");
|
|
|
- foreach(DataRow dr in dt.Rows)
|
|
|
- {
|
|
|
- PromissAmount += decimal.Parse(function.CheckNum(dr["PromissAmount"].ToString()));
|
|
|
- }
|
|
|
- decimal AmountMore = 0;
|
|
|
- //仓库中机具占用额度+小分仓机具占用额度
|
|
|
- DataTable dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (1,2,4,6,7,8) and `Status`>-1");
|
|
|
- if(dtmore.Rows.Count > 0)
|
|
|
- {
|
|
|
- AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
- }
|
|
|
- dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (3,5,9) and `Status`>-1");
|
|
|
- if(dtmore.Rows.Count > 0)
|
|
|
- {
|
|
|
- AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
- }
|
|
|
- //除开小分仓中带“授”标记机具占用额度
|
|
|
- dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (1,2,4,6,7,8) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
|
|
|
- if(dtmore.Rows.Count > 0)
|
|
|
- {
|
|
|
- AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
- }
|
|
|
- dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (3,5,9) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
|
|
|
- if(dtmore.Rows.Count > 0)
|
|
|
- {
|
|
|
- AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
- }
|
|
|
- //申请补货订单占用额度
|
|
|
- dt = OtherMySqlConn.dtable("select UseAmount from StoreMachineApply where UserId=" + UserId + " and Status=0");
|
|
|
- foreach(DataRow dr in dt.Rows)
|
|
|
- {
|
|
|
- AmountMore += decimal.Parse(function.CheckNum(dr["UseAmount"].ToString()));
|
|
|
- }
|
|
|
- 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.FixedAmount = Amount;
|
|
|
- account.ValidAmount = Amount + PromissAmount + account.TempAmount - AmountMore;
|
|
|
- function.WriteLog("UserId:" + UserId + ";FixedAmount:" + account.FixedAmount + ";AmountMore:" + AmountMore + ";ValidAmount:" + account.ValidAmount, "计算分仓申请机具额度日志");
|
|
|
- }
|
|
|
- db.SaveChanges();
|
|
|
+ DoSomething(db);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -168,6 +54,156 @@ public class StoreApplyHelper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void ResetStoreReserve()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(ResetStoreReserveDo);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ResetStoreReserveDo()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string data = RedisDbconn.Instance.RPop<string>("ResetStoreReserveQueue");
|
|
|
+ if(!string.IsNullOrEmpty(data))
|
|
|
+ {
|
|
|
+ int UserId = int.Parse(data);
|
|
|
+ if(UserId > 0) DoSomething(db, UserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "重置分仓额度异常");
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoSomething(WebCMSEntities db, int UId = 0)
|
|
|
+ {
|
|
|
+ Dictionary<int, decimal> dataDic = new Dictionary<int, decimal>();
|
|
|
+ string pre = DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01 00:00:00";
|
|
|
+ string start = DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00";
|
|
|
+ string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
+ string condition = "";
|
|
|
+ if(UId > 0)
|
|
|
+ {
|
|
|
+ condition = " and StoreId in (select Id from StoreHouse where UserId=" + UId + ")";
|
|
|
+ }
|
|
|
+ //上月出货额度
|
|
|
+ DataTable dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (1,2,4,6,7,8) and TransType in (10,11,2) and StoreId>0" + condition + " group by StoreId");
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
|
|
|
+ int Count = int.Parse(function.CheckInt(dr[1].ToString()));
|
|
|
+ decimal AmountMore = Count * 200;
|
|
|
+ StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
|
|
|
+ if(!dataDic.ContainsKey(store.UserId))
|
|
|
+ {
|
|
|
+ dataDic.Add(store.UserId, AmountMore);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dataDic[store.UserId] += AmountMore;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where Id>=528358 and CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (3,5,9) and TransType in (10,11,2) and StoreId>0" + condition + " group by StoreId");
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ int StoreId = int.Parse(function.CheckInt(dr["StoreId"].ToString()));
|
|
|
+ int Count = int.Parse(function.CheckInt(dr[1].ToString()));
|
|
|
+ decimal AmountMore = Count * 300;
|
|
|
+ StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
|
|
|
+ if(!dataDic.ContainsKey(store.UserId))
|
|
|
+ {
|
|
|
+ dataDic.Add(store.UserId, AmountMore);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dataDic[store.UserId] += AmountMore;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //上月没出货的创库
|
|
|
+ string ids = "0";
|
|
|
+ foreach(int UserId in dataDic.Keys)
|
|
|
+ {
|
|
|
+ ids += "," + UserId;
|
|
|
+ }
|
|
|
+ DataTable dts = OtherMySqlConn.dtable("select distinct UserId from StoreHouse where UserId not in (" + ids + ") and Status>-1");
|
|
|
+ foreach(DataRow dr in dts.Rows)
|
|
|
+ {
|
|
|
+ int UserId = int.Parse(function.CheckInt(dr[0].ToString()));
|
|
|
+ if(!dataDic.ContainsKey(UserId))
|
|
|
+ {
|
|
|
+ dataDic.Add(UserId, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach(int UserId in dataDic.Keys)
|
|
|
+ {
|
|
|
+ decimal Amount = dataDic[UserId];
|
|
|
+ //上月出货额度与保底额度之间取较高值,保底额度为押金的两倍
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ decimal StoreDeposit = account.StoreDeposit;
|
|
|
+ if(Amount < StoreDeposit * 2)
|
|
|
+ {
|
|
|
+ Amount = StoreDeposit * 2;
|
|
|
+ }
|
|
|
+ //被担保额度
|
|
|
+ decimal PromissAmount = 0;
|
|
|
+ dt = OtherMySqlConn.dtable("select PromissAmount from StoreHouseAmountPromiss where ToUserId=" + UserId + " and Status=1");
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ PromissAmount += decimal.Parse(function.CheckNum(dr["PromissAmount"].ToString()));
|
|
|
+ }
|
|
|
+ decimal AmountMore = 0;
|
|
|
+ //仓库中机具占用额度+小分仓机具占用额度
|
|
|
+ DataTable dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (1,2,4,6,7,8) and `Status`>-1");
|
|
|
+ if(dtmore.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
+ }
|
|
|
+ dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PosMachinesTwo pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BuyUserId=0 and BrandId in (3,5,9) and `Status`>-1");
|
|
|
+ if(dtmore.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
+ }
|
|
|
+ //除开小分仓中带“授”标记机具占用额度
|
|
|
+ dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (1,2,4,6,7,8) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
|
|
|
+ if(dtmore.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
+ }
|
|
|
+ dtmore = OtherMySqlConn.dtable("select count(Id)*300 from PreSendStockDetail pos where FromStoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (3,5,9) and AuthFlag=1 and ApplyFlag=0 and `Status`>-1 and `Status`<2");
|
|
|
+ if(dtmore.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ AmountMore -= decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
+ }
|
|
|
+ //申请补货订单占用额度
|
|
|
+ dt = OtherMySqlConn.dtable("select UseAmount from StoreMachineApply where UserId=" + UserId + " and Status=0");
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ AmountMore += decimal.Parse(function.CheckNum(dr["UseAmount"].ToString()));
|
|
|
+ }
|
|
|
+ account.FixedAmount = Amount;
|
|
|
+ account.ValidAmount = Amount + PromissAmount + account.TempAmount - AmountMore;
|
|
|
+ function.WriteLog("UserId:" + UserId + ";FixedAmount:" + account.FixedAmount + ";AmountMore:" + AmountMore + ";ValidAmount:" + account.ValidAmount, "计算分仓申请机具额度日志");
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
public void StartEverTime()
|
|
|
{
|
|
|
Thread th = new Thread(StartEverTimeDo);
|