示例#1
0
def add_one_user(id, name):
    account = Account()
    account.account_id = id
    account.username = name
    account.gift_balance = 999
    account.cash_balance = 1999
    account.type = "credt"
    account.status = "normal"
    accountDao = AccountDao(account)
    accountDao.add()
    print account.created_at
示例#2
0
def add(accountJson, headers=None, **kwargs):
    """创建账户"""
    try:
        LOG.info('account add....')
        if isinstance(accountJson, str):
            accountJson = json.loads(accountJson)
        accountDict = accountJson['account']
        account = Account()
        getObjFromJson(account, accountDict)
        if not account.account_id:
            account.account_id = getUUID()
        LOG.info('account add start ..' + account.account_id)
        # *** add by zhangaw ***
        #        session = sa.get_session()
        #        parent_userid = accountDict['parent_id'] if accountDict.has_key('parend_id') else ''
        #        if not parent_userid:
        #            user_id = accountDict['user_id']
        #            query_temp = session.execute('select parent_id from keystone.user where id=\'{}\' '.format(str(user_id))).first()
        #            parent_userid = query_temp.parent_id if query_temp else ''
        #        sql2 = 'select * from billing.account where user_id=\'{}\''.format(str(parent_userid))
        #        query2 = session.execute(sql2).first()
        #        if query2:
        #            account.parent_account = query2.account_id
        #        session.close()
        # *** end ***
        accountDao = AccountDao(account)
        accountDao.add()
        #        user=accountDao.getUserById(account.user_id)
        #        accountDao.addcontact(accountDao.account.account_id, {'name': user['name'],
        #                                      'position':None,
        #                                      'telephone': user['telephone'],
        #                                      'email':user['email'],
        #                                      'remark': None,
        #                                      'created_by': None,
        #                                      'created_at': datetime.datetime.now()})
        LOG.info('account add end ..' + account.account_id)
        return outSuccess(
            "account", getJsonFromObj(accountDao.account, ACCOUNT_OBJECT_KEY))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("创建账户失败!")