def save_balance_change(self, vc, student_user, parent_user, student_amount, balance_reason, account_balance): BalanceChange.save_balance_change( BalanceChange.CHILDREN, student_user.id, vc.id, balance_reason, student_amount, parent_user_id=parent_user.id, adviser_user_id=parent_user.adviser_user_id, xg_user_id=parent_user.xg_user_id, balance_id=account_balance.id)
def add_student_fbc(self, vc, students, reason): for student in students: parent_user = student.parent_user BalanceChange.save_balance_change( BalanceChange.CHILDREN, student.id, vc.id, reason, 0, parent_user_id=parent_user.id, adviser_user_id=parent_user.adviser_user_id, xg_user_id=parent_user.xg_user_id, balance_id=None)
def compensation_student(self, vc, students, student_amount, account_class): for student in students: parent_user = student.parent_user account_balance = self.create_account( parent_user, AccountBalance.ACTIVITY_AMOUNT, account_class) BalanceChange.save_balance_change( BalanceChange.CHILDREN, student.id, vc.id, BalanceChange.NO_SHOW_COMPENSATION, student_amount, parent_user_id=parent_user.id, adviser_user_id=parent_user.adviser_user_id, xg_user_id=parent_user.xg_user_id, balance_id=account_balance.id) return True
def check_exception(self, request, pk): try: result = int(request.data.get('result')) student_amount = Decimal(request.data.get('student_amount', 0)) teacher_amount = Decimal(request.data.get('teacher_amount', 0)) description = request.data.get('description', None) if student_amount > 200 or student_amount < 0: raise ArithmeticError('参数超出范围') if teacher_amount > 200 or teacher_amount < 0: raise ArithmeticError('参数超出范围') except Exception as e: logger.error(e) return JsonResponse(code=1, msg='参数错误', status=status.HTTP_200_OK) try: vc = VirtualclassInfo.objects.get(id=pk) if vc.reason == VirtualclassInfo.NORMAL and vc.status == VirtualclassInfo.FINISH_NOMAL: return JsonResponse(code=1, msg='该课堂正常结束,不能审核', status=status.HTTP_200_OK) except ObjectDoesNotExist as e: return JsonResponse(code=1, msg='该课堂不存在', status=status.HTTP_200_OK) user = request.session.get('user') logger.debug( 'check_exception, operator:{}, result:{}, student_amount:{}, teacher_amount:{}, description:{}, virtual_class_id:{}' .format(user.get('id'), result, student_amount, teacher_amount, description, pk)) now_time = timezone.now() members = vc.virtual_class_member.all() students = [member.student_user for member in members] teacher = vc.tutor_user vc_exception = VirtualclassException.objects.filter( virtual_class_id=vc.id).first() if vc_exception: return JsonResponse(code=1, msg='该条数据已审核,请勿重复审核', status=status.HTTP_200_OK) account_balance_change = BalanceChange.objects.filter( reason__in=( BalanceChange.ABSENCE_PENALTY, # 学生缺席罚金 BalanceChange.NO_SHOW_COMPENSATION, # 导师不出席对学生的补偿 BalanceChange.ABSENCE_COMPENSATION, # 学生缺席老师奖励 BalanceChange.NO_SHOW_PENALTY, # 老师缺席罚金 ), reference=vc.id).all() if len(account_balance_change) > 1: return JsonResponse(code=1, msg='该条数据已审核,请勿重复审核', status=status.HTTP_200_OK) vc_exception = VirtualclassException() vc_exception.result = result vc_exception.description = description vc_exception.cms_user_id = request.session.get('user').get('id') vc_exception.virtual_class_id = vc.id exchange = ExchangeRate.objects.filter( currency='CNY', valid_start__lt=now_time, valid_end__gte=now_time).first() account_class = AccountBalance.NORMAL_ACCOUNT class_type_price = ClasstypePrice.objects.filter( class_type_id=vc.class_type_id, course_edition_id=vc.lesson.course.course_edition.id).first() if class_type_price: account_class = class_type_price.account_class if result == VirtualclassException.STUDENT_ABSENCE: # 学生缺席 '''学生缺席,对老师进行补偿,对学生进行扣款''' vc.reason = VirtualclassInfo.STUDENT_ABSENCE vc.status = VirtualclassInfo.FINISH_ABNOMAL vc.save() if student_amount: student_amount = 0 - (student_amount / exchange.rate) self.absence_penalty(vc, students, student_amount, account_class) else: self.add_student_fbc(vc, students, BalanceChange.ABSENCE_PENALTY) teacher_amount = teacher_amount / exchange.rate BalanceChange.save_balance_change( BalanceChange.TEACHER, teacher.id, vc.id, BalanceChange.ABSENCE_COMPENSATION, teacher_amount) elif result == VirtualclassException.TEACHER_ABSENCE: # 老师缺席 '''老师缺席,对学生进行补偿,对老师进行扣款''' vc.reason = VirtualclassInfo.TUTOR_ABSENCE vc.status = VirtualclassInfo.FINISH_ABNOMAL vc.save() if student_amount: student_amount = student_amount / exchange.rate self.compensation_student(vc, students, student_amount, account_class) else: self.add_student_fbc(vc, students, BalanceChange.NO_SHOW_COMPENSATION) teacher_amount = 0 - (teacher_amount / exchange.rate) BalanceChange.save_balance_change(BalanceChange.TEACHER, teacher.id, vc.id, BalanceChange.NO_SHOW_PENALTY, teacher_amount) elif result == VirtualclassException.TEACHER_AND_STUDENT_ABSENCE: # 老师学生都缺席 '''老师学生都缺席,对学生老师进行扣款''' vc.status = VirtualclassInfo.FINISH_ABNOMAL vc.reason = VirtualclassInfo.CLASS_NOONE vc.save() teacher_amount = 0 - (teacher_amount / exchange.rate) BalanceChange.save_balance_change(BalanceChange.TEACHER, teacher.id, vc.id, BalanceChange.NO_SHOW_PENALTY, teacher_amount) if student_amount: student_amount = 0 - (student_amount / exchange.rate) self.absence_penalty(vc, students, student_amount, account_class) else: self.add_student_fbc(vc, students, BalanceChange.ABSENCE_PENALTY) vc_exception.save() return JsonResponse(code=0, msg='success', status=status.HTTP_200_OK)