Ejemplo n.º 1
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))
Ejemplo n.º 2
0
            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)
Ejemplo n.º 3
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()]
        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")
Ejemplo n.º 4
0
            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"开通账号:%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)
Ejemplo n.º 5
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()]
        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")
Ejemplo n.º 6
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))
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()