Example #1
0
async def update_driver_terminal_oper(term_id, term_opertime,
                                      term_pay_system_id, term_summ, comment,
                                      oper_id):
    UPDATE = 'update driver_oper set term_operation=1, term_id=%s, term_opertime=\'%s\'' % (
        term_id, term_opertime)
    if term_pay_system_id:
        # id платёжной системы
        UPDATE += ', term_pay_system_id=%s' % term_pay_system_id
    if term_summ:
        # Внесённая сумма
        UPDATE += ', term_summ=%s' % term_summ
    if comment:
        UPDATE += ', comment=\'%s\'' % comment
    UPDATE += ' where id=%s' % oper_id
    with (await db_semaphore), fdb.connect(**settings.FDB) as db:
        try:
            with db.cursor() as c:
                c.execute(UPDATE)
            db.commit()
            logger.info(f'driver_opers.id={oper_id} updated')
            updated = True
        except Exception as e:
            db.rollback()
            logger.info(f'driver_opers.id={oper_id} updating error {e}')
            updated = True
    return updated
Example #2
0
def event_result(future):
    """Событие обработано, дальнейшие действия"""
    event, events, order_data = future.result()
    print(f'event_result: {event}, {events}, {order_data}')

    if event in ('ORDER_COMPLETED', 'ORDER_ABORTED'):
        del orders[order_data['order_id']]
    logger.info(f'{event}, {events}, {order_data}')
Example #3
0
async def get_greeting(order_state):
    order_state = order_state.upper()
    with (await greetings['acquire']):
        if order_state in greetings.keys():
            return greetings[order_state]
        else:
            try:
                data = await get_sounds(
                    'select name, description from asterisk_sounds where (sound_type=4) and (description is not null)'
                )
                # data = {k.upper(): v for k, v in data.items()}
                logger.info(f'get_greeting: {data}')
                greetings.update(data)
                logger.info(f'{greetings[order_state]}')
                return greetings[order_state]
            except Exception as e:
                logger.error(e)
                logger.error(traceback2.extract_tb(sys.exc_info()[2]))
                return ''
Example #4
0
async def driver_term_oper_create(event, oper_data, ws, loop):
    events = []
    term_oper = await database.select_pay_term_id(oper_data['txn_id'])
    if term_oper:
        oper_id, oper_time, driver_id = term_oper
        oper_data.update(oper_id=oper_id)
        oper_data.update(oper_time=oper_time)
        oper_data.update(driver_id=driver_id)
        await ws.send_json({
            'DRIVER_TERM_OPER_DUBLICATE': oper_data,
        })
        logger.info(f'{oper_data} существует')
    else:
        driver_id = await database.get_driver_id(oper_data['account'])
        if driver_id < 0:
            logger.info(f"Недопустимый аккаунт {oper_data['account']}")
            driver_id = await database.get_driver_id(settings.FAKE_TERM_ACCOUNT
                                                     )
        oper_data['driver_id'] = driver_id
        amount = oper_data['amount']
        # oper_data['oper_type'] = ['receipt', 'expense'][oper_data['oper_type']] # Приход/Расход
        request = ('create_driver_operation', {
            'driver_id': driver_id,
            'oper_sum': amount,
            'oper_type': ['receipt', 'expense'][oper_data['oper_type']]
        })
        name = oper_data.get('name')
        comment = oper_data.get('comment')
        if name is not None:
            request[1].update(name=name)
        if comment is not None:
            request[1].update(comment=comment)
        api_result = await tmtapi.api_request(request)
        oper_id = api_result['data']['oper_id'] if api_result[
            'code'] == 0 else 0
        if oper_id > 0:
            # Операция создана
            oper_data.update(oper_id=oper_id)
            await ws.send_json({
                'DRIVER_TERM_OPER_CREATED': oper_data,
            })

    return event, events, oper_data
Example #5
0
async def get_order_data(event, order_data, ws, loop):
    order_state = await tmtapi.api_request(
        ('get_order_state',
            {'order_id': order_data['order_id']})
    )
    logger.info(order_state)
    order_info = await tmtapi.api_request(
        ('get_info_by_order_id',
            {'order_id': order_data['order_id'],
                'fields': ('DRIVER_TIMECOUNT-SUMM-SUMCITY-'
                           'DISCOUNTEDSUMM-SUMCOUNTRY-SUMIDLETIME-CASHLESS-'
                           'CLIENT_ID-FROMBORDER-DRIVER_PHONE-CREATION_WAY').lower(), })
    )
    logger.info(f'{order_info}')
    order_info = order_info['data']
    # Консолидировать подробности по заказу
    order_info.update(order_state)
    order_info['phones'] = (order_info['phone_to_callback'][-10:], )
    # del order_info['phone_to_callback']
    logger.info(order_info)
    events = []
    return event, events, order_info
Example #6
0
async def get_voip_message(order_data):
    logger.info(f'get_voip_message: {order_data}')
    order_state = order_data['state'].upper()
    voip_message = await get_greeting(order_state)
    if voip_message:
        if order_state != 'NO_CARS':
            mark = await get_mark(order_data['car_mark'])
            logger.info(f'get_voip_message: {mark}')
            voip_message = voip_message.replace('$mark', mark if mark else '')
            model = await get_model(order_data['car_mark'],
                                    order_data['car_model'])
            logger.info(f'get_voip_message: {model}')
            voip_message = voip_message.replace('$model',
                                                model if model else '')
            color = await get_color(order_data['car_color'])
            logger.info(f'get_voip_message: {color}')
            voip_message = voip_message.replace('$color', color)
            if not color:
                voip_message = voip_message.replace('&ru/tmColor&', '')
            gosnumber = await get_gosnumber(order_data['gosnumber'])
            logger.info(f'get_voip_message: {gosnumber}')
            if not gosnumber:
                voip_message = voip_message.replace('&ru/tmgosnomer&', '')
            voip_message = voip_message.replace('$gosnumber', gosnumber)
            minutes = await get_minutes(order_data['driver_timecount'])
            voip_message = voip_message.replace('$minutes', minutes)
    voip_message = [f'{vm}.wav' for vm in voip_message.split('&') if vm]
    logger.info(f'get_voip_message: {voip_message}')
    return voip_message