/// <summary>
        /// 作废定金
        /// <para>作     者::Huang GaoLiang  </para>
        /// <para>创建时间:2018-10-30 </para>
        /// </summary>
        /// <param name="orderId">订金编号</param>
        /// <param name="cancelUserId">作废人操作编号</param>
        /// <param name="cancelUserName">作废人名称</param>
        /// <param name="cancelRemark">作废原因</param>
        /// <exception cref="BussinessException">
        /// 异常ID:5,数据异常
        /// 异常ID:8,余额不足,不能作废
        /// </exception>
        public override Task Cancel(long orderId, string cancelUserId, string cancelUserName, string cancelRemark)
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_DEPOSITORDERCANCEL, this._schoolId, orderId.ToString()))
            {
                // 根据订金编号查询订金信息
                TblOdrDepositOrder odrDepositOrder = _odrDepositOrderRepository.Value.GetOdrDepositOrder(orderId);

                if (odrDepositOrder == null)
                {
                    throw new BussinessException((byte)ModelType.Cash, 5);
                }

                // 1、数据校验
                OdrDepositOrderCancelVerification(odrDepositOrder);

                // 2、准备数据
                odrDepositOrder.OrderStatus    = (int)OrderStatus.Cancel;
                odrDepositOrder.CancelDate     = DateTime.Now;
                odrDepositOrder.CancelUserId   = cancelUserId;
                odrDepositOrder.CancelUserName = cancelUserName;
                odrDepositOrder.CancelRemark   = cancelRemark;

                // 3、作废之后,余额扣除掉相应的金额
                bool isWalletSufficient = WalletService.IsWalletSufficient(_schoolId, odrDepositOrder.StudentId, odrDepositOrder.Amount);

                if (!isWalletSufficient)
                {
                    throw new BussinessException((byte)ModelType.Cash, 8);
                }

                DepositOrderTrade orderTrade = new DepositOrderTrade(odrDepositOrder);

                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        unitOfWork.BeginTransaction();

                        // 1、资金交易
                        TradeService tradeService = new TradeService(orderTrade, unitOfWork);
                        tradeService.Invalid();

                        // 2、订金
                        unitOfWork.GetCustomRepository <TblOdrDepositOrderRepository, TblOdrDepositOrder>().UpdateTask(odrDepositOrder).Wait();

                        // 3、收款交接
                        new OrderHandoverService(_schoolId).DeleteHandleOver(orderId, OrderTradeType.DepositOrder, unitOfWork);

                        unitOfWork.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.RollbackTransaction();
                        throw ex;
                    }
                }
            }
            return(Task.CompletedTask);
        }
Пример #2
0
        /// <summary>
        /// 检查学生余额是否足够
        /// </summary>
        /// <param name="schoolId">校区ID</param>
        /// <param name="studentId">学生ID</param>
        /// <param name="useBalanceAmount">将要使用的余额金额</param>
        /// <returns>true 足够 false 不足</returns>
        internal static bool IsWalletSufficient(string schoolId, long studentId, decimal useBalanceAmount)
        {
            if (useBalanceAmount <= 0)
            {
                return(true);
            }
            WalletService service = new WalletService(schoolId, studentId);

            return(service.IsWalletSufficient(useBalanceAmount));
        }