/// <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));
        }
        /// <summary>
        /// 发起交易并使交易进入冻结
        /// </summary>
        internal override void Trade()
        {
            TradeInfo tradeInfo = base._tradeInfo;

            // 1、添加一笔交易记录
            this.AddTradeFroze();

            //2、扣除余额并冻结
            WalletService service = new WalletService(tradeInfo.SchoolId, Convert.ToInt64(tradeInfo.Buyer), base._unitOfWork);

            service.TradeFroze(_orderTrade.TradeType, tradeInfo.OrderId, tradeInfo.TradeBalanceAmount, tradeInfo.Remark);
        }
예제 #4
0
        /// <summary>
        /// 作废交易,从已完成的订单产生一笔作废交易
        /// caiyakang 2018-10-06
        /// </summary>
        internal override void Invalid()
        {
            base.AddTradeInvalid();//写入交易表
            TradeInfo tradeInfo = base._tradeInfo;

            //余额服务不关心订单新增或订单取消,应由交易服务业务来决定如何调余额服务
            if (tradeInfo.TradeBalanceAmount != 0)
            {
                WalletService walltService = new WalletService(tradeInfo.SchoolId, Convert.ToInt64(tradeInfo.Buyer), base._unitOfWork);
                walltService.Trade(GetCancelTradeType(this._orderTrade.TradeType), tradeInfo.OrderId, -tradeInfo.TradeBalanceAmount, tradeInfo.Remark);
            }
        }
예제 #5
0
        /// <summary>
        /// 发起交易并使交易完成
        /// </summary>
        internal override void Trade()
        {
            base.AddTradeComplete();//写入交易表
            TradeInfo tradeInfo = base._tradeInfo;

            //余额交易
            if (tradeInfo.TradeBalanceAmount != 0)
            {
                WalletService walltService = new WalletService(tradeInfo.SchoolId, Convert.ToInt64(tradeInfo.Buyer), base._unitOfWork);
                walltService.Trade(this._orderTrade.TradeType, tradeInfo.OrderId, tradeInfo.TradeBalanceAmount, tradeInfo.Remark);
            }
        }
        /// <summary>
        /// 取消交易,从交易中的订单取消
        /// </summary>
        internal override void Cancel()
        {
            TradeInfo tradeInfo = base._tradeInfo;

            //1、处理交易单
            base.UpdateTradeCancel();

            //2、处理余额
            //余额服务不关心订单新增或订单取消,应由交易服务业务来决定如何调余额服务
            if (tradeInfo.TradeBalanceAmount != 0)
            {
                WalletService walltService = new WalletService(tradeInfo.SchoolId, Convert.ToInt64(tradeInfo.Buyer), base._unitOfWork);
                walltService.TradeFrozeCancel(base._orderTrade.TradeType, base.GetCancelTradeType(base._orderTrade.TradeType), tradeInfo.OrderId, tradeInfo.Remark);
            }
        }
        /// <summary>
        /// 数据校验
        /// <para>作    者:郭伟佳</para>
        /// <para>创建时间:2018-12-05</para>
        /// </summary>
        /// <param name="refundRequest">余额退费请求对象</param>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:
        /// 15. 转出余额不足
        /// 23. 该学生已经没有余额可退
        /// </exception>
        private void CheckBeforeTransact(BalanceRefundOrderRequest refundRequest)
        {
            //1、获取学生的余额信息
            decimal balance = new WalletService(this._schoolId, this._studentId, null).Balance;

            //检查用户是否还有余额
            if (balance == 0)
            {
                throw new BussinessException((byte)ModelType.Order, 23);
            }
            //检查用户余额是否足够转出
            if (refundRequest.RefundAmount > balance)
            {
                throw new BussinessException((byte)ModelType.Order, 15);
            }
        }
        /// <summary>
        /// 更新交易完成状态
        /// </summary>
        internal void TradeComplete()
        {
            TradeInfo         tradeInfo = base._tradeInfo;
            TblCashOrderTrade entity    = _tradeRepository.Value.GetByOrderId(tradeInfo.SchoolId, tradeInfo.OrderId, tradeInfo.OrderNo);

            if (entity.TradeStatus == (int)TradeStatus.Trading)
            {
                entity.TradeStatus = (int)TradeStatus.Complete;
                entity.Remark      = _tradeInfo.Remark;
            }
            //1、操作交易完成
            _tradeRepository.Value.Update(entity);

            //2、操作余额冻结完成
            WalletService service = new WalletService(tradeInfo.SchoolId, Convert.ToInt64(tradeInfo.Buyer), base._unitOfWork);

            service.TradeFrozeComplete(_orderTrade.TradeType, tradeInfo.OrderId);
        }