Example #1
0
def new_agent():
    if not (g.user.is_contract() or g.user.is_super_leader()):
        abort(403)
    form = NewAgentForm(request.form)
    if request.method == 'POST' and form.validate():
        db_agent_name = Agent.name_exist(form.name.data)
        if not db_agent_name:
            agent = Agent.add(form.name.data, Group.get(form.group.data),
                              form.tax_num.data, form.address.data, form.phone_num.data,
                              form.bank.data, form.bank_num.data, form.contact.data,
                              form.contact_phone.data)
            flash(u'新建代理/直客(%s)成功!' % agent.name, 'success')
        else:
            flash(u'新建代理/直客(%s)失败, 名称已经被占用!' % form.name.data, 'danger')
            return tpl('/client/agent/info.html', form=form, title=u"新建代理公司", status='news')
        agent.add_comment(g.user, u"新建了代理: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n\
            银行账号:%s\n\n内部联系人:%s\n\n内部联系人电话:%s\n\n" %
                          (agent.name, agent.tax_num, agent.address, agent.phone_num,
                           agent.bank, agent.bank_num, agent.contact, agent.contact_phone),
                          msg_channel=13)
        return redirect(url_for("client.agents"))
    return tpl('/client/agent/info.html',
               form=form,
               status='news',
               title=u"新建代理/直客")
Example #2
0
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
Example #3
0
def add_agent(name):
    agent = Agent.add(name)
    return agent
Example #4
0
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)
Example #5
0
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)