Example #1
0
 def get_expire_date(self, expire):
     if not utils.is_expire(expire):
         return expire
     renew_type = self.get_param_value('renew_time_type', '0')
     if renew_type == '0':
         return utils.get_currdate()
     elif renew_type == '1':
         return expire
     else:
         return utils.get_currdate()
    def event_rossync_resync_pppoe_user(self, bas_id=None, **kwargs):
        if os.environ.get('LICENSE_TYPE',
                          '') not in ('taurusxee', 'routeros-oem'):
            return
        try:
            logger.info('resync pppoe user: bas_id={0}'.format(bas_id))
            rcli = self.get_bas_ros(bas_id)

            def update_user(resp, name, password, profile):
                d = rcli.add_pppoe_user(name, password, profile)
                d.addCallback(self.onresp, 'add pppoe user', rcli.apiaddr)
                d.addErrback(self.onerror, 'add pppoe user', rcli.apiaddr)

            with make_db(self.db) as db:
                for node_id, in db.query(models.TrNode.id).filter(
                        models.TrBasNode.node_id == models.TrNode.id,
                        models.TrNode.node_type == 'pppoe',
                        models.TrBasNode.bas_id == bas_id):
                    for user in self.db.query(models.TrAccount).filter(
                            models.TrAccount.status < 2,
                            models.TrAccount.expire_date >=
                            utils.get_currdate(), models.TrAccount.customer_id
                            == models.TrCustomer.customer_id,
                            models.TrCustomer.node_id == node_id):
                        dg = rcli.del_pppoe_user(user.account_number)
                        dg.addCallback(update_user, user.account_number,
                                       self.aes.decrypt(user.password),
                                       user.product_id)
                        dg.addErrback(self.onerror, 'del pppoe user',
                                      rcli.apiaddr)

        except Exception as err:
            logger.exception(err)
Example #3
0
def upgrade(config):
    """ 数据库升级,保留日志数据
    """
    try:
        db_engine = get_engine(config)
        metadata = models.get_metadata(db_engine)
        batchsize = 32 if config.database.dbtype == 'sqlite' else 500
        db_backup = DBBackup(metadata, excludes=['tr_online',
                                                 'system_session',
                                                 'system_cache',
                                                 'tr_ticket',
                                                 'tr_billing'], batchsize=batchsize)
        backup_path = config.database.backup_path
        backup_file = 'taurusxr_upgrade_%s.json.gz' % utils.get_currdate()
        backupfs = os.path.join(backup_path, backup_file)
        if not os.path.exists(backupfs):
            raise RuntimeError('please backup old database first!')
        print 'starting upgrade database...'
        tables = [ v for k, v in metadata.tables.iteritems() if k not in ('tr_ticket', 'tr_billing') ]
        metadata.drop_all(db_engine, tables=tables)
        metadata.create_all(db_engine, tables=tables)
        print 'upgrade database done'
        print 'start restore database from %s...' % backupfs
        db_backup.restoredb(backupfs)
        print 'restore database done'
    except:
        import traceback
        traceback.print_exc()
Example #4
0
        def post(self):
            card_code = self.get_argument('card_code', None)
            card_type = self.get_argument('card_type', None)
            product_tag = self.get_argument('product_tag', None)
            status = self.get_argument('status', None)
            query_begin_time = self.get_argument('query_begin_time', None)
            query_end_time = self.get_argument('query_end_time', None)
            _query = self.db.query(models.TrValCard)
            if card_code:
                _query = _query.filter(models.TrValCard.card_code == card_code)
            if card_type:
                _query = _query.filter(models.TrValCard.card_type == card_type)
            if product_tag:
                _query = _query.filter(
                    models.TrValCard.product_tag == product_tag)
            if status:
                if status == 'expire':
                    _query = _query.filter(
                        models.TrValCard.expire_date < utils.get_currdate())
                else:
                    _query = _query.filter(
                        models.TrValCard.status == int(status))
            if query_begin_time:
                _query = _query.filter(models.TrValCard.active_time >=
                                       '{} 00:00:00'.format(query_begin_time))
            if query_end_time:
                _query = _query.filter(models.TrValCard.active_time <=
                                       '{} 23:59:59'.format(query_end_time))
            page_data = self.get_page_data(_query)
            if self.request.path == '/admin/vcard':
                self.render('vcard_list.html', page_data=page_data)
            elif self.request.path == '/admin/vcard/export':
                data = Dataset()
                data.append((u'卡号', u'密码', u'卡类型', u'卡状态', u'资费标签', u'储值余额',
                             u'储值流量', u'储值时长', u'零售价格', u'过期时间', u'激活时间'))
                for i in _query:
                    data.append(
                        (i.card_code, self.aes.decrypt(i.card_pwd),
                         i.card_type, vcard_forms.cardstatus.get(i.status),
                         i.product_tag, i.credit, i.flowlen, i.timelen,
                         i.fee_price, i.expire_date, i.active_time))

                name = u'VCARD-' + datetime.datetime.now().strftime(
                    '%Y%m%d-%H%M%S') + '.xls'
                self.export_file(name, data)
            return
Example #5
0
 def add_note(self, order_id):
     order = self.db.query(models.TrCustomerOrder).get(order_id)
     account = self.db.query(models.TrAccount).filter_by(
         account_number=order.account_number).first()
     product = self.db.query(
         models.TrProduct).filter_by(id=order.product_id).first()
     customer = self.db.query(models.TrCustomer).get(order.customer_id)
     opr = self.db.query(models.TrOperator).filter(
         models.TrCustomerOrder.accept_id == models.TrAcceptLog.id,
         models.TrAcceptLog.operator_name ==
         models.TrOperator.operator_name,
         models.TrCustomerOrder.order_id == order_id).first()
     clogs = self.db.query(models.TrCharges.charge_name,
                           models.TrCharges.charge_value).filter(
                               models.TrCharges.charge_code ==
                               models.TrChargeLog.charge_code,
                               models.TrChargeLog.order_id == order_id)
     charge_values = ', '.join([
         '%s:%s' % (cname, utils.fen2yuan(cvalue))
         for cname, cvalue in clogs
     ])
     note = models.TrCustomerNote()
     note.id = utils.get_uuid()
     note.note_id = utils.gen_order_id()
     note.order_id = order.order_id
     note.customer_cname = customer.realname
     note.account_number = account.account_number
     note.mobile = customer.mobile
     note.install_address = account.install_address
     note.pay_type = u'现金'
     note.pay_date = utils.get_currdate()
     note.expire_date = account.expire_date
     note.order_num = 1
     note.product_name = product.product_name
     note.fee_price = product.fee_price
     note.fee_total = order.actual_fee
     note.charge_values = charge_values
     note.operator_name = opr and opr.operator_desc or ''
     note.print_times = 0
     note.remark = u'用户套餐续费'
     note.sync_ver = tools.gen_sync_ver()
     self.db.add(note)
     self.db.commit()
     return note
Example #6
0
def backup(config):
    try:
        db_engine = get_engine(config)
        metadata = models.get_metadata(db_engine)
        batchsize = 32 if config.database.dbtype == 'sqlite' else 500
        db_backup = DBBackup(metadata, excludes=['tr_online',
                                                 'system_session',
                                                 'system_cache',
                                                 'tr_ticket',
                                                 'tr_billing'], batchsize=batchsize)
        print 'start backup database...'
        backup_path = config.database.backup_path
        backup_file = 'taurusxr_upgrade_%s.json.gz' % utils.get_currdate()
        backupfs = os.path.join(backup_path, backup_file)
        db_backup.dumpdb(backupfs)
        print 'backup database %s done' % backupfs
    except:
        import traceback
        traceback.print_exc()
Example #7
0
 def get(self):
     pay_status = self.get_argument('pay_status', None)
     accept_type = self.get_argument('accept_type', None)
     stat_month = self.get_argument('stat_month', utils.get_currdate()[0:7])
     _query = self.db.query(
         models.TrAcceptLog.operator_name,
         func.sum(models.TrCustomerOrder.actual_fee).label('fee_value'),
         func.count(
             models.TrCustomerOrder.order_id).label('dev_count')).filter(
                 models.TrCustomer.customer_id ==
                 models.TrCustomerOrder.customer_id,
                 models.TrAcceptLog.id == models.TrCustomerOrder.accept_id,
                 models.TrCustomerOrder.stat_month == stat_month)
     if pay_status:
         _query = _query.filter(
             models.TrCustomerOrder.pay_status == int(pay_status))
     if accept_type:
         _query = _query.filter(
             models.TrAcceptLog.accept_type == accept_type)
     _query = _query.group_by(models.TrAcceptLog.operator_name)
     _query = _query.order_by(models.TrAcceptLog.operator_name.asc())
     userqry = _query.subquery()
     fee_total = self.db.query(func.sum(userqry.c.fee_value)).scalar() or 0
     dev_total = self.db.query(func.sum(userqry.c.dev_count)).scalar() or 0
     fee_data = [{
         'name': i.operator_name,
         'y': float(utils.fen2yuan(i.fee_value))
     } for i in _query]
     dev_data = [{
         'name': i.operator_name,
         'y': float(i.dev_count)
     } for i in _query]
     self.render_json(code=0,
                      msg='ok',
                      fee_data=fee_data,
                      dev_data=dev_data,
                      dev_total=int(dev_total),
                      fee_total=utils.fen2yuan(fee_total))
     return
Example #8
0
 def get_expire_date(self, expire):
     if utils.is_expire(expire):
         return utils.get_currdate()
     else:
         return expire