def ordersinsert(request): #封装订单信息,并执行添加 orders = Orders() orders.uid = request.session['vipuser']['id'] orders.linkman = request.POST.get('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(): 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() del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist del request.session['shoplist'] context = {'info': '订单成功: 订单id号:' + str(orders.id)} # return HttpResponse("订单成功:订单id号: "+str(orders.id)) return render(request, "myweb/shop/info.html", context)
def jiesuanadd(request): # 封装订单信息,并执行添加 orders = Orders() orders.uid = request.session['vipuser']['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'] #遍历购物信息,并添加订单详情信息 for shop in orderlist.values(): print(shop) detail = Detail() detail.orderid = orders.id detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['m'] detail.addtime = time.time() detail.picname = shop['picname'] detail.save() return redirect(reverse('xiangqin'))
def ordersinsert(request): #执行订单信息添加操作 try: od = Orders() # print(request.session['vipusers']['id']) a = request.session['vipusers']['id'] od.uid = request.session['vipusers']['id'] od.linkman = request.POST.get('linkman') od.address = request.POST.get('address') od.code = request.POST.get('code') od.phone = request.POST.get('phone') od.addtime = time.time() od.total = request.session['total'] od.status = 0 od.save() #执行订单详情添加操作 orderslist = request.session['orderslist'] shoplist = request.session['shoplist'] for shop in orderslist.values(): del shoplist[str(shop['id'])] ov = Detail() ov.orderid = od.id ov.goodsid = shop['id'] ov.name = shop['goods'] ov.price = shop['price'] ov.num = shop['m'] ov.save() del request.session['orderslist'] del request.session['total'] request.session['shoplist'] = shoplist return HttpResponse("订单添加成功! 订单号:"+str(od.id)) except: return HttpResponse("订单添加失败!")
def order_carry(request, cid): #订单数据库存储 user = Users.objects.get(id=cid) order = Orders() order.uid = user.id order.linkman = request.POST['name'] order.address = request.POST['address'] order.code = request.POST['code'] order.phone = request.POST['phone'] order.addtime = time.time() order.total = request.session['total'] order.status = 0 order.save() #订单详情数据库存储 orderlist = request.session['orderlist'] shoplist = request.session['shoplist'] for shop in orderlist.values(): del shoplist[str(shop['id'])] detail = Detail() detail.orderid = order.id detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['num'] detail.save() #删除购物车中已经购买的商品 del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist return redirect(reverse('myweb_order'))
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'))
def ordersinsert(request): print(request.path) # 封装订单信息,并执行添加 orders = Orders() orders.uid = request.session['vipuser']['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'] #遍历购物信息,并添加订单详情信息 for shop in orderlist.values(): print(shop) detail = Detail() detail.orderid = orders.id detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['m'] detail.save() lists = Orders.objects.filter() context = {'info': "订单成功:", "hao": str(orders.id), 'lists': lists} return render(request, 'myweb/info.html', context)
def orderinsert(request): orders = Orders() orders.uid = request.session['vipuser']['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(): 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() del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist return render(request, "myweb/shoporder.html")
def ordersinsert(request): orders = Orders() orders.uid = request.session['vipuser']['id'] orders.address = request.POST['address'] orders.linkman = request.POST['linkman'] 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(): del shoplist[str(shop['id'])] # print(shop) # print(request.session['shoplist']) # print(shoplist[str(shop['id'])]) # print(shoplist) detail = Detail() detail.orderid = orders.id detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['m'] detail.save() del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist # print(request.session.keys()) return redirect(reverse('ordersinfo'))
def orderxd(request): ord = Orders() ord.uid = request.session['uid'] ord.linkman = request.session['order_username'] ord.address = request.session['user_address'] ord.code = request.session['user_code'] ord.phone = request.session['user_phone'] ord.addtime = time.time() ord.total = request.session['total'] ord.save() # 获取订单详情 orderlist = request.session['orderlist'] shoplist = request.session['shoplist'] for shop in orderlist.values(): del shoplist[str(shop['id'])] det = Detail() det.orderid = ord.id det.goodsid = shop['id'] det.name = shop['goods'] det.price = shop['price'] det.num = shop['shop_num'] det.save() # 在购物车中删除以购买的商品 del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist return redirect(reverse('myorder'))
def shoporderinsert(request): #封装订单信息,并执行添加 orders = Orders() orders.uid = request.session['vipuser']['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(): 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() del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist # request render(request,"myweb/order.html") return HttpResponse("订单成功:订单id号:"+str(orders.id))
def ordersure(request): #取出订单信息 order = request.session["order"] total = order["total"] goods = order["goods"] getinfo = order["getinfo"] #商品库存判断 for g in goods: shop1 = Goods.objects.get(id=goods[g]['goodsid']) if goods[g]['gnum'] > shop1.store: info = False content = {'info': info} return JsonResponse(content) #取出购物车信息,以便删除订单中的商品 cartlist = request.session["cart"] try: #存入订单数据库 toorder = Orders() toorder.uid = request.session['userid'] toorder.linkman = getinfo['linkman'] toorder.address = getinfo['address'] toorder.code = getinfo['code'] toorder.phone = getinfo['phone'] toorder.addtime = time.strftime('%Y%m%d%H%M', time.localtime()) toorder.total = total toorder.status = 0 toorder.save() #存入详情库 for i in goods: todetail = Detail() todetail.orderid = toorder.id todetail.goodsid = goods[i]['goodsid'] todetail.name = goods[i]['goods'] todetail.price = goods[i]['price'] todetail.num = goods[i]['gnum'] todetail.save() #在购物车中删除订单中的商品 cartlist.pop(i, None) #改变商品的购买量 shop = Goods.objects.get(id=i) shop.num += todetail.num shop.store -= todetail.num shop.save() request.session["cart"] = cartlist del request.session['order'] info = True except: info = False content = {"info": info} return JsonResponse(content) #=========================end 订单=====================
def orderadd(request): # 订单表 ob = Orders() ob.uid = request.session['user']['id'] ob.linkman = request.session['user']['name'] ob.address = request.session['express']['address'] ob.code = request.session['express']['code'] ob.phone = request.session['express']['phone'] ob.addtime = time.time() ob.total = request.session['total'] ob.status = 0 ob.save() # 订单详情表 orderlist = request.session['orderlist'] print(orderlist) shoplist = request.session['shoplist'] print(shoplist) for i in orderlist: dd = Detail() dd.orderid = str(int(time.time())) + str( request.session['express']['code']) + str( request.session['user']['id']) goodsid = orderlist[i]['id'] dd.goodid = goodsid dd.name = orderlist[i]['goods'] dd.price = orderlist[i]['price'] dd.num = orderlist[i]['num'] dd.save() shoplist = {} shoplist = request.session['shoplist'] del shoplist[str(goodsid)] request.session['shoplist'] = shoplist # 加入到历史订单中 history = {} for i in orderlist: history[str(orderlist[i]['id'])] = orderlist[i] try: nbb = request.session['history'] for i in nbb: history[nbb[i]['id']] = nbb[i] request.session['history'] = history except: request.session['history'] = history return redirect(reverse('ordershow'))
def orderxd(request): ord = Orders() ord.uid = request.session['uid'] ord.linkman = request.session['order_username'] ord.address = request.session['user_address'] ord.code = request.session['user_code'] ord.phone = request.session['user_phone'] # 记录购买的商品情况 ord.goods = json.dumps(request.session['orderlist']) # 支付完成后 ord.status = 2 ord.addtime = time.time() ord.total = request.session['total'] ord.save() # 添加库存 - 新增 goods_list = json.loads(ord.goods) for good_id, good_info in goods_list.items(): store_room = Store() store_room.uid = ord.uid store_room.good_id = good_id store_room.price = good_info['price'] store_room.number = good_info['shop_num'] store_room.addtime = time.time() store_room.save() # 获取订单详情 orderlist = request.session['orderlist'] shoplist = request.session['shoplist'] for shop in orderlist.values(): del shoplist[str(shop['id'])] det = Detail() det.orderid = ord.id det.goodsid = shop['id'] det.name = shop['goods'] det.price = shop['price'] det.num = shop['shop_num'] det.save() # 在购物车中删除以购买的商品 del request.session['orderlist'] del request.session['total'] request.session['shoplist'] = shoplist return redirect(reverse('myorder'))
def ordersinsert(request): context = loadinfo() #封装订单信息,并执行添加 buytime = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%I:%S")) orders = Orders() orders.uid = request.session['vipuser']['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.POST['total'] orders.status = 0 orders.save() #获取订单详情 orderlist = request.session['orderlist'] shoplist = request.session['shoplist'] #遍历购物信息,并添加订单详情信息 for shop in orderlist.values(): del shoplist[str(shop['id'])] detail = Detail() detail.orderid = orders.id print(shop['id']) detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['m'] detail.save() request.session['shoplist'] = shoplist context = { 'buytime': buytime, 'ordersid': int(orders.addtime), 'orderlist': request.session['orderlist'], 'total': request.session['total'] } del request.session['orderlist'] del request.session['total'] return render(request, 'myweb/orders/ordersinfo.html', context)
def orderinsert(request): #添加订单 orders = Orders() orders.uid = request.session['webuser']['id'] orders.linkman = request.POST['name'] 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(): detail = Detail() detail.orderid = orders.id detail.goodsid = shop['id'] detail.name = shop['goods'] detail.price = shop['price'] detail.num = shop['m'] detail.save() goods = Goods.objects.get(id=shop['id']) goods.store = int(goods.store) - int(shop['m']) goods.save() shoplist.pop(str(shop['id'])) request.session['shoplist'] = shoplist context = {'info': "下单成功: 您的订单号:" + str(orders.id)} return render(request, 'myweb/info.html', context)
def order(request): user = Users.objects.get(id = request.session['id']) try: shopid = request.GET['shopid'] shopid = shopid.split(',') # 获取登录对象 user = Users.objects.get(id = request.session['id']) # 创建订单表 order = Orders() order.uid = user.id order.linkman = user.name order.address = user.address order.code = user.code order.phone = user.phone # tz = pytz.timezone('Asia/Shanghai') order.addtime = datetime.now() order.total = 0 order.status = 4 for i in shopid: # 判断页面是否刷新 if request.session['shoplist'][str(i)]: # 未刷新 order.save() # 获取商品 shop = Goods.objects.get(id = int(i)) # 创建订单详情表 ob = Detail() ob.orderid = order.id ob.goodsid = shop.id ob.name = shop.goods ob.price = shop.price ob.num = int(request.session['shoplist'][str(i)]['num']) order = Orders.objects.get(id = order.id) order.total += shop.price*int(request.session['shoplist'][str(i)]['num']) order.save() ob.save() # 清除选中商品session shoplist = request.session['shoplist'] shoplist.pop(str(i)) request.session['shoplist'] = shoplist elif Orders.objects.filter(uid = user.id): order = Orders.objects.filter(uid = user.id) context = {'orders':order} else: context={'info':'暂无订单!'} return render(request,'myweb/meizu/order/order.html',context) orders = Orders.objects.filter(uid = user.id) midorder = orders midorder = midorder.order_by('-id') orders = midorder context = {'orders':orders} context['detaillist'] = Detail.objects.filter(orderid__in=Orders.objects.only('id').filter(uid=user.id)) except: if Orders.objects.filter(uid = request.session['id']): orders = Orders.objects.filter(uid = request.session['id']) midorder = orders midorder = midorder.order_by('-id') orders = midorder context = {'orders':orders} context['detaillist'] = Detail.objects.filter(orderid__in=Orders.objects.only('id').filter(uid=user.id)) #context['goodslist'] = Goods.objects.filter(id__in=Detail.objects.only('goodsid').filter(orderid__in=Orders.objects.only('id').filter(uid=user.id))) else: context={} context['info'] = '暂无订单!' goodsidlist = [] for i in Detail.objects.only('goodsid').filter(orderid__in=Orders.objects.only('id').filter(uid=user.id)): goodsidlist.append(i.goodsid) context['goodslist'] = Goods.objects.filter(id__in=goodsidlist) return render(request,'myweb/meizu/order/order.html',context)