Beispiel #1
0
def search_goods_by_label(required_label):
    tmp_list = list()
    all_goods = Goods.objects()
    for goods in all_goods:
        # whether list has contains relationship
        if set(required_label) <= set(goods.label):
            tmp_list.append(goods)
    return tmp_list
Beispiel #2
0
def del_goods(goods_id, result):
    goods = Goods.objects(_id=goods_id)
    if goods:
        goods.delete()
        result['status'] = 'success'
    else:
        result['status'] = 'fail'
        result['msg'] = 'goods not exist'
Beispiel #3
0
def get_all_goods():
    goods_list = list()
    all_goods = Goods.objects()
    for goods in all_goods:
        single_goods = dict()
        single_goods['_id'] = str(goods['_id'])
        single_goods['name'] = goods['name']
        single_goods['price'] = goods['price']
        single_goods['label'] = goods['label']
        goods_list.append(single_goods)
    return goods_list
Beispiel #4
0
def edit_goods(args, result):
    goods_id = args[0]
    edit_type = args[1]
    edit_content = args[2]
    goods = Goods.objects(_id=goods_id).first()
    if goods:
        if edit_type == 'price':
            goods[edit_type] = float(edit_content)
        else:
            goods[edit_type] = edit_content
        goods.save()
        result['status'] = 'success'
    else:
        result['status'] = 'fail'
        result['msg'] = 'goods not exist'
Beispiel #5
0
def put_cart(args, result):
    goods_id = args[0]
    phone_num = args[1]
    goods_num = args[2]
    user = User.objects(phone_num=phone_num).first()
    goods = Goods.objects(_id=goods_id).first()
    if user and goods:
        for cart in user.cart:
            if cart['goods_id'] == goods_id:
                cart['good_num'] = goods_num
                cart['goods_price'] = float(goods.price) * int(goods_num)
                break
        else:
            goods_info = dict()
            goods_info['goods_id'] = goods_id
            goods_info['goods_name'] = goods.name
            goods_info['goods_price'] = float(goods.price) * int(goods_num)
            goods_info['good_num'] = goods_num
            user.cart.append(goods_info)
        user.save()
        result['status'] = 'success'
    else:
        result['status'] = 'fail'
        result['msg'] = 'user or goods not exist'