DuGuYang vor 2 Jahren
Ursprung
Commit
087613fa53

+ 8 - 0
AppStart/Redis/RedisDbconn.cs

@@ -147,6 +147,14 @@ namespace MySystem
         }
         }
         #endregion
         #endregion
 
 
+        #region 删除列表对象
+        public long DelFromList(string key, object value)
+        {
+            return csredis.LRem(key, 0, value);
+            // return false;
+        }
+        #endregion
+
         #region 获取列表
         #region 获取列表
         public List<T> GetList<T>(string key, int pageNum = 1, int pageSize = 10)
         public List<T> GetList<T>(string key, int pageNum = 1, int pageSize = 10)
         {
         {

+ 153 - 0
Areas/Admin/Controllers/MainServer/PreSendStockDetailController.cs

@@ -585,6 +585,159 @@ namespace MySystem.Areas.Admin.Controllers
         #endregion
         #endregion
 
 
 
 
+        #region 预发机撤回
+
+        /// <summary>
+        /// 预发机撤回
+        /// </summary>
+        /// <returns></returns>
+        public string Cancle(string Id)
+        {
+            string[] idlist = Id.Split(new char[] { ',' });
+            AddSysLog(Id, "PreSendStockDetail", "cancle");
+            foreach (string subid in idlist)
+            {
+                int id = int.Parse(subid);
+                Dictionary<string, object> Fields = new Dictionary<string, object>();
+                Fields.Add("Status", -1);
+                new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PreSendStockDetail", Fields, id);
+                
+                string check = RedisDbconn.Instance.Get<string>("SmallStoreCancel:" + id);
+                if (!string.IsNullOrEmpty(check))
+                {
+                    return "请勿频繁操作,稍后再试";
+                }
+                RedisDbconn.Instance.Set("SmallStoreCancel:" + id, "wait");
+                RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + id, 3);
+                var query = db.PreSendStockDetail.FirstOrDefault(m => m.Id == id);
+                var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == query.FromUserId) ?? new UserAccount();
+                var tuserAccount = db.UserAccount.FirstOrDefault(m => m.Id == query.ToUserId) ?? new UserAccount();
+                KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == query.BrandId);
+                var date = DateTime.Now.AddDays(-30);
+                var amount = 0;
+                if (query != null)
+                {
+                    PosMachinesTwo posMachinesTwo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId) ?? new PosMachinesTwo();
+                    StoreHouse storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse();
+                    PosMachinesTwo pm = db.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId);
+                    var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == posMachinesTwo.BrandId);
+                    if (brandInfo.Name.Contains("电签"))
+                    {
+                        amount = 200;
+                    }
+                    if (brandInfo.Name.Contains("大POS"))
+                    {
+                        amount = 300;
+                    }
+                    if (pm != null)
+                    {
+                        // if (pm.BindingState == 1)
+                        // {
+                        //     return "机具已绑定,不可撤回!请创客申请机具后补录!";
+                        // }
+                        SmallStoreHouse smallStoreHouse = db.SmallStoreHouse.FirstOrDefault(m => m.UserId == query.ToUserId);
+                        posMachinesTwo.PreUserId = 0;
+                        query.UpdateDate = DateTime.Now;
+                        query.Status = -1;
+                        query.CancelFlag = 1;
+                        storeHouse.LaveNum += 1;
+                        smallStoreHouse.UpdateDate = DateTime.Now;
+                        smallStoreHouse.LaveNum += 1;
+                        smallStoreHouse.TotalNum -= 1;
+                        if (query.CreateDate <= date)
+                        {
+                            //撤回占用小分仓额度的增加接收创客的小分仓可用额度
+                            if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount)
+                            {
+                                userAccount.ValidAmount -= amount;//扣减分仓可用额度
+                                tuserAccount.SmallStoreDeposit -= amount;
+                                tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度
+                                var add = db.UserAccountRecord.Add(new UserAccountRecord()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    Remark = "小分仓押金退还",
+                                    ChangeType = 66,
+                                    BeforeBalanceAmount = tuserAccount.SmallStoreDeposit + amount, //变更前小分仓押金
+                                    AfterBalanceAmount = tuserAccount.SmallStoreDeposit, //变更后小分仓押金
+                                    ChangeAmount = amount,//变动金额
+                                    UserId = tuserAccount.Id,
+                                }).Entity;
+                                db.SaveChanges();
+                            }
+                        }
+                        else
+                        {
+                            //撤回占用小分仓额度的增加接收创客的小分仓可用额度
+                            if (query.AuthFlag == 1)
+                            {
+                                tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度
+                                userAccount.ValidAmount -= amount;//扣减分仓可用额度
+                            }
+                        }
+                        // if(query)
+                        string text = string.Format("创客-首页-仓库管理-小分仓-撤回,UserId: '" + query.FromUserId + "',ToUserId: '" + smallStoreHouse.UserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + 1 + "',Time'" + DateTime.Now + "'");
+                        function.WriteLog(text, "smallstorehouse");//小分仓记录日志
+                        if (smallStoreHouse.LaveNum > 10 || smallStoreHouse.TotalNum < 0)
+                        {
+                            return "*库存已重置,不可撤回!";
+                        }
+                        db.SaveChanges();
+                        RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+                        {
+                            UserId = query.ToUserId, //收货创客
+                            Title = "预发机撤回通知", //标题
+                            Content = "<div class='f16'>您的预发机 SN:<br/>" + query.SnNo + "<br/>已被" + storeHouse.StoreName + " 撤回!</div>", //内容
+                            Summary = "您的预发机: " + kqProducts.Name + "  sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!",
+                            CreateDate = DateTime.Now,
+
+                        }));
+
+                        var toUser = db.Users.FirstOrDefault(m => m.Id == query.ToUserId);
+                        RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
+                        {
+                            UserId = query.FromUserId, //收货创客
+                            Title = "预发机撤回通知", //标题
+                            Content = "<div class='f16'>已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:<br/>" + query.SnNo + "</div>", //内容
+                            Summary = "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + "",
+                            CreateDate = DateTime.Now,
+
+                        }));
+
+                        //删除预发机过期提醒
+                        List<Dictionary<string, string>> result = RedisDbconn.Instance.GetList<Dictionary<string, string>>("PrePosRing:" + DateTime.Now.ToString("yyyyMMdd") + ":" + query.ToUserId);
+                        if (result.Count > 0)
+                        {
+                            foreach (Dictionary<string, string> item in result)
+                            {
+                                if (item["SnNo"] == pm.PosSn)
+                                {
+                                    RedisDbconn.Instance.DelFromList("PrePosRing:" + DateTime.Now.ToString("yyyyMMdd") + ":" + query.ToUserId, item);
+                                }
+                            }
+                        }
+                        result = RedisDbconn.Instance.GetList<Dictionary<string, string>>("PrePosRingForExpired:" + DateTime.Now.ToString("yyyyMMdd") + ":" + query.ToUserId);
+                        if (result.Count > 0)
+                        {
+                            foreach (Dictionary<string, string> item in result)
+                            {
+                                if (item["SnNo"] == pm.PosSn)
+                                {
+                                    RedisDbconn.Instance.DelFromList("PrePosRingForExpired:" + DateTime.Now.ToString("yyyyMMdd") + ":" + query.ToUserId, item);
+                                }
+                            }
+                        }
+                    }
+                }
+                RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + id, 1);
+            }
+            db.SaveChanges();
+
+            return "success";
+        }
+
+        #endregion
+
+
         #region 预发货库存明细列表(占额度超过30天未兑换)
         #region 预发货库存明细列表(占额度超过30天未兑换)
 
 
         /// <summary>
         /// <summary>

+ 2 - 2
Areas/Admin/Views/MainServer/PreSendStockDetail/Index.cshtml

@@ -192,9 +192,9 @@
                     {
                     {
                         <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                         <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                     }
                     }
-                    @if (RightInfo.Contains("," + right + "_edit,"))
+                    @if (RightInfo.Contains("," + right + "_Cancle,"))
                     {
                     {
-
+                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="Cancle"><i class="layui-icon layui-icon-edit"></i>撤回</a>
                     }
                     }
                 </script>
                 </script>
             </div>
             </div>

+ 17 - 0
wwwroot/layuiadmin/modules_main/PreSendStockDetail_Admin.js

@@ -174,6 +174,23 @@ layui.config({
                     }
                     }
                 });
                 });
             });
             });
+        }
+        else if (obj.event === 'Cancle') {
+            var index = layer.confirm('确定要撤回吗?撤回后不能恢复!', function (index) {
+                $.ajax({
+                    type: "POST",
+                    url: "/Admin/PreSendStockDetail/Cancle?r=" + Math.random(1),
+                    data: "Id=" + data.Id,
+                    dataType: "text",
+                    success: function (data) {
+                        if (data == "success") {
+                            layer.close(index);
+                        } else {
+                            parent.layer.msg(data);
+                        }
+                    }
+                });
+            });
         } else if (obj.event === 'edit') {
         } else if (obj.event === 'edit') {
             var tr = $(obj.tr);
             var tr = $(obj.tr);
             var perContent = layer.open({
             var perContent = layer.open({