Browse Source

修复每月重置分仓额度

lichunlei 2 years ago
parent
commit
93aa2bf791

+ 1 - 1
AppStart/Helper/Profit/ProfitHelperV2.cs

@@ -38,7 +38,7 @@ namespace MySystem
             while (true)
             {
                 string content = RedisDbconn.Instance.RPop<string>("DoProfitQueue");
-                if(!string.IsNullOrEmpty(content))
+                if(!string.IsNullOrEmpty(content) && DateTime.Now.Day < 6)
                 {
                     StatProfiting();
                 }

+ 32 - 16
AppStart/Helper/StatService.cs

@@ -1639,7 +1639,7 @@ namespace MySystem
         {
             while (true)
             {
-                if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 4)
+                if(DateTime.Now.Day == 1 && DateTime.Now.Hour >= 4)
                 {
                     string Month = DateTime.Now.AddDays(-1).ToString("yyyy-MM");
                     string flag = function.ReadInstance("/ProfitFlag/" + Month + ".txt");
@@ -1667,7 +1667,7 @@ namespace MySystem
                 int startid = 0;
                 while(op)
                 {
-                    var users = db.Users.Select(m => new { m.Id, m.AuthFlag }).Where(m => m.Id > startid && m.AuthFlag == 1).OrderBy(m => m.Id).Take(50).ToList();
+                    var users = db.Users.Select(m => new { m.Id, m.AuthFlag }).Where(m => m.Id > startid && m.AuthFlag == 1 && m.Id == 66575).OrderBy(m => m.Id).Take(50).ToList();
                     function.WriteLog(users.Count.ToString(), "创客升级日志");
                     if(users.Count > 0)
                     {
@@ -1715,27 +1715,43 @@ namespace MySystem
                                     }
                                     if(TradeAmt < 12000000)
                                     {
-                                        upFlag = false;
+                                        if(AfterLevel > BeforeLevel && BeforeLevel >= 5) //保级,只升不降
+                                        {
+                                            AfterLevel = BeforeLevel;
+                                        }
+                                        else if(AfterLevel > BeforeLevel && BeforeLevel < 5)
+                                        {
+                                            AfterLevel = 5;
+                                        }
+                                        else
+                                        {
+                                            upFlag = false;
+                                        }
                                     }
                                 }
                                 if (AfterLevel > BeforeLevel && AfterLevel > 1 && upFlag)
                                 {
                                     function.WriteLog("升级:" + user.Id.ToString() + BeforeLevel + "->" + AfterLevel, "创客升级日志");
                                     user.UserLevel = AfterLevel;
-                                    db.UserRank.Add(new UserRank()
+                                    DateTime checkTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
+                                    bool checkExist = db.UserRank.Any(m => m.CreateDate >= checkTime && m.UserId == user.Id);
+                                    if(!checkExist)
                                     {
-                                        CreateDate = DateTime.Now,
-                                        UpdateDate = DateTime.Now,
-                                        UserId = user.Id, //创客
-                                        WhiteRank = BeforeLevel,
-                                        Rank = AfterLevel, //当前等级
-                                        StatYear = DateTime.Now.Year, //统计年份
-                                        StatMonth = DateTime.Now.Month, //统计月份
-                                        TradeAmt = TradeAmount, //团队交易总额
-                                        UpgradeFlag = 1, //升级标识
-                                        OperateDate = DateTime.Now, //操作时间
-                                    });
-                                    db.SaveChanges();
+                                        db.UserRank.Add(new UserRank()
+                                        {
+                                            CreateDate = DateTime.Now,
+                                            UpdateDate = DateTime.Now,
+                                            UserId = user.Id, //创客
+                                            WhiteRank = BeforeLevel,
+                                            Rank = AfterLevel, //当前等级
+                                            StatYear = DateTime.Now.Year, //统计年份
+                                            StatMonth = DateTime.Now.Month, //统计月份
+                                            TradeAmt = TradeAmount, //团队交易总额
+                                            UpgradeFlag = 1, //升级标识
+                                            OperateDate = DateTime.Now, //操作时间
+                                        });
+                                        db.SaveChanges();
+                                    }
                                 }
                                 // 降级逻辑
                                 // if(!upFlag && AfterLevel > 5)

+ 9 - 21
AppStart/Timer/StoreApplyHelper.cs

@@ -24,8 +24,8 @@ public class StoreApplyHelper
 
     // 每月1号重置仓库额度
     // 固定额度=上月出货额度与保底额度之间的最高值
-    // 已用额度=仓库中机具占用额度+小分仓机具占用额度+申请补货订单占用额度
-    // 可用额度=重置后的固定额度+被担保额度+临时额度-已用额度-小分仓未授权额度
+    // 已用额度=仓库中机具占用额度+小分仓机具占用额度+申请补货订单占用额度-小分仓中带“授”标记机具占用额度
+    // 可用额度=重置后的固定额度+被担保额度+临时额度-已用额度
     private void DoWorks()
     {
         while (true)
@@ -44,21 +44,8 @@ public class StoreApplyHelper
                         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 dts = OtherMySqlConn.dtable("select UserId from StoreHouse where CreateDate>='" + pre + "' and CreateDate<'" + end + "' and UserId in (select UserId from (select UserId,count(Id) from StoreHouse group by UserId HAVING count(Id)=1) tb)");
-                        // foreach(DataRow dr in dts.Rows)
-                        // {
-                        //     int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
-                        //     if(!dataDic.ContainsKey(UserId))
-                        //     {
-                        //         dataDic.Add(UserId, 20000);
-                        //     }
-                        //     else
-                        //     {
-                        //         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");
+                        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()));
@@ -74,7 +61,7 @@ public class StoreApplyHelper
                                 dataDic[store.UserId] += AmountMore;
                             }
                         }
-                        dt = OtherMySqlConn.dtable("select StoreId,count(Id) from StoreStockChange where CreateDate>='" + start + "' and CreateDate<'" + end + "' and BrandId in (3,5,9) and TransType in (10,11,2) and StoreId>0 group by StoreId");
+                        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()));
@@ -122,7 +109,7 @@ public class StoreApplyHelper
                             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()));
+                                PromissAmount += decimal.Parse(function.CheckNum(dr["PromissAmount"].ToString()));
                             }
                             decimal AmountMore = 0;
                             //仓库中机具占用额度+小分仓机具占用额度
@@ -136,13 +123,13 @@ public class StoreApplyHelper
                             {
                                 AmountMore += decimal.Parse(function.CheckNum(dtmore.Rows[0][0].ToString()));
                             }
-                            //除开小分仓未授权机具
-                            dtmore = OtherMySqlConn.dtable("select count(Id)*200 from PreSendStockDetail pos where StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (1,2,4,6,7,8) and `Status`=1");
+                            //除开小分仓中带“授”标记机具占用额度
+                            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 StoreId in (select Id from StoreHouse where UserId=" + UserId + ") and BrandId in (3,5,9) and `Status`=1");
+                            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()));
@@ -479,6 +466,7 @@ public class StoreApplyHelper
         ids.Add(28538);
         ids.Add(2927);
         ids.Add(584);
+        ids.Add(6659);
         return ids;
     }
 }