Beispiel #1
0
def myorder_add(request):
    orders = Orders()
    try:
        user = Users.objects.get(id=request.session['user']['id'])
        orders.uid = user
    except:
        context = {"info": "请重新登录!"}
        return render(request, 'myweb/info.html', context)
    # try:
    #     for goods in request.session['order_gids']:
    #         order_goods = Goods.objects.get(id = goods)
    #         orders.goods.add(order_goods)
    # except Exception as e:
    #     print(e)
    #     return render(request,'myweb/info.html',{'info':'订单商品不存在!'})
    orders.linkman = request.POST.get('linkman')
    orders.address = request.POST.get('address')
    orders.code = request.POST.get('code')
    orders.phone = request.POST.get('phone')
    orders.price = request.POST.get('total')
    orders.save()

    order_list = request.session['order_list']
    for og in order_list:
        od = Order_detail()
        od.order_id = orders.id
        od.goods_id = og
        od.goods_num = order_list[og]['num']
        print('order_id:' + str(od.order_id) + 'goods_id:' + str(od.goods_id) +
              'goods_num:' + str(od.goods_num))
        od.save()

    return redirect(reverse('myorder_indent'))
Beispiel #2
0
def ordercreate(request):
    # 接受用户id
    uid = request.session['VipUser']['uid']
    # 接受地址id
    addressid = request.POST['addressid']
    # 商品信息
    data = request.session['order']
    # 获取购物车中的数据
    cart = request.session['cart']
    # 生成订单
    ob = Orders()
    ob.uid = Users.objects.get(id=uid)
    ob.addressid = Address.objects.get(id=addressid)
    ob.totalprice = data['totalprice']
    ob.totalnum = data['totalnum']
    ob.save()
    # 订单详情
    for v in data['items']:
        oinfo = OrderInfo()
        oinfo.orderid = ob
        oinfo.gid = Goods.objects.get(id=v['goodsid'])
        oinfo.num = v['num']
        oinfo.save()
        # 在购物车中删除当前购买的商品
        del cart[v['goodsid']]
    # 清楚购物车中已经下单的商品,清楚order数据
    request.session['cart'] = cart
    request.session['order'] = ''
    # 把生成订单id 请求到一个新的付款页面
    return HttpResponse('<script>location.href="/buy/?orderid=' + str(ob.id) +
                        '"</script>')
Beispiel #3
0
def createorder(request):
    aid = request.POST['addrid']
    uid = request.session['User']['uid']
    data = request.session['order']
    cart = request.session['cart']

    ob = Orders()
    ob.uid = Users.objects.get(id=uid)
    ob.addressid = Address.objects.get(id=aid)
    ob.tolprice = data['tolprice']
    ob.tolnum = data['tolnum']
    ob.save()

    for i in data['items']:
        obinfo = OrderInfo()
        obinfo.orderid = ob
        obinfo.gid = Goods.objects.get(id=i['gid'])
        obinfo.num = i['gnum']
        obinfo.save()
        del cart[i['gid']]
        request.session['count'] -= 1

    request.session['cart'] = cart
    request.session['order'] = ''

    return HttpResponse('<script>location.href="/pay/?orderid=' + str(ob.id) +
                        '"</script>')
Beispiel #4
0
def ordercreate(request):

    # 接受用户id
    uid = request.session['VipUser']['uid']
    # 收货地址id
    addressid = request.POST['addressid']

    # 商品信息
    data = request.session['order']

    # 获取购物车中的数据
    cart = request.session['cart']

 

    '''
        {
            '4': {'price': 9.9, 'num': 2, 'id': 4, 'title': '小蛋糕真好吃:23', 'pics': '/static/pics/1530080135.535089758178.jpg'}, 
            '22': {'price': 9.9, 'num': 3, 'id': 22, 'title': '小蛋糕真好吃:24', 'pics': '/static/pics/1530080135.535089758178.jpg'}, 
            '3': {'price': 1999.99, 'num': 1, 'id': 3, 'title': '小蛋糕真好吃:22', 'pics': '/static/pics/1530080135.535089758178.jpg'}
        }


    '''


    # 生成订单
    ob = Orders()
    ob.uid = admin.objects.get(id=uid)
    ob.addressid = Address.objects.get(id=addressid)
    ob.totalprice = data['totalprice']
    ob.totalnum = data['totalnum']
    ob.save()

     # 'items': [
     # {'price': 1999.99, 'pics': '/static/pics/1530080135.535089758178.jpg', 'num': 1, 'title': '小蛋糕真好吃:22', 'goodsid': '3'}, 
     # {'price': 9.9, 'pics': '/static/pics/1530080135.535089758178.jpg', 'num': 3, 'title': '小蛋糕真好吃:24', 'goodsid': '22'}
     # ]

    # .订单详情
    for v in data['items']:
     
        oinfo = OrderInfo()
        oinfo.orderid = ob
        oinfo.gid = Goods.objects.get(id=v['goodsid'])
        oinfo.num = v['num']
        oinfo.save()
        # 在购物车中删除当前购买的商品
        del cart[v['goodsid']]


    # 清除购物车中已经下单的商品,清除order数据
    request.session['cart'] = cart
    request.session['order'] = ''

    # 把生成订单id get请求到一个新的付款页面

    return HttpResponse('<script>location.href="/buy/?orderid='+str(ob.id)+'"</script>')
Beispiel #5
0
def centersdel(request, uid):
    order = Orders()
    lists = Orders.objects.filter(id=uid).update(status='1')
    # status=Orders.objects.filter().values('status')
    # print(status)
    # ob = Orders.objects.get(id=uid)
    # print(ob.status)
    # # ob.status=1
    # # order.save()
    # print(uid)
    # lists=Orders.objects.filter()
    # lists.status=1
    # lists.save()
    lists = Orders.objects.filter()
    print(order.status)

    # order.id=request.POST['uid']
    # for i in lists:
    #     print(i.id,'ididdi')
    #     print(i.status,'准备改')
    #     print(uid,'uid')
    #     if i.id == int(uid):
    #         i.status=1
    #         print(i.status,'为什么')
    # for k in lists:
    #     if k.id == int(uid):
    #         print(k.status,'改后的值')
    leng = len(lists)
    wei = 0
    yi = 0
    qu = 0

    for i in lists:
        time_local = time.localtime(i.addtime)
        i.addtime = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
        if i.status == 0:
            wei += 1
        if i.status == 1:
            yi += 1
        if i.status == 2:
            qu += 1
    context = {'lists': lists, 'leng': leng, 'wei': wei, 'yi': yi, 'qu': qu}
    # ob = Orders.objects.get(id=uid)
    # print(ob.status)
    return render(request, 'myadmin/center.html', context)
    return render(request, 'myadmin/center.html', context)
Beispiel #6
0
def ordercreate(request):

    # 接收用户id
    uid = request.session['VipUser']['uid']

    # 收货地址id
    addressid = request.POST.get('addressid')

    # 商品信息
    data = request.session['order']

    # 获取购物车中的数据
    cart = request.session['cart']

    # 生成订单
    ob = Orders()
    ob.uid = Users.objects.get(id=uid)
    ob.addressid = Address.objects.get(id=addressid)
    ob.totalprice = float(data['totalprice'])
    ob.totalnum = data['totalnum']
    ob.save()

    # 订单详情
    for v in data['items']:
        oinfo = OrderInfo()
        oinfo.orderid = ob
        oinfo.gid = Goods.objects.get(id=v['goodsid'])
        oinfo.num = v['num']
        oinfo.save()
        # 在购物车中删除当前的商品
        del cart[v['goodsid']]

    # 清楚购物车中已经下单的商品 清楚order数据
    request.session['cart'] = cart
    request.session['order'] = ''
    print(ob.id)
    # 把生成订单id get请求到一个新的付款页面
    return HttpResponse(
        '<script>alert("订单生成成功");location.href="/buy/?orderid=' + str(ob.id) +
        '"</script>')
Beispiel #7
0
def ordersinsert(request):
    # 封装订单信息,并执行添加
    orders = Orders()
    orders.uid = Users.objects.get(name=request.session['yonghu']).id
    orders.linkman = request.POST['username']
    orders.address = request.POST['address']
    orders.code = request.POST['code']
    orders.phone = request.POST['phone']
    orders.addtime = time.time()
    orders.total = request.session['total']
    orders.status = 0
    orders.save()
    #获取订单详情
    orderlist = request.session['orderlist']
    shoplist = request.session['shoplist']

    #遍历购物信息,并添加订单详情信息
    for shop in orderlist.values():
        print(shop)
        detail = Detail()
        detail.orderid = orders.id
        detail.goodsid = shop['id']
        # detail.picname = shop['picname']
        detail.name = shop['goods']
        detail.price = shop['price']
        detail.num = shop['m']
        detail.save()
        shoplist.pop(str(shop['id']))
        request.session['shoplist'] = shoplist
    return redirect(reverse('ordersinfo'))
Beispiel #8
0
def createorder(request):
    ids = request.POST.get('ids', '').split(',')
    cart = request.session['cart']
    print('cartcreate', cart)
    totalprice = 0
    totalnum = 0
    for x in ids:
        print("cart[x]['price']", cart[x]['price'], type(cart[x]['price']))
        print("cart[x]['num']", cart[x]['num'], type(cart[x]['num']))
        totalprice += (cart[x]['price'] * cart[x]['num'])
        print('totalprice', totalprice)
        totalnum += cart[x]['num']
        print('totalnum', totalnum)

    od = Orders()
    # 收货信息
    od.uid = Users.objects.get(id=request.session['VipUser']['uid'])
    od.linkman = request.POST.get('linkman')
    od.address = request.POST.get('address')
    od.phone = request.POST.get('phone')
    od.code = request.POST.get('code')
    # 总价
    od.total = totalprice
    # 数量
    od.nums = totalnum
    # 状态
    od.status = 1
    # 打印测试
    # print('od.uid',od.uid,type(od.uid))
    # print('od.linkman',od.linkman,type(od.linkman))
    # print('od.address',od.address,type(od.address))
    # print('od.phone',od.phone,type(od.phone))
    # print('od.code',od.code,type(od.code))
    # print('od.totalprice',od.total,type(od.total))
    # print('od.nums',od.nums,type(od.nums))
    od.save()

    # 添加订单详情信息
    for x in ids:
        info = Detail()
        info.orderid = od
        info.goodsid = Goods.objects.get(id=x)
        info.num = cart[x]['num']
        info.name = cart[x]['goods']
        info.price = cart[x]['price']
        # 打印测试
        # print('info.orderid',info.orderid,type(info.orderid))
        # print('info.goodsid',info.goodsid,type(info.goodsid))
        # print('info.num',info.num,type(info.num))
        # print('info.price',info.price,type(info.price))
        info.save()
        # 删除购物车中对应的商品信息
        del cart[x]

    # 把购物车信息重新存入session中
    request.session['cart'] = cart
    # 跳转到付款页面
    return HttpResponse('<script>alert("下单成功");location.href="displayorder/' +
                        str(od.id) + '"</script>')
Beispiel #9
0
def myorderadd(request):
    # 封装订单信息,并执行添加
    orders = Orders()
    orders.uid = request.session['user']['id']
    orders.linkman = request.POST['linkman']
    orders.address = request.POST['address']
    orders.code = request.POST['code']
    orders.phone = request.POST['phone']
    orders.addtime = time.time()
    orders.total = request.session['total']
    orders.status = 0
    orders.save()
    # 获取订单详情
    orderlist = request.session['orderlist']
    shoplist = request.session['shoplist']
    # 遍历订单信息,添加订单信息
    for shop in orderlist.values():
        # print(shop)
        del shoplist[str(shop['id'])]
        detail = Detail()
        detail.orderid = orders.id
        detail.goodsid = shop['id']
        detail.name = shop['goods']
        detail.price = shop['price']
        detail.num = shop['m']
        detail.save()
    # 删除用户存在session中的值
    del request.session['orderlist']
    del request.session['total']
    request.session['shoplist'] = shoplist
    # return HttpResponse("订单成功:订单id号:"+str(orders.id))
    return redirect(reverse('indent'))