コード例 #1
0
def bankcard_approve(rst_id, bankcard_id):
    args = _get_bankcard_args()
    args.update({
        'id': bankcard_id,
        "status": RstBankCard.STATUS_VALID,
        "rst_id": rst_id
    })

    rst_admin = get_rst_admin(rst_id)

    current_zeus_bankcard = None
    mobile = None
    if rst_admin:
        current_zeus_bankcard = \
            user_base.get_bankcard(rst_admin.get('user_id'))
        mobile = rst_admin.get("mobile")
    try:
        if rst_admin:
            _unbind_admin_mobile(rst_admin.get('user_id'))
            _unbind_admin_bankcard(rst_admin.get('user_id'))

        bankcard_base.super_user_bind(username=args['username'],
                                      mobile=args['mobile'],
                                      restaurant_id=rst_id,
                                      bank_id=args['bank_id'],
                                      card_id=args['card_id'],
                                      cardholder_name=args['cardholder_name'],
                                      process_user_id=current_user.id)

        _current_to_history(rst_id)
        bankcard_base.update_bankcard(**args)
        bankcard_base.add_bankcard_processing_record(
            rst_id=rst_id,
            bankcard_id=bankcard_id,
            process_user_id=current_user.id,
            messages=u'审核通过该银行卡信息',
            status_to=RstBankCard.STATUS_VALID,
        )
        rst = rst_base.get(rst_id)
        bank = bankcard_base.get_bank(int(args['bank_id']))
        async .send_task(send_bankcard_approve_sms,
                         phone=args['mobile'],
                         params={
                             "restaurant_name": rst.get('name'),
                             "card_holder": args["cardholder_name"],
                             "bank": bank.bank_name,
                             "card_tail_number": args["card_id"][-4:]
                         })
    except thirdparty_svc.eus.EUSUserException as e:
        # rollback bankcard and mobile
        if mobile and rst_admin.get("is_mobile_valid") == 1:
            user_base.bind_mobile(rst_admin.get("user_id"), mobile)
        if current_zeus_bankcard:
            user_base.bankcard_bind(
                user_id=current_zeus_bankcard.user_id,
                cardholder_name=current_zeus_bankcard.cardholder_name,
                bank_id=current_zeus_bankcard.bank_id,
                card_id=current_zeus_bankcard.card_id)

        raise_user_exc(BANKCARD_APPROVE_ERR, error_msg=e.message)
コード例 #2
0
def get(restaurant_id):
    certification=''
    try:
        certification = cert_base.get(int(restaurant_id))
    except BaseException as e:
        raise_user_exc(CERT_NOT_EXISTS_ERR, restaurant_id=restaurant_id)
    return {'certification': certification}
コード例 #3
0
ファイル: cert.py プロジェクト: liuzelei/walis
def get(restaurant_id):
    certification = ""
    try:
        certification = cert_base.get(int(restaurant_id))
    except BaseException as e:
        raise_user_exc(CERT_NOT_EXISTS_ERR, restaurant_id=restaurant_id)
    return {"certification": certification}
コード例 #4
0
ファイル: handler.py プロジェクト: liuzelei/walis
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
コード例 #5
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
コード例 #6
0
def _check_region_json(area):
    if area is not None:
        try:
            geojson.loads(json.dumps(area))
        except ValueError:
            raise_user_exc(REGION_INVALID)

    return True
コード例 #7
0
def get_pay_records(rst_id, activity_id=None, activity_category_id=None,
                    offset=None, limit=None):
    records_paging = query_paylog_by_rst(rst_id, activity_id,
                                         activity_category_id, offset, limit)
    total_num = count_paylog_by_rst(rst_id, activity_id, activity_category_id)

    record_process_ids = [r[9] for r in records_paging if r[9]]
    record_process_logs = query_process_records_by_ids(record_process_ids)
    process_log_map = {r.id: r for r in record_process_logs}

    records = []
    for record in records_paging:
        new_record = {
            'record_id': record[0],
            'first_date': record[4],
            'last_date': record[5],
            'quantity': to_int(record[6]),
            'audit_time': record[8],
            'total_subsidy': to_float(record[7]),
            'activity_id': record[1],
            'activity_category_id': record[2],
        }
        process_log = process_log_map.get(record[9], None)

        new_record['card_id'] = process_log.card_id \
            if process_log else None
        new_record['cardholder_name'] = process_log.cardholder_name \
            if process_log else None

        if process_log:
            new_record['status'] = process_log.status
        elif record[3] == ActivityStats.STATUS_PAY_RECORD_GENERATED:
            new_record['status'] = 1
        else:
            raise_user_exc(ACTIVITY_PAYMENT_PROC_ILL_ERR)

        if new_record['status'] == SubsidyProcessRecord.STATUS_SUBMITTED:
            new_record['submit_time'] = process_log.processed_at
        elif new_record['status'] in [3, 4]:
            new_record['success_time'] = process_log.processed_at

        records.append(new_record)

    for record in records:
        # set activity name
        try:
            record['activity_name'] = act_base.get_name(
                record['activity_id'], record['activity_category_id'])
        except:
            # Fix history problem
            record['activity_name'] = ''

    record_results = set_null(records,
                              ['card_id', 'cardholder_name',
                               'audit_time', 'submit_time', 'success_time'])

    return record_results, total_num
コード例 #8
0
ファイル: bankcard.py プロジェクト: liuzelei/walis
def bankcard_approve(rst_id, bankcard_id):
    args = _get_bankcard_args()
    args.update({'id': bankcard_id,
                 "status": RstBankCard.STATUS_VALID,
                 "rst_id": rst_id})

    rst_admin = get_rst_admin(rst_id)

    current_zeus_bankcard = None
    mobile = None
    if rst_admin:
        current_zeus_bankcard = \
            user_base.get_bankcard(rst_admin.get('user_id'))
        mobile = rst_admin.get("mobile")
    try:
        if rst_admin:
            _unbind_admin_mobile(rst_admin.get('user_id'))
            _unbind_admin_bankcard(rst_admin.get('user_id'))

        bankcard_base.super_user_bind(
            username=args['username'],
            mobile=args['mobile'],
            restaurant_id=rst_id,
            bank_id=args['bank_id'],
            card_id=args['card_id'],
            cardholder_name=args['cardholder_name'],
            process_user_id=current_user.id)

        _current_to_history(rst_id)
        bankcard_base.update_bankcard(**args)
        bankcard_base.add_bankcard_processing_record(
            rst_id=rst_id,
            bankcard_id=bankcard_id,
            process_user_id=current_user.id,
            messages=u'审核通过该银行卡信息',
            status_to=RstBankCard.STATUS_VALID,
        )
        rst = rst_base.get(rst_id)
        bank = bankcard_base.get_bank(int(args['bank_id']))
        async.send_task(send_bankcard_approve_sms, phone=args['mobile'],
                        params={"restaurant_name": rst.get('name'),
                                "card_holder": args["cardholder_name"],
                                "bank": bank.bank_name,
                                "card_tail_number": args["card_id"][-4:]})
    except thirdparty_svc.eus.EUSUserException as e:
        # rollback bankcard and mobile
        if mobile and rst_admin.get("is_mobile_valid") == 1:
            user_base.bind_mobile(rst_admin.get("user_id"), mobile)
        if current_zeus_bankcard:
            user_base.bankcard_bind(user_id=current_zeus_bankcard.user_id,
                                    cardholder_name=current_zeus_bankcard.cardholder_name,
                                    bank_id=current_zeus_bankcard.bank_id,
                                    card_id=current_zeus_bankcard.card_id)

        raise_user_exc(BANKCARD_APPROVE_ERR, error_msg=e.message)
コード例 #9
0
def get_event(event_id, with_records=True, with_name=True):
    event = inner.get_event(event_id)

    if not event:
        raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id)

    event = event.to_dict()
    if with_records:
        records = get_records(event['id'], with_name=with_name)
        event['records'] = records

    return event
コード例 #10
0
def update_event(event_id, compensation=None, user_id=None, content=None):
    event = inner.get_event(event_id)

    if not event:
        raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id)

    if compensation is not None:
        event.update(compensation=compensation)

    if user_id and content:
        inner.add_record(event_id, user_id, content, event.status)

    return True
コード例 #11
0
    def set_valid(cls):
        """ 设置banner是否有效
        """
        args_spec = {
            'id': Arg(int),
            'is_valid': Arg(int),
        }
        args = args_parser.parse(args_spec)

        if not len(args.values()) == 2 or args.get('is_valid') is None:
            # TODO raise incorrect args exception
            raise_user_exc(BANNER_ARGS_ERR)

        cls.update(args)
        return ''
コード例 #12
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 ''
コード例 #13
0
ファイル: cert.py プロジェクト: liuzelei/walis
def processing():
    args = args_parser.parse_all()
    status_to = int(args.get("status"))
    comment = args.get("comment", "")
    restaurant_id = int(args.get("restaurant_id"))
    cert = cert_base.get(restaurant_id)

    if status_to != CERTIFICATION_CONST.STATUS_PASSED and status_to != CERTIFICATION_CONST.STATUS_FAILED:
        raise_user_exc(CERT_PROC_ILL_ERR)

    if cert.status != CERTIFICATION_CONST.STATUS_PENDING:
        raise_user_exc(CERT_NOT_PENDING_ERR)

    cert_base.process_certification(restaurant_id, status_to)

    record_base.add(restaurant_id, cert.type, cert.status, status_to, comment)
    return ""
コード例 #14
0
ファイル: cert.py プロジェクト: liuzelei/walis
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 ''
コード例 #15
0
ファイル: city_manage.py プロジェクト: liuzelei/walis
def check_same(new_city):

    lcdist = new_city.get('_districts', [])
    if len(lcdist) == 0:  # no dist,no ploblem,over
        return 0

    distname = set([item.get('name', '') for item in lcdist])
    if len(distname) < len(lcdist):
        raise_user_exc(DIST_NAME_REDUNDANCE)

    for item in lcdist:
        zones = item.get('_zones', [])
        if len(zones) == 0:
            break
        else:
            zonename = set([item.get('name', '') for item in zones])
            if len(zonename) < len(zones):
                raise_user_exc(ZONE_NAME_REDUNDANCE)
コード例 #16
0
def check_same(new_city):

    lcdist = new_city.get('_districts', [])
    if len(lcdist) == 0:  # no dist,no ploblem,over
        return 0

    distname = set([item.get('name', '') for item in lcdist])
    if len(distname) < len(lcdist):
        raise_user_exc(DIST_NAME_REDUNDANCE)

    for item in lcdist:
        zones = item.get('_zones', [])
        if len(zones) == 0:
            break
        else:
            zonename = set([item.get('name', '') for item in zones])
            if len(zonename) < len(zones):
                raise_user_exc(ZONE_NAME_REDUNDANCE)
コード例 #17
0
    def post(cls):
        args = get_args()
        regions = cls._region_list2map(args.pop('cities'),
                                        args.pop('region_groups'),
                                        args.pop('regions'))
        args['regions'] = regions

        b_type = args.pop('type')
        if b_type == banner_client.banner_type.NON_INTERACTIVE:
            banner_id = banner_client.add_non_interactive_banner(args)
        elif b_type == banner_client.banner_type.LINK:
            banner_id = banner_client.add_link_banner(args)
        elif b_type == banner_client.banner_type.ACTIVITY:
            banner_id = banner_client.add_activity_banner(args)
        else:
            # TODO
            raise_user_exc(BANNER_TYPE_ERR)
        return {'id': banner_id}
コード例 #18
0
def process_event(event_id, status, handler_id=None):
    if status is None:
        return False

    if status == CSEvent.STATUS_FORWARD and handler_id is None:
        raise_dev_exc(DEV_BAD_REQUEST_ERROR, arg='handler_id')

    event = inner.get_event(event_id)

    if not event:
        raise_user_exc(CS_EVENT_NOT_EXIST, event_id=event_id)

    if event.status == CSEvent.STATUS_DONE:
        raise_dev_exc(CS_EVENT_PROCESS_STATUS_INVALID, event_id=event_id,
                      status=event.status)

    event.update(status=status, handler_id=handler_id)
    return True
コード例 #19
0
    def _get_modify_permission(cls, banner_id):
        banner = banner_client.get(banner_id)
        if not banner:
            raise_user_exc(BANNER_NOT_EXISTS_ERR, banner_id=banner_id)

        banner_regions = banner.regions
        if not banner_regions or not banner_regions.keys():
            return True

        banner_city_ids = banner_regions.keys()

        if current_user.has_groups(['activity_manager', 'marketing_manager']):
            return True
        elif current_user.has_groups(['city_director']):
            user_city_ids = city_base.get_city_ids_by_user()
            return all([banner_city_id in user_city_ids
                        for banner_city_id in banner_city_ids])

        return False
コード例 #20
0
def processing():
    args = args_parser.parse_all()
    status_to = int(args.get('status'))
    comment = args.get('comment', '')
    restaurant_id = int(args.get('restaurant_id'))
    cert = cert_base.get(restaurant_id)

    if status_to != CERTIFICATION_CONST.STATUS_PASSED and \
       status_to != CERTIFICATION_CONST.STATUS_FAILED:
        raise_user_exc(CERT_PROC_ILL_ERR)

    if cert.status != CERTIFICATION_CONST.STATUS_PENDING:
        raise_user_exc(CERT_NOT_PENDING_ERR)

    cert_base.process_certification(restaurant_id, status_to)

    record_base.add(restaurant_id, cert.type,
                        cert.status, status_to, comment)
    return ''
コード例 #21
0
    def update(cls, id, **bankcard_dict):
        query = Session().query(cls)
        query = query.filter(cls.id == id)
        rst_bankcard = query.first()
        if not rst_bankcard:
            return ''

        status = bankcard_dict.get('status')
        if status == cls.STATUS_VALID \
                and rst_bankcard.status == cls.STATUS_VALID:
            raise_user_exc(BANKCARD_UPDATE_ERR)

        if rst_bankcard.status == cls.STATUS_HISTORY:
            raise_user_exc(BANKCARD_STATUS_INVALID)

        for k, v in bankcard_dict.iteritems():
            if hasattr(rst_bankcard, k):
                setattr(rst_bankcard, k, v)

        Session().add(rst_bankcard)
コード例 #22
0
ファイル: rst.py プロジェクト: liuzelei/walis
    def update(cls, id, **bankcard_dict):
        query = Session().query(cls)
        query = query.filter(cls.id == id)
        rst_bankcard = query.first()
        if not rst_bankcard:
            return ''

        status = bankcard_dict.get('status')
        if status == cls.STATUS_VALID \
                and rst_bankcard.status == cls.STATUS_VALID:
            raise_user_exc(BANKCARD_UPDATE_ERR)

        if rst_bankcard.status == cls.STATUS_HISTORY:
            raise_user_exc(BANKCARD_STATUS_INVALID)

        for k, v in bankcard_dict.iteritems():
            if hasattr(rst_bankcard, k):
                setattr(rst_bankcard, k, v)

        Session().add(rst_bankcard)
コード例 #23
0
def save():
    args_spec = {
        'coupon_type':
        Arg(int,
            required=True,
            validate=lambda t: t in COUPON_TYPE,
            error='Invalid coupon type'),
        'batch_sn':
        Arg(str, required=True),
        'deadline':
        Arg(str, required=True),
        'sn':
        Arg(str),
        'remain':
        Arg(int),
        'count':
        Arg(int),
    }
    args = args_parser.parse(args_spec)

    if args['coupon_type'] == GENERIC_COUPON:
        if args.get('sn') is None:
            raise_user_exc(COUPON_SN_REQUIRED)

        if not _check_sn_length(args['sn']):
            raise_user_exc(COUPON_SN_INVALID)

        remain = args.get('remain') or GENERAL_COUPON_DEFAULT_REMAIN

        result = coupon_base.save_generic_coupon(batch_sn=args['batch_sn'],
                                                 deadline=args['deadline'],
                                                 sn=args['sn'],
                                                 remain=remain)
        result = [
            result.get('sn'),
        ]
    else:
        if args.get('count') is None:
            raise_user_exc(COUPON_COUNT_REQUIRED)

        if int(args.get('count')) > 500:
            raise_user_exc(COUPON_COUNT_INVALID)

        result = coupon_base.save_onetime_coupon(batch_sn=args['batch_sn'],
                                                 remain=1,
                                                 deadline=args['deadline'],
                                                 remarks=u"后台生成",
                                                 count=args['count'])

    return result
コード例 #24
0
ファイル: batch.py プロジェクト: liuzelei/walis
def save():
    args_spec = {
        'batch_type': Arg(int, required=True, validate=lambda t: t in BATCH_TYPE_LIST, error='Invalid batch type'),
        'rst_ids': Arg(str, allow_missing=True)
    }
    args = args_parser.parse(args_spec)

    # check restaurant ids when the batch bound with restaurant
    if args['batch_type'] in BATCH_TYPE_RST:
        if args.get('rst_ids') is None:
            raise_user_exc(RST_IDS_REQUIRED)

        args['rst_ids'] = [int(rst_id) for rst_id in args['rst_ids'].split()]

    batch_sn = coupon_batch_base.save(
        args['batch_type'], current_user.id, current_user.name,
        args.get('rst_ids', None)
    )

    return {
        'batch_sn': batch_sn
    }
コード例 #25
0
def save():
    args_spec = {
        'batch_type':
        Arg(int,
            required=True,
            validate=lambda t: t in BATCH_TYPE_LIST,
            error='Invalid batch type'),
        'rst_ids':
        Arg(str, allow_missing=True)
    }
    args = args_parser.parse(args_spec)

    # check restaurant ids when the batch bound with restaurant
    if args['batch_type'] in BATCH_TYPE_RST:
        if args.get('rst_ids') is None:
            raise_user_exc(RST_IDS_REQUIRED)

        args['rst_ids'] = [int(rst_id) for rst_id in args['rst_ids'].split()]

    batch_sn = coupon_batch_base.save(args['batch_type'], current_user.id,
                                      current_user.name,
                                      args.get('rst_ids', None))

    return {'batch_sn': batch_sn}
コード例 #26
0
ファイル: coupon.py プロジェクト: longzhang/walis
def save():
    args_spec = {
        'coupon_type': Arg(int, required=True, validate=lambda t: t in COUPON_TYPE, error='Invalid coupon type'),
        'batch_sn': Arg(str, required=True),
        'deadline': Arg(str, required=True),
        'sn': Arg(str),
        'remain': Arg(int),
        'count': Arg(int),
    }
    args = args_parser.parse(args_spec)

    if args['coupon_type'] == GENERIC_COUPON:
        if args.get('sn') is None:
            raise_user_exc(COUPON_SN_REQUIRED)

        if not _check_sn_length(args['sn']):
            raise_user_exc(COUPON_SN_INVALID)

        remain = args.get('remain') or GENERAL_COUPON_DEFAULT_REMAIN

        result = coupon_base.save_generic_coupon(
            batch_sn=args['batch_sn'],
            deadline=args['deadline'],
            sn=args['sn'],
            remain=remain
        )
        result = [result.get('sn'), ]
    else:
        if args.get('count') is None:
            raise_user_exc(COUPON_COUNT_REQUIRED)

        if int(args.get('count')) > 500:
            raise_user_exc(COUPON_COUNT_INVALID)

        result = coupon_base.save_onetime_coupon(
            batch_sn=args['batch_sn'],
            remain=1,
            deadline=args['deadline'],
            remarks=u"后台生成",
            count=args['count']
        )

    return result
コード例 #27
0
def to_float(something, silence=True):
    """
    transform to int silently.
    return: int if ok
            None if error.
    """
    error = False
    try:
        return float(something)
    except TypeError:
        error = True
        raise_user_exc(FORMAT_ERR, src_type='None', target_type="Float")
    except ValueError:
        error = True
        raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float")
    except Exception:
        error = True
        raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float")
    finally:
        if error and silence:
            return None
コード例 #28
0
ファイル: format.py プロジェクト: liuzelei/walis
def to_float(something, silence=True):
    """
    transform to int silently.
    return: int if ok
            None if error.
    """
    error = False
    try:
        return float(something)
    except TypeError:
        error = True
        raise_user_exc(FORMAT_ERR, src_type='None', target_type="Float")
    except ValueError:
        error = True
        raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float")
    except Exception:
        error = True
        raise_user_exc(FORMAT_ERR, src_type=something, target_type="Float")
    finally:
        if error and silence:
            return None
コード例 #29
0
def add_or_update(city_id, date_from, date_end):
    if not _check_city_exists(city_id):
        raise_user_exc(CITY_NOT_EXISTS, city_id)
    trs_query_cfg = inner.add_or_update_trs_query_cfg(city_id, date_from,
                                                      date_end)
    return {'city_transaction_query_config_id': trs_query_cfg.id}
コード例 #30
0
ファイル: trs_query_config.py プロジェクト: longzhang/walis
def add_or_update(city_id, date_from, date_end):
    if not _check_city_exists(city_id):
        raise_user_exc(CITY_NOT_EXISTS, city_id)
    trs_query_cfg = inner.add_or_update_trs_query_cfg(city_id, date_from, date_end)
    return {'city_transaction_query_config_id': trs_query_cfg.id}
コード例 #31
0
def _check_region_type(type_code):
    if type_code is not None:
        if int(type_code) not in (RegionBrand.TYPE_CBD, RegionBrand.TYPE_SCHOOL):
            raise_user_exc(REGION_TYPE_INVALID)

    return True