Exemple #1
0
def gets_hongbao_grab(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_weixin_hongbao_record(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_weixin_hongbao_record(query)
    hongbao_grab_list = []
    hongbao_grab_keys = ['id','sn','group_sn','sns_uid','sns_username','sns_avatar','phone','amount','sum_condition','status','name','source','created_at','updated_at','user_id']
    for hongbao_grab in results:
        hongbao_grab = ttype2dict(hongbao_grab, keys=hongbao_grab_keys)
        hongbao_grab['created_at'] = timestamp2datetime(hongbao_grab['created_at'])
        hongbao_grab['updated_at'] = timestamp2datetime(hongbao_grab['updated_at'])
        hongbao_grab_list.append(hongbao_grab)
    return hongbao_grab_list,count
Exemple #2
0
def push():
    if not check_hermes_auth():
        abort(403)

    raw_data = request.data or request.json
    if not raw_data:
        abort(400)

    data_map = loads(raw_data)
    n_type = data_map['n_type']
    data = data_map['data']

    if n_type == 0:
        # update sms status and update_time
        sms_task_id = int(data['task_id'])
        try:
            to_status = STATUS_MAP[data['new_status']]
            update_time = datetime.strptime(data['update_time'],
                                            "%Y-%m-%d %H:%M:%S")
        except Exception:
            return ''
        _update_sms_status(sms_task_id, to_status, update_time)

    elif n_type == 1:
        # sms reply
        reply_id = int(data['reply_id'])
        phone_number = data['phone_number']
        message = data['message']
        reply_at = timestamp2datetime(data['timestamp'])
        _save_sms_reply(reply_id, phone_number, message, reply_at)

    else:
        abort(400)

    return ''
Exemple #3
0
def gets_hongbao_grab(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_weixin_hongbao_record(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_weixin_hongbao_record(query)
    hongbao_grab_list = []
    hongbao_grab_keys = [
        'id', 'sn', 'group_sn', 'sns_uid', 'sns_username', 'sns_avatar',
        'phone', 'amount', 'sum_condition', 'status', 'name', 'source',
        'created_at', 'updated_at', 'user_id'
    ]
    for hongbao_grab in results:
        hongbao_grab = ttype2dict(hongbao_grab, keys=hongbao_grab_keys)
        hongbao_grab['created_at'] = timestamp2datetime(
            hongbao_grab['created_at'])
        hongbao_grab['updated_at'] = timestamp2datetime(
            hongbao_grab['updated_at'])
        hongbao_grab_list.append(hongbao_grab)
    return hongbao_grab_list, count
Exemple #4
0
def query(admin_id=None, offset=None, limit=DEFAULT_QUERY_LIMIT):
    condition = thirdparty_svc.eos.TCouponBatchQuery()

    if admin_id is not None:
        condition.admin_id = admin_id

    if offset is not None:
        condition.offset = offset

    if limit is not None:
        condition.limit = min(limit, MAX_QUERY_LIMIT)

    with thrift_client('eos') as eos:
        batch_record_list = eos.query_coupon_batch_record(condition)

    # make datetime readable
    for batch_record in batch_record_list:
        batch_record.created_at = timestamp2datetime(batch_record.created_at)
        batch_record.updated_at = timestamp2datetime(batch_record.updated_at)

    return batch_record_list
Exemple #5
0
def gets_hongbao_exchange(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_hongbao_exchange(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_hongbao_exchange(query)
    hongbao_exchanges = []
    hongbao_exchange_keys = ['exchange','amount','sum_condition','created_at','end_date','status','hongbao_sn','phone']
    for hongbao_exchange in results:
        hongbao_exchange_dict = ttype2dict(hongbao_exchange, keys=hongbao_exchange_keys)
        hongbao_exchange_dict['created_at'] = timestamp2datetime(hongbao_exchange_dict['created_at'])
        hongbao_exchanges.append(hongbao_exchange_dict)
    return hongbao_exchanges,count
Exemple #6
0
def query(admin_id=None, offset=None, limit=DEFAULT_QUERY_LIMIT):
    condition = thirdparty_svc.eos.TCouponBatchQuery()

    if admin_id is not None:
        condition.admin_id = admin_id

    if offset is not None:
        condition.offset = offset

    if limit is not None:
        condition.limit = min(limit, MAX_QUERY_LIMIT)

    with thrift_client('eos') as eos:
        batch_record_list = eos.query_coupon_batch_record(condition)

    # make datetime readable
    for batch_record in batch_record_list:
        batch_record.created_at = timestamp2datetime(
            batch_record.created_at)
        batch_record.updated_at = timestamp2datetime(
            batch_record.updated_at)

    return batch_record_list
Exemple #7
0
def gets_hongbao_share(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_hongbao_group(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_hongbao_group(query)
    hongbao_shares = []
    hongbao_share_keys = ['order_id','phone','total_count','used_count','status','source','updated_at']
    for hongbao_share in results:
        hongbao_share = ttype2dict(hongbao_share, keys=hongbao_share_keys)
        hongbao_share['order_id'] = str(hongbao_share['order_id'])
        hongbao_share['updated_at'] = timestamp2datetime(hongbao_share['updated_at'])
        hongbao_shares.append(hongbao_share)
    return hongbao_shares,count
Exemple #8
0
def gets_hongbao(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_user_hongbao(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_user_hongbao(query)
    hongbaos = []
    user_hongbao_keys = ['hongbao_sn','created_at','amount','sum_condition','begin_date','end_date','status','name','username','phone','order_id']
    for result in results:
        hongbao_dict = ttype2dict(result, keys=user_hongbao_keys)
        hongbao_dict['order_id'] = str(hongbao_dict['order_id'])
        hongbao_dict['created_at'] = timestamp2datetime(hongbao_dict['created_at'])
        hongbaos.append(hongbao_dict)
    return hongbaos,count
Exemple #9
0
def gets_hongbao_share(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_hongbao_group(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_hongbao_group(query)
    hongbao_shares = []
    hongbao_share_keys = [
        'order_id', 'phone', 'total_count', 'used_count', 'status', 'source',
        'updated_at'
    ]
    for hongbao_share in results:
        hongbao_share = ttype2dict(hongbao_share, keys=hongbao_share_keys)
        hongbao_share['order_id'] = str(hongbao_share['order_id'])
        hongbao_share['updated_at'] = timestamp2datetime(
            hongbao_share['updated_at'])
        hongbao_shares.append(hongbao_share)
    return hongbao_shares, count
Exemple #10
0
def gets_hongbao_exchange(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_hongbao_exchange(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_hongbao_exchange(query)
    hongbao_exchanges = []
    hongbao_exchange_keys = [
        'exchange', 'amount', 'sum_condition', 'created_at', 'end_date',
        'status', 'hongbao_sn', 'phone'
    ]
    for hongbao_exchange in results:
        hongbao_exchange_dict = ttype2dict(hongbao_exchange,
                                           keys=hongbao_exchange_keys)
        hongbao_exchange_dict['created_at'] = timestamp2datetime(
            hongbao_exchange_dict['created_at'])
        hongbao_exchanges.append(hongbao_exchange_dict)
    return hongbao_exchanges, count
Exemple #11
0
def gets_hongbao(args):
    query = get_hongbao_query(args)
    with thrift_client('eus') as eus:
        count = eus.walle_count_user_hongbao(query)
        query.offset = args.get('offset', None)
        query.limit = args.get('limit', None)
        results = eus.walle_query_user_hongbao(query)
    hongbaos = []
    user_hongbao_keys = [
        'hongbao_sn', 'created_at', 'amount', 'sum_condition', 'begin_date',
        'end_date', 'status', 'name', 'username', 'phone', 'order_id'
    ]
    for result in results:
        hongbao_dict = ttype2dict(result, keys=user_hongbao_keys)
        hongbao_dict['order_id'] = str(hongbao_dict['order_id'])
        hongbao_dict['created_at'] = timestamp2datetime(
            hongbao_dict['created_at'])
        hongbaos.append(hongbao_dict)
    return hongbaos, count
Exemple #12
0
def push():
    if not check_hermes_auth():
        abort(403)

    raw_data = request.data or request.json
    if not raw_data:
        abort(400)

    data_map = loads(raw_data)
    n_type = data_map['n_type']
    data = data_map['data']

    if n_type == 0:
        # update sms status and update_time
        sms_task_id = int(data['task_id'])
        try:
            to_status = STATUS_MAP[data['new_status']]
            update_time = datetime.strptime(data['update_time'],
                                            "%Y-%m-%d %H:%M:%S")
        except Exception:
            return ''
        _update_sms_status(sms_task_id, to_status, update_time)

    elif n_type == 1:
        # sms reply
        reply_id = int(data['reply_id'])
        phone_number = data['phone_number']
        message = data['message']
        reply_at = timestamp2datetime(data['timestamp'])
        _save_sms_reply(
            reply_id, phone_number, message, reply_at)

    else:
        abort(400)

    return ''