Example #1
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
Example #2
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
Example #3
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
Example #4
0
 def get(cls, pk_or_pks):
     with thrift_client('eos') as eos:
         if isinstance(pk_or_pks, (tuple, list)):
             result = eos.mget(pk_or_pks)
         else:
             result = eos.get_entry(pk_or_pks)
     result = any_to_raw(result)
     return result
Example #5
0
 def get(cls, pk_or_pks):
     with thrift_client('eos') as eos:
         if isinstance(pk_or_pks, (tuple, list)):
             result = eos.mget(pk_or_pks)
         else:
             result = eos.get_entry(pk_or_pks)
     result = any_to_raw(result)
     return result
Example #6
0
def get(pk_or_pks):
    with thrift_client('eus') as eus:
        if isinstance(pk_or_pks, (tuple, list)):
            pk_or_pks = list(set(pk_or_pks))
            result = eus.mget(pk_or_pks)
        else:
            result = eus.get(pk_or_pks)
    result = any_to_raw(result)
    return result
Example #7
0
def get(pk_or_pks):
    with thrift_client('eus') as eus:
        if isinstance(pk_or_pks, (tuple, list)):
            pk_or_pks = list(set(pk_or_pks))
            result = eus.mget(pk_or_pks)
        else:
            result = eus.get(pk_or_pks)
    result = any_to_raw(result)
    return result
Example #8
0
def zeus_query(service, func_name, query_type, **kwargs):
    """
    这个-.-额.等把第一个参数和第二个参数和在一起把...
    """
    with thrift_client(service) as client:
        func = getattr(client, func_name)
        q = dic_to_tobj(kwargs, query_type)
        result = func(q)
        result = any_to_raw(result)
        return result
Example #9
0
 def set_invalid(cls, order_id, reason_type, remark):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.eleme_process_order(
             order_id, thirdparty_svc.eos.ElemeOrderConst.STATUS_INVALID,
             current_user.id,
             thirdparty_svc.eos.OrderRecordConst.PROCESS_GROUP_ADMIN,
             remark, reason_type)
         result = any_to_raw(result)
     return result
Example #10
0
def gets():
    city_query = thirdparty_svc.ers.TCityQuery()
    city_query.is_valid = True
    with thrift_client('ers') as ers:
        cities = ers.query_city(city_query)
        cities = any_to_raw(cities)

    city_ids = [city['id'] for city in cities]
    return [city_manager_base.city_filter(city)
            for city in city_manager_base.mget(city_ids)]
Example #11
0
 def set_invalid(cls, order_id, reason_type, remark):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.eleme_process_order(order_id,
                                          thirdparty_svc.eos.ElemeOrderConst.STATUS_INVALID,
                                          current_user.id,
                                          thirdparty_svc.eos.OrderRecordConst.PROCESS_GROUP_ADMIN,
                                          remark,
                                          reason_type)
         result = any_to_raw(result)
     return result
Example #12
0
def gets():
    city_query = thirdparty_svc.ers.TCityQuery()
    city_query.is_valid = True
    with thrift_client('ers') as ers:
        cities = ers.query_city(city_query)
        cities = any_to_raw(cities)

    city_ids = [city['id'] for city in cities]
    return [
        city_manager_base.city_filter(city)
        for city in city_manager_base.mget(city_ids)
    ]
Example #13
0
 def set_valid(cls, order_id, ):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.eleme_process_order(
             order_id,
             thirdparty_svc.eos.ElemeOrderConst.STATUS_PROCESSED_AND_VALID,
             current_user.id,
             thirdparty_svc.eos.OrderRecordConst.PROCESS_GROUP_ADMIN,
             "",
             thirdparty_svc.eos.OrderInvalidDescConst.TYPE_OTHERS,
         )
         result = any_to_raw(result)
     return result
Example #14
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
Example #15
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
Example #16
0
def get_regions_by_city_id(city_id, type_code=None, show_all=None):
    with thrift_client('ers') as ers:
        region_query = thirdparty_svc.ers.TRegionQuery()
        region_query.city_ids = [city_id,]

        if type_code is not None:
            region_query.type_codes = [type_code]

        if show_all is not None:
            region_query.show_all = show_all

        result = ers.query_region(region_query)
        result = any_to_raw(result)
    result = any_to_dic(result)
    return result
Example #17
0
 def set_valid(
     cls,
     order_id,
 ):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.eleme_process_order(
             order_id,
             thirdparty_svc.eos.ElemeOrderConst.STATUS_PROCESSED_AND_VALID,
             current_user.id,
             thirdparty_svc.eos.OrderRecordConst.PROCESS_GROUP_ADMIN,
             "",
             thirdparty_svc.eos.OrderInvalidDescConst.TYPE_OTHERS,
         )
         result = any_to_raw(result)
     return result
Example #18
0
def get_regions_by_city_id(city_id, type_code=None, show_all=None):
    with thrift_client('ers') as ers:
        region_query = thirdparty_svc.ers.TRegionQuery()
        region_query.city_ids = [
            city_id,
        ]

        if type_code is not None:
            region_query.type_codes = [type_code]

        if show_all is not None:
            region_query.show_all = show_all

        result = ers.query_region(region_query)
        result = any_to_raw(result)
    result = any_to_dic(result)
    return result
Example #19
0
def get_struct(user_id):
    with thrift_client('ers') as ers:
        result = ers.get_direct_struct(user_id)
        result = getresult_to_raw(result)

        region_group_query = thirdparty_svc.ers.TRegionGroupQuery()
        region_group_query.city_ids = result.city_ids
        region_group_query.show_all = True

        region_groups_of_city = ers.query_region_group(region_group_query)
        region_groups_of_city = any_to_raw(region_groups_of_city)

        region_group_ids = result.region_group_ids
        region_group_ids.extend([obj['id'] for obj in region_groups_of_city])
        region_groups = ers.mget_region_group(region_group_ids).values()
        for region_group in region_groups:
            regions = ers.get_regions_by_region_group_ids([region_group.id])
            setattr(region_group,'_regions',regions)
        regions = ers.mget_region(result.region_ids).values()
        for region in regions:
            region_group_of_alone_region = ers.get_region_group_by_region(region.id)
            for region_group in region_groups:
                if region_group_of_alone_region.id == region_group.id:
                    region_group._regions.append(region)
            else:
                setattr(region_group_of_alone_region,'_regions',[region])
                region_groups.append(region_group_of_alone_region)
        region_group_group_by_city_id = defaultdict(list)
        for region_group in region_groups:
            region_group_group_by_city_id[region_group.city_id].append(region_group)
        city_ids = list(set(result.city_ids+region_group_group_by_city_id.keys()))
        cities = city_base.get(city_ids)
        for city in cities:
            setattr(city,'_region_groups',region_group_group_by_city_id.get(city.id,[]))
        cities = getresult_to_raw(cities)
        result = cities
        return result
Example #20
0
def get_struct(user_id):
    with thrift_client("ers") as ers:
        result = ers.get_direct_struct(user_id)
        result = getresult_to_raw(result)

        region_group_query = thirdparty_svc.ers.TRegionGroupQuery()
        region_group_query.city_ids = result.city_ids
        region_group_query.show_all = True

        region_groups_of_city = ers.query_region_group(region_group_query)
        region_groups_of_city = any_to_raw(region_groups_of_city)

        region_group_ids = result.region_group_ids
        region_group_ids.extend([obj["id"] for obj in region_groups_of_city])
        region_groups = ers.mget_region_group(region_group_ids).values()
        for region_group in region_groups:
            regions = ers.get_regions_by_region_group_ids([region_group.id])
            setattr(region_group, "_regions", regions)
        regions = ers.mget_region(result.region_ids).values()
        for region in regions:
            region_group_of_alone_region = ers.get_region_group_by_region(region.id)
            for region_group in region_groups:
                if region_group_of_alone_region.id == region_group.id:
                    region_group._regions.append(region)
            else:
                setattr(region_group_of_alone_region, "_regions", [region])
                region_groups.append(region_group_of_alone_region)
        region_group_group_by_city_id = defaultdict(list)
        for region_group in region_groups:
            region_group_group_by_city_id[region_group.city_id].append(region_group)
        city_ids = list(set(result.city_ids + region_group_group_by_city_id.keys()))
        cities = city_base.get(city_ids)
        for city in cities:
            setattr(city, "_region_groups", region_group_group_by_city_id.get(city.id, []))
        cities = getresult_to_raw(cities)
        result = cities
        return result
Example #21
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
Example #22
0
def ess_search2(**args):
    def calc_index(query):
        return 'order'
    doc_type = 'eleme_order'
    query = args['query']
    index = calc_index(query)
    q = json.loads(query)
    if 'filter' not in q:
        q['filter'] = {}
    if 'bool' not in q['filter']:
        q['filter']['bool'] = {}
    struct = args['struct']
    struct = json.loads(struct)
    regions = []
    current_user_struct = get_struct(current_user.id)
    if not current_user_struct:
        return {'total':0,'objects':[]}

    #处理未分组
    is_ungroup = False
    _region_groups_ids = struct.get('region_group_ids',[])
    with thrift_client('ers') as ers:
        _result = ers.mget_region_group(_region_groups_ids)
        _result = getresult_to_raw(_result)
    for _region_group in _result.values():
        if _region_group.name.find(u'未分组') >= 0:
            is_ungroup = True
            with thrift_client('ers') as ers:
                region_query = thirdparty_svc.ers.TRegionQuery()
                region_query.city_ids = [_region_group.city_id]
                regions = ers.query_region(region_query)
                regions = any_to_raw(regions)
                regions = getresult_to_raw(regions)
            should = []
            for region in regions:
                should.append(
                    {
                        'geo_polygon':{
                            'eleme_order.location':{
                                'points':region_area_to_es_points(region.area)
                            }
                        }
                    }
                )
            q['filter']['bool']['must_not'] = [
                #{'filter':{
                {
                    'bool':{
                        'should':should,
                        #'mininum_should_match':1,
                    }
                }
                #}
            ]
            restaurant_q = {
                "fields" : [],
                "filter" : {
                    "term" : { "city_id" : _region_group.city_id}
                },
                "from" : 0,
                "size" : random.randint(100000,500000),
            }
            restaurant_q = json.dumps(restaurant_q)
            result1 = _ess_search2('restaurant','restaurant',restaurant_q)
            result1 = result1['hits']
            city_restaurant_ids = [r['_id'] for r in result1]
            q['filter']['bool']['must'].append(
                {
                    'terms':{'restaurant_id':city_restaurant_ids}
                }
            )
            break
    if not is_ungroup:
        city_ids = struct.get('city_ids',[])
        region_group_ids = struct.get('region_group_ids',[])
        region_ids = struct.get('region_ids',[])
        if struct:
            regions = regions_from_struct(input_struct=struct,his_struct=current_user_struct)
        if not city_ids and not region_group_ids and not region_ids:
            regions = []
            for city in current_user_struct:
                for region_groups in city._region_groups:
                    for region in region_groups._regions:
                        regions.append(region)
        if regions:
            should = []
            for region in regions:
                points = region_area_to_es_points(region.area)
                if points:
                    should.append(
                        {
                            'geo_polygon':{
                                'eleme_order.location':{
                                    'points':region_area_to_es_points(region.area)
                                }
                            }
                        }
                    )
            q['filter']['bool']['should'] = should

    query = json.dumps(q)

    result = _ess_search2(index,doc_type,query)
    result = extract_ess_search_result(result)

    order_ids = [order['id'] for order in result['objects']]
    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['objects']:
        order.update(orders_info[order['id']])
    for order in result['objects']:
        if order['phone_rating'] == 1:
            order['is_new_user'] = True
        else:
            order['is_new_user'] = False
    with thrift_client('eus') as eus_client:
        chaos = eus_client.get_order_payment_constitution_map(order_ids)
    for order in result['objects']:
        payment_constituion = chaos.get(order['id'],[])
        order['payment_constituion'] = whatzfvcksay(payment_constituion,order['total'])
    restaurant_ids = list(set([o['restaurant_id'] for o in result['objects']]))
    restaurants = rst_base.get(restaurant_ids)
    for r in restaurants:
        r['_image_url'] = image_hash_to_url(r['image_hash'])
    restaurant_map = {r.id:r for r in restaurants}
    for order in result['objects']:
        order['_restaurant'] = restaurant_map[order['restaurant_id']]
    for _object in result['objects']:
        _object['order_id'] = unicode(_object['id'])
    with thrift_client('eyes') as eyes_client:
        suspicious_orders = eyes_client.walle_get_suspicious_order_detail(order_ids)
        suspicious_orders = getresult_to_raw(suspicious_orders)
        suspicious_orders_map = {order.id:order for order in suspicious_orders}
    for _object in result['objects']:
        suspicious = suspicious_orders_map.get(_object['id'],{})
        _object['_order_suspicious_reason'] = suspicious.get('reasons',[])
    return result
Example #23
0
def ess_search2(**args):
    def calc_index(query):
        return "order"

    doc_type = "eleme_order"
    query = args["query"]
    index = calc_index(query)
    q = json.loads(query)
    if "filter" not in q:
        q["filter"] = {}
    if "bool" not in q["filter"]:
        q["filter"]["bool"] = {}
    struct = args["struct"]
    struct = json.loads(struct)
    regions = []
    current_user_struct = get_struct(current_user.id)
    if not current_user_struct:
        return {"total": 0, "objects": []}

    # 处理未分组
    is_ungroup = False
    _region_groups_ids = struct.get("region_group_ids", [])
    with thrift_client("ers") as ers:
        _result = ers.mget_region_group(_region_groups_ids)
        _result = getresult_to_raw(_result)
    for _region_group in _result.values():
        if _region_group.name.find(u"未分组") >= 0:
            is_ungroup = True
            with thrift_client("ers") as ers:
                region_query = thirdparty_svc.ers.TRegionQuery()
                region_query.city_ids = [_region_group.city_id]
                regions = ers.query_region(region_query)
                regions = any_to_raw(regions)
                regions = getresult_to_raw(regions)
            should = []
            for region in regions:
                should.append(
                    {"geo_polygon": {"eleme_order.location": {"points": region_area_to_es_points(region.area)}}}
                )
            q["filter"]["bool"]["must_not"] = [
                # {'filter':{
                {
                    "bool": {
                        "should": should,
                        #'mininum_should_match':1,
                    }
                }
                # }
            ]
            restaurant_q = {
                "fields": [],
                "filter": {"term": {"city_id": _region_group.city_id}},
                "from": 0,
                "size": random.randint(100000, 500000),
            }
            restaurant_q = json.dumps(restaurant_q)
            result1 = _ess_search2("restaurant", "restaurant", restaurant_q)
            result1 = result1["hits"]
            city_restaurant_ids = [r["_id"] for r in result1]
            q["filter"]["bool"]["must"].append({"terms": {"restaurant_id": city_restaurant_ids}})
            break
    if not is_ungroup:
        city_ids = struct.get("city_ids", [])
        region_group_ids = struct.get("region_group_ids", [])
        region_ids = struct.get("region_ids", [])
        if struct:
            regions = regions_from_struct(input_struct=struct, his_struct=current_user_struct)
        if not city_ids and not region_group_ids and not region_ids:
            regions = []
            for city in current_user_struct:
                for region_groups in city._region_groups:
                    for region in region_groups._regions:
                        regions.append(region)
        if regions:
            should = []
            for region in regions:
                points = region_area_to_es_points(region.area)
                if points:
                    should.append(
                        {"geo_polygon": {"eleme_order.location": {"points": region_area_to_es_points(region.area)}}}
                    )
            q["filter"]["bool"]["should"] = should

    query = json.dumps(q)

    result = _ess_search2(index, doc_type, query)
    result = extract_ess_search_result(result)

    order_ids = [order["id"] for order in result["objects"]]
    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["objects"]:
        order.update(orders_info[order["id"]])
    for order in result["objects"]:
        if order["phone_rating"] == 1:
            order["is_new_user"] = True
        else:
            order["is_new_user"] = False
    with thrift_client("eus") as eus_client:
        chaos = eus_client.get_order_payment_constitution_map(order_ids)
    for order in result["objects"]:
        payment_constituion = chaos.get(order["id"], [])
        order["payment_constituion"] = whatzfvcksay(payment_constituion, order["total"])
    restaurant_ids = list(set([o["restaurant_id"] for o in result["objects"]]))
    restaurants = rst_base.get(restaurant_ids)
    for r in restaurants:
        r["_image_url"] = image_hash_to_url(r["image_hash"])
    restaurant_map = {r.id: r for r in restaurants}
    for order in result["objects"]:
        order["_restaurant"] = restaurant_map[order["restaurant_id"]]
    for _object in result["objects"]:
        _object["order_id"] = unicode(_object["id"])
    with thrift_client("eyes") as eyes_client:
        suspicious_orders = eyes_client.walle_get_suspicious_order_detail(order_ids)
        suspicious_orders = getresult_to_raw(suspicious_orders)
        suspicious_orders_map = {order.id: order for order in suspicious_orders}
    for _object in result["objects"]:
        suspicious = suspicious_orders_map.get(_object["id"], {})
        _object["_order_suspicious_reason"] = suspicious.get("reasons", [])
    return result
Example #24
0
 def set_phone_confirmed(cls, order_id, confirmed):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.set_order_phone_confirmed(order_id, confirmed)
         result = any_to_raw(result)
     return result
Example #25
0
    def get(self, pk=None):
        result = None
        with thrift_client('eus') as eus:
            if pk is None:
                # 2 是客服人员-.-
                all_permissions = current_user.has_permissions(
                    'walle_all_user_manage', True)
                parial_permissions = current_user.has_permissions(
                    'walle_partial_user_manage', True)
                user_ids = None
                if not all_permissions:
                    user_ids = eus.get_managed_user_ids(current_user.id)
                    if parial_permissions and len(user_ids):
                        pass
                    else:
                        user_ids = [current_user.id]
                query_kwargs = {
                    'limit': 1000,
                    'offset': 0,
                    'keyword': None,
                    'is_active': None,
                    'is_super_admin': None,
                    'group_ids': None,
                    'category': 2,
                    'mobile': None,
                    'email': None,
                    'name': None,
                    'region_ids': None,
                    'region_group_ids': None,
                    'city_ids': None,
                    'user_ids': user_ids,
                }
                _result = zeus_query('eus', 'walle_get_user_list',
                                     thirdparty_svc.eus.TUserQuery,
                                     **query_kwargs)
                _result = json.loads(_result)
                users = _result['list']

                dop_users = eus.mget_dop_user([user['id'] for user in users])

                # dop_users = eus.mget_dop_user(range(0,500))
                dop_users = any_to_raw(dop_users)

                # user_ids = [dop_user['user_id'] for dop_user in dop_users]
                # _result = zeus_query('eus','walle_get_user_list',eus_thrift.TUserQuery,user_ids=user_ids)
                # _result = json.loads(_result)
                # users = _result['list']

                user_id_name_map = {
                    user['id']: user['username']
                    for user in users
                }
                for dop_user in dop_users:
                    dop_user['username'] = user_id_name_map[
                        dop_user['user_id']]
                result = dop_users
                # mongo update allow_order_audit
                _dop_users = mongo.dop_user.find()
                _dop_users_map = {doc['user_id']: doc for doc in _dop_users}
                for dop_user in dop_users:
                    _dop_user = _dop_users_map.get(dop_user['user_id'], {})
                    dop_user['allow_order_audit'] = _dop_user.get(
                        'allow_order_audit', False)
        return result
Example #26
0
    def get(self, pk=None):
        result = None
        with thrift_client('eus') as eus:
            if pk is None:
                # 2 是客服人员-.-
                all_permissions = current_user.has_permissions(
                    'walle_all_user_manage', True)
                parial_permissions = current_user.has_permissions(
                    'walle_partial_user_manage', True)
                user_ids = None
                if not all_permissions:
                    user_ids = eus.get_managed_user_ids(current_user.id)
                    if parial_permissions and len(user_ids):
                        pass
                    else:
                        user_ids = [current_user.id]
                query_kwargs = {
                    'limit': 1000,
                    'offset': 0,
                    'keyword': None,

                    'is_active': None,
                    'is_super_admin': None,
                    'group_ids': None,
                    'category': 2,
                    'mobile': None,
                    'email': None,
                    'name': None,

                    'region_ids': None,
                    'region_group_ids': None,
                    'city_ids': None,
                    'user_ids': user_ids,
                }
                _result = zeus_query('eus', 'walle_get_user_list',
                                     thirdparty_svc.eus.TUserQuery, **query_kwargs)
                _result = json.loads(_result)
                users = _result['list']

                dop_users = eus.mget_dop_user([user['id'] for user in users])

                # dop_users = eus.mget_dop_user(range(0,500))
                dop_users = any_to_raw(dop_users)

                # user_ids = [dop_user['user_id'] for dop_user in dop_users]
                # _result = zeus_query('eus','walle_get_user_list',eus_thrift.TUserQuery,user_ids=user_ids)
                # _result = json.loads(_result)
                # users = _result['list']

                user_id_name_map = {user['id']: user['username'] for user in
                                    users}
                for dop_user in dop_users:
                    dop_user['username'] = user_id_name_map[dop_user['user_id']]
                result = dop_users
                # mongo update allow_order_audit
                _dop_users = mongo.dop_user.find()
                _dop_users_map = {doc['user_id']: doc for doc in _dop_users}
                for dop_user in dop_users:
                    _dop_user = _dop_users_map.get(dop_user['user_id'], {})
                    dop_user['allow_order_audit'] = _dop_user.get(
                        'allow_order_audit', False)
        return result
Example #27
0
 def set_phone_confirmed(cls, order_id, confirmed):
     order_id = int(order_id)
     with thrift_client('eos') as eos:
         result = eos.set_order_phone_confirmed(order_id, confirmed)
         result = any_to_raw(result)
     return result