コード例 #1
0
ファイル: alipayment_new.py プロジェクト: sailorhdx/taurusxr
 def post(self):
     try:
         product_id = self.get_argument('product_id', '')
         product = self.db.query(models.TrProduct).get(product_id)
         if not product:
             return self.render('neworder_form.html', form=form, msg=u'套餐不存在')
         form = order_forms.order_form(product.product_policy)
         if not form.validates(source=self.get_params()):
             return self.render('neworder_form.html', form=form, msg=form.errors)
         account_count = self.db.query(models.TrCustomer).filter_by(email=form.d.email).count()
         if account_count > 0:
             return self.render('neworder_form.html', form=form, msg=u'电子邮件已经存在')
         if form.d.vcard_code and form.d.vcard_pwd:
             return self.do_vcard(form, product)
         _feevalue, _expire = self.order_calc(form.d.product_id)
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata.order_id = order_id
         formdata['node_id'] = self.get_param_value('default_user_node_id', 1)
         formdata['area_id'] = ''
         formdata['fee_value'] = _feevalue
         formdata['expire_date'] = _expire
         formdata['accept_source'] = 'ssportal'
         formdata['giftdays'] = 0
         formdata['giftflows'] = 0
         formdata['ip_address'] = ''
         formdata['status'] = 1
         formdata['customer_desc'] = u'客户自助开户'
         formdata['product_name'] = product.product_name
         self.paycache.set(order_paycaache_key(order_id), formdata)
         return self.render('order_alipay.html', formdata=formdata)
     except Exception as err:
         logger.exception(err)
         return self.render('neworder_form.html', form=form, msg=u'无效的订单')
コード例 #2
0
 def acctounting(self):
     if not self.account:
         return logger.error(u'收到用户:%s 记账结束请求,但用户资料不存在' %
                             self.request.account_number,
                             tag='radius_acct_stop_error',
                             trace='radius',
                             username=self.request.account_number)
     ticket = Storage(**self.request)
     _datetime = datetime.datetime.now()
     online = self.get_online(ticket.nas_addr, ticket.acct_session_id)
     if not online:
         session_time = ticket.acct_session_time
         stop_time = _datetime.strftime('%Y-%m-%d %H:%M:%S')
         start_time = (_datetime - datetime.timedelta(
             seconds=int(session_time))).strftime('%Y-%m-%d %H:%M:%S')
         ticket.acct_start_time = start_time
         ticket.acct_stop_time = stop_time
         ticket.start_source = STATUS_TYPE_STOP
         ticket.stop_source = STATUS_TYPE_STOP
         self.add_ticket(ticket)
     else:
         self.del_online(ticket.nas_addr, ticket.acct_session_id)
         ticket.acct_start_time = online.acct_start_time
         ticket.acct_stop_time = _datetime.strftime('%Y-%m-%d %H:%M:%S')
         ticket.start_source = online.start_source
         ticket.stop_source = STATUS_TYPE_STOP
         self.add_ticket(ticket)
         self.billing(online)
         logger.info(u'用户:%s 记账结束, 清除在线用户数据' % self.account.account_number,
                     trace='radius',
                     username=online.account_number)
コード例 #3
0
ファイル: alipayment_new.py プロジェクト: sailorhdx/taurusxr
 def do_vcard(self, form, product):
     vcard_code = form.d.vcard_code
     vcard_pwd = form.d.vcard_pwd
     _feevalue, _expire = self.order_calc(form.d.product_id)
     order_id = utils.gen_order_id()
     formdata = Storage(form.d)
     formdata.order_id = order_id
     formdata['node_id'] = self.get_param_value('default_user_node_id', 1)
     formdata['area_id'] = ''
     formdata['fee_value'] = _feevalue
     formdata['expire_date'] = _expire
     formdata['accept_source'] = 'ssportal'
     formdata['giftdays'] = 0
     formdata['giftflows'] = 0
     formdata['ip_address'] = ''
     formdata['status'] = 1
     formdata['vcard_code'] = vcard_code
     formdata['vcard_pwd'] = vcard_pwd
     formdata['customer_desc'] = u'客户自助充值卡开户'
     formdata['product_name'] = product.product_name
     manager = CustomerAdd(self.db, self.aes)
     ret = manager.add(formdata)
     if ret:
         order = self.db.query(models.TrCustomerOrder).get(order_id)
         logger.info(u'充值卡开户成功')
         self.render('alipay_return.html', order=order)
     else:
         return self.render_error(code=1, msg=u'充值卡订单处理失败 %s' % manager.last_error)
コード例 #4
0
 def acctounting(self):
     if not self.account:
         dispatch.pub(UNLOCK_ONLINE_EVENT,
                      self.request.account_number,
                      self.request.nas_addr,
                      self.request.acct_session_id,
                      async=True)
         return logger.error(u'收到用户:%s 记账更新请求,但用户资料不存在' %
                             self.request.account_number,
                             tag='radius_acct_update_error',
                             trace='radius',
                             username=self.request.account_number)
     ticket = Storage(**self.request)
     online = self.get_online(ticket.nas_addr, ticket.acct_session_id)
     if not online:
         sessiontime = ticket.acct_session_time
         updatetime = datetime.datetime.now()
         _starttime = updatetime - datetime.timedelta(seconds=sessiontime)
         online = Storage(
             account_number=self.account.account_number,
             nas_addr=ticket.nas_addr,
             acct_session_id=ticket.acct_session_id,
             acct_start_time=_starttime.strftime('%Y-%m-%d %H:%M:%S'),
             framed_ipaddr=ticket.framed_ipaddr or '',
             mac_addr=ticket.mac_addr or '',
             nas_port_id=ticket.nas_port_id or '',
             billing_times=ticket.acct_session_time,
             input_total=self.get_input_total(),
             output_total=self.get_output_total(),
             start_source=STATUS_TYPE_UPDATE)
         self.add_online(online)
     self.billing(online)
     logger.info(u'用户:%s 记账更新, 更新用户在线数据' % self.account.account_number,
                 trace='radius',
                 username=online.account_number)
コード例 #5
0
ファイル: test_product.py プロジェクト: sailorhdx/taurusxr
 def test_add_update_ppmf_product(self):
     pid = None
     with make_db(self.db) as db:
         formdata = Storage({
             'input_max_limit':
             '10',
             'output_max_limit':
             '10',
             'bind_mac':
             '0',
             'flow_price':
             '1',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'fee_flows':
             '10',
             'concur_number':
             '0',
             'bind_vlan':
             '0',
             'fee_price':
             '10',
             'max_giftflows':
             '10',
             'product_name':
             u'\u6d4b\u8bd5\u6d41\u91cf\u5305\u6708\u8d44\u8d3930G10\u5143\u81ea\u52a8\u7eed\u8d39'
         })
         serv = ProductService(db, self.aes)
         item = serv.add_ppmf(formdata)
         self.print_error(serv)
         raise item or AssertionError
         pid = item.id
     with make_db(self.db) as db:
         formdata2 = Storage({
             'input_max_limit': '10.000',
             'bind_mac': '0',
             'flow_price': '1',
             'free_auth': '1',
             'fee_flows': '10.00',
             'product_name':
             u'\u6d4b\u8bd5\u6d41\u91cf\u5305\u6708\u8d44\u8d3930G10\u5143',
             'concur_number': '10',
             'free_auth_uprate': '2.000',
             'output_max_limit': '10.000',
             'bind_vlan': '0',
             'fee_price': '10.00',
             'max_giftflows': '10',
             'free_auth_downrate': '2.000',
             'product_status': '0',
             'id': pid
         })
         raise serv.update_ppmf(formdata2) or AssertionError
     with make_db(self.db) as db:
         raise serv.delete(pid) or AssertionError
     return
コード例 #6
0
 def test_agency_change(self):
     product1 = self.add_bomonth_product(price=400)
     raise product1 or AssertionError
     product2 = self.add_bomonth_product(price=500)
     raise product2 or AssertionError
     pids = [product1.id]
     agency1 = self.add_agency(
         u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u53d8\u66f4\u6d4b\u8bd5)',
         'agency4', '1000', '50', pids)
     raise agency1 or AssertionError
     user1 = self.add_customer('chuser1', product1, agency1)
     raise user1 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({
             'account_number': 'chuser1',
             'add_value': 100,
             'product_id': product2.id,
             'expire_date': '2017-12-12',
             'operate_desc': u'\u6d4b\u8bd5\u53d8\u66f4\u8d44\u8d39',
             'balance': '0.00',
             'time_length': '0',
             'flow_length': '0'
         })
         serv = AccountChange(db, self.aes)
         self.print_error(serv)
         raise serv.change(formdata) or AssertionError
コード例 #7
0
ファイル: vcard_charge.py プロジェクト: sailorhdx/taurusxr
 def post(self):
     form = order_forms.vcard_charge_form()
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(
         form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = '0.00'
         formdata['accept_source'] = 'ssportal'
         formdata['operate_desc'] = u'用户自助充值卡充值'
         formdata['vcard_code'] = form.d.vcard_code
         formdata['vcard_pwd'] = form.d.vcard_pwd
         manager = AccountCharge(self.db, self.aes)
         ret = manager.charge(formdata)
         if ret:
             logger.info(u'充值卡充值成功')
             self.render_json(code=0, msg=u'充值卡充值成功')
         else:
             return self.render_json(code=1,
                                     msg=u'充值卡订单处理失败 %s' %
                                     manager.last_error)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=1, msg=u'无效的订单')
コード例 #8
0
 def acctounting(self):
     if self.is_online(self.request.nas_addr, self.request.acct_session_id):
         return logger.error(u'用户:%s 已经在线' % self.request.acct_session_id,
                             tag='radius_acct_start_error')
     if not self.account:
         dispatch.pub(UNLOCK_ONLINE_EVENT,
                      self.request.account_number,
                      self.request.nas_addr,
                      self.request.acct_session_id,
                      async=True)
         return logger.error(u'用户:%s 不存在' % self.request.account_number,
                             tag='radius_acct_start_error')
     online = Storage(account_number=self.request.account_number,
                      nas_addr=self.request.nas_addr,
                      acct_session_id=self.request.acct_session_id,
                      acct_start_time=datetime.datetime.now().strftime(
                          '%Y-%m-%d %H:%M:%S'),
                      framed_ipaddr=self.request.framed_ipaddr,
                      mac_addr=self.request.mac_addr or '',
                      nas_port_id=self.request.nas_port_id,
                      billing_times=0,
                      input_total=0,
                      output_total=0,
                      start_source=STATUS_TYPE_START)
     self.add_online(online)
     logger.info(u'用户:%s 记账开始, 新增在线用户数据' % online.account_number,
                 trace='radius',
                 username=online.account_number)
コード例 #9
0
 def post(self):
     try:
         openid = self.session.get('mps_openid',
                                   os.environ.get('DEV_OPEN_ID'))
         customer = self.db.query(
             models.TrCustomer).filter_by(wechat_oid=openid).first()
         account = self.db.query(models.TrAccount).filter_by(
             customer_id=customer.customer_id).first()
         product = self.db.query(
             models.TrProduct).filter_by(id=account.product_id).first()
         fee_value = self.get_argument('fee_value', '')
         if not rules.is_rmb.valid(fee_value):
             return self.render('wxrecharge_order_form.html',
                                account=account,
                                product=product,
                                msg=u'金额校验错误',
                                **self.get_params())
         order_id = tools.gen_num_id(16)
         formdata = Storage({'order_attach': 'rechargeorder'})
         formdata['wxpay_body'] = u'套餐充值:%s' % product.product_name
         formdata['openid'] = openid
         formdata['order_id'] = order_id
         formdata['account_number'] = account.account_number
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = fee_value
         formdata['accept_source'] = 'wechat'
         formdata['operate_desc'] = u'用户微信支付充值'
         self.paycache.set(order_wxpaycaache_key(order_id), formdata, 28800)
         self.redirect('/mps/wxorder/pay/%s' % order_id)
     except Exception as err:
         logger.exception(err, trace='wechat')
         self.render('error.html', msg=u'用户充值失败,请联系客服 %s' % repr(err))
コード例 #10
0
 def test_add_agency_and_renew(self):
     product1 = self.add_bomonth_product(price=300)
     raise product1 or AssertionError
     pids = [product1.id]
     agency1 = self.add_agency(
         u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u7eed\u8d39\u6d4b\u8bd5)',
         'agrenew', '1500', '50', pids)
     raise agency1 or AssertionError
     user1 = self.add_customer('auser_renew', product1, agency1)
     raise user1 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({
             'product_id':
             product1.id,
             'old_expire':
             '2016-12-12',
             'account_number':
             'auser_renew',
             'giftdays':
             '0',
             'months':
             0,
             'fee_value':
             product1.fee_price / 100.0,
             'expire_date':
             '2017-12-12',
             'operate_desc':
             u'\u6d4b\u8bd5\u4ee3\u7406\u5546\u7528\u6237\u7eed\u8d39'
         })
         serv = AccountRenew(db, self.aes)
         item = serv.renew(formdata)
         self.print_error(serv)
         raise item or AssertionError
コード例 #11
0
 def add_customer(self, username, product, agency=None):
     from taurusxradius.modules.dbservice.customer_add import CustomerAdd
     with make_db(self.db) as db:
         formdata = Storage({
             'account_number': username,
             'password': '******',
             'area_id': '1',
             'idcard': '000000',
             'agency_id': str(agency.id) if agency else None,
             'builder_name': None,
             'giftflows': '0',
             'giftdays': '0',
             'charge_code': None,
             'expire_date': '2017-06-27',
             'fee_value': str(product.fee_price / 100.0),
             'status': '1',
             'realname': 'r_%s' % username,
             'node_id': '1',
             'account_rule': '1',
             'address': u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740',
             'ip_address': None,
             'product_id': str(product.id),
             'mobile': '000000',
             'months': '0',
             'customer_desc': u'\u6d4b\u8bd5\u7528\u6237'
         })
         serv = CustomerAdd(db, self.aes)
         cuser = serv.add(formdata)
         self.print_error(serv)
         return cuser
     return
コード例 #12
0
 def test_update_agency(self):
     product1 = self.add_bomonth_product(price=1000)
     raise product1 or AssertionError
     pids = [product1.id]
     agency2 = self.add_agency(
         u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u6d4b\u8bd5\u4fee\u6539)',
         'agencyup', '50000', '30', pids)
     raise agency2 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({
             'agency_id': agency2.id,
             'agency_name':
             '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbb\xa3\xe7\x90\x86\xe5\x95\x86(\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9ok)',
             'contact': 'wjt1',
             'mobile': '13333333334',
             'share_rate': 20,
             'operator_status': 0,
             'operator_name': 'agencyupopr',
             'operator_pass': '******',
             'agency_desc': u'\u6d4b\u8bd5\u4ee3\u7406\u5546'
         })
         serv = AgencyService(db, self.aes)
         item = serv.update(formdata,
                            operator_nodes=[1],
                            operator_products=pids)
         self.print_error(serv)
         raise item or AssertionError
コード例 #13
0
 def test_add_update_delete_bas(self):
     node = self.add_node()
     bas = None
     with make_db(self.db) as db:
         serv = BasService(db, self.aes, config=self.config)
         ret = serv.add(
             Storage({
                 'ip_addr': '127.0.0.2',
                 'nas_id': '12121211',
                 'nodes': [node.id],
                 'dns_name': '',
                 'bas_name': 'taurusxac',
                 'bas_secret': '123456',
                 'vendor_id': '0',
                 'coa_port': '3799',
                 'sync_ver': tools.gen_sync_ver()
             }))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         bas = self.warp(ret)
         raise bas or AssertionError
     with make_db(self.db) as db:
         serv = BasService(db, self.aes, config=self.config)
         ret = serv.update(
             Storage({
                 'id': bas.id,
                 'ip_addr': '127.1.0.1',
                 'nas_id': '12121211',
                 'nodes': [node.id],
                 'dns_name': '',
                 'bas_name': 'taurusxac2',
                 'bas_secret': '123456',
                 'vendor_id': '0',
                 'coa_port': '3799',
                 'sync_ver': tools.gen_sync_ver()
             }))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         bas = self.warp(ret)
         raise bas or AssertionError
     with make_db(self.db) as db:
         serv = BasService(db, self.aes, config=self.config)
         ret = serv.delete(bas.id)
         if hasattr(serv, 'last_error'):
             print serv.last_error
         raise ret or AssertionError
     return
コード例 #14
0
    def warp(self, mdl):
        if not hasattr(mdl, '__table__'):
            return
        data = Storage()
        for c in mdl.__table__.columns:
            data[c.name] = getattr(mdl, c.name)

        return data
コード例 #15
0
ファイル: syncd.py プロジェクト: sailorhdx/taurusxr
 def dataReceived(self, msgid, request):
     if 'HASYNC_DISABLE' in os.environ:
         return
     try:
         message = msgpack.unpackb(request)
         self.que.appendleft([msgid, Storage(message)])
     except:
         logger.error(traceback.print_exc())
コード例 #16
0
ファイル: businessgw.py プロジェクト: sailorhdx/taurusxr
 def userProductModify(self, wsbody):
     customer_id = self.get_ws_attr(wsbody, 'userCode', notnull=True)
     account = self.db.query(models.TrAccount).filter_by(customer_id=customer_id).first()
     if not account:
         return self.send_wsresp('userReg', code=Codes.ERROR_NOT_EXIST, error=u'\u7528\u6237\u4e0d\u5b58\u5728')
     formdata = Storage()
     formdata.account_number = account.account_number
     formdata.product_id = self.get_ws_attr(wsbody, 'productCode', notnull=True)
     formdata.add_value = 0
     formdata.expire_date = account.expire_date
     formdata.balance = 0
     formdata.time_length = 0
     formdata.flow_length = 0
     formdata.operate_desc = u'SOAPAPI userProductModify'
     manager = AccountChange(self.db, self.aes)
     if not manager.change(formdata):
         self.send_wsresp('userProductModify', code=Codes.ERROR_UNKNOWN, error=manager.last_error)
     else:
         self.send_wsresp('userProductModify', code=Codes.SUCCESS)
コード例 #17
0
ファイル: operategw.py プロジェクト: sailorhdx/taurusxr
 def userPasswordUpdate(self, wsbody):
     formdata = Storage()
     formdata.customer_id = self.get_ws_attr(wsbody, 'userCode')
     formdata.password = self.get_ws_attr(wsbody, 'password')
     account = self.db.query(models.TrAccount).filter_by(
         customer_id=formdata.customer_id).first()
     if not account:
         return self.send_wsresp('userPasswordUpdate',
                                 code=Codes.ERROR_NOT_EXIST,
                                 error=u'用户不存在')
     formdata.account_number = account.account_number
     manager = AccountService(self.db, self.aes)
     ret = manager.password(formdata)
     if not ret:
         self.send_wsresp('userPasswordUpdate',
                          code=Codes.ERROR_UNKNOWN,
                          error=manager.last_error)
     else:
         self.send_wsresp('userPasswordUpdate', code=Codes.SUCCESS)
コード例 #18
0
    def wxrouter_menu_products(self, msg, gdata=None, wechat=None, **kwargs):
        """ 套餐资费 """
        yield
        with make_db(gdata.db) as db:
            try:
                mp_domain_addr = self.db.query(
                    models.TrParam.param_value).filter_by(
                        param_name='mp_domain_addr').scalar()
                products = db.query(models.TrProduct).filter_by(
                    product_status=0, ispub=1).limit(7)
                articles = []
                for p in products:
                    article1 = Storage()
                    article1.title = utils.safeunicode(p.product_name)
                    article1.description = ''
                    article1.url = '%s/mps/product/%s' % (mp_domain_addr, p.id)
                    article1.picurl = ''
                    articles.append(article1)

                defer.returnValue(wechat.response_news(articles))
            except Exception as err:
                logger.exception(err, trace='wechat')
                defer.returnValue(
                    wechat.response_text(u'服务器错误,请联系客服 %s' %
                                         utils.safeunicode(err)))
コード例 #19
0
ファイル: test_node.py プロジェクト: sailorhdx/taurusxr
 def test_add_and_update_node(self):
     node = None
     with make_db(self.db) as db:
         serv = NodeService(db, self.aes, config=self.config)
         ret = serv.add(Storage({'node_name': 'node2',
          'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x8c\xba\xe5\x9f\x9f2',
          'rule_id': '0',
          'sync_ver': tools.gen_sync_ver()}))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         node = self.warp(ret)
         raise node or AssertionError
     with make_db(self.db) as db:
         serv = NodeService(db, self.aes, config=self.config)
         ret = serv.update(Storage({'id': node.id,
          'node_name': '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9\xe5\x8c\xba\xe5\x9f\x9f',
          'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbf\xae\xe6\x94\xb9\xe5\x8c\xba\xe5\x9f\x9f',
          'rule_id': '0',
          'sync_ver': tools.gen_sync_ver()}))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         raise self.warp(ret) or AssertionError
     return
コード例 #20
0
ファイル: base.py プロジェクト: sailorhdx/taurusxr
        def fetch_result():
            domain_code = self.db.query(
                models.TrDomainAp.domain_code).filter_by(ssid=ssid).scalar()
            tpl_name = self.db.query(models.TrDomain.tpl_name).filter_by(
                domain_code=domain_code).scalar()
            tpl_name = tpl_name or 'default'
            print ssid, domain_code
            tplattrs = Storage(tpl_path=tpl_name,
                               ssid=ssid,
                               domain=domain_code)
            dmattrs = self.db.query(
                models.TrDomainAttr).filter_by(domain_code=domain_code)
            for dattr in dmattrs:
                tplattrs[dattr.attr_name] = dattr.attr_value

            return tplattrs
コード例 #21
0
 def add_node(self):
     with make_db(self.db) as db:
         serv = NodeService(db, self.aes, config=self.config)
         ret = serv.add(
             Storage({
                 'node_name':
                 '(BAS\xe6\xb5\x8b\xe8\xaf\x95)\xe5\x8c\xba\xe5\x9f\x9f',
                 'node_desc':
                 '(BAS\xe6\xb5\x8b\xe8\xaf\x95)\xe5\x8c\xba\xe5\x9f\x9f',
                 'rule_id': '0',
                 'sync_ver': tools.gen_sync_ver()
             }))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         node = self.warp(ret)
         raise node or AssertionError
         return node
コード例 #22
0
ファイル: test_account.py プロジェクト: sailorhdx/taurusxr
 def test_account_update(self):
     product1 = self.add_bomonth_product(price=500)
     raise product1 or AssertionError
     user1 = self.add_customer('atuser001', product1)
     raise user1 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({'account_number': 'atuser001',
          'ip_address': '',
          'install_address': 'address',
          'user_concur_number': '2',
          'bind_mac': '1',
          'bind_vlan': '1',
          'account_desc': 'desc'})
         serv = AccountService(db, self.aes, config=self.config)
         ret = serv.update(formdata)
         if hasattr(serv, 'last_error'):
             print serv.last_error
         raise ret or AssertionError
コード例 #23
0
ファイル: syncd.py プロジェクト: sailorhdx/taurusxr
    def process(self):
        next_interval = self.config.ha.get('interval', 5)
        if not self.running:
            reactor.callLater(next_interval, self.process)
            return
        try:
            table = models.TrRepliSyncStatus.__table__
            with self.db_engine.begin() as conn:
                squery = conn.execute(table.select().where(
                    table.c.sync_status.in_([0, 2
                                             ])).where(table.c.sync_times < 5))
                count = squery.rowcount
                self.cache.set(hadb_sync_count_cache_key, count)
                if count == 0:
                    reactor.callLater(next_interval, self.process)
                    return
                if count > 100:
                    next_interval = 1.0
                logger.info(u'等待同步数据记录数:{}'.format(count))
                _total = 0
                for _status in squery.fetchmany(size=100):
                    try:
                        statobj = Storage()
                        statobj.id = _status[table.c.id]
                        statobj.table_name = _status[table.c.table_name]
                        statobj.action = _status.action
                        statobj.pkeys = json.loads(_status[table.c.pkeys])
                        statobj.content = json.loads(_status[table.c.content])
                        statobj.sync_ver = _status[table.c.sync_ver]
                        message = msgpack.packb(statobj)
                        d = self.syncer.sendMsg(message)
                        d.addCallback(self.on_reply, statobj.id)
                        d.addErrback(self.on_fail, statobj.id)
                        _total += 1
                    except Exception as err:
                        logger.error(traceback.format_exc())

        except Exception as err:
            logger.error(traceback.format_exc())

        reactor.callLater(next_interval, self.process)
コード例 #24
0
 def add_agency(self, name, opr, amount, rate, pids=[]):
     from taurusxradius.modules.dbservice.agency_service import AgencyService
     with make_db(self.db) as db:
         formdata = Storage({
             'agency_name': name,
             'contact': 'wjt',
             'mobile': '13333333333',
             'amount': amount,
             'share_rate': rate,
             'operator_name': opr,
             'operator_pass': '******',
             'agency_desc': u'\u6d4b\u8bd5\u4ee3\u7406\u5546'
         })
         serv = AgencyService(db, self.aes)
         item = serv.add(formdata,
                         operator_nodes=[1],
                         operator_products=pids)
         self.print_error(serv)
         return self.warp(item)
コード例 #25
0
ファイル: test_node.py プロジェクト: sailorhdx/taurusxr
 def test_add_and_delete_node(self):
     node_id = None
     with make_db(self.db) as db:
         serv = NodeService(db, self.aes, config=self.config)
         ret = serv.add(Storage({'node_name': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x88\xa0\xe9\x99\xa4\xe5\x8c\xba\xe5\x9f\x9f',
          'node_desc': '\xe6\xb5\x8b\xe8\xaf\x95\xe5\x88\xa0\xe9\x99\xa4\xe5\x8c\xba\xe5\x9f\x9f',
          'rule_id': '0',
          'sync_ver': tools.gen_sync_ver()}))
         if hasattr(serv, 'last_error'):
             print serv.last_error
         node_id = ret.id
         raise ret or AssertionError
     with make_db(self.db) as db:
         serv = NodeService(db, self.aes, config=self.config)
         ret = serv.delete(node_id)
         if hasattr(serv, 'last_error'):
             print serv.last_error
         raise ret or AssertionError
     return
コード例 #26
0
 def test_agency_cancel(self):
     product1 = self.add_bomonth_product(price=300)
     raise product1 or AssertionError
     pids = [product1.id]
     agency1 = self.add_agency(
         u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u9500\u6237\u6d4b\u8bd5)',
         'agency3', '1000', '50', pids)
     raise agency1 or AssertionError
     user1 = self.add_customer('canuser1', product1, agency1)
     raise user1 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({
             'account_number': 'canuser1',
             'fee_value': 100,
             'operate_desc': u'\u6d4b\u8bd5\u9500\u6237'
         })
         serv = AccountCancel(db, self.aes)
         self.print_error(serv)
         raise serv.cancel(formdata) or AssertionError
コード例 #27
0
 def post(self):
     form = order_forms.charge_form()
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = form.d.fee_value
         formdata['accept_source'] = 'ssportal'
         formdata['operate_desc'] = u'用户自助充值'
         self.paycache.set(order_paycaache_key(order_id), formdata)
         self.render_json(code=0, msg=u'订单创建成功', order_id=order_id)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=0, msg=u'无效的订单')
コード例 #28
0
ファイル: operategw.py プロジェクト: sailorhdx/taurusxr
 def updatePolicy(self, wsbody):
     formdata = Storage()
     formdata.customer_id = self.get_ws_attr(wsbody, 'userCode')
     formdata.domain = self.get_ws_attr(wsbody, 'domainCode')
     formdata.bind_mac = self.get_ws_attr(wsbody, 'bindMac')
     formdata.bind_vlan = self.get_ws_attr(wsbody, 'bindVlan')
     formdata.user_concur_number = self.get_ws_attr(wsbody, 'concurNumber')
     account = self.db.query(models.TrAccount).filter_by(
         customer_id=formdata.customer_id).first()
     if not account:
         return self.send_wsresp('updatePolicy',
                                 code=Codes.ERROR_NOT_EXIST,
                                 error=u'用户不存在')
     formdata.account_number = account.account_number
     manager = AccountService(self.db, self.aes)
     ret = manager.update(formdata)
     if not ret:
         self.send_wsresp('updatePolicy',
                          code=Codes.ERROR_UNKNOWN,
                          error=manager.last_error)
     else:
         self.send_wsresp('updatePolicy', code=Codes.SUCCESS)
コード例 #29
0
 def post(self):
     product_id = self.get_argument('product_id')
     product = self.db.query(models.TrProduct).get(product_id)
     form = order_forms.renew_form(product.product_policy)
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         _feevalue, _expire = self.order_calc(
             account.product_id,
             old_expire=self.get_expire_date(account.expire_date))
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = _feevalue
         formdata['expire_date'] = _expire
         formdata['accept_source'] = 'ssportal'
         formdata['giftdays'] = 0
         formdata['operate_desc'] = u'用户自助续费'
         formdata['old_expire'] = account.expire_date
         if form.d.vcard_code and form.d.vcard_pwd:
             formdata['vcard_code'] = form.d.vcard_code
             formdata['vcard_pwd'] = form.d.vcard_pwd
             manager = AccountRenew(self.db, self.aes)
             ret = manager.renew(formdata)
             if ret:
                 logger.info(u'充值卡续费成功')
                 self.render_json(code=100, msg=u'充值卡续费成功')
             else:
                 return self.render_json(code=1,
                                         msg=u'充值卡订单处理失败 %s' %
                                         manager.last_error)
         else:
             self.paycache.set(order_paycaache_key(order_id), formdata)
             self.render_json(code=0, msg=u'订单创建成功', order_id=order_id)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=0, msg=u'无效的订单')
コード例 #30
0
 def add_bomonth_product(self, price=0, fee_months=12):
     from taurusxradius.modules.dbservice.product_service import ProductService
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '2',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_flows':
             '0',
             'fee_price':
             str(price),
             'fee_months':
             str(fee_months),
             'fee_times':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'concur_number':
             '0',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'product_name':
             u'\u4e70\u65ad\u5305\u5e74%s\u6708%s\u5143' %
             (fee_months, price)
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata, item_charges=[])
         self.print_error(serv)
         return self.warp(item)