overdue_fix
This commit is contained in:
		
							parent
							
								
									89d17f1ba6
								
							
						
					
					
						commit
						04cc629988
					
				@ -22,6 +22,16 @@ def borrow_book():
 | 
			
		||||
        flash('请选择要借阅的图书', 'danger')
 | 
			
		||||
        return redirect(url_for('book.book_list'))
 | 
			
		||||
 | 
			
		||||
    # 检查用户当前借阅数量是否达到上限(5本)
 | 
			
		||||
    current_borrows_count = BorrowRecord.query.filter_by(
 | 
			
		||||
        user_id=current_user.id,
 | 
			
		||||
        status=1  # 1表示借阅中
 | 
			
		||||
    ).count()
 | 
			
		||||
 | 
			
		||||
    if current_borrows_count >= 5:
 | 
			
		||||
        flash('您当前已借阅5本图书,达到借阅上限。请先归还后再借阅新书。', 'warning')
 | 
			
		||||
        return redirect(url_for('book.book_detail', book_id=book_id))
 | 
			
		||||
 | 
			
		||||
    book = Book.query.get_or_404(book_id)
 | 
			
		||||
 | 
			
		||||
    # 检查库存
 | 
			
		||||
@ -101,6 +111,18 @@ def add_borrow(book_id):
 | 
			
		||||
    # 验证图书存在
 | 
			
		||||
    book = Book.query.get_or_404(book_id)
 | 
			
		||||
 | 
			
		||||
    # 检查用户当前借阅数量是否达到上限(5本)
 | 
			
		||||
    current_borrows_count = BorrowRecord.query.filter_by(
 | 
			
		||||
        user_id=current_user.id,
 | 
			
		||||
        status=1  # 1表示借阅中
 | 
			
		||||
    ).count()
 | 
			
		||||
 | 
			
		||||
    if current_borrows_count >= 5:
 | 
			
		||||
        return jsonify({
 | 
			
		||||
            'success': False,
 | 
			
		||||
            'message': '您当前已借阅5本图书,达到借阅上限。请先归还后再借阅新书。'
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
    # 默认借阅天数
 | 
			
		||||
    borrow_days = 14
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,7 @@ def inventory_list():
 | 
			
		||||
 | 
			
		||||
@inventory_bp.route('/adjust/<int:book_id>', methods=['GET', 'POST'])
 | 
			
		||||
@login_required
 | 
			
		||||
@permission_required('manage_inventory')  # 替代 @admin_required
 | 
			
		||||
@permission_required('manage_inventory')
 | 
			
		||||
def adjust_inventory(book_id):
 | 
			
		||||
    """调整图书库存"""
 | 
			
		||||
    book = Book.query.get_or_404(book_id)
 | 
			
		||||
 | 
			
		||||
@ -118,6 +118,8 @@ def api_borrow_trend():
 | 
			
		||||
    """获取借阅趋势数据API"""
 | 
			
		||||
    time_range = request.args.get('time_range', 'month')
 | 
			
		||||
 | 
			
		||||
    now = datetime.now()
 | 
			
		||||
 | 
			
		||||
    # 记录获取借阅趋势数据的日志
 | 
			
		||||
    Log.add_log(
 | 
			
		||||
        action="获取数据",
 | 
			
		||||
@ -150,8 +152,8 @@ def api_borrow_trend():
 | 
			
		||||
 | 
			
		||||
            # 当天逾期未还的数量
 | 
			
		||||
            overdue_count = BorrowRecord.query.filter(
 | 
			
		||||
                BorrowRecord.due_date < day_end,
 | 
			
		||||
                BorrowRecord.return_date.is_(None)
 | 
			
		||||
                BorrowRecord.return_date.is_(None),  # 未归还
 | 
			
		||||
                BorrowRecord.due_date < now  # 应还日期早于当前时间
 | 
			
		||||
            ).count()
 | 
			
		||||
 | 
			
		||||
            results.append({
 | 
			
		||||
@ -186,9 +188,10 @@ def api_borrow_trend():
 | 
			
		||||
            ).count()
 | 
			
		||||
 | 
			
		||||
            # 当天逾期未还的数量
 | 
			
		||||
            now = datetime.now()
 | 
			
		||||
            overdue_count = BorrowRecord.query.filter(
 | 
			
		||||
                BorrowRecord.due_date < day_end,
 | 
			
		||||
                BorrowRecord.return_date.is_(None)
 | 
			
		||||
                BorrowRecord.return_date.is_(None),
 | 
			
		||||
                BorrowRecord.due_date < now
 | 
			
		||||
            ).count()
 | 
			
		||||
 | 
			
		||||
            results.append({
 | 
			
		||||
@ -231,9 +234,10 @@ def api_borrow_trend():
 | 
			
		||||
            ).count()
 | 
			
		||||
 | 
			
		||||
            # 当月逾期未还的数量
 | 
			
		||||
            now = datetime.now()
 | 
			
		||||
            overdue_count = BorrowRecord.query.filter(
 | 
			
		||||
                BorrowRecord.due_date < month_end,
 | 
			
		||||
                BorrowRecord.return_date.is_(None)
 | 
			
		||||
                BorrowRecord.return_date.is_(None),
 | 
			
		||||
                BorrowRecord.due_date < now
 | 
			
		||||
            ).count()
 | 
			
		||||
 | 
			
		||||
            results.append({
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user