예제 #1
0
def create_sales_record(count, seller_id, book_id, purchaser_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    book = Book.objects(id=book_id).first()
    if book is None:
        return {'message': 'Missing parameter book, or book id is wrong.'}
    if book.remaining < count:
        return {'message': 'This book is not enough'}
    price = book.price
    seller = Account.objects(id=seller_id).first()
    if seller is None:
        return {'message': 'Missing parameter seller, or seller id is wrong.'}
    try:
        purchaser = Vip.objects(id=purchaser_id).first()
    except ValidationError:
        purchaser = None
    if purchaser is not None:
        price *= 0.8
    book.remaining -= count
    book.sales += count
    book.save()
    sales_record = SalesRecord(
        count=count,
        price=price,
        book=book,
        seller=seller,
        purchaser=purchaser,
    ).save()
    return {'id': sales_record.id, 'success': 1}
예제 #2
0
def get_vips(args, token=None):
    if token is None or not is_stuff(token):
        return abort(403)

    if 'name' in args:
        return Vip.objects(Q(name=args['name']))
    return None
예제 #3
0
def get_vips(args, token=None):
    if token is None or not is_stuff(token):
        return abort(403)

    if 'name' in args:
        return Vip.objects(Q(name=args['name']))
    return None
예제 #4
0
def create_vip(username, nickname, phone, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    if phone is None:
        phone = ""
    if Vip.objects(username=username).first() is not None:
        return {'message': 'The vip\'s name has been used'}
    vip = Vip(
        username=username,
        nickname=nickname,
        phone=phone,
    ).save()
    return {
        'id': vip.id,
        'success': 1,
    }
예제 #5
0
def create_sales_record(count, seller_id, book_id, purchaser_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    book = Book.objects(id=book_id).first()
    if book is None:
        return {'message': 'Missing parameter book, or book id is wrong.'}
    if book.remaining < count:
        return {'message': 'This book is not enough'}
    price = book.price
    seller = Account.objects(id=seller_id).first()
    if seller is None:
        return {'message': 'Missing parameter seller, or seller id is wrong.'}
    try:
        purchaser = Vip.objects(id=purchaser_id).first()
    except ValidationError:
        purchaser = None
    if purchaser is not None:
        price *= 0.8
    book.remaining -= count
    book.sales += count
    book.save()
    sales_record = SalesRecord(
        count=count,
        price=price,
        book=book,
        seller=seller,
        purchaser=purchaser,
    ).save()
    return {
        'id': sales_record.id,
        'success': 1
    }
예제 #6
0
def create_vip(username, nickname, phone, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    if phone is None:
        phone = ""
    if Vip.objects(username=username).first() is not None:
        return {'message': 'The vip\'s name has been used'}
    vip = Vip(
        username=username,
        nickname=nickname,
        phone=phone,
    ).save()
    return {
        'id': vip.id,
        'success': 1,
    }
예제 #7
0
def rm_vip(book_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    vip = Vip.objects(id=book_id)
    vip.delete()
    return {'success': 1}
예제 #8
0
def get_all_vips(token=None):
    if token is None or not is_stuff(token):
        return abort(403)

    vips = Vip.objects()
    return vips
예제 #9
0
def get_sales_records_by_vip(vip_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    vip = Vip.objects(id=vip_id).first()
    sales_records = SalesRecord.objects(purchaser=vip)
    return sales_records
예제 #10
0
def rm_vip(book_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    vip = Vip.objects(id=book_id)
    vip.delete()
    return {'success': 1}
예제 #11
0
def get_all_vips(token=None):
    if token is None or not is_stuff(token):
        return abort(403)

    vips = Vip.objects()
    return vips
예제 #12
0
def get_sales_records_by_vip(vip_id, token=None):
    if token is None or not is_stuff(token):
        return abort(403)
    vip = Vip.objects(id=vip_id).first()
    sales_records = SalesRecord.objects(purchaser=vip)
    return sales_records