Пример #1
0
        /// <summary>
        /// 批量删除消息发送策略
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Result <int> DeleteStrategyByIds(List <long> ids)
        {
            Result <int> result = new Result <int>();

            try
            {
                var models = DataOperateMsg <Msg_MessageStrategy> .Get().GetList(i => ids.Contains(i.Id)).ToList();

                var rows = DataOperateMsg <Msg_MessageStrategy> .Get().DeleteRange(models);

                result.Data = rows;
                result.Flag = EResultFlag.Success;

                #region 写日志
                WriteLog(AdminModule.MessageStrategy.GetText(), SystemRight.Delete.GetText(), "批量删除消息发送策略:" + rows);
                #endregion
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "DeleteStrategyByIds");
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 验证码校验
        /// 如果是邮件链接,步骤/接收人/邮箱无须传入
        /// 如果是验证码,则接收人和邮箱二者必须传入一个
        /// </summary>
        /// <param name="code"></param>
        /// <param name="receiveId"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        private Result <Msg_EmailValidate> ValidateEmailCode(string code, MessageStep step, long receiveId = 0, string email = "")
        {
            Result <Msg_EmailValidate> result = new Result <Msg_EmailValidate>();

            try
            {
                string strStep = step.ToString();
                //链接里的验证码校验
                if (receiveId == 0 && string.IsNullOrEmpty(email))
                {
                    //解密校验
                    string         sourceData  = DesTool.DesDecrypt(code);
                    IList <string> decryptData = sourceData.SplitString("#");
                    strStep = decryptData[0];
                    email   = decryptData[1];
                    code    = decryptData[2];
                }
                var model = DataOperateMsg <Msg_EmailValidate> .Get().Single(i => (i.ReceiveId == receiveId || i.ReceiveEmail == email) && i.Code == code && i.ValidateType == strStep);

                if (model == null)
                {
                    throw new Exception("验证码错误");
                }
                else
                {
                    if (model.State == ValCodeState.Used.ToString())
                    {
                        throw new Exception("验证码已经使用过");
                    }
                    if (model.ExpiredTime < DateTime.Now)
                    {
                        throw new Exception("验证码已过期");
                    }
                    //更新验证码
                    model.State = ValCodeState.Used.ToString();
                    DataOperateMsg <Msg_EmailValidate> .Get().Update(model);

                    result.Data = model;
                    result.Flag = EResultFlag.Success;
                }
            }
            catch (Exception ex)
            {
                result.Data      = null;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "ValidateEmailCode");
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 获取未读站内信
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="companyId"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public Result <List <Msg_Message> > GetMessageNoReadList(long userId, long companyId, int top)
        {
            Result <List <Msg_Message> > result = new Result <List <Msg_Message> >();

            try
            {
                var list = DataOperateMsg <Msg_Message> .Get().GetList(i => i.ReceiveId == userId && i.ReceiveCompanyId == companyId && i.State == false).Take(top).ToList();

                result.Data = list;
                result.Flag = EResultFlag.Success;
            }
            catch (Exception ex)
            {
                result.Data      = null;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "GetMessageNoReadList");
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 获取消息发送策略详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Result <Msg_MessageStrategy> GetStrategyModel(long id)
        {
            Result <Msg_MessageStrategy> result = new Result <Msg_MessageStrategy>();

            try
            {
                var model = DataOperateMsg <Msg_MessageStrategy> .Get().GetModel(id);

                result.Data = model;
                result.Flag = EResultFlag.Success;
            }
            catch (Exception ex)
            {
                result.Data      = null;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "GetStrategyModel");
            }
            return(result);
        }
Пример #5
0
        ///<summary>
        ///修改:短信接口设置
        ///</summary>
        public Result <int> UpdateSMSSetting(Msg_SMSSetting model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_SMSSetting> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.SMSPlatform.GetText(), SystemRight.Add.GetText(), "修改短信接口设置: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "UpdateSMSSetting");
            }
            return(result);
        }
Пример #6
0
        ///<summary>
        ///修改:短信记录
        ///</summary>
        public Result <int> UpdateSMS(Msg_SMS model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_SMS> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(MessageType.SMS.GetText(), SystemRight.Add.GetText(), "修改短信记录: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "UpdateSMS");
            }
            return(result);
        }
Пример #7
0
        ///<summary>
        ///添加:短信模板
        ///</summary>
        public Result <int> AddSMSTemplete(Msg_SMSTemplete model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_SMSTemplete> .Get().Add(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.SMSTemplete.GetText(), SystemRight.Add.GetText(), "新增短信模板: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddSMSTemplete");
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        /// 修改消息发送策略
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> UpdateStrategy(Msg_MessageStrategy model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_MessageStrategy> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.MessageStrategy.GetText(), SystemRight.Add.GetText(), "修改消息发送策略:" + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "UpdateStrategy");
            }
            return(result);
        }
Пример #9
0
        /// <summary>
        /// 添加消息环节
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> AddSection(Msg_MessageSection model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_MessageSection> .Get().Add(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.MessageSection.GetText(), SystemRight.Add.GetText(), "新增消息环节:" + model.Id + ":" + model.Name);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddSection");
            }
            return(result);
        }
Пример #10
0
        /// <summary>
        /// 修改站内消息模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> UpdateMessageTemplete(Msg_MessageTemplete model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_MessageTemplete> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.MessageTemplete.GetText(), SystemRight.Add.GetText(), "修改站内消息模板:" + model.Id + ":" + model.Name);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "UpdateMessageTemplete");
            }
            return(result);
        }
Пример #11
0
        ///<summary>
        ///添加:邮件接口设置
        ///</summary>
        public Result <int> AddEmailSetting(Msg_EmailSetting model)
        {
            Result <int> result = new Result <int>();

            try
            {
                var rows = DataOperateMsg <Msg_EmailSetting> .Get().Add(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.EmailSetting.GetText(), SystemRight.Add.GetText(), "新增邮件接口设置: " + model.Id);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddEmailSetting");
            }
            return(result);
        }
Пример #12
0
        ///<summary>
        ///删除:邮件发送记录
        ///</summary>
        public Result <int> DeleteEmailByIds(List <long> ids)
        {
            Result <int> result = new Result <int>();

            try
            {
                var models = DataOperateMsg <Msg_Email> .Get().GetList(i => ids.Contains(i.Id)).ToList();

                var rows = DataOperateMsg <Msg_Email> .Get().DeleteRange(models);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(MessageType.Email.GetText(), SystemRight.Add.GetText(), "批量删除邮件发送记录: " + rows);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "DeleteEmailByIds");
            }
            return(result);
        }
Пример #13
0
        /// <summary>
        /// 验证码校验,接收人和电话二者需要传入一个
        /// </summary>
        /// <param name="code"></param>
        /// <param name="receiveId"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public Result <Msg_SMSValidate> ValidateSMSCode(string code, MessageStep step, string phone, long receiveId = -1)
        {
            Result <Msg_SMSValidate> result = new Result <Msg_SMSValidate>();

            try
            {
                string strStep = step.ToString();
                var    model   = DataOperateMsg <Msg_SMSValidate> .Get().Single(i => (i.ReceiveId == receiveId || i.ReceivePhone == phone) && i.Code == code && i.ValidateType == strStep);

                if (model == null)
                {
                    throw new Exception("验证码错误");
                }
                else
                {
                    if (model.State == ValCodeState.Used.ToString())
                    {
                        throw new Exception("验证码已经使用过");
                    }
                    if (model.ExpiredTime < DateTime.Now)
                    {
                        throw new Exception("验证码已过期");
                    }
                    //更新验证码
                    model.State = ValCodeState.Used.ToString();
                    DataOperateMsg <Msg_SMSValidate> .Get().Update(model);

                    result.Data = model;
                    result.Flag = EResultFlag.Success;
                }
            }
            catch (Exception ex)
            {
                result.Data      = null;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "ValidateSMSCode");
            }
            return(result);
        }
Пример #14
0
        ///<summary>
        ///删除:历史短信
        ///</summary>
        public Result <int> DeleteSMSHistoryByIds(List <long> ids)
        {
            Result <int> result = new Result <int>();

            try
            {
                var models = DataOperateMsg <Msg_SMSHistory> .Get().GetList(i => ids.Contains(i.Id)).ToList();

                var rows = DataOperateMsg <Msg_SMSHistory> .Get().DeleteRange(models);

                result.Data = rows;
                result.Flag = EResultFlag.Success;
                WriteLog(AdminModule.SMSHistory.GetText(), SystemRight.Add.GetText(), "批量删除历史短信: " + rows);
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "DeleteSMSHistoryByIds");
            }
            return(result);
        }
Пример #15
0
        /// <summary>
        /// 审核消息发送策略
        /// </summary>
        /// <param name="strategyId">消息策略Id</param>
        /// <param name="type">1代表启用/禁用,2代表确认/未确认</param>
        /// <returns></returns>
        public Result <int> AuditStrategy(long strategyId, int type)
        {
            Result <int> result = new Result <int>();

            try
            {
                var model = DataOperateMsg <Msg_MessageStrategy> .Get().GetModel(strategyId);

                if (type == 1)
                {
                    model.IsEnable = !model.IsEnable;
                }
                else if (type == 2)
                {
                    model.IsConfirm = !model.IsConfirm;
                }
                var rows = DataOperateMsg <Msg_MessageStrategy> .Get().Update(model);

                result.Data = rows;
                result.Flag = EResultFlag.Success;

                if (type == 1)
                {
                    WriteStateLog(model, (!model.IsEnable).ToString(), (model.IsEnable).ToString());
                }
                else if (type == 2)
                {
                    WriteStateLog(model, (!model.IsConfirm).ToString(), (model.IsConfirm).ToString());
                }
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AuditStrategy");
            }
            return(result);
        }
Пример #16
0
        /// <summary>
        /// 读取站内信
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Result <Msg_Message> ReadMessage(long id)
        {
            Result <Msg_Message> result = new Result <Msg_Message>();

            try
            {
                var model = DataOperateMsg <Msg_Message> .Get().GetModel(id);

                model.State    = true;
                model.ReadTime = DateTime.Now;
                DataOperateMsg <Msg_Message> .Get().Update(model);

                result.Data = model;
                result.Flag = EResultFlag.Success;
            }
            catch (Exception ex)
            {
                result.Data      = null;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "ReadMessage");
            }
            return(result);
        }
Пример #17
0
        /// <summary>
        /// 短信验证码
        /// </summary>
        /// <param name="receiveId"></param>
        /// <param name="step"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public Result <int> AddSMSValCode(string phone, MessageStep step, Dictionary <string, string> parameters)
        {
            //生成验证码
            string code = ConstString.CreateRandomNum(ConstString.RANDOMNUMCOUNT);

            parameters.Add("Code", code);

            Result <int> result = new Result <int>();

            try
            {
                //查找模板
                var templete = DataOperateMsg <Msg_SMSTemplete> .Get().Single(i => i.Step == step.ToString() && i.IsConfirm && i.IsEnable);

                if (templete != null)
                {
                    Msg_SMS model = new Msg_SMS();
                    string  con   = templete.TemplateCon;
                    if (parameters != null && parameters.Any())
                    {
                        //替换内容参数
                        foreach (var item in parameters)
                        {
                            con = con.Replace("{" + item.Key + "}", item.Value);
                        }
                    }
                    var receive = DataOperateBasic <Base_User> .Get().Single(i => i.Phone == phone);

                    long receiveId = 0;
                    if (receive != null && receive.Id > 0)
                    {
                        receiveId = receive.Id;
                    }
                    model.ReceivePhone     = phone;
                    model.ReceiveId        = receiveId;
                    model.SendeCompanyId   = 0;
                    model.ReceiveCompanyId = 0;
                    model.SenderId         = 0;
                    model.SenderPhone      = "";
                    model.SenderTime       = null;
                    model.SmsCon           = con;
                    model.State            = false;
                    model.SubmissionTime   = DateTime.Now;
                    model.Step             = step.ToString();
                    model.TemplateId       = templete.Id;
                    model.ServerNo         = templete.ServerNo;
                    model.Params           = UtilitySendMessage.CreateSmsParam(parameters).Data;
                    model.SignName         = templete.SignName;
                    var splitTime = (LoadSettingsByKeys(Settings.SendRegisterCodeTime));
                    //验证是否频繁发送
                    var last = DataOperateMsg <Msg_SMSValidate> .Get().GetList(i => i.ReceivePhone == phone).OrderByDescending(i => i.Id).FirstOrDefault();

                    if (last != null && (DateTime.Now - last.RecordTime).TotalSeconds < splitTime.Value.ToInt32Req())
                    {
                        throw new Exception("不能频繁发送验证码");
                    }
                    var rows = DataOperateMsg <Msg_SMS> .Get().Add(model);

                    //添加验证码数据
                    Msg_SMSValidate valModel = new Msg_SMSValidate();
                    valModel.Code         = code;
                    valModel.SMSId        = model.Id;
                    valModel.ReceivePhone = model.ReceivePhone;
                    valModel.ReceiveId    = model.ReceiveId;
                    valModel.SendId       = model.SenderId;
                    valModel.SendTime     = model.SubmissionTime;
                    valModel.State        = ValCodeState.UNUse.ToString();
                    valModel.ValidateType = step.ToString();
                    var seconds = LoadSettingsByKeys(Settings.SMSCodeDuration).Value.ToInt32Req();
                    valModel.ExpiredTime = DateTime.Now.AddSeconds(seconds);
                    rows = DataOperateMsg <Msg_SMSValidate> .Get().Add(valModel);


                    result.Data = rows;
                    result.Flag = EResultFlag.Success;

                    WriteLog(AdminModule.SMSHistory.GetText(), SystemRight.Add.GetText(), "新增短信验证码:" + model.Id + ":" + model.SmsCon);
                }
                else
                {
                    throw new Exception("未查找到对应短信模板");
                }
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddSMSValCode");
            }
            return(result);
        }
Пример #18
0
        /// <summary>
        /// 邮件验证码
        /// </summary>
        /// <param name="receiveId"></param>
        /// <param name="step"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public Result <int> AddEmailValCode(string email, MessageStep step, Dictionary <string, string> parameters)
        {
            //生成验证码
            string code = ConstString.CreateRandomNum(ConstString.RANDOMNUMCOUNT);

            parameters.Add("Code", code);

            Result <int> result = new Result <int>();

            try
            {
                //查找模板
                var templete = DataOperateMsg <Msg_EmailTemplete> .Get().Single(i => i.Step == step.ToString() && i.IsConfirm && i.IsEnable);

                if (templete != null)
                {
                    Msg_Email model = new Msg_Email();
                    string    con   = templete.TemplateCon;
                    string    title = templete.TitleCon;
                    if (parameters != null && parameters.Any())
                    {
                        //替换标题和内容参数
                        foreach (var item in parameters)
                        {
                            con   = con.Replace("{" + item.Key + "}", item.Value);
                            title = title.Replace("{" + item.Key + "}", item.Value);
                        }
                    }
                    var receive = DataOperateBasic <Base_User> .Get().Single(i => i.Email == email);

                    long receiveId = 0;
                    if (receive != null && receive.Id > 0)
                    {
                        receiveId = receive.Id;
                    }

                    model.EmailCon         = con;
                    model.ReceiveId        = receiveId;
                    model.SendeCompanyId   = 0;
                    model.ReceiveCompanyId = 0;
                    model.ReceiveEmaile    = email;
                    model.SenderId         = 0;//管理员
                    model.SenderEmail      = DataOperateMsg <Msg_EmailSetting> .Get().Single(i => i.IsConfirm && i.IsEnable).UserName;

                    model.State          = false;
                    model.Step           = step.ToString();
                    model.TemplateId     = templete.Id;
                    model.Title          = title;
                    model.SenderTime     = null;
                    model.SubmissionTime = DateTime.Now;

                    var rows = DataOperateMsg <Msg_Email> .Get().Add(model);

                    //添加验证码数据
                    Msg_EmailValidate valModel = new Msg_EmailValidate();
                    valModel.Code         = code;
                    valModel.EmailId      = model.Id;
                    valModel.ReceiveEmail = model.ReceiveEmaile;
                    valModel.ReceiveId    = model.ReceiveId;
                    valModel.SendId       = model.SenderId;
                    valModel.SendTime     = model.SubmissionTime;
                    valModel.State        = ValCodeState.UNUse.ToString();
                    valModel.ValidateType = step.ToString();
                    var seconds = LoadSettingsByKeys(Settings.EmailCodeDuration).Value.ToInt32Req();
                    valModel.ExpiredTime = DateTime.Now.AddSeconds(seconds);
                    rows = DataOperateMsg <Msg_EmailValidate> .Get().Add(valModel);


                    result.Data = rows;
                    result.Flag = EResultFlag.Success;

                    WriteLog(AdminModule.EmailHistory.GetText(), SystemRight.Add.GetText(), "新增邮件验证码:" + model.Id + ":" + model.Title);
                }
                else
                {
                    throw new Exception("未查找到对应邮件模板");
                }
            }
            catch (Exception ex)
            {
                result.Data      = -1;
                result.Flag      = EResultFlag.Failure;
                result.Exception = new ExceptionEx(ex, "AddEmailValCode");
            }
            return(result);
        }