Exemple #1
0
def strategy_2016_spring(user_id):
    from core.models.promotion.festival.spring import SpringGift
    user = Account.get(user_id)
    gift = SpringGift.get_by_user(user)
    return gift.status is SpringGift.Status.reserved
Exemple #2
0
 def user(self):
     """The current account."""
     return Account.get(self.id_)
Exemple #3
0
 def user(self):
     return Account.get(self.user_id)
Exemple #4
0
 def local_account(self):
     return LocalAccount.get(self.account_id)
Exemple #5
0
 def user(self):
     from core.models.user.account import Account
     return Account.get(self.user_id)
def get_users_by_birthday(date_str):
    sql = 'select id from profile_identity where substring(person_ricn, 11, 4)=%s'
    rs = db.execute(sql, date_str)
    for r in rs:
        yield Account.get(r[0])
Exemple #7
0
    def check_before_adding(cls,
                            user_id,
                            bankcard_id,
                            product_id,
                            amount,
                            wrapped_product_id=None):
        product = ZhiwangProduct.get(product_id)
        wrapped_product = ZhiwangWrappedProduct.get(
            wrapped_product_id) if wrapped_product_id else None

        # check the product and wrapped_product
        if wrapped_product_id is not None and not wrapped_product:
            raise NotFoundError(wrapped_product_id, ZhiwangWrappedProduct)
        if wrapped_product and wrapped_product.raw_product.product_id != product_id:
            raise UnknownProductInheritance(product_id, wrapped_product_id)
        if wrapped_product and not wrapped_product.is_qualified(user_id):
            raise IneligiblePurchase(user_id, wrapped_product_id)

        product = wrapped_product if wrapped_product else product
        bankcard = BankCard.get(bankcard_id)
        local_account = Account.get(user_id)
        zhiwang_account = ZhiwangAccount.get_by_local(user_id)

        # checks the related entities
        if not bankcard:
            raise NotFoundError(bankcard_id, BankCard)
        if not local_account:
            raise NotFoundError(local_account, Account)
        if not zhiwang_account:
            raise UnboundAccountError(user_id)

        # checks the identity
        if not has_real_identity(local_account):
            raise InvalidIdentityError

        # 产品是否处于可售状态
        if product.is_either_sold_out:
            raise SoldOutError(product_id, wrapped_product_id)
        # 产品是否处于正常销售状态
        if product.is_taken_down:
            raise SuspendedError(product_id, wrapped_product_id)
        # 产品是否处于在售状态
        if not product.in_stock:
            raise OffShelfError(product_id, wrapped_product_id)

        # checks the product amount limit
        if not isinstance(amount, Decimal):
            raise TypeError('order amount must be decimal')
        amount_range = (product.min_amount, product.max_amount)
        amount_check = [
            amount.is_nan(), amount < 0, amount < amount_range[0],
            amount > amount_range[1]
        ]
        if any(amount_check):
            raise OutOfRangeError(amount, amount_range)

        # checks the bank amount limit
        bank_limit = bankcard.bank.zwlib_amount_limit
        bank_limit = max(bank_limit) if cls.is_bankcard_swiped(
            bankcard) else min(bank_limit)
        if amount > bank_limit:
            raise ExceedBankAmountLimitError(amount, bank_limit)
Exemple #8
0
def initial_new_user(uid, password):
    user = Account.get(uid)
    change_password(user.id_, password)
    user_register_completed.send(user)
    return user
Exemple #9
0
 def send(self, user_id):
     user = Account.get(user_id)
     distribute_welfare_gift(user, self.package)
Exemple #10
0
    def __init__(self, user_id):
        if not Account.get(user_id):
            raise ValueError('invalid user id %s' % user_id)

        self.user_id = user_id