def make_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True) order = Order() order.o_user = request.user order.o_price = get_total_price() order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() # 从购物车中删除 cart_obj.delete() address_obj = Address.objects.filter(a_user=request.user).filter( a_using=True).first() order_address_obj = OrderAddress() order_address_obj.oa_address = address_obj order_address_obj.oa_order = order order_address_obj.save() data = { "status": 200, "msg": "ok", "order_id": order.id, } return JsonResponse(data)
def make_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True) order = Order() order.o_user = request.user order.o_price = get_total_price(user=request.user) order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.o_goods_price = cart_obj.c_goods.price ordergoods.save() cart_obj.delete() data = { 'status': 200, 'msg': 'order success', 'order_id': order.id, } return JsonResponse(data=data)
def make_order(request): order = Order() order.o_user = request.user order.o_price = get_total_price( Cart.objects.filter(c_user=request.user).filter(c_is_select=True)) order.save() cart_list = Cart.objects.filter(c_user=request.user).filter( c_is_select=True) for cart in cart_list: ordergoods = OrderGoods() ordergoods.og_order = order ordergoods.og_goods = cart.c_goods ordergoods.og_goods_num = cart.c_goods_nums ordergoods.save() cart.delete() data = {'status': 200, 'msg': 'ok', 'orderid': order.id} return JsonResponse(data=data)
def make_order(request): user = request.user carts = Cart.objects.filter(c_user=user).filter(c_is_selected=True) # 生成订单 order = Order() order.o_user = user order.o_price = total_price(user) order.save() # 订单和商品级联 for cart in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods = cart.c_good ordergoods.o_goods_num = cart.c_goods_num ordergoods.save() cart.delete() data = { 'status': 700, 'msg': 'ok', 'order_id': order.id, } return JsonResponse(data)
def make_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True) order = Order() order.o_user = request.user order.o_price = get_total_price() order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods = cart_obj.c_goods ordergoods.o_goods_nums = cart_obj.c_goods_num ordergoods.save() data = { "status": 200, "msg": "ok", "order_id": order.id } return JsonResponse(data=data)
def post(self, request, *args, **kwargs): carts = Cart.objects.filter(c_user=request.user).filter( c_is_select=True) order = Order() order.o_user = request.user order.o_price = get_total_price(self.request) order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data = {"status": 200, "msg": 'ok', "data": {'order_id': order.id}} return Response(data)
def create_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_selected=True) order = Order() order.o_user = request.user order.o_price = get_total_price() # get it again at backend order.save() # create order from selected in cart for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() # removed cart obj data = { 'status': 200, 'msg': 'ok', 'order_id': order.id, } return JsonResponse(data=data)
def post(self, request, *args, **kwargs): token = request.POST.get('token') # 未登录 if token == None or token == "null": return Response({"status": 901, "msg": "未登录"}) u_id = cache.get(token) user = User.objects.get(pk=u_id) cart = request.POST.get("cart") if cart: o_addr = request.POST.get("addr_id") o_note = request.POST.get("o_note") cartfoods = Cart.objects.filter(c_user=user).filter(is_select=1) if cartfoods: try: order = Order() order.o_user = user order.o_addr = o_addr order.o_note = o_note order.o_id = get_order_id(user) order.o_price = get_total_price(user) order.o_points = get_total_points(user) order.save() for food in cartfoods: orderfood = OrderFoods() orderfood.o_user_order = order orderfood.o_foods_id = food.c_foods_id orderfood.o_foods_num = food.c_foods_num orderfood.save() food.delete() return Response({"status": 200, "order_id": order.id}) except Exception as e: print(e) Response({"status": 901, "msg": "信息填写有误"}) else: return Response({"status": 901, "msg": "没有商品被选中或刷新再试"}) return Response({"status": 200, "msg": "....."})
def make_order(request): # 构建订单地址对象 a_id = request.GET.get("a_id") address = Address.objects.filter(pk=a_id).first() orderAddress = OrderAddress() orderAddress.o_address = address carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True) order = Order() order.o_user = request.user order.o_price = get_total_price() order.save() order = Order.objects.all().last() orderAddress.o_order = order orderAddress.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data = {"status": 200, "msg": 'ok', 'order_id': order.id} return JsonResponse(data)