private static int ProcessCreateRequestToCashRecord(string toCashSysNos, CommissionToCashRecordEntity data) { int toCashRecordSysNo = 0; //开启事务 TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { if (data.IsHasInvoice == "N") { //不能提供发票,扣除个人所得税。 data.AfterTaxAmt = CalculationPersonalIncomeTax(data.ToCashAmt); //计算去税金额 } toCashRecordSysNo = SyncAutomationDAL.CreateRequestToCashRecord(data); if (toCashRecordSysNo <= 0) { return(toCashRecordSysNo); } bool isSuccess = SyncAutomationDAL.UpdateCommissionSettlement(toCashRecordSysNo, toCashSysNos); if (!isSuccess) { return(toCashRecordSysNo); } scope.Complete(); } return(toCashRecordSysNo); }
public void ProcessWork() { //1.获取时间 DateTime now = Settings.SettledDate; int day = 20; if (Settings.SettledDay.HasValue) { day = Settings.SettledDay.Value; } if (now.Day != day) { //默认每月20号结算 #if !Test return; #endif } // 已结算但未付款 // 且无兑现单 List <CommissionSettlementEntity> list = SyncAutomationDAL.GetUnApplyedCommissionSettlement(); if (list == null || list.Count == 0) { return; } Dictionary <int, List <CommissionSettlementEntity> > userCSList = GroupbyCustomer(list); foreach (KeyValuePair <int, List <CommissionSettlementEntity> > key in userCSList) { // 计算 CommissionAmt 总金额 List <CommissionSettlementEntity> userEntityList = key.Value; decimal?total = userEntityList.Sum(x => x.CommissionAmt); if (total.HasValue && total.Value >= 100) { // 获取用户信息、帐户信息 UserInfo userInfo = SyncAutomationDAL.GetUserInfo(key.Key); if (userInfo == null) { continue; } // 总金额大于100,自动申请兑现单 try { RequestCashPay(userInfo, userEntityList, total.Value); } catch { } } } }
/// <summary> /// 数据合法性 & 准备数据 /// </summary> /// <param name="toCashSysNos"></param> private CommissionToCashRecordEntity CheckAndPrepareData(UserInfo userInfo, List <CommissionSettlementEntity> commissionSettlementEntitys, decimal requestAmount, string isHasInvoice) { //1.获取用户信息 if (string.IsNullOrEmpty(userInfo.BankCode) || string.IsNullOrEmpty(userInfo.BankName) || string.IsNullOrEmpty(userInfo.BranchBank) || string.IsNullOrEmpty(userInfo.BankCardNumber) || string.IsNullOrEmpty(userInfo.ReceivableName) ) { throw new BusinessException("您的收款账户信息不完整,请完善收款信息后再提交兑现申请!"); } //2.计算兑现佣金金额 //3.校验账户余额 decimal unRequestAmt = SyncAutomationDAL.GetUnRequestCommissionSettlementAmt(userInfo.SysNo); //获取当前用户已结算单是为付款的金额 if (userInfo.BalanceAmt < 0) { string msg = string.Format("申请兑现时,账户余额不能少于0元!"); throw new BusinessException(msg); } if (userInfo.BalanceAmt + requestAmount + unRequestAmt < 0) { string msg = string.Format("申请兑现后的余额账户不能少于0元!账户余额{0}元,本次申请金额{1}元,未提交申请{2}元", userInfo.BalanceAmt, requestAmount, unRequestAmt); throw new BusinessException(msg); } //4.设置数据 CommissionToCashRecordEntity recordEntity = new CommissionToCashRecordEntity { UserSysNo = userInfo.SysNo, Status = "R", ToCashAmt = requestAmount, BankCode = userInfo.BankCode, BankName = userInfo.BankName, BranchBank = userInfo.BranchBank, BankCardNumber = userInfo.BankCardNumber, ReceivableName = userInfo.ReceivableName, IsHasInvoice = isHasInvoice, InUser = userInfo.SysNo.ToString() }; return(recordEntity); }