def post(self): form = product_forms.product_add_form() if not form.validates(source=self.get_params()): return self.render("product_form.html", form=form) product = models.TrProduct() product.product_name = form.d.product_name product.product_policy = form.d.product_policy product.product_status = form.d.product_status product.fee_months = int(form.d.get("fee_months", 0)) product.fee_times = utils.hour2sec(form.d.get("fee_times", 0)) product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0)) product.bind_mac = form.d.bind_mac product.bind_vlan = form.d.bind_vlan product.concur_number = form.d.concur_number product.fee_price = utils.yuan2fen(form.d.fee_price) product.fee_period = '' #form.d.fee_period or '' product.input_max_limit = utils.mbps2bps(form.d.input_max_limit) product.output_max_limit = utils.mbps2bps(form.d.output_max_limit) _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") product.create_time = _datetime product.update_time = _datetime self.db.add(product) self.add_oplog(u'新增资费信息:%s' % utils.safeunicode(product.product_name)) self.db.commit() self.redirect("/admin/product", permanent=False)
return self.render_verify_err(err) try: product = models.TrProduct() product.product_name = form.d.product_name product.product_policy = form.d.product_policy product.product_status = form.d.product_status product.fee_months = int(form.d.get("fee_months", 0)) product.fee_times = utils.hour2sec(form.d.get("fee_times", 0)) product.fee_flows = utils.mb2kb(form.d.get("fee_flows", 0)) product.bind_mac = form.d.bind_mac product.bind_vlan = form.d.bind_vlan product.concur_number = form.d.concur_number product.fee_price = utils.yuan2fen(form.d.fee_price) product.fee_period = '' # form.d.fee_period or '' product.input_max_limit = utils.mbps2bps(form.d.input_max_limit) product.output_max_limit = utils.mbps2bps(form.d.output_max_limit) _datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") product.create_time = _datetime product.update_time = _datetime self.db.add(product) self.add_oplog(u'API新增资费信息:%s' % utils.safeunicode(product.product_name)) self.db.commit() return self.render_success(msg=u'资费添加成功') except Exception as e: return self.render_verify_err(e)
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 elif product.product_policy == FreeFee: # 自由资费 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'
balance = utils.yuan2fen(form.d.balance) expire_date = MAX_EXPIRE_DATE elif product.product_policy == FreeFee: # 自由资费 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