def new_medium(medium_group_id): if not (g.user.is_media_leader() or g.user.is_super_leader()): abort(403) if request.method == 'POST': medium_group = MediumGroup.get(int(request.values.get('medium_group_id'))) name = request.values.get('name', '') if not medium_group: flash(u'新建媒体(%s)失败,请选择正确的供应商!' % name, 'danger') return tpl('/client/medium/info.html', title=u"新建媒体", medium=None, medium_groups=MediumGroup.all(), medium_group_id=medium_group_id) medium = Medium.add( name=name, medium_group=medium_group) flash(u'新建媒体(%s)成功!' % name, 'success') return redirect(url_for("client.medium_detail", medium_id=medium.id)) return tpl('/client/medium/info.html', title=u"新建媒体", medium=None, medium_groups=MediumGroup.all(), medium_group_id=medium_group_id)
def _into_order(param): group = Group.query.filter_by(name=u'默认集团').first() if not group: group = Group.add(name=u'默认集团') group.save() agent = Agent.query.filter_by(name=param['agent_name']).first() if not agent: agent = Agent.add( name=param['agent_name'], group=group, tax_num='', address='', phone_num='', bank='', bank_num='', ) client = Client.query.filter_by(name=param['client_name']).first() if not client: client = Client.add(name=param['client_name'], industry=1) # client.save() medium = Medium.query.filter_by(name=param['medium_name']).first() if not medium: medium = Medium.add(name=param['medium_name'], abbreviation=param['medium_name'], tax_num='', address='', phone_num='', bank='', bank_num='', owner=Team.query.filter_by(type=8).first()) team_huabei = Team.query.filter_by(name=u'导入渠道销售团队华北').first() if not team_huabei: team_huabei = Team.add( name=u'导入渠道销售团队华北', type=4, location=1, admins=[], ) team_huanan = Team.query.filter_by(name=u'导入渠道销售团队华南').first() if not team_huanan: team_huanan = Team.add( name=u'导入渠道销售团队华南', type=4, location=3, admins=[], ) team_huadong = Team.query.filter_by(name=u'导入渠道销售团队华东').first() if not team_huadong: team_huadong = Team.add( name=u'导入渠道销售团队华东', type=4, location=2, admins=[], ) team_qita = Team.query.filter_by(name=u'导入渠道销售团队其他').first() if not team_qita: team_qita = Team.add( name=u'导入渠道销售团队其他', type=4, location=0, admins=[], ) if not param['agent_sale_name']: agents = [] else: agent_names = param['agent_sale_name'].split(' ') agents = [] if param['location'] == u'华北': team = team_huabei elif param['location'] == u'华东': team = team_huadong elif param['location'] == u'华南': team = team_huanan else: team = team_qita for k in agent_names: name = k.strip() p_name = p.get_pinyin(name, '').lower() email = p_name + '@inad.com' user = User.query.filter_by(email=email).first() if not user: user = User.add(name, email, 'pwd@inad', team, 1) agents.append(user.id) if param['contract_type'].find(u'非标') >= 0: contract_type = 1 else: contract_type = 0 if param['resource_type'].find(u'硬广') >= 0: resource_type = 0 elif param['resource_type'].find(u'互动') >= 0: resource_type = 1 else: resource_type = 4 if param['sale_type'] == u'代理': sale_type = 0 else: sale_type = 1 if ClientOrder.query.filter_by(agent=agent, client=client, campaign=param['campaign'], status=1).first(): return order = ClientOrder.add( agent=agent, client=client, campaign=param['campaign'], money=param['money'], client_start=param['medium_start'], client_end=param['medium_end'], reminde_date=param['reminde_date'], direct_sales=[], agent_sales=User.gets(agents), contract_type=contract_type, resource_type=resource_type, sale_type=sale_type, creator=g.user, create_time=datetime.datetime.now(), ) order.add_comment( g.user, u"新建了客户订单:%s - %s - %s" % (order.agent.name, order.client.name, order.campaign)) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=param['money'], medium_money=param['medium_money'], medium_money2=param['medium_money2'], medium_start=param['medium_start'], medium_end=param['medium_end'], creator=g.user) order.add_comment(g.user, u"新建了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.medium_orders = [mo] order.save() return
def add_medium(name): team = add_team(TEST_DEFAULT_MEDIUM) medium = Medium.add(name, team) return medium
from app import app from libs.db import db db.create_all() from models.user import (User, Team, TEAM_TYPE_SUPER_ADMIN, TEAM_TYPE_MEDIUM, TEAM_TYPE_LEADER, TEAM_TYPE_DIRECT_SELLER) from models.medium import Medium, MediumGroup from models.client import Client, Agent, Group from models.order import Order from config import DEFAULT_PASSWORD admin_team = Team.add(u'管理员', type=TEAM_TYPE_SUPER_ADMIN) medium_team = Team.add(u'媒体', type=TEAM_TYPE_MEDIUM) leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD, team=sale_team) medium_group = MediumGroup.add(name='测试媒体供应商', tax_num="", address="", phone_num="", bank="", bank_num="", level=100) medium = Medium.add(medium_group, u"测试媒体", owner=medium_team) client = Client.add(u"测试客户", 0) group = Group.add(u'测试代理集团') agent = Agent.add(u"测试代理", group=group)
leader_team = Team.add('ledaer', type=TEAM_TYPE_LEADER) sale_team = Team.add('ledaer', type=TEAM_TYPE_DIRECT_SELLER) user = User.add(name="admin", email="*****@*****.**", password=DEFAULT_PASSWORD, team=admin_team) leader = User.add(name="leader", email="*****@*****.**", password=DEFAULT_PASSWORD, team=leader_team) saler = User.add(name="saler", email="*****@*****.**", password=DEFAULT_PASSWORD, team=sale_team) medium_group = MediumGroup.add(name='测试媒体供应商', tax_num="", address="", phone_num="", bank="", bank_num="", level=100) medium = Medium.add(medium_group, u"测试媒体", owner=medium_team) client = Client.add(u"测试客户", 0) group = Group.add(u'测试代理集团') agent = Agent.add(u"测试代理", group=group)