public void SendCardCouponsByCurrUserInfo(UserInfo currUserInfo, string cardId) { try { BLLWeixin bllWeixin = new BLLWeixin(); BLLWebsiteDomainInfo bllDomain = new BLLWebsiteDomainInfo(); CardCoupons cardCoupon = Get <CardCoupons>(string.Format(" WebsiteOwner='{0}' AND CardId={1} ", currUserInfo.WebsiteOwner, int.Parse(cardId))); MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = GetGUID(BLLJIMP.TransacType.CommAdd); model.CardCouponType = cardCoupon.CardCouponType; model.CardId = cardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = currUserInfo.UserID; model.WebSiteOwner = currUserInfo.WebsiteOwner; if (Add(model)) { string title = "您收到一张优惠券"; string content = string.Format("{0}", cardCoupon.Name); string redicturl = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/mycoupons#/mycoupons", bllDomain.GetWebsiteDoMain(currUserInfo.WebsiteOwner)); bllWeixin.SendTemplateMessageNotifyComm(currUserInfo, title, content, redicturl); } } catch (Exception) { } }
/// <summary> /// 增加冻结积分记录: /// 真正返积分是确认收货7天退货期过后 /// 返积分按冻结记录去返,以解决:如果用户7天后升级,防止下单的时候冻结的数量跟真正分的数量不一样 /// </summary> /// <param name="orderInfo"></param> /// <param name="tran"></param> /// <returns></returns> public bool AddLockScoreByOrder(WXMallOrderInfo orderInfo) { ToLog("into AddLockScoreByOrder"); BLLWeixin bllWeiXin = new BLLWeixin(); bool result = false; //获取是否已经存有的冻结积分 var lockModel = GetLockScoreByOrder(orderInfo.OrderID); if (lockModel != null) { return(true); } ToLog("AddLockScoreByOrder 计算获得积分"); //计算获得积分 var addScore = CalcOrderRebateScore(orderInfo); ToLog("AddLockScoreByOrder addScore:" + addScore); //如获得积分则存入冻结表 if (addScore > 0) { ToLog("AddLockScoreByOrder 存入冻结表"); ScoreLockInfo scoreLockInfo = new ScoreLockInfo() { ForeignkeyId = orderInfo.OrderID, LockStatus = 0, LockTime = DateTime.Now, LockType = 1, Score = addScore, UserId = orderInfo.OrderUserID, WebsiteOwner = orderInfo.WebsiteOwner }; if (Add(scoreLockInfo)) { ToLog("AddLockScoreByOrder 存入冻结表成功"); result = true; //发送通知; string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/lockscores#/lockscores", HttpContext.Current.Request.Url.Host); bllWeiXin.SendTemplateMessageNotifyComm(GetCurrentUserInfo(), "您有一笔即将到账积分", string.Format("下单获得 {0} 积分,点击查看", addScore), url); } else { ToLog("AddLockScoreByOrder 存入冻结表失败"); } } return(result); }
/// <summary> /// 关注自动送券 /// </summary> public void SubscribeGive(UserInfo userInfo) { try { BLLDistribution bllDis = new BLLDistribution(); BLLWeixin bllWeixin = new BLLWeixin(); BLLWebsiteDomainInfo bllDomain = new BLLWebsiteDomainInfo(); List <CardCoupons> cardCouponList = GetList <CardCoupons>(string.Format("WebsiteOwner='{0}' And IsSubscribeGive='1'", userInfo.WebsiteOwner)); foreach (var cardCoupon in cardCouponList) { if (GetCount <MyCardCoupons>(string.Format("CardId='{0}' And UserId='{1}'", cardCoupon.CardId, userInfo.UserID)) > 0) { continue;//已经发过了 } if (!string.IsNullOrEmpty(cardCoupon.BindChannelUserId)) { if (bllDis.GetUserChannel(userInfo) != cardCoupon.BindChannelUserId) { continue; } } if (cardCoupon.MaxCount > 0) { int sendCount = GetCount <MyCardCoupons>(string.Format(" CardID={0}", cardCoupon.CardId)); if (sendCount >= cardCoupon.MaxCount) { continue; } } //给用户发满送券 MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = string.Format("No.{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), GetGUID(BLLJIMP.TransacType.CommAdd)); model.CardCouponType = cardCoupon.CardCouponType; model.CardId = cardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = userInfo.UserID; model.WebSiteOwner = userInfo.WebsiteOwner; if (Add(model)) { string title = "您收到一张优惠券"; string content = string.Format("{0}", cardCoupon.Name); string redicturl = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/mycoupons#/mycoupons", bllDomain.GetWebsiteDoMain(userInfo.WebsiteOwner)); bllWeixin.SendTemplateMessageNotifyComm(userInfo, title, content, redicturl); } } } catch (Exception) { } }
public void ProcessRequest(HttpContext context) { string ids = context.Request["ids"]; List <UserInfo> list = bllUser.GetList <UserInfo>(string.Format(" AutoID In ({0}) ", ids)); list = list.Where(p => p.MemberApplyStatus < 9 || p.AccessLevel < 1).ToList(); if (list.Count > 0) { BLLTransaction tran = new BLLTransaction(); foreach (var item in list) { if (item.AccessLevel < 1) { item.AccessLevel = 1; } item.MemberStartTime = DateTime.Now; item.MemberApplyStatus = 9; if (!bllUser.Update(item, tran)) { tran.Rollback(); apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; bllUser.ContextResponse(context, apiResp); return; } } tran.Commit(); foreach (var user in list) { bllWeixin.SendTemplateMessageNotifyComm(user, "审核通过", "您已经通过会员审核"); } } apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "提交完成"; bllUser.ContextResponse(context, apiResp); }
/// <summary> /// 新分销会员通知 /// </summary> /// <param name="messageInfo"></param> /// <param name="ramark"></param> /// <param name="errMsg"></param> public void DistNewMemberNotice(MessageInfo messageInfo, out string ramark, out string errMsg) { Console.WriteLine("正在处理新分销会员通知"); BLLUserDistributionMember bllUserDistributionMember = new BLLUserDistributionMember(); BLLUser bllUser = new BLLUser(); BLLWeixin bllWeixin = new BLLWeixin(); ramark = ""; errMsg = ""; var msgBody = JsonConvert.DeserializeObject <Model.MQ.DistNewMemberNoticeInfo>(messageInfo.Msg); Console.WriteLine("转换完msgBody"); //获取分销员和会员 var distUser = bllUser.GetUserInfoByAutoID(int.Parse(msgBody.DistributionOwnerAutoId), messageInfo.WebsiteOwner); var member = bllUser.GetUserInfoByAutoID(int.Parse(msgBody.MemberAutoId), messageInfo.WebsiteOwner); //记录到会员表 bllUserDistributionMember.SetUserDistributionOwnerInMember(new List <string>() { member.UserID }, distUser.UserID, member.WebsiteOwner); //获取当前是第几位会员 var rowCount = bllUserDistributionMember.GetMemberRowCount(member.UserID, distUser.UserID, member.WebsiteOwner); Console.WriteLine("排名:" + rowCount); //获取会员昵称 if (string.IsNullOrWhiteSpace(member.WXNickname) && !string.IsNullOrWhiteSpace(member.WXOpenId)) { Console.WriteLine("无微信昵称,开始获取微信昵称"); var accessToken = bllWeixin.GetAccessToken(messageInfo.WebsiteOwner); if (!string.IsNullOrEmpty(accessToken)) { Console.WriteLine("获取到accessToken,开始获取会员信息"); var wxUserInfo = bllWeixin.GetWeixinUserInfo(accessToken, member.WXOpenId); Console.WriteLine("处理完获取会员信息"); if (wxUserInfo != null) { Console.WriteLine("获取到会员信息"); member.WXHeadimgurl = wxUserInfo.headimgurl; member.WXNickname = string.IsNullOrWhiteSpace(wxUserInfo.nickname) ? "" : wxUserInfo.nickname.Replace("'", ""); member.WXProvince = wxUserInfo.province; member.WXCity = wxUserInfo.city; bllUser.Update(new UserInfo(), string.Format(" WXHeadimgurl='{0}',WXNickname='{1}',WXProvince='{2}',WXCity='{3}' ", member.WXHeadimgurl, member.WXNickname, member.WXProvince, member.WXCity ), string.Format(" UserId = '{0}' AND WebsiteOwner = '{1}' ", member.UserID, member.WebsiteOwner)); } else { Console.WriteLine("获取不到会员信息"); } } else { Console.WriteLine("获取不到accessToken"); } } var notice = string.Format("恭喜 {0} 成为您的第{1}号会员", member.WXNickname, rowCount); Console.WriteLine("开始发通知"); //发送通知 bllWeixin.SendTemplateMessageNotifyComm(distUser, string.Format("新会员通知"), notice); Console.WriteLine(notice); }
/// <summary> /// 是否通过报名 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ActivityDataByIsPass(HttpContext context) { string activityId = context.Request["ActivityID"]; string uId = context.Request["UID"]; string remarks = context.Request["Remarks"]; int status = int.Parse(context.Request["Status"]); string[] ids = uId.Split(','); ActivityDataInfo model = new ActivityDataInfo(); foreach (var item in ids) { model = bllActivity.GetActivityDataInfo(activityId, int.Parse(item)); model.Status = status; model.Remarks = remarks; UserInfo commendUserInfo = bllUser.GetUserInfoByAutoID(int.Parse(model.DistributionOffLineRecommendCode)); if (commendUserInfo == null) { continue; } #region 审核通过 if (status == 1001)//审核通过 { UserInfo userInfo = bllUser.GetUserInfo(model.UserId); userInfo.TrueName = model.Name; if (string.IsNullOrEmpty(model.SpreadUserID))//不是微转发的才分配上级用户 { userInfo.DistributionOffLinePreUserId = commendUserInfo.UserID; } else//微转发直接成为分销员 { commendUserInfo = bllUser.GetUserInfo(model.SpreadUserID); userInfo.DistributionOffLinePreUserId = commendUserInfo.UserID; } if (bllUser.Update(userInfo)) { //申请通过向申请人和上级提醒通过申请 //申请人 //bllWeixin.SendTemplateMessageNotifyComm(userInfo.WXOpenId, "财富伙伴申请结果", "恭喜您已经通过审核!", string.Format("http://{0}/App/Distribution/m/index.aspx", context.Request.UserHostName)); if (string.IsNullOrEmpty(model.SpreadUserID))//不是微转发的才分配上级用户 { //上级 bllWeixin.SendTemplateMessageNotifyComm(commendUserInfo, string.Format("恭喜您的会员“{0}”申请财富会员成功", model.Name), "请提醒他关注公众号并帮助他熟悉系统操作吧。", string.Format("http://{0}/App/Distribution/m/index.aspx", context.Request.Url.Host)); } } //if (!string.IsNullOrEmpty(model.SpreadUserID))//不是微转发的才分配上级用户 //{ // model.Status = 4003; //} } #endregion #region 审核不通过 else if (status == 4001) { UserInfo userInfo = bllUser.GetUserInfo(model.UserId); //判断下,当他有下线的时候就不可以取消审核状态 if (bllDistributionOffLine.IsHaveLowerLevel(model.UserId)) { continue; } else { userInfo.DistributionOffLinePreUserId = ""; bllUser.Update(userInfo); } //申请通过向申请人和上级提醒通过申请 //申请人 //bllWeixin.SendTemplateMessageNotifyComm(userInfo.WXOpenId, "财富伙伴申请结果", string.Format("审核未通过!\\{0}", remarks)); //上级 bllWeixin.SendTemplateMessageNotifyComm(commendUserInfo, string.Format("很抱歉您的会员“{0}”申请财富会员失败", model.Name), string.Format(" 原因:{0}\\n您可提醒他满足要求后重新申请。", remarks), string.Format("http://{0}/App/Distribution/m/index.aspx", context.Request.Url.Host)); if (!string.IsNullOrEmpty(model.SpreadUserID)) { //微转发审核不通过,删除此记录 bllActivity.Delete(model, string.Format("ActivityID={0} And UID={1}", model.ActivityID, model.UID)); } } #endregion if (!bllActivity.Update(model)) { continue; } } resp.Status = 1; return(Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 赠送满送券 /// </summary> public void Give(decimal totalAmount, UserInfo userInfo) { try { BLLWeixin bllWeixin = new BLLWeixin(); BLLWebsiteDomainInfo bllDomain = new BLLWebsiteDomainInfo(); List <CardCoupons> cardCouponList = GetList <CardCoupons>(string.Format("WebsiteOwner='{0}' And CardCouponType='MallCardCoupon_BuckleGive'", userInfo.WebsiteOwner)).OrderBy(p => p.Ex5).ToList(); foreach (var cardCoupon in cardCouponList) { if (totalAmount >= decimal.Parse(cardCoupon.Ex5)) { if (cardCoupon.MaxCount > 0) { int sendCount = GetCount <MyCardCoupons>(string.Format(" CardID={0}", cardCoupon.CardId)); if (sendCount >= cardCoupon.MaxCount) { break; } } //给用户发满送券 MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = string.Format("No.{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), GetGUID(BLLJIMP.TransacType.CommAdd)); model.CardCouponType = cardCoupon.CardCouponType; model.CardId = cardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = userInfo.UserID; model.WebSiteOwner = userInfo.WebsiteOwner; if (Add(model)) { string title = "您收到一张优惠券"; string content = string.Format("{0}", cardCoupon.Name); string redicturl = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/mycoupons#/mycoupons", bllDomain.GetWebsiteDoMain(userInfo.WebsiteOwner)); bllWeixin.SendTemplateMessageNotifyComm(userInfo, title, content, redicturl); } //给用户发满送券 //break; } } #region New List <CardCoupons> cardCouponListNew = GetList <CardCoupons>(string.Format("WebsiteOwner='{0}' And FullGive!=''", userInfo.WebsiteOwner)); foreach (var cardCoupon in cardCouponListNew) { if (totalAmount >= decimal.Parse(cardCoupon.FullGive)) { if (cardCoupon.MaxCount > 0) { int sendCount = GetCount <MyCardCoupons>(string.Format(" CardID={0}", cardCoupon.CardId)); if (sendCount >= cardCoupon.MaxCount) { break; } } //给用户发券 MyCardCoupons model = new MyCardCoupons(); model.CardCouponNumber = string.Format("No.{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), GetGUID(BLLJIMP.TransacType.CommAdd)); model.CardCouponType = cardCoupon.CardCouponType; model.CardId = cardCoupon.CardId; model.InsertDate = DateTime.Now; model.UserId = userInfo.UserID; model.WebSiteOwner = userInfo.WebsiteOwner; if (Add(model)) { string title = "您收到一张优惠券"; string content = string.Format("{0}", cardCoupon.Name); string redicturl = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/mycoupons#/mycoupons", bllDomain.GetWebsiteDoMain(userInfo.WebsiteOwner)); bllWeixin.SendTemplateMessageNotifyComm(userInfo, title, content, redicturl); } else { } //给用户发券 //break; } else { } } #endregion } catch (Exception ex) { } }
public void ProcessRequest(HttpContext context) { BLLJIMP.BLLDistributionOffLine bll = new BLLJIMP.BLLDistributionOffLine(); BllPay bllPay = new BllPay(); BLLWeixin bllWeixin = new BLLWeixin(); string ids = context.Request["ids"]; string moduleName = "积分"; if (!string.IsNullOrWhiteSpace(context.Request["module_name"])) { moduleName = context.Request["module_name"]; } int total = 0; if (string.IsNullOrWhiteSpace(ids)) { apiResp.msg = "请选中申请"; apiResp.code = (int)APIErrCode.IsNotFound; bll.ContextResponse(context, apiResp); return; } var sourceList = bll.QueryWithdrawCashList(1, int.MaxValue, null, out total, "0", context.Request["type"], ids); if (sourceList.Count == 0) { apiResp.msg = "选中的申请无待审核申请"; apiResp.code = (int)APIErrCode.IsNotFound; bll.ContextResponse(context, apiResp); return; } string websiteOwner = bll.WebsiteOwner; string ip = System.Web.HttpContext.Current.Request.UserHostAddress; int snum = 0; foreach (var p in sourceList) { UserInfo pu = bllUser.GetUserInfo(p.UserId, websiteOwner); if (pu == null || string.IsNullOrWhiteSpace(pu.WXOpenId)) { apiResp.status = snum > 0; apiResp.msg = string.Format("编号:{0},审核出错,用户信息有误", p.AutoID); apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } //通知 BLLJIMP.Model.SystemNotice notice = new BLLJIMP.Model.SystemNotice(); notice.Ncontent = string.Format("申请提现通过审核,编号:{0}", p.AutoID); notice.UserId = currentUserInfo.UserID; notice.Receivers = pu.UserID; notice.SendType = 2; notice.Title = "申请提现通过审核"; notice.NoticeType = 1; notice.WebsiteOwner = websiteOwner; notice.InsertTime = DateTime.Now; BLLTransaction tran = new BLLTransaction(); bool result = bll.Update(p, string.Format("Status=2,LastUpdateDate=getdate()"), string.Format("AutoID={0}", p.AutoID), tran) > 0; if (!result) { tran.Rollback(); apiResp.status = snum > 0; apiResp.msg = string.Format("编号:{0},审核出错", p.AutoID); apiResp.code = snum > 0 ? (int)APIErrCode.IsSuccess : (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } string msg = ""; if (bllPay.WeixinTransfers(p.AutoID.ToString(), p.RealAmount, pu.WXOpenId, ip, out msg, "提现")) { //发送微信模板消息 bllWeixin.SendTemplateMessageNotifyComm(pu, "您提现的佣金已经到账", string.Format("提现金额:{0}元。请查看微信钱包", p.RealAmount)); //发送微信模板消息 //发送通知 notice.SerialNum = bllUser.GetGUID(TransacType.SendSystemNotice); bll.Add(notice); //发送通知 } else//打款失败 { tran.Rollback(); apiResp.status = snum > 0; apiResp.msg = string.Format("编号:{0},微信打款出错 : {1}", p.AutoID, msg); apiResp.code = snum > 0 ? (int)APIErrCode.IsSuccess : (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } tran.Commit(); snum++; } if (snum == 0) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "审核失败"; } else { apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = string.Format("审核完成"); } bll.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { BLLTransaction tran = new BLLTransaction(); try { string id = context.Request["id"]; //id string useAmountStr = context.Request["useAmount"]; decimal useAmount = 0; //使用金额 string remark = context.Request["remark"]; //备注 if (!decimal.TryParse(useAmountStr, out useAmount)) { apiResp.msg = "使用金额不正确"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } if (useAmount <= 0) { apiResp.msg = "使用金额需要大于0"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } if (!bllUser.IsWeixinKefu(CurrentUserInfo)) { apiResp.msg = "拒绝操作"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } StoredValueCardRecord record = bll.GetByKey <StoredValueCardRecord>("AutoId", id, websiteOwner: bll.WebsiteOwner); if (record == null) { apiResp.msg = "储值卡未找到"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } if (record.ValidTo.HasValue && record.ValidTo.Value < DateTime.Now) { apiResp.msg = "储值卡已过期"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } decimal maxUseAmount = (record.Amount - bll.GetUseRecordList(record.AutoId, record.UserId).Sum(p => p.UseAmount)); if (useAmount > maxUseAmount) { apiResp.msg = string.Format("储值卡最多可以使用{0}元", maxUseAmount); apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } record.UseDate = DateTime.Now; record.Status = 9; if (!bll.Update(record, tran)) { tran.Rollback(); apiResp.msg = "操作失败"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } StoredValueCardUseRecord storeValueCardUseRecord = new StoredValueCardUseRecord(); storeValueCardUseRecord.UseAmount = useAmount; storeValueCardUseRecord.CardId = record.CardId; storeValueCardUseRecord.Remark = string.Format("{0}使用{1}元", remark, useAmount); storeValueCardUseRecord.UseDate = DateTime.Now; storeValueCardUseRecord.UserId = record.UserId; storeValueCardUseRecord.UseUserId = record.UserId; if (!string.IsNullOrEmpty(record.ToUserId)) { storeValueCardUseRecord.UseUserId = record.ToUserId; } storeValueCardUseRecord.WebsiteOwner = bll.WebsiteOwner; storeValueCardUseRecord.MyCardId = record.AutoId; if (!bll.Add(storeValueCardUseRecord, tran)) { tran.Rollback(); apiResp.msg = "操作失败"; apiResp.code = (int)APIErrCode.OperateFail; bll.ContextResponse(context, apiResp); return; } tran.Commit(); apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = string.Format("储值卡已成功使用{0}元", useAmount); UserInfo userInfo = bllUser.GetUserInfo(storeValueCardUseRecord.UseUserId, storeValueCardUseRecord.WebsiteOwner); bllWeixin.SendTemplateMessageNotifyComm(userInfo, "储值卡消费通知", storeValueCardUseRecord.Remark, string.Format("http://{0}/App/SvCard/Wap/UseRecord.aspx?id={1}", context.Request.Url.Host, id)); } catch (Exception ex) { tran.Rollback(); apiResp.msg = ex.ToString(); } bll.ContextResponse(context, apiResp); }
/// <summary> /// 储值卡发放 /// </summary> /// <param name="userIds"></param> /// <param name="cardId"></param> /// <param name="websiteOwner"></param> /// <param name="msg"></param> /// <param name="authority">域名加端口</param> /// <returns></returns> public bool SendRecord(string card_id, string type, string user_ids, string tags, string websiteOwner, string createUserId, out string msg, string authority) { msg = ""; if (type == "2" && string.IsNullOrWhiteSpace(tags)) { msg = "请选择接受储值卡的用户标签组"; return(false); } else if (type == "1" && string.IsNullOrWhiteSpace(user_ids)) { msg = "请选择接受储值卡的用户"; return(false); } StoredValueCard card = GetByKey <StoredValueCard>("AutoId", card_id, websiteOwner: websiteOwner); if (card == null) { msg = "储值卡不存在"; return(false); } if (card.Status != 0) { msg = "储值卡已停用"; return(false); } DateTime curDate = DateTime.Now; string dateString = curDate.ToString("yyyyMMdd"); if (card.ValidType == 0 && card.ValidTo.HasValue && card.ValidTo.Value < curDate) { msg = string.Format("储值卡已过有效期"); return(false); } List <string> userIdList = new List <string>(); if (type == "2") { StringBuilder sbWhere = new StringBuilder(); sbWhere.AppendFormat(" WebSiteOwner='{0}' And ( 1=2 ", websiteOwner); foreach (var tag in tags.Split(',')) { sbWhere.AppendFormat(" Or ',' + TagName + ',' Like '%,{0},%' ", tag); } sbWhere.AppendFormat(" )"); List <UserInfo> userList = GetColList <UserInfo>(int.MaxValue, 1, sbWhere.ToString(), "AutoID,UserID"); if (userList.Count > 0) { userIdList = userList.Select(p => p.UserID).Distinct().ToList(); } } else if (type == "1") { userIdList = user_ids.Split(',').Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList(); } if (userIdList.Count == 0) { msg = "接受卡券的用户未找到"; return(false); } int cCount = userIdList.Count - (card.MaxCount - card.SendCount); if (cCount > 0) { msg = string.Format("储值卡可发放数量不足,少{0}张", cCount); return(false); } int startNum = 0; StoredValueCardRecord oldRecord = Get <StoredValueCardRecord>(string.Format("{0}{1}", GetRecordWhereString(card.AutoId.ToString(), websiteOwner, null, null), " Order By AutoId Desc")); if (oldRecord != null) { startNum = Convert.ToInt32(oldRecord.CardNumber.Substring(16)); } StoredValueCardRecord baseRecord = new StoredValueCardRecord(); baseRecord.CardId = card.AutoId; baseRecord.WebsiteOwner = websiteOwner; baseRecord.CreateUserId = createUserId; baseRecord.CreateDate = curDate; if (card.ValidType == 0) { baseRecord.ValidTo = card.ValidTo; } else if (card.ValidType == 1 && card.ValidDay.HasValue) { baseRecord.ValidTo = curDate.AddDays(card.ValidDay.Value); } baseRecord.Amount = card.Amount; Random ran = new Random(); string cardString = card_id.PadLeft(3, '0'); if (card_id.Length > 3) { cardString = cardString.Substring(card_id.Length - 3); } List <StoredValueCardRecord> sendRecordList = new List <StoredValueCardRecord>(); List <UserInfo> usList = new List <UserInfo>(); for (int i = 0; i < userIdList.Count; i++) { UserInfo cru = usList.FirstOrDefault(p => p.UserID == userIdList[i]); if (cru == null) { cru = GetColByKey <UserInfo>("UserID", userIdList[i], "AutoID,UserID,WXOpenId,WebsiteOwner", websiteOwner: websiteOwner); if (cru == null) { continue; } usList.Add(cru); } else { usList.Add(cru); } startNum++; StoredValueCardRecord rRecord = (StoredValueCardRecord)baseRecord.Clone(); rRecord.UserId = userIdList[i]; string numString = startNum.ToString(); string ranString = ran.Next(99).ToString(); rRecord.CardNumber = "No." + dateString + cardString + ranString.PadLeft(2, '0') + numString.PadLeft(3, '0'); sendRecordList.Add(rRecord); } if (sendRecordList.Count == 0) { msg = "接收用户未找到"; return(false); } BLLWeixin bllWeixin = new BLLWeixin(); int suCount = 0; string redicturl = string.Format("http://{0}/App/SVCard/Wap/List.aspx", authority); for (int i = 0; i < sendRecordList.Count; i++) { if (Add(sendRecordList[i])) { suCount++; string content = string.Format("{0}\\n金额:{1}", card.Name, card.Amount); if (sendRecordList[i].ValidTo.HasValue) { content += string.Format("\\n有效期:{0}", sendRecordList[i].ValidTo.Value.ToString("yyyy-MM-dd HH:mm")); } bllWeixin.SendTemplateMessageNotifyComm(usList[i], "您收到一张储值卡", content, redicturl); } } if (Update(card, string.Format("SendCount=SendCount+{0}", suCount), string.Format("AutoId={0} And WebsiteOwner='{1}'", card.AutoId, websiteOwner)) <= 0) { if (suCount < sendRecordList.Count) { msg = "发送成功" + suCount + "张,但更新发放数量出错"; } else { msg = "发送成功,但更新发放数量出错"; } return(true); } if (suCount < sendRecordList.Count) { msg = "发送成功" + suCount + "张"; } else { msg = "发放储值卡成功"; } return(true); }