فهرست منبع

购买临时额度才加临时额度

lichunlei 2 سال پیش
والد
کامیت
3a120ec56f
1فایلهای تغییر یافته به همراه47 افزوده شده و 8 حذف شده
  1. 47 8
      AppStart/Timer/StoreApplyHelper.cs

+ 47 - 8
AppStart/Timer/StoreApplyHelper.cs

@@ -117,20 +117,18 @@ public class StoreApplyHelper
                     JsonData jsonObj = JsonMapper.ToObject(data);
                     if(jsonObj["Kind"].ToString() == "1") // 购买临时额度
                     {
-                        function.WriteLog("1", "分仓向总仓申请机具日志");
                         int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString());
                         Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
                         if(order != null)
                         {
-                            function.WriteLog("2", "分仓向总仓申请机具日志");
                             decimal TotalPrice = order.TotalPrice * 2;
-                            AddAmount(db, order.UserId, TotalPrice, 1, order.Id);
+                            AddAmount2(db, order.UserId, TotalPrice, 1, order.Id);
                         }
                     }
                     else if(jsonObj["Kind"].ToString() == "2") // 增减分仓临时额度
                     {
                         int UserId = int.Parse(jsonObj["Data"]["UserId"].ToString());
-                        int Amount = int.Parse(jsonObj["Data"]["Amount"].ToString());
+                        decimal Amount = decimal.Parse(jsonObj["Data"]["Amount"].ToString());
                         int OperateType = int.Parse(jsonObj["Data"]["OperateType"].ToString());
                         AddAmount(db, UserId, Amount, OperateType);
                     }
@@ -176,7 +174,7 @@ public class StoreApplyHelper
                             }).Entity;
                         }
                     }
-                    else if(jsonObj["Kind"].ToString() == "4")
+                    else if(jsonObj["Kind"].ToString() == "4") // 仓库发货,预发机申请
                     {
                         int StoreId = int.Parse(jsonObj["Data"]["StoreId"].ToString());
                         string SnIds = jsonObj["Data"]["SnIds"].ToString();
@@ -204,7 +202,7 @@ public class StoreApplyHelper
                             }
                         }
                     }
-                    else if(jsonObj["Kind"].ToString() == "5")
+                    else if(jsonObj["Kind"].ToString() == "5") // 后台仓库调拨
                     {
                         int StoreId = int.Parse(jsonObj["Data"]["StoreId"].ToString());
                         int BrandId = int.Parse(jsonObj["Data"]["BrandId"].ToString());
@@ -229,6 +227,10 @@ public class StoreApplyHelper
                     }
                     db.SaveChanges();
                 }
+                else
+                {
+                    Thread.Sleep(5000);
+                }
             }
             catch (Exception ex)
             {
@@ -250,7 +252,44 @@ public class StoreApplyHelper
             }).Entity;
             db.SaveChanges();
         }
-        decimal BeforeTotalAmount = account.TempAmount; //变更前总金额
+        decimal BeforeTotalAmount = account.ValidAmount; //变更前总金额
+        if(OperateType == 1)
+        {
+            account.ValidAmount += Amount;
+        }
+        else
+        {
+            account.ValidAmount -= Amount;
+        }
+        decimal AfterTotalAmount = account.ValidAmount; //变更后总金额
+        StoreHouseAmountRecord record = db.StoreHouseAmountRecord.Add(new StoreHouseAmountRecord()
+        {
+            CreateDate = DateTime.Now,
+            UpdateDate = DateTime.Now,
+            OperateType = OperateType,
+            AmountType = 1,
+            AfterAmount = AfterTotalAmount,
+            BeforeAmount = BeforeTotalAmount,
+            UseAmount = Amount,
+            UserId = UserId,
+            QueryCount = OrderId,
+        }).Entity;
+        db.SaveChanges();
+    }
+
+    public void AddAmount2(WebCMSEntities db, int UserId, decimal Amount, int OperateType = 1, int OrderId = 0)
+    {
+        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 BeforeTotalAmount = account.ValidAmount; //变更前总金额
         if(OperateType == 1)
         {
             account.TempAmount += Amount;
@@ -261,7 +300,7 @@ public class StoreApplyHelper
             account.TempAmount -= Amount;
             account.ValidAmount -= Amount;
         }
-        decimal AfterTotalAmount = account.TempAmount; //变更后总金额
+        decimal AfterTotalAmount = account.ValidAmount; //变更后总金额
         StoreHouseAmountRecord record = db.StoreHouseAmountRecord.Add(new StoreHouseAmountRecord()
         {
             CreateDate = DateTime.Now,