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

商城订单导出功能优化

DuGuYang 3 лет назад
Родитель
Сommit
cb7a95c2a7

+ 223 - 17
Areas/Admin/Controllers/MainServer/OrdersController.cs

@@ -178,7 +178,7 @@ namespace MySystem.Areas.Admin.Controllers
             //商品类型名称
             if (!string.IsNullOrEmpty(ProductIdSelect))
             {
-                condition += " and Id in (select OrderId from OrderProduct where ProductId="+ProductIdSelect+")";//表数据量过大时不适用
+                condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
             }
             //仓库类型
             if (!string.IsNullOrEmpty(StoreTypeSelect))
@@ -238,7 +238,7 @@ namespace MySystem.Areas.Admin.Controllers
                 if (SendStatus == 1) dic["SendStatusName"] = "已发货";
                 if (SendStatus == 2) dic["SendStatusName"] = "已退货";
                 if (SendStatus == 0)
-                { 
+                {
                     dic["SendInfo"] = dic["SendStatus"].ToString();
                 }
                 else
@@ -461,7 +461,7 @@ namespace MySystem.Areas.Admin.Controllers
         }
 
         #endregion
-        
+
         #region 发货
 
         public IActionResult Send(string right, int Id = 0)
@@ -557,11 +557,11 @@ namespace MySystem.Areas.Admin.Controllers
                 // string result = new Alipay.AlipayPublicClass(_accessor.HttpContext).Refund(set.AlipayAppId, set.AlipayPrivateKey, set.AlipayPublicKey, order.OrderNo, order.TotalPrice);
                 // if (result.StartsWith("success"))
                 // {
-                    order.RefundActAmount = data.RefundActAmount;
-                    order.RefundReason = data.RefundReason;
-                    order.RefundStatus = 1;                    
-                    db.SaveChanges();
-                    return "success";
+                order.RefundActAmount = data.RefundActAmount;
+                order.RefundReason = data.RefundReason;
+                order.RefundStatus = 1;
+                db.SaveChanges();
+                return "success";
                 // }
                 // else
                 // { 
@@ -951,7 +951,7 @@ namespace MySystem.Areas.Admin.Controllers
                     dic["ProductPrice"] = product.ProductPrice;  //商品单价
                     dic["NormDetail"] = product.NormDetail;  //商品规格
                     if (i == 1)
-                    { 
+                    {
                         ReturnFields.Add("ProductCode", "商品编号");
                         ReturnFields.Add("ProductName", "商品名称");
                         ReturnFields.Add("ProductCount", "商品数量");
@@ -986,7 +986,7 @@ namespace MySystem.Areas.Admin.Controllers
             // result.Add("Status", "1");
             // result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
             // result.Add("Obj", diclist);
-            
+
             var title = table.CreateRow(0);
             int j = 0;
             foreach (string key in ReturnFields.Keys)
@@ -1032,7 +1032,213 @@ namespace MySystem.Areas.Admin.Controllers
         #endregion
 
 
+        #region 导出Excel
+
+        /// <summary>
+        /// 导出Excel
+        /// </summary>
+        /// <returns></returns>
+        public JsonResult ExportsExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, string RedisKey = "ExportKey")
+        {
+            Dictionary<string, string> Fields = new Dictionary<string, string>();
+            Fields.Add("CreateDate", "3"); //时间
+            Fields.Add("OrderNo", "1"); //订单号
+            Fields.Add("RealName", "1"); //姓名
+            Fields.Add("Mobile", "1"); //手机号
+            Fields.Add("ErpCode", "1"); //运单号
+            Fields.Add("SendDate", "3"); //发货时间
+            Fields.Add("TradeNo", "1"); //支付交易号
+            Fields.Add("StoreContact", "1"); //仓库联系人
+            Fields.Add("SnNos", "2"); //SN编号
+            Fields.Add("TopUserId", "0");
+
+            string condition = " and Status>-1";
+            //创客编号
+            if (!string.IsNullOrEmpty(UserIdMakerCode))
+            {
+                condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
+            }
+            //创客真实姓名
+            if (!string.IsNullOrEmpty(UserIdRealName))
+            {
+                condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
+            }
+            //支付方式
+            if (!string.IsNullOrEmpty(PayModeSelect))
+            {
+                condition += " and PayMode=" + PayModeSelect;
+            }
+            //仓库编号
+            if (!string.IsNullOrEmpty(StoreIdStoreNo))
+            {
+                condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
+            }
+            //仓库名称
+            if (!string.IsNullOrEmpty(StoreIdStoreName))
+            {
+                condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
+            }
+            //退款状态
+            if (!string.IsNullOrEmpty(RefundStatusSelect))
+            {
+                condition += " and RefundStatus=" + RefundStatusSelect;
+            }
+            //提货类型
+            if (!string.IsNullOrEmpty(DeliveryTypeSelect))
+            {
+                condition += " and DeliveryType=" + DeliveryTypeSelect;
+            }
+            //发货状态
+            if (!string.IsNullOrEmpty(SendStatusSelect))
+            {
+                condition += " and SendStatus=" + SendStatusSelect;
+            }
+            //商品名称
+            if (!string.IsNullOrEmpty(ProductIdSelect))
+            {
+                condition += " and ProductId=" + ProductIdSelect;
+            }
+            //仓库类型
+            if (!string.IsNullOrEmpty(StoreTypeSelect))
+            {
+                condition += " and StoreType=" + StoreTypeSelect;
+            }
+            //仓库归属创客编号
+            if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
+            {
+                condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
+            }
+            //仓库归属创客真实姓名
+            if (!string.IsNullOrEmpty(StoreUserIdRealName))
+            {
+                condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
+            }
+            //支付状态
+            if (!string.IsNullOrEmpty(PayStatusSelect))
+            {
+                condition += " and PayStatus=" + PayStatusSelect;
+            }
+            Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,TradeNo,StoreId,RefundStatus,DeliveryType,SendStatus,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,PayStatus,BuyCount,Remark,Id", false);
+            List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
+            foreach (Dictionary<string, object> dic in diclist)
+            {
+                //创客
+                int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
+                Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                dic["UserIdMakerCode"] = userid_Users.MakerCode;
+                dic["UserIdRealName"] = userid_Users.RealName;
+                dic.Remove("UserId");
+                //物流名称
+                dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
+                //支付方式
+                int PayMode = int.Parse(dic["PayMode"].ToString());
+                if (PayMode == 1) dic["PayMode"] = "支付宝";
+                if (PayMode == 2) dic["PayMode"] = "微信";
+                if (PayMode == 3) dic["PayMode"] = "账户余额";
+                if (PayMode == 0) dic["PayMode"] = "";
+                //仓库
+                int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
+                StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
+                dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
+                dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
+                dic.Remove("StoreId");
+                //退款状态
+                int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
+                if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
+                if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
+                //提货类型
+                int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
+                if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
+                if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
+                if (DeliveryType == 0) dic["DeliveryType"] = "";
+                //发货状态
+                int SendStatus = int.Parse(dic["SendStatus"].ToString());
+                if (SendStatus == 0) dic["SendStatus"] = "未发货";
+                if (SendStatus == 1) dic["SendStatus"] = "已发货";
+                if (SendStatus == 2) dic["SendStatus"] = "已退货";
+                //商品名称
+                dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
+                //仓库类型
+                int StoreType = int.Parse(dic["StoreType"].ToString());
+                if (StoreType == 0) dic["StoreType"] = "总仓";
+                if (StoreType == 1) dic["StoreType"] = "分仓";
+                //仓库归属创客
+                int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
+                Users storeuserid_Users = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
+                dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
+                dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
+                dic.Remove("StoreUserId");
+                //顶级创客
+                int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
+                Users topuserid_Users = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
+                dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
+                dic["TopUserIdRealName"] = topuserid_Users.RealName;
+                dic.Remove("TopUserId");
+                //支付状态
+                int PayStatus = int.Parse(dic["PayStatus"].ToString());
+                if (PayStatus == 0) dic["PayStatus"] = "未支付";
+                if (PayStatus == 1) dic["PayStatus"] = "支付成功";
+                if (PayStatus == 2) dic["PayStatus"] = "支付失败";
+                if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
+                if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
+
+                int OrderId = int.Parse(dic["Id"].ToString());
+                List<OrderProduct> products = db.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
+                foreach (OrderProduct product in products)
+                {
+                    dic["ProductCode"] = product.ProductCode;  //商品编号
+                    dic["ProductName"] = product.ProductName;  //商品名称
+                    dic["ProductCount"] = product.ProductCount;  //商品数量
+                    dic["ProductPrice"] = product.ProductPrice;  //商品单价
+                    dic["NormDetail"] = product.NormDetail;  //商品规格
+                }
+                dic.Remove("Id");
+            }
+
+            Dictionary<string, object> result = new Dictionary<string, object>();
+            result.Add("Status", "1");
+            result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
+            result.Add("Obj", diclist);
+            Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
+            ReturnFields.Add("UserIdMakerCode", "创客编号");
+            ReturnFields.Add("UserIdRealName", "创客真实姓名");
+            ReturnFields.Add("OrderNo", "订单号");
+            ReturnFields.Add("RealName", "姓名");
+            ReturnFields.Add("Mobile", "手机号");
+            ReturnFields.Add("TotalPrice", "总价");
+            ReturnFields.Add("Areas", "所在地区");
+            ReturnFields.Add("Address", "详细地址");
+            ReturnFields.Add("ErpName", "物流名称");
+            ReturnFields.Add("ErpCode", "运单号");
+            ReturnFields.Add("SendDate", "发货时间");
+            ReturnFields.Add("PayMode", "支付方式");
+            ReturnFields.Add("TradeNo", "支付交易号");
+            ReturnFields.Add("StoreIdStoreNo", "仓库编号");
+            ReturnFields.Add("StoreIdStoreName", "仓库名称");
+            ReturnFields.Add("RefundStatus", "退款状态");
+            ReturnFields.Add("DeliveryType", "提货类型");
+            ReturnFields.Add("SendStatus", "发货状态");
+            ReturnFields.Add("ProductId", "商品名称");
+            ReturnFields.Add("StoreContact", "仓库联系人");
+            ReturnFields.Add("StoreType", "仓库类型");
+            ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
+            ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
+            ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
+            ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
+            ReturnFields.Add("PayStatus", "支付状态");
+            ReturnFields.Add("BuyCount", "下单数量");
+            ReturnFields.Add("Remark", "订单备注");
+            ReturnFields.Add("ProductCode", "商品编号");
+            ReturnFields.Add("ProductName", "商品名称");
+            ReturnFields.Add("ProductCount", "商品数量");
+            ReturnFields.Add("ProductPrice", "商品单价");
+            ReturnFields.Add("NormDetail", "商品规格");
+            result.Add("Fields", ReturnFields);
+            AddSysLog("0", "Orders", "ExportExcel");
+            return Json(result);
+        }
 
+        #endregion
 
 
         #region 查询直推奖励100
@@ -1043,7 +1249,7 @@ namespace MySystem.Areas.Admin.Controllers
             string result = "";
             Orders order = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
             if (order.PayStatus < 1)
-            { 
+            {
                 result += "未付款\n";
                 dic.Add("code", "1");
                 dic.Add("result", result);
@@ -1068,13 +1274,13 @@ namespace MySystem.Areas.Admin.Controllers
                     item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
                 }
                 if (item != null)
-                { 
-                    IsGet = "已发放(发放时间:"+item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")+")";
+                {
+                    IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
                     ToUserId = item.UserId;
                     dic.Add("code", "1");
                 }
                 else
-                { 
+                {
                     dic.Add("code", "0");
                 }
                 Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
@@ -1084,14 +1290,14 @@ namespace MySystem.Areas.Admin.Controllers
             }
             else
             {
-                result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";                
+                result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
                 dic.Add("code", "1");
             }
             dic.Add("result", result);
             return dic;
         }
         public string AddPrize100(int Id)
-        { 
+        {
             Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
             if (order != null)
             {
@@ -1160,7 +1366,7 @@ namespace MySystem.Areas.Admin.Controllers
                                 return "success";
                             }
                             else
-                            { 
+                            {
                                 return "上级创客未满足条件:购买机:" + machineCount + "台,激活机:" + ActiveCount + "台";
                             }
                         }

+ 1 - 1
Areas/Admin/Views/MainServer/Orders/Index.cshtml

@@ -235,7 +235,7 @@
                         </button>
                         @if (RightInfo.Contains("," + right + "_export,"))
                         {
-                        <button class="layui-btn" data-type="ExportExcel"><i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出</button>
+                        <button class="layui-btn" data-type="ExportsExcel"><i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出</button>
                         }
                     </div>
                 </div>

+ 18 - 0
wwwroot/layuiadmin/modules_main/Orders_Admin.js

@@ -541,6 +541,24 @@ layui.config({
                 }
             });
             $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
+        },ExportsExcel: function () {
+            var userdata = '';
+            $(".layuiadmin-card-header-auto input").each(function (i) {
+                userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
+            });
+            $(".layuiadmin-card-header-auto select").each(function (i) {
+                userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
+            });
+            $.ajax({
+                type: "GET",
+                url: "/Admin/Orders/ExportsExcel?r=" + Math.random(1),
+                data: userdata,
+                dataType: "json",
+                success: function (data) {
+                    data.Obj.unshift(data.Fields);
+                    excel.exportExcel(data.Obj, data.Info, 'xlsx');
+                }
+            });
         }
         , ExportExcel: function () {
             var userdata = '';