Exemple #1
0
        /// <summary>
        /// 导出会员数据
        /// </summary>
        /// <param name="keywords">会员名</param>
        /// <param name="weChatNick">微信昵称</param>
        /// <param name="mobile">手机号码</param>
        /// <param name="gradeId">会员等级</param>
        /// <param name="status">会员状态</param>
        /// <param name="platform">会员来源</param>
        /// <param name="labels">会员标签</param>
        /// <param name="registTimeStart">注册时间开始时间</param>
        /// <param name="registTimeEnd">注册时间结束时间</param>
        /// <param name="isFocusWeiXin">是否关注微信</param>
        /// <param name="isSeller">是否为入驻商家</param>
        /// <param name="logintimeStart">登录时间开始</param>
        /// <param name="logintimeEnd">登录时间结束</param>
        /// <returns></returns>
        public ActionResult ExportToExcel(string keywords        = "", string weChatNick      = null, string mobile = null,
                                          long?gradeId           = null, bool?status          = null, int?platform  = null, long?labels = null,
                                          string registTimeStart = null, string registTimeEnd = null, bool?isFocusWeiXin = null, bool?isSeller = null,
                                          string logintimeStart  = null, string logintimeEnd  = null)
        {
            #region 获取查询结果
            DateTime?rtstart = null;
            DateTime?rtend   = null;
            DateTime?ltstart = null;
            DateTime?ltend   = null;
            if (!string.IsNullOrWhiteSpace(registTimeStart))
            {
                rtstart = DateTime.Parse(registTimeStart);
            }
            if (!string.IsNullOrWhiteSpace(registTimeEnd))
            {
                rtend = DateTime.Parse(registTimeEnd);
            }
            if (!string.IsNullOrWhiteSpace(logintimeStart))
            {
                ltstart = DateTime.Parse(logintimeStart);
            }
            if (!string.IsNullOrWhiteSpace(logintimeEnd))
            {
                ltend = DateTime.Parse(logintimeEnd);
            }
            var query = new MemberQuery()
            {
                PageNo          = 1,
                PageSize        = int.MaxValue,
                keyWords        = keywords,
                weChatNick      = weChatNick,
                Mobile          = mobile,
                GradeId         = gradeId,
                Status          = status,
                Platform        = platform,
                Labels          = labels.HasValue ? new long[] { labels.Value } : null,
                RegistTimeStart = rtstart,
                RegistTimeEnd   = rtend,
                IsFocusWeiXin   = isFocusWeiXin,
                IsSeller        = isSeller,
                LoginTimeStart  = ltstart,
                LoginTimeEnd    = ltend,
            };
            if (gradeId.HasValue)
            {
                var expenditureRange = MemberApplication.GetMemberGradeRange(gradeId.Value);
                query.MinIntegral = expenditureRange.MinIntegral;
                query.MaxIntegral = expenditureRange.MaxIntegral;
            }
            var result = MemberApplication.GetMemberList(query);
            #endregion
            return(ExcelView("ExportMemberinfo", "会员信息", result.Models.ToList()));

            #region 构建Excel文档
            //  ViewData.Model = result.Models;
            // string viewHtml = RenderPartialViewToString(this, "ExportMemberinfo");
            // return File(System.Text.Encoding.UTF8.GetBytes(viewHtml), "application/ms-excel", string.Format("会员信息_{0}.xls", DateTime.Now.ToString("yyyy-MM-dd")));
            #endregion
        }
        public JsonResult List(int page, string keywords, int rows, long?labelid, bool?status,
                               bool?isSeller, bool?isFocus, DateTime?regtimeStart, DateTime?regtimeEnd,
                               long?gradeId,
                               string mobile,
                               string weChatNick
                               )
        {
            var result = MemberApplication.GetMemberList(new MemberQuery()
            {
                keyWords        = keywords,
                Status          = status,
                PageNo          = page,
                PageSize        = rows,
                IsSeller        = isSeller,
                IsFocusWeiXin   = isFocus,
                Mobile          = mobile,
                GradeId         = gradeId,
                weChatNick      = weChatNick,
                RegistTimeStart = regtimeStart,
                RegistTimeEnd   = regtimeEnd,
                LabelId         = labelid.HasValue ? new long[] { labelid.Value } : null
            });

            var model = new DataGridModel <DTO.Members>()
            {
                rows = result.Models, total = result.Total
            };

            return(Json(model));
        }
Exemple #3
0
        public JsonResult List(MemberQuery query)
        {
            if (query.Sort == "CreateDateStr")
            {
                query.Sort = "CreateDate";
            }

            var result = MemberApplication.GetMemberList(query);
            var model  = new DataGridModel <DTO.Members>()
            {
                rows  = result.Models,
                total = result.Total
            };

            return(Json(model));
        }
        /// <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);
            }
        }