/// <summary> /// 添加学生现金券 /// </summary> /// <param name="studentId"></param> /// <param name="cashVoucherId"></param> /// <param name="gotType"></param> /// <param name="gotReferId"></param> /// <returns></returns> private int AddStudentCashVoucher(int studentId, int cashVoucherId, VoucherGotTypeEnum gotType, int gotReferId) { var cashVoucher = CashVoucherRepository.Get(cashVoucherId); Yw_StudentCashVoucher studentCashVoucher = new Yw_StudentCashVoucher(); studentCashVoucher.Ysv_CashVoucherId = cashVoucher.Ycv_Id; studentCashVoucher.Ysv_StudentId = studentId; studentCashVoucher.Ysv_VoucherNo = GetVoucherNo(cashVoucher.Ycv_Id, studentId, cashVoucher.Ycv_VoucherType); studentCashVoucher.Ysv_VoucherType = cashVoucher.Ycv_VoucherType; if (cashVoucher.Ycv_ExpireType == (int)ExpireTypeEnum.截止日期) { studentCashVoucher.Ysv_ExpireDate = cashVoucher.Ycv_ExpireDate; } else if (cashVoucher.Ycv_ExpireType == (int)ExpireTypeEnum.固定天数) { studentCashVoucher.Ysv_ExpireDate = DateTime.Now.AddDays(cashVoucher.Ycv_ExpireDayCount); } else if (cashVoucher.Ycv_ExpireType == (int)ExpireTypeEnum.长期有效) { studentCashVoucher.Ysv_ExpireDate = "3000-01-01"._ToDateTime(); } studentCashVoucher.Ysv_GotType = (int)gotType; studentCashVoucher.Ysv_GotReferId = gotReferId; studentCashVoucher.Ysv_UsedType = 0; studentCashVoucher.Ysv_UsedReferId = 0; studentCashVoucher.Ysv_UsedReferNo = ""; studentCashVoucher.Ysv_TakenTime = DateTime.Now; studentCashVoucher.Ysv_Status = (int)StudentCashVoucherStatusEnum.未使用; studentCashVoucher.Ysv_UsedTime = "1900-01-01"._ToDateTime(); studentCashVoucher.Ysv_UpdateTime = DateTime.Now; return(StudentCashVoucherRepository.Add(studentCashVoucher)); }
/// <summary> /// 领取现金券(添加) /// </summary> /// <param name="studentId"></param> /// <param name="cashVoucherId"></param> /// <param name="gotType">现金券获取方式</param> /// <param name="gotReferId">现金券获取关联Id</param> /// <returns></returns> public bool TakeStudentCashVoucher(int studentId, int cashVoucherId, VoucherGotTypeEnum gotType, int gotReferId) { using (TransactionScope scope = new TransactionScope()) { try { StudentBll studentBll = new Bll.StudentBll(); var student = studentBll.StudentRepository.Get(studentId); if (student != null) { //查询学生是否已经拥有该现金券 if (!StudentCashVoucherRepository.StudentIsHaveCashVoucher(studentId, cashVoucherId)) { //修改现金券已领取数量 int result = CashVoucherRepository.UpdateCashVoucherTakenCount(cashVoucherId, student.Bst_SchoolId); if (result > 0) { //添加学生现金券 int studentCashVoucherId = AddStudentCashVoucher(studentId, cashVoucherId, gotType, gotReferId); //添加现金券领取记录 // AddStudentGetCashVoucher(studentId, cashVoucherId); } else { throw new AbhsException(ErrorCodeEnum.NotCashVoucherCount, AbhsErrorMsg.ConstNotCashVoucherCount); } } else { throw new AbhsException(ErrorCodeEnum.AlreadyHaveCashVoucher, AbhsErrorMsg.ConstAlreadyHaveCashVoucher); } } scope.Complete(); return(true); } catch (Exception ex) { RollbackTran(); throw ex; } } }