Пример #1
0
def cancel_sell(uid, entry_id):
    s = current_session()
    entry = s.query(Exchange).filter(
        Exchange.id == entry_id,
        Exchange.seller_id == uid,
    ).first()

    if not entry:
        raise exceptions.ItemNotFound

    helpers.require_free_backpack_slot(s, uid)

    item = entry.item
    item.owner_id = uid
    item.status = 'backpack'

    s.add(
        ItemActivity(
            uid=uid,
            action='cancel_sell',
            item_id=entry.item.id,
            extra=json.dumps({'price': entry.price}),
            created=datetime.datetime.now(),
        ))

    s.delete(entry)
Пример #2
0
def draw(uid, currency):
    s = current_session()
    u = Account.find(uid)
    if not u:
        raise exceptions.UserNotFound

    helpers.require_free_backpack_slot(s, uid)

    if currency == 'ppoint':
        amount = constants.LOTTERY_PRICE
        Account.add_user_credit(u, [('ppoint', -amount)],
                                exceptions.InsufficientFunds)

    elif currency == 'jiecao':
        amount = constants.LOTTERY_JIECAO_PRICE
        Account.add_user_credit(u, [('jiecao', -amount)],
                                exceptions.InsufficientFunds)

    else:
        raise exceptions.InvalidCurrency

    reward = random.choice(constants.LOTTERY_REWARD_LIST)

    item = Item(owner_id=uid, sku=reward, status='backpack')
    s.add(item)
    s.flush()
    s.add(ItemActivity(
        uid=uid, action='lottery', item_id=item.id,
        extra=json.dumps({'currency': currency, 'amount': amount}),
        created=datetime.datetime.now(),
    ))
    return reward
Пример #3
0
def add(uid, item_sku, reason=None):
    s = current_session()
    helpers.require_free_backpack_slot(s, uid)

    item = Item(owner_id=uid, sku=item_sku, status='backpack')
    s.add(item)
    s.flush()

    s.add(ItemActivity(
        uid=uid, action='get', item_id=item.id,
        extra=reason and json.dumps(reason),
        created=datetime.datetime.now(),
    ))

    return item.id
Пример #4
0
def add(uid, item_sku, reason=None):
    s = current_session()
    helpers.require_free_backpack_slot(s, uid)

    item = Item(owner_id=uid, sku=item_sku, status='backpack')
    s.add(item)
    s.flush()

    s.add(
        ItemActivity(
            uid=uid,
            action='get',
            item_id=item.id,
            extra=reason and json.dumps(reason),
            created=datetime.datetime.now(),
        ))

    return item.id
Пример #5
0
def buy(uid, entry_id):
    s = current_session()

    u = Account.find(uid)
    if not u:
        raise exceptions.UserNotFound

    entry = s.query(Exchange).filter(Exchange.id == entry_id).first()
    if not entry:
        raise exceptions.ItemNotFound

    seller = entry.seller

    if u.ppoint < entry.price:
        raise exceptions.InsufficientFunds

    helpers.require_free_backpack_slot(s, uid)

    u.ppoint -= entry.price
    seller.ppoint += entry.price

    item = entry.item

    s.add(
        ItemActivity(
            uid=uid,
            action='buy',
            item_id=entry.item.id,
            extra=json.dumps({
                'seller': seller.id,
                'price': entry.price
            }),
            created=datetime.datetime.now(),
        ))

    item.owner_id = u.id
    item.status = 'backpack'

    s.delete(entry)
Пример #6
0
def buy(uid, entry_id):
    s = current_session()

    u = Account.find(uid)
    if not u:
        raise exceptions.UserNotFound

    entry = s.query(Exchange).filter(Exchange.id == entry_id).first()
    if not entry:
        raise exceptions.ItemNotFound

    seller = entry.seller

    if u.ppoint < entry.price:
        raise exceptions.InsufficientFunds

    helpers.require_free_backpack_slot(s, uid)

    u.ppoint -= entry.price
    seller.ppoint += entry.price

    item = entry.item

    s.add(
        ItemActivity(
            uid=uid,
            action="buy",
            item_id=entry.item.id,
            extra=json.dumps({"seller": seller.id, "price": entry.price}),
            created=datetime.datetime.now(),
        )
    )

    item.owner_id = u.id
    item.status = "backpack"

    s.delete(entry)
Пример #7
0
def cancel_sell(uid, entry_id):
    s = current_session()
    entry = s.query(Exchange).filter(Exchange.id == entry_id, Exchange.seller_id == uid).first()

    if not entry:
        raise exceptions.ItemNotFound

    helpers.require_free_backpack_slot(s, uid)

    item = entry.item
    item.owner_id = uid
    item.status = "backpack"

    s.add(
        ItemActivity(
            uid=uid,
            action="cancel_sell",
            item_id=entry.item.id,
            extra=json.dumps({"price": entry.price}),
            created=datetime.datetime.now(),
        )
    )

    s.delete(entry)