public bool Recharge(int id, int money, LoginModel loginModel) { bool res = true; try { Repository <student> studentModuleDal = _unitOfWork.GetRepository <student>(); Repository <student_recharge_detail> rechargeDal = _unitOfWork.GetRepository <student_recharge_detail>(); student studententity = studentModuleDal.GetObjectByKey(id).Entity; if (studententity != null) { //更新 studententity.remaining_balance = studententity.remaining_balance + money; _unitOfWork.AddAction(studententity, DataActions.Update); //新增学员费用交易流水 student_recharge_detail srd = new student_recharge_detail(); srd.student_id = id; srd.amount = money; srd.inout_type = 1; srd.incur_time = DateTime.Now; srd.recharge_user = loginModel.UserCode; _unitOfWork.AddAction(srd, DataActions.Add); _unitOfWork.Save(); } else { res = false; throw new FaultException <LCFault>(new LCFault("学员充值失败"), "该学员不存在,无法充值"); } return(res); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } }
public bool UnCheckStudent(int scheduleId, int studentId, LoginModel loginModel) { bool res = true; try { //获取学生签到状态 Repository <status> statusDal = _unitOfWork.GetRepository <status>(); IEnumerable <status> attendanceStatus = statusDal.Find(s => s.cat == "attendance").Entities; int attendedStatus = attendanceStatus.Single(s => s.description == "Attended").id; int excusedStatus = attendanceStatus.Single(s => s.description == "Excused absence").id; //获取排课信息 Repository <class_schedule> scheduleDal = _unitOfWork.GetRepository <class_schedule>(); class_schedule scheduleentity = scheduleDal.GetObjectByKey(scheduleId).Entity; int price = scheduleentity.wclass.parentClassTypes.unit_price; //获取学生信息 Repository <student> studentDal = _unitOfWork.GetRepository <student>(); Repository <student_recharge_detail> srdDal = _unitOfWork.GetRepository <student_recharge_detail>(); student st = studentDal.GetObjectByKey(studentId).Entity; //学生剩余金额返还 st.remaining_balance = st.remaining_balance + price; _unitOfWork.AddAction(st, DataActions.Update); //更新课程记录明细状态该学生未参加 List <class_record_detail> crds = scheduleentity.classrecords.First().class_record_detail.ToList(); int crdid = 0; foreach (class_record_detail crd in crds) { if (crd.attendance_status == 1006 && crd.student_id == studentId) { crd.attendance_status = excusedStatus; crdid = crd.class_record_detail_id; _unitOfWork.AddAction(crd, DataActions.Update); break; } } //课程记录减少一个实际参加学生人数 class_record cr = scheduleentity.classrecords.First(); //设置实际收费综合,根据实际到课人数计算 cr.student_number = cr.student_number - 1; cr.actual_amount = cr.student_number * price; //设置提成金额基数,如果实际到课人数低于计算下限人数,则按照下限人数计算 if (cr.student_number < cr.student_limit) { cr.amount_receivable = cr.student_limit * price; } else { cr.amount_receivable = cr.student_number * price; } _unitOfWork.AddAction(cr, DataActions.Update); //删除学生扣款记录 //根据学生编号以及上课记录明细找到对应记录 student_recharge_detail srd = srdDal.FindEntity(sr => sr.student_id == studentId && sr.class_record_detail_id == crdid).FirstOrDefault(); _unitOfWork.AddAction(srd, DataActions.Delete); _unitOfWork.Save(); } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } return(res); }
public bool DeleteById(int id) { bool res = true; try { Repository <class_schedule> scheduleDal = _unitOfWork.GetRepository <class_schedule>(); class_schedule scheduleEntity = scheduleDal.GetObjectByKey(id).Entity; if (scheduleEntity != null) { if (scheduleEntity.classrecords.Count > 0 && scheduleEntity.classrecords.First().is_checked == 1) { throw new FaultException <LCFault>(new LCFault("删除课程失败"), "该课程已上课并结算,无法删除"); } else { if (scheduleEntity.classrecords.Count > 0) { Repository <student> studentDal = _unitOfWork.GetRepository <student>(); Repository <student_recharge_detail> srdDal = _unitOfWork.GetRepository <student_recharge_detail>(); Repository <class_record_detail> crdDal = _unitOfWork.GetRepository <class_record_detail>(); List <class_record_detail> crds = crdDal.Find(cr => cr.class_record_id == scheduleEntity.classrecords.First().class_record_id).Entities.ToList(); //先将本来签到的学生金额回滚 foreach (class_record_detail crd in crds) { if (crd.attendance_status == 1006) { //删除该学员扣款记录并回滚金额 student_recharge_detail srd = srdDal.Single(ss => ss.class_record_detail_id == crd.class_record_detail_id).Entity; student s = studentDal.GetObjectByKey(crd.student_id).Entity; s.remaining_balance = s.remaining_balance + crd.class_record.class_schedule.wclass.parentClassTypes.unit_price; _unitOfWork.AddAction(srd, DataActions.Delete); _unitOfWork.AddAction(s, DataActions.Update); } //删除上课明细 _unitOfWork.AddAction(crd, DataActions.Delete); } } _unitOfWork.AddAction(scheduleEntity, DataActions.Delete); _unitOfWork.Save(); } } else { res = false; throw new FaultException <LCFault>(new LCFault("删除课程失败"), "该课程不存在,无法删除"); } } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } return(res); }
public bool CheckStudent(int scheduleId, List <int> studentIds, LoginModel loginModel) { bool res = true; try { //获取学生签到状态 Repository <status> statusDal = _unitOfWork.GetRepository <status>(); IEnumerable <status> attendanceStatus = statusDal.Find(s => s.cat == "attendance").Entities; int attendedStatus = attendanceStatus.Single(s => s.description == "Attended").id; int excusedStatus = attendanceStatus.Single(s => s.description == "Excused absence").id; //获取排课信息 Repository <class_schedule> scheduleDal = _unitOfWork.GetRepository <class_schedule>(); class_schedule scheduleentity = scheduleDal.GetObjectByKey(scheduleId).Entity; int price = scheduleentity.wclass.parentClassTypes.unit_price; classes wclass = scheduleentity.wclass; if (scheduleentity != null) { if (scheduleentity.classrecords == null || scheduleentity.classrecords.Count == 0) { //尚未有上课记录,说明还没有上课学生信息 Repository <class_record> recordDal = _unitOfWork.GetRepository <class_record>(); class_record cr = new class_record(); cr.schedule_id = scheduleId; //设置学生下限计算值,用于教师提成金额核算 cr.student_limit = wclass.parentClassTypes.student_limit; //设置教师信息和教师提成比例 cr.teacher_id = scheduleentity.teacher_id; cr.teacher_check_rate = wclass.parentClassTypes.commission_rate_teacher; //设置学生实际点到数量 cr.student_number = studentIds.Count; cr.is_checked = 0; //如果有助教设置,则设置助教信息和助教提成比例 if (scheduleentity.assistant_id.HasValue && scheduleentity.assistant_id.Value != 0) { cr.assistant_id = scheduleentity.assistant_id.Value; cr.assistant_check_rate = wclass.parentClassTypes.commission_rate_assistant; cr.assistant_is_checked = 0; } //设置实际收费综合,根据实际到课人数计算 cr.actual_amount = studentIds.Count * price; //设置提成金额基数,如果实际到课人数低于计算下限人数,则按照下限人数计算 if (studentIds.Count < cr.student_limit) { cr.amount_receivable = cr.student_limit * price; } else { cr.amount_receivable = studentIds.Count * price; } foreach (student st in scheduleentity.wclass.students) { //班级所有学员建立上课明细,默认为没有参加课程 class_record_detail crd = new class_record_detail(); //上课明细记录中学生点到状态设置为没有参加 crd.attendance_status = excusedStatus; //设置该学员会籍顾问提成比例,如果有会籍顾问,则设置会籍顾问相关信息 if (st.consultant_check_rate == 0) { crd.consultant_check_rate = wclass.parentClassTypes.commission_rate_consultant; } else { crd.consultant_check_rate = st.consultant_check_rate; } if (st.consultants.Count > 0) { crd.consultants_id = st.consultants.First().consultant_id; } crd.student_id = st.student_id; if (studentIds.Contains(st.student_id)) { //如果该学员在签到列表中,则需要更新状态为参加课程状态 crd.attendance_status = attendedStatus; //学员上课,需要扣减学员剩余金额 st.remaining_balance = st.remaining_balance - price; _unitOfWork.AddAction(st, DataActions.Update); //更行学员充值消费记录流水信息 student_recharge_detail srd = new student_recharge_detail(); srd.student_id = st.student_id; srd.amount = price; srd.inout_type = -1; srd.incur_time = DateTime.Now; srd.recharge_user = loginModel.UserCode; crd.student_recharge_detail.Add(srd); } cr.class_record_detail.Add(crd); } //该班级课程数量扣减一次,如果班级课程数量为0,则该班级进入锁定状态 wclass.last_count = wclass.last_count - 1; if (wclass.last_count == 0) { wclass.is_active = false; } _unitOfWork.AddAction(wclass, DataActions.Update); _unitOfWork.AddAction(cr, DataActions.Add); } else { Repository <student> studentDal = _unitOfWork.GetRepository <student>(); Repository <class_record_detail> classrecordDal = _unitOfWork.GetRepository <class_record_detail>(); //有上课信息,则需要更新上课学生信息 class_record cr = scheduleentity.classrecords.First(); cr.actual_amount = studentIds.Count * price; cr.student_number = studentIds.Count; if (cr.student_number < cr.student_limit) { //如果上课总数小于下限,则按照下限设定收费金额 cr.amount_receivable = cr.student_limit * price; } List <int> crdstids = new List <int>(); foreach (class_record_detail crd in cr.class_record_detail) { crdstids.Add(crd.student_id); //处理所有已经在列表但是未check的学员 if (studentIds.Contains(crd.student_id) && crd.attendance_status != attendedStatus) { if (cr.student_number > cr.student_limit) { //增加一个学员收费进入该堂课程总额 cr.amount_receivable += price; } //签到学生原有明细记录为没有上课,标明是后来点到,则需要更新学员信息 student st = studentDal.GetObjectByKey(crd.student_id).Entity; st.remaining_balance = st.remaining_balance - price; _unitOfWork.AddAction(st, DataActions.Update); class_record_detail crdd = classrecordDal.GetObjectByKey(crd.class_record_detail_id).Entity; crdd.attendance_status = attendedStatus; //同时需要更新学员充值消费记录流水信息 student_recharge_detail srd = new student_recharge_detail(); srd.student_id = st.student_id; srd.amount = price; srd.inout_type = -1; srd.incur_time = DateTime.Now; srd.recharge_user = loginModel.UserCode; crdd.student_recharge_detail.Add(srd); _unitOfWork.AddAction(crdd, DataActions.Update); } } //if (studentIds.Count > crdstids.Count) //{ foreach (int studentId in studentIds) { if (!crdstids.Contains(studentId)) { //原理记录不包含学员id,则需要新增记录 class_record_detail crd = new class_record_detail(); crd.attendance_status = attendedStatus; student st = studentDal.GetObjectByKey(studentId).Entity; st.remaining_balance = st.remaining_balance - price; //设置该学员会籍顾问提成比例,如果有会籍顾问,则设置会籍顾问相关信息 if (st.consultant_check_rate == 0) { crd.consultant_check_rate = wclass.parentClassTypes.commission_rate_consultant; } else { crd.consultant_check_rate = st.consultant_check_rate; } _unitOfWork.AddAction(st, DataActions.Update); //同时需要更新学员充值消费记录流水信息 student_recharge_detail srd = new student_recharge_detail(); srd.student_id = st.student_id; srd.amount = price; srd.inout_type = -1; srd.incur_time = DateTime.Now; srd.recharge_user = loginModel.UserCode; crd.student_recharge_detail.Add(srd); if (st.consultants.Count > 0) { crd.consultants_id = st.consultants.First().consultant_id; } crd.student_id = st.student_id; if (cr.student_number > cr.student_limit) { //增加一个学员收费进入该堂课程总额 cr.amount_receivable += price; } cr.class_record_detail.Add(crd); } } //} _unitOfWork.AddAction(cr, DataActions.Update); } _unitOfWork.Save(); } } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException <LCFault> (new LCFault(msg), reason); } return(res); }