Пример #1
0
    def get_olpay_detail(self, restaurant_id, date=None, status=None):

        admin_id = self._get_admin_id(restaurant_id)
        page_no, page_size = get_paging_params()

        begin_date = end_date = None
        if date is not None:
            begin_date = self._get_hour0_timestamp(date)
            end_date = self._get_hour24_timestamp(date)

        # unify status code
        if status == self.TR_COMING_INCOME:
            status = self.TR_PROCESSING
        elif status == self.TR_ARRIVED_INCOME:
            status = self.TR_SUCCESS

        details, total_num = self.restaurant_base.get_olpay_detail(
            admin_id, begin_date, end_date, (page_no - 1) * page_size,
            page_size, status)

        # unify status code
        detail_result = []
        for detail in details:
            if detail.status == self.TR_PROCESSING:
                detail.status = self.TR_COMING_INCOME
                detail_result.append(detail)
            elif detail.status == self.TR_SUCCESS:
                detail.status = self.TR_ARRIVED_INCOME
                detail_result.append(detail)

        return detail_result, total_num
Пример #2
0
    def get_balance_change(self, restaurant_id, trade_type, begin_date,
                           end_date):

        admin_id = self._get_admin_id(restaurant_id)
        page_no, page_size = get_paging_params()

        if begin_date is not None:
            begin_date = self._get_hour0_timestamp(begin_date)

        if end_date is not None:
            end_date = self._get_hour24_timestamp(end_date)

        # unify trade_type
        if trade_type is not None:
            trade_type = self._balance_change_status_map('api2zeus', trade_type)
        else:
            trade_type = [0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

        records, total_num = self.restaurant_base.get_balance_change(
            admin_id, trade_type, begin_date, end_date,
            (page_no - 1) * page_size, page_size)

        # unify trade_type
        for record in records:
            record.trade_type = self._balance_change_status_map(
                'zeus2api', record.trade_type)

        return records, total_num
Пример #3
0
def gets():
    arg_spec = {
        'city_id': Arg(int, allow_missing=True)
    }
    args = args_parser.parse(arg_spec)

    offset, limit = get_paging_params(db_style=True)
    return trs_query_cfg_service.gets(city_id=args.get('city_id'), offset=offset, limit=limit)
Пример #4
0
def get_notifications(args):
    city_ids, region_group_ids, region_ids = get_direct_struct()

    if city_ids == [] and region_ids == [] and region_ids == []:
        return [], 0

    rst_id = args.pop('restaurant_id', None)
    if rst_id is not None:
        args['restaurant_ids'] = [rst_id]

    page_no, page_size = get_paging_params()
    restaurants, total_num = director_base.search_restaurants(
        city_ids=city_ids, region_group_ids=region_group_ids,
        region_ids=region_ids, offset=(page_no - 1) * page_size,
        limit=page_size, **args)

    if not restaurants:
        return [], 0

    restaurant_ids = [r['id'] for r in restaurants]
    city_ids = list(set([r['city_id'] for r in restaurants]))
    notifications = director_base.query_restaurant_director(
        restaurant_ids, [current_user.id, ])
    notification_map = {n.restaurant_id: [n.notice_enabled, n.in_charge]
                        for n in notifications}

    result = []
    city_map = city_base.mget(city_ids, return_map=True)
    for restaurant in restaurants:
        if city_map.get(restaurant['city_id'], None) is None:
            continue

        with thrift_client('ers') as ers:
            try:
                region = ers.get_region_by_restaurant(restaurant['id'])
                region_name = region.name
            except Exception as e:
                region_name = ''
                region_group_name = ''
            else:
                try:
                    region_group_name = ers.get_region_group_by_region(
                        region.id).name
                except Exception as e:
                    region_group_name = ''

        result.append({
            'restaurant_id': restaurant['id'],
            'restaurant_name': restaurant['name'],
            'city_id': restaurant['city_id'],
            'city_name': city_map[restaurant['city_id']].name,
            'region_group_name': region_group_name,
            'region_name': region_name,
            'notice_enabled': notification_map.get(restaurant['id'], [0])[0],
            'in_charge': notification_map.get(restaurant['id'], [None, 0])[1]
        })

    return result, total_num
Пример #5
0
def get_sms_reply():
    args_spec = {"phone": Arg(str, allow_missing=True)}
    args = args_parser.parse(args_spec)
    page_no, page_size = get_paging_params()
    if page_no and page_size:
        args["offset"] = (page_no - 1) * page_size
        args["limit"] = page_size
    result = PaymentNoticeReply.query(**args)
    reply_list = [{"phone": r.phone_number, "message": r.message, "reply_at": r.reply_at} for r in result]
    total_num = PaymentNoticeReply.query_count(**args)
    return {"reply_list": reply_list, "total_num": total_num}
Пример #6
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 []
Пример #7
0
def query():
    args_spec = {
        'admin_id': Arg(int, allow_missing=True)
    }
    args = args_parser.parse(args_spec)
    page_no, page_size = get_paging_params()
    offset = (page_no - 1) * page_size
    limit = page_size

    return coupon_batch_base.query(
        admin_id=args.get('admin_id', current_user.get_id()),
        offset=offset,
        limit=limit
    )
Пример #8
0
def payment_log(restaurant_id):
    args = args_parser.parse_all()
    activity_id = args.get('activity_id')
    activity_category_id = args.get('activity_category_id')

    page_no, page_size = get_paging_params()
    records, total_num = act_pay_base.get_pay_records2(
        restaurant_id,
        activity_id,
        activity_category_id,
        offset=(page_no-1) * page_size,
        limit=page_size,
    )

    return {'records': records, 'total_num': total_num}
Пример #9
0
def query_events():
    args = args_parser.parse({
        'id': Arg(int),
        'status': Arg(int),
        'category_l1': Arg(int),
        'user_type': Arg(int),
        'priority': Arg(int),
        'source': Arg(int),
        'is_my_event': Arg(int, allow_missing=True),
        'is_to_compensate': Arg(int, allow_missing=True),
        'begin_date': Arg(str),
        'end_date': Arg(str),
        'phone': Arg(str),
        'with_name': Arg(int, allow_missing=True),
        'with_records': Arg(int, allow_missing=True),
    })
    event_id = args.pop('id', None)
    if event_id is not None:
        events = []
        try:
            event = event_service.get_event(event_id)
        except UserExc:
            event = None

        if event:
            events.append(event)
        return {
            'events': events,
            'count': len(events)
        }

    offset, limit = get_paging_params(db_style=True)
    args.update({'offset': offset, 'limit': limit})

    is_my_event = args.pop('is_my_event', None)
    if is_my_event is not None:
        if is_my_event:
            args.update(handler_id=current_user.id)
        else:
            args.update(not_handler_id=current_user.id)

    events = event_service.query_events(**args)
    count = event_service.count_events(**args)
    _format_event(events)
    return {
        'events': events,
        'count': count
    }
Пример #10
0
def query():
    args_spec = {
        'sn': Arg(str),
        'batch_sn': Arg(str),
    }
    args = args_parser.parse(args_spec)
    page_no, page_size = get_paging_params()
    offset = (page_no - 1) * page_size
    limit = page_size

    return coupon_base.query(
        sn=args['sn'],
        batch_sn=args['batch_sn'],
        offset=offset,
        limit=limit
    )
Пример #11
0
def get_list_from_mm():
    args_spec = {
        'cert_type': Arg(int, allow_missing=True),
        'cert_status': Arg(int, allow_missing=True),
        'time_from': Arg(str, allow_missing=True),
        'time_to': Arg(str, allow_missing=True),
        'restaurant_id_or_name': Arg(unicode, allow_missing=True),
    }
    args = args_parser.parse(args_spec)
    cert_type = args.get('cert_type', None)
    status = args.get('cert_status')
    time_from = args.get('time_from', None)
    time_to = args.get('time_to', None)
    restaurant_id_or_name = args.get('restaurant_id_or_name', None)

    page_no, page_size = get_paging_params()
    offset = (page_no-1)*page_size

    certs = cert_base.get_by_status(status)

    if not certs:
        return {'cert_list': [], 'total_num': 0}

    response_certs = _assemble_cert_response(certs)

    if cert_type:
        response_certs = filter(lambda res: res['type'] == cert_type,
                                response_certs)

    if time_from:
        response_certs = filter(lambda res: time_from <
                                res['application_time'], response_certs)

    if time_to:
        response_certs = filter(lambda res: res['application_time'] <
                                time_to, response_certs)

    if restaurant_id_or_name is not None:
        response_certs = filter(
            lambda res: restaurant_id_or_name in
            str(res['restaurant_id']) + res['restaurant_name'],
            response_certs)

    return {'total_num': len(response_certs),
                             'cert_list': paging(response_certs)}
Пример #12
0
def get_all_bankcard_list():
    arg_spec = {
        'search_text': Arg(),
        'status': Arg(int, allow_missing=True),
        'type_code': Arg(int, allow_missing=True),
    }
    args = args_parser.parse(arg_spec)
    search_text = args.pop('search_text')

    rst_ids = _filter_ids(search_text)

    args['rst_ids'] = rst_ids
    page_no, page_size = get_paging_params(paging_size=50)
    offset = (page_no - 1) * page_size
    limit = page_size
    args.update({"offset": offset, "limit": limit})
    bankcard_list = bankcard_base.query_by_status(**args)

    if not bankcard_list:
        return {
            'bankcard_list': [],
            'total_num': 0,
        }

    bankcard_list_new = []
    rst_set_ids = set()
    for bankcard in bankcard_list:
        bankcard_list_new.append(model2dict(bankcard))
        rst_set_ids.add(bankcard.rst_id)

    rst_map = rst_base.get_map(rst_set_ids)
    for bankcard in bankcard_list_new:
        bankcard.update({
            "restaurant_name": rst_map[bankcard['rst_id']].name,
        })

    return {
        'bankcard_list': bankcard_list_new,
        'total_num':
            bankcard_base.get_bankcard_count(
                rst_ids=rst_ids,
                status=args.get("status"),
                type_code=args.get("type_code")),
    }
Пример #13
0
def get_all_bankcard_list():
    arg_spec = {
        'search_text': Arg(),
        'status': Arg(int, allow_missing=True),
        'type_code': Arg(int, allow_missing=True),
    }
    args = args_parser.parse(arg_spec)
    search_text = args.pop('search_text')

    rst_ids = _filter_ids(search_text)

    args['rst_ids'] = rst_ids
    page_no, page_size = get_paging_params(paging_size=50)
    offset = (page_no - 1) * page_size
    limit = page_size
    args.update({"offset": offset, "limit": limit})
    bankcard_list = bankcard_base.query_by_status(**args)

    if not bankcard_list:
        return {
            'bankcard_list': [],
            'total_num': 0,
        }

    bankcard_list_new = []
    rst_set_ids = set()
    for bankcard in bankcard_list:
        bankcard_list_new.append(model2dict(bankcard))
        rst_set_ids.add(bankcard.rst_id)

    rst_map = rst_base.get_map(rst_set_ids)
    for bankcard in bankcard_list_new:
        bankcard.update({
            "restaurant_name": rst_map[bankcard['rst_id']].name,
        })

    return {
        'bankcard_list':
        bankcard_list_new,
        'total_num':
        bankcard_base.get_bankcard_count(rst_ids=rst_ids,
                                         status=args.get("status"),
                                         type_code=args.get("type_code")),
    }
Пример #14
0
def query_events():
    args = args_parser.parse({
        'id': Arg(int),
        'status': Arg(int),
        'category_l1': Arg(int),
        'user_type': Arg(int),
        'priority': Arg(int),
        'source': Arg(int),
        'is_my_event': Arg(int, allow_missing=True),
        'is_to_compensate': Arg(int, allow_missing=True),
        'begin_date': Arg(str),
        'end_date': Arg(str),
        'phone': Arg(str),
        'with_name': Arg(int, allow_missing=True),
        'with_records': Arg(int, allow_missing=True),
    })
    event_id = args.pop('id', None)
    if event_id is not None:
        events = []
        try:
            event = event_service.get_event(event_id)
        except UserExc:
            event = None

        if event:
            events.append(event)
        return {'events': events, 'count': len(events)}

    offset, limit = get_paging_params(db_style=True)
    args.update({'offset': offset, 'limit': limit})

    is_my_event = args.pop('is_my_event', None)
    if is_my_event is not None:
        if is_my_event:
            args.update(handler_id=current_user.id)
        else:
            args.update(not_handler_id=current_user.id)

    events = event_service.query_events(**args)
    count = event_service.count_events(**args)
    _format_event(events)
    return {'events': events, 'count': count}
Пример #15
0
def get_list_from_mm():
    args_spec = {
        "cert_type": Arg(int, allow_missing=True),
        "cert_status": Arg(int, allow_missing=True),
        "time_from": Arg(str, allow_missing=True),
        "time_to": Arg(str, allow_missing=True),
        "restaurant_id_or_name": Arg(unicode, allow_missing=True),
    }
    args = args_parser.parse(args_spec)
    cert_type = args.get("cert_type", None)
    status = args.get("cert_status")
    time_from = args.get("time_from", None)
    time_to = args.get("time_to", None)
    restaurant_id_or_name = args.get("restaurant_id_or_name", None)

    page_no, page_size = get_paging_params()
    offset = (page_no - 1) * page_size

    certs = cert_base.get_by_status(status)

    if not certs:
        return {"cert_list": [], "total_num": 0}

    response_certs = _assemble_cert_response(certs)

    if cert_type:
        response_certs = filter(lambda res: res["type"] == cert_type, response_certs)

    if time_from:
        response_certs = filter(lambda res: time_from < res["application_time"], response_certs)

    if time_to:
        response_certs = filter(lambda res: res["application_time"] < time_to, response_certs)

    if restaurant_id_or_name is not None:
        response_certs = filter(
            lambda res: restaurant_id_or_name in str(res["restaurant_id"]) + res["restaurant_name"], response_certs
        )

    return {"total_num": len(response_certs), "cert_list": paging(response_certs)}
Пример #16
0
def get_sms_info():
    args_spec = {
        "phone": Arg(str, allow_missing=True),
        "restaurant_name": Arg(unicode, allow_missing=True),
        "activity_name": Arg(unicode, allow_missing=True),
        "first_date": Arg(str, allow_missing=True),
        "last_date": Arg(str, allow_missing=True),
        "statuses": Arg(int, multiple=True, allow_missing=True),
    }
    args = args_parser.parse(args_spec)
    page_no, page_size = get_paging_params()
    if page_no and page_size:
        args["offset"] = (page_no - 1) * page_size
        args["limit"] = page_size
    if current_user.restaurant_ids:
        args["restaurant_ids"] = current_user.restaurant_ids

    result = PaymentNoticeRecord.query(**args)
    sms_list = [
        {
            "phone": r.phone,
            "restaurant_id": r.restaurant_id,
            "restaurant_name": r.restaurant_name,
            "activity_name": r.activity_name,
            "first_date": r.first_date,
            "last_date": r.last_date,
            "amount": r.amount,
            "total_subsidy": float(r.total_subsidy),
            "process_date": r.process_date,
            "card_num_tail": r.card_num_tail,
            "status": r.status,
            "created_at": r.created_at,
            "update_time": r.update_time if r.update_time else r.created_at,
        }
        for r in result
    ]
    total_num = PaymentNoticeRecord.query_count(**args)

    return {"sms_list": sms_list, "total_num": total_num}
Пример #17
0
    def get_withdraw_records(self, restaurant_id, status, begin_date, end_date):

        page_no, page_size = get_paging_params()

        if begin_date is not None:
            begin_date = self._get_hour0_timestamp(begin_date)

        if end_date is not None:
            end_date = self._get_hour24_timestamp(end_date)

        # unify status code
        if status is not None:
            status = self._withdraw_status_map('api2zeus', status)

        records, total_num = self.restaurant_base.get_withdraw_records(
            restaurant_id, status, begin_date, end_date,
            (page_no - 1) * page_size, page_size)

        # unify status code
        for record in records:
            record.status = self._withdraw_status_map('zeus2api', record.status)

        return records, total_num
Пример #18
0
def list_for_market():
    """
    获取活动合同列表
    """
    user_args = {
        'activity_category_id': Arg(int, allow_missing=True),
        'restaurant_id': Arg(int, allow_missing=True),
        'status': Arg(int, allow_missing=True),
    }
    page_no, page_size = get_paging_params(db_style=True)
    args = args_parser.parse(user_args)
    args.update(offset=page_no, limit=page_size)
    city_ids = _get_current_user_relative_city_ids()
    result = activity_contract_service.query(
        city_ids=city_ids,
        activity_category_id=args.get('activity_category_id'),
        restaurant_ids=[args.get('restaurant_id')]
        if args.get('restaurant_id') else None,
        status=args.get('status'),
        offset=args.get('offset'),
        limit=args.get('limit'))
    result['contracts'] = _decorate_contracts(result['contracts'])
    return result
Пример #19
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
Пример #20
0
def get_rst_bankcard_list(rst_id):
    arg_spec = {
        'status': Arg(int, allow_missing=True),
        'type_code': Arg(int, allow_missing=True),
        'page_size': Arg(int, allow_missing=True),
        'page_no': Arg(int, allow_missing=True)
    }
    args = args_parser.parse(arg_spec)
    status = args.get('status')
    type_code = args.get('type_code')
    page_no, page_size = get_paging_params()
    offset = (page_no - 1) * page_size
    limit = page_size
    rst_bankcard_list = bankcard_base \
        .query_bankcard(rst_id, status=status, limit=limit, offset=offset)
    rst_bankcard_list_new = [model2dict(m) for m in rst_bankcard_list]
    return {
        'bankcard_list': rst_bankcard_list_new,
        'total_num':
            bankcard_base.get_bankcard_count([rst_id, ],
                                             status=status,
                                             type_code=type_code)
    }
Пример #21
0
def create_act_stats_query(args):
    page_no, page_size = get_paging_params()
    t_query = dict2ttype(args, thirdparty_svc.eos.TActivityStatsQuery(),
                         keys=['activity_id', 'activity_category_id',
                               'from_date', 'to_date'])
    if t_query.activity_id:
        t_query.activity_id = int(t_query.activity_id)
    if t_query.activity_category_id:
        t_query.activity_category_id = int(t_query.activity_category_id)
    t_query.offset = (page_no - 1) * page_size
    t_query.limit = page_size

    status = args.get('status')
    city_id = args.get('city_id')
    restaurant_id = args.get('restaurant_id')

    city_ids, rest_ids = get_city_ids_or_restaurant_ids_by_user()
    t_query.city_ids = city_ids
    t_query.restaurant_ids = rest_ids

    if status:
        t_query.statuses = [int(status), ]

    if city_id:
        city_id = int(city_id)
        if city_ids is None or city_id in city_ids:
            t_query.city_ids = [city_id, ]
        else:
            return None

    if restaurant_id:
        restaurant_id = int(restaurant_id)
        if rest_ids is None or restaurant_id in rest_ids:
            t_query.restaurant_ids = [restaurant_id, ]
        else:
            return None
    return t_query
Пример #22
0
def list_for_market():
    """
    获取活动合同列表
    """
    user_args = {
        'activity_category_id': Arg(int, allow_missing=True),
        'restaurant_id': Arg(int, allow_missing=True),
        'status': Arg(int, allow_missing=True),
    }
    page_no, page_size = get_paging_params(db_style=True)
    args = args_parser.parse(user_args)
    args.update(offset=page_no, limit=page_size)
    city_ids = _get_current_user_relative_city_ids()
    result = activity_contract_service.query(
        city_ids=city_ids,
        activity_category_id=args.get('activity_category_id'),
        restaurant_ids=[args.get('restaurant_id')] if args.get(
            'restaurant_id') else None,
        status=args.get('status'),
        offset=args.get('offset'),
        limit=args.get('limit')
    )
    result['contracts'] = _decorate_contracts(result['contracts'])
    return result
Пример #23
0
def get_notifications(args):
    city_ids, region_group_ids, region_ids = get_direct_struct()

    if city_ids == [] and region_ids == [] and region_ids == []:
        return [], 0

    rst_id = args.pop('restaurant_id', None)
    if rst_id is not None:
        args['restaurant_ids'] = [rst_id]

    page_no, page_size = get_paging_params()
    restaurants, total_num = director_base.search_restaurants(
        city_ids=city_ids,
        region_group_ids=region_group_ids,
        region_ids=region_ids,
        offset=(page_no - 1) * page_size,
        limit=page_size,
        **args)

    if not restaurants:
        return [], 0

    restaurant_ids = [r['id'] for r in restaurants]
    city_ids = list(set([r['city_id'] for r in restaurants]))
    notifications = director_base.query_restaurant_director(
        restaurant_ids, [
            current_user.id,
        ])
    notification_map = {
        n.restaurant_id: [n.notice_enabled, n.in_charge]
        for n in notifications
    }

    result = []
    city_map = city_base.mget(city_ids, return_map=True)
    for restaurant in restaurants:
        if city_map.get(restaurant['city_id'], None) is None:
            continue

        with thrift_client('ers') as ers:
            try:
                region = ers.get_region_by_restaurant(restaurant['id'])
                region_name = region.name
            except Exception as e:
                region_name = ''
                region_group_name = ''
            else:
                try:
                    region_group_name = ers.get_region_group_by_region(
                        region.id).name
                except Exception as e:
                    region_group_name = ''

        result.append({
            'restaurant_id':
            restaurant['id'],
            'restaurant_name':
            restaurant['name'],
            'city_id':
            restaurant['city_id'],
            'city_name':
            city_map[restaurant['city_id']].name,
            'region_group_name':
            region_group_name,
            'region_name':
            region_name,
            'notice_enabled':
            notification_map.get(restaurant['id'], [0])[0],
            'in_charge':
            notification_map.get(restaurant['id'], [None, 0])[1]
        })

    return result, total_num