/// <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);
        }
        /// <summary>
        /// 描述:休学办理
        /// <para>作    者:瞿琦</para>
        /// <para>创建时间:2018-11-7</para>
        /// </summary>
        /// <param name="iRequest">休学的相关数据</param>
        /// <param name="companyId">公司编号</param>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:8,异常描述:没有要休学的课程
        /// </exception>
        public override void Transact(IRefundOrderTransactRequest iRequest, string companyId)   //
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_AMSSCHOOLSTUDENT, base._schoolId, base._studentId.ToString()))
            {
                var request = iRequest as LeaveSchoolOrderAddRequest;
                //获取学生课次费用明细
                var courseLessonList = base.GetCourseLessonList(request.LeaveTime, companyId);

                if (!courseLessonList.Any()) //如果订单课程已休学则获取不到学生课次费用明细,则抛出异常
                {
                    throw new BussinessException(ModelType.Order, 8);
                }

                using (var unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        unitOfWork.BeginTransaction();
                        //1.写入退费订单主表                      --休学订单表
                        var refundOrder = AddOdrRefundOrder(request, courseLessonList, unitOfWork);
                        //2.写入退费订单课程明细
                        AddOdrRefundOrdeEnroll(courseLessonList, refundOrder, unitOfWork);
                        //3.写入休学表详细信息表
                        var leaveSchoolOrder = AddOdrLeaveSchoolOrder(request, courseLessonList, refundOrder, unitOfWork);
                        //4.添加附件
                        AddAttachment(request, leaveSchoolOrder, unitOfWork);
                        //5、课次调用
                        LeaveSchoolLessonFinisher leaveSchoolFinisher = new LeaveSchoolLessonFinisher(refundOrder, leaveSchoolOrder, unitOfWork);
                        LessonService             lessonService       = new LessonService(unitOfWork);
                        lessonService.Finish(leaveSchoolFinisher);//课次销毁
                        //6、资金调用
                        LeaveSchoolOrderTrade orderTrade = new LeaveSchoolOrderTrade(refundOrder);
                        TradeService          trade      = new TradeService(orderTrade, unitOfWork);
                        trade.Trade();
                        //7、修改课程明细表为休学状态
                        EnrollOrderService service = new EnrollOrderService(this._schoolId);
                        var enrollOrderItemIdList  = courseLessonList.Select(x => x.EnrollOrderItemId).ToList();
                        service.ChangeToLeaveSchool(enrollOrderItemIdList, unitOfWork).Wait();
                        //8.修改学生状态
                        var studentService = new StudentService(this._schoolId);
                        studentService.UpdateStudentStatusById(this._studentId, unitOfWork, StudyStatus.Suspension);

                        unitOfWork.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.RollbackTransaction();
                        throw ex;
                    }
                }
            }
        }
        /// <summary>
        /// 余额退费办理
        /// <para>作    者:郭伟佳</para>
        /// <para>创建时间:2018-11-08</para>
        /// </summary>
        /// <param name="iRequest">退费订单办理数据</param>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:
        /// 15. 转出余额不足
        /// 23. 该学生已经没有余额可退
        /// </exception>
        public override void Transact(IRefundOrderTransactRequest iRequest, string companyId)
        {
            var refundRequest = iRequest as BalanceRefundOrderRequest;

            //1、数据校验
            CheckBeforeTransact(refundRequest);

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                try
                {
                    unitOfWork.BeginTransaction(System.Data.IsolationLevel.Snapshot);

                    //2、保存退费订单信息
                    var refundOrderId             = IdGenerator.NextId();
                    TblOdrRefundOrder refundOrder = AddRefundOrder(unitOfWork, refundRequest, refundOrderId).Result;

                    //3、保存余额退费的其他费用信息
                    AddRefundOrderCost(unitOfWork, refundRequest, refundOrderId);

                    //4、保存余额退费上传的附件
                    AddAttachment(unitOfWork, refundRequest.AttachmentUrlList, refundOrderId);

                    //5、保存余额退费的支付信息
                    AddRefundPay(unitOfWork, refundRequest, refundOrderId);

                    //6、资金调用
                    BalanceOrderTrade orderTrade = new BalanceOrderTrade(refundOrder, "余额退费");
                    TradeService      trade      = new TradeService(orderTrade, unitOfWork);
                    trade.Trade();

                    unitOfWork.CommitTransaction();
                }
                catch (Exception ex)
                {
                    unitOfWork.RollbackTransaction();
                    throw ex;
                }
            }
        }
        /// <summary>
        /// 添加订金
        /// <para>作     者:Huang GaoLiang </para>
        /// <para>创建时间:2018-10-30 </para>
        /// </summary>
        /// <param name="request">订金充值实体</param>
        /// <param name="payeeId">收银人编号</param>
        /// <param name="payeeName">收银人</param>
        /// <returns>返回订金编号</returns>

        public string Add(DepositOrderAddRequest request, string payeeId, string payeeName)
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_DEPOSITORDERADD, this._schoolId, request.StudentId.ToString()))
            {
                // 1、数据合法性校验
                Verification(request);

                long depositOrderId = IdGenerator.NextId();

                // 2、准备数据
                TblOdrDepositOrder odrDepositOrder = this.SetOdrDepositOrder(request, payeeId, payeeName, depositOrderId);

                // 3、资金调用
                DepositOrderTrade orderTrade = new DepositOrderTrade(odrDepositOrder);

                // 4、添加事务
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        unitOfWork.BeginTransaction();

                        TradeService tradeService = new TradeService(orderTrade, unitOfWork);
                        tradeService.Trade();

                        unitOfWork.GetCustomRepository <TblOdrDepositOrderRepository, TblOdrDepositOrder>().AddTask(odrDepositOrder).Wait();

                        unitOfWork.CommitTransaction();
                        return(depositOrderId.ToString());
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.RollbackTransaction();
                        throw ex;
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 描述:办理
        /// <para>作    者:瞿琦</para>
        /// <para>创建时间:2018-11-8</para>
        /// </summary>
        /// <param name="iRequest">要退费的信息</param>
        /// <param name="companyId">公司编号</param>
        /// <returns>无</returns>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:22,异常描述:找不到可退班的订单课程
        /// 异常ID:20,异常描述:该订单课程已退班退费
        /// </exception>
        public override void Transact(IRefundOrderTransactRequest iRequest, string companyId)
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_AMSSCHOOLSTUDENT, this._schoolId, this._studentId.ToString()))
            {
                var request       = iRequest as LeaveClassOrderAddRequest;
                var vailteRequest = EnrollOrderService.GetEnrollOrderItemIdByEnroOrderList(request.RefundCourseLesson);
                if (!request.RefundCourseLesson.Any())
                {
                    throw new BussinessException((byte)ModelType.Order, 22);
                }
                if (vailteRequest.Any(x => x.Status != OrderItemStatus.Enroll))  //如果订单课程不是已报名,则抛出异常
                {
                    throw new BussinessException((byte)ModelType.Order, 20);
                }

                //获取要退班的课次
                var courseLessonList = base.GetCourseLessonList(request.LeaveTime, companyId).Where(x => request.RefundCourseLesson.Contains(x.EnrollOrderItemId)).ToList();
                if (!courseLessonList.Any()) //如果要退费的订单课程为空,则抛出异常
                {
                    throw new BussinessException((byte)ModelType.Order, 22);
                }

                using (var unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        unitOfWork.BeginTransaction();
                        //1.退费订单
                        var tblOdrRefundOrder = AddOdrRefundOrder(request, courseLessonList, unitOfWork);
                        //2.退费订单课程明细
                        AddOdrRefundOrdeEnroll(courseLessonList, tblOdrRefundOrder, unitOfWork);
                        //3.其他费用
                        AddOdrRefundOrderCost(request, tblOdrRefundOrder, unitOfWork);
                        //4.支付信息
                        AddOdrRefundPay(request, tblOdrRefundOrder, unitOfWork);
                        //5.退班详细信息
                        var tblOdrLeaveClassOrder = AddOdrLeaveClassOrder(request, tblOdrRefundOrder, unitOfWork);
                        //6.添加附件
                        AddAttachment(request, tblOdrRefundOrder, unitOfWork);

                        //7、课次调用
                        LeaveClassLessonFinisher leaveSchoolFinisher = new LeaveClassLessonFinisher(tblOdrRefundOrder, tblOdrLeaveClassOrder, request.RefundCourseLesson, unitOfWork);
                        LessonService            lessonService       = new LessonService(unitOfWork);
                        lessonService.Finish(leaveSchoolFinisher);//课次销毁


                        //8、资金调用
                        LeaveClassOrderTrade orderTrade = new LeaveClassOrderTrade(tblOdrRefundOrder, request.RefundType);
                        TradeService         trade      = new TradeService(orderTrade, unitOfWork);
                        trade.Trade();

                        //9、修改为退班状态
                        EnrollOrderService service = new EnrollOrderService(this._schoolId);
                        var enrollOrderItemIdList  = courseLessonList.Select(x => x.EnrollOrderItemId).ToList();
                        service.ChangeToLeaveClass(enrollOrderItemIdList, unitOfWork).Wait();

                        //10.修改学生状态
                        var studentService = new StudentService(this._schoolId);
                        studentService.UpdateStudentStatusById(this._studentId, unitOfWork);

                        unitOfWork.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.RollbackTransaction();
                        throw;
                    }
                }
            }
        }