Beispiel #1
0
        private static void HandleProjectFinancingFailMsg(int projectId)
        {
            var context = new Agp2pDataContext();
            var project = context.li_projects.Single(p => p.id == projectId);

            // 查出所有已经退款的投资者 TODO 排除自己退款的投资者
            var investors = project.li_project_transactions.Where(
                ptr =>
                ptr.type == (int)Agp2pEnums.ProjectTransactionTypeEnum.Invest &&
                ptr.status == (int)Agp2pEnums.ProjectTransactionStatusEnum.Rollback)
                            .GroupBy(ptr => ptr.dt_users).Select(g => g.Key);

            var sendTime = DateTime.Now;

            //找出模板
            var smsModel = context.dt_sms_template.SingleOrDefault(te => te.call_index == "project_financing_fail");

            if (smsModel == null)
            {
                throw new InvalidOperationException("找不到流标提醒模板: project_financing_fail");
            }

            var msgContent = smsModel.content
                             .Replace("{project}", project.title)
                             .Replace("{date}", sendTime.ToString("yyyy-MM-dd HH:mm"));


            // 通知投资者项目流标
            investors.ForEach(investor =>
            {
                try
                {
                    //发送站内消息
                    var userMsg = new dt_user_message
                    {
                        type             = 1,
                        post_user_name   = "",
                        accept_user_name = investor.user_name,
                        title            = smsModel.title,
                        content          = msgContent,
                        post_time        = sendTime,
                        receiver         = investor.id
                    };
                    context.dt_user_message.InsertOnSubmit(userMsg);
                    context.SubmitChanges();
                    var errorMsg = string.Empty;
                    if (!SMSHelper.SendTemplateSms(investor.mobile, msgContent, out errorMsg))
                    {
                        context.AppendAdminLogAndSave("ProjectFinancingFailSms",
                                                      string.Format("发送项目流标提醒失败:{0}(客户ID:{1},项目名称:{2})", errorMsg, investor.user_name, project.title));
                    }
                }
                catch (Exception ex)
                {
                    context.AppendAdminLogAndSave("ProjectFinancingFailSms",
                                                  string.Format("发送项目流标提醒失败:{0}(客户ID:{1},项目名称:{2})", ex.GetSimpleCrashInfo(), investor.user_name, project.title));
                }
            });
        }
Beispiel #2
0
        /// <summary>
        /// 有新用户注册回调
        /// </summary>
        /// <param name="context"></param>
        /// <param name="userId"></param>
        /// <param name="regTime"></param>
        private static void NewUser(int userId, DateTime regTime)
        {
            var context = new Agp2pDataContext();
            var newUser = context.dt_users.Single(u => u.id == userId);

            // 创建钱包
            var wallet = new li_wallets {
                user_id = userId, last_update_time = regTime
            };

            context.li_wallets.InsertOnSubmit(wallet);

            // 创建自己的邀请码
            var codeModel = new dt_user_code
            {
                dt_users  = newUser,
                user_name = newUser.user_name,
                type      = DTEnums.CodeEnum.Register.ToString(),
                str_code  = Utils.GetCheckCode(8), //获取邀请码
                eff_time  = newUser.reg_time ?? DateTime.Now,
                add_time  = newUser.reg_time ?? DateTime.Now
            };

            context.dt_user_code.InsertOnSubmit(codeModel);

            // 注册送积分
            var dtUserPointLog = new dt_user_point_log
            {
                user_id   = newUser.id,
                user_name = newUser.user_name,
                add_time  = newUser.reg_time ?? DateTime.Now,
                value     = newUser.dt_user_groups.point ?? 0,
                remark    = "注册赠送积分"
            };

            context.dt_user_point_log.InsertOnSubmit(dtUserPointLog);

            // 发站内信
            var userConfig    = ConfigLoader.loadUserConfig();
            var dtUserMessage = new dt_user_message
            {
                type             = 1,
                accept_user_name = newUser.user_name,
                title            = "欢迎您成为本站会员",
                content          = userConfig == null ? "恭喜您注册成功,马上充值投资,赚的飞起来!" : userConfig.regmsgtxt,
                post_user_name   = "",
                post_time        = newUser.reg_time.Value,
                receiver         = newUser.id
            };

            context.dt_user_message.InsertOnSubmit(dtUserMessage);

            context.SubmitChanges();
        }
Beispiel #3
0
        private static void SendChargeSuccessNotification(li_bank_transactions tr, bool sendUserMsg, bool sendSms)
        {
            var context = new Agp2pDataContext();
            //短信通知
            var charger = tr.dt_users;

            //找出模板
            var dtSmsTemplate = context.dt_sms_template.FirstOrDefault(t => t.call_index == "user_recharge_info");

            if (dtSmsTemplate == null)
            {
                return;
            }

            var siteConfig = ConfigLoader.loadSiteConfig(false);

            //替换模板内容
            var msgContent = dtSmsTemplate.content.Replace("{amount}", tr.value.ToString())
                             .Replace("{webtel}", siteConfig.webtel);

            if (sendSms)
            {
                try
                {
                    string errorMsg;
                    if (!SMSHelper.SendTemplateSms(charger.mobile, msgContent, out errorMsg))
                    {
                        context.AppendAdminLogAndSave("ReChargeSms", "发送充值提醒失败:" + errorMsg + "(客户ID:" + charger.user_name + ",订单号:" + tr.no_order + ")");
                    }
                }
                catch (Exception ex)
                {
                    context.AppendAdminLogAndSave("ReChargeSms", "发送充值提醒失败:" + ex.GetSimpleCrashInfo() + "(客户ID:" + charger.user_name + ",订单号:" + tr.no_order + ")");
                }
            }
            if (sendUserMsg)
            {
                var message = new dt_user_message
                {
                    type             = 1,
                    accept_user_name = charger.user_name,
                    content          = msgContent,
                    receiver         = charger.id,
                    title            = dtSmsTemplate.title,
                    post_time        = tr.transact_time.GetValueOrDefault(tr.create_time)
                };
                context.dt_user_message.InsertOnSubmit(message);
                context.SubmitChanges();
            }
        }
Beispiel #4
0
        private static void sendWithdrawApplyNotification(li_bank_transactions tr, bool sendSms, bool sendUserMsg)
        {
            var context = new Agp2pDataContext();
            //短信通知
            var withdrawer = tr.li_bank_accounts.dt_users;

            //找出模板
            var dtSmsTemplate = context.dt_sms_template.FirstOrDefault(t => t.call_index == "user_withdraw_info");

            if (dtSmsTemplate == null)
            {
                return;
            }

            //替换模板内容
            var msgContent = dtSmsTemplate.content.Replace("{amount}", tr.value.ToString())
                             //.Replace("{user_name}", withdrawer.user_name)
                             .Replace("{date}", tr.create_time.ToString("yyyy-MM-dd HH:mm"));

            if (sendSms)
            {
                try
                {
                    string errorMsg;
                    if (!SMSHelper.SendTemplateSms(withdrawer.mobile, msgContent, out errorMsg))
                    {
                        context.AppendAdminLogAndSave("WithdrawSms", "发送提现通知失败:" + errorMsg + "(客户ID:" + withdrawer.user_name + ",订单号:" + tr.no_order + ")");
                    }
                }
                catch (Exception ex)
                {
                    context.AppendAdminLogAndSave("WithdrawSms", "发送提现通知失败:" + ex.GetSimpleCrashInfo() + "(客户ID:" + withdrawer.user_name + ",订单号:" + tr.no_order + ")");
                }
            }
            if (sendUserMsg)
            {
                var message = new dt_user_message
                {
                    type             = 1,
                    accept_user_name = withdrawer.user_name,
                    content          = msgContent,
                    receiver         = withdrawer.id,
                    title            = dtSmsTemplate.title,
                    post_time        = tr.transact_time.GetValueOrDefault(tr.create_time)
                };
                context.dt_user_message.InsertOnSubmit(message);
                context.SubmitChanges();
            }
        }
Beispiel #5
0
        private static void HandleProjectRepaidMsg(int repaymentTaskId)
        {
            if (ConfigLoader.loadSiteConfig().sendShortMsgAfterRepay != 1)
            {
                return;
            }

            var context      = new Agp2pDataContext();
            var repayTask    = context.li_repayment_tasks.Single(r => r.id == repaymentTaskId);
            var transactions = context.li_project_transactions.Where(t =>
                                                                     t.project == repayTask.project &&
                                                                     t.type == (int)Agp2pEnums.ProjectTransactionTypeEnum.RepayToInvestor &&
                                                                     t.create_time == repayTask.repay_at).ToLookup(ptr => ptr.dt_users);

            transactions.ForEach(group =>
            {
                var repayToUser    = group.Key;
                var repayPrincipal = group.Sum(tr => tr.principal);
                var repayInterest  = group.Sum(tr => tr.interest.GetValueOrDefault());
                var now            = DateTime.Now;

                // 检测用户是否接收放款的通知
                var sendNotificationSettings = context.li_notification_settings.Where(n => n.user_id == repayToUser.id)
                                               .Select(n => n.type).Cast <Agp2pEnums.DisabledNotificationTypeEnum>();

                try
                {
                    //找出模板
                    var smsModel = 0 < repayPrincipal
                        ? context.dt_sms_template.SingleOrDefault(te => te.call_index == "user_repay_all_info")
                        : context.dt_sms_template.SingleOrDefault(te => te.call_index == "user_repay_info");
                    if (smsModel == null)
                    {
                        throw new InvalidOperationException("找不到放款提醒模板: user_repay_all_info 或 user_repay_info");
                    }

                    //发送短信
                    var msgContent = smsModel.content
                                     //.Replace("{user_name}", t.dt_users.user_name)
                                     .Replace("{project_name}", repayTask.li_projects.title)
                                     .Replace("{amount}", (repayPrincipal + repayInterest).ToString());

                    if (!sendNotificationSettings.Contains(Agp2pEnums.DisabledNotificationTypeEnum.ProjectRepaidForUserMsg))
                    {
                        //发送站内消息
                        var userMsg = new dt_user_message
                        {
                            type             = 1,
                            post_user_name   = "",
                            accept_user_name = repayToUser.user_name,
                            title            = smsModel.title,
                            content          = msgContent,
                            post_time        = now,
                            receiver         = repayToUser.id
                        };
                        context.dt_user_message.InsertOnSubmit(userMsg);
                        context.SubmitChanges();
                    }
                    if (!sendNotificationSettings.Contains(Agp2pEnums.DisabledNotificationTypeEnum.ProjectRepaidForSms))
                    {
                        var errorMsg = string.Empty;
                        if (!SMSHelper.SendTemplateSms(repayToUser.mobile, msgContent, out errorMsg))
                        {
                            context.AppendAdminLogAndSave("RepaymentSms",
                                                          $"发送放款提醒失败:{errorMsg}(客户ID:{repayToUser.user_name},项目名称:{repayTask.li_projects.title})");
                        }
                    }
                }
                catch (Exception e)
                {
                    context.AppendAdminLogAndSave("RepaymentSms",
                                                  $"发送放款提醒失败:{e.GetSimpleCrashInfo()}(客户ID:{repayToUser.user_name},项目名称:{repayTask.li_projects.title})");
                }
            });
        }
Beispiel #6
0
        /// <summary>
        /// 发送投资成功消息
        /// </summary>
        /// <param name="projectTransactionId"></param>
        /// <param name="investTime"></param>
        private static void HandleProjectInvestMsg(int projectTransactionId, DateTime investTime)
        {
            var context = new Agp2pDataContext();

            try
            {
                //找出项目投资信息
                var investment = context.li_project_transactions.Single(p => p.id == projectTransactionId);

                //发送电子合同
                siteconfig siteConfig = ConfigLoader.loadSiteConfig();
                //增加协议号到投资记录中
                investment.agree_no = investment.li_projects.dt_article_category.call_index.ToUpper() + Utils.GetOrderNumber();
                //获得投资协议邮件内容
                var bodytxt = context.GetInvestContractContext(investment, AppDomain.CurrentDomain.BaseDirectory + "\\tools\\invest-agreement.html");
                //发送投资协议邮件
                // TODO 新手体验标 不发投资协议到邮箱
                if (!string.IsNullOrWhiteSpace(investment.dt_users.email) && !investment.li_projects.IsNewbieProject1())
                {
                    DTMail.sendMail(siteConfig.emailsmtp,
                                    siteConfig.emailusername,
                                    DESEncrypt.Decrypt(siteConfig.emailpassword),
                                    siteConfig.emailnickname,
                                    siteConfig.emailfrom,
                                    investment.dt_users.email,
                                    "安广融合投资协议", bodytxt);
                }

                // 检测用户是否接收放款的通知
                var sendNotificationSettings = context.li_notification_settings.Where(n => n.user_id == investment.investor)
                                               .Select(n => n.type).Cast <Agp2pEnums.DisabledNotificationTypeEnum>();

                if (sendNotificationSettings.Contains(Agp2pEnums.DisabledNotificationTypeEnum.InvestSuccessForUserMsg))
                {
                    return;
                }
                else
                {
                    context.SubmitChanges();
                }

                //发送投资站内信息
                var dtSmsTemplate = context.dt_sms_template.FirstOrDefault(t => t.call_index == "invest_success");
                if (dtSmsTemplate == null)
                {
                    return;
                }

                var content = dtSmsTemplate.content.Replace("{date}", investment.create_time.ToString("yyyy年MM月dd日HH时mm分"))
                              .Replace("{projectName}", investment.li_projects.title)
                              .Replace("{amount}", investment.principal.ToString("N"));

                var userMsg = new dt_user_message
                {
                    type             = 1,
                    post_user_name   = "",
                    accept_user_name = investment.dt_users.user_name,
                    title            = dtSmsTemplate.title,
                    content          = content,
                    post_time        = investTime,
                    receiver         = investment.investor
                };
                context.dt_user_message.InsertOnSubmit(userMsg);
                context.SubmitChanges();
            }
            catch (Exception ex)
            {
                context.AppendAdminLog("Invest", "发送投资成功消息时错误:" + ex.Message);
                context.SubmitChanges();
            }
        }