def opencalc(db): months = request.params.get('months', 0) product_id = request.params.get("product_id") old_expire = request.params.get("old_expire") product = db.query(models.SlcRadProduct).get(product_id) if product.product_policy == 1: return dict(code=0, data=dict(policy=product.product_policy, fee_value=0, expire_date="3000-12-30")) elif product.product_policy == 0: fee = decimal.Decimal(months) * decimal.Decimal(product.fee_price) fee_value = utils.fen2yuan(int(fee.to_integral_value())) start_expire = datetime.datetime.now() if old_expire: start_expire = datetime.datetime.strptime(old_expire, "%Y-%m-%d") expire_date = utils.add_months(start_expire, int(months)) expire_date = expire_date.strftime("%Y-%m-%d") return dict(code=0, data=dict(policy=product.product_policy, fee_value=fee_value, expire_date=expire_date)) elif product.product_policy == 2: start_expire = datetime.datetime.now() if old_expire: start_expire = datetime.datetime.strptime(old_expire, "%Y-%m-%d") fee_value = utils.fen2yuan(product.fee_price) expire_date = utils.add_months(start_expire, product.fee_months) expire_date = expire_date.strftime("%Y-%m-%d") return dict(code=0, data=dict(policy=product.product_policy, fee_value=fee_value, expire_date=expire_date))
def card_calc(db): product_id = request.params.get('product_id') product = db.query(models.SlcRadProduct).get(product_id) if product and product.product_policy == 0: return dict(code=0,data={ 'fee_value' : utils.fen2yuan(product.fee_price), 'months' : 1 }) elif product and product.product_policy == 2: return dict(code=0,data={ 'fee_value' : utils.fen2yuan(product.fee_price), 'months' : product.fee_months }) else: return dict(code=1,data=u"不支持的资费")
def product_update(db): product_id = request.params.get("product_id") form=forms.product_update_form() product = db.query(models.SlcRadProduct).get(product_id) form.fill(product) form.product_policy_name.set_value(forms.product_policy[product.product_policy]) form.fee_price.set_value(utils.fen2yuan(product.fee_price)) return render("sys_product_form",form=form)
def product_update(db): product_id = request.params.get("product_id") form = forms.product_update_form() product = db.query(models.SlcRadProduct).get(product_id) form.fill(product) form.product_policy_name.set_value( forms.product_policy[product.product_policy]) form.fee_price.set_value(utils.fen2yuan(product.fee_price)) return render("sys_product_form", form=form)
def card_list(db): product_id = request.params.get('product_id') card_type = request.params.get('card_type') card_status = request.params.get('card_status') batch_no = request.params.get('batch_no') query_begin_time = request.params.get('query_begin_time') query_end_time = request.params.get('query_end_time') _query = db.query(models.SlcRechargerCard) if product_id and card_type == '0': _query = _query.filter(models.SlcRechargerCard.product_id==product_id) if card_type: _query = _query.filter(models.SlcRechargerCard.card_type==card_type) if batch_no: _query = _query.filter(models.SlcRechargerCard.batch_no==batch_no) if card_status: _query = _query.filter(models.SlcRechargerCard.card_status==card_status) if query_begin_time: _query = _query.filter(models.SlcRechargerCard.create_time >= query_begin_time+' 00:00:00') if query_end_time: _query = _query.filter(models.SlcRechargerCard.create_time <= query_end_time+' 23:59:59') products = db.query(models.SlcRadProduct).filter( models.SlcRadProduct.product_status == 0, models.SlcRadProduct.product_policy.in_([0,2]) ) if request.path == '/list': print "total:",_query.count() return render("card_list", page_data = get_page_data(_query), card_types = forms.card_types, card_states = forms.card_states, products = products, colors = {0:'',1:'class="success"',2:'class="warning"',3:'class="danger"'}, **request.params ) elif request.path == '/export': data = Dataset() data.append(( u'批次号',u'充值卡号',u'充值卡密码',u'充值卡类型',u'状态', u'资费id', u'面值/售价',u"授权月数",u"过期时间",u'创建时间' )) print "total:",_query.count() for i in _query: data.append(( i.batch_no, i.card_number, utils.decrypt(i.card_passwd),forms.card_types[i.card_type], forms.card_states[i.card_status],get_product_name(db,i.product_id),utils.fen2yuan(i.fee_value), i.months,i.expire_date,i.create_time )) name = u"RADIUS-CARD-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".xls" with open(u'./static/xls/%s' % name, 'wb') as f: f.write(data.xls) return static_file(name, root='./static/xls',download=True)
def opencalc(db): months = request.params.get('months',0) product_id = request.params.get("product_id") old_expire = request.params.get("old_expire") product = db.query(models.SlcRadProduct).get(product_id) if product.product_policy == 1: return dict(code=0,data=dict(policy=product.product_policy,fee_value=0,expire_date="3000-12-30")) elif product.product_policy == 0: fee = decimal.Decimal(months) * decimal.Decimal(product.fee_price) fee_value = utils.fen2yuan(int(fee.to_integral_value())) start_expire = datetime.datetime.now() if old_expire: start_expire = datetime.datetime.strptime(old_expire,"%Y-%m-%d") expire_date = utils.add_months(start_expire,int(months)) expire_date = expire_date.strftime( "%Y-%m-%d") return dict(code=0,data=dict(policy=product.product_policy,fee_value=fee_value,expire_date=expire_date)) elif product.product_policy == 2: start_expire = datetime.datetime.now() if old_expire: start_expire = datetime.datetime.strptime(old_expire,"%Y-%m-%d") fee_value = utils.fen2yuan(product.fee_price) expire_date = utils.add_months(start_expire,product.fee_months) expire_date = expire_date.strftime( "%Y-%m-%d") return dict(code=0,data=dict(policy=product.product_policy,fee_value=fee_value,expire_date=expire_date))
def user_query(db): node_id = request.params.get('node_id') product_id = request.params.get('product_id') user_name = request.params.get('user_name') status = request.params.get('status') _query = db.query( models.SlcRadAccount, models.SlcMember.realname, models.SlcRadProduct.product_name).filter( models.SlcRadProduct.id == models.SlcRadAccount.product_id, models.SlcMember.member_id == models.SlcRadAccount.member_id) if node_id: _query = _query.filter(models.SlcMember.node_id == node_id) if product_id: _query = _query.filter(models.SlcRadAccount.product_id == product_id) if user_name: _query = _query.filter( models.SlcRadAccount.account_number.like('%' + user_name + '%')) if status: _query = _query.filter(models.SlcRadAccount.status == status) if request.path == '/user': return render("ops_user_list", page_data=get_page_data(_query), node_list=db.query(models.SlcNode), product_list=db.query(models.SlcRadProduct), **request.params) elif request.path == "/user/export": result = _query.all() data = Dataset() data.append((u'上网账号', u'姓名', u'资费', u'过期时间', u'余额(元)', u'时长(秒)', u'并发数', u'ip地址', u'状态', u'创建时间')) for i, _realname, _product_name in result: data.append( (i.account_number, _realname, _product_name, i.expire_date, utils.fen2yuan(i.balance), i.time_length, i.user_concur_number, i.ip_address, forms.user_state[i.status], i.create_time)) name = u"RADIUS-USER-" + datetime.datetime.now().strftime( "%Y%m%d-%H%M%S") + ".xls" with open(u'./static/xls/%s' % name, 'wb') as f: f.write(data.xls) return static_file(name, root='./static/xls', download=True)
def user_query(db): node_id = request.params.get('node_id') product_id = request.params.get('product_id') user_name = request.params.get('user_name') status = request.params.get('status') _query = db.query( models.SlcRadAccount, models.SlcMember.realname, models.SlcRadProduct.product_name ).filter( models.SlcRadProduct.id == models.SlcRadAccount.product_id, models.SlcMember.member_id == models.SlcRadAccount.member_id ) if node_id: _query = _query.filter(models.SlcMember.node_id == node_id) if product_id: _query = _query.filter(models.SlcRadAccount.product_id==product_id) if user_name: _query = _query.filter(models.SlcRadAccount.account_number.like('%'+user_name+'%')) if status: _query = _query.filter(models.SlcRadAccount.status == status) if request.path == '/user': return render("ops_user_list", page_data = get_page_data(_query), node_list=db.query(models.SlcNode), product_list=db.query(models.SlcRadProduct),**request.params) elif request.path == "/user/export": result = _query.all() data = Dataset() data.append((u'上网账号',u'姓名', u'资费', u'过期时间', u'余额(元)',u'时长(秒)',u'并发数',u'ip地址',u'状态',u'创建时间')) for i,_realname,_product_name in result: data.append(( i.account_number, _realname, _product_name, i.expire_date,utils.fen2yuan(i.balance), i.time_length,i.user_concur_number,i.ip_address, forms.user_state[i.status],i.create_time )) name = u"RADIUS-USER-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".xls" with open(u'./static/xls/%s' % name, 'wb') as f: f.write(data.xls) return static_file(name, root='./static/xls',download=True)