/// <summary>
        /// 申请发票
        /// </summary>
        /// <param name="invoice"></param>
        /// <param name="operateUserId"></param>
        public void ApplyInvoice(InvoiceViewModel invoice, int operateUserId)
        {
            var loginUser = RedisHelp.GetLoginUserCacheNotNull(operateUserId);
            #region 安全验证
            if (loginUser.Type == UserType.Company)
            {
                throw new DataOperationPermissions("无此操作权限,总公司账号不能操作发票");
            }
            else if (loginUser.Type == UserType.Branch)
            {
                throw new DataOperationPermissions("无此操作权限,分社账号不能申请发票");
            }
            else if (loginUser.Type == UserType.SpecialLine)
            {
                if (loginUser.SpecialId.HasValue && loginUser.SpecialId != invoice.SpecialId)
                {
                    throw new DataOperationPermissions("无此操作权限,专线只能申请自己的发票");
                }
            }
            #endregion
            #region 数据验证
            if (invoice.Money <= 0)
                throw new DataValidationException("发票金额不能小于等于0");
            if (string.IsNullOrEmpty(invoice.Content))
                throw new DataValidationException("发票详细不能为空");
            if (!invoice.Content.ValidateLen(500))
                throw new DataValidationException("发票详细填写过多,请分批申请");
            if (invoice.ParValueTime < DateTime.Parse("1753-01-01"))
                throw new DataValidationException("请填写正确的票面日期");
            #endregion
            #region 欠款判断

            var special = _specialRepository.GetModel().Include(p => p.SpecialCapital)
                .Include(p => p.Branch)
                .SingleOrDefault(p => p.ID == invoice.SpecialId);
            if (special == null)
                throw new BusinessException("专线不存在");
            if (special.Status == SpecialStatus.Freeze)
            {
                throw new BusinessException("所属专线已被冻结");
            }
            if (special.Status == SpecialStatus.AccountCancellation)
            {
                throw new BusinessException("所属专线已被销户");
            }
            //专线已开票+当前开票+当前专线所有待审核金额总数-专线已收款>=专线欠款最大额度
            //得到当前专线所有待审核金额总数
            var sumMoney = _invoiceRepository.GetModel(p => p.SpecialId == special.ID && p.Status == InvoiceStatus.WaitInvoice).Sum(s => (decimal?)s.Money) ?? 0;
            if (special.SpecialCapital.InvoiceSend + invoice.Money + sumMoney - special.SpecialCapital.Gathering >= special.Branch.ArrearsTotal)
            {
                throw new BusinessException("你提交发票金额已超出设置的最大欠款额度,暂时不能提交发票申请");
            }
            #endregion

            Invoice model = new Invoice();

            model.Status = InvoiceStatus.WaitInvoice;
            model.SpecialId = invoice.SpecialId;
            model.SpecialName = special.Name;

            model.SellerId = invoice.SellerId;
            model.Title = invoice.SellerSupplier.Name;
            model.ParValueTime = invoice.ParValueTime;
            model.Money = invoice.Money;
            model.Content = invoice.Content;
            model.ApplicantId = loginUser.ID;
            model.ApplicantName = loginUser.Name;
            model.ApplicationTime = DateTime.Now;

            _invoiceRepository.Insert(model);
        }
        /// <summary>
        /// 判断此服务中方法中的数据权限
        /// 总公司     :   无权限
        /// 分社       :   查看列表(自己下属数据)、审核发票(自己下属数据)、得到发票详细(只能查看自己下属数据)
        /// 专线       :   申请发票(自己属在专线)、查看列表(自己所在专线)
        /// 超级管理员 :   所有权限(所有数据)
        /// </summary>
        /// <param name="operateUserId"></param>
        /// <param name="invoice"></param>
        private void BuidDataAuthorityVerify(int operateUserId, Invoice invoice)
        {
            var loginUser = RedisHelp.GetLoginUserCacheNotNull(operateUserId);

            if (loginUser.Type == UserType.Company)
            {
                throw new DataOperationPermissions("无此访问权限,总公司账号不能查看发票");
            }//分社 查看 他下属所有专线的发票申请
            else if (loginUser.Type == UserType.Branch)
            {
                if (loginUser.BranchId != invoice.Special.BranchId)
                {
                    throw new DataOperationPermissions("无此访问权限,分社账号只能查看他下属所有专线发票申请");
                }
            }//专线 查看 他自己的发票申请
            else if (loginUser.Type == UserType.SpecialLine)
            {
                if (loginUser.ID == invoice.SpecialId)
                {
                    throw new DataOperationPermissions("无此访问权限,专线账号只能查看自身所在专线发票申请");
                }
            }
        }