def list(self, req, **args):
     page_no = req.params.get('pageNo')
     page_size = req.params.get('pageSize')
     page_no = int(page_no) if page_no else 1
     page_size = int(page_size) if page_size else 15
     account_id = args.get('account_id')
     started_at = req.params.get('started_at')
     if started_at is None:
         started_at = datetime.datetime.strftime(datetime.datetime.now(),
                                                 '%Y-%m') + '-01'
     started_at = change2UTC(started_at,
                             timezone=CONF.timezone_local,
                             format='%Y-%m-%d')
     ended_at = req.params.get('ended_at')
     if ended_at is None:
         ended_at = datetime.datetime.utcnow()
     else:
         ended_at = change2UTC(ended_at,
                               timezone=CONF.timezone_local,
                               format='%Y-%m-%d')
     region_id = req.params.get('region_id')
     resource_type = req.params.get('resource_type')
     return Consumption.consumptionList(account_id, started_at, ended_at,
                                        region_id, resource_type, page_no,
                                        page_size)
 def getOrderRechargeList(self,req, **args):
     page_no = req.params.get('pageNo')
     page_size = req.params.get('pageSize')
     page_no = int(page_no) if page_no else 1
     page_size = int(page_size) if page_size else 15
     account_id = args.get('account_id')
     payment_type=req.params.get('payment_type')
     started_at=req.params.get('started_at')
     started_at=change2UTC(started_at,timezone=CONF.timezone_local,format='%Y-%m-%d')
     ended_at=req.params.get('ended_at')
     ended_at=change2UTC(ended_at,timezone=CONF.timezone_local,format='%Y-%m-%d')
     return Recharge.getOrderRechargeList(account_id, payment_type, started_at, ended_at,page_no,page_size)
Пример #3
0
 def list(self, req, **args):
     page_no = req.params.get('pageNo')
     page_size = req.params.get('pageSize')
     page_no = int(page_no) if page_no else 1
     page_size = int(page_size) if page_size else 15
     account_id = args.get('account_id')
     started_at = req.params.get('started_at')
     started_at=change2UTC(started_at,timezone=CONF.timezone_local,format='%Y-%m-%d')
     ended_at = req.params.get('ended_at')
     ended_at=change2UTC(ended_at,timezone=CONF.timezone_local,format='%Y-%m-%d')
     bill_type = req.params.get('bill_type')
     return Bill.list(account_id, started_at, ended_at, page_no, page_size, bill_type=bill_type)
Пример #4
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("取得子账户消费列表失败!")
 def getAmountSummary(self, req, **args):
     '''账户消费总额汇总'''
     account_id = args.get('account_id')
     started_at = req.params.get('started_at')
     if started_at is None:
         started_at = datetime.datetime.strftime(datetime.datetime.now(),
                                                 '%Y-%m') + '-01'
     started_at = change2UTC(started_at,
                             timezone=CONF.timezone_local,
                             format='%Y-%m-%d')
     ended_at = req.params.get('ended_at')
     if ended_at is None:
         ended_at = datetime.datetime.utcnow()
     else:
         ended_at = change2UTC(ended_at,
                               timezone=CONF.timezone_local,
                               format='%Y-%m-%d')
     return Consumption.getAmountSummary(account_id, started_at, ended_at)
def insteadRecharge(insteadRechargeJson, headers=None, **kwargs):
    try:
        if isinstance(insteadRechargeJson, str):
            insteadRechargeJson = json.loads(insteadRechargeJson)
        order = Order()
        account_id = insteadRechargeJson['recharge']['account_id']
        amount = float(insteadRechargeJson['recharge']['amount'])
        remark = insteadRechargeJson['instead_recharge']['remark']
        instead_recharge_by = insteadRechargeJson['instead_recharge']['instead_recharge_by']
        instead_recharge_account = insteadRechargeJson['instead_recharge']['instead_recharge_account']

        insteadRechargeDict = insteadRechargeJson['instead_recharge']
        insteadRecharge = InsteadRecharge()
        getObjFromJson(insteadRecharge, insteadRechargeDict)
        
        transferinfoDict=insteadRechargeJson['transferinfo']
        transferinfo=TransferInfo()
        getObjFromJson(transferinfo,transferinfoDict)

        order.account_id = account_id
        order.amount = amount
        order.payment_type = "recharge"
        order.status = "pay_success"
        order.order_no = generation()

        recharge = Recharge()
        recharge.order = order
        recharge.payment_way = "transfer_pay"
        recharge.status = "pay_success"
        recharge.pay_at = datetime.datetime.utcnow()
        recharge.is_instead_recharge = True
        recharge.remark = insteadRecharge.remark
        recharge.amount = amount

        insteadRecharge = InsteadRecharge()
        insteadRecharge.recharge = recharge
        insteadRecharge.instead_recharge_by = instead_recharge_by
        insteadRecharge.instead_recharge_account = instead_recharge_account
        insteadRecharge.remark = remark

        insteadRechargeDao = InsteadRechargeDao(insteadRecharge)
        insteadRechargeDao.insteadRechargeAmount()
        
        transferinfo.recharge_id=insteadRechargeDao.insteadRecharge.recharge_id
        transferinfo.amount=amount
        transferinfo.inward_at=change2UTC(transferinfo.inward_at,format='%Y-%m-%d')
        transferInfoDao=TransferInfoDao(transferinfo)
        transferInfoDao.add()
        
        insteadRechargeDao.insteadRecharge.transferInfo=transferInfoDao.tansferinfo
        return outSuccess("insteadecharge", getJsonFromObj(insteadRechargeDao.insteadRecharge))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("代充值失败!")
Пример #7
0
 def subAccountAmountSum(self,
                         parent_id,
                         started_at,
                         ended_at,
                         session=None):
     if session is None:
         session = sa.get_session()
     adminrow = session.execute(SQL.checkAdmin, {
         'user_id': parent_id
     }).first()
     if adminrow:
         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'):
             query = session.execute(
                 SQL.admin_subAccountCurrentMonthAmountSum,
                 {'parent_id': parent_id})
         else:
             query = session.execute(
                 SQL.admin_subAccountAmountSum, {
                     'parent_id': parent_id,
                     'started_at': started_at,
                     'ended_at': ended_at
                 })
     else:
         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'):
             query = session.execute(
                 SQL.subAccountCurrentMonthAmountSum, {
                     'parent_id': parent_id,
                     'started_at': started_at,
                     'ended_at': ended_at
                 })
         else:
             query = session.execute(
                 SQL.subAccountAmountSum, {
                     'parent_id': parent_id,
                     'started_at': started_at,
                     'ended_at': ended_at
                 })
     row = query.first()
     if row:
         return {
             'amount_total': row.amount_total,
             'standard_amount_total': row.standard_amount_total
         }
     session.close()
     return {}