Exemple #1
0
    def post(self):
        form = product_forms.product_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("product_form.html", form=form)

        product = models.TrProduct()
        product.product_name = form.d.product_name
        product.product_policy = form.d.product_policy
        product.product_status = form.d.product_status
        product.fee_months = int(form.d.get("fee_months", 0))
        product.fee_times = utils.hour2sec(form.d.get("fee_times", 0))
        product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0))
        product.bind_mac = form.d.bind_mac
        product.bind_vlan = form.d.bind_vlan
        product.concur_number = form.d.concur_number
        product.fee_price = utils.yuan2fen(form.d.fee_price)
        product.fee_period =  '' #form.d.fee_period or ''
        product.input_max_limit = utils.mbps2bps(form.d.input_max_limit)
        product.output_max_limit = utils.mbps2bps(form.d.output_max_limit)
        _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        product.create_time = _datetime
        product.update_time = _datetime
        self.db.add(product)
        self.add_oplog(u'新增资费信息:%s' % utils.safeunicode(product.product_name))
        self.db.commit()
        self.redirect("/admin/product", permanent=False)
Exemple #2
0
    def post(self):
        form = product_forms.product_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("product_form.html", form=form)

        product = models.TrProduct()
        product.product_name = form.d.product_name
        product.product_policy = form.d.product_policy
        product.product_status = form.d.product_status
        product.fee_months = int(form.d.get("fee_months", 0))
        product.fee_times = utils.hour2sec(form.d.get("fee_times", 0))
        product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0))
        product.bind_mac = form.d.bind_mac
        product.bind_vlan = form.d.bind_vlan
        product.concur_number = form.d.concur_number
        product.fee_price = utils.yuan2fen(form.d.fee_price)
        product.fee_period = ''  #form.d.fee_period or ''
        product.input_max_limit = utils.mbps2bps(form.d.input_max_limit)
        product.output_max_limit = utils.mbps2bps(form.d.output_max_limit)
        _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        product.create_time = _datetime
        product.update_time = _datetime
        self.db.add(product)
        self.add_oplog(u'新增资费信息:%s' % utils.safeunicode(product.product_name))
        self.db.commit()
        self.redirect("/admin/product", permanent=False)
Exemple #3
0
    def post(self):
        account_number = self.get_argument("account_number")
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        form = account_forms.account_change_form(products=products)
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        if account.status not in (1, 4):
            return self.render("account_change_form.html",
                               user=user,
                               form=form,
                               msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_change_form.html",
                               user=user,
                               form=form)

        product = self.db.query(models.TrProduct).get(form.d.product_id)

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'change'
        accept_log.accept_source = 'console'
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        accept_log.accept_desc = u"用户资费变更为:%s;%s" % (
            product.product_name, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_exoire_date = account.expire_date

        account.product_id = product.id
        # (PPMonth,PPTimes,BOMonth,BOTimes,PPFlow,BOFlows)
        if product.product_policy in (PPMonth, BOMonth):
            account.expire_date = form.d.expire_date
            account.balance = 0
            account.time_length = 0
            account.flow_length = 0
        elif product.product_policy in (PPTimes, PPFlow):
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = utils.yuan2fen(form.d.balance)
            account.time_length = 0
            account.flow_length = 0
        elif product.product_policy == BOTimes:
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = 0
            account.time_length = utils.hour2sec(form.d.time_length)
            account.flow_length = 0
        elif product.product_policy == BOFlows:
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = 0
            account.time_length = 0
            account.flow_length = utils.mb2kb(form.d.flow_length)

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = account.customer_id
        order.product_id = account.product_id
        order.account_number = account.account_number
        order.order_fee = 0
        order.actual_fee = utils.yuan2fen(form.d.add_value) - utils.yuan2fen(
            form.d.back_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"用户变更资费,变更前到期:%s,变更后到期:%s" % (old_exoire_date,
                                                          account.expire_date)

        self.db.add(order)
        self.add_oplog(accept_log.accept_desc)
        self.db.commit()
        dispatch.pub(settings.CACHE_DELETE_EVENT,
                     account_cache_key(account.account_number),
                     async=True)
        self.redirect(self.detail_url_fmt(account_number))
Exemple #4
0
        try:
            if not form.validates(**request):
                return self.render_verify_err(form.errors)

            if self.db.query(models.TrProduct).filter_by(product_name=form.d.product_name).count() > 0:
                return self.render_verify_err(msg=u"product name already exists")
        except Exception, err:
            return self.render_verify_err(err)

        try:
            product = models.TrProduct()
            product.product_name = form.d.product_name
            product.product_policy = form.d.product_policy
            product.product_status = form.d.product_status
            product.fee_months = int(form.d.get("fee_months", 0))
            product.fee_times = utils.hour2sec(form.d.get("fee_times", 0))
            product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0))
            product.bind_mac = form.d.bind_mac
            product.bind_vlan = form.d.bind_vlan
            product.concur_number = form.d.concur_number
            product.fee_price = utils.yuan2fen(form.d.fee_price)
            product.fee_period = ''  # form.d.fee_period or ''
            product.input_max_limit = utils.mbps2bps(form.d.input_max_limit)
            product.output_max_limit = utils.mbps2bps(form.d.output_max_limit)
            _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            product.create_time = _datetime
            product.update_time = _datetime
            self.db.add(product)
            self.add_oplog(u'API新增资费信息:%s' % utils.safeunicode(product.product_name))
            self.db.commit()
            return self.render_success(msg=u'资费添加成功')
    def post(self):
        nodes = [(n.id, n.node_desc) for n in self.get_opr_nodes()]
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        iform = customer_forms.customer_import_form(nodes, products)
        node_id = self.get_argument('node_id')
        product_id = self.get_argument('product_id')
        f = self.request.files['import_file'][0]
        impctx = utils.safeunicode(f['body'])
        lines = impctx.split("\n")
        _num = 0
        impusers = []
        for line in lines:
            _num += 1
            line = line.strip()
            if not line or u"用户姓名" in line: continue
            attr_array = line.split(",")
            if len(attr_array) < 11:
                return self.render("customer_import_form.html",
                                   form=iform,
                                   msg=u"line %s error: length must 11 " %
                                   _num)

            vform = customer_forms.customer_import_vform()
            if not vform.validates(
                    dict(realname=attr_array[0],
                         idcard=attr_array[1],
                         mobile=attr_array[2],
                         address=attr_array[3],
                         account_number=attr_array[4],
                         password=attr_array[5],
                         begin_date=attr_array[6],
                         expire_date=attr_array[7],
                         balance=attr_array[8],
                         time_length=utils.hour2sec(attr_array[9]),
                         flow_length=utils.mb2kb(attr_array[10]))):
                return self.render("customer_import_form.html",
                                   form=iform,
                                   msg=u"line %s error: %s" %
                                   (_num, vform.errors))

            impusers.append(vform)

        _unums = 0
        for form in impusers:
            try:
                customer = models.TrCustomer()
                customer.node_id = node_id
                customer.realname = form.d.realname
                customer.idcard = form.d.idcard
                customer.customer_name = form.d.account_number
                customer.password = md5(form.d.password.encode()).hexdigest()
                customer.sex = '1'
                customer.age = '0'
                customer.email = ''
                customer.mobile = form.d.mobile
                customer.address = form.d.address
                customer.create_time = form.d.begin_date + ' 00:00:00'
                customer.update_time = utils.get_currtime()
                customer.email_active = 0
                customer.mobile_active = 0
                customer.active_code = utils.get_uuid()
                self.db.add(customer)
                self.db.flush()
                self.db.refresh(customer)

                accept_log = models.TrAcceptLog()
                accept_log.accept_type = 'open'
                accept_log.accept_source = 'console'
                _desc = u"用户导入账号:%s" % form.d.account_number
                accept_log.accept_desc = _desc
                accept_log.account_number = form.d.account_number
                accept_log.accept_time = customer.update_time
                accept_log.operator_name = self.current_user.username
                self.db.add(accept_log)
                self.db.flush()
                self.db.refresh(accept_log)

                order_fee = 0
                actual_fee = 0
                balance = 0
                time_length = 0
                flow_length = 0
                expire_date = form.d.expire_date
                product = self.db.query(models.TrProduct).get(product_id)
                # 买断时长
                if product.product_policy == BOTimes:
                    time_length = int(form.d.time_length)
                # 买断流量
                elif product.product_policy == BOFlows:
                    flow_length = int(form.d.flow_length)
                # 预付费时长,预付费流量
                elif product.product_policy in (PPTimes, PPFlow):
                    balance = utils.yuan2fen(form.d.balance)
                    expire_date = MAX_EXPIRE_DATE

                order = models.TrCustomerOrder()
                order.order_id = utils.gen_order_id()
                order.customer_id = customer.customer_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 = customer.update_time
                order.order_desc = u"用户导入开户"
                self.db.add(order)

                account = models.TrAccount()
                account.account_number = form.d.account_number
                account.customer_id = customer.customer_id
                account.product_id = order.product_id
                account.install_address = customer.address
                account.ip_address = ''
                account.mac_addr = ''
                account.password = self.aes.encrypt(form.d.password)
                account.status = 1
                account.balance = balance
                account.time_length = time_length
                account.flow_length = flow_length
                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 = customer.create_time
                account.update_time = customer.update_time
                self.db.add(account)
                _unums += 1

            except Exception as e:
                return self.render("customer_import_form.html",
                                   form=iform,
                                   msg=u"error : %s" % str(e))

        self.add_oplog(u"导入开户,用户数:%s" % _unums)
        self.db.commit()
        self.redirect("/admin/customer")
            order.order_source = 'console'
            order.create_time = customer.update_time
            order.order_desc = u"API开通账号"
            self.db.add(order)

            account = models.TrAccount()
            account.account_number = form.d.account_number
            account.customer_id = customer.customer_id
            account.product_id = order.product_id
            account.install_address = customer.address
            account.ip_address = form.d.ip_address
            account.mac_addr = ''
            account.password = self.aes.encrypt(form.d.password)
            account.status = 1
            account.balance = balance
            account.time_length = utils.hour2sec(time_length)
            account.flow_length = utils.mb2kb(flow_length)
            account.expire_date = expire_date
            account.user_concur_number = user_concur_number
            account.bind_mac = user_bind_mac
            account.bind_vlan = user_bind_vlan
            account.vlan_id1 = 0
            account.vlan_id2 = 0
            account.create_time = customer.create_time
            account.update_time = customer.update_time
            self.db.add(account)
            self.add_oplog(u"API开户,%s" % form.d.account_number)

            self.db.commit()
            self.render_success()
        except Exception as e:
Exemple #7
0
            order.order_source = 'api'
            order.create_time = customer.update_time
            order.order_desc = u"开通账号"
            self.db.add(order)

            account = models.TrAccount()
            account.account_number = form.d.account_number
            account.customer_id = customer.customer_id
            account.product_id = order.product_id
            account.install_address = customer.address
            account.ip_address = form.d.ip_address
            account.mac_addr = ''
            account.password = self.aes.encrypt(form.d.password)
            account.status = 1
            account.balance = balance
            account.time_length = utils.hour2sec(time_length)
            account.flow_length = utils.mb2kb(flow_length)
            account.expire_date = expire_date
            account.user_concur_number = user_concur_number
            account.bind_mac = user_bind_mac
            account.bind_vlan = user_bind_vlan
            account.vlan_id1 = 0
            account.vlan_id2 = 0
            account.create_time = customer.create_time
            account.update_time = customer.update_time
            self.db.add(account)
            self.add_oplog(u"新用户开户,%s" % form.d.account_number)

            self.db.commit()
            self.render_success()
        except Exception as e:
    def post(self):
        nodes = [(n.id, n.node_desc) for n in self.get_opr_nodes()]
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        iform = customer_forms.customer_import_form(nodes, products)
        node_id = self.get_argument('node_id')
        product_id = self.get_argument('product_id')
        f = self.request.files['import_file'][0]
        impctx = utils.safeunicode(f['body'])
        lines = impctx.split("\n")
        _num = 0
        impusers = []
        for line in lines:
            _num += 1
            line = line.strip()
            if not line or u"用户姓名" in line: continue
            attr_array = line.split(",")
            if len(attr_array) < 11:
                return self.render("customer_import_form.html", form=iform, msg=u"line %s error: length must 11 " % _num)

            vform = customer_forms.customer_import_vform()
            if not vform.validates(dict(
                realname=attr_array[0],
                idcard=attr_array[1],
                mobile=attr_array[2],
                address=attr_array[3],
                account_number=attr_array[4],
                password=attr_array[5],
                begin_date=attr_array[6],
                expire_date=attr_array[7],
                balance=attr_array[8],
                time_length=utils.hour2sec(attr_array[9]),
                flow_length=utils.mb2kb(attr_array[10]))):
                return self.render("customer_import_form.html", form=iform, msg=u"line %s error: %s" % (_num, vform.errors))

            impusers.append(vform)

        _unums = 0
        for form in impusers:
            try:
                customer = models.TrCustomer()
                customer.node_id = node_id
                customer.realname = form.d.realname
                customer.idcard = form.d.idcard
                customer.customer_name = form.d.account_number
                customer.password = md5(form.d.password.encode()).hexdigest()
                customer.sex = '1'
                customer.age = '0'
                customer.email = ''
                customer.mobile = form.d.mobile
                customer.address = form.d.address
                customer.create_time = form.d.begin_date + ' 00:00:00'
                customer.update_time = utils.get_currtime()
                customer.email_active = 0
                customer.mobile_active = 0
                customer.active_code = utils.get_uuid()
                self.db.add(customer)
                self.db.flush()
                self.db.refresh(customer)

                accept_log = models.TrAcceptLog()
                accept_log.accept_type = 'open'
                accept_log.accept_source = 'console'
                _desc = u"用户导入账号:%s" % form.d.account_number
                accept_log.accept_desc = _desc
                accept_log.account_number = form.d.account_number
                accept_log.accept_time = customer.update_time
                accept_log.operator_name = self.current_user.username
                self.db.add(accept_log)
                self.db.flush()
                self.db.refresh(accept_log)

                order_fee = 0
                actual_fee = 0
                balance = 0
                time_length = 0
                flow_length = 0
                expire_date = form.d.expire_date
                product = self.db.query(models.TrProduct).get(product_id)
                # 买断时长
                if product.product_policy == BOTimes:
                    time_length = int(form.d.time_length)
                # 买断流量
                elif product.product_policy == BOFlows:
                    flow_length = int(form.d.flow_length)
                # 预付费时长,预付费流量
                elif product.product_policy in (PPTimes, PPFlow):
                    balance = utils.yuan2fen(form.d.balance)
                    expire_date = MAX_EXPIRE_DATE

                order = models.TrCustomerOrder()
                order.order_id = utils.gen_order_id()
                order.customer_id = customer.customer_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 = customer.update_time
                order.order_desc = u"用户导入开户"
                self.db.add(order)

                account = models.TrAccount()
                account.account_number = form.d.account_number
                account.customer_id = customer.customer_id
                account.product_id = order.product_id
                account.install_address = customer.address
                account.ip_address = ''
                account.mac_addr = ''
                account.password = self.aes.encrypt(form.d.password)
                account.status = 1
                account.balance = balance
                account.time_length = time_length
                account.flow_length = flow_length
                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 = customer.create_time
                account.update_time = customer.update_time
                self.db.add(account)
                _unums += 1

            except Exception as e:
                return self.render("customer_import_form.html", form=iform, msg=u"error : %s" % str(e))

        self.add_oplog(u"导入开户,用户数:%s" % _unums)
        self.db.commit()
        self.redirect("/admin/customer")
    def post(self):
        account_number = self.get_argument("account_number")
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        form = account_forms.account_change_form(products=products)
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        if account.status not in (1, 4):
            return self.render("account_change_form.html", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_change_form.html", user=user, form=form)

        product = self.db.query(models.TrProduct).get(form.d.product_id)

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'change'
        accept_log.accept_source = 'console'
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        accept_log.accept_desc = u"用户资费变更为:%s;%s" % (
            product.product_name, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_exoire_date = account.expire_date

        account.product_id = product.id
        # (PPMonth,PPTimes,BOMonth,BOTimes,PPFlow,BOFlows)
        if product.product_policy in (PPMonth, BOMonth):
            account.expire_date = form.d.expire_date
            account.balance = 0
            account.time_length = 0
            account.flow_length = 0
        elif product.product_policy in (PPTimes, PPFlow):
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = utils.yuan2fen(form.d.balance)
            account.time_length = 0
            account.flow_length = 0
        elif product.product_policy == BOTimes:
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = 0
            account.time_length = utils.hour2sec(form.d.time_length)
            account.flow_length = 0
        elif product.product_policy == BOFlows:
            account.expire_date = MAX_EXPIRE_DATE
            account.balance = 0
            account.time_length = 0
            account.flow_length = utils.mb2kb(form.d.flow_length)

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = account.customer_id
        order.product_id = account.product_id
        order.account_number = account.account_number
        order.order_fee = 0
        order.actual_fee = utils.yuan2fen(form.d.add_value) - utils.yuan2fen(form.d.back_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"用户变更资费,变更前到期:%s,变更后到期:%s" % (
            old_exoire_date, account.expire_date)

        self.db.add(order)
        self.add_oplog(accept_log.accept_desc)
        self.db.commit()
        dispatch.pub(settings.CACHE_DELETE_EVENT,account_cache_key(account.account_number), async=True)
        self.redirect(self.detail_url_fmt(account_number))