/// <summary> /// 发送优惠券成功时发送消息 /// </summary> /// <param name="userId"></param> /// <param name="info"></param> public void SendMessageOnCouponSuccess(long userId, MessageCouponInfo info) { var message = PluginsManagement.GetPlugins <IMessagePlugin>().ToList(); foreach (var msg in message) { if (msg.Biz.GetStatus(MessageTypeEnum.SendCouponSuccess) == StatusEnum.Open) { string destination = GetDestination(userId, msg.PluginInfo.PluginId, MemberContactsInfo.UserTypes.General); if (!msg.Biz.CheckDestination(destination)) { throw new HimallException(msg.Biz.ShortName + "错误"); } var content = msg.Biz.SendMessageOnCouponSuccess(destination, info); if (msg.Biz.EnableLog) { Context.MessageLog.Add(new MessageLog() { SendTime = DateTime.Now, ShopId = 0, MessageContent = content, TypeId = "短信" }); Context.SaveChanges(); } } } }
public string SendMessageOnCouponSuccess(string destination, MessageCouponInfo info) { var config = SMSCore.GetMessageContentConfig(); var text = config.SendCouponSuccess.Replace("#userName#", info.UserName).Replace("#Money#", info.Money.ToString("F2")).Replace("#Url#", info.Url).Replace("#siteName#", info.SiteName); SendMessage(destination, text); return(text); }
/// <summary> /// 发送优惠券成功 /// </summary> /// <param name="userId"></param> /// <param name="info"></param> public static void SendMessageOnCouponSuccess(long userId, MessageCouponInfo info) { _iMessageService.SendMessageOnCouponSuccess(userId, info); }
/// <summary> /// 发送优惠券,根据搜索条件 /// </summary> /// <param name="query"></param> /// <param name="couponIds"></param> public static void SendCoupon(MemberPowerQuery query, IEnumerable <long> couponIds, string labelinfos = "") { var siteName = SiteSettingApplication.GetSiteSettings().SiteName; decimal price = 0; string result = ""; //会员领取优惠券记录ID // List<long> memberCouponIds = new List<long>(); // dictResult = new Dictionary<string, int>(); query.PageSize = 500; query.PageNo = 1; var pageMode = MemberApplication.GetPurchasingPowerMember(query); if (pageMode.Total > 0) { var mUserMember = new List <MemberPurchasingPower>(); while (pageMode.Models.Count() > 0)//循环批量获取用户信息 { // string[] dests = pageMode.Models.Select(e => e.).ToArray(); foreach (var item in pageMode.Models) { mUserMember.Add(item); } query.PageNo += 1; pageMode = MemberApplication.GetPurchasingPowerMember(query); } var model = _iCouponService.GetCouponInfo(couponIds.ToArray());//获取所选优惠券集合 //查询优惠券领取状况 var mCouponRecord = _iCouponService.GetCouponRecordTotal(couponIds.ToArray()); List <SendmessagerecordCouponInfo> lsendInfo = new List <SendmessagerecordCouponInfo>(); //验证优惠券是否充足 foreach (var item in model) { price += item.Price; lsendInfo.Add(new SendmessagerecordCouponInfo() { CouponId = item.Id }); if ((item.Num - item.Himall_CouponRecord.Count()) < mUserMember.Count) { result = item.CouponName + "优惠券的数量不足,无法赠送"; break; } } if (result == "") { //发送优惠券 bool alTotal = false; for (int i = 0; i < mUserMember.Count; i++) { bool suTotal = false;//会员发送优惠券成功数 foreach (var item in model) { //判断会员领取限制,是否可领取此优惠券 bool isf = true; if (item.PerMax > 0) { int total = mCouponRecord.Where(p => p.UserId == mUserMember[i].Id && p.CouponId == item.Id).ToList().Count; if (item.PerMax <= total) { isf = false; } } if (isf) { suTotal = true; alTotal = true; CouponRecordInfo info = new CouponRecordInfo(); info.UserId = mUserMember[i].Id; info.UserName = mUserMember[i].UserName; info.ShopId = item.ShopId; info.CouponId = item.Id; _iCouponService.AddCouponRecord(info); } } if (suTotal) { MessageCouponInfo info = new MessageCouponInfo(); info.Money = price; info.SiteName = siteName; info.UserName = mUserMember[i].UserName; MessageApplication.SendMessageOnCouponSuccess(mUserMember[i].Id, info); } } Log.Debug("sendCoupon:" + alTotal); //查看成功发送会员数 if (alTotal) { //记录发送历史 var sendRecord = new Himall.Model.SendMessageRecordInfo { ContentType = WXMsgType.wxcard, MessageType = MsgType.Coupon, SendContent = "", SendState = 1, SendTime = DateTime.Now, ToUserLabel = labelinfos == null ? "" : labelinfos, Himall_SendmessagerecordCoupon = lsendInfo }; WXMsgTemplateApplication.AddSendRecord(sendRecord); } else { result = "此标签下无符合领取此优惠券的会员"; } } } else { result = "该标签下无任何会员"; } if (!string.IsNullOrWhiteSpace(result)) { throw new HimallException(result); } }
/// <summary> /// 发送优惠券,根据会员ID /// </summary> /// <param name="userIds">发送对象</param> /// <param name="couponIds">优惠券名称</param> public static void SendCouponByUserIds(IEnumerable <long> userIds, IEnumerable <long> couponIds) { var model = _iCouponService.GetCouponInfo(couponIds.ToArray()); var siteName = SiteSettingApplication.GetSiteSettings().SiteName; var mCouponRecord = _iCouponService.GetCouponRecordTotal(couponIds.ToArray()); var mUserMember = MemberApplication.GetMembers(userIds); decimal price = 0; string result = ""; List <SendmessagerecordCouponInfo> lsendInfo = new List <SendmessagerecordCouponInfo>(); //验证优惠券是否充足 foreach (var item in model) { price += item.Price; lsendInfo.Add(new SendmessagerecordCouponInfo() { CouponId = item.Id }); if ((item.Num - item.Himall_CouponRecord.Count()) < mUserMember.Count) { result = item.CouponName + "优惠券的数量不足,无法赠送"; break; } } if (result == "") { //发送优惠券 bool alTotal = false; for (int i = 0; i < mUserMember.Count; i++) { bool suTotal = false;//会员发送优惠券成功数 foreach (var item in model) { //判断会员领取限制,是否可领取此优惠券 bool isf = true; if (item.PerMax > 0) { int total = mCouponRecord.Where(p => p.UserId == mUserMember[i].Id && p.CouponId == item.Id).ToList().Count; if (item.PerMax <= total) { isf = false; } } if (isf) { suTotal = true; alTotal = true; CouponRecordInfo info = new CouponRecordInfo(); info.UserId = mUserMember[i].Id; info.UserName = mUserMember[i].UserName; info.ShopId = item.ShopId; info.CouponId = item.Id; _iCouponService.AddCouponRecord(info); } } if (suTotal) { MessageCouponInfo info = new MessageCouponInfo(); info.Money = price; info.SiteName = siteName; info.UserName = mUserMember[i].UserName; MessageApplication.SendMessageOnCouponSuccess(mUserMember[i].Id, info); } } Log.Debug("sendCoupon:" + alTotal); //查看成功发送会员数 if (alTotal) { //记录发送历史 var sendRecord = new Himall.Model.SendMessageRecordInfo { ContentType = WXMsgType.wxcard, MessageType = MsgType.Coupon, SendContent = "", SendState = 1, SendTime = DateTime.Now, ToUserLabel = "", Himall_SendmessagerecordCoupon = lsendInfo }; WXMsgTemplateApplication.AddSendRecord(sendRecord); } else { result = "无符合领取此优惠券的会员"; } } else { result = "该标签下无任何会员"; } if (!string.IsNullOrWhiteSpace(result)) { throw new HimallException(result); } }
/// <summary> /// 发送优惠券 /// </summary> /// <param name="labelids">发送标签</param> /// <param name="labelinfos">标签名称</param> /// <param name="couponIds">优惠券名称</param> /// <returns>-1:优惠券不足;-2:请选择发送的优惠券;-3:标签中用户数为0</returns> public static string SendCouponMsg(string labelids, string labelinfos, string couponIds, string url) { var messageEmali = PluginsManagement.GetPlugin <IMessagePlugin>("Himall.Plugin.Message.Email"); var messageSMS = PluginsManagement.GetPlugin <IMessagePlugin>("Himall.Plugin.Message.SMS"); string result = ""; if (!couponIds.TrimEnd(',').Equals("")) { //取出标签对应的会员信息 long[] lids = string.IsNullOrWhiteSpace(labelids) ? null : labelids.Split(',').Select(s => long.Parse(s)).ToArray(); int pageNo = 1, pageSize = 100; var pageMode = MemberApplication.GetMembers(new MemberQuery { LabelId = lids, PageNo = pageNo, PageSize = pageSize }); if (pageMode.Total > 0) { List <UserMemberInfo> mUserMember = new List <UserMemberInfo>(); while (pageMode.Models.Count() > 0)//循环批量获取用户信息 { string[] dests = pageMode.Models.Select(e => e.Email).ToArray(); foreach (var item in pageMode.Models) { mUserMember.Add(item); } pageNo += 1; pageMode = MemberApplication.GetMembers(new MemberQuery { LabelId = lids, PageNo = pageNo, PageSize = pageSize }); } string[] arrStr = couponIds.TrimEnd(',').Split(','); long[] arrcouponIds = arrStr.Select(a => long.Parse(a)).ToArray(); var model = _iCouponService.GetCouponInfo(arrcouponIds);//获取所选优惠券集合 //查询优惠券领取状况 var mCouponRecord = _iCouponService.GetCouponRecordTotal(arrcouponIds); decimal price = 0; List <SendmessagerecordCouponInfo> lsendInfo = new List <SendmessagerecordCouponInfo>(); List <SendmessagerecordCouponSNInfo> lsendSN = new List <SendmessagerecordCouponSNInfo>(); //验证优惠券是否充足 foreach (var item in model) { price += item.Price; lsendInfo.Add(new SendmessagerecordCouponInfo() { CouponId = item.Id }); if ((item.Num - item.Himall_CouponRecord.Count()) < mUserMember.Count) { result = item.CouponName + "优惠券的数量不足,无法赠送"; break; } } var siteName = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings().SiteName; if (result == "") { //发送优惠券 bool alTotal = false; for (int i = 0; i < mUserMember.Count; i++) { bool suTotal = false;//会员发送优惠券成功数 foreach (var item in model) { //判断会员领取限制,是否可领取此优惠券 bool isf = true; if (item.PerMax > 0) { int total = mCouponRecord.Where(p => p.UserId == mUserMember[i].Id && p.CouponId == item.Id).ToList().Count; if (item.PerMax <= total) { isf = false; } } if (isf) { suTotal = true; alTotal = true; CouponRecordInfo info = new CouponRecordInfo(); info.UserId = mUserMember[i].Id; info.UserName = mUserMember[i].UserName; info.ShopId = item.ShopId; info.CouponId = item.Id; var couponRecord = _iCouponService.AddCouponRecord(info); lsendSN.Add(new SendmessagerecordCouponSNInfo() { CouponSN = couponRecord.CounponSN }); } } if (suTotal) { MessageCouponInfo info = new MessageCouponInfo(); info.Money = price; info.SiteName = siteName; info.UserName = mUserMember[i].UserName; MessageApplication.SendMessageOnCouponSuccess(mUserMember[i].Id, info); } } Log.Debug("sendCoupon:" + alTotal); //查看成功发送会员数 if (alTotal) { //记录发送历史 var sendRecord = new Himall.Model.SendMessageRecordInfo { ContentType = WXMsgType.wxcard, MessageType = MsgType.Coupon, SendContent = "", SendState = 1, SendTime = DateTime.Now, ToUserLabel = labelinfos == null ? "" : labelinfos, Himall_SendmessagerecordCoupon = lsendInfo }; var record = WXMsgTemplateApplication.AddSendRecordItem(sendRecord); foreach (var item in lsendSN) { item.MessageId = record.Id; } _iCouponService.AddSendmessagerecordCouponSN(lsendSN); } else { result = "此标签下无符合领取此优惠券的会员"; } } } else { result = "该标签下无任何会员"; } } else { result = "请选择发送的优惠券"; } return(result); }