/// <summary> /// 提现申请 /// </summary> /// <returns></returns> public bool AuditApply(Guid id) { using (var dbContext = new WalletDbContext()) { CrashApply crashApply = dbContext.CrashApplys.FirstOrDefault(c => c.Id == id); if (crashApply == null) { throw new Exception("找不到提现的记录"); } crashApply.ApplyState = ApplyState.ApplyPassed; crashApply.AuditTime = DateTime.Now; dbContext.Set <CrashApply>().Attach(crashApply); dbContext.Entry(crashApply).State = EntityState.Modified; Models.Wallet wallet = GetWalletByMemberId(crashApply.MemberId); if (wallet == null) { throw new Exception("钱包是空的"); } else if (crashApply.Money > wallet.Frozen) { throw new Exception("提现的金额不能大于冻结的金额"); } return(dbContext.SaveChanges() > 0); } }
/// <summary> /// 申请提现 /// </summary> public bool ApplyCrash(string memberId, string account, decimal money, PaymentType paymentType, string name) { using (var dbContext = new WalletDbContext()) { CrashApply crashApply = new CrashApply(); crashApply.Id = KeyGenerator.GetGuidKey(); crashApply.MemberId = memberId; crashApply.Account = account; crashApply.TransactionNo = KeyGenerator.GetOrderNumber(); crashApply.RealName = name; crashApply.Money = money; crashApply.PaymentType = paymentType; crashApply.ApplyState = ApplyState.Applying; crashApply.CreateTime = DateTime.Now; dbContext.CrashApplys.Add(crashApply); if (paymentType == PaymentType.WeiXin) { //判断是否绑定了微信 } Models.Wallet wallet = GetWalletByMemberId(memberId); if (wallet == null) { throw new WebApiInnerException("0003", "钱包没有可以提现的余额"); } else { if (money > wallet.Available) { throw new WebApiInnerException("0004", "提现的金额不能大于钱包的余额"); } wallet.Frozen += money; wallet.Available -= money; } dbContext.Set <Models.Wallet>().Attach(wallet); dbContext.Entry(wallet).State = EntityState.Modified; return(dbContext.SaveChanges() > 0); } }
/// <summary> /// 异步返回结果 /// </summary> /// <param name="request"></param> /// <returns></returns> public string AsyncReturn(HttpRequestBase request) { Logger.Debug("支付宝批量转账回调"); var alipayConfig = _configService.Get <AlipayConfig>(); var config = new AlipayConfig2 { Partner = alipayConfig.Partner, SellerId = alipayConfig.SellerId, Md5Key = alipayConfig.MD5Key, SignType = SignType.MD5 }; SortedDictionary <string, string> sPara = GetRequestPost(request); Logger.Debug(sPara.ToJson()); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(config); bool verifyResult = aliNotify.Verify(sPara, request.Form["notify_id"], request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //批量付款数据中转账成功的详细信息 string successDetails = request.Form["success_details"]; Logger.Debug($"支付宝批量转账回调成功数据{successDetails}"); if (!string.IsNullOrEmpty(successDetails)) { var detaildata = successDetails.Split('|'); if (detaildata.Length > 0) { foreach (var detail in detaildata) { using (TransactionScope scope = new TransactionScope()) { //其他操作 var crash = detail.Split('^').FirstOrDefault(); CrashApply crashApply = _currencyService.GetSingleByConditon <CrashApply>(c => c.TransactionNo == crash); if (crashApply != null) { crashApply.ApplyState = ApplyState.Transferred; crashApply.TransferTime = DateTime.Now; crashApply.Description = "支付宝提现成功"; _currencyService.Update(crashApply); string error; if (!_walletService.Draw(crashApply.MemberId, WalletType.Cash, crashApply.Money, "提现支出", out error, null, null, true)) { Logger.Operation($"提现转账成功,扣除冻结金额处理失败,TransactionNo:{crashApply.TransactionNo},原因:{error}", PaymentProcessModule.Instance, Security.SecurityLevel.Danger); } _systemMessageService.CreatePushSystemMessage("提现打款", "您申请的提现已打款,请注意查收", "您申请的提现已打款,请注意查收", crashApply.MemberId, null, null, "CrashApply", WalletModule.Key, MessageCategory.Personal); //提交 scope.Complete(); } } } } } //批量付款数据中转账失败的详细信息 string failDetails = request.Form["fail_details"]; Logger.Debug($"支付宝批量转账回调失败数据{failDetails}"); if (!string.IsNullOrEmpty(failDetails)) { var faildata = failDetails.Split('|'); if (faildata.Length > 0) { foreach (var detail in faildata) { using (TransactionScope scope = new TransactionScope()) { var crash = detail.Split('^').FirstOrDefault(); var description = detail.Split('^'); CrashApply crashApply = _currencyService.GetSingleByConditon <CrashApply>(c => c.TransactionNo == crash); if (crashApply != null) { crashApply.ApplyState = ApplyState.Failure; crashApply.Description = description[5]; _currencyService.Update(crashApply); string error; if (!_walletService.Thaw(crashApply.MemberId, WalletType.Cash, crashApply.Money, "提现失败,解除冻结", out error)) { Logger.Operation($"提现转账失败,退还金额处理失败,TransactionNo:{crashApply.TransactionNo},原因:{error}", PaymentProcessModule.Instance, Security.SecurityLevel.Danger); } //提交 scope.Complete(); } } } } } //判断是否在商户网站中已经做过了这次通知返回的处理 //如果没有做过处理,那么执行商户的业务程序 //如果有做过处理,那么不执行商户的业务程序 return("success"); //请不要修改或删除 //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Logger.Information("提现支付宝回调处理失败,数据验证失败"); return("fail"); } } else { Logger.Information("无通知参数"); return("无通知参数"); } }