def subAccountConsumptionList(account_id, started_at, ended_at, condition, page_no=1, page_size=15): '''子账户消费列表''' try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() rows, count = accountDao.subAccountList(accountDao.account.user_id, condition, page_no, page_size) result = [] if datetime2Str(started_at) == change2UTC( datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m') + '-01', format='%Y-%m-%d') and datetime2Str( datetime2Str(ended_at, outformat='%Y-%m-%d %H'), informat='%Y-%m-%d %H') == change2UTC( datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H'), format='%Y-%m-%d %H'): if rows: accountDao = AccountDao() for row in rows: account = Account() account.account_id = row['account_id'] accountDao.account = account accountDao.detail() row['amount_total'] = accountDao.account.current_month_amount row['standard_amount_total'] = accountDao.account.current_month_standard_amount result.append(row) else: if rows: consumptionDao = ConsumptionDao() for row in rows: total = consumptionDao.getAmountSummary( row['account_id'], started_at, ended_at) result.append(dict(row, **total)) return outSuccess( 'subAccountConsumptionList', pagePackage("accounts", result, page_no=page_no, page_size=page_size, total=count)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得子账户消费列表失败!")
def detail(account_id): '''账号详情''' try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() return outSuccess( "account", getJsonFromObj(accountDao.account, ACCOUNT_OBJECT_KEY)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得账号详情失败!")
def subAccountAmountSum(account_id, started_at, ended_at): try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() return outSuccess( "sunAccountAmountSum", accountDao.subAccountAmountSum(accountDao.account.user_id, started_at, ended_at)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得子账户列表失败!")
def getSubAccountSum(account_id, headers=None, **kwargs): '''子账户数目统计''' try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() return outSuccess( "subAccountSum", accountDao.getSubAccountComsump(accountDao.account.user_id)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得子账户统计失败!")
def ProjectAdminsubAccountList(account_id, condition=None): try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() result, count = accountDao.ProjectAdminsubAccountList( accountDao.account.user_id, condition) print result return outSuccess('subAccountList', pagePackage('accounts', result, total=count)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得子账户列表失败!")
def checkProjectAdmin(account_id): '''判断是否是分销商用户''' try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() commonDao = CommonDao() return outSuccess( 'isProjectAdmin', commonDao.checkProjectAdmin(accountDao.account.user_id)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("服务器错误")
def subAccountList(account_id, condition=None, page_no=1, page_size=15): try: account = Account() account.account_id = account_id accountDao = AccountDao(account) accountDao.detail() result, count = accountDao.subAccountList(accountDao.account.user_id, condition, page_no, page_size) return outSuccess( "subAccountList", pagePackage("accounts", result, page_no=page_no, page_size=page_size, total=count)) except Exception as e: LOG.error(str(e)) LOG.error(traceback.format_exc()) return outError("取得子账户列表失败!")