def account_next(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db, account_number) form = forms.account_next_form() form.product_id.set_value(user.product_id) if account.status not in (1, 4): return render("bus_account_next_form", user=user, form=form, msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_next_form", user=user, form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'next' accept_log.accept_source = 'console' accept_log.accept_desc = u"用户续费:上网账号:%s,续费%s元" % (account_number, form.d.fee_value) accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 product = db.query(models.SlcRadProduct).get(user.product_id) order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal( form.d.months) order_fee = int(order_fee.to_integral_value()) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = utils.get_currtime() order.order_desc = u"用户续费" db.add(order) account.status = 1 account.expire_date = form.d.expire_date db.commit() websock.update_cache("account", account_number=account_number) redirect("/bus/member/detail?member_id={}".format(user.member_id))
def account_next(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db, account_number) form = forms.account_cancel_form() if account.status != 1: return render("bus_account_form", user=user, form=form, msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_form", user=user, form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'cancel' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") accept_log.accept_desc = u"用户销户:上网账号:%s,退费%s(元)" % (account_number, form.d.fee_value) db.add(accept_log) db.flush() db.refresh(accept_log) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = 0 order.actual_fee = -utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.order_source = 'console' order.accept_id = accept_log.id order.create_time = utils.get_currtime() order.order_desc = u'用户销户' db.add(order) account.status = 3 db.commit() websock.update_cache("account", account_number=account_number) onlines = db.query( models.SlcRadOnline).filter_by(account_number=account_number) for _online in onlines: websock.invoke_admin("coa_request", nas_addr=_online.nas_addr, acct_session_id=_online.acct_session_id, message_type='disconnect') redirect("/bus/member/detail?member_id={}".format(user.member_id))
def account_next(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db,account_number) form = forms.account_next_form() form.product_id.set_value(user.product_id) if account.status not in (1,4): return render("bus_account_next_form", user=user,form=form,msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_next_form", user=user,form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'next' accept_log.accept_source = 'console' accept_log.accept_desc = u"用户续费:上网账号:%s,续费%s元"%(account_number,form.d.fee_value) accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 product = db.query(models.SlcRadProduct).get(user.product_id) order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months) order_fee = int(order_fee.to_integral_value()) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = utils.get_currtime() order.order_desc = u"用户续费" db.add(order) account.status = 1 account.expire_date = form.d.expire_date db.commit() websock.update_cache("account",account_number=account_number) redirect(member_detail_url_formatter(user.member_id))
def account_next(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db,account_number) form = forms.account_cancel_form() if account.status !=1 : return render("bus_account_form", user=user,form=form,msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_form", user=user,form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'cancel' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") accept_log.accept_desc = u"用户销户:上网账号:%s,退费%s(元)"%(account_number,form.d.fee_value) db.add(accept_log) db.flush() db.refresh(accept_log) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = 0 order.actual_fee = -utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.order_source = 'console' order.accept_id = accept_log.id order.create_time = utils.get_currtime() order.order_desc = u'用户销户' db.add(order) account.status = 3 db.commit() websock.update_cache("account",account_number=account_number) onlines = db.query(models.SlcRadOnline).filter_by(account_number=account_number) for _online in onlines: websock.invoke_admin("coa_request", nas_addr=_online.nas_addr, acct_session_id=_online.acct_session_id, message_type='disconnect') redirect(member_detail_url_formatter(user.member_id))
def account_charge(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db, account_number) form = forms.account_charge_form() if account.status != 1: return render("bus_account_form", user=user, form=form, msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_form", user=user, form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'charge' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") _new_fee = account.balance + utils.yuan2fen(form.d.fee_value) accept_log.accept_desc = u"用户充值:上网账号:%s,充值前%s(分),充值后%s(分)" % ( account_number, account.balance, _new_fee) db.add(accept_log) db.flush() db.refresh(accept_log) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = 0 order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = utils.get_currtime() order.order_desc = u"用户充值" db.add(order) account.balance += order.actual_fee db.commit() websock.update_cache("account", account_number=account_number) redirect("/bus/member/detail?member_id={}".format(user.member_id))
def account_charge(db): account_number = request.params.get("account_number") account = db.query(models.SlcRadAccount).get(account_number) user = query_account(db,account_number) form = forms.account_charge_form() if account.status !=1 : return render("bus_account_form", user=user,form=form,msg=u"无效用户状态") if not form.validates(source=request.forms): return render("bus_account_form", user=user,form=form) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'charge' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") _new_fee = account.balance + utils.yuan2fen(form.d.fee_value) accept_log.accept_desc = u"用户充值:上网账号:%s,充值前%s(分),充值后%s(分)"%(account_number,account.balance,_new_fee) db.add(accept_log) db.flush() db.refresh(accept_log) order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = user.member_id order.product_id = user.product_id order.account_number = form.d.account_number order.order_fee = 0 order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = utils.get_currtime() order.order_desc = u"用户充值" db.add(order) account.balance += order.actual_fee db.commit() websock.update_cache("account",account_number=account_number) redirect(member_detail_url_formatter(user.member_id))
def member_import(db): nodes = [(n.id, n.node_name) for n in db.query(models.SlcNode)] products = [(p.id, p.product_name) for p in db.query(models.SlcRadProduct)] iform = forms.user_import_form(nodes, products) node_id = request.params.get('node_id') product_id = request.params.get('product_id') upload = request.files.get('import_file') impctx = upload.file.read() lines = impctx.split("\n") _num = 0 impusers = [] for line in lines: _num += 1 line = line.strip() if not line or "用户姓名" in line: continue attr_array = line.split(",") if len(attr_array) < 5: return render("bus_import_form", form=iform, msg=u"line %s error: length must 5 " % _num) vform = forms.user_import_vform() if not vform.validates( dict(realname=attr_array[0], account_number=attr_array[1], password=attr_array[2], expire_date=attr_array[3], balance=attr_array[4])): return render("bus_import_form", form=iform, msg=u"line %s error: %s" % (_num, vform.errors)) impusers.append(vform) for form in impusers: try: member = models.SlcMember() member.node_id = node_id member.realname = form.d.realname member.idcard = '123456' member.member_name = form.d.account_number member.password = form.d.account_number member.sex = '1' member.age = '0' member.email = '' member.mobile = '123456' member.address = 'address' member.create_time = utils.get_currtime() member.update_time = utils.get_currtime() db.add(member) db.flush() db.refresh(member) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' accept_log.accept_desc = u"用户导入账号:(%s)%s - 上网账号:%s" % ( member.member_name, member.realname, form.d.account_number) accept_log.account_number = form.d.account_number accept_log.accept_time = member.create_time accept_log.operator_name = get_cookie("username") db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 actual_fee = 0 balance = 0 expire_date = form.d.expire_date product = db.query(models.SlcRadProduct).get(product_id) if product.product_policy == 1: balance = int(form.d.balance) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = member.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = actual_fee order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = member.create_time order.order_desc = u"用户导入开户" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.member_id = member.member_id account.product_id = order.product_id account.install_address = member.address account.ip_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 = member.create_time account.update_time = member.create_time db.add(account) except Exception as e: return render("bus_import_form", form=iform, msg=u"error : %s" % str(e)) db.commit() redirect("/bus/member")
def account_open(db): products = [ (n.id, n.product_name) for n in db.query(models.SlcRadProduct).filter_by(product_status=0) ] form = forms.account_open_form(products) if not form.validates(source=request.forms): return render("bus_open_form", form=form) if db.query(models.SlcRadAccount).filter_by( account_number=form.d.account_number).count() > 0: return render("bus_open_form", form=form, msg=u"上网账号已经存在") if form.d.ip_address and db.query(models.SlcRadAccount).filter_by( ip_address=form.d.ip_address).count() > 0: return render("bus_open_form", form=form, msg=u"ip%s已经被使用" % form.d.ip_address) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") 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 = form.d.expire_date product = db.query(models.SlcRadProduct).get(form.d.product_id) if product.product_policy == 0: order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal( form.d.months) order_fee = int(order_fee.to_integral_value()) elif product.product_policy == 1: balance = utils.yuan2fen(form.d.fee_value) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = form.d.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = _datetime order.order_desc = u"用户增开账号" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.ip_address = form.d.ip_address account.member_id = int(form.d.member_id) account.product_id = order.product_id account.install_address = form.d.address account.mac_addr = '' account.password = utils.encrypt(form.d.password) account.status = form.d.status 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) db.commit() redirect("/bus/member/detail?member_id={}".format(form.d.member_id))
def member_import(db): nodes = [ (n.id,n.node_name) for n in db.query(models.SlcNode)] products = [(p.id,p.product_name) for p in db.query(models.SlcRadProduct)] iform = forms.user_import_form(nodes,products) node_id = request.params.get('node_id') product_id = request.params.get('product_id') upload = request.files.get('import_file') impctx = upload.file.read() lines = impctx.split("\n") _num = 0 impusers = [] for line in lines: _num += 1 line = line.strip() if not line or "用户姓名" in line:continue attr_array = line.split(",") if len(attr_array) < 5: return render("bus_import_form",form=iform,msg=u"line %s error: length must 5 "%_num) vform = forms.user_import_vform() if not vform.validates(dict( realname = attr_array[0], account_number = attr_array[1], password = attr_array[2], expire_date = attr_array[3], balance = str(utils.yuan2fen(attr_array[4])))): return render("bus_import_form",form=iform,msg=u"line %s error: %s"%(_num,vform.errors)) impusers.append(vform) for form in impusers: try: member = models.SlcMember() member.node_id = node_id member.realname = form.d.realname member.idcard = '123456' member.member_name = form.d.account_number member.password = form.d.account_number member.sex = '1' member.age = '0' member.email = '' member.mobile = '123456' member.address = 'address' member.create_time = utils.get_currtime() member.update_time = utils.get_currtime() db.add(member) db.flush() db.refresh(member) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' _desc = u"用户导入账号:(%s)%s - 上网账号:%s"% \ (member.member_name,member.realname,form.d.account_number) accept_log.accept_desc = _desc accept_log.account_number = form.d.account_number accept_log.accept_time = member.create_time accept_log.operator_name = get_cookie("username") db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 actual_fee = 0 balance = 0 expire_date = form.d.expire_date product = db.query(models.SlcRadProduct).get(product_id) if product.product_policy == 1: balance = int(form.d.balance) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = member.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = actual_fee order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = member.create_time order.order_desc = u"用户导入开户" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.member_id = member.member_id account.product_id = order.product_id account.install_address = member.address account.ip_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 = member.create_time account.update_time = member.create_time db.add(account) except Exception as e: return render("bus_import_form",form=iform,msg=u"error : %s"%str(e)) db.commit() redirect("/bus/member")
def member_open(db): nodes = [ (n.id,n.node_name) for n in db.query(models.SlcNode)] products = [ (n.id,n.product_name) for n in db.query(models.SlcRadProduct).filter_by( product_status = 0 )] form = forms.user_open_form(nodes,products) if not form.validates(source=request.forms): return render("bus_open_form", form=form) if db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).count()>0: return render("bus_open_form", form=form,msg=u"上网账号%s已经存在"%form.d.account_number) if form.d.ip_address and db.query(models.SlcRadAccount).filter_by(ip_address=form.d.ip_address).count()>0: return render("bus_open_form", form=form,msg=u"ip%s已经被使用"%form.d.ip_address) if db.query(models.SlcMember).filter_by( member_name=form.d.member_name).count()>0: return render("bus_open_form", form=form,msg=u"用户名%s已经存在"%form.d.member_name) member = models.SlcMember() member.node_id = form.d.node_id member.realname = form.d.realname member.member_name = form.d.member_name member.password = md5(form.d.member_password.encode()).hexdigest() member.idcard = form.d.idcard member.sex = '1' member.age = '0' member.email = '' member.mobile = form.d.mobile member.address = form.d.address member.create_time = utils.get_currtime() member.update_time = utils.get_currtime() db.add(member) db.flush() db.refresh(member) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = member.create_time accept_log.operator_name = get_cookie("username") accept_log.accept_desc = u"用户新开户:(%s)%s - 上网账号:%s"%(member.member_name,member.realname,form.d.account_number) db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 balance = 0 expire_date = form.d.expire_date product = db.query(models.SlcRadProduct).get(form.d.product_id) if product.product_policy == 0: order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months) order_fee = int(order_fee.to_integral_value()) elif product.product_policy == 1: balance = utils.yuan2fen(form.d.fee_value) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = member.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = member.create_time order.order_desc = u"用户新开账号" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.ip_address = form.d.ip_address account.member_id = member.member_id account.product_id = order.product_id account.install_address = member.address account.mac_addr = '' account.password = utils.encrypt(form.d.password) account.status = form.d.status 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 = member.create_time account.update_time = member.create_time db.add(account) db.commit() redirect("/bus/member")
def account_open(db): products = [ (n.id,n.product_name) for n in db.query(models.SlcRadProduct).filter_by( product_status = 0 )] form = forms.account_open_form(products) if not form.validates(source=request.forms): return render("bus_open_form", form=form) if db.query(models.SlcRadAccount).filter_by( account_number=form.d.account_number).count()>0: return render("bus_open_form", form=form,msg=u"上网账号已经存在") if form.d.ip_address and db.query(models.SlcRadAccount).filter_by(ip_address=form.d.ip_address).count()>0: return render("bus_open_form", form=form,msg=u"ip%s已经被使用"%form.d.ip_address) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = utils.get_currtime() accept_log.operator_name = get_cookie("username") 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 = form.d.expire_date product = db.query(models.SlcRadProduct).get(form.d.product_id) if product.product_policy == 0: order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.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 = utils.yuan2fen(form.d.fee_value) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = form.d.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = _datetime order.order_desc = u"用户增开账号" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.ip_address = form.d.ip_address account.member_id = int(form.d.member_id) account.product_id = order.product_id account.install_address = form.d.address account.mac_addr = '' account.password = utils.encrypt(form.d.password) account.status = form.d.status 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) db.commit() redirect(member_detail_url_formatter(form.d.member_id))
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("/")
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('/')
def member_open(db): nodes = [ (n.id,n.node_name) for n in db.query(models.SlcNode)] products = [ (n.id,n.product_name) for n in db.query(models.SlcRadProduct).filter_by( product_status = 0 )] groups = [ (n.id,n.group_name) for n in db.query(models.SlcRadGroup)] groups.insert(0,('','')) form = forms.user_open_form(nodes,products,groups) if not form.validates(source=request.forms): return render("bus_open_form", form=form) if db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).count()>0: return render("bus_open_form", form=form,msg=u"上网账号%s已经存在"%form.d.account_number) if form.d.ip_address and db.query(models.SlcRadAccount).filter_by(ip_address=form.d.ip_address).count()>0: return render("bus_open_form", form=form,msg=u"ip%s已经被使用"%form.d.ip_address) if db.query(models.SlcMember).filter_by( member_name=form.d.member_name).count()>0: return render("bus_open_form", form=form,msg=u"用户名%s已经存在"%form.d.member_name) member = models.SlcMember() member.node_id = form.d.node_id member.realname = form.d.realname member.member_name = form.d.member_name member.password = md5(form.d.member_password.encode()).hexdigest() member.idcard = form.d.idcard member.sex = '1' member.age = '0' member.email = '' member.mobile = form.d.mobile member.address = form.d.address member.create_time = utils.get_currtime() member.update_time = utils.get_currtime() db.add(member) db.flush() db.refresh(member) accept_log = models.SlcRadAcceptLog() accept_log.accept_type = 'open' accept_log.accept_source = 'console' accept_log.account_number = form.d.account_number accept_log.accept_time = member.create_time accept_log.operator_name = get_cookie("username") accept_log.accept_desc = u"用户新开户:(%s)%s - 上网账号:%s"%(member.member_name,member.realname,form.d.account_number) db.add(accept_log) db.flush() db.refresh(accept_log) order_fee = 0 balance = 0 expire_date = form.d.expire_date product = db.query(models.SlcRadProduct).get(form.d.product_id) if product.product_policy == 0: order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months) order_fee = int(order_fee.to_integral_value()) elif product.product_policy == 1: balance = utils.yuan2fen(form.d.fee_value) expire_date = '3000-11-11' order = models.SlcMemberOrder() order.order_id = utils.gen_order_id() order.member_id = member.member_id order.product_id = product.id order.account_number = form.d.account_number order.order_fee = order_fee order.actual_fee = utils.yuan2fen(form.d.fee_value) order.pay_status = 1 order.accept_id = accept_log.id order.order_source = 'console' order.create_time = member.create_time order.order_desc = u"用户新开账号" db.add(order) account = models.SlcRadAccount() account.account_number = form.d.account_number account.ip_address = form.d.ip_address account.member_id = member.member_id account.product_id = order.product_id account.install_address = member.address account.mac_addr = '' account.password = utils.encrypt(form.d.password) account.status = form.d.status 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 = member.create_time account.update_time = member.create_time db.add(account) db.commit() redirect("/bus/member")
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("/")
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('/')