Пример #1
0
def update_keysback():
    """ Get back voice call's keys which restaurant inputs """
    ElemeOrderConst = thirdparty_svc.eos.ElemeOrderConst
    OrderRecordConst = thirdparty_svc.eos.OrderRecordConst

    args = request.args if request.method == 'GET' else request.form
    log.info('Keysback args: %s' % args.items())
    order_id = to_int(args.get('orderId'))
    key_pressed = to_int(args.get('press'))
    call_id = to_int(args.get('userField'), silence=False)

    voice_order = VoiceOrder.get_by_order_id(order_id)

    if key_pressed == KEY_AFFIRM:
        status_to = ElemeOrderConst.STATUS_PROCESSED_AND_VALID

        with thrift_client('eos') as eos:
            eos.eleme_process_order(order_id, status_to,
                                    OrderRecordConst.PROCESSED_BY_MACHINE,
                                    OrderRecordConst.PROCESS_GROUP_ADMIN, '',
                                    0)

        voice_order.status_code = status_to
        log.info('update eleme order to status: %d.' % status_to)

    elif key_pressed == KEY_BAN_TODAY:
        restaurant_id = VoiceCall.get(call_id).restaurant_id
        VoicecallBan.add(restaurant_id, VoicecallBan.BAN_TYPE_TODAY)
        log.info('add voice call ban for restaurant {}'.format(restaurant_id))

    voice_order.key_pressed = key_pressed

    return {'result': 'success'}
Пример #2
0
def update_keysback():
    """ Get back voice call's keys which restaurant inputs """
    ElemeOrderConst = thirdparty_svc.eos.ElemeOrderConst
    OrderRecordConst = thirdparty_svc.eos.OrderRecordConst

    args = request.args if request.method == 'GET' else request.form
    log.info('Keysback args: %s' % args.items())
    order_id = to_int(args.get('orderId'))
    key_pressed = to_int(args.get('press'))
    call_id = to_int(args.get('userField'), silence=False)

    voice_order = VoiceOrder.get_by_order_id(order_id)

    if key_pressed == KEY_AFFIRM:
        status_to = ElemeOrderConst.STATUS_PROCESSED_AND_VALID

        with thrift_client('eos') as eos:
            eos.eleme_process_order(
                order_id, status_to, OrderRecordConst.PROCESSED_BY_MACHINE,
                OrderRecordConst.PROCESS_GROUP_ADMIN, '', 0)

        voice_order.status_code = status_to
        log.info('update eleme order to status: %d.' % status_to)

    elif key_pressed == KEY_BAN_TODAY:
        restaurant_id = VoiceCall.get(call_id).restaurant_id
        VoicecallBan.add(restaurant_id, VoicecallBan.BAN_TYPE_TODAY)
        log.info('add voice call ban for restaurant {}'.format(
            restaurant_id))

    voice_order.key_pressed = key_pressed

    return {'result': 'success'}
Пример #3
0
def get_pending_activity_stats(args):
    """ get activity status which is pending """
    search_text = to_int(args.get('search_text'))
    query_city_id = to_int(args.get('city_id'))
    page_no, page_size = get_paging_params()
    user_city_ids, user_restaurant_ids = \
        get_city_ids_or_restaurant_ids_by_user()

    t_activity_status_query = thirdparty_svc.eos.TActivityStatsQuery()
    t_activity_status_query.statuses = [
        thirdparty_svc.eos.ActivityStatsConst.STATUS_PENDING, ]
    t_activity_status_query.with_subsidy = True
    t_activity_status_query.from_date = args.get('from_date')
    t_activity_status_query.to_date = args.get('to_date')
    t_activity_status_query.offset = (page_no - 1) * page_size
    t_activity_status_query.limit = page_size

    # if current_user is admin, restaurant_ids and user_city_ids are None.
    if current_user.is_super_admin():
        if query_city_id is not None:
            t_activity_status_query.city_ids = [query_city_id, ]
        if search_text is not None:
            t_activity_status_query.restaurant_ids = [search_text, ]
        with thrift_client('eos') as eos:
            activity_status_list = eos.query_auto_pay_activity_stats_result(
                t_activity_status_query)
        return [act.__dict__ for act in activity_status_list]

    if user_restaurant_ids or user_city_ids:
        city_ids = user_city_ids
        if query_city_id is not None:
            if user_city_ids is None or query_city_id in user_city_ids:
                city_ids = [query_city_id, ]
            else:
                return []
        t_activity_status_query.city_ids = city_ids

        # if user_city_ids is not None, user_restaurant_ids must be None
        restaurant_ids = user_restaurant_ids
        if search_text is not None:
            restaurant_ids = [search_text, ]
        t_activity_status_query.restaurant_ids = restaurant_ids

        with thrift_client('eos') as eos:
            activity_status_list = eos.query_auto_pay_activity_stats_result(
                t_activity_status_query)

        return [act.__dict__ for act in activity_status_list]

    else:
        return []
Пример #4
0
def get_pay_records(rst_id, activity_id=None, activity_category_id=None,
                    offset=None, limit=None):
    records_paging = query_paylog_by_rst(rst_id, activity_id,
                                         activity_category_id, offset, limit)
    total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id)

    record_process_ids = [r[9] for r in records_paging if r[9]]
    record_process_logs = query_process_records_by_ids(record_process_ids)
    process_log_map = {r.id: r for r in record_process_logs}

    records = []
    for record in records_paging:
        new_record = {
            'record_id': record[0],
            'first_date': record[4],
            'last_date': record[5],
            'quantity': to_int(record[6]),
            'audit_time': record[8],
            'total_subsidy': to_float(record[7]),
            'activity_id': record[1],
            'activity_category_id': record[2],
        }
        process_log = process_log_map.get(record[9], None)

        new_record['card_id'] = process_log.card_id \
            if process_log else None
        new_record['cardholder_name'] = process_log.cardholder_name \
            if process_log else None

        if process_log:
            new_record['status'] = process_log.status
        elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED:
            new_record['status'] = 1
        else:
            raise_user_exc(ACTIVITY_PAYMENT_PROC_ILL_ERR)

        if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED:
            new_record['submit_time'] = process_log.processed_at
        elif new_record['status'] in [3, 4]:
            new_record['success_time'] = process_log.processed_at

        records.append(new_record)

    for record in records:
        # set activity name
        try:
            record['activity_name'] = act_base.get_name(
                record['activity_id'], record['activity_category_id'])
        except:
            # Fix history problem
            record['activity_name'] = ''

    record_results = set_null(records,
                              ['card_id', 'cardholder_name',
                               'audit_time', 'submit_time', 'success_time'])

    return record_results, total_num
Пример #5
0
def load_user(uid):
    user_id = None
    # todo 计算token
    if request.cookies.get('god_token'):
        user_id = to_int(request.cookies.get('god_uid'), return_none=True)
    if user_id is None:
        return WalisUser.get_user(request.cookies.get('SSO_TOKEN'))

    return WalisUser(user_id)
Пример #6
0
def load_user(uid):
    user_id = None
    # todo 计算token
    if request.cookies.get('god_token'):
        user_id = to_int(request.cookies.get('god_uid'), return_none=True)
    if user_id is None:
        return WalisUser.get_user(request.cookies.get('SSO_TOKEN'))

    return WalisUser(user_id)
Пример #7
0
def get_pay_records2(rst_id, activity_id=None, activity_category_id=None,
                     offset=None, limit=None):

    pay_records = query_pay_records(rst_id)
    pay_record_ids = [p.id for p in pay_records]
    pay_record_map = {p.id: p.created_at for p in pay_records}

    paylogs = query_paylog(pay_record_ids, activity_id, activity_category_id,
                           offset, limit)
    record_process_ids = get_max_subsidy_process_record_ids(pay_record_ids)

    total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id)

    record_process_logs = query_process_records_by_ids(
        [p[0] for p in record_process_ids])
    process_log_map = {r.pay_record_id: r for r in record_process_logs}

    records = []
    for record in paylogs:
        new_record = {
            'record_id': record[0],
            'first_date': record[4],
            'last_date': record[5],
            'quantity': to_int(record[6]),
            'audit_time': pay_record_map[record[0]],
            'total_subsidy': to_float(record[7]),
            'activity_id': record[1],
            'activity_category_id': record[2],
        }
        process_log = process_log_map.get(record[0], None)

        new_record['card_id'] = process_log.card_id \
            if process_log else None
        new_record['cardholder_name'] = process_log.cardholder_name \
            if process_log else None

        if process_log:
            new_record['status'] = process_log.status
        elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED:
            new_record['status'] = 1
        else:
            raise Exception('Invalid pay process record status.')

        if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED:
            new_record['submit_time'] = process_log.processed_at
        elif new_record['status'] in [3, 4]:
            new_record['success_time'] = process_log.processed_at

        records.append(new_record)

    for record in records:
        # set activity name
        try:
            record['activity_name'] = act_base.get_name(
                record['activity_id'], record['activity_category_id'])
        except:
            # Fix history problem
            record['activity_name'] = ''

    record_results = set_null(records,
                              ['card_id', 'cardholder_name',
                               'audit_time', 'submit_time', 'success_time'])

    return record_results, total_num
Пример #8
0
def _format_certification(cert):
    cert.restaurant_id = to_int(cert.restaurant_id)
    cert.type = to_int(cert.type)
    cert.status = to_int(cert.status)
Пример #9
0
def _format_certification(cert):
    cert.restaurant_id = to_int(cert.restaurant_id)
    cert.type = to_int(cert.type)
    cert.status = to_int(cert.status)