示例#1
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}
示例#2
0
def send_one():
    sms_task_id = -1
    try:
        sms_task_id = send_pay_notice_sms(pay_record['phone'], pay_record)
        status = PaymentNoticeRecord.STATUS_SENDING
    except Exception:
        status = PaymentNoticeRecord.STATUS_SMS_FAILED

    pay_record['first_date'] = strpdate(pay_record['first_date'])
    pay_record['last_date'] = strpdate(pay_record['last_date'])
    pay_record['process_date'] = strpdate(pay_record['process_date'])
    PaymentNoticeRecord.add(pay_record['record_id'],
                            status=status,
                            sms_task_id=sms_task_id,
                            **pay_record)
示例#3
0
文件: base.py 项目: liuzelei/walis
def update_sms_status(sms_task_id, to_status, update_time):
    record = PaymentNoticeRecord.get_by_sms_task_id(sms_task_id)
    if not record:
        log.error('Activity pay record with id {} is not exist.'.
                  format(sms_task_id))
        return

    record.update(to_status, update_time)
示例#4
0
def update_sms_status(sms_task_id, to_status, update_time):
    record = PaymentNoticeRecord.get_by_sms_task_id(sms_task_id)
    if not record:
        log.error(
            'Activity pay record with id {} is not exist.'.format(sms_task_id))
        return

    record.update(to_status, update_time)
示例#5
0
文件: base.py 项目: liuzelei/walis
def process_pay_records(pay_record_infos):
    """ Process : send sms and make data persistence
    """

    process_at = 0
    for pay_record in pay_record_infos:

        sms_task_id = None
        for key, value in pay_record.items():
            pay_record[key] = unicode(value)

        log.info('ready to send payment notification sms to {}.'.
                 format(pay_record['phone']))
        try:
            if is_mobile_valid(pay_record['phone']):
                sms_task_id = send_pay_notice_sms(
                    pay_record['phone'], pay_record)
                status = PaymentNoticeRecord.STATUS_SENDING
            else:
                status = PaymentNoticeRecord.STATUS_MOBILE_INVALID
        except Exception as e:
            log.error(e)
            status = PaymentNoticeRecord.STATUS_SMS_FAILED

        pay_record['first_date'] = strpdate(pay_record['first_date'])
        pay_record['last_date'] = strpdate(pay_record['last_date'])
        pay_record['process_date'] = strpdate(pay_record['process_date'])
        PaymentNoticeRecord.add(status=status,
                                sms_task_id=sms_task_id or -1,
                                **pay_record)

        rm_pending_record_ids(pay_record['record_id'])

        if pay_record['record_id'] > process_at:
            process_at = pay_record['record_id']

    log.info('pay_record_id process at {}'.format(process_at))

    set_process_at_record_id(process_at)
示例#6
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}
示例#7
0
def process_pay_records(pay_record_infos):
    """ Process : send sms and make data persistence
    """

    process_at = 0
    for pay_record in pay_record_infos:

        sms_task_id = None
        for key, value in pay_record.items():
            pay_record[key] = unicode(value)

        log.info('ready to send payment notification sms to {}.'.format(
            pay_record['phone']))
        try:
            if is_mobile_valid(pay_record['phone']):
                sms_task_id = send_pay_notice_sms(pay_record['phone'],
                                                  pay_record)
                status = PaymentNoticeRecord.STATUS_SENDING
            else:
                status = PaymentNoticeRecord.STATUS_MOBILE_INVALID
        except Exception as e:
            log.error(e)
            status = PaymentNoticeRecord.STATUS_SMS_FAILED

        pay_record['first_date'] = strpdate(pay_record['first_date'])
        pay_record['last_date'] = strpdate(pay_record['last_date'])
        pay_record['process_date'] = strpdate(pay_record['process_date'])
        PaymentNoticeRecord.add(status=status,
                                sms_task_id=sms_task_id or -1,
                                **pay_record)

        rm_pending_record_ids(pay_record['record_id'])

        if pay_record['record_id'] > process_at:
            process_at = pay_record['record_id']

    log.info('pay_record_id process at {}'.format(process_at))

    set_process_at_record_id(process_at)