Beispiel #1
0
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("取得子账户消费列表失败!")
Beispiel #2
0
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("取得子账户列表失败!")
Beispiel #3
0
def generateRebateBill(started_at=None,
                       ended_at=None,
                       last=None,
                       current=None):
    if isinstance(started_at, str):
        started_at = datetime.strptime(started_at, '%Y-%m-%d %H:%M:%S')
    if isinstance(ended_at, str):
        ended_at = datetime.strptime(ended_at, '%Y-%m-%d %H:%M:%S')
    accountDao = AccountDao()
    consumptionDao = ConsumptionDao()
    rebatebillDao = RebateBillDao()
    rows = accountDao.getAllProjectAdminAccount()
    if rows:
        for row in rows:
            account_id = row.account_id
            user_id = row.user_id
            if rebatebillDao.checkRebateBill(account_id, started_at, ended_at):
                continue
            subaccounts = accountDao.subAccountList(user_id,
                                                    page_size=50000)[0]
            if subaccounts:
                rebatebill = RebateBill()
                rebatebill.started_at = started_at
                rebatebill.ended_at = ended_at
                rebatebill.account_id = account_id
                rebatebill_rebate_amount = 0
                rebatebill_subaccount_amount = 0
                rebatebill_subaccount_gift_amount = 0
                rebatebill.rebate_subbills = []
                rebatebill.no = generation()
                for subaccount in subaccounts:
                    temp_account_id = subaccount['account_id']
                    result = consumptionDao.getRebateSubBill(
                        temp_account_id, started_at, ended_at)
                    if result:
                        rebatesubbill = RebateSubBill()
                        rebatesubbill.rebate_bill_items = []
                        for item in result:
                            result2 = consumptionDao.getrebatebillitem(
                                temp_account_id, started_at, ended_at)
                            if result2:
                                for item2 in result2:
                                    rebatebillitem = RebateBillItem()
                                    rebatebillitem.started_at = started_at
                                    rebatebillitem.ended_at = ended_at
                                    rebatebillitem.amount = round(
                                        item2['amount_total'], 2)
                                    rebatebillitem.rebate_amount = round(
                                        item2['rebate_amount_total'], 2)
                                    rebatebillitem.resource_id = item2[
                                        'resource_id']
                                    rebatebillitem.resource_type = item2[
                                        'resource_type']
                                    rebatebillitem.resource_name = item2[
                                        'resource_name']
                                    rebatebillitem.region_id = item2[
                                        'region_id']
                                    rebatebillitem.gift_amount = round(
                                        item2['gift_amount_total'],
                                        2) if item2['gift_amount_total'] else 0
                                    rebatesubbill.rebate_bill_items.append(
                                        rebatebillitem)
                            rebatebill_rebate_amount += float(
                                item['rebate_amount_total']
                            ) if item['rebate_amount_total'] else 0
                            rebatebill_subaccount_amount += float(
                                item['amount_total']
                            ) if item['amount_total'] else 0
                            rebatebill_subaccount_gift_amount += float(
                                item['gift_amount_total']
                            ) if item['gift_amount_total'] else 0
                            rebatesubbill.account_id = temp_account_id
                            rebatesubbill.started_at = started_at
                            rebatesubbill.ended_at = ended_at
                            rebatesubbill.rebate_amount = round(
                                item['rebate_amount_total'], 2)
                            rebatesubbill.amount = round(
                                item['amount_total'], 2)
                            rebatesubbill.gift_amount = round(
                                item['gift_amount_total'], 2)
                            rebatebill.rebate_subbills.append(rebatesubbill)
                rebatebill.rebate_amount = round(rebatebill_rebate_amount, 2)
                rebatebill.subaccount_amount = round(
                    rebatebill_subaccount_amount, 2)
                rebatebill.subaccount_gift_amount = round(
                    rebatebill_subaccount_gift_amount, 2)
                rebatebillDao.rebateBill = rebatebill
                rebatebillDao.add()