Ejemplo n.º 1
0
        public JsonResult MemberPowerList(MemberPowerQuery query)
        {
            var result = MemberApplication.GetPurchasingPowerMember(query);

            var models = result.Models.Select(item =>
                                              new
            {
                Id                  = item.Id,
                UserName            = item.UserName,
                CellPhone           = item.CellPhone,
                GradeName           = item.GradeName,
                NetAmount           = item.NetAmount,
                OrderNumber         = item.OrderNumber,
                LastConsumptionTime = item.LastConsumptionTime.HasValue ? item.LastConsumptionTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
                CategoryNames       = item.CategoryNames,
            }
                                              );

            var model = new { rows = models, total = result.Total, ids = string.Join(",", models.Select(p => p.Id)) };

            return(Json(model, true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送优惠券,根据搜索条件
        /// </summary>
        /// <param name="query"></param>
        /// <param name="couponIds"></param>
        public static void SendCoupon(MemberPowerQuery query, IEnumerable <long> couponIds, MemberQuery memberQuery = null, string labelinfos = "")
        {
            var     siteName = SiteSettingApplication.SiteSettings.SiteName;
            decimal price    = 0;
            string  result   = "";
            //会员领取优惠券记录ID
            //   List<long> memberCouponIds = new List<long>();
            // dictResult = new Dictionary<string, int>();

            var isMember        = memberQuery != null;//是否为会员管理发送
            var mUserMember     = new List <MemberPurchasingPower>();
            var mUserMemberList = new List <Members>();

            if (isMember)
            {
                memberQuery.PageSize = 500;
                memberQuery.PageNo   = 1;
                var pageMode = MemberApplication.GetMemberList(memberQuery);
                if (pageMode.Total > 0)
                {
                    while (pageMode.Models.Count() > 0)//循环批量获取用户信息
                    {
                        //   string[] dests = pageMode.Models.Select(e => e.).ToArray();
                        foreach (var item in pageMode.Models)
                        {
                            mUserMemberList.Add(item);
                        }
                        memberQuery.PageNo += 1;
                        pageMode            = MemberApplication.GetMemberList(memberQuery);
                    }
                }
            }
            else
            {
                query.PageSize = 500;
                query.PageNo   = 1;
                var pageMode = MemberApplication.GetPurchasingPowerMember(query);
                if (pageMode.Total > 0)
                {
                    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 isTrue = isMember ? mUserMemberList.Any() : mUserMember.Any();

            if (isTrue)
            {
                var model = Service.GetCouponInfo(couponIds.ToArray());//获取所选优惠券集合

                //查询优惠券领取状况
                var mCouponRecord = Service.GetCouponRecordTotal(couponIds.ToArray());

                List <SendmessagerecordCouponInfo> lsendInfo = new List <SendmessagerecordCouponInfo>();
                var records = Service.GetRecordCountByCoupon(model.Select(p => p.Id).ToList());
                //验证优惠券是否充足
                foreach (var item in model)
                {
                    price += item.Price;
                    lsendInfo.Add(new SendmessagerecordCouponInfo()
                    {
                        CouponId = item.Id
                    });
                    var record = records.ContainsKey(item.Id) ? records[item.Id] : 0;
                    var count  = isMember ? mUserMemberList.Count : mUserMember.Count;
                    if (item.Num - record < count)
                    {
                        result = item.CouponName + "优惠券的数量不足,无法赠送";
                        break;
                    }
                }
                if (result == "")
                {
                    //发送优惠券
                    bool alTotal = false;
                    var  count   = isMember ? mUserMemberList.Count : mUserMember.Count;
                    for (int i = 0; i < count; i++)
                    {
                        bool suTotal = false;//会员发送优惠券成功数
                        foreach (var item in model)
                        {
                            //判断会员领取限制,是否可领取此优惠券
                            bool isf = true;
                            if (item.PerMax > 0)
                            {
                                int total = mCouponRecord.Where(p => p.UserId == (isMember ? mUserMemberList[i].Id : 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   = isMember ? mUserMemberList[i].Id : mUserMember[i].Id;
                                info.UserName = isMember ? mUserMemberList[i].UserName : mUserMember[i].UserName;
                                info.ShopId   = item.ShopId;
                                info.CouponId = item.Id;
                                Service.AddCouponRecord(info);
                            }
                        }

                        if (suTotal)
                        {
                            MessageCouponInfo info = new MessageCouponInfo();
                            info.Money    = price;
                            info.SiteName = siteName;
                            info.UserName = isMember ? mUserMemberList[i].UserName : mUserMember[i].UserName;
                            MessageApplication.SendMessageOnCouponSuccess((isMember ? mUserMemberList[i].Id : mUserMember[i].Id), info);
                        }
                    }

                    Log.Debug("sendCoupon:" + alTotal);
                    //查看成功发送会员数
                    if (alTotal)
                    {
                        //记录发送历史
                        var sendRecord = new SendMessageRecordInfo
                        {
                            ContentType = WXMsgType.wxcard,
                            MessageType = MsgType.Coupon,
                            SendContent = "",
                            SendState   = 1,
                            SendTime    = DateTime.Now,
                            ToUserLabel = labelinfos ?? "",
                        };
                        WXMsgTemplateApplication.AddSendRecord(sendRecord, lsendInfo);
                    }
                    else
                    {
                        result = "此标签下无符合领取此优惠券的会员";
                    }
                }
            }
            else
            {
                result = "该标签下无任何会员";
            }

            if (!string.IsNullOrWhiteSpace(result))
            {
                throw new MallException(result);
            }
        }