Beispiel #1
0
        /// <summary>
        /// 导出EXCEL
        /// </summary>
        /// <param name="day"></param>
        /// <param name="pay_state"></param>
        /// <param name="order_state"></param>
        public void ExportExcel(int day, int pay_state, int order_state)
        {
            var order_list = OrderCache($"orderlist_{day}", day);

            if (order_list.Any())
            {
                order_list = order_list.Where(n => n.pay_state == pay_state && n.order_state == order_state).ToList();
                List <dynamic> list = new List <dynamic>();
                if (order_list.Any())
                {
                    foreach (var item in order_list)
                    {
                        var one = new
                        {
                            item.id,
                            product_name = item.product.name,
                            pay_state    = Enum.GetName(typeof(Pay_state), item.pay_state),
                            order_state  = Enum.GetName(typeof(Order_state), item.order_state),
                            user_name    = item.user.name,
                            item.order_number,
                            item.wx_order_num,
                            item.user_remark,
                            item.add_time,
                            item.pay_time,
                            item.refund_number,
                            item.pay_account,
                            item.count,
                            item.product.price,
                            item.order_money
                        };
                        list.Add(one);
                    }
                    if (list.Any())
                    {
                        DataTable dt = ListToDataTable.List2DataTable <dynamic>(list);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            dt.Columns["id"].ColumnName            = "id";
                            dt.Columns["product_name"].ColumnName  = "产品名称";
                            dt.Columns["user_name"].ColumnName     = "用户名称";
                            dt.Columns["count"].ColumnName         = "产品个数";
                            dt.Columns["price"].ColumnName         = "产品价格";
                            dt.Columns["order_money"].ColumnName   = "订单金额";
                            dt.Columns["pay_state"].ColumnName     = "支付状态";
                            dt.Columns["order_state"].ColumnName   = "订单状态";
                            dt.Columns["order_number"].ColumnName  = "订单号";
                            dt.Columns["wx_order_num"].ColumnName  = "微信订单号";
                            dt.Columns["add_time"].ColumnName      = "下单时间";
                            dt.Columns["pay_time"].ColumnName      = "支付时间";
                            dt.Columns["pay_account"].ColumnName   = "付款账号";
                            dt.Columns["refund_number"].ColumnName = "退单号";
                        }
                        bool hh = OfficeHelper.ExportExcelWithAspose(dt, $"{day}天内订单信息{DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}", "", true);
                    }
                }
            }
        }
        /// <summary>
        /// 导出用户EXCEL
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public void ExportExcel(string name)
        {
            var user_list = CacheUser("all_user_list");

            if (user_list.Any())
            {
                if (!string.IsNullOrEmpty(name))
                {
                    user_list = user_list.Where(n => n.name.Contains(name)).ToList();
                }
                List <dynamic> list = new List <dynamic>();
                if (user_list.Any())
                {
                    foreach (var item in user_list)
                    {
                        var one = new
                        {
                            item.id,
                            item.name,
                            item.tel,
                            parent_user = item.pid == 0 ? "" : user_list.FirstOrDefault(n => n.id == item.pid).name,
                            item.total_pay,
                            item.sex,
                            state = Enum.GetName(typeof(User_state), item.state),
                            item.wx_user.nickname,
                            item.wx_user.add_time,
                            item.total_product_count,
                            item.usable_score,
                            item.total_score,
                            isbuy = Enum.GetName(typeof(Isbuy), item.isbuy),
                            item.wx_user.city,
                            item.wx_user.country,
                            item.wx_user.province,
                        };
                        list.Add(one);
                    }
                    if (list.Any())
                    {
                        DataTable dt = ListToDataTable.List2DataTable <dynamic>(list);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            dt.Columns["id"].ColumnName                  = "id";
                            dt.Columns["name"].ColumnName                = "名称";
                            dt.Columns["nickname"].ColumnName            = "微信昵称";
                            dt.Columns["tel"].ColumnName                 = "电话号码";
                            dt.Columns["sex"].ColumnName                 = "性别";
                            dt.Columns["city"].ColumnName                = "城市";
                            dt.Columns["province"].ColumnName            = "省份";
                            dt.Columns["country"].ColumnName             = "国家";
                            dt.Columns["add_time"].ColumnName            = "加入时间";
                            dt.Columns["parent_user"].ColumnName         = "推荐人";
                            dt.Columns["total_pay"].ColumnName           = "总消费";
                            dt.Columns["state"].ColumnName               = "状态";
                            dt.Columns["total_product_count"].ColumnName = "产品数量";
                            dt.Columns["total_score"].ColumnName         = "总积分";
                            dt.Columns["usable_score"].ColumnName        = "可用积分";
                            dt.Columns["isbuy"].ColumnName               = "是否购买";
                        }
                        bool hh = OfficeHelper.ExportExcelWithAspose(dt, $"用户信息{DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒")}", "", true);
                    }
                }
            }
        }