Exemplo n.º 1
0
Arquivo: views.py Projeto: ulexy/ulexy
def add_goods_to_cart(request):
    goods_no = request.POST.get('goods_no', '')
    goods_num = request.POST.get('goods_num', '')
    try:
        goods_no = int(goods_no)
        goods_num = int(goods_num)
    except ValueError:
        raise Http404

    # goods_no=10003
    # goods_num=3
    goods_cart_type=0
    uid = request.session.get('uid', None)
    if not uid:
        result={'status':'NEED_LOGIN'}
        return HttpResponse(json.dumps(result,ensure_ascii = False))
    # uid=10

    cart=Cart_customer.objects.filter(uid=uid)
    if cart and len(cart) == 1:
        cart_id=cart[0].id
    else:
        new_cart=Cart_customer(uid=uid)
        new_cart.save()
        cart_id=new_cart.id
    goods=Cart_goods.objects.filter(cart_id=cart_id,goods_no=goods_no,goods_cart_type=goods_cart_type)
    if goods:
        goods[0].goods_num=goods[0].goods_num+goods_num
        goods[0].save()
    else:
        new_goods=Cart_goods(cart_id=cart_id,goods_no=goods_no,goods_num=goods_num,goods_cart_type=goods_cart_type)
        new_goods.save()
    result={'status':'SUCCESS'}
    return HttpResponse(json.dumps(result,ensure_ascii = False))
Exemplo n.º 2
0
Arquivo: views.py Projeto: ulexy/ulexy
def index(request):
    uid = request.session.get('uid', None)
    assert uid
    try:
        cart = Cart_customer.objects.get(uid = uid)
    except Cart_customer.DoesNotExist:
        print(" Cart_customer.DoesNotExist")
        cart = Cart_customer(uid=uid)
        cart.save()
    try:
        goods_list = Cart_goods.objects.filter(cart_id = cart.id,goods_cart_type = 0)
    except Cart_goods.DoesNotExist:
        print(" Cart_goods.DoesNotExist")
        return render_to_response('cart/cart.html',{'step':1,'shop_info':[]},context_instance=RequestContext(request))
    shop_info = []
    # shop_goods_info = []
    for goods in goods_list:
        goods_tmp = {}
        goods_tmp['cart_goods_id'] = goods.cart_goods_id
        goods_tmp['goods_num'] = goods.goods_num
        goods_no = Goods_no.objects.get(goods_no = goods.goods_no)
        goods_tmp['goods_color'] = goods_no.goods_color
        goods_tmp['goods_size'] = goods_no.goods_size
        goods_tmp['goods_unit_price'] = goods_no.goods_price
        goods_shoe = Goods_shoe.objects.get(goods_id = goods_no.goods_id)
        goods_tmp['goods_title'] = goods_shoe.goods_title
        goods_tmp['goods_pic'] = goods_shoe.goods_pic_url
        shop_id = goods_shoe.shop_id
        goods_tmp['original_price'] = goods_shoe.goods_price
        goods_tmp['price'] = int(goods_tmp['goods_unit_price']) * int(goods_tmp['goods_num'])
        shop_goods_info = checkSameShop(shop_info,shop_id)
        if shop_goods_info == None:
            shop = Shop.objects.get(shop_id = goods_shoe.shop_id)
            shop_info.append({'shop_id':shop.shop_id ,'shop_name': shop.shop_name,'goods':[goods_tmp]})
        else:
            shop_goods_info['goods'].append(goods_tmp)

    # print(shop_info)

    return render_to_response('cart/cart.html',{'step':1,'shop_info':shop_info},context_instance=RequestContext(request))
Exemplo n.º 3
0
Arquivo: views.py Projeto: ulexy/ulexy
def confirmOrder(request):
    cart_goods_id_list = request.POST.get("cart_goods_id_list",'')
    try:
        cart_goods_id_arr = cart_goods_id_list.split(',')
    except ValueError:
        raise Http404

    uid = request.session.get('uid', None)
    assert uid

    try:
        cart = Cart_customer.objects.get(uid = uid)
    except Cart_customer.DoesNotExist:
        print(" Cart_customer.DoesNotExist")
        cart = Cart_customer(uid=uid)
        cart.save()
    try:
        goods_list = Cart_goods.objects.filter(cart_id = cart.id,goods_cart_type = 0)
    except Cart_goods.DoesNotExist:
        print(" Cart_goods.DoesNotExist")
        raise Http404

    shop_info = []
    total_money = 0
    for goods in goods_list:
        if str(goods.cart_goods_id) in cart_goods_id_arr:
            goods_tmp = {}
            goods_tmp['cart_goods_id'] = goods.cart_goods_id
            goods_tmp['goods_num'] = goods.goods_num
            goods_no = Goods_no.objects.get(goods_no = goods.goods_no)
            goods_tmp['goods_color'] = goods_no.goods_color
            goods_tmp['goods_size'] = goods_no.goods_size
            goods_tmp['goods_unit_price'] = goods_no.goods_price
            goods_shoe = Goods_shoe.objects.get(goods_id = goods_no.goods_id)
            goods_tmp['goods_title'] = goods_shoe.goods_title
            goods_tmp['goods_pic'] = goods_shoe.goods_pic_url
            shop_id = goods_shoe.shop_id
            goods_tmp['original_price'] = goods_shoe.goods_price
            goods_tmp['price'] = int(goods_tmp['goods_unit_price']) * int(goods_tmp['goods_num'])
            total_money += goods_tmp['price']
            shop_goods_info = checkSameShop(shop_info,shop_id)
            if shop_goods_info == None:
                shop = Shop.objects.get(shop_id = goods_shoe.shop_id)
                shop_info.append({'shop_id':shop.shop_id ,'shop_name': shop.shop_name,'goods':[goods_tmp]})
            else:
                shop_goods_info['goods'].append(goods_tmp)

    addressInfo = []
    try:
        addressList = CustomerAddress.objects.filter(customer_id = uid,status_type=0)
        for address in addressList:
            tmp = {}
            tmp['address_id'] = address.address_id
            tmp['receiver_name'] = address.receiver_name
            tmp['receiver_cellphone'] = address.receiver_cellphone
            tmp['address_school'] = address.address_school
            tmp['address_campus'] = address.address_campus
            tmp['spec_address'] = address.spec_address
            if request.ulexy_user.default_address_id != None and request.ulexy_user.default_address_id == address.address_id:
                tmp['is_default_address'] = True
            else:
                tmp['is_default_address'] = False
            addressInfo.append(tmp)
    except CustomerAddress.DoesNotExist:
        print("address not exist")

    print(addressInfo)
    return render_to_response('order/confirmOrder.html',{'step':2,'shop_info':shop_info,'total_money':total_money,'addressInfo':addressInfo},context_instance=RequestContext(request))