예제 #1
0
def indent_ok(request):
    try:
        username = request.session.get('username')
        if '@' in username:
            user_id = TUser.objects.filter(username=username)[0].id
        else:
            user_id = TUser.objects.filter(phone_number=username)[0].id
        order = TOrder.objects.filter(user_id=user_id, status=0)
        order_number = order[0].order_number
        total_price = order[0].total_price
        books_number = order[0].torderdetail_set.all().aggregate(books_number=Sum('books_number'))['books_number']
        address = TAddress.objects.filter(id=order[0].address_id)[0]
        books = Cart()
        for order_detail in TOrderDetail.objects.filter(order_id=order[0].id):
            books.add_shopping_cart(order_detail.book_id, order_detail.books_number)
        order[0].status = 1
        order[0].save()
        return render(request, 'order/indent ok.html', {
            'username': username,
            'order_number': order_number,
            'total_price': total_price,
            'books_number': books_number,
            'address': address,
            'books': books.book_items
        })
    except Exception as error:
        print(error)
        return HttpResponse('哎呀!服务器出错了~')
예제 #2
0
def indent_page(request):
    try:
        username = request.session.get('username')
        if '@' in username:
            user_id = TUser.objects.filter(username=username)[0].id
        else:
            user_id = TUser.objects.filter(phone_number=username)[0].id
        address = TAddress.objects.filter(user_id=user_id)
        cart = TShoppingCart.objects.filter(user_id=user_id)
        order = Cart()
        for book in cart:
            order.add_shopping_cart(book.book_id, book.quantity)
        total_price = 0
        for book in order.book_items:
            total_price += book.total_price
        request.session['total_price'] = total_price
        request.session['order'] = order
        return render(request, 'order/indent.html', {
            'username': username,
            'address': address,
            'total_price': total_price,
            'order': order,
        })
    except Exception as error:
        print(error)
        return HttpResponse('哎呀!服务器出错了~')
예제 #3
0
def shopping_cart(request):
    try:
        username = request.session.get('username')
        if request.session.get('login_status'):
            if '@' in username:
                user_id = TUser.objects.filter(username=username)[0].id
            else:
                user_id = TUser.objects.filter(phone_number=username)[0].id
            books = TShoppingCart.objects.filter(user_id=user_id)
            cart = Cart()
            for book in books:
                cart.add_shopping_cart(book.book_id, book.quantity)
        else:
            cart = request.session.get('cart')
        return render(request, 'cart/car.html', {
            'username': username,
            'cart': cart
        })
    except Exception as error:
        print(error)
        return HttpResponse('哎呀!服务器出错了~')