|
|
@@ -23,6 +23,9 @@ public class StoreApplyHelper
|
|
|
}
|
|
|
|
|
|
// 每月1号重置仓库额度
|
|
|
+ // 固定额度=上月出货额度与保底额度之间的最高值
|
|
|
+ // 已用额度=仓库中机具占用额度+小分仓机具占用额度+申请补货订单占用额度
|
|
|
+ // 可用额度=重置后的固定额度+被担保额度+临时额度-已用额度
|
|
|
private void DoWorks()
|
|
|
{
|
|
|
while (true)
|
|
|
@@ -31,8 +34,8 @@ public class StoreApplyHelper
|
|
|
OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
|
|
|
try
|
|
|
{
|
|
|
- if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
|
|
|
- {
|
|
|
+ // if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
|
|
|
+ // {
|
|
|
string check = function.ReadInstance("/StoreApply/" + DateTime.Now.ToString("yyyyMM") + ".txt");
|
|
|
if(string.IsNullOrEmpty(check))
|
|
|
{
|
|
|
@@ -54,6 +57,7 @@ public class StoreApplyHelper
|
|
|
dataDic[UserId] += 20000;
|
|
|
}
|
|
|
}
|
|
|
+ //上月出货额度
|
|
|
DataTable dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where 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)
|
|
|
{
|
|
|
@@ -86,11 +90,31 @@ public class StoreApplyHelper
|
|
|
dataDic[store.UserId] += AmountMore;
|
|
|
}
|
|
|
}
|
|
|
- // TODO: 上个月申请了但未发货的额度,要减掉
|
|
|
foreach(int UserId in dataDic.Keys)
|
|
|
{
|
|
|
decimal Amount = dataDic[UserId];
|
|
|
+ //上月出货额度与保底额度之间取较高值
|
|
|
+ if(Amount < 10000 && SpecialUsers10000().Contains(UserId))
|
|
|
+ {
|
|
|
+ Amount = 10000;
|
|
|
+ }
|
|
|
+ if(Amount < 20000 && SpecialUsers20000().Contains(UserId))
|
|
|
+ {
|
|
|
+ Amount = 20000;
|
|
|
+ }
|
|
|
+ if(Amount < 20000)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
{
|
|
|
@@ -101,13 +125,11 @@ public class StoreApplyHelper
|
|
|
{
|
|
|
AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
|
|
|
}
|
|
|
- if(Amount < 10000 && SpecialUsers10000().Contains(UserId))
|
|
|
- {
|
|
|
- Amount = 10000;
|
|
|
- }
|
|
|
- if(Amount < 20000 && SpecialUsers20000().Contains(UserId))
|
|
|
+ //申请补货订单占用额度
|
|
|
+ dt = OtherMySqlConn.dtable("select UseAmount from StoreMachineApply where UserId=" + UserId + " and Status=0");
|
|
|
+ foreach(DataRow dr in dt.Rows)
|
|
|
{
|
|
|
- Amount = 20000;
|
|
|
+ AmountMore += decimal.Parse(function.CheckNum(dr["UseAmount"].ToString()));
|
|
|
}
|
|
|
UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
if (account == null)
|
|
|
@@ -120,12 +142,12 @@ public class StoreApplyHelper
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
account.FixedAmount = Amount;
|
|
|
- account.ValidAmount = Amount + account.TempAmount - AmountMore;
|
|
|
+ account.ValidAmount = Amount + PromissAmount + account.TempAmount - AmountMore;
|
|
|
function.WriteLog("UserId:" + UserId + ";FixedAmount:" + account.FixedAmount + ";AmountMore:" + AmountMore + ";ValidAmount:" + account.ValidAmount, "计算分仓申请机具额度日志");
|
|
|
}
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
- }
|
|
|
+ // }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
@@ -163,7 +185,7 @@ public class StoreApplyHelper
|
|
|
if(order != null)
|
|
|
{
|
|
|
decimal TotalPrice = order.TotalPrice * 2;
|
|
|
- AddAmount2(db, order.UserId, TotalPrice, 1, order.Id);
|
|
|
+ AddAmount2(db, 1, order.UserId, TotalPrice, 1, order.Id);
|
|
|
}
|
|
|
}
|
|
|
else if(jsonObj["Kind"].ToString() == "2") // 增减分仓临时额度
|
|
|
@@ -171,13 +193,13 @@ public class StoreApplyHelper
|
|
|
int UserId = int.Parse(jsonObj["Data"]["UserId"].ToString());
|
|
|
decimal Amount = decimal.Parse(jsonObj["Data"]["Amount"].ToString());
|
|
|
int OperateType = int.Parse(jsonObj["Data"]["OperateType"].ToString());
|
|
|
- AddAmount(db, UserId, Amount, OperateType);
|
|
|
+ AddAmount(db, 2, UserId, Amount, OperateType);
|
|
|
}
|
|
|
else if(jsonObj["Kind"].ToString() == "3") // 调低额度返回余额
|
|
|
{
|
|
|
int UserId = int.Parse(jsonObj["Data"]["UserId"].ToString());
|
|
|
decimal Amount = decimal.Parse(jsonObj["Data"]["Amount"].ToString());
|
|
|
- AddAmount2(db, UserId, Amount, 0);
|
|
|
+ AddAmount2(db, 3, UserId, Amount, 0);
|
|
|
decimal BalanceAmount = Amount / 2;
|
|
|
UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
if (account == null)
|
|
|
@@ -235,7 +257,7 @@ public class StoreApplyHelper
|
|
|
}
|
|
|
if(Amount > 0)
|
|
|
{
|
|
|
- AddAmount(db, store.UserId, Amount, 1);
|
|
|
+ AddAmount(db, 4, store.UserId, Amount, 1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -260,7 +282,7 @@ public class StoreApplyHelper
|
|
|
}
|
|
|
if(Amount > 0)
|
|
|
{
|
|
|
- AddAmount(db, store.UserId, Amount, OpType);
|
|
|
+ AddAmount(db, 5, store.UserId, Amount, OpType);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -279,7 +301,7 @@ public class StoreApplyHelper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void AddAmount(WebCMSEntities db, int UserId, decimal Amount, int OperateType = 1, int OrderId = 0)
|
|
|
+ public void AddAmount(WebCMSEntities db, int Kind, int UserId, decimal Amount, int OperateType = 1, int OrderId = 0)
|
|
|
{
|
|
|
UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
if (account == null)
|
|
|
@@ -312,11 +334,12 @@ public class StoreApplyHelper
|
|
|
UseAmount = Amount,
|
|
|
UserId = UserId,
|
|
|
QueryCount = OrderId,
|
|
|
+ Sort = Kind,
|
|
|
}).Entity;
|
|
|
db.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public void AddAmount2(WebCMSEntities db, int UserId, decimal Amount, int OperateType = 1, int OrderId = 0)
|
|
|
+ public void AddAmount2(WebCMSEntities db, int Kind, int UserId, decimal Amount, int OperateType = 1, int OrderId = 0)
|
|
|
{
|
|
|
UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
|
|
|
if (account == null)
|
|
|
@@ -351,6 +374,7 @@ public class StoreApplyHelper
|
|
|
UseAmount = Amount,
|
|
|
UserId = UserId,
|
|
|
QueryCount = OrderId,
|
|
|
+ Sort = Kind,
|
|
|
}).Entity;
|
|
|
db.SaveChanges();
|
|
|
}
|