Exemple #1
0
        /// <summary>
        /// 导出会员数据
        /// </summary>
        /// <param name="keywords">会员名</param>
        /// <param name="weChatNick">微信昵称</param>
        /// <param name="mobile">手机号码</param>
        /// <param name="gradeId">会员等级</param>
        /// <param name="status">会员状态</param>
        /// <param name="platform">会员来源</param>
        /// <param name="labels">会员标签</param>
        /// <param name="registTimeStart">注册时间开始时间</param>
        /// <param name="registTimeEnd">注册时间结束时间</param>
        /// <param name="isFocusWeiXin">是否关注微信</param>
        /// <param name="isSeller">是否为入驻商家</param>
        /// <param name="logintimeStart">登录时间开始</param>
        /// <param name="logintimeEnd">登录时间结束</param>
        /// <returns></returns>
        public ActionResult ExportToExcel(string keywords        = "", string weChatNick      = null, string mobile = null,
                                          long?gradeId           = null, bool?status          = null, int?platform  = null, long?labels = null,
                                          string registTimeStart = null, string registTimeEnd = null, bool?isFocusWeiXin = null, bool?isSeller = null,
                                          string logintimeStart  = null, string logintimeEnd  = null)
        {
            #region 获取查询结果
            DateTime?rtstart = null;
            DateTime?rtend   = null;
            DateTime?ltstart = null;
            DateTime?ltend   = null;
            if (!string.IsNullOrWhiteSpace(registTimeStart))
            {
                rtstart = DateTime.Parse(registTimeStart);
            }
            if (!string.IsNullOrWhiteSpace(registTimeEnd))
            {
                rtend = DateTime.Parse(registTimeEnd);
            }
            if (!string.IsNullOrWhiteSpace(logintimeStart))
            {
                ltstart = DateTime.Parse(logintimeStart);
            }
            if (!string.IsNullOrWhiteSpace(logintimeEnd))
            {
                ltend = DateTime.Parse(logintimeEnd);
            }
            var query = new MemberQuery()
            {
                PageNo          = 1,
                PageSize        = int.MaxValue,
                keyWords        = keywords,
                weChatNick      = weChatNick,
                Mobile          = mobile,
                GradeId         = gradeId,
                Status          = status,
                Platform        = platform,
                Labels          = labels.HasValue ? new long[] { labels.Value } : null,
                RegistTimeStart = rtstart,
                RegistTimeEnd   = rtend,
                IsFocusWeiXin   = isFocusWeiXin,
                IsSeller        = isSeller,
                LoginTimeStart  = ltstart,
                LoginTimeEnd    = ltend,
            };
            if (gradeId.HasValue)
            {
                var expenditureRange = MemberApplication.GetMemberGradeRange(gradeId.Value);
                query.MinIntegral = expenditureRange.MinIntegral;
                query.MaxIntegral = expenditureRange.MaxIntegral;
            }
            var result = MemberApplication.GetMemberList(query);
            #endregion
            return(ExcelView("ExportMemberinfo", "会员信息", result.Models.ToList()));

            #region 构建Excel文档
            //  ViewData.Model = result.Models;
            // string viewHtml = RenderPartialViewToString(this, "ExportMemberinfo");
            // return File(System.Text.Encoding.UTF8.GetBytes(viewHtml), "application/ms-excel", string.Format("会员信息_{0}.xls", DateTime.Now.ToString("yyyy-MM-dd")));
            #endregion
        }