Ver código fonte

坏机回仓、机具回仓退款,要重置创客机具数

lcl 3 anos atrás
pai
commit
0108d8ab97

+ 32 - 0
AppStart/PublicFunction.cs

@@ -439,6 +439,38 @@ namespace MySystem
 
         #endregion
 
+        #region 统计机具绑定数据
+
+        public static void StatUserMachineData(int UserId, int BrandId, int Count)
+        {
+            using (WebCMSEntities db = new WebCMSEntities())
+            {
+                string IdBrand = UserId + "_" + BrandId;
+                UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                if (MachineData == null)
+                {
+                    MachineData = db.UserMachineData.Add(new UserMachineData()
+                    {
+                        IdBrand = IdBrand,
+                    }).Entity;
+                    db.SaveChanges();
+                }
+                if(Count < 0)
+                {
+                    MachineData.TotalMachineCount -= Math.Abs(Count);
+                    MachineData.UnBindCount -= Math.Abs(Count);
+                }
+                else
+                {
+                    MachineData.TotalMachineCount += Count;
+                    MachineData.UnBindCount += Count;
+                }
+                db.SaveChanges();
+            }
+        }
+
+        #endregion
+
         #region 退回仓库,清除历史记录
 
         public static void ClearPosHistory(WebCMSEntities db, string PosSn)

+ 21 - 0
Areas/Admin/Controllers/MainServer/SysToolsController.cs

@@ -4079,6 +4079,7 @@ namespace MySystem.Areas.Admin.Controllers
             string[] OldSnList;
             OldSnList = OldSn.Replace("\r", "").Split('\n');
             string error = "";
+            List<string> opData = new List<string>();
             for (int i = 0; i < OldSnList.Length; i++)
             {
                 string OldSnNum = OldSnList[i];
@@ -4089,6 +4090,10 @@ namespace MySystem.Areas.Admin.Controllers
                 {
                     error += "以下操作失败" + OldSnNum + ',' + "该机具不在坏机仓或不存在" + '\n';
                 }
+                if(!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
+                {
+                    opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
+                }
                 oldpos.Status = 1;
                 oldpos.QueryCount = 0;
                 oldpos.UpdateDate = null;
@@ -4136,6 +4141,11 @@ namespace MySystem.Areas.Admin.Controllers
                 return "Warning|" + error;
             }
             db.SaveChanges();
+            foreach(string sub in opData)
+            {
+                string[] datalist = sub.Split(":");
+                PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
+            }
             return "success";
         }
         #endregion
@@ -4250,6 +4260,7 @@ namespace MySystem.Areas.Admin.Controllers
             var endTime = time.AddDays(20 - time.Day).AddDays(-60);
             StoreForCode storeForBack = new StoreForCode();
             StoreHouse BackStore = new StoreHouse();
+            List<string> opData = new List<string>();
             foreach (var item in PosSnList)
             {
                 MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
@@ -4391,6 +4402,11 @@ namespace MySystem.Areas.Admin.Controllers
                     var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
                     userMachineDatas.TotalMachineCount -= 1;
                     userMachineDatas.UnBindCount -= 1;
+                    
+                    if(!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
+                    {
+                        opData.Add(pos.BuyUserId + ":" + pos.BrandId);
+                    }
 
                     pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
                     pos.Status = 1;
@@ -4472,6 +4488,11 @@ namespace MySystem.Areas.Admin.Controllers
                 }
             }
             db.SaveChanges();
+            foreach(string sub in opData)
+            {
+                string[] datalist = sub.Split(":");
+                PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
+            }
             return "success";
         }
         #endregion