Exemple #1
0
def set_user_bank_card(activity_payments):
    restaurant_ids = [payment['restaurant_id']
                      for payment in activity_payments]

    with thrift_client('eus') as eus:
        bank_card_map = eus.mget_bankcard_by_restaurant(restaurant_ids)

    with thrift_client('ers') as ers:
        bank_card_map2 = ers.mget_restaurant_bankcard(restaurant_ids)

    for payment in activity_payments:
        payment['have_bank_card'] = False
        card_id = cardholder_name = ''
        user_bank_card = bank_card_map.get(payment['restaurant_id'])
        if user_bank_card is not None:
            card_id = user_bank_card.card_id
            cardholder_name = user_bank_card.cardholder_name
        else:
            user_bank_card2 = bank_card_map2.get(payment['restaurant_id'])
            if user_bank_card2 is not None:
                card_id = user_bank_card2.card_id
                cardholder_name = user_bank_card2.cardholder_name

        payment['card_id'] = card_id
        payment['cardholder_name'] = cardholder_name

    return activity_payments
Exemple #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
Exemple #3
0
    def get_restaurant_ids_in_charge(self):
        # if super admin
        if self.is_super_admin():
            return None

        with thrift_client('ers') as ers:
            user_struct = ers.get_direct_struct(self.id)

        # if city.admin
        if user_struct.city_ids:
            return None

        region_ids = []
        # if region_group.admin
        if user_struct.region_group_ids:
            with thrift_client('ers') as ers:
                regions = ers.get_regions_by_region_group_ids(
                    user_struct.region_group_ids)
            region_ids = [region.id for region in regions]

        # if region.admin
        if user_struct.region_ids:
            region_ids.extend(user_struct.region_ids)
            region_ids = list(set(region_ids))

        with thrift_client('ers') as ers:
            restaurant_ids = ers.mget_restaurant_in_region(region_ids, True)

        return restaurant_ids
Exemple #4
0
def get_city_ids_or_restaurant_ids_by_user():
    """ return [city_ids,], [restaurant_ids] """
    user_id = current_user.id

    # if super admin
    if current_user.is_super_admin():
        return None, None

    with thrift_client('ers') as ers:
        user_struct = ers.get_direct_struct(user_id)

    # if city.admin
    if user_struct.city_ids:
        return user_struct.city_ids, None

    region_ids = []
    # if region_group.admin
    if user_struct.region_group_ids:
        with thrift_client('ers') as ers:
            regions = ers.get_regions_by_region_group_ids(
                user_struct.region_group_ids)
        region_ids = [region.id for region in regions]

    # if region.admin
    if user_struct.region_ids:
        region_ids.extend(user_struct.region_ids)
        region_ids = list(set(region_ids))

    with thrift_client('ers') as ers:
        restaurant_ids = ers.mget_restaurant_in_region(region_ids, True)

    return None, restaurant_ids
Exemple #5
0
    def get_all_city_ids(self):
        if self._all_city_ids is None:
            if self._user_struct is None:
                self._user_struct = self.get_user_struct()
                # if city.admin
            user_city_ids = self._user_struct.city_ids
            if user_city_ids:
                self._all_city_ids = user_city_ids
                return user_city_ids
            # if region_group.admin
            if self._user_struct.region_group_ids:
                with thrift_client('ers') as ers:
                    region_groups = ers.mget_region_group(
                        self._user_struct.region_group_ids)
                user_city_ids = list(
                    set([
                        region_group.city_id for region_group in region_groups
                    ]))
            # if region.admin
            if self._user_struct.region_ids:
                with thrift_client('ers') as ers:
                    regions = ers.mget_region(self._user_struct.region_ids)

                user_city_ids_by_region = [
                    v.city_id for k, v in regions.iteritems()
                ]
                user_city_ids = list(
                    set(user_city_ids_by_region + user_city_ids))

            if user_city_ids:
                self._all_city_ids = user_city_ids
                return user_city_ids
        return self._all_city_ids
Exemple #6
0
    def get_all_city_ids(self):
        if self._all_city_ids is None:
            if self._user_struct is None:
                self._user_struct = self.get_user_struct()
                # if city.admin
            user_city_ids = self._user_struct.city_ids
            if user_city_ids:
                self._all_city_ids = user_city_ids
                return user_city_ids
            # if region_group.admin
            if self._user_struct.region_group_ids:
                with thrift_client('ers') as ers:
                    region_groups = ers.mget_region_group(self._user_struct.region_group_ids)
                user_city_ids = list(set([region_group.city_id
                                          for region_group in region_groups]))
            # if region.admin
            if self._user_struct.region_ids:
                with thrift_client('ers') as ers:
                    regions = ers.mget_region(self._user_struct.region_ids)

                user_city_ids_by_region = [v.city_id for k,v in regions.iteritems()]
                user_city_ids = list(set(user_city_ids_by_region + user_city_ids))

            if user_city_ids:
                self._all_city_ids = user_city_ids
                return user_city_ids
        return self._all_city_ids
Exemple #7
0
    def sget(pk):
        city = city_base.get(pk)

        district_query = thirdparty_svc.ers.TDistrictQuery()
        district_query.city_id = city['id']
        district_query.is_valid = True
        with thrift_client('ers') as ers:
            districts = ers.query_district(district_query)
            districts = any_to_raw(districts)

        zone_query = thirdparty_svc.ers.TZoneQuery()
        zone_query.city_id = city['id']
        zone_query.is_valid = True
        with thrift_client('ers') as ers:
            zones = ers.query_zone(zone_query)
            zones = any_to_raw(zones)

        [_district.__setitem__('_zones', []) for _district in districts]
        districts_map = {district['id']: district for district in districts}
        for zone in zones:
            district = districts_map.get(zone['district_id'], None)
            if district:
                district['_zones'].append(zone)
        city['_districts'] = districts
        return city
Exemple #8
0
    def sget(pk):
        city = city_base.get(pk)

        district_query = thirdparty_svc.ers.TDistrictQuery()
        district_query.city_id = city['id']
        district_query.is_valid = True
        with thrift_client('ers') as ers:
            districts = ers.query_district(district_query)
            districts = any_to_raw(districts)

        zone_query = thirdparty_svc.ers.TZoneQuery()
        zone_query.city_id = city['id']
        zone_query.is_valid = True
        with thrift_client('ers') as ers:
            zones = ers.query_zone(zone_query)
            zones = any_to_raw(zones)

        [_district.__setitem__('_zones', []) for _district in districts]
        districts_map = {district['id']: district for district in districts}
        for zone in zones:
            district = districts_map.get(zone['district_id'], None)
            if district:
                district['_zones'].append(zone)
        city['_districts'] = districts
        return city
Exemple #9
0
def set_food_activity():
    """
    设置食物活动
    """
    restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \
    food_id = parse_args1()
    _food_ids = copy.copy(food_ids)
    with thrift_client('ers') as ers:
        for _id in restaurant_ids:
            food_query = thirdparty_svc.ers.TFoodQuery()
            food_query.restaurant_id = _id
            food_query.is_valid = True
            food_query.limit = 1000
            foods = ers.query_food(food_query)
            _food_ids.extend([food.id for food in foods])
        for _id in category_ids:
            food_query = thirdparty_svc.ers.TFoodQuery()
            food_query.category_id = _id
            food_query.is_valid = True
            food_query.limit = 1000
            foods = ers.query_food(food_query)
            _food_ids.extend([food.id for food in foods])
    _food_ids = list(set(_food_ids))
    act_id = request.json.get('activity_id', None)
    weekdays = request.json.get('weekdays', [])
    with thrift_client('ers') as ers:
        if act_id:
            ers.add_food_activity(act_id, _food_ids, weekdays)
        else:
            ers.clear_food_activity(_food_ids, weekdays)
    return ''
Exemple #10
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
Exemple #11
0
def set_food_activity():
    """
    设置食物活动
    """
    restaurant_ids, category_ids, food_ids, restaurant_id, category_id, \
    food_id = parse_args1()
    _food_ids = copy.copy(food_ids)
    with thrift_client('ers') as ers:
        for _id in restaurant_ids:
            food_query = thirdparty_svc.ers.TFoodQuery()
            food_query.restaurant_id = _id
            food_query.is_valid = True
            food_query.limit = 1000
            foods = ers.query_food(food_query)
            _food_ids.extend([food.id for food in foods])
        for _id in category_ids:
            food_query = thirdparty_svc.ers.TFoodQuery()
            food_query.category_id = _id
            food_query.is_valid = True
            food_query.limit = 1000
            foods = ers.query_food(food_query)
            _food_ids.extend([food.id for food in foods])
    _food_ids = list(set(_food_ids))
    act_id = request.json.get('activity_id', None)
    weekdays = request.json.get('weekdays', [])
    with thrift_client('ers') as ers:
        if act_id:
            ers.add_food_activity(act_id, _food_ids, weekdays)
        else:
            ers.clear_food_activity(_food_ids, weekdays)
    return ''
Exemple #12
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
Exemple #13
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
Exemple #14
0
    def get_restaurant_ids_in_charge(self):
        # if super admin
        if self.is_super_admin():
            return None

        with thrift_client('ers') as ers:
            user_struct = ers.get_direct_struct(self.id)

        # if city.admin
        if user_struct.city_ids:
            return None

        region_ids = []
        # if region_group.admin
        if user_struct.region_group_ids:
            with thrift_client('ers') as ers:
                regions = ers.get_regions_by_region_group_ids(
                    user_struct.region_group_ids)
            region_ids = [region.id for region in regions]

        # if region.admin
        if user_struct.region_ids:
            region_ids.extend(user_struct.region_ids)
            region_ids = list(set(region_ids))

        with thrift_client('ers') as ers:
            restaurant_ids = ers.mget_restaurant_in_region(region_ids, True)

        return restaurant_ids
Exemple #15
0
def get(food_id):
    food_id = int(food_id)
    # todo image_size未使用!
    image_size = request.args.get('image_size', None)
    with thrift_client('ers') as ers:
        food = ers.master_get_food(food_id)
        image_hash = food.image_hash
        image_path = ''
        if image_hash:
            with thrift_client('fuss') as fuss:
                image_path = fuss.file_get_sized(image_hash, image_size)
    return image_path
Exemple #16
0
def get(food_id):
    food_id = int(food_id)
    # todo image_size未使用!
    image_size = request.args.get('image_size', None)
    with thrift_client('ers') as ers:
        food = ers.master_get_food(food_id)
        image_hash = food.image_hash
        image_path = ''
        if image_hash:
            with thrift_client('fuss') as fuss:
                image_path = fuss.file_get_sized(image_hash, image_size)
    return image_path
Exemple #17
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 []
Exemple #18
0
    def get_user_struct(self):
        if self._user_struct is None:
            with thrift_client('ers') as ers:
                self._user_struct = ers.get_direct_struct(self.id)

        region_ids = []
        if self._user_struct.region_group_ids:
            with thrift_client('ers') as ers:
                regions = ers.get_regions_by_region_group_ids(
                    self._user_struct.region_group_ids)
            region_ids = [region.id for region in regions]
        if region_ids:
            self._user_struct.region_ids.extend(region_ids)
        return self._user_struct
Exemple #19
0
 def get_suspicious_orders(cls, restaurant_id, date, **kwargs):
     query_kwargs = {
         'restaurant_id': restaurant_id,
         'date': date
     }
     result = zeus_query('eyes', 'walle_get_suspicious_orders',
                         thirdparty_svc.eyes.TWalleSuspiciousOrderQuery,
                         **query_kwargs)
     # for order in result:
     # order['id'] = order['_id']
     order_ids = [order['id'] for order in result]
     orders = OrderBase.mget(order_ids)
     orders = {order['id']: order for order in orders}
     with thrift_client('eos') as eos:
         orders_info = eos.mget_order_info(order_ids)
         orders_info = getresult_to_raw(orders_info)
     orders_info = {info['order_id']: info for info in orders_info}
     for order in result:
         order.update(orders[order['id']])
         order.update(orders_info[order['id']])
     for order in result:
         if order['phone_rating'] == 1:
             order['is_new_user'] = True
         else:
             order['is_new_user'] = False
     phones = [order['phone'] for order in orders.values()]
     phones_ban_status_map = {phone: PhoneBanBase.get_phone_ban_status(phone)
                              for phone in phones}
     user_ids = [order['user_id'] for order in orders.values()]
     with thrift_client('eus') as eus_client:
         users = eus_client.mget(user_ids)
         users = any_to_raw(users)
     users_map = {user['id']: user for user in users}
     for order in result:
         order['phone_ban_status'] = phones_ban_status_map[order['phone']]
         order['user_is_active'] = users_map[order['user_id']]['is_active']
     for order in result:
         try:
             better_json = json.loads(order['better_json'])
             better_json = flatten(better_json)
             subsidy = 0
             for _better_what in better_json:
                 price = _better_what.get('price', 0)
                 if price < 0:
                     subsidy += price
             order['subsidy'] = abs(subsidy)
             order['id'] = unicode(order['id'])
         except:
             continue
     return result
Exemple #20
0
def post_or_put(activity_id=None):
    if activity_id is not None:
        activity_id = int(activity_id)
    activity_json = request.json
    with thrift_client('ers') as ers_client:
        if activity_id:
            with thrift_client('ers') as ers:
                activity = ers.get_restaurant_activity(activity_id)
            activity = _restaurant_activity_json2ttype(activity_json, activity)
            ers_client.update_restaurant_activity(activity_id, activity)
        else:
            activity = _restaurant_activity_json2ttype(activity_json)
            ers_client.add_restaurant_activity(activity)
        return ''
Exemple #21
0
def post_or_put(activity_id=None):
    if activity_id is not None:
        activity_id = int(activity_id)
    activity_json = request.json
    with thrift_client('ers') as ers_client:
        if activity_id:
            with thrift_client('ers') as ers:
                activity = ers.get_restaurant_activity(activity_id)
            activity = _restaurant_activity_json2ttype(activity_json, activity)
            ers_client.update_restaurant_activity(activity_id, activity)
        else:
            activity = _restaurant_activity_json2ttype(activity_json)
            ers_client.add_restaurant_activity(activity)
        return ''
Exemple #22
0
    def get_user_struct(self):
        if self._user_struct is None:
            with thrift_client('ers') as ers:
                self._user_struct = ers.get_direct_struct(self.id)

        region_ids = []
        if self._user_struct.region_group_ids:
            with thrift_client('ers') as ers:
                regions = ers.get_regions_by_region_group_ids(
                    self._user_struct.region_group_ids)
            region_ids = [region.id for region in regions]
        if region_ids:
            self._user_struct.region_ids.extend(region_ids)
        return self._user_struct
Exemple #23
0
 def get_suspicious_orders(cls, restaurant_id, date, **kwargs):
     query_kwargs = {'restaurant_id': restaurant_id, 'date': date}
     result = zeus_query('eyes', 'walle_get_suspicious_orders',
                         thirdparty_svc.eyes.TWalleSuspiciousOrderQuery,
                         **query_kwargs)
     # for order in result:
     # order['id'] = order['_id']
     order_ids = [order['id'] for order in result]
     orders = OrderBase.mget(order_ids)
     orders = {order['id']: order for order in orders}
     with thrift_client('eos') as eos:
         orders_info = eos.mget_order_info(order_ids)
         orders_info = getresult_to_raw(orders_info)
     orders_info = {info['order_id']: info for info in orders_info}
     for order in result:
         order.update(orders[order['id']])
         order.update(orders_info[order['id']])
     for order in result:
         if order['phone_rating'] == 1:
             order['is_new_user'] = True
         else:
             order['is_new_user'] = False
     phones = [order['phone'] for order in orders.values()]
     phones_ban_status_map = {
         phone: PhoneBanBase.get_phone_ban_status(phone)
         for phone in phones
     }
     user_ids = [order['user_id'] for order in orders.values()]
     with thrift_client('eus') as eus_client:
         users = eus_client.mget(user_ids)
         users = any_to_raw(users)
     users_map = {user['id']: user for user in users}
     for order in result:
         order['phone_ban_status'] = phones_ban_status_map[order['phone']]
         order['user_is_active'] = users_map[order['user_id']]['is_active']
     for order in result:
         try:
             better_json = json.loads(order['better_json'])
             better_json = flatten(better_json)
             subsidy = 0
             for _better_what in better_json:
                 price = _better_what.get('price', 0)
                 if price < 0:
                     subsidy += price
             order['subsidy'] = abs(subsidy)
             order['id'] = unicode(order['id'])
         except:
             continue
     return result
Exemple #24
0
def get(id_or_ids):
    with thrift_client('ers') as ers:
        if isinstance(id_or_ids, (tuple, list)):
            result = ers.mget_food_activity(id_or_ids)
        else:
            result = ers.get_food_activity(id_or_ids)
    return result
Exemple #25
0
 def is_banned(cls, phone):
     with thrift_client('eos') as eos_client:
         result = eos_client.check_phones_in_blacklist([phone, ])
         if result:
             return cls.BLACK
         else:
             return cls.WHITE
Exemple #26
0
def get_city_id_name_pairs_by_user():
    # if super admin
    if current_user.is_super_admin():
        return {city.id: city.name for city in get_all_cities()}

    with thrift_client('ers') as ers:
        user_struct = ers.get_direct_struct(current_user.id)

    # if city.admin
    if user_struct.city_ids:
        with thrift_client('ers') as ers:
            cities = ers.mget_city(user_struct.city_ids).values()
        return {city.id: city.name for city in cities}

    # do not have cities
    return []
Exemple #27
0
def reject_payment(payment_dict):
    restaurant_ids_set = set()
    [restaurant_ids_set.update(restaurant_ids) for restaurant_ids in
     payment_dict.values()]
    with thrift_client('eos') as eos:
        for restaurant_id in restaurant_ids_set:
            eos.doubt_activity_subsidy_stats_new(restaurant_id)
Exemple #28
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'}
Exemple #29
0
def get_by_username(username):
    try:
        with thrift_client('eus') as eus:
            user = eus.get_by_username(username)
    except thirdparty_svc.eus.EUSUserException:
        user = {}
    return user
Exemple #30
0
def delete(food_id):
    food_id = int(food_id)
    with thrift_client('ers') as ers:
        food = thirdparty_svc.ers.TFood()
        food.image_hash = ''
        result = ers.save_food(food_id, food)
    return ''
Exemple #31
0
def get_bankcard(user_id, status=None):
    with thrift_client("eus") as eus:
        try:
            bankcard = eus.get_bankcard(user_id, status)
            return bankcard
        except thirdparty_svc.eus.EUSUserException:
            return None
Exemple #32
0
def query_restaurant(city_ids=None, region_ids=None, is_premium=False, is_valid=True, offset=None, limit=None):
    query = _create_restaurant_query(city_ids, region_ids, is_premium,
                                     is_valid, offset, limit)
    with thrift_client('ers') as ers:
        result = ers.search_filter_restaurant(query)
        rst_list = json.loads(result)['hits']
    return rst_list
Exemple #33
0
def get(restaurant_id):
    restaurant_id = int(restaurant_id)

    with thrift_client('ers') as ers_client:
        restaurant = ers_client.get(restaurant_id)
        fix_restaurant_attribute(restaurant)
        return restaurant
Exemple #34
0
def voiceorder_job():
    """ query all unprocessed orders from now

    """

    now = time.time()
    ORDER_CONST = thirdparty_svc.eos.ElemeOrderConst
    order_trigger_time = int(now - settings.send_vc_deadline)

    order_query = thirdparty_svc.eos.TOrderQuery()
    order_query.from_datetime = order_trigger_time
    order_query.statuses = (ORDER_CONST.STATUS_PROCESSING,)
    order_query.order_modes = (ORDER_CONST.ORDER_MODE_ELEME,)
    order_query.limit = 1000
    with thrift_client('eos') as eos:
        orders = _filter_orders(eos.query_order(order_query))

    log.info('total {} unprocessed sms orders.'.format(len(orders)))
    if _trigger_voicecall(
            orders,
            order_trigger_time,
            order_trigger_time + settings.voice_order_interval - 1):

        log.info('triggered voicecall with orders {}'.format(orders))
        enqueue(BSTALK_TUBES['tube_vo'], voice_order_handler, orders)
Exemple #35
0
def pack_recruits(recruits):
    recruits = [recruit for recruit in recruits if
                recruit.restaurant_id is not None]

    package = {'recruits': []}
    restaurant_ids = list(
        set([recruit.restaurant_id for recruit in recruits]))
    with thrift_client('ers') as ers:
        restaurants = ers.mget(restaurant_ids)

    restaurant_map = {}
    for r in restaurants:
        restaurant_map[r.id] = [r.name, r.phone]

    for index, recruit in enumerate(recruits):
        if recruit.restaurant_id < 0:
            continue
        recruit_map = {}
        for attr in attr_to_display:
            recruit_map[attr] = getattr(recruit, attr)
        recruit_map['name'] = restaurant_map.get(recruit.restaurant_id, ' ')[0]
        recruit_map['phone'] = restaurant_map.get(recruit.restaurant_id, ' ')[-1]
        recruit_map['salary'] = float(recruit_map['salary'])
        package['recruits'].append(recruit_map)

    return package['recruits']
Exemple #36
0
def update_restaurant(rst_id, user_id, **rst_struct):
    rst = thirdparty_svc.ers.TRestaurant()
    for k, v in rst_struct.iteritems():
        if hasattr(rst, k):
            setattr(rst, k, v)
    with thrift_client('ers') as ers:
        ers.update_restaurant(rst_id, user_id, rst)
Exemple #37
0
def mget(region_ids, return_map=False):
    with thrift_client('ers') as ers:
        region_map = ers.mget_region(region_ids)

    if return_map:
        return region_map
    return region_map.values()
Exemple #38
0
def query_verify_code_by_mobile(mobile):
    with thrift_client('sms') as sms:
        result = sms.query_verify_code_by_mobile(mobile)
    for sms in result:
        sms.content = u'您在饿了么上的验证码{},请在5分钟内输入。' \
                      u'如非本人操作请忽略本短信'.format(sms.code)
    return sorted(result, key=lambda r: r.created_at, reverse=True)
Exemple #39
0
def query_regions(region_ids=None,
                  city_ids=None,
                  type_codes=None,
                  search=None,
                  show_all=None):
    """

    :param region_ids:
    :param city_ids:
    :param type_codes: {CBD:1, SCHOOL:2}
    :param search: search by region_name
    :param show_all: whether show regions whose id < 0
    :return:
    """
    query = thirdparty_svc.ers.TRegionQuery()
    query.search = search
    query.show_all = show_all
    query.city_ids = city_ids
    query.region_ids = region_ids
    query.type_codes = type_codes

    with thrift_client('ers') as ers:
        result = ers.query_region(query)

    result = any_to_raw(result)
    result = any_to_dic(result)
    return result
Exemple #40
0
def get(id_or_ids):
    with thrift_client('ers') as ers:
        if isinstance(id_or_ids, (tuple, list)):
            result = ers.mget_restaurant_activity(id_or_ids)
        else:
            result = ers.get_restaurant_activity(id_or_ids)
    return result
Exemple #41
0
def approval_payment(payment_dict):
    restaurant_ids_set = set()
    [restaurant_ids_set.update(restaurant_ids) for restaurant_ids in
     payment_dict.values()]
    with thrift_client('eos') as eos:
        for restaurant_id in restaurant_ids_set:
            eos.generate_activity_subsidy_pay_record_new(restaurant_id)
Exemple #42
0
def food_category(restaurant_id):
    """
    获取餐厅菜单上所有分类
    """
    with thrift_client('ers') as ers:
        categories = ers.query_food_category_by_restaurant(restaurant_id)
        return categories
Exemple #43
0
def voice_call_handler(call_id):
    """ handle only one call each time. """
    STATUS_PROCESSING = thirdparty_svc.eos.ORDER_STATUS.STATUS_PROCESSING
    voice_call = VoiceCall.get(call_id)
    if not voice_call:
        raise_user_exc(VOICE_CALL_NOT_FOUND, call_id=call_id)
    voice_orders = VoiceOrder.get_by_call_id(voice_call.id)

    # recheck
    with thrift_client('eos') as eos_client:
        order_ids = [order.order_id for order in voice_orders]
        t_orders = eos_client.mget(order_ids)

    t_orders = filter(
        lambda _o: _o.status_code == STATUS_PROCESSING,
        t_orders)
    t_order_ids = [order.id for order in t_orders]

    voice_orders = [v_order for v_order in voice_orders
                    if v_order.order_id in t_order_ids]

    if not voice_orders:
        return

    call_params = _generate_call_params(voice_call, voice_orders)
    call_status = _send_call(call_params)

    voice_call.call_status = call_status
Exemple #44
0
def food_activity_map(restaurant_id):
    """
    wait to add
    """
    with thrift_client('ers') as ers:
        _map = ers.get_weekday_food_activity_id_map([], restaurant_id)
        return _map
Exemple #45
0
def get_director_ids_by_area(region_ids=None,
                             region_group_ids=None,
                             city_ids=None):
    with thrift_client('ers') as ers:
        user_ids = ers.get_director_ids_by_area(region_ids, region_group_ids,
                                                city_ids)
    return user_ids
Exemple #46
0
def gets_by_userid(user_id):
    page_no, page_size = get_paging_params()
    t_query = thirdparty_svc.eus.THongbaoQuery()
    t_query.user_id = user_id
    t_query.statuses = [STATUS_UNUSED, STATUS_USED]
    t_query.offset = (page_no - 1) * page_size
    t_query.limit = page_size

    with thrift_client('eus') as eus:
        hongbaos = eus.query_hongbao(t_query)

    results = []
    disp_keys = [
        'sn', 'sum_condition', 'begin_date', 'end_date', 'amount',
        'used_amount'
    ]
    for hongbao in hongbaos:
        hongbao_dict = ttype2dict(hongbao, keys=disp_keys)

        hongbao_dict['left_amount'] =\
            hongbao_dict['amount'] - hongbao_dict['used_amount']

        if hongbao_dict['left_amount'] != 0:
            results.append(hongbao_dict)

    return results
Exemple #47
0
def file_upload_raw(buf,
                    extension,
                    sized=False,
                    watermark=False,
                    file_size=FILE_SIZE,
                    isprivate=False):

    fusshost = 'fuss'
    if isprivate:
        fusshost = 'fuss2'
    if watermark:
        sized = True
    with thrift_client(fusshost) as fuss:
        fuss_file = thirdparty_svc.fuss.FussFile()
        fuss_file.content = buf
        fuss_file.extension = extension

        if watermark:
            file_hash = fuss.file_upload_sized_with_watermarker(
                fuss_file, file_size)
        elif sized:
            file_hash = fuss.file_upload_sized(fuss_file, file_size)
        else:
            file_hash = fuss.file_upload(fuss_file)

    return file_hash
Exemple #48
0
def voice_order_handler(orders):
    """ save voice-call and voice-order """
    order_groups = defaultdict(list)
    for order in orders:
        order_groups[order.restaurant_id].append(order)

    for restaurant_id, orders in order_groups.items():
        orders = _validate_order(orders)
        if not orders:
            continue

        with thrift_client('ers') as ers:
            restaurant = ers.get(restaurant_id)
        restaurant_phone = get_rst_takeout_phone(restaurant)
        if not restaurant_phone:
            continue

        voice_call = VoiceCall.add(restaurant_id=restaurant_id,
                                   call_status=VoiceCall.STATUS_NOT_DIAL,
                                   created_at=datetime.now(),
                                   phone=restaurant_phone,
                                   flush=True)
        for order in orders:
            VoiceOrder.add(order_id=order.id,
                           status_code=order.status_code,
                           sequence_number=order.restaurant_number,
                           created_at=datetime.fromtimestamp(order.created_at),
                           call_id=voice_call.id)
        log.info('voice order received with restaurant_id [{}], call_id [{}]'.
                 format(restaurant_id, voice_call.id))
Exemple #49
0
def voice_call_handler(call_id):
    """ handle only one call each time. """
    STATUS_PROCESSING = thirdparty_svc.eos.ORDER_STATUS.STATUS_PROCESSING
    voice_call = VoiceCall.get(call_id)
    if not voice_call:
        raise_user_exc(VOICE_CALL_NOT_FOUND, call_id=call_id)
    voice_orders = VoiceOrder.get_by_call_id(voice_call.id)

    # recheck
    with thrift_client('eos') as eos_client:
        order_ids = [order.order_id for order in voice_orders]
        t_orders = eos_client.mget(order_ids)

    t_orders = filter(lambda _o: _o.status_code == STATUS_PROCESSING, t_orders)
    t_order_ids = [order.id for order in t_orders]

    voice_orders = [
        v_order for v_order in voice_orders if v_order.order_id in t_order_ids
    ]

    if not voice_orders:
        return

    call_params = _generate_call_params(voice_call, voice_orders)
    call_status = _send_call(call_params)

    voice_call.call_status = call_status
Exemple #50
0
def get_region_by_rst(rst_id):
    with thrift_client('ers') as ers:
        try:
            region = ers.get_region_by_restaurant(rst_id)
        except thirdparty_svc.ers.ERSUserException:
            region = None
    return region
Exemple #51
0
def voice_order_handler(orders):
    """ save voice-call and voice-order """
    order_groups = defaultdict(list)
    for order in orders:
        order_groups[order.restaurant_id].append(order)

    for restaurant_id, orders in order_groups.items():
        orders = _validate_order(orders)
        if not orders:
            continue

        with thrift_client('ers') as ers:
            restaurant = ers.get(restaurant_id)
        restaurant_phone = get_rst_takeout_phone(restaurant)
        if not restaurant_phone:
            continue

        voice_call = VoiceCall.add(restaurant_id=restaurant_id,
                                   call_status=VoiceCall.STATUS_NOT_DIAL,
                                   created_at=datetime.now(),
                                   phone=restaurant_phone,
                                   flush=True)
        for order in orders:
            VoiceOrder.add(order_id=order.id,
                           status_code=order.status_code,
                           sequence_number=order.restaurant_number,
                           created_at=datetime.fromtimestamp(order.created_at),
                           call_id=voice_call.id)
        log.info('voice order received with restaurant_id [{}], call_id [{}]'.
                 format(restaurant_id, voice_call.id))
Exemple #52
0
def update_restaurant(rst_id, user_id, **rst_struct):
    rst = thirdparty_svc.ers.TRestaurant()
    for k, v in rst_struct.iteritems():
        if hasattr(rst, k):
            setattr(rst, k, v)
    with thrift_client('ers') as ers:
        ers.update_restaurant(rst_id, user_id, rst)
Exemple #53
0
def update(cert):
    with thrift_client('ers') as ers:
        db_cert = ers.get_restaurant_certification(cert.restaurant_id)

    if not db_cert:
        raise_user_exc(CERT_UPDATE_ERR, restaurant_id=cert.restaurant_id)

    with thrift_client('ers') as ers:
        ers.update_restaurant_certification(cert)

    record_process_base.add(cert.restaurant_id,
                            cert.type,
                            cert.status,
                            STATUS_PENDING,
                            comment='修改认证信息')
    return ''