瀏覽代碼

Merge branch 'feature-小分仓额度' into develop

lichunlei 2 年之前
父節點
當前提交
5bd575e24f
共有 4 個文件被更改,包括 113 次插入8 次删除
  1. 1 0
      AppStart/Helper/Profit/ProfitHelperV2.cs
  2. 88 0
      AppStart/Timer/ResetSmallStoreHelper.cs
  3. 23 8
      AppStart/Timer/StoreApplyHelper.cs
  4. 1 0
      Startup.cs

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

@@ -43,6 +43,7 @@ namespace MySystem
                 check = check.AddDays(1);
             }
 
+            RedisDbconn.Instance.AddList("ResetSmallStoreQueue", "1");
             ProfitHelper.Instance.StatProfit();
         }
         public void StatProfitEveryDay(object sender)

+ 88 - 0
AppStart/Timer/ResetSmallStoreHelper.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Linq;
+using System.Data;
+using MySystem;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+public class ResetSmallStoreHelper
+{
+    public readonly static ResetSmallStoreHelper Instance = new ResetSmallStoreHelper();
+    private ResetSmallStoreHelper()
+    {
+    }
+
+    public void Start()
+    {
+        Thread th = new Thread(DoWorks);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    // 每月1号小分仓额度,额度为上个月实际发放的总分润
+    private void DoWorks()
+    {
+        while (true)
+        {
+            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();
+            try
+            {
+                string content = RedisDbconn.Instance.RPop<string>("ResetSmallStoreQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
+                    string check = function.ReadInstance("/ResetSmallStore/" + Month + ".txt");
+                    if(string.IsNullOrEmpty(check))
+                    {
+                        function.WritePage("/ResetSmallStore/", Month + ".txt", DateTime.Now.ToString());
+                        string minId = "0";
+                        DataTable minIdDt = OtherMySqlConn.dtable("select min(Id) from ProfitRewardRecord where TradeMonth='" + Month + "'");
+                        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='" + Month + "' 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()));
+                            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 = ProfitAmount;
+                            account.ValidPreAmount = ProfitAmount;
+                            if(index % 200 == 0)
+                            {
+                                db.SaveChanges();
+                            }
+                            function.WriteLog(index.ToString(), "计算小分仓额度日志");
+                        }
+                        db.SaveChanges();
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "计算小分仓额度异常");
+            }
+            db.Dispose();
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算小分仓额度日志");
+            Thread.Sleep(60000);
+        }
+    }
+}

+ 23 - 8
AppStart/Timer/StoreApplyHelper.cs

@@ -25,7 +25,7 @@ public class StoreApplyHelper
     // 每月1号重置仓库额度
     // 固定额度=上月出货额度与保底额度之间的最高值
     // 已用额度=仓库中机具占用额度+小分仓机具占用额度+申请补货订单占用额度
-    // 可用额度=重置后的固定额度+被担保额度+临时额度-已用额度
+    // 可用额度=重置后的固定额度+被担保额度+临时额度-已用额度-小分仓未授权额度
     private void DoWorks()
     {
         while (true)
@@ -136,6 +136,17 @@ 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");
+                            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");
+                            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)
@@ -260,14 +271,18 @@ public class StoreApplyHelper
                             foreach(string SnIdString in SnIdList)
                             {
                                 int SnId = int.Parse(SnIdString);
-                                PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
-                                if(pos.BrandId == 1 || pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 6 || pos.BrandId == 7 || pos.BrandId == 8)
-                                {
-                                    Amount += 200;
-                                }
-                                else if(pos.BrandId == 3 || pos.BrandId == 5 || pos.BrandId == 9)
+                                PreSendStockDetail prepos = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == SnId && m.Status == 1 && m.ApplyFlag == 1) ?? new PreSendStockDetail();
+                                if(prepos.AuthFlag == 0)
                                 {
-                                    Amount += 300;
+                                    PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
+                                    if(pos.BrandId == 1 || pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 6 || pos.BrandId == 7 || pos.BrandId == 8)
+                                    {
+                                        Amount += 200;
+                                    }
+                                    else if(pos.BrandId == 3 || pos.BrandId == 5 || pos.BrandId == 9)
+                                    {
+                                        Amount += 300;
+                                    }
                                 }
                             }
                             if(Amount > 0)

+ 1 - 0
Startup.cs

@@ -212,6 +212,7 @@ namespace MySystem
             SetDepositPostService.Instance.Start(); //提交支付公司设置费率接口
             SetDepositPostService.Instance.StartKdb(); //监控开店宝费率设置结果
             SetFeeFlagService.Instance.Start(); //178天提前通知创客费率调升消息
+            ResetSmallStoreHelper.Instance.Start();
 
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数