public string AddCoupon(int couponType, int bindType, int bindValue, string bindName, int ruleType, int ruleValue, int couponValue, string couponDesc, int maxLimitNum, DateTime endDate, string remark, string prefix) { ManageUserModel uM = (ManageUserModel)Session["logUser"]; T_Order_CouponInfo model = new T_Order_CouponInfo(); model.couponType = couponType; model.bindType = bindType; model.bindValue = bindValue; model.bindName = bindName; model.ruleType = ruleType; model.ruleValue = ruleValue; model.couponValue = couponValue; model.couponStatus = 0; model.couponDesc = couponDesc; model.maxLimitNum = maxLimitNum; model.createDate = DateTime.Now; model.endDate = endDate.AddHours(23).AddMinutes(59).AddSeconds(59); model.remark = remark; model.operatorId = uM.UserID; model.operarorIp = Request.UserHostAddress; model.operatorTime = DateTime.Now; model.prefixAgent = (prefix == null ? 0 : Convert.ToInt32(prefix)); model.id = T_Order_CouponInfoBLL.Add(model); if (model.id > 0) { return("0"); } else { return("-1"); } }
/// <summary> /// 批量生成优惠码 /// </summary> /// <param name="groupId"></param> /// <param name="createNum"></param> /// <returns></returns> public bool CreateCouponGroup(int groupId, int iCreateNum = 1) { int iCount = iCreateNum; if (iCreateNum > 1000) { return(false); } //获得需要生成概要信息 OrderCouponInfo couponInfo = T_Order_CouponInfoBLL.GetModel(groupId); //获得当前总生成条数 int couponListCount = couponInfo.produceNum; //新生成优惠码 List <string> couponCreateList = new List <string>(); //判断是否超出限制数量 if ((iCreateNum + couponListCount) > couponInfo.maxLimitNum) { iCount = couponInfo.maxLimitNum - couponListCount; } string couponCode = ""; string couponPre = ""; //前缀命名 if (couponInfo.couponType == 1) { couponPre = "DJ"; } else if (couponInfo.couponType == 2) { couponPre = "GN"; } while (iCount > 0) { //循环生成优惠券Code couponCode = couponPre + CreateNumber(); //Utility.Logger.Info(couponCode); if (!CheckCouponCode(couponCode)) { if (!(T_Order_CouponListBLL.CreateCouponGroup(couponInfo.id, couponCode, couponInfo.couponValue, couponInfo.endDate) > 0)) { return(false); } UpdateHtCouponList(0, couponCode); iCount--; if (iCount > 0) { Thread.Sleep(100); } } } return(true); }
/// <summary> /// 优惠券列表 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public static Dictionary <string, object> GetList(int pageIndex, int pageSize, string couponDesc = "", DateTime?statTime = null, DateTime?endTime = null, string operatorName = "", string expired = "y") { Dictionary <string, object> list = new Dictionary <string, object>(); List <DapperWhere> sqlWhere = new List <DapperWhere>(); if (couponDesc != "") { sqlWhere.Add(new DapperWhere("couponDesc", couponDesc, "couponDesc like '%'+ @couponDesc +'%'")); } if (statTime != null) { sqlWhere.Add(new DapperWhere("statTime", statTime, " createDate>@statTime ")); } if (endTime != null) { sqlWhere.Add(new DapperWhere("endTime", endTime, "createDate<@endTime")); } if (expired == "n") { sqlWhere.Add(new DapperWhere("endDate", DateTime.Now, "endDate>@endDate")); } if (operatorName != "") { if (operatorName == "0") { sqlWhere.Add(new DapperWhere("operatorId", 0)); } else if (operatorName == "1") { sqlWhere.Add(new DapperWhere("operatorId", 0, " operatorId > @operatorId")); } else { sqlWhere.Add(new DapperWhere("operatorName", operatorName) { Where = " operatorId in (select id from Sys_I200.dbo.Sys_Manage_User where name like '%'+ @operatorName +'%') " }); } } if (pageSize < 1) { pageSize = 20; } int rowCount = 0; if (pageIndex == 1) { rowCount = BLL.Base.T_Order_CouponInfoBaseBLL.GetCount(sqlWhere); } int maxPage = 0; if (rowCount > 0) { maxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(rowCount) / pageSize)); } list["rowCount"] = rowCount; list["maxPage"] = maxPage; list["pageIndex"] = pageIndex; list["listData"] = T_Order_CouponInfoBLL.GetList(pageIndex, pageSize, sqlWhere, " id desc"); return(list); }
/// <summary> /// 优惠券内容 /// </summary> /// <param name="id"></param> /// <returns></returns> public static OrderCouponInfo GetModel(int id) { return(T_Order_CouponInfoBLL.GetModel(id)); }