Beispiel #1
0
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_cancel_form()
        if account.status != 1:
            return self.render("account_form.html",
                               user=user,
                               form=form,
                               msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_form.html", user=user, form=form)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户销户退费%s(元);%s" % (
            form.d.fee_value, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_expire_date = account.expire_date

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_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 = accept_log.accept_desc
        self.db.add(order)

        account.status = 3

        self.db.commit()

        dispatch.pub(ACCOUNT_CHANNEL_EVENT, account.account_number, async=True)
        dispatch.pub(db_cache.CACHE_DELETE_EVENT,
                     account_cache_key(account.account_number),
                     async=True)
        for online in self.db.query(
                models.TrOnline).filter_by(account_number=account_number):
            dispatch.pub(UNLOCK_ONLINE_EVENT,
                         account_number,
                         online.nas_addr,
                         online.acct_session_id,
                         async=True)
        self.redirect(self.detail_url_fmt(account_number))
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_cancel_form()
        if account.status != 1:
            return self.render("account_form.html",
                               user=user,
                               form=form,
                               msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_form.html", user=user, form=form)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户销户退费%s(元);%s" % (
            form.d.fee_value, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_expire_date = account.expire_date

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_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 = accept_log.accept_desc
        self.db.add(order)

        account.status = 3

        self.db.commit()

        onlines = self.db.query(
            models.TrOnline).filter_by(account_number=account_number)
        for _online in onlines:
            pass

        self.redirect(self.detail_url_fmt(account_number))
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_cancel_form()
        if account.status != 1:
            return self.render("account_form.html", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_form.html", user=user, form=form)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户销户退费%s(元);%s" % (
            form.d.fee_value, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_expire_date = account.expire_date

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_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 = accept_log.accept_desc
        self.db.add(order)

        account.status = 3

        self.db.commit()

        dispatch.pub(ACCOUNT_CHANNEL_EVENT, account.account_number, async=True)
        dispatch.pub(db_cache.CACHE_DELETE_EVENT,account_cache_key(account.account_number), async=True)
        for online in self.db.query(models.TrOnline).filter_by(account_number=account_number):
            dispatch.pub(UNLOCK_ONLINE_EVENT,account_number,online.nas_addr, online.acct_session_id,async=True)
        self.redirect(self.detail_url_fmt(account_number))
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_cancel_form()
        if account.status != 1:
            return self.render("account_form.html", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return self.render("account_form.html", user=user, form=form)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户销户退费%s(元);%s" % (form.d.fee_value, utils.safeunicode(form.d.operate_desc))
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        old_expire_date = account.expire_date

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_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 = accept_log.accept_desc
        self.db.add(order)

        account.status = 3

        self.db.commit()

        onlines = self.db.query(models.TrOnline).filter_by(account_number=account_number)
        for _online in onlines:
            pass

        self.redirect(self.detail_url_fmt(account_number))
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_charge_form()

        if account.status not in (1, 4):
            return render("account_form", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return render("account_form", user=user, form=form)

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'charge'
        accept_log.accept_source = 'console'
        _new_fee = account.balance + utils.yuan2fen(form.d.fee_value)
        accept_log.accept_desc = u"用户充值:充值前%s元,充值后%s元;%s" % (
            utils.fen2yuan(account.balance),
            utils.fen2yuan(_new_fee),
            (form.d.operate_desc or '')
        )        
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_id
        order.product_id = user.product_id
        order.account_number = form.d.account_number
        order.order_fee = utils.yuan2fen(form.d.fee_value)
        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 = accept_log.accept_desc

        self.db.add(order)
        self.add_oplog(order.order_desc)

        account.balance += order.actual_fee
        self.db.commit()
        self.redirect(self.detail_url_fmt(account_number))
Beispiel #6
0
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_charge_form()

        if account.status not in (1, 4):
            return render("account_form", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return render("account_form", user=user, form=form)

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'charge'
        accept_log.accept_source = 'console'
        _new_fee = account.balance + utils.yuan2fen(form.d.fee_value)
        accept_log.accept_desc = u"用户充值:充值前%s元,充值后%s元;%s" % (
            utils.fen2yuan(account.balance), utils.fen2yuan(_new_fee),
            (form.d.operate_desc or ''))
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_id
        order.product_id = user.product_id
        order.account_number = form.d.account_number
        order.order_fee = utils.yuan2fen(form.d.fee_value)
        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 = accept_log.accept_desc

        self.db.add(order)
        self.add_oplog(order.order_desc)

        account.balance += order.actual_fee
        self.db.commit()
        self.redirect(self.detail_url_fmt(account_number))
                if int(form.d.free_bill_type or 9999) not in (FreeFeeDate,FreeFeeFlow,FreeFeeTimeLen):
                    return self.render_verify_err(msg=u"free_bill_type in (0,1,2)")
                time_length = int(form.d.time_length or 0)
                flow_length = int(form.d.flow_length or 0)
                balance = utils.yuan2fen(form.d.balance or 0)
                user_concur_number = int(form.d.concur_number or 0)
                user_bind_mac = int(form.d.bind_mac or 0)
                user_bind_vlan = int(form.d.bind_vlan or 0)
                user_input_max_limit = utils.mbps2bps(form.d.input_max_limit or 0)
                user_output_max_limit = utils.mbps2bps(form.d.output_max_limit or 0)
                self.set_account_attr(form.d.account_number,'bill_type',form.d.free_bill_type)
                self.set_account_attr(form.d.account_number,'input_max_limit',user_input_max_limit)
                self.set_account_attr(form.d.account_number,'output_max_limit',user_output_max_limit)

            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"API开通账号"
            self.db.add(order)

            account = models.TrAccount()
            account.account_number = form.d.account_number
            account.customer_id = customer.customer_id
Beispiel #8
0
    def post(self):
        account_number = self.get_argument("account_number")
        account = self.db.query(models.TrAccount).get(account_number)
        user = self.query_account(account_number)
        form = account_forms.account_next_form()
        form.product_id.set_value(user.product_id)
        if account.status not in (1, 4):
            return render("account_next_form", user=user, form=form, msg=u"无效用户状态")
        if not form.validates(source=self.get_params()):
            return render("account_next_form", user=user, form=form)

        accept_log = models.TrAcceptLog()
        accept_log.accept_type = 'next'
        accept_log.accept_source = 'console'
        accept_log.accept_desc = u"用户续费:上网账号:%s,续费%s元;%s" % (account_number, form.d.fee_value,form.d.operate_desc)
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = utils.get_currtime()
        accept_log.operator_name = self.current_user.username
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        

        order_fee = 0
        product = self.db.query(models.TrProduct).get(user.product_id)

        # 预付费包月
        if product.product_policy == PPMonth:
            order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months)
            order_fee = int(order_fee.to_integral_value())

        # 买断包月,买断流量,买断时长
        elif product.product_policy in (BOMonth, BOTimes, BOFlows):
            order_fee = int(product.fee_price)

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = user.customer_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()

        old_expire_date = account.expire_date

        account.status = 1
        account.expire_date = form.d.expire_date
        if product.product_policy == BOTimes:
            account.time_length += product.fee_times
        elif product.product_policy == BOFlows:
            account.flow_length += product.fee_flows

        order.order_desc = u"用户续费,续费前到期:%s,续费后到期:%s" % (old_expire_date, account.expire_date)
        self.db.add(order)
        self.add_oplog(order.order_desc)

        self.db.commit()
        self.redirect(self.detail_url_fmt(account_number))
Beispiel #9
0
                user_bind_mac = int(form.d.bind_mac or 0)
                user_bind_vlan = int(form.d.bind_vlan or 0)
                user_input_max_limit = utils.mbps2bps(form.d.input_max_limit
                                                      or 0)
                user_output_max_limit = utils.mbps2bps(form.d.output_max_limit
                                                       or 0)
                self.set_account_attr(form.d.account_number, 'bill_type',
                                      form.d.free_bill_type)
                self.set_account_attr(form.d.account_number, 'input_max_limit',
                                      user_input_max_limit)
                self.set_account_attr(form.d.account_number,
                                      'output_max_limit',
                                      user_output_max_limit)

            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 = '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
Beispiel #10
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))
Beispiel #11
0
    def post(self):
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        form = account_forms.account_open_form(products)
        if not form.validates(source=self.get_params()):
            return self.render("account_open_form.html", form=form)

        if self.db.query(models.TrAccount).filter_by(
            account_number=form.d.account_number).count() > 0:
            return self.render("account_open_form.html", form=form, msg=u"上网账号已经存在")

        if form.d.ip_address and self.db.query(models.TrAccount).filter_by(ip_address=form.d.ip_address).count() > 0:
            return self.render("account_open_form.html", form=form, msg=u"ip%s已经被使用" % form.d.ip_address)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户新增账号:上网账号:%s" % (form.d.account_number)
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        _datetime = utils.get_currtime()
        order_fee = 0
        balance = 0
        expire_date = form.d.expire_date
        product = self.db.query(models.TrProduct).get(form.d.product_id)

        # 预付费包月
        if product.product_policy == PPMonth:
            order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months)
            order_fee = int(order_fee.to_integral_value())
        # 买断包月,买断时长,买断流量
        elif product.product_policy in (BOMonth, BOTimes, BOFlows):
            order_fee = int(product.fee_price)
        # 预付费时长,预付费流量
        elif product.product_policy in (PPTimes, PPFlow):
            balance = utils.yuan2fen(form.d.fee_value)
            expire_date = MAX_EXPIRE_DATE

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = form.d.customer_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"用户增开账号"
        self.db.add(order)

        account = models.TrAccount()
        account.account_number = form.d.account_number
        account.ip_address = form.d.ip_address
        account.customer_id = int(form.d.customer_id)
        account.product_id = order.product_id
        account.install_address = form.d.address
        account.mac_addr = ''
        account.password = self.aes.encrypt(form.d.password)
        account.status = form.d.status
        account.balance = balance
        account.time_length = int(product.fee_times)
        account.flow_length = int(product.fee_flows)
        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_id1 = 0
        account.vlan_id2 = 0
        account.create_time = _datetime
        account.update_time = _datetime
        account.account_desc = form.d.account_desc
        self.db.add(account)
        self.add_oplog(u"用户增开子账号 %s" % account.account_number)
        self.db.commit()
        self.redirect(self.detail_url_fmt(account.account_number))
Beispiel #12
0
    def post(self):
        form = customer_add_vform()
        try:
            request = self.parse_form_request()
            if not form.validates(**request):
                raise Exception(form.errors)
            if self.db.query(models.TrAccount).filter_by(account_number=form.d.account_number).count() > 0:
                raise Exception("account already exists")
        except Exception as err:
            self.render_result(code=1, msg=utils.safeunicode(err.message))
            return

        try:
            customer = models.TrCustomer()
            customer.node_id = form.d.node_id
            customer.realname = form.d.realname
            customer.idcard = form.d.idcard
            customer.customer_name = form.d.customer_name or form.d.account_number
            customer.password = md5(form.d.password.encode()).hexdigest()
            customer.sex = '1'
            customer.age = '0'
            customer.email = form.d.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 = 1
            customer.mobile_active = 1
            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 = 'api'
            accept_log.accept_desc =  u"API开通账号:%s" % form.d.account_number
            accept_log.account_number = form.d.account_number
            accept_log.accept_time = customer.update_time
            accept_log.operator_name = 'api'
            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(form.d.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"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 = ''
            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_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_result(code=0, msg='success')
        except Exception as e:
            self.render_result(code=1, msg=utils.safeunicode(e.message))
            import traceback
            traceback.print_exc()
Beispiel #13
0
    def post(self):
        products = [(n.id, n.product_name) for n in self.get_opr_products()]
        form = account_forms.account_open_form(products)
        if not form.validates(source=self.get_params()):
            return self.render("account_open_form.html", form=form)

        if self.db.query(models.TrAccount).filter_by(
                account_number=form.d.account_number).count() > 0:
            return self.render("account_open_form.html",
                               form=form,
                               msg=u"上网账号已经存在")

        if form.d.ip_address and self.db.query(models.TrAccount).filter_by(
                ip_address=form.d.ip_address).count() > 0:
            return self.render("account_open_form.html",
                               form=form,
                               msg=u"ip%s已经被使用" % form.d.ip_address)

        accept_log = models.TrAcceptLog()
        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 = self.current_user.username
        accept_log.accept_desc = u"用户新增账号:上网账号:%s" % (form.d.account_number)
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        _datetime = utils.get_currtime()
        order_fee = 0
        balance = 0
        expire_date = form.d.expire_date
        product = self.db.query(models.TrProduct).get(form.d.product_id)

        # 预付费包月
        if product.product_policy == PPMonth:
            order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(
                form.d.months)
            order_fee = int(order_fee.to_integral_value())
        # 买断包月,买断时长,买断流量
        elif product.product_policy in (BOMonth, BOTimes, BOFlows):
            order_fee = int(product.fee_price)
        # 预付费时长,预付费流量
        elif product.product_policy in (PPTimes, PPFlow):
            balance = utils.yuan2fen(form.d.fee_value)
            expire_date = MAX_EXPIRE_DATE

        order = models.TrCustomerOrder()
        order.order_id = utils.gen_order_id()
        order.customer_id = form.d.customer_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"用户增开账号"
        self.db.add(order)

        account = models.TrAccount()
        account.account_number = form.d.account_number
        account.ip_address = form.d.ip_address
        account.customer_id = int(form.d.customer_id)
        account.product_id = order.product_id
        account.install_address = form.d.address
        account.mac_addr = ''
        account.password = self.aes.encrypt(form.d.password)
        account.status = form.d.status
        account.balance = balance
        account.time_length = int(product.fee_times)
        account.flow_length = int(product.fee_flows)
        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_id1 = 0
        account.vlan_id2 = 0
        account.create_time = _datetime
        account.update_time = _datetime
        account.account_desc = form.d.account_desc
        self.db.add(account)
        self.add_oplog(u"用户增开子账号 %s" % account.account_number)
        self.db.commit()

        dispatch.pub(ACCOUNT_OPEN_EVENT, account.account_number, async=True)

        self.redirect(self.detail_url_fmt(account.account_number))
    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")
Beispiel #15
0
    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()]
        form = customer_forms.customer_open_form(nodes, products)
        if not form.validates(source=self.get_params()):
            return self.render("account_open_form.html", form=form)

        if self.db.query(models.TrAccount).filter_by(
                account_number=form.d.account_number).count() > 0:
            return self.render("account_open_form.html",
                               form=form,
                               msg=u"账号%s已经存在" % form.d.account_number)

        if form.d.ip_address and self.db.query(models.TrAccount).filter_by(
                ip_address=form.d.ip_address).count() > 0:
            return self.render("account_open_form.html",
                               form=form,
                               msg=u"ip%s已经被使用" % form.d.ip_address)

        if self.db.query(models.TrCustomer).filter_by(
                customer_name=form.d.account_number).count() > 0:
            return self.render("account_open_form.html",
                               form=form,
                               msg=u"用户名%s已经存在" % form.d.account_number)

        customer = models.TrCustomer()
        customer.node_id = form.d.node_id
        customer.realname = form.d.realname
        customer.customer_name = form.d.account_number
        customer.password = md5(form.d.password.encode()).hexdigest()
        customer.idcard = form.d.idcard
        customer.sex = '1'
        customer.age = '0'
        customer.email = ''
        customer.mobile = form.d.mobile
        customer.address = form.d.address
        customer.create_time = utils.get_currtime()
        customer.update_time = utils.get_currtime()
        customer.email_active = 0
        customer.mobile_active = 0
        customer.active_code = utils.get_uuid()
        customer.customer_desc = form.d.customer_desc
        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'
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = customer.create_time
        accept_log.operator_name = self.current_user.username
        accept_log.accept_desc = u"用户新开户:(%s)%s" % (customer.customer_name,
                                                    customer.realname)
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        order_fee = 0
        balance = 0
        expire_date = form.d.expire_date
        product = self.db.query(models.TrProduct).get(form.d.product_id)

        # 预付费包月
        if product.product_policy == BOMonth:
            order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(
                form.d.months)
            order_fee = int(order_fee.to_integral_value())

        # 买断包月,买断流量
        elif product.product_policy in (BOMonth, BOFlows):
            order_fee = int(product.fee_price)

        # 预付费时长,预付费流量
        elif product.product_policy in (PPTimes, PPFlow):
            balance = utils.yuan2fen(form.d.fee_value)
            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 = utils.yuan2fen(form.d.fee_value)
        order.pay_status = 1
        order.accept_id = accept_log.id
        order.order_source = 'console'
        order.create_time = customer.create_time
        order.order_desc = u"用户新开账号,赠送天数:%s" % (form.d.giftdays)
        self.db.add(order)

        account = models.TrAccount()
        account.account_number = form.d.account_number
        account.ip_address = form.d.ip_address
        account.customer_id = customer.customer_id
        account.product_id = order.product_id
        account.install_address = customer.address
        account.mac_addr = ''
        account.password = self.aes.encrypt(form.d.password)
        account.status = form.d.status
        account.balance = balance
        account.time_length = int(product.fee_times)
        account.flow_length = int(product.fee_flows)
        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_id1 = 0
        account.vlan_id2 = 0
        account.create_time = customer.create_time
        account.update_time = customer.create_time
        account.account_desc = customer.customer_desc
        self.db.add(account)

        self.add_oplog(u"用户新开账号 %s, 赠送天数:%s " %
                       (account.account_number, form.d.giftdays))
        self.db.commit()

        dispatch.pub(ACCOUNT_OPEN_EVENT, account.account_number, async=True)
        dispatch.pub(settings.CACHE_DELETE_EVENT,
                     account_cache_key(account.account_number),
                     async=True)

        self.redirect(self.detail_url_fmt(account.account_number))
Beispiel #16
0
    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()]
        form = customer_forms.customer_open_form(nodes, products)
        if not form.validates(source=self.get_params()):
            return self.render("account_open_form.html", form=form)

        if self.db.query(models.TrAccount).filter_by(account_number=form.d.account_number).count() > 0:
            return self.render("account_open_form.html", form=form, msg=u"账号%s已经存在" % form.d.account_number)

        if form.d.ip_address and self.db.query(models.TrAccount).filter_by(ip_address=form.d.ip_address).count() > 0:
            return self.render("account_open_form.html", form=form, msg=u"ip%s已经被使用" % form.d.ip_address)

        if self.db.query(models.TrCustomer).filter_by(
            customer_name=form.d.account_number).count() > 0:
            return self.render("account_open_form.html", form=form, msg=u"用户名%s已经存在" % form.d.account_number)

        customer = models.TrCustomer()
        customer.node_id = form.d.node_id
        customer.realname = form.d.realname
        customer.customer_name = form.d.account_number
        customer.password = md5(form.d.password.encode()).hexdigest()
        customer.idcard = form.d.idcard
        customer.sex = '1'
        customer.age = '0'
        customer.email = ''
        customer.mobile = form.d.mobile
        customer.address = form.d.address
        customer.create_time = utils.get_currtime()
        customer.update_time = utils.get_currtime()
        customer.email_active = 0
        customer.mobile_active = 0
        customer.active_code = utils.get_uuid()
        customer.customer_desc = form.d.customer_desc
        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'
        accept_log.account_number = form.d.account_number
        accept_log.accept_time = customer.create_time
        accept_log.operator_name = self.current_user.username
        accept_log.accept_desc = u"用户新开户:(%s)%s" % (customer.customer_name, customer.realname)
        self.db.add(accept_log)
        self.db.flush()
        self.db.refresh(accept_log)

        order_fee = 0
        balance = 0
        expire_date = form.d.expire_date
        product = self.db.query(models.TrProduct).get(form.d.product_id)

        # 预付费包月
        if product.product_policy == BOMonth:
            order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months)
            order_fee = int(order_fee.to_integral_value())

        # 买断包月,买断流量
        elif product.product_policy in (BOMonth, BOFlows):
            order_fee = int(product.fee_price)

        # 预付费时长,预付费流量
        elif product.product_policy in (PPTimes, PPFlow):
            balance = utils.yuan2fen(form.d.fee_value)
            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 = utils.yuan2fen(form.d.fee_value)
        order.pay_status = 1
        order.accept_id = accept_log.id
        order.order_source = 'console'
        order.create_time = customer.create_time
        order.order_desc = u"用户新开账号,赠送天数:%s" % (form.d.giftdays)
        self.db.add(order)

        account = models.TrAccount()
        account.account_number = form.d.account_number
        account.ip_address = form.d.ip_address
        account.customer_id = customer.customer_id
        account.product_id = order.product_id
        account.install_address = customer.address
        account.mac_addr = ''
        account.password = self.aes.encrypt(form.d.password)
        account.status = form.d.status
        account.balance = balance
        account.time_length = int(product.fee_times)
        account.flow_length = int(product.fee_flows)
        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_id1 = 0
        account.vlan_id2 = 0
        account.create_time = customer.create_time
        account.update_time = customer.create_time
        account.account_desc = customer.customer_desc
        self.db.add(account)

        self.add_oplog(u"用户新开账号 %s, 赠送天数:%s " % (account.account_number,form.d.giftdays))
        self.db.commit()

        dispatch.pub(ACCOUNT_OPEN_EVENT, account.account_number, async=True)
        dispatch.pub(db_cache.CACHE_DELETE_EVENT,account_cache_key(account.account_number), async=True)

        self.redirect(self.detail_url_fmt(account.account_number))
    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")
Beispiel #18
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))
    def post(self):
        form = customer_add_vform()
        try:
            request = self.parse_form_request()
            if not form.validates(**request):
                raise Exception(form.errors)
            if self.db.query(models.TrAccount).filter_by(
                    account_number=form.d.account_number).count() > 0:
                raise Exception("account already exists")
        except Exception as err:
            self.render_result(code=1, msg=utils.safeunicode(err.message))
            return

        try:
            customer = models.TrCustomer()
            customer.node_id = form.d.node_id
            customer.realname = form.d.realname
            customer.idcard = form.d.idcard
            customer.customer_name = form.d.customer_name or form.d.account_number
            customer.password = md5(form.d.password.encode()).hexdigest()
            customer.sex = '1'
            customer.age = '0'
            customer.email = form.d.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 = 1
            customer.mobile_active = 1
            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 = 'api'
            accept_log.accept_desc = u"API开通账号:%s" % form.d.account_number
            accept_log.account_number = form.d.account_number
            accept_log.accept_time = customer.update_time
            accept_log.operator_name = 'api'
            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(form.d.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"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 = ''
            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_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_result(code=0, msg='success')
        except Exception as e:
            self.render_result(code=1, msg=utils.safeunicode(e.message))
            import traceback
            traceback.print_exc()