/// <summary> /// 确认 /// </summary> /// <param name="model"></param> public void ToConfirmPayment(PaymentConAbaViewModel model) { #region valid var user = this.ValidIsBranch(model.Sys_LoginUserID); if (string.IsNullOrWhiteSpace(model.SerialNumber)) throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "银行流水号")); else if (!model.SerialNumber.ValidateLen(100)) throw new DataValidationException("银行流水号长度在1-100个字符"); var single = this._paymentRepository.GetModelTracking().Include(c => c.Special).Where(c => c.ID == model.ID).SingleOrDefault(); if (single == null) throw new BusinessException("付款信息不存在"); if (single.Status == PaymentStatus.Discard) throw new BusinessException("付款信息已被废弃"); if (single.Status == PaymentStatus.HasPayment) throw new BusinessException("付款信息已被确认"); #endregion //如果付款金额加上付款手续费大于余额减掉毛利就不能付款 var special = this._specialMainRepository.GetModelTracking().Include(c => c.SpecialCapital).Include(c => c.Branch).Where(c => c.ID == single.Special.ID).SingleOrDefault(); var payMoney = single.Money + single.CounterFee; var balance = special.SpecialCapital.Balance - special.SpecialCapital.Profit; //也需要加上未审核的付款申请总金额 //var notAuditMoney = this._paymentRepository.GetModel(c => c.SpecialId == single.Special.ID && c.Status == PaymentStatus.WaitVerify).Sum(c => c.Money + c.CounterFee); //if ((payMoney + notAuditMoney) > balance) var notAuditMoney = this._paymentRepository.GetModel(c => c.SpecialId == single.SpecialId && c.Status == PaymentStatus.WaitVerify).ToList(); var waitMoney = 0M; if (notAuditMoney != null && notAuditMoney.Count() > 0) { waitMoney = notAuditMoney.Sum(c => c.Money + c.CounterFee); } if (waitMoney > balance) throw new BusinessException("专线余额不足,无法付款"); ////需检查专线欠票情况,如果当前时间-最早的一次请款时间>专线欠票周期 就不允许请款 //if (!this.ApplyBeforeValidateDebts(single.Special.ID)) // throw new BusinessException("专线已欠票,无法付款"); single.SerialNumber = model.SerialNumber; single.Remark = model.Remark; single.Status = PaymentStatus.HasPayment; single.AuditTime = DateTime.Now; single.AuditId = user.ID; single.AuditName = user.Name; TransactionScopeNoMsdtc.UsingTransactionNoMsdtc(this._db, () => { //增加资金池已付款(不要忘了付款手续费) special.SpecialCapital.Payment = special.SpecialCapital.Payment + payMoney; //减余额 special.SpecialCapital.Balance = special.SpecialCapital.Balance - payMoney; //查找机构下的'付款手续费'扣款类型ID var deduction = this._deductionRepository.GetModel().Where(c => c.BranchId == special.Branch.ID && c.Name == BusinessConst.PAYMENTFEENAME && c.Status).SingleOrDefault(); if (deduction == null) throw new BusinessException("未设置'付款手续费'扣款类型"); //增加一条付款手续费的扣款记录 Debit debit = new Debit() { TypeId = deduction.ID, PaymentId = single.ID, SpecialId = single.Special.ID, Money = single.CounterFee, Remark = single.Remark, DebitorId = user.ID, DebitorName = user.Name, Time = DateTime.Now }; this._paymentRepository.Update(single); this._specialMainRepository.Update(special); this._debitRepository.Insert(debit); }); }
/// <summary> /// 废弃 /// </summary> /// <param name="model"></param> public void ToAbandonedPayment(PaymentConAbaViewModel model) { #region valid var user = this.ValidIsBranch(model.Sys_LoginUserID); if (!string.IsNullOrWhiteSpace(model.SerialNumber)) { if (!model.SerialNumber.ValidateLen(100)) throw new DataValidationException("银行流水号长度在1-100个字符"); } if (string.IsNullOrWhiteSpace(model.Remark)) throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "付款备注")); var single = this._paymentRepository.GetModelTracking().Where(c => c.ID == model.ID).SingleOrDefault(); if (single == null) throw new BusinessException("付款信息不存在"); if (single.Status == PaymentStatus.Discard) throw new BusinessException("付款信息已被废弃"); #endregion single.SerialNumber = model.SerialNumber; single.Remark = model.Remark; single.Status = PaymentStatus.Discard; single.AuditTime = DateTime.Now; single.AuditId = user.ID; single.AuditName = user.Name; this._paymentRepository.Update(single); }