Esempio n. 1
0
def billing_query(db):
    account_number = request.params.get('account_number')
    query_begin_time = request.params.get('query_begin_time')
    query_end_time = request.params.get('query_end_time')
    _query = db.query(
        models.SlcRadBilling,
        models.SlcMember.node_id,
    ).filter(
        models.SlcRadBilling.account_number ==
        models.SlcRadAccount.account_number,
        models.SlcMember.member_id == models.SlcRadAccount.member_id,
        models.SlcMember.member_id == get_cookie("customer_id"))
    if account_number:
        _query = _query.filter(
            models.SlcRadBilling.account_number.like('%' + account_number +
                                                     '%'))
    if query_begin_time:
        _query = _query.filter(
            models.SlcRadBilling.create_time >= query_begin_time)
    if query_end_time:
        _query = _query.filter(
            models.SlcRadBilling.create_time <= query_end_time)
    _query = _query.order_by(models.SlcRadBilling.create_time.desc())
    return render("billing_list",
                  accounts=db.query(models.SlcRadAccount).filter_by(
                      member_id=get_cookie("customer_id")),
                  page_data=get_page_data(_query),
                  **request.params)
Esempio n. 2
0
def ticket_query(db):
    account_number = request.params.get('account_number')
    query_begin_time = request.params.get('query_begin_time')
    query_end_time = request.params.get('query_end_time')
    _query = db.query(
        models.SlcRadTicket.id, models.SlcRadTicket.account_number,
        models.SlcRadTicket.nas_addr, models.SlcRadTicket.acct_session_id,
        models.SlcRadTicket.acct_start_time,
        models.SlcRadTicket.acct_input_octets,
        models.SlcRadTicket.acct_output_octets,
        models.SlcRadTicket.acct_stop_time, models.SlcRadTicket.framed_ipaddr,
        models.SlcRadTicket.mac_addr, models.SlcRadTicket.nas_port_id,
        models.SlcMember.node_id, models.SlcMember.realname).filter(
            models.SlcRadTicket.account_number ==
            models.SlcRadAccount.account_number,
            models.SlcMember.member_id == models.SlcRadAccount.member_id,
            models.SlcMember.member_id == get_cookie("customer_id"))
    if account_number:
        _query = _query.filter(
            models.SlcRadTicket.account_number == account_number)
    if query_begin_time:
        _query = _query.filter(
            models.SlcRadTicket.acct_start_time >= query_begin_time)
    if query_end_time:
        _query = _query.filter(
            models.SlcRadTicket.acct_stop_time <= query_end_time)

    _query = _query.order_by(models.SlcRadTicket.acct_start_time.desc())
    return render("ticket_list",
                  accounts=db.query(models.SlcRadAccount).filter_by(
                      member_id=get_cookie("customer_id")),
                  page_data=get_page_data(_query),
                  **request.params)
Esempio n. 3
0
def ticket_query(db): 
    account_number = request.params.get('account_number')  
    query_begin_time = request.params.get('query_begin_time')  
    query_end_time = request.params.get('query_end_time')  
    _query = db.query(
        models.SlcRadTicket.id,
        models.SlcRadTicket.account_number,
        models.SlcRadTicket.nas_addr,
        models.SlcRadTicket.acct_session_id,
        models.SlcRadTicket.acct_start_time,
        models.SlcRadTicket.acct_input_octets,
        models.SlcRadTicket.acct_output_octets,
        models.SlcRadTicket.acct_stop_time,
        models.SlcRadTicket.framed_ipaddr,
        models.SlcRadTicket.mac_addr,
        models.SlcRadTicket.nas_port_id,
        models.SlcMember.node_id,
        models.SlcMember.realname
    ).filter(
        models.SlcRadTicket.account_number == models.SlcRadAccount.account_number,
        models.SlcMember.member_id == models.SlcRadAccount.member_id,
        models.SlcMember.member_id == get_cookie("customer_id")
    )
    if account_number:
        _query = _query.filter(models.SlcRadTicket.account_number == account_number)
    if query_begin_time:
        _query = _query.filter(models.SlcRadTicket.acct_start_time >= query_begin_time)
    if query_end_time:
        _query = _query.filter(models.SlcRadTicket.acct_stop_time <= query_end_time)

    _query = _query.order_by(models.SlcRadTicket.acct_start_time.desc())
    return render("ticket_list", 
        accounts=db.query(models.SlcRadAccount).filter_by(member_id=get_cookie("customer_id")),
        page_data = get_page_data(_query),
        **request.params)    
Esempio n. 4
0
def customer_index(db):
    member,accounts,orders = get_data(db,get_cookie('customer'))
    status_colors = {0:'',1:'',2:'class="warning"',3:'class="danger"',4:'class="warning"'}
    return  render("index",
        member=member,
        accounts=accounts,
        orders=orders,
        status_colors=status_colors
    )    
Esempio n. 5
0
def password_update_get(db):
    form = forms.password_update_form()
    account_number = request.params.get('account_number')
    account = db.query(models.SlcRadAccount).get(account_number)
    if not account:
        return render("base_form", form=form, msg=u'没有这个账号')

    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form, msg=u'该账号用用户不匹配')

    form.account_number.set_value(account_number)
    return render("base_form", form=form)
Esempio n. 6
0
def billing_query(db): 
    account_number = request.params.get('account_number')  
    query_begin_time = request.params.get('query_begin_time')  
    query_end_time = request.params.get('query_end_time')  
    _query = db.query(
        models.SlcRadBilling,
        models.SlcMember.node_id,
    ).filter(
        models.SlcRadBilling.account_number == models.SlcRadAccount.account_number,
        models.SlcMember.member_id == models.SlcRadAccount.member_id,
        models.SlcMember.member_id == get_cookie("customer_id")
    )
    if account_number:
        _query = _query.filter(models.SlcRadBilling.account_number.like('%'+account_number+'%'))
    if query_begin_time:
        _query = _query.filter(models.SlcRadBilling.create_time >= query_begin_time)
    if query_end_time:
        _query = _query.filter(models.SlcRadBilling.create_time <= query_end_time)
    _query = _query.order_by(models.SlcRadBilling.create_time.desc())
    return render("billing_list", 
        accounts=db.query(models.SlcRadAccount).filter_by(member_id=get_cookie("customer_id")),
        page_data=get_page_data(_query),**request.params)
Esempio n. 7
0
def customer_index(db):
    member, accounts, orders = get_data(db, get_cookie('customer'))
    status_colors = {
        0: '',
        1: '',
        2: 'class="warning"',
        3: 'class="danger"',
        4: 'class="warning"'
    }
    return render("index",
                  member=member,
                  accounts=accounts,
                  orders=orders,
                  status_colors=status_colors)
Esempio n. 8
0
def password_update_post(db):
    form = forms.password_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    account = db.query(models.SlcRadAccount).get(form.d.account_number)
    if not account:
        return render("base_form", form=form, msg=u'没有这个账号')

    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form, msg=u'该账号用用户不匹配')

    if account.password != form.d.old_password:
        return render("base_form", form=form, msg=u'旧密码不正确')

    if form.d.new_password != form.d.new_password2:
        return render("base_form", form=form, msg=u'确认新密码不匹配')

    account.password = utils.encrypt(form.d.new_password)
    db.commit()
    redirect("/")
Esempio n. 9
0
def password_update_post(db):
    form = forms.password_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
        
    account = db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form,msg=u'没有这个账号')
        
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form,msg=u'该账号用用户不匹配')
    
    if utils.decrypt(account.password) !=  form.d.old_password:
        return render("base_form", form=form,msg=u'旧密码不正确')
        
    if form.d.new_password != form.d.new_password2:
        return render("base_form", form=form,msg=u'确认新密码不匹配')
    
    account.password =  utils.encrypt(form.d.new_password)
    db.commit()
    websock.update_cache("account",account_number=account.account_number)
    redirect("/")
Esempio n. 10
0
#coding:utf-8
import requests
from config import *
import base


def edit(areacode, wenli=2):
    body['ProvinceCode'] = areacode
    body['WenLi'] = wenli
    print requests.post(url=url, data=body, headers=header).content


if __name__ == "__main__":
    edit(410000)
    base.get_cookie()
Esempio n. 11
0
def customer_index(db):
    member, accounts, orders = get_data(db, get_cookie('customer'))
    return render("index", member=member, accounts=accounts, orders=orders)
Esempio n. 12
0
def account_recharge(db):
    form = forms.recharge_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
    if vcache.is_over(get_cookie("customer_id"), form.d.recharge_card):
        return render("base_form",
                      form=form,
                      msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")

    # 1 check card
    card = db.query(models.SlcRechargerCard).filter_by(
        card_number=form.d.recharge_card).first()
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('base_form', form=form, msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"), form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"), form.d.recharge_card)
        return render('base_form', form=form, msg=u"充值卡密码错误%s次" % errs)

    vcache.clear(get_cookie("customer_id"), form.d.recharge_card)

    # 2 check account
    account = db.query(models.SlcRadAccount).filter_by(
        account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form, msg=u'没有这个账号')
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form, msg=u'该账号用用户不匹配')
    if account.status not in (1, 4):
        return render("base_form", form=form, msg=u'只有正常或到期状态的用户才能充值')

    # 3 check product
    user_product = db.query(models.SlcRadProduct).get(account.product_id)
    if card.card_type == 0 and card.product_id != account.product_id:
        return render("base_form", form=form, msg=u'您使用的是资费套餐卡,但资费套餐与该账号资费不匹配')
    if card.card_type == 1 and user_product.product_policy not in (1, ):
        return render("base_form", form=form, msg=u'您使用的是余额卡,不能为当前账号包月资费充值')

    # 4 start recharge
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'charge'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助充值:上网账号:%s" % (form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)

    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = account.expire_date
    d_expire_date = datetime.datetime.strptime(expire_date, "%Y-%m-%d")
    if user_product.product_policy == 0:
        expire_date = utils.add_months(d_expire_date,
                                       card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price) * decimal.Decimal(
            card.months)
        order_fee = int(order_fee.to_integral_value())
    if user_product.product_policy == 2:
        expire_date = utils.add_months(d_expire_date,
                                       card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price)
        order_fee = int(order_fee.to_integral_value())
    elif user_product.product_policy == 1:
        balance = card.fee_value

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = account.product_id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助充值,充值卡[ %s ]" % form.d.recharge_card
    db.add(order)

    account.expire_date = expire_date
    account.balance += balance

    db.commit()
    redirect("/")
Esempio n. 13
0
def account_open(db):
    form = forms.account_open_form()
    if not form.validates(source=request.forms):
        return render("card_open_form", form=form)
    if vcache.is_over(get_cookie("customer_id"), form.d.recharge_card):
        return render("card_open_form",
                      form=form,
                      msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")

    card = db.query(models.SlcRechargerCard).filter_by(
        card_number=form.d.recharge_card).first()
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('card_open_form', form=form, msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"), form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"), form.d.recharge_card)
        return render('card_open_form', form=form, msg=u"充值卡密码错误%s次" % errs)

    vcache.clear(get_cookie("customer_id"), form.d.recharge_card)

    # start open
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户新开账号:上网账号:%s" % (form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)

    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = utils.add_months(datetime.datetime.now(),
                                   card.months).strftime("%Y-%m-%d")
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    if product.product_policy == 0:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(
            card.months)
        order_fee = int(order_fee.to_integral_value())
    if product.product_policy == 2:
        order_fee = decimal.Decimal(product.fee_price)
        order_fee = int(order_fee.to_integral_value())
    elif product.product_policy == 1:
        balance = card.fee_value
        expire_date = '3000-11-11'

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助开户,使用充值卡[ %s ]" % form.d.recharge_card
    db.add(order)

    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = ''
    account.member_id = get_cookie("customer_id")
    account.product_id = order.product_id
    account.install_address = ''
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = 1
    account.balance = balance
    account.time_length = 0
    account.expire_date = expire_date
    account.user_concur_number = product.concur_number
    account.bind_mac = product.bind_mac
    account.bind_vlan = product.bind_vlan
    account.vlan_id = 0
    account.vlan_id2 = 0
    account.create_time = _datetime
    account.update_time = _datetime
    db.add(account)

    clog = models.SlcRechargeLog()
    clog.member_id = get_cookie("customer_id")
    clog.card_number = card.card_number
    clog.account_number = form.d.account_number
    clog.recharge_status = 0
    clog.recharge_time = _datetime
    db.add(clog)

    card.card_status = 2

    db.commit()
    redirect('/')
Esempio n. 14
0
def account_recharge(db):
    form = forms.recharge_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
    if vcache.is_over(get_cookie("customer_id"),form.d.recharge_card):
         return render("base_form", form=form,msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")
    
    # 1 check card     
    card = db.query(models.SlcRechargerCard).filter_by(card_number=form.d.recharge_card).first()  
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('base_form',form=form,msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"),form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"),form.d.recharge_card)
        return render('base_form',form=form,msg=u"充值卡密码错误%s次"%errs)   
        
    vcache.clear(get_cookie("customer_id"),form.d.recharge_card)
        
    # 2 check account
    account = db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form,msg=u'没有这个账号')
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form,msg=u'该账号用用户不匹配')
    if account.status not in (1,4):
        return render("base_form", form=form,msg=u'只有正常或到期状态的用户才能充值')
    
    # 3 check product
    user_product = db.query(models.SlcRadProduct).get(account.product_id)    
    if card.card_type == 0 and card.product_id != account.product_id:
        return render("base_form", form=form,msg=u'您使用的是资费套餐卡,但资费套餐与该账号资费不匹配')
    if card.card_type == 1 and user_product.product_policy not in (1,):
        return render("base_form", form=form,msg=u'您使用的是余额卡,不能为当前账号包月资费充值')
    
    # 4 start recharge
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'charge'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助充值:上网账号:%s"%(form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log) 
    
    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = account.expire_date
    d_expire_date = datetime.datetime.strptime(expire_date,"%Y-%m-%d")
    if user_product.product_policy == 0:
        expire_date = utils.add_months(d_expire_date,card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price) * decimal.Decimal(card.months)
        order_fee = int(order_fee.to_integral_value())
    if user_product.product_policy == 2:
        expire_date = utils.add_months(d_expire_date,card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price) 
        order_fee = int(order_fee.to_integral_value())
    elif user_product.product_policy == 1:
        balance = card.fee_value
    
    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = account.product_id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助充值,充值卡[ %s ]"%form.d.recharge_card
    db.add(order)
         
    account.expire_date = expire_date
    account.balance += balance
    
    db.commit()
    redirect("/") 
Esempio n. 15
0
def account_open(db):
    form = forms.account_open_form()
    if not form.validates(source=request.forms):
        return render("card_open_form", form=form)
    if vcache.is_over(get_cookie("customer_id"),form.d.recharge_card):
         return render("card_open_form", form=form,msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试") 

    card = db.query(models.SlcRechargerCard).filter_by(card_number=form.d.recharge_card).first()  
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('card_open_form',form=form,msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"),form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"),form.d.recharge_card)
        return render('card_open_form',form=form,msg=u"充值卡密码错误%s次"%errs)
    
    vcache.clear(get_cookie("customer_id"),form.d.recharge_card)
    
    # start open
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户新开账号:上网账号:%s"%(form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)
    
    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = utils.add_months(datetime.datetime.now(),card.months).strftime("%Y-%m-%d") 
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    if product.product_policy == 0:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(card.months)
        order_fee = int(order_fee.to_integral_value())
    if product.product_policy == 2:
        order_fee = decimal.Decimal(product.fee_price) 
        order_fee = int(order_fee.to_integral_value())
    elif product.product_policy == 1:
        balance = card.fee_value
        expire_date = '3000-11-11'
    
    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助开户,使用充值卡[ %s ]"%form.d.recharge_card
    db.add(order)
    
    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = ''
    account.member_id = get_cookie("customer_id")
    account.product_id = order.product_id
    account.install_address = ''
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = 1
    account.balance = balance
    account.time_length = 0
    account.expire_date = expire_date
    account.user_concur_number = product.concur_number
    account.bind_mac = product.bind_mac
    account.bind_vlan = product.bind_vlan
    account.vlan_id = 0
    account.vlan_id2 = 0
    account.create_time = _datetime
    account.update_time = _datetime
    db.add(account)
    
    clog = models.SlcRechargeLog()
    clog.member_id = get_cookie("customer_id")
    clog.card_number = card.card_number
    clog.account_number = form.d.account_number
    clog.recharge_status = 0
    clog.recharge_time = _datetime
    db.add(clog)
    
    card.card_status = 2
    
    db.commit()
    redirect('/')