Просмотр исходного кода

Merge branch 'feature-dgy-仓库管理仓库统计管理修复' into DuGuYang

DuGuYang 2 лет назад
Родитель
Сommit
55562cb089

+ 122 - 60
Areas/Admin/Controllers/MainServer/StoreHouseController.cs

@@ -1454,7 +1454,7 @@ namespace MySystem.Areas.Admin.Controllers
         /// 仓库列表
         /// </summary>
         /// <returns></returns>
-        public JsonResult StatDo(string CreateDateData, int page = 1, int limit = 30)
+        public JsonResult StatDo(string MakerCode, string StoreNo, string CreateDateData, int page = 1, int limit = 30)
         {
             OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
             string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
@@ -1475,6 +1475,15 @@ namespace MySystem.Areas.Admin.Controllers
 
                 return Json(nodata);
             }
+            var condtion = "";
+            if (!string.IsNullOrEmpty(MakerCode))
+            {
+                condtion += "and MakerCode='" + MakerCode + "'";
+            }
+            if (!string.IsNullOrEmpty(StoreNo))
+            {
+                condtion += "and StoreNo='" + StoreNo + "'";
+            }
             string minId = "0";
             string maxId = "0";
             string minPosId = "0";
@@ -1505,33 +1514,35 @@ namespace MySystem.Areas.Admin.Controllers
                     }
                 }
             }
-            DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
-            if (startPosDt.Rows.Count > 0)
-            {
-                minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
-                if (minPosId == "0")
-                {
-                    startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
-                    if (startPosDt.Rows.Count > 0)
-                    {
-                        minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
-                    }
-                }
-            }
-            DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
-            if (endPosDt.Rows.Count > 0)
-            {
-                maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
-                if (maxPosId == "0")
-                {
-                    endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
-                    if (endPosDt.Rows.Count > 0)
-                    {
-                        maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
-                    }
-                }
-            }
-            DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
+            // DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
+            // if (startPosDt.Rows.Count > 0)
+            // {
+            //     minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
+            //     if (minPosId == "0")
+            //     {
+            //         startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
+            //         if (startPosDt.Rows.Count > 0)
+            //         {
+            //             minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
+            //         }
+            //     }
+            // }
+            // DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
+            // if (endPosDt.Rows.Count > 0)
+            // {
+            //     maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
+            //     if (maxPosId == "0")
+            //     {
+            //         endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
+            //         if (endPosDt.Rows.Count > 0)
+            //         {
+            //             maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
+            //         }
+            //     }
+            // }
+            // DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where (c1>0 or c2>0 or c3>0) " + condtion);
+
+            DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.MakerCode,u.RealName,u.Mobile,s.ManageMobile,s.Address,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1, (select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2, (select ActCount from KxsStatServer.StoreAct202211 where StoreId=s.Id) as c3, ua.FixedAmount, ua.ValidAmount, ua.TempAmount, (select sum(PromissAmount) from StoreHouseAmountPromiss where ToUserId=s.UserId and `Status`=1) as PromissAmount from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id left join UserAccount ua on s.UserId=ua.Id) tb where (c1>0 or c2>0 or c3>0)" + condtion + "");
 
             int recordcount = list.Rows.Count;
             List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
@@ -1567,7 +1578,7 @@ namespace MySystem.Areas.Admin.Controllers
         /// 导出Excel
         /// </summary>
         /// <returns></returns>
-        public JsonResult StatExportExcel(string CreateDateData)
+        public JsonResult StatExportExcel(string MakerCode, string StoreNo, string CreateDateData)
         {
             OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
             string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
@@ -1590,7 +1601,7 @@ namespace MySystem.Areas.Admin.Controllers
                 NoDataReturnFields.Add("Mobile", "仓库所属人手机号");
                 NoDataReturnFields.Add("RealName", "仓库所属人名称");
                 NoDataReturnFields.Add("MakerCode", "仓库所属人编码");
-                NoDataReturnFields.Add("ManageMakerCode", "仓库管理员编码");
+                // NoDataReturnFields.Add("ManageMakerCode", "仓库管理员编码");
                 NoDataReturnFields.Add("Name", "品牌");
                 NoDataReturnFields.Add("LaveNum", "当前库存");
                 NoDataReturnFields.Add("c1", "出库(调拨)量");
@@ -1599,6 +1610,16 @@ namespace MySystem.Areas.Admin.Controllers
                 nodata.Add("Fields", NoDataReturnFields);
                 return Json(nodata);
             }
+
+            var condtion = "";
+            if (!string.IsNullOrEmpty(MakerCode))
+            {
+                condtion += "and MakerCode='" + MakerCode + "'";
+            }
+            if (!string.IsNullOrEmpty(StoreNo))
+            {
+                condtion += "and StoreNo='" + StoreNo + "'";
+            }
             string minId = "0";
             string maxId = "0";
             string minPosId = "0";
@@ -1629,34 +1650,7 @@ namespace MySystem.Areas.Admin.Controllers
                     }
                 }
             }
-            DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
-            if (startPosDt.Rows.Count > 0)
-            {
-                minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
-                if (minPosId == "0")
-                {
-                    startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
-                    if (startPosDt.Rows.Count > 0)
-                    {
-                        minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
-                    }
-                }
-            }
-            DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
-            if (endPosDt.Rows.Count > 0)
-            {
-                maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
-                if (maxPosId == "0")
-                {
-                    endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
-                    if (endPosDt.Rows.Count > 0)
-                    {
-                        maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
-                    }
-                }
-            }
-            DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,u.MakerCode,(select MakerCode from Users where Id=s.ManageUserId) as ManageMakerCode,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
-
+            DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.MakerCode,u.RealName,u.Mobile,s.ManageMobile,s.Address,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1, (select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2, (select ActCount from KxsStatServer.StoreAct202211 where StoreId=s.Id) as c3, ua.FixedAmount, ua.ValidAmount, ua.TempAmount, (select sum(PromissAmount) from StoreHouseAmountPromiss where ToUserId=s.UserId and `Status`=1) as PromissAmount from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id left join UserAccount ua on s.UserId=ua.Id) tb where (c1>0 or c2>0 or c3>0)" + condtion + "");
             int recordcount = list.Rows.Count;
             List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
             foreach (DataRow sub in list.Rows)
@@ -1667,7 +1661,7 @@ namespace MySystem.Areas.Admin.Controllers
                 row.Add("Mobile", sub["Mobile"].ToString());
                 row.Add("RealName", sub["RealName"].ToString());
                 row.Add("MakerCode", sub["MakerCode"].ToString());
-                row.Add("ManageMakerCode", sub["ManageMakerCode"].ToString());
+                // row.Add("ManageMakerCode", sub["ManageMakerCode"].ToString());
                 row.Add("Name", sub["Name"].ToString());
                 row.Add("LaveNum", sub["LaveNum"].ToString());
                 row.Add("c1", sub["c1"].ToString());
@@ -1686,7 +1680,7 @@ namespace MySystem.Areas.Admin.Controllers
             ReturnFields.Add("Mobile", "仓库所属人手机号");
             ReturnFields.Add("RealName", "仓库所属人名称");
             ReturnFields.Add("MakerCode", "仓库所属人编码");
-            ReturnFields.Add("ManageMakerCode", "仓库管理员编码");
+            // ReturnFields.Add("ManageMakerCode", "仓库管理员编码");
             ReturnFields.Add("Name", "品牌");
             ReturnFields.Add("LaveNum", "当前库存");
             ReturnFields.Add("c1", "出库(调拨)量");
@@ -1700,6 +1694,74 @@ namespace MySystem.Areas.Admin.Controllers
         #endregion
 
 
+        #region 快捷导出Excel
+        public IActionResult StatQuickExportExcel(string right)
+        {
+            ViewBag.RightInfo = RightInfo;
+            ViewBag.right = right;
+
+            return View();
+        }
+
+        [HttpPost]
+        public string StatQuickExportExcelDo(string MakerCode, string StoreNo, string CreateDateData)
+        {
+
+            string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
+            string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
+            if (!string.IsNullOrEmpty(CreateDateData))
+            {
+                string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
+                sCreateDate = datelist[0] + " 00:00:00";
+                eCreateDate = datelist[1] + " 23:59:59";
+            }
+            var condtion = "";
+            if (!string.IsNullOrEmpty(MakerCode))
+            {
+                condtion += "and MakerCode='" + MakerCode + "'";
+            }
+            if (!string.IsNullOrEmpty(StoreNo))
+            {
+                condtion += "and StoreNo='" + StoreNo + "'";
+            }
+            string minId = "0";
+            string maxId = "0";
+            DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
+            if (startDt.Rows.Count > 0)
+            {
+                minId = function.CheckInt(startDt.Rows[0][0].ToString());
+                if (minId == "0")
+                {
+                    startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
+                    if (startDt.Rows.Count > 0)
+                    {
+                        minId = function.CheckInt(startDt.Rows[0][0].ToString());
+                    }
+                }
+            }
+            DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
+            if (endDt.Rows.Count > 0)
+            {
+                maxId = function.CheckInt(endDt.Rows[0][0].ToString());
+                if (minId == "0")
+                {
+                    endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
+                    if (endDt.Rows.Count > 0)
+                    {
+                        maxId = function.CheckInt(endDt.Rows[0][0].ToString());
+                    }
+                }
+            }
+            var Sql = "select StoreName '仓库名称',StoreNo '仓库编号',MakerCode '仓库所属人编码',RealName '仓库所属人名称',Mobile '仓库所属人手机号',ManageMobile '仓库管理员手机号',Address '地址',Name '品牌',LaveNum '当前库存',c1 '出库(调拨)量',c2 '出货(发货到创客)量',c3 '激活量' from (select s.StoreName,s.StoreNo,u.MakerCode,u.RealName,u.Mobile,s.ManageMobile,s.Address,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1, (select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2, (select ActCount from KxsStatServer.StoreAct202211 where StoreId=s.Id) as c3, ua.FixedAmount, ua.ValidAmount, ua.TempAmount, (select sum(PromissAmount) from StoreHouseAmountPromiss where ToUserId=s.UserId and `Status`=1) as PromissAmount from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id left join UserAccount ua on s.UserId=ua.Id) tb where (c1>0 or c2>0 or c3>0)" + condtion + "";
+            var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
+            var FileName = "仓库统计管理记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
+            RedisDbconn.Instance.AddList("ExportQueue", SendData);
+            return "success";
+        }
+        #endregion
+
+
         #region 同步数据
 
         /// <summary>

+ 35 - 10
wwwroot/layuiadmin/modules_main/StoreHouseStat_Admin.js

@@ -555,16 +555,41 @@ layui.config({
             $(".layuiadmin-card-header-auto select").each(function (i) {
                 userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
             });
-            $.ajax({
-                type: "GET",
-                url: "/Admin/StoreHouse/StatExportExcel?r=" + Math.random(1),
-                data: userdata,
-                dataType: "json",
-                success: function (data) {
-                    data.Obj.unshift(data.Fields);
-                    excel.exportExcel(data.Obj, data.Info, 'xlsx');
-                    layer.close(loadindex);
-                }
+            // $.ajax({
+            //     type: "GET",
+            //     url: "/Admin/StoreHouse/StatExportExcel?r=" + Math.random(1),
+            //     data: userdata,
+            //     dataType: "json",
+            //     success: function (data) {
+            //         data.Obj.unshift(data.Fields);
+            //         excel.exportExcel(data.Obj, data.Info, 'xlsx');
+            //         layer.close(loadindex);
+            //     }
+            // });
+            var index = layer.confirm('确定导出吗?', function (index) {
+                var indexs = layer.load(1, {
+                    shade: [0.5, '#000']
+                });
+                $.ajax({
+                    type: "POST",
+                    url: "/Admin/StoreHouse/StatQuickExportExcelDo?r=" + Math.random(1),
+                    data: userdata,
+                    dataType: "text",
+                    success: function (data) {
+                        layer.close(index); //关闭弹层
+                        if (data == "success") {
+                            layer.close(indexs); //关闭弹层
+                            layer.msg('导出成功,请到我的下载中点击下载文件', {
+                                time: 1000
+                            }, function () {
+                                window.location.reload();
+                            });
+                        } else {
+                            layer.close(indexs); //关闭弹层
+                            layer.msg(data);
+                        }
+                    }
+                });
             });
         },
         Open: function () {