/// <summary>
        /// 申请付款
        /// </summary>
        /// <param name="model"></param>
        public void ToApplyPayment(PaymentApplyViewModel model)
        {
            #region valid
            var user = this.ValidIsSpecial(model.Sys_LoginUserID);
            if (model.SupplierID <= 0)
                throw new DataValidationException("请选择供应商");
            if (model.IsEntrust)
            {
                if (string.IsNullOrWhiteSpace(model.Payee))
                    throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "收款人姓名"));
                else
                    if (!model.Payee.ValidateLen(20))
                        throw new DataValidationException("收款人姓名长度在1-20个字符");

                if (string.IsNullOrWhiteSpace(model.BankNumber))
                    throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "收款人银行帐号"));
                else
                    if (!model.BankNumber.ValidateLen(20))
                        throw new DataValidationException("收款人银行帐号长度在1-20个字符");

                if (string.IsNullOrWhiteSpace(model.CollectionBank))
                    throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "银行名称"));
                else
                    if (!model.CollectionBank.ValidateLen(30))
                        throw new DataValidationException("银行名称长度在1-30个字符");

                if (model.EntrustAttachments == null || model.EntrustAttachments.Count() <= 0)
                    throw new DataValidationException("请上传委托附件");
                if (model.CounterFee <= 0)
                    throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "付款手续费"));
            }
            if (model.Moeny <= 0)
                throw new DataValidationException(string.Format(BusinessResourceMessage.PleaseInput, "付款金额"));

            var supplier = this._sellerSupplierRepository.GetModel().Where(c => c.ID == model.SupplierID).SingleOrDefault();
            if (supplier == null)
                throw new DataValidationException("供应商不存在");
            if (!supplier.Status)
                throw new DataValidationException("供应商状态异常");
            #endregion

            //付款信息
            var payment = new Payment()
            {
                SpecialId = user.Special.ID,
                SupplyId = model.SupplierID,
                Type = PaymentType.General,
                Status = PaymentStatus.WaitVerify,
                Payee = supplier.ChargeName,
                CollectionBank = supplier.Bank,
                BankNumber = supplier.ChargeBankNumber,
                Money = model.Moeny,
                ApplicantId = user.ID,
                ApplicationTime = DateTime.Now,
                SpecialName = user.Special.Name,
                ApplicantName = user.Name
            };

            //委托付款
            if (model.IsEntrust)
            {
                payment.Type = PaymentType.Entrust;
                payment.CounterFee = model.CounterFee;
                payment.PaymentEntrust = new List<PaymentEntrust>();
                payment.PaymentEntrust.Add(new PaymentEntrust()
                {
                    Payee = model.Payee,
                    CollectionBank = model.CollectionBank,
                    BankNumber = model.BankNumber,
                    Attachments = new List<Attachment>()
                });
                model.EntrustAttachments.ForEach((e) =>
                {
                    payment.PaymentEntrust[0].Attachments.Add(new Attachment()
                    {
                        Address = e.Item2,
                        CreateTime = DateTime.Now,
                        Name = e.Item1,
                        Type = AttachmentType.PaymentDelegateAttachment,
                        Suffix = e.Item1.Substring(e.Item1.LastIndexOf('.'), e.Item1.Length - e.Item1.LastIndexOf('.'))
                    });
                });
            }

            //计算付款手续费 付款手续费=付款金额*付款手续费率
            var special = this._specialMainRepository.GetModel().Include(c => c.Branch).Include(c => c.SpecialCapital).Where(c => c.ID == user.Special.ID).SingleOrDefault();
            string cf = string.Format("{0:F2}", model.Moeny * (special.Branch.CounterFeeRate / 100));
            payment.CounterFee = decimal.Parse(cf);

            //如果付款金额加上付款手续费大于余额减掉毛利就不能提交申请
            var payMoney = model.Moeny + model.CounterFee;
            var balance = special.SpecialCapital.Balance - special.SpecialCapital.Profit;
            //也需要加上未审核的付款申请总金额
            var notAuditMoney = this._paymentRepository.GetModel(c => c.SpecialId == special.ID && c.Status == PaymentStatus.WaitVerify).ToList();
            var waitMoney = 0M;
            if (notAuditMoney != null && notAuditMoney.Count() > 0)
            {
                waitMoney = notAuditMoney.Sum(c => c.Money + c.CounterFee);
            }
            if ((payMoney + waitMoney) > balance)
                throw new BusinessException("余额不足,无法申请付款");

            //需检查专线欠票情况,如果当前时间-最早的一次请款时间>专线欠票周期 就不允许请款
            if (!this.ApplyBeforeValidateDebts(user.Special.ID))
                throw new BusinessException("专线已欠票,无法申请付款");

            this._paymentRepository.Insert(payment);
        }
        public DataResult DetailCollectInvoice(Payment inputPayment)
        {
            #region 角色验证
            //if (LoginUser.Type != 0 && LoginUser.Type != UserType.SpecialLine)
            //{
            //	throw new DataOperationPermissions(BusinessResourceMessage.NoPower);
            //}
            #endregion

            #region 输入验证
            if (inputPayment.ID == 0)
                throw new DataValidationException(string.Format(BusinessResourceMessage.Inexistent, "付款发票"));
            #endregion

            dataResult.Code = ResponseStatusCode.Success;
            dataResult.Msg = BusinessResourceMessage.Success;
            dataResult.Data = collectinvoiceService.DetailCollectInvoice(inputPayment.ID);
            return dataResult;
        }