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 generate_order(request): goods_list = request.GET.get("goods_list") good_list = goods_list.split("#") ''' 生成订单 移除购物车数据 将购物车数据添加到商品订单中 ''' username = request.session.get("username") user = UserModel.objects.get(u_name=username) order = Order() order.o_user = user order.save() # 移除数据 for good in good_list: ordergoods = OrderGoods() ordergoods.o_order = order cart_obj = CartModel.objects.get(pk=good) 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=data)
def make_order(request): carts = request.GET.get('carts') cart_list = carts.split('#') print(cart_list) order = OrderModel() userid = request.session.get("user_id") order.o_user = UserModel.objects.get(pk=userid) order.save() # 生成订单的商品数据 从购物车中来的 # 将购物车中的数据删除 ,在订单商品中添加移除的数据 for cartid in cart_list: # 查询购物车中的数据 cartmodel = CartModel.objects.get(pk=cartid) # 创建订单商品数据 ordergoods = OrderGoods() # 绑定订单号 ordergoods.o_order = order # 订单商品数据的商品个数 ordergoods.o_goods_num = cartmodel.c_goods_num # 订单商品中的商品 ordergoods.o_goods = cartmodel.c_goods ordergoods.save() cartmodel.delete() data = { 'msg':'ok', 'status':'200', 'order':order.id, } return JsonResponse(data)
def make_order(request): carts = request.GET.get('carts') cart_list = carts.split('#') print(cart_list) order = OrderModel() userid = request.session.get('user_id') order.o_user = UserModel.objects.get(pk=userid) order.save() for cartid in cart_list: # 查询购物车的数据 carmodel = CarModel.objects.get(pk=cartid) # 创建订单商品数据 ordergoods = OrderGoods() # 生成订单号 ordergoods.o_order = order # 商品个数 ordergoods.o_goods_num = carmodel.c_goods_num # 商品信息 ordergoods.o_goods = carmodel.c_goods ordergoods.save() carmodel.delete() data = { 'mas': 'ok', 'status': 200, 'order': order.id } return JsonResponse(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 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)