예제 #1
0
def get_all_status():
    args = args_parser.parse_all()

    activity_payments = pay_base.get_all_activity_stats(args)

    # set restaurant name
    restaurants = rst_base.mget(
        [pay.get('restaurant_id') for pay in activity_payments])
    for index, payments in enumerate(activity_payments):
        payments['restaurant_name'] = restaurants[index].name
        if not restaurants[index].is_valid:
            payments['restaurant_name'] += u'(餐厅已无效)'

    activity_payments = pay_base.set_activity_names(activity_payments)
    activity_payments = pay_base.set_bank_card_exist_or_not(activity_payments)
    visible_city_ids = city_base.get_city_id_name_pairs_by_user()

    no_subsidy_indication, pay_fail_indication = pay_base.\
        get_failed_status_indication(args)

    return {
        'payments': activity_payments,
        'city_ids': visible_city_ids,
        'no_subsidy_indication': no_subsidy_indication,
        'pay_fail_indication': pay_fail_indication,
        'total_num': 0
    }
예제 #2
0
파일: cert.py 프로젝트: liuzelei/walis
def _assemble_cert_response(certs):
    if not certs:
        return []

    response_map = object2dict(certs)
    restaurant_ids = [r["restaurant_id"] for r in response_map]
    restaurants = rst_base.mget(restaurant_ids)
    restaurant_map = {r.id: r.name for r in restaurants}

    for index, rest in enumerate(restaurants):
        response_map[index]["restaurant_name"] = rest.name

    # process_records = record_base.mget_latest_record(restaurant_ids)
    # process_records = {"{0}".format(record.restaurant_id):record for record in process_records}

    for cert_dict in response_map:

        application_time = cert_dict["created_at"]
        process_record = record_base.get_latest_record(cert_dict["restaurant_id"])
        # process_record = process_records.get(
        #     cert_dict['restaurant_id'])

        if process_record:
            application_time = datetime2timestamp(process_record.created_at)

        cert_dict["application_time"] = application_time

        cert_dict["restaurant_name"] = restaurant_map.get(cert_dict["restaurant_id"], "")

    return response_map
예제 #3
0
def _assemble_cert_response(certs):
    if not certs:
        return []

    response_map = object2dict(certs)
    restaurant_ids = [r['restaurant_id'] for r in response_map]
    restaurants = rst_base.mget(restaurant_ids)
    restaurant_map = {r.id: r.name for r in restaurants}

    for index, rest in enumerate(restaurants):
        response_map[index]['restaurant_name'] = rest.name

    # process_records = record_base.mget_latest_record(restaurant_ids)
    # process_records = {"{0}".format(record.restaurant_id):record for record in process_records}

    for cert_dict in response_map:

        application_time = cert_dict['created_at']
        process_record = record_base.get_latest_record(
            cert_dict['restaurant_id'])
        # process_record = process_records.get(
        #     cert_dict['restaurant_id'])

        if process_record:
            application_time = \
                datetime2timestamp(process_record.created_at)

        cert_dict['application_time'] = application_time

        cert_dict['restaurant_name'] = \
            restaurant_map.get(cert_dict['restaurant_id'], '')

    return response_map
예제 #4
0
def get_rst_not_in_charge(user_id, rst_ids):
    region_struct = get_direct_struct(user_id)
    city_ids = set(getattr(region_struct, 'city_ids', []))
    region_ids = set(getattr(region_struct, 'region_ids', []))
    rg_ids = set(getattr(region_struct, 'region_group_ids', []))

    rst_to_clean = copy.copy(rst_ids)

    if city_ids:
        rsts = rst_base.mget(rst_ids)
        rst_to_clean = [rst.id for rst in rsts if rst.city_id not in city_ids]

    if rg_ids:
        with thrift_client('ers') as ers:
            ex_regions = ers.get_regions_by_region_group_ids(rg_ids)
            ex_region_ids = set([r.id for r in ex_regions])
        if ex_region_ids:
            region_ids |= ex_region_ids

    if not region_ids:
        return rst_to_clean

    with thrift_client('ers') as ers:
        rst_region_map = ers.get_restaurant_region_map(rst_to_clean)

    for rst_id, region_id in rst_region_map.items():
        if region_id in region_ids:
            rst_to_clean.remove(rst_id)

    return rst_to_clean
예제 #5
0
def get_rst_not_in_charge(user_id, rst_ids):
    region_struct = get_direct_struct(user_id)
    city_ids = set(getattr(region_struct, 'city_ids', []))
    region_ids = set(getattr(region_struct, 'region_ids', []))
    rg_ids = set(getattr(region_struct, 'region_group_ids', []))

    rst_to_clean = copy.copy(rst_ids)

    if city_ids:
        rsts = rst_base.mget(rst_ids)
        rst_to_clean = [rst.id for rst in rsts if rst.city_id not in city_ids]

    if rg_ids:
        with thrift_client('ers') as ers:
            ex_regions = ers.get_regions_by_region_group_ids(rg_ids)
            ex_region_ids = set([r.id for r in ex_regions])
        if ex_region_ids:
            region_ids |= ex_region_ids

    if not region_ids:
        return rst_to_clean

    with thrift_client('ers') as ers:
        rst_region_map = ers.get_restaurant_region_map(rst_to_clean)

    for rst_id, region_id in rst_region_map.items():
        if region_id in region_ids:
            rst_to_clean.remove(rst_id)

    return rst_to_clean
예제 #6
0
def export_excel():
    args = args_parser.parse_all()

    activity_payments = pay_base.get_all_activity_stats(args)

    # set restaurant name
    restaurants = rst_base.mget(
        [pay.get('restaurant_id') for pay in activity_payments])
    for index, payments in enumerate(activity_payments):
        payments['restaurant_name'] = restaurants[index].name

    activity_payments = pay_base.set_activity_names(activity_payments)
    activity_payments = pay_base.set_act_category_names(activity_payments)

    temp_file = tempfile.TemporaryFile()
    workbook = generate_excel(activity_payments, u'活动打款审核记录', (
        ('restaurant_id', u'餐厅id'),
        ('restaurant_name', u'餐厅名称'),
        ('activity_name', u'活动名称'),
        ('activity_id', u'活动id'),
        ('first_date', u'起始日期'),
        ('last_date', u'结束日期'),
        ('activity_category_id', u'活动类别'),
        ('total_subsidy', u'打款总额'),
        ('quantity', u'数量'),
    ))
    workbook.save(temp_file)

    temp_file.seek(0)
    response = send_file(temp_file,
                         as_attachment=True,
                         mimetype='application/vnd.ms-excel',
                         attachment_filename='活动打款审核记录.xls',
                         add_etags=False)

    temp_file.seek(0, os.SEEK_END)
    size = temp_file.tell()
    temp_file.seek(0)
    response.headers.extend({
        'Content-Length': size,
        'Cache-Control': 'no-cache'
    })
    return response
예제 #7
0
def get_pending_status():
    args = args_parser.parse_all()

    audit_enabled = pay_base.get_audit_status()
    activity_payments = pay_base.get_pending_activity_stats(args)

    restaurants = rst_base.mget(
        [pay.get('restaurant_id') for pay in activity_payments])
    rest_map = {r.id: r.name for r in restaurants}
    for index, payments in enumerate(activity_payments):
        payments['restaurant_name'] = rest_map.get(payments['restaurant_id'],
                                                   u'')

    activity_payments = pay_base.set_activity_names(activity_payments)
    activity_payments = pay_base.set_bank_card_exist_or_not(activity_payments)

    final_payments = {}
    for act_pay in activity_payments:
        payment = final_payments.get(act_pay['restaurant_id'])
        if payment:
            payment['activities'].append({
                'activity_name':
                act_pay['activity_name'],
                'activity_id':
                act_pay['activity_id'],
                'activity_category_id':
                act_pay['activity_category_id'],
                'first_date':
                act_pay['first_date'],
                'last_date':
                act_pay['last_date'],
                'quantity':
                act_pay['quantity'],
                'total_subsidy':
                act_pay['total_subsidy']
            })
        else:
            act_pay['activities'] = [{
                'activity_name':
                act_pay['activity_name'],
                'activity_id':
                act_pay['activity_id'],
                'activity_category_id':
                act_pay['activity_category_id'],
                'first_date':
                act_pay['first_date'],
                'last_date':
                act_pay['last_date'],
                'quantity':
                act_pay['quantity'],
                'total_subsidy':
                act_pay['total_subsidy']
            }]
            act_pay.__delitem__('activity_id')
            act_pay.__delitem__('activity_category_id')
            act_pay.__delitem__('activity_name')
            act_pay.__delitem__('first_date')
            act_pay.__delitem__('last_date')
            act_pay.__delitem__('quantity')
            act_pay.__delitem__('total_subsidy')
            final_payments[act_pay['restaurant_id']] = act_pay

    return {
        'payments': final_payments.values(),
        'audit_enabled': audit_enabled,
        'total_num': 0
    }