/// <summary> /// 注册赠送现金券 /// </summary> /// <param name="members"></param> protected void RegistSendVoucher(IList <Member> members) { IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(2); IList <VoucherItemInfo> list = new System.Collections.Generic.List <VoucherItemInfo>(); string claimCode = string.Empty; string password = string.Empty; if (voucherList.Count > 0) { foreach (Member member in members) { foreach (VoucherInfo voucher in voucherList) { VoucherItemInfo item = new VoucherItemInfo(); if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, member.UserId) > 0) { continue; } else { claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); claimCode = Sign(claimCode, "UTF-8").Substring(8, 16); password = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new VoucherItemInfo(voucher.VoucherId, claimCode, password, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity)); list.Add(item); } } } } if (list.Count > 0) { try { VoucherHelper.SendClaimCodes(list); } catch { } } }
private void OrderSendVoucher(IList <OrderInfo> orderList) { IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(1); IList <VoucherItemInfo> list = new System.Collections.Generic.List <VoucherItemInfo>(); string claimCode = string.Empty; string password = string.Empty; if (voucherList.Count > 0) { foreach (OrderInfo orderInfo in orderList) { foreach (VoucherInfo voucher in voucherList) { VoucherItemInfo item = new VoucherItemInfo(); ///不存在拆单 if (String.IsNullOrEmpty(orderInfo.SourceOrderId)) { if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, orderInfo.OrderId) > 0) { continue; } else { if (orderInfo.Amount >= Convert.ToDecimal(voucher.SendTypeItem)) { claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); claimCode = Sign(claimCode, "UTF-8").Substring(8, 16); password = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new VoucherItemInfo(orderInfo.OrderId, voucher.VoucherId, claimCode, password, new int?(orderInfo.UserId), orderInfo.Username, orderInfo.EmailAddress, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity)); list.Add(item); } } } //拆单 else { if (VoucherHelper.GetCountVoucherItem(voucher.VoucherId, orderInfo.SourceOrderId) > 0) { continue; } else { decimal sourceAmount = OrderHelper.GetOrderAmount(orderInfo.SourceOrderId); if (sourceAmount >= Convert.ToDecimal(voucher.SendTypeItem)) { claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); claimCode = Sign(claimCode, "UTF-8").Substring(8, 16); password = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new VoucherItemInfo(orderInfo.SourceOrderId, voucher.VoucherId, claimCode, password, new int?(orderInfo.UserId), orderInfo.Username, orderInfo.EmailAddress, System.DateTime.Now, DateTime.Now.AddDays(voucher.Validity)); list.Add(item); } } } } } } if (list.Count > 0) { try { VoucherHelper.SendClaimCodes(list); } catch { } } }
protected override void AttachChildControls() { this.vVoucherImage = (VVoucherImage)this.FindControl("vVoucherImage"); string nowKeyCode = ""; if (!string.IsNullOrEmpty(this.Page.Request.QueryString["k"])) { nowKeyCode = this.Page.Request.QueryString["k"]; } else { if (this.vVoucherImage != null) { vVoucherImage.Visible = false; } } string k = "8c0f9f7b58864063bd83cffeb9624915"; int voucherItemsCount = 0; if (nowKeyCode != k) { if (this.vVoucherImage != null) { vVoucherImage.Visible = false; } } else { Member member = HiContext.Current.User as Member; voucherItemsCount = VoucherHelper.GetVoucherItemsCount(member.UserId, nowKeyCode); if (voucherItemsCount == 0) { //通过发送方式获取优惠券列表(3为自助领劵) IList <VoucherInfo> voucherList = VoucherHelper.GetVoucherBySendType(3); //1.看是否登录,就是判断有没有userId,获取openId;2.往Ecshop_VoucherItems插入记录 VoucherItemInfo item = new VoucherItemInfo(); IList <VoucherItemInfo> list = new List <VoucherItemInfo>(); string claimCode = string.Empty; string password = string.Empty; DateTime deadline; foreach (VoucherInfo current in voucherList) { deadline = DateTime.Today.AddDays(current.Validity); claimCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); claimCode = Sign(claimCode, "UTF-8").Substring(8, 16); password = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15); item = new VoucherItemInfo(current.VoucherId, claimCode, password, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, deadline, nowKeyCode); list.Add(item); } VoucherHelper.BulkAddVoucherItems(list); } voucherItemsCount = VoucherHelper.GetVoucherItemsCount(member.UserId, nowKeyCode); } if (voucherItemsCount > 0) { //显示页面 if (this.vVoucherImage != null) { //可见 vVoucherImage.Visible = true; } } else { //否则隐藏 if (this.vVoucherImage != null) { vVoucherImage.Visible = false; } } //string.Format("此次发送操作已成功,现金券发送数量:{0}", list.Count); PageTitle.AddSiteNameTitle("发送优惠券"); }