/// <summary> /// 活期项目转出本金 /// </summary> /// <param name="projectCode"></param> /// <param name="grouping"></param> /// <param name="callBack"></param> public static void SendReturnPrinInte(int projectCode, IGrouping <li_projects, li_claims> grouping, Action callBack) { var context = new Agp2pDataContext(); //创建本息到账请求并设置分账列表 var returnPrinInteReqMsg = new ReturnPrinInteReqMsg(projectCode, grouping.Sum(pcsc => pcsc.principal).ToString("f"), true); //生成分账列表(每个转出用户的本金) returnPrinInteReqMsg.SetSubledgerList(grouping.ToLookup(c => c.dt_users)); //发送请求 MessageBus.Main.PublishAsync(returnPrinInteReqMsg, msg => { //处理请求同步返回结果 var returnPrinInteRespMsg = BaseRespMsg.NewInstance <ReturnPrinInteRespMsg>(msg.SynResult); returnPrinInteRespMsg.Sync = true; returnPrinInteReqMsg.Remarks = "isEarly=false&isHuoqi=true"; MessageBus.Main.PublishAsync(returnPrinInteRespMsg, result => { if (callBack != null && returnPrinInteRespMsg.HasHandle) { callBack(); } }); }); }
protected void btnRefund_OnClick(object sender, EventArgs e) { try { int projectTransactionId = Convert.ToInt32(((Button)sender).CommandArgument); var proTran = context.li_project_transactions.SingleOrDefault(t => t.id == projectTransactionId); if (proTran == null) { throw new ArgumentNullException(nameof(proTran)); } var msg = new WithDrawalReqMsg(proTran.project, proTran.li_projects.investment_amount.ToString("f"), proTran.no_order, proTran.principal.ToString("f")); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <WithDrawalRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { var remark = "撤销投资成功, 涉及金额: " + proTran.principal; AddAdminLog(DTEnums.ActionEnum.Cancel.ToString(), remark); //记录日志 JscriptMsg(remark, Utils.CombUrlTxt("project_investment_list.aspx", "project_id={0}", project_id), "Success"); } else { JscriptMsg("撤销投资失败:" + msgResp.Remarks, "back", "Error"); } var bt = context.Refund(projectTransactionId, DateTime.Now); } catch (Exception ex) { JscriptMsg("撤销投资失败!" + ex.Message, Utils.CombUrlTxt("project_investment_list.aspx", "project_id={0}", project_id), "Failure"); } }
/// <summary> /// 解绑快捷支付银行卡 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRemoveCard_OnClick(object sender, EventArgs e) { ChkAdminLevel("all_bank_account_list", DTEnums.ActionEnum.Edit.ToString()); //检查权限 try { var bankId = Utils.StrToInt(((LinkButton)sender).CommandArgument, 0); var bank = context.li_bank_accounts.SingleOrDefault(b => b.id == bankId); var user = bank.dt_users; var msg = new RemoveCardReqMsg(user.id, user.real_name, user.id_card_number, user.mobile, user.email); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <RemoveCardRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { JscriptMsg("解绑操作成功!", "../transact/all_bank_account_list.aspx"); } else { JscriptMsg("解绑操作失败:" + msgResp.Remarks, "back", "Error"); } } catch (Exception ex) { JscriptMsg("解绑操作失败:" + ex.Message, "back", "Error"); } }
/// <summary> /// 借款流标 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnFail_OnClick(object sender, EventArgs e) { ChkAdminLevel("loan_financing", DTEnums.ActionEnum.Delete.ToString()); var project = LqContext.li_projects.SingleOrDefault(p => p.id == ProjectId); if (project != null) { var msg = new RepealProjectReqMsg(ProjectId, project.investment_amount.ToString("F")); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <RepealProjectRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { project.status = (int)Agp2pEnums.ProjectStatusEnum.FinancingFail; JscriptMsg("流标操作成功!", Utils.CombUrlTxt("loan_financing.aspx", "channel_id={0}&status={1}", this.ChannelId.ToString(), ((int)Agp2pEnums.ProjectStatusEnum.ProjectRepaying).ToString())); } else { JscriptMsg("流标操作失败:" + msgResp.Remarks, "back", "Error"); } } else { JscriptMsg("项目不存在或已被删除!", "back", "Error"); } }
private static void DoPayBonusInterest(int projectId, DateTime projectCompleteTime) { var context = new Agp2pDataContext(); // 找出未支付的奖励 var projectAtrs = context.li_activity_transactions.Where(atr => atr.activity_type == (byte)Agp2pEnums.ActivityTransactionActivityTypeEnum.InterestRateTicket && atr.status == (byte)Agp2pEnums.ActivityTransactionStatusEnum.Confirm && atr.type == (byte)Agp2pEnums.ActivityTransactionTypeEnum.Gain && atr.transact_time == null && (atr.details.Contains("\"ProjectId\":" + projectId + ",") || atr.details.Contains("\"ProjectId\":" + projectId + "}"))) .ToLookup(atr => atr.dt_users); // 支付奖励并减去代收金额 projectAtrs.ForEach(userTickets => { var wallet = userTickets.Key.li_wallets; userTickets.ForEach(atr => { //丰付获取收益 var msg = new HongbaoPayReqMsg(atr.user_id, atr.value); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <HongbaoPayRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { atr.remarks = "加息券收益"; atr.transact_time = projectCompleteTime; wallet.profiting_money -= atr.value; wallet.idle_money += atr.value; wallet.total_profit += atr.value; wallet.last_update_time = projectCompleteTime; var his = TransactionFacade.CloneFromWallet(wallet, Agp2pEnums.WalletHistoryTypeEnum.GainConfirm); his.li_activity_transactions = atr; context.li_wallet_histories.InsertOnSubmit(his); } }); }); if (projectAtrs.Any()) { context.AppendAdminLog(DTEnums.ActionEnum.Edit.ToString(), "加息券自动放款用户数:" + projectAtrs.Count); } context.SubmitChanges(); }
public void TestSumapayApi() { //1.请求前台接口 //1.1发送请求 var msgReq = new UserRegisterReqMsg(1030, "18681406981", "罗明星", "440233198602010019", "0"); MessageBus.Main.Publish(msgReq); //正式请求时,进行如下异步调用 //MessageBus.Main.PublishAsync(msgReq, s => //{ // Utils.HttpPost(msgReq.ApiInterface, msgReq.RequestContent); //}); //1.2模拟响应返回 Agp2pDataContext context = new Agp2pDataContext(); var responseLog = new li_pay_response_log() { request_id = msgReq.RequestId, result = "00000", status = (int)Agp2pEnums.SumapayResponseEnum.Return, response_time = DateTime.Now, response_content = "{request:'" + msgReq.RequestId + "',result:'00000'}" }; context.li_pay_response_log.InsertOnSubmit(responseLog); //1.3发送响应消息 var respMsg = BaseRespMsg.NewInstance <UserRegisterRespMsg>(responseLog.response_content); MessageBus.Main.PublishAsync(respMsg, s => { if (respMsg.HasHandle) { var req = context.li_pay_request_log.SingleOrDefault(r => r.id == responseLog.request_id); req.complete_time = DateTime.Now; req.status = (int)Agp2pEnums.SumapayRequestEnum.Complete; responseLog.user_id = respMsg.UserIdIdentity; responseLog.status = (int)Agp2pEnums.SumapayResponseEnum.Complete; } responseLog.remarks = respMsg.Remarks; context.SubmitChanges(); //Assert.IsTrue(s.IsCompleted); }); }
/// <summary> /// 发送本息到账请求 /// </summary> /// <param name="projectCode"></param> /// <param name="sum"></param> /// <param name="repayTaskId">定期为还款计划id,活期为转出人id</param> /// <param name="isEarlyPay"></param> /// <param name="huoqi"></param> /// <param name="callBack"></param> public static void SendReturnPrinInte(int projectCode, string sum, int repayTaskId, bool isEarlyPay, bool isHuoqi) { var context = new Agp2pDataContext(); //创建本息到账请求并设置分账列表 var returnPrinInteReqMsg = new ReturnPrinInteReqMsg(projectCode, sum, isHuoqi); //定期项目需计算全部投资者本息明细 var repayRask = context.li_repayment_tasks.SingleOrDefault(r => r.id == repayTaskId); var transList = TransactionFacade.GenerateRepayTransactions(repayRask, DateTime.Now); returnPrinInteReqMsg.SetSubledgerList(transList); returnPrinInteReqMsg.Remarks = $"isEarly=false&repayTaskId={repayTaskId}&isHuoqi={isHuoqi}"; //发送请求 MessageBus.Main.PublishAsync(returnPrinInteReqMsg, msg => { //处理请求同步返回结果 var returnPrinInteRespMsg = BaseRespMsg.NewInstance <ReturnPrinInteRespMsg>(msg.SynResult); MessageBus.Main.PublishAsync(returnPrinInteRespMsg); }); }
/// <summary> /// 查询活期项目 /// </summary> /// <param name="msg"></param> private static void QueryProject(QueryProjectRespMsg msg) { try { //检查请求处理结果 if (msg.CheckResult()) { //检查签名 if (msg.CheckSignature()) { //根据放款余额,发送放款请求 if (Utils.StrToDecimal(msg.LoanAccountBalance, 0) > 0) { Agp2pDataContext context = new Agp2pDataContext(); var project = context.li_projects.SingleOrDefault(p => p.id == msg.ProjectCode); if (project != null) { var makeLoanReqMsg = new MakeLoanReqMsg(project.li_risks.li_loaners.user_id, project.id, msg.LoanAccountBalance, true); MessageBus.Main.PublishAsync(makeLoanReqMsg, ar => { var msgResp = BaseRespMsg.NewInstance<MakeLoanRespMsg>(makeLoanReqMsg.SynResult); msgResp.Sync = true; MessageBus.Main.PublishAsync(msgResp); }); } else { msg.Remarks = "没有找到对应的项目,项目id:" + msg.ProjectCode; } } } } } catch (Exception ex) { msg.Remarks = "内部错误:" + ex.Message; } }
/// <summary> /// 解绑银行卡 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRemoveCard_OnClick(object sender, EventArgs e) { try { var user = context.dt_users.SingleOrDefault(u => u.id == user_id); var msg = new RemoveCardReqMsg(user_id, user.real_name, user.id_card_number, user.mobile, user.email); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <RemoveCardRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { JscriptMsg("解绑操作成功!", "../transact/all_bank_account_list.aspx"); } else { JscriptMsg("解绑操作失败:" + msgResp.Remarks, "back", "Error"); } } catch (Exception ex) { JscriptMsg("解绑操作失败:" + ex.Message, "back", "Error"); } }
private static void DoAutoMakeLoan(TimerMsg.Type timerType, bool onTime) { if (timerType != TimerMsg.Type.AutoMakeLoanTimer) { return; } var db = new Agp2pDataContext(); var huoqiPro = db.li_projects.OrderByDescending(p => p.publish_time).FirstOrDefault(p => p.dt_article_category.call_index == "huoqi"); if (huoqiPro != null) { //查询活期项目放款余额 var reqMsg = new QueryProjectReqMsg(huoqiPro.id); MessageBus.Main.PublishAsync(reqMsg, ar => { var msgResp = BaseRespMsg.NewInstance <QueryProjectRespMsg>(reqMsg.SynResult); msgResp.Sync = true; MessageBus.Main.Publish(msgResp); db.AppendAdminLog("AutoMakeLoan", "查询今日放款余额为:" + msgResp.LoanAccountBalance); db.SubmitChanges(); }); } }
/// <summary> /// 放款给借款人 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnMakeLoan_OnClick(object sender, EventArgs e) { try { ChkAdminLevel("make_loan_audit", DTEnums.ActionEnum.Audit.ToString()); var project = LqContext.li_projects.SingleOrDefault(p => p.id == ProjectId); //调用托管平台实名验证接口 if (project != null) { var user = project.li_risks.li_loaners.dt_users; //TODO 是否集合项目 var msg = new MakeLoanReqMsg(user.id, ProjectId, project.investment_amount.ToString("F"), false, user.dt_user_groups.title.Equals("融资合作组")); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance <MakeLoanRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { JscriptMsg("放款操作成功!", Utils.CombUrlTxt("../audit/make_loan_audit.aspx", "channel_id={0}&status={1}", this.ChannelId.ToString(), ((int)Agp2pEnums.ProjectStatusEnum.ProjectRepaying).ToString())); } else { JscriptMsg("放款操作失败:" + msgResp.Remarks, "back", "Error"); } } else { JscriptMsg("放款操作失败,没有找到项目!", "back", "Error"); } } catch (Exception ex) { JscriptMsg("放款操作失败:" + ex.Message, "back", "Error"); } }
/// <summary> /// 处理托管接口请求响应 /// </summary> /// <param name="isSync">是否同步返回</param> protected void DoResponse(bool isSync = false) { Agp2pDataContext context = new Agp2pDataContext(); try { string reqStr = ReadReqStr(); ResponseLog = new li_pay_response_log() { request_id = string.IsNullOrEmpty(Request["requestId"]) ? null : Request["requestId"], result = string.IsNullOrEmpty(Request["result"]) ? "" : Request["result"], status = (int)Agp2pEnums.SumapayResponseEnum.Return, response_time = DateTime.Now, response_content = reqStr }; if (!string.IsNullOrEmpty(ResponseLog.request_id)) { //根据响应报文找到对应的request,生成处理消息,对应各种消息处理逻辑 RequestLog = context.li_pay_request_log.SingleOrDefault(r => r.id == ResponseLog.request_id); if (RequestLog != null) { //检查请求是否已经处理过 if (RequestLog.status != (int)Agp2pEnums.SumapayRequestEnum.Complete) { BaseRespMsg respMsg = null; switch (RequestLog.api) { //个人/企业 开户/激活 case (int)Agp2pEnums.SumapayApiEnum.URegi: case (int)Agp2pEnums.SumapayApiEnum.URegM: case (int)Agp2pEnums.SumapayApiEnum.Activ: case (int)Agp2pEnums.SumapayApiEnum.CRegi: respMsg = new UserRegisterRespMsg(reqStr); break; //个人自动投标续约 case (int)Agp2pEnums.SumapayApiEnum.AtBid: respMsg = new AutoBidSignRespMsg(reqStr); break; //个人自动投标取消 case (int)Agp2pEnums.SumapayApiEnum.ClBid: respMsg = new AutoBidSignRespMsg(reqStr, true); break; //个人/企业 自动账户/银行还款开通 case (int)Agp2pEnums.SumapayApiEnum.AcReO: case (int)Agp2pEnums.SumapayApiEnum.CcReO: case (int)Agp2pEnums.SumapayApiEnum.AbReO: respMsg = new AutoRepaySignRespMsg(reqStr); break; //个人/企业 自动还款取消 case (int)Agp2pEnums.SumapayApiEnum.ClRep: case (int)Agp2pEnums.SumapayApiEnum.CancR: respMsg = new AutoRepaySignRespMsg(reqStr, true); break; //企业/个人网银充值 case (int)Agp2pEnums.SumapayApiEnum.WeRec: case (int)Agp2pEnums.SumapayApiEnum.CeRec: respMsg = new RechargeRespMsg(reqStr); break; //个人一键充值 case (int)Agp2pEnums.SumapayApiEnum.WhRec: case (int)Agp2pEnums.SumapayApiEnum.WhReM: respMsg = new WithholdingRechargeRespMsg(reqStr); break; //个人投标/自动投标 普通/集合项目 case (int)Agp2pEnums.SumapayApiEnum.MaBid: case (int)Agp2pEnums.SumapayApiEnum.McBid: case (int)Agp2pEnums.SumapayApiEnum.MaBiM: case (int)Agp2pEnums.SumapayApiEnum.McBiM: case (int)Agp2pEnums.SumapayApiEnum.AmBid: case (int)Agp2pEnums.SumapayApiEnum.AcBid: respMsg = new BidRespMsg(reqStr); break; //个人撤标 case (int)Agp2pEnums.SumapayApiEnum.CaPro: case (int)Agp2pEnums.SumapayApiEnum.CoPro: respMsg = new WithDrawalRespMsg(reqStr); break; //流标普通项目 case (int)Agp2pEnums.SumapayApiEnum.RePro: respMsg = new RepealProjectRespMsg(reqStr); break; //普通/集合项目放款 case (int)Agp2pEnums.SumapayApiEnum.ALoan: case (int)Agp2pEnums.SumapayApiEnum.CLoan: respMsg = new MakeLoanRespMsg(reqStr); break; //个人/企业提现 case (int)Agp2pEnums.SumapayApiEnum.Wdraw: case (int)Agp2pEnums.SumapayApiEnum.Cdraw: case (int)Agp2pEnums.SumapayApiEnum.WdraM: respMsg = new WithdrawRespMsg(reqStr, isSync); break; //个人/企业 存管账户还款普通/集合项目 case (int)Agp2pEnums.SumapayApiEnum.MaRep: case (int)Agp2pEnums.SumapayApiEnum.McRep: case (int)Agp2pEnums.SumapayApiEnum.CaRep: case (int)Agp2pEnums.SumapayApiEnum.CoRep: respMsg = new RepayRespMsg(reqStr); break; //个人协议还款普通/集合项目 case (int)Agp2pEnums.SumapayApiEnum.BaRep: case (int)Agp2pEnums.SumapayApiEnum.BcRep: respMsg = new RepayRespMsg(reqStr, true); break; //个人自动还款普通/集合项目 case (int)Agp2pEnums.SumapayApiEnum.AcRep: case (int)Agp2pEnums.SumapayApiEnum.AbRep: case (int)Agp2pEnums.SumapayApiEnum.CcRep: case (int)Agp2pEnums.SumapayApiEnum.CbRep: respMsg = new RepayRespMsg(reqStr, false, true); break; //普通/集合项目本息到账 case (int)Agp2pEnums.SumapayApiEnum.RetPt: case (int)Agp2pEnums.SumapayApiEnum.RetCo: respMsg = new ReturnPrinInteRespMsg(reqStr); break; //债权转让 case (int)Agp2pEnums.SumapayApiEnum.CreAs: case (int)Agp2pEnums.SumapayApiEnum.CreAM: respMsg = new CreditAssignmentRespMsg(reqStr); break; //查询项目 case (int)Agp2pEnums.SumapayApiEnum.QuPro: respMsg = BaseRespMsg.NewInstance <QueryProjectRespMsg>(reqStr); break; //银行卡解绑 case (int)Agp2pEnums.SumapayApiEnum.RemCa: respMsg = new RemoveCardRespMsg(reqStr); break; //红包付款至用户 case (int)Agp2pEnums.SumapayApiEnum.HbPay: respMsg = new HongbaoPayRespMsg(reqStr); break; default: respMsg = new BaseRespMsg(); break; } //发送响应消息处理 MessageBus.Main.Publish(respMsg); //更新日志信息 ResponseLog.user_id = respMsg.UserIdIdentity; ResponseLog.project_id = respMsg.ProjectCode; RequestLog.complete_time = DateTime.Now; if (respMsg.HasHandle) { ResponseLog.status = (int)Agp2pEnums.SumapayResponseEnum.Complete; RequestLog.status = (int)Agp2pEnums.SumapayRequestEnum.Complete; } else { ResponseLog.status = (int)Agp2pEnums.SumapayResponseEnum.Invalid; RequestLog.status = (int)Agp2pEnums.SumapayRequestEnum.Fail; //记录失败信息 ResponseLog.remarks += respMsg.Remarks; } context.li_pay_response_log.InsertOnSubmit(ResponseLog); } } else { context.AppendAdminLog("SumaPayNotic", "没有找到对应的请求,RequestID:" + ResponseLog.request_id); } } else { context.AppendAdminLog("SumaPayNotic", "请求流水号为空!返回报文为:" + reqStr); } } catch (Exception ex) { context.AppendAdminLog("SumaPayNotic", "noticeUrl 内部错误:" + ex.Message); } //解决错误“找不到行或已修改” try { context.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict); } catch (System.Data.Linq.ChangeConflictException ex) { //不再提交数据更新 new Agp2pDataContext().AppendAdminLogAndSave("SumaPayNotic", "noticeUrl 找不到行或已修改:" + ex.Message); } }
public static void DoGainLoanerRepayment(TimerMsg.Type timerType, bool onTime) { if (timerType != TimerMsg.Type.LoanerRepayTimer) { return; } // 找出今天需要回款,并且没有收取还款的计划 var context = new Agp2pDataContext(); var shouldRepayTask = context.li_repayment_tasks.Where(t => t.li_projects.li_risks.li_loaners != null && t.status == (int)Agp2pEnums.RepaymentStatusEnum.Unpaid && t.should_repay_time.Date <= DateTime.Today) .AsEnumerable() .Where(t => { var loaner = t.li_projects.li_risks.li_loaners; return(!loaner.dt_users.li_bank_transactions.Any( btr => btr.type == (int)Agp2pEnums.BankTransactionTypeEnum.GainLoanerRepay && btr.status == (int)Agp2pEnums.BankTransactionStatusEnum.Confirm && btr.remarks == t.id.ToString())); }) .ToList(); if (!shouldRepayTask.Any()) { return; } shouldRepayTask.ForEach(t => { var project = context.li_projects.SingleOrDefault(p => p.id == t.project); if (project != null) { var loaner = project.li_risks.li_loaners.dt_users; try { if (project.IsHuoqiProject() || (project.autoRepay != null && (bool)project.autoRepay)) { //创建自动还款托管接口请求 var autoRepayReqMsg = loaner.dt_user_groups.title.Equals("融资合作组") ? new CompanyAutoRepayReqMsg(loaner.id, t.project, (t.repay_principal + t.repay_interest).ToString("f")) : new AutoRepayReqMsg(loaner.id, t.project, (t.repay_principal + t.repay_interest).ToString("f")); autoRepayReqMsg.Remarks = $"isEarly=false&repayTaskId={t.id}"; //发送请求 MessageBus.Main.PublishAsync(autoRepayReqMsg, msg => { //处理请求同步返回结果 var repayRespMsg = BaseRespMsg.NewInstance <RepayRespMsg>(msg.SynResult); repayRespMsg.AutoRepay = true; MessageBus.Main.PublishAsync(repayRespMsg); }); } } catch (Exception ex) { context.AppendAdminLog("GainLoanerRepayment", ex.Message == "借款人的余额不足" ? $"借款人 {loaner.GetFriendlyUserName()} 的余额小于还款计划需要收取的金额 {t.repay_principal + t.repay_interest}" : ex.GetSimpleCrashInfo()); } } }); }
private static void HandleUserInvestedMsg(int projectTransactionId, DateTime investTime) { var context = new Agp2pDataContext(); var projectTransaction = context.li_project_transactions.Single(tr => tr.id == projectTransactionId); var unactived = context.li_activity_transactions.Where(a => a.user_id == projectTransaction.investor && a.status == (int)Agp2pEnums.ActivityTransactionStatusEnum.Acting && a.type == (int)Agp2pEnums.ActivityTransactionTypeEnum.Gain && a.activity_type == (int)Agp2pEnums.ActivityTransactionActivityTypeEnum.HongBao).ToList(); if (!unactived.Any()) return; var wallet = context.li_wallets.Single(w => w.user_id == projectTransaction.investor); decimal investAmount = projectTransaction.principal; // 优先取得较大的红包,一样大的话优先满足快过期的红包 var rps = unactived.Select(a => new HongBao(a)) .OrderByDescending(a => a.GetInvestUntil()) .ThenBy(a => a.GetDeadline()) .ToList(); // 汇总未激活红包的投资金额 investAmount += rps.Sum(rp => rp.GetInvested()); rps.ForEach(rp => rp.SetInvested(null)); foreach (var rp in rps) { if (rp.GetInvestUntil() <= investAmount) // 投资足够激活红包 { //丰付支付 var msg = new HongbaoPayReqMsg(rp.atr.user_id, rp.atr.value); MessageBus.Main.Publish(msg); var msgResp = BaseRespMsg.NewInstance<HongbaoPayRespMsg>(msg.SynResult); MessageBus.Main.Publish(msgResp); if (msgResp.HasHandle) { investAmount -= rp.GetInvestUntil(); // 红包激活,发放奖金,更改状态 rp.Activate(investTime); var curr = rp.atr; wallet.idle_money += curr.value; wallet.last_update_time = investTime; var his = TransactionFacade.CloneFromWallet(wallet, Agp2pEnums.WalletHistoryTypeEnum.GainConfirm); his.li_activity_transactions = curr; context.li_wallet_histories.InsertOnSubmit(his); } } } // 有剩余投资金额不够激活钱包的话将其记在第一个未被激活的红包 var firstRp = rps.FirstOrDefault(rp => rp.atr.status == (int)Agp2pEnums.ActivityTransactionStatusEnum.Acting); if (0 < investAmount && firstRp != null) { firstRp.SetInvested(investAmount); } context.SubmitChanges(); }
public new static string AjaxAppendCard(string cardNumber, string bankName) { var userInfo = GetUserInfoByLinq(); HttpContext.Current.Response.TrySkipIisCustomErrors = true; if (userInfo == null) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return("请先登录"); } // 检查用户的输入 if (!new Regex(@"^\d{16,}$").IsMatch(cardNumber)) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest; return("银行卡号格式不正确"); } if (!new Regex(@"^[\u4e00-\u9fa5]+$").IsMatch(bankName)) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest; return("银行名称格式不正确"); } var context = new Agp2pDataContext(); var alreadyHave = userInfo.li_bank_accounts.Any(c => c.account == cardNumber); if (alreadyHave) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Conflict; return("你已经添加了卡号为 " + cardNumber + " 的银行卡,不能重复添加"); } if (3 <= userInfo.li_bank_accounts.Count) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest; return("最多只能添加 3 张银行卡"); } //查询该客户是否已经在丰付绑定了银行卡 var user = context.dt_users.Single(u => u.id == userInfo.id); var req = new SignBankCardQueryRequest(user.id); MessageBus.Main.Publish(req); var resp = BaseRespMsg.NewInstance <SignBankCardQueryRespone>(req.SynResult); if (resp.RechargeProtocolList != null) { if (resp.CheckRechargeProtocol(bankName, cardNumber)) { var card = new li_bank_accounts { dt_users = user, account = cardNumber, bank = bankName, last_access_time = DateTime.Now, opening_bank = "", location = "", type = (int)Common.Agp2pEnums.BankAccountType.QuickPay, }; context.li_bank_accounts.InsertOnSubmit(card); context.SubmitChanges(); var msg = new UserPointMsg(user.id, user.user_name, (int)Agp2pEnums.PointEnum.BindingBank); MessageBus.Main.Publish(msg); return("保存银行卡信息成功"); } else { return("添加银行卡失败,您输入的银行卡号与丰付平台绑定的银行卡号不一致!"); } } var cardUnknown = new li_bank_accounts { dt_users = user, account = cardNumber, bank = bankName, last_access_time = DateTime.Now, opening_bank = "", location = "", type = (int)Common.Agp2pEnums.BankAccountType.Unknown, }; context.li_bank_accounts.InsertOnSubmit(cardUnknown); context.SubmitChanges(); var msg2 = new UserPointMsg(user.id, user.user_name, (int)Agp2pEnums.PointEnum.BindingBank); MessageBus.Main.Publish(msg2); return("保存银行卡信息成功"); }
public static void HuoqiClaimTransferToCompanyWhenNeeded(TimerMsg.Type timerType, bool onTime) { if (timerType != TimerMsg.Type.AutoRepayTimer) { return; } using (var ts = new TransactionScope()) { // 将需要转让的债权由中间人购买,转手之后设置为 TransferredUnpaid var context = new Agp2pDataContext(); var companyUsers = context.dt_users.Where(u => u.dt_user_groups.title == AutoRepay.AgentGroup).ToList(); if (!companyUsers.Any()) { throw new InvalidOperationException("请先往“中间户”的会员组添加会员"); } // 接手昨日/更早的提现 var needTransferClaims = context.li_claims.Where( c => c.projectId != c.profitingProjectId && c.status == (int)Agp2pEnums.ClaimStatusEnum.NeedTransfer && !c.Children.Any() && c.createTime.Date < DateTime.Today) .ToList(); if (!needTransferClaims.Any()) { return; } //根据活期项目发送还款请求 needTransferClaims.ToLookup(c => c.li_projects_profiting).ForEach(groupByProj => { //找出活期项目对应的中间人 var huoqiProj = groupByProj.Key; var loaner = huoqiProj.li_risks.li_loaners.dt_users; var needTransferClaimsSum = groupByProj.Sum(c => c.principal); if (loaner.li_wallets.idle_money < needTransferClaimsSum) { throw new InvalidOperationException("警告:中间人的余额不足以接手需要转让的债权"); } //创建自动还款托管接口请求 var autoRepayReqMsg = new AutoRepayReqMsg(loaner.id, huoqiProj.id, needTransferClaimsSum.ToString("f")); MessageBus.Main.PublishAsync(autoRepayReqMsg, ar => { //处理请求同步返回结果 var repayRespMsg = BaseRespMsg.NewInstance <RepayRespMsg>(autoRepayReqMsg.SynResult); repayRespMsg.HuoqiRepay = true; MessageBus.Main.PublishAsync(repayRespMsg, result => { if (repayRespMsg.HasHandle) { //托管还款完成后才接手转出的债权 context.RecaptureHuoqiClaim(groupByProj.ToList(), DateTime.Now); } }); }); }); ts.Complete(); } }