@loginValid
def pay_order(request):
    '\n    get请求 商品详情页购买单个商品。传入商品id，数量。\n    post请求 购物车购买多个商品。\n    '
    if (request.method == 'GET'):
        num = request.GET.get('num')
        id = request.GET.get('id')
        if (num and id):
            num = int(num)
            id = int(id)
            order = PayOrder()
            order.order_number = str(time.time()).replace('.', '')
            order.order_date = datetime.datetime.now()
            order.order_user = LoginUser.objects.get(id=int(request.COOKIES.get('user_id')))
            order.save()
            good = Goods.objects.get(id=id)
            order_info = OrderInfo()
            order_info.order_id = order
            order_info.goods_id = good.id
            order_info.goods_picture = good.goods_picture
            order_info.goods_name = good.goods_name
            order_info.goods_count = num
            order_info.goods_price = good.goods_price
            order_info.goods_total_price = round((good.goods_price * num), 3)
            order_info.store_id = good.goods_store
            order_info.order_status = 0
            order_info.save()
            order.order_total = order_info.goods_total_price
            order.save()
    elif (request.method == 'POST'):
        request_data = []
        data = request.POST
        data_item = request.POST.items()
        for (key, value) in data_item:
            if key.startswith('check_'):
                id = int(key.split('_', 1)[1])
                num = int(data.get(('count_' + str(id))))
                request_data.append((id, num))
        if request_data:
            order = PayOrder()
            order.order_number = str(time.time()).replace('.', '')
            order.order_date = datetime.datetime.now()
            order.order_user = LoginUser.objects.get(id=int(request.COOKIES.get('user_id')))
            order.order_total = 0.0
            order.goods_number = 0
            order.save()
            for (id, num) in request_data:
                good = Goods.objects.get(id=id)
                order_info = OrderInfo()
                order_info.order_id = order
                order_info.goods_id = good.id
                order_info.goods_picture = good.goods_picture
                order_info.goods_name = good.goods_name
                order_info.goods_count = num
                order_info.goods_price = good.goods_price
                order_info.goods_total_price = round((good.goods_price * num), 3)
                order_info.store_id = good.goods_store
                order_info.order_status = 0
                order_info.save()
                order.order_total += order_info.goods_total_price
                order.goods_number += 1
            order.save()
    return render(request, 'buyer/place_order.html', locals())
get请求 商品详情页购买单个商品。传入商品id，数量。
post请求 购物车购买多个商品。
@loginValid
def pay_order(request):
    '\n    get请求 商品详情页购买单个商品。传入商品id，数量。\n    post请求 购物车购买多个商品。\n    '
    if (request.method == 'GET'):
        num = request.GET.get('num')
        id = request.GET.get('id')
        if (num and id):
            num = int(num)
            id = int(id)
            order = PayOrder()
            order.order_number = str(time.time()).replace('.', )
            order.order_date = datetime.datetime.now()
            order.order_user = LoginUser.objects.get(id=int(request.COOKIES.get('user_id')))
            order.save()
            good = Goods.objects.get(id=id)
            order_info = OrderInfo()
            order_info.order_id = order
            order_info.goods_id = good.id
            order_info.goods_picture = good.goods_picture
            order_info.goods_name = good.goods_name
            order_info.goods_count = num
            order_info.goods_price = good.goods_price
            order_info.goods_total_price = round((good.goods_price * num), 3)
            order_info.store_id = good.goods_store
            order_info.order_status = 0
            order_info.save()
            order.order_total = order_info.goods_total_price
            order.save()
    elif (request.method == 'POST'):
        request_data = []
        data = request.POST
        data_item = request.POST.items()
        for (key, value) in data_item:
            if key.startswith('check_'):
                id = int(key.split('_', 1)[1])
                num = int(data.get(('count_' + str(id))))
                request_data.append((id, num))
        if request_data:
            order = PayOrder()
            order.order_number = str(time.time()).replace('.', )
            order.order_date = datetime.datetime.now()
            order.order_user = LoginUser.objects.get(id=int(request.COOKIES.get('user_id')))
            order.order_total = 0.0
            order.goods_number = 0
            order.save()
            for (id, num) in request_data:
                good = Goods.objects.get(id=id)
                order_info = OrderInfo()
                order_info.order_id = order
                order_info.goods_id = good.id
                order_info.goods_picture = good.goods_picture
                order_info.goods_name = good.goods_name
                order_info.goods_count = num
                order_info.goods_price = good.goods_price
                order_info.goods_total_price = round((good.goods_price * num), 3)
                order_info.store_id = good.goods_store
                order_info.order_status = 0
                order_info.save()
                order.order_total += order_info.goods_total_price
                order.goods_number += 1
            order.save()
    return render(request, 'buyer/place_order.html', locals())