Esempio n. 1
0
def get_success_pay_activities(restaurant_id):
    """
    获取指定餐厅的所有活动名称
    """
    activities = get_pay_activities_by_restaurant(restaurant_id)

    results = [{'activity_id': act[0],
                'activity_category_id': act[1],
                'activity_name': ''}
               for act in activities]

    for act in results:
        if act['activity_category_id'] == \
                SubsidyPayRecord.CATEGORY_FOOD_ACTIVITY:
            try:
                with thrift_client('ers') as ers:
                    act['activity_name'] =\
                        ers.get_food_activity(act['activity_id']).name
            except:
                act['activity_name'] = ''

        elif act['activity_category_id'] == \
                SubsidyPayRecord.CATEGORY_RESTAURANT_ACTIVITY:
            try:
                with thrift_client('ers') as ers:
                    act['activity_name'] = get_restaurant_activity_name(
                        ers.get_restaurant_activity(act['activity_id']))
            except:
                act['activity_name'] = ''

    return results
Esempio n. 2
0
def get_success_pay_activities(restaurant_id):
    """
    获取指定餐厅的所有活动名称
    """
    activities = get_pay_activities_by_restaurant(restaurant_id)

    results = [{
        'activity_id': act[0],
        'activity_category_id': act[1],
        'activity_name': ''
    } for act in activities]

    for act in results:
        if act['activity_category_id'] == \
                SubsidyPayRecord.CATEGORY_FOOD_ACTIVITY:
            try:
                with thrift_client('ers') as ers:
                    act['activity_name'] =\
                        ers.get_food_activity(act['activity_id']).name
            except:
                act['activity_name'] = ''

        elif act['activity_category_id'] == \
                SubsidyPayRecord.CATEGORY_RESTAURANT_ACTIVITY:
            try:
                with thrift_client('ers') as ers:
                    act['activity_name'] = get_restaurant_activity_name(
                        ers.get_restaurant_activity(act['activity_id']))
            except:
                act['activity_name'] = ''

    return results
Esempio n. 3
0
def get_name(activity_id, category_id):
    ACTIVITY_CATEGORY = thirdparty_svc.ers.SubsidyConst()
    if category_id == ACTIVITY_CATEGORY.CATEGORY_RESTAURANT_ACTIVITY:
        restaurant_activity = rst_activity.get(activity_id)
        return get_restaurant_activity_name(restaurant_activity)
    elif category_id == ACTIVITY_CATEGORY.CATEGORY_FOOD_ACTIVITY:
        return food_activity.get(activity_id).name
Esempio n. 4
0
def get_by_city_and_period():
    """ [GET] get restaurant-activities by city_ids and
        start-date and end-date """
    rest_activity_query = thirdparty_svc.ers.TRestaurantActivityQuery()
    args_spec = {
        'city_ids': Arg([], allow_missing=True),
        'begin_date': Arg(str, allow_missing=True),
        'end_date': Arg(str, allow_missing=True),
        'overdue': Arg(bool, allow_missing=True),
    }
    args = args_parser.parse(args_spec, request)

    city_ids = args.get('city_ids', [])

    if not coffee.hr_permission.isPermittedToThis(
            context=current_user.auth_context,
            permission=auth_map_admin['ACT_RST_ADMIN']):
        user_city_ids = current_user.utp_city_ids
        if city_ids:
            city_ids = list(set(city_ids + user_city_ids))
        else:
            city_ids = user_city_ids

    rest_activity_query.city_ids = city_ids
    rest_activity_query.begin_date = args.get('begin_date', None)
    rest_activity_query.end_date = args.get('end_date', None)
    rest_activity_query.limit = 1000
    overdue = args.get('overdue', None)

    with thrift_client('ers') as ers_client:
        restaurant_activities = ers_client.query_restaurant_activity_for_admin(
            rest_activity_query)

    if overdue is not None:
        today = date.today()
        if overdue:
            restaurant_activities = [
                act for act in restaurant_activities if _overdue(act, today)
            ]
        else:
            restaurant_activities = [
                act for act in restaurant_activities
                if not _overdue(act, today)
            ]

    total_num = len(restaurant_activities)
    rest_activities_page = paging(restaurant_activities)
    for act in rest_activities_page:
        act.activity_name = get_restaurant_activity_name(act)

    return {
        'restaurant_activities': rest_activities_page,
        'total_num': total_num
    }
Esempio n. 5
0
def get_by_city_and_period():
    """ [GET] get restaurant-activities by city_ids and
        start-date and end-date """
    rest_activity_query = thirdparty_svc.ers.TRestaurantActivityQuery()
    args_spec = {
        'city_ids': Arg([], allow_missing=True),
        'begin_date': Arg(str, allow_missing=True),
        'end_date': Arg(str, allow_missing=True),
        'overdue': Arg(bool, allow_missing=True),
    }
    args = args_parser.parse(args_spec, request)

    city_ids = args.get('city_ids', [])

    if not coffee.hr_permission.isPermittedToThis(context=current_user.auth_context,
                                                  permission=auth_map_admin['ACT_RST_ADMIN']):
        user_city_ids = current_user.utp_city_ids
        if city_ids:
            city_ids = list(set(city_ids + user_city_ids))
        else:
            city_ids = user_city_ids

    rest_activity_query.city_ids = city_ids
    rest_activity_query.begin_date = args.get('begin_date', None)
    rest_activity_query.end_date = args.get('end_date', None)
    rest_activity_query.limit = 1000
    overdue = args.get('overdue', None)

    with thrift_client('ers') as ers_client:
        restaurant_activities = ers_client.query_restaurant_activity_for_admin(
            rest_activity_query)

    if overdue is not None:
        today = date.today()
        if overdue:
            restaurant_activities = [act for act in restaurant_activities if
                                     _overdue(act, today)]
        else:
            restaurant_activities = [act for act in restaurant_activities if
                                     not _overdue(act, today)]

    total_num = len(restaurant_activities)
    rest_activities_page = paging(restaurant_activities)
    for act in rest_activities_page:
        act.activity_name = get_restaurant_activity_name(act)

    return {
        'restaurant_activities': rest_activities_page,
        'total_num': total_num
    }
Esempio n. 6
0
def get_activity_name(activity_id, category_id):
    activity_name = ''
    try:
        activity = act_base.get(activity_id, category_id)
    except:
        return u'活动不存在'

    ACTIVITY_CATEGORY = thirdparty_svc.ers.SubsidyConst()
    if category_id == ACTIVITY_CATEGORY.CATEGORY_RESTAURANT_ACTIVITY:
        activity_name = get_restaurant_activity_name(activity)
        if activity_name:
            try:
                activity_name = activity_name.decode('utf-8')
            except Exception:
                pass
        else:
            activity_name = ''
    elif category_id == ACTIVITY_CATEGORY.CATEGORY_FOOD_ACTIVITY:
        activity_name = activity.name

    return activity_name
Esempio n. 7
0
 def create_name(acty):
     setattr(acty, 'name', get_restaurant_activity_name(acty))
     return acty
Esempio n. 8
0
 def create_name(acty):
     setattr(acty, 'name', get_restaurant_activity_name(acty))
     return acty