public ActionResult Manager(WeChatQRCodeSearchDTO dto, int page)
        {
            dto.AppId     = (Guid)Session["APPID"];
            dto.PageIndex = page;
            WeChatQRCodeFacade facade = new WeChatQRCodeFacade();
            var result = facade.GetWechatQrCodeList(dto);

            if (result.isSuccess)
            {
                return(Json(new
                {
                    data = result.Data.List,
                    records = result.Data.Count,
                    page = dto.PageIndex
                }));
            }
            return(Json(result));
        }
        private ResultDTO <List <QrTypeDTO> > GetQrCodeTypeListExt(WeChatQRCodeSearchDTO search)
        {
            IEnumerable <WeChatQrCodeType> query = WeChatQrCodeType.ObjectSet().AsQueryable();

            //if (!search.IsShowCatering)
            //{
            //    query = WeChatQrCodeType.ObjectSet().Where(c => c.UseTye != 1);
            //}

            List <QrTypeDTO> resultData = query.Select(c => new QrTypeDTO {
                Type = c.Type, Description = c.Description
            }).ToList();

            return(new ResultDTO <List <QrTypeDTO> >
            {
                isSuccess = true,
                Message = "success",
                Data = resultData
            });
        }
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ActionResult ExportExcel(WeChatQRCodeSearchDTO dto)
        {
            dto.AppId     = (Guid)Session["APPID"];
            dto.PageIndex = 1;
            dto.PageSize  = int.MaxValue;
            WeChatQRCodeFacade facade = new WeChatQRCodeFacade();
            var qrCodes = facade.GetWechatQrCodeList(dto);
            var sbHtml  = new StringBuilder();

            sbHtml.Append("<table border='1' cellspacing='0' cellpadding='0'>");
            sbHtml.Append("<tr>");
            var lstTitle = new List <string> {
                "推广渠道", "微信公众号名称", "微信AppID", "微信AppSecret", "二维码链接", "绑定状态", "是否启用", "备注"
            };

            foreach (var item in lstTitle)
            {
                sbHtml.AppendFormat("<td style='font-size: 14px;text-align:center;background-color: #DCE0E2; font-weight:bold;' height='25'>{0}</td>", item);
            }
            sbHtml.Append("</tr>");
            foreach (var model in qrCodes.Data.List)
            {
                sbHtml.Append("<tr>");
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.QrTypeDesc);
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.WeChatPublicCode);
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.AppId);
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.AppId);
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'><a href='{0}'>{0}</a></td>", "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + model.WeChatTicket);
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.IsUse ? "已绑定" : "未绑定");
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.IsDel == 0 ? "是" : "否");
                sbHtml.AppendFormat("<td style='font-size: 12px;height:20px;'>{0}</td>", model.Description);
                sbHtml.Append("</tr>");
            }
            sbHtml.Append("</table>");
            return(File(System.Text.Encoding.UTF8.GetBytes(sbHtml.ToString()), "application/ms-excel", string.Format("带参数二维码{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss"))));
        }
        private ResultDTO <ListResult <WeChatQRCodeShowDTO> > GetWechatQrCodeListExt(WeChatQRCodeSearchDTO search)
        {
            var result = new ListResult <WeChatQRCodeShowDTO>();
            //var query = BE.WeChatQRCode.ObjectSet().Where(c => c.IsDel != 1 && c.AppId == search.AppId);
            var query = from code in WeChatQRCode.ObjectSet()
                        join type in WeChatQrCodeType.ObjectSet() on code.QRType.Value equals type.Type
                        where code.IsDel != 1 && code.AppId == search.AppId
                        select new
            {
                Id = code.Id,
                WeChatPublicCode = code.WeChatPublicCode,
                AppId            = code.AppId,
                QRNo             = code.QRNo,
                WeChatTicket     = code.WeChatTicket,
                StoreId          = code.StoreId,
                IsDel            = code.IsDel,
                IsUse            = code.IsUse,
                SpreadInfoId     = code.SpreadInfoId,
                Description      = code.Description,
                QRType           = code.QRType,
                SubTime          = code.SubTime,
                QRTypeDesc       = type.Description,
                QRTypeUseType    = type.UseTye,
                Name             = code.Name
            };

            if (search.QRType.HasValue)
            {
                query = query.Where(q => q.QRType.Value == search.QRType.Value);
            }
            //else if (!search.IsShowCatering)
            //{
            //    query = query.Where(c => c.QRTypeUseType != 1);
            //}
            if (!string.IsNullOrEmpty(search.WeChatPublicCode))
            {
                query = query.Where(q => q.WeChatPublicCode == search.WeChatPublicCode);
            }
            if (search.IsUse.HasValue)
            {
                query = query.Where(q => q.IsUse == search.IsUse.Value);
            }

            result.Count = query.Count();
            result.List  = query.OrderByDescending(q => q.SubTime).
                           Skip((search.PageIndex - 1) * search.PageSize).
                           Take(search.PageSize).
                           Select(q => new WeChatQRCodeShowDTO
            {
                Id = q.Id,
                WeChatPublicCode = q.WeChatPublicCode,
                AppId            = q.AppId,
                QRNo             = q.QRNo,
                WeChatTicket     = q.WeChatTicket,
                StoreId          = q.StoreId,
                IsDel            = q.IsDel,
                IsUse            = q.IsUse,
                SpreadInfoId     = q.SpreadInfoId,
                Description      = q.Description,
                QRType           = q.QRType.Value,
                SubTime          = q.SubTime,
                QrTypeDesc       = q.QRTypeDesc,
                Name             = q.Name
            }).
                           ToList();
            if (result.List.Any())
            {
                foreach (var weChatQrCodeShowDTO in result.List)
                {
                    if (string.IsNullOrEmpty(weChatQrCodeShowDTO.Name))
                    {
                        weChatQrCodeShowDTO.Name = weChatQrCodeShowDTO.QRNo.ToString(CultureInfo.InvariantCulture);
                    }
                }
            }
            return(new ResultDTO <ListResult <WeChatQRCodeShowDTO> >()
            {
                isSuccess = true, Data = result
            });
        }