/// <summary>
        /// 描述:根据退费订单的Id获取退费订单的课程明细
        /// <para>作    者:瞿  琦</para>
        /// <para>创建时间:2018-12-20</para>
        /// </summary>
        /// <param name="refundOrderId">退费订单表Id</param>
        /// <param name="companyId">公司编号</param>
        /// <returns>休学订单课程明细</returns>
        internal static List <RefundOrderTransactDetailListResponse> GetRefundCourseAmountDetail(long refundOrderId, string companyId)
        {
            //获取所有的课程信息
            var courseList = CourseService.GetAllAsync().Result;
            //获取所有的学期类型
            var termTypeList = new TermTypeService().GetAll();
            //获取所有的课程级别集合
            var courseLevelList = new CourseLevelService(companyId).GetList().Result;

            var refundCourseList        = new TblOdrRefundOrdeEnrollRepository().GetRefundOrderByOrderEnroll(refundOrderId);
            var leaveSchoolCourseIdList = refundCourseList.Select(x => x.EnrollOrderItemId);

            var courseOrderDetailList = EnrollOrderService.GetEnrollOrderItemIdByEnroOrderList(leaveSchoolCourseIdList);
            var refundCourseDetail    = new List <RefundOrderTransactDetailListResponse>();

            foreach (var item in courseOrderDetailList)
            {
                var refundCourseInfo = refundCourseList.FirstOrDefault(k => k.EnrollOrderItemId == item.EnrollOrderItemId);
                //获取上课课次
                var haveClassLesson = refundCourseInfo?.UseLessonCount ?? 0;
                //获取扣除费用
                var deductAmount = haveClassLesson * (item.MaterialFee + item.TuitionFee);
                //获取休学/退班课次
                var leaveSchoolLessons = refundCourseInfo?.LessonCount ?? 0;
                //获取退费金额
                var refundAmount = refundCourseInfo?.Amount ?? 0;

                var entity = new RefundOrderTransactDetailListResponse
                {
                    Year               = item.Year,
                    TermTypeId         = item.TermTypeId,
                    TermTypeName       = termTypeList.FirstOrDefault(k => k.TermTypeId == item.TermTypeId)?.TermTypeName,
                    EnrollOrderItemId  = item.EnrollOrderItemId,
                    CourseId           = item.CourseId,
                    CourseName         = courseList.FirstOrDefault(k => k.CourseId == item.CourseId)?.CourseCnName,
                    CourseLevelId      = item.CourseLevelId,
                    CourseLevelName    = courseLevelList.FirstOrDefault(k => k.CourseLevelId == item.CourseLevelId)?.LevelCnName,
                    ClassTimes         = item.ClassTimes,
                    PaidAmount         = item.PayAmount,
                    HaveClassLesson    = haveClassLesson,    //上课课次
                    DeductAmount       = deductAmount,       //扣除费用
                    LeaveSchoolLessons = leaveSchoolLessons, //休学/退班课次
                    RefundAmount       = refundAmount,       //退费金额
                    TuitionFee         = item.TuitionFee,
                    MaterialFee        = item.MaterialFee,
                    DiscountFee        = item.DiscountFee,
                };
                refundCourseDetail.Add(entity);
            }

            return(refundCourseDetail);
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }