示例#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("取得子账户消费列表失败!")
示例#2
0
def listByPage(conditionJson,
               likeConditionjson=None,
               page_no=1,
               page_size=15,
               headers=None,
               **kwargs):
    '''
    分页查询账户信息
    '''
    try:
        conditionJson = json.loads(conditionJson)
        likeConditionjson = json.loads(likeConditionjson)
        accountDao = AccountDao()
        result = accountDao.getAccountByPage(
            accountDao.getQueryByCondition(conditionJson, likeConditionjson),
            page_no, page_size)
        dataResult = []
        if result:
            for account in result:
                dataResult.append(getJsonFromObj(account, ACCOUNT_OBJECT_KEY))
        return outSuccess(
            "accountList",
            pagePackage("accounts",
                        dataResult,
                        page_no=result.no,
                        page_size=result.page_size,
                        total=result.total))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("取得账户列表失败!")
示例#3
0
def checkAdmin(account_id):
    '''校验是否是admin用户'''
    try:
        accountDao = AccountDao()
        return outSuccess("isAdmin", accountDao.checkAdmin(account_id))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("校验用户失败!")
示例#4
0
def subAccountDetail(account_id):
    try:
        accountDao = AccountDao()
        return outSuccess("subAccountDetail",
                          accountDao.subAccountDetail(account_id))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("取得子账户列表失败!")
示例#5
0
def changeCreditLine(account_id, credit_line):
    '''调整信用额度'''
    try:
        accountDao = AccountDao()
        return outSuccess("account",
                          accountDao.changeCreditLine(account_id, credit_line))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("调整信用额度失败!")
示例#6
0
def change2Credit(account_id, credit_line):
    '''普通用户升级信用用户'''
    try:
        accountDao = AccountDao()
        return outSuccess("account",
                          accountDao.change2Credit(account_id, credit_line))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("升级信用用户失败!")
示例#7
0
def getParentUserByID(user_id):
    '''根据user的ID查找父用户'''
    try:
        accountDao = AccountDao()
        parentUser = accountDao.getParentUserById(user_id)
        return outSuccess("parentUser", parentUser)
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("取得账号失败!")
示例#8
0
def getAccountByProjectId(project_id):
    '''根据project的ID查找账号'''
    try:
        accountDao = AccountDao()
        accountDao.getAccountByProjectId(project_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("取得账号失败!")
示例#9
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
示例#10
0
def delete(account_id):
    '''删除账号'''
    try:
        account = Account()
        account.account_id = account_id
        accountDao = AccountDao(account)
        accountDao.delete()
        return outSuccess("msg", "删除账号成功!")
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("删除账号失败!")
示例#11
0
def generateBill(started_at=None, ended_at=None, last=None, current=None):
    '''生成账单'''
    if isinstance(started_at, str):
        started_at = datetime.datetime.strptime(started_at,
                                                '%Y-%m-%d %H:%M:%S')
    if isinstance(ended_at, str):
        ended_at = datetime.datetime.strptime(ended_at, '%Y-%m-%d %H:%M:%S')
    accountDao = AccountDao()
    consumptionDao = ConsumptionDao()
    #    rows = accountDao.list(condition={"status":"normal"})
    rows = accountDao.list()
    billDao = BillDao()
    for row in rows:
        account_id = row.account_id
        if billDao.checkBill(account_id, started_at, ended_at):
            continue
        result = consumptionDao.getAmountTotal_new(account_id, started_at,
                                                   ended_at)
        if result:
            result = totalAmount_bill(result)
            bill = Bill()
            bill.account_id = account_id
            bill.started_at = started_at
            bill.ended_at = ended_at
            bill.no = generation()
            bill.bill_items = []
            bill.amount = 0
            bill.gift_amount = 0
            bill.standard_amount = 0
            for bill_item_data in result:
                billItem = BillItem()
                getObjFromJson(billItem, bill_item_data)
                if bill_item_data['amount_total'] is None:
                    bill_item_data['amount_total'] = 0
                if bill_item_data['standard_total'] is None:
                    bill_item_data['standard_total'] = 0
                if bill_item_data['gift_total'] is None:
                    bill_item_data['gift_total'] = 0
                bill.amount += float(bill_item_data['amount_total'])
                bill.standard_amount += float(bill_item_data['standard_total'])
                bill.gift_amount += float(bill_item_data['gift_total'])
                billItem.amount = round(float(bill_item_data['amount_total']),
                                        2)
                billItem.standard_amount = round(
                    float(bill_item_data['standard_total']), 2)
                billItem.gift_amount = round(
                    float(bill_item_data['gift_total']), 2)
                bill.bill_items.append(billItem)
            bill.amount = round(bill.amount, 2)
            bill.type = 'cloud'
            billDao.bill = bill
            billDao.add()
示例#12
0
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("取得账号详情失败!")
示例#13
0
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("取得子账户统计失败!")
示例#14
0
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("取得子账户列表失败!")
示例#15
0
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("取得子账户列表失败!")
示例#16
0
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("服务器错误")
示例#17
0
def update(accountJson, headers=None, **kwargs):
    """更新账户"""
    try:
        if isinstance(accountJson, str):
            accountJson = json.loads(accountJson)
        accountDict = accountJson['account']
        account = Account()
        account.account_id = accountDict['account_id']
        accountDao = AccountDao(account)
        accountDao.update(accountDict)
        return outSuccess(
            "account", getJsonFromObj(accountDao.account, ACCOUNT_OBJECT_KEY))
    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("更新账户失败!")
示例#18
0
def detail_dict(account_id):
    '''帐号详情字典,包括account信息,user信息以及region信息'''
    try:
        account = Account()
        account.account_id = account_id
        accountDao = AccountDao(account)
        accountDao.detail_dict()
        return_dict = {
            "account": getJsonFromObj(accountDao.account, ACCOUNT_OBJECT_KEY),
            "user": accountDao.user_info,
            "region": accountDao.region_info,
            "success": "success"
        }
        return json.dumps(return_dict, cls=CJsonEncoder, ensure_ascii=False)

    except Exception as e:
        LOG.error(str(e))
        LOG.error(traceback.format_exc())
        return outError("取得账号详情字典失败!")
示例#19
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("创建账户失败!")
示例#20
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("取得子账户列表失败!")
示例#21
0
def lowcashReminder_3():
    accountDao = AccountDao()
    for account in accountDao.list({'status': 'normal'}):
        try:
            if accountDao.lowcashReminder_3(account.account_id):
                account.cash_balance = account.cash_balance if account.cash_balance else 0
                account.gift_balance = account.gift_balance if account.gift_balance else 0
                account.credit_line = account.credit_line if account.credit_line else 0
                content = None
                if account.type == 'normal':
                    content = '账户:' + account.username + '余额不足使用3天,请催款。目前账户现金余额:' + str(
                        account.cash_balance) + ',赠送余额:' + str(
                            account.gift_balance)
                else:
                    content = '账户:' + account.username + '余额不足使用3天,请催款。目前账户现金余额:' + str(
                        account.cash_balance) + ',赠送余额:' + str(
                            account.gift_balance) + ',信用额度:' + str(
                                account.credit_line) + ',可用额度:' + str(
                                    account.credit_line if account.
                                    cash_balance > 0 else account.credit_line +
                                    account.cash_balance) + "。"
                payment_workorder = {
                    'workordertype': 6,
                    'workorder_no': generation(),
                    'apply_by': 'billing',
                    'apply_source': 'billing',
                    'status': 'apply',
                    'theme': '账户:' + account.username + '余额不足使用3天,请催款',
                    'content': content
                }
                workOrderDao = WorkOrderDao()

                if workOrderDao.checkPaymentWorkOrder(
                        6, 'billing', 'billing', 'apply',
                        '账户:' + account.username + '余额不足使用3天,请催款',
                        datetime.datetime.utcnow() -
                        datetime.timedelta(days=3)):
                    workOrderDao.create(payment_workorder)
        except Exception as e:
            LOG.error(str(e))
            LOG.error(traceback.format_exc())
示例#22
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()