private void DownLoadCoupon_TicketNumber(HttpContext pContext) { try { #region 获取信息 string couponTypeID = FormatParamValue(Request("couponTypeID")); //优惠券类型id string filename = FormatParamValue(Request("filename")); //导出的文件名 int intDownLoadNum = Request("downLoadNum") == null ? 0 : Convert.ToInt32(Request("downLoadNum")); var bllCouponType = new CouponTypeBLL(CurrentUserInfo); var couponType = bllCouponType.QueryByEntity(new CouponTypeEntity() { CustomerId = CurrentUserInfo.ClientID, CouponTypeID = new Guid(couponTypeID), IsDelete = 0 }, null).SingleOrDefault(); var couponBLL = new CouponBLL(CurrentUserInfo); var count = RedisOpenAPI.Instance.CCCoupon().GetCouponListLength(new CC_Coupon() { CustomerId = CurrentUserInfo.ClientID, CouponTypeId = couponTypeID, }); if (couponType.IsNotLimitQty == 0 && intDownLoadNum > count.Result) { throw new APIException("下载数量大于优惠券剩余量") { ErrorCode = 333 }; } //System.Data.DataTable list_CouponEntity = couponBLL.GetCouponIDBycouponType(couponTypeID).Tables[0]; var redisCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisCouponBLL(); System.Data.DataTable list_CouponEntity = redisCouponBLL.DownloadCoupon(new CC_Coupon() { CustomerId = CurrentUserInfo.ClientID, CouponTypeId = couponTypeID, }, CurrentUserInfo.ClientID, intDownLoadNum, couponType.IsNotLimitQty); //xu的redis //System.Data.DataTable list_CouponEntity = redisCouponBLL.DownloadCouponNew(CurrentUserInfo.ClientID, couponTypeID, intDownLoadNum); #endregion if (list_CouponEntity.Rows.Count == 0) { return; } if (filename == null || filename == "") { filename = "优惠券"; } string filesrc = @"~/Framework/Upload/" + DateTime.Now.ToString("yyyyMMdd") + "/"; if (!System.IO.Directory.Exists(pContext.Server.MapPath(filesrc))) { System.IO.Directory.CreateDirectory(pContext.Server.MapPath(filesrc)); } string MapUrl = pContext.Server.MapPath(filesrc + filename + ".xls"); Aspose.Cells.License lic = new Aspose.Cells.License(); lic.SetLicense("Aspose.Total.lic"); Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; Cells cells = sheet.Cells;//单元格 #region //为标题设置样式 Style styleTitle = workbook.Styles[workbook.Styles.Add()]; //新增样式 styleTitle.HorizontalAlignment = TextAlignmentType.Center; //文字居中 styleTitle.Font.Name = "宋体"; //文字字体 styleTitle.Font.Size = 18; //文字大小 styleTitle.Font.IsBold = true; //粗体 //样式2 Style style2 = workbook.Styles[workbook.Styles.Add()]; //新增样式 style2.HorizontalAlignment = TextAlignmentType.Center; //文字居中 style2.Font.Name = "宋体"; //文字字体 style2.Font.Size = 14; //文字大小 style2.Font.IsBold = true; //粗体 style2.IsTextWrapped = true; //单元格内容自动换行 style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //样式3 Style style3 = workbook.Styles[workbook.Styles.Add()]; //新增样式 style3.HorizontalAlignment = TextAlignmentType.Center; //文字居中 style3.Font.Name = "宋体"; //文字字体 style3.Font.Size = 12; //文字大小 style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; #endregion //生成行1 标题行 cells[0, 0].PutValue(string.Format("{0}券号", filename));//填写内容 cells[0, 0].SetStyle(styleTitle); cells.SetRowHeight(0, 30); cells.SetColumnWidth(0, 50); #region 生成数据行 for (int i = 0; i < list_CouponEntity.Rows.Count; i++) { cells[1 + i, 0].PutValue(list_CouponEntity.Rows[i]["CouponCode"]); cells[1 + i, 0].SetStyle(style3); cells.SetRowHeight(1 + i, 24); } #endregion workbook.Save(MapUrl); Utils.OutputExcel(pContext, MapUrl); //输出Excel文件 } catch (Exception ex) { throw (ex); } }
protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetCouponRP> pRequest) { var rd = new EmptyResponseData(); var para = pRequest.Parameters; var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; var couponTypeBLL = new CouponTypeBLL(loggingSessionInfo); var couponBLL = new CouponBLL(loggingSessionInfo); var couponTypeUnitMappingBLL = new CouponTypeUnitMappingBLL(loggingSessionInfo); CouponTypeItemMappingBLL bllCouponTypeItemMapping = new CouponTypeItemMappingBLL(loggingSessionInfo); CouponTypeItemMappingEntity entityCouponTypeItemMapping = null; var redisCouponBLL = new JIT.CPOS.BS.BLL.RedisOperationBLL.Coupon.RedisCouponBLL(); if (couponTypeBLL.ExistsCouponTypeName(para.CouponTypeName, loggingSessionInfo.ClientID) > 0) { throw new APIException(-1, "优惠券名称不可重复!"); } var pTran = couponTypeBLL.GetTran();//事务 using (pTran.Connection) { try { CouponTypeEntity couponTypeEntity = null; //保存券产品表 if (string.IsNullOrEmpty(para.CouponTypeID))//生成优惠券 { couponTypeEntity = new CouponTypeEntity(); couponTypeEntity.CouponTypeName = para.CouponTypeName; couponTypeEntity.CouponTypeDesc = para.CouponTypeDesc; couponTypeEntity.CouponCategory = para.CouponCategory; couponTypeEntity.ParValue = para.ParValue; couponTypeEntity.IsVoucher = 0; couponTypeEntity.UsableRange = para.UsableRange; if (para.BeginTime != DateTime.MinValue) { couponTypeEntity.BeginTime = para.BeginTime; } if (para.EndTime != DateTime.MinValue) { para.EndTime = para.EndTime.AddHours(23).AddMinutes(59).AddSeconds(59); couponTypeEntity.EndTime = para.EndTime; } couponTypeEntity.ServiceLife = para.ServiceLife; couponTypeEntity.ConditionValue = para.ConditionValue; couponTypeEntity.SuitableForStore = para.SuitableForStore; couponTypeEntity.CustomerId = loggingSessionInfo.ClientID; couponTypeEntity.IsNotLimitQty = para.IsNotLimitQty; if (para.IsNotLimitQty != null && para.IsNotLimitQty == 1) { couponTypeEntity.IssuedQty = 1000; } else { couponTypeEntity.IssuedQty = para.IssuedQty; } couponTypeEntity.IsRepeatable = 0; couponTypeEntity.IsMixable = 0; couponTypeEntity.ValidPeriod = 0; couponTypeEntity.CouponTypeID = couponTypeBLL.CreateReturnID(couponTypeEntity, pTran); redisCouponBLL.RedisSetSingleCoupon(new CC_Coupon() { CustomerId = couponTypeEntity.CustomerId, CouponTypeId = couponTypeEntity.CouponTypeID.ToString(), CouponTypeDesc = couponTypeEntity.CouponTypeDesc, CouponTypeName = couponTypeEntity.CouponTypeName, BeginTime = couponTypeEntity.BeginTime.ToString(), EndTime = couponTypeEntity.EndTime.ToString(), ServiceLife = couponTypeEntity.ServiceLife ?? 0, CouponLenth = couponTypeEntity.IssuedQty ?? 0, CouponCategory = couponTypeEntity.CouponCategory }); //保存适用门店 if (para.SuitableForStore == 2) { CouponTypeUnitMappingEntity mapping = null; foreach (var obj in para.ObjectIDList) { mapping = new CouponTypeUnitMappingEntity() { CouponTypeID = couponTypeEntity.CouponTypeID, ObjectID = obj.ObjectID, CustomerID = loggingSessionInfo.ClientID }; couponTypeUnitMappingBLL.Create(mapping, pTran); } } if (!string.IsNullOrEmpty(para.BindType) && para.BindTypeIdList != null) { foreach (var objId in para.BindTypeIdList) { entityCouponTypeItemMapping = new CouponTypeItemMappingEntity() { CouponTypeID = couponTypeEntity.CouponTypeID, BindType = para.BindType, ObjectId = objId.ObjectID }; bllCouponTypeItemMapping.Create(entityCouponTypeItemMapping); } } } else//追加优惠券 { couponTypeEntity = couponTypeBLL.GetByID(para.CouponTypeID); couponTypeEntity.IssuedQty += para.IssuedQty; couponTypeBLL.Update(couponTypeEntity); redisCouponBLL.RedisSetSingleCoupon(new CC_Coupon() { CustomerId = couponTypeEntity.CustomerId, CouponTypeId = couponTypeEntity.CouponTypeID.ToString(), CouponTypeDesc = couponTypeEntity.CouponTypeDesc, CouponTypeName = couponTypeEntity.CouponTypeName, BeginTime = couponTypeEntity.BeginTime.ToString(), EndTime = couponTypeEntity.EndTime.ToString(), ServiceLife = couponTypeEntity.ServiceLife ?? 0, CouponLenth = para.IssuedQty, CouponCategory = couponTypeEntity.CouponCategory }); } pTran.Commit();//提交事物 //批量生成券 //if (couponTypeEntity != null) //{ // Hashtable htCouponInfo = new Hashtable(); // htCouponInfo["CouponTypeID"] = couponTypeEntity.CouponTypeID; // htCouponInfo["CouponName"] = couponTypeEntity.CouponTypeName; // htCouponInfo["CouponDesc"] = couponTypeEntity.CouponTypeDesc; // if (couponTypeEntity.BeginTime != DateTime.MinValue) // htCouponInfo["BeginTime"] = couponTypeEntity.BeginTime; // else // htCouponInfo["BeginTime"] = null; // if (couponTypeEntity.EndTime != DateTime.MinValue) // htCouponInfo["EndTime"] = couponTypeEntity.EndTime; // else // htCouponInfo["EndTime"] = null; // htCouponInfo["IssuedQty"] = para.IssuedQty; // couponBLL.GenerateCoupon(htCouponInfo); //} } catch (Exception ex) { pTran.Rollback(); throw new APIException(ex.Message); } } return(rd); }