Exemple #1
0
def index():
    if not g.user.is_super_leader():
        abort(403)
    salers = User.sales()
    if request.method == 'POST':
        f_saler = int(request.values.get('f_saler', 0))
        t_saler = int(request.values.get('t_saler', 0))
        if not f_saler or not t_saler:
            flash(u'请选择正确的员工', 'danger')
            return tpl('/account/turnover/index.html', salers=salers)
        f_user = User.get(f_saler)
        t_user = User.get(t_saler)
        client_orders = ClientOrder.all()
        douban_orders = DoubanOrder.all()
        for k in client_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        for k in douban_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        flash(u'成功', 'success')
    return tpl('/account/turnover/index.html', salers=salers)
Exemple #2
0
def index():
    if not g.user.is_super_leader():
        abort(403)
    salers = User.sales()
    if request.method == 'POST':
        f_saler = int(request.values.get('f_saler', 0))
        t_saler = int(request.values.get('t_saler', 0))
        if not f_saler or not t_saler:
            flash(u'请选择正确的员工', 'danger')
            return tpl('/account/turnover/index.html', salers=salers)
        f_user = User.get(f_saler)
        t_user = User.get(t_saler)
        client_orders = ClientOrder.all()
        douban_orders = DoubanOrder.all()
        for k in client_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        for k in douban_orders:
            if f_user in k.salers and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
            if k.creator == f_user and t_user not in k.replace_sales:
                k.replace_sales = k.replace_sales + [t_user]
                k.save()
        flash(u'成功', 'success')
    return tpl('/account/turnover/index.html', salers=salers)
Exemple #3
0
def outsource():
    if not (g.user.is_leader() or g.user.is_super_leader()):
        abort(403)
    orders = list(ClientOrder.all())
    orders += list(DoubanOrder.all())
    orders = [k for k in orders if k.status == 1]
    search_info = request.values.get('search_info', '')
    location = int(request.values.get('location', 0))
    if search_info:
        orders = [
            k for k in orders
            if search_info.lower().strip() in k.search_info.lower()
        ]
    if location:
        orders = [k for k in orders if location in k.locations]
    if g.user.team.type == TEAM_TYPE_LEADER:
        orders = [
            o for o in orders
            if g.user.location in o.locations and o.get_outsources_by_status(1)
        ]
    elif g.user.team.type == TEAM_TYPE_SUPER_LEADER:
        orders = [o for o in orders if o.get_outsources_by_status(5)]
    if g.user.is_super_admin():
        orders = [
            o for o in orders
            if o.get_outsources_by_status(5) or o.get_outsources_by_status(1)
        ]
    return tpl('/manage/apply/order.html',
               title=u'外包费用报备审批',
               orders=orders,
               search_info=search_info,
               location=location,
               a_type="outsource")
Exemple #4
0
def order_info():
    now_year = int(request.values.get('year', datetime.datetime.now().year))
    outsources = [_target_outsource_to_dict(
        k, 'client_order') for k in OutSource.all()]
    outsources += [_target_outsource_to_dict(k, 'douban_order')
                   for k in DoubanOutSource.all()]
    outsources = [k for k in outsources if k]
    orders = [k for k in ClientOrder.all() if (k.client_start.year ==
                                               now_year or k.client_end.year == now_year) and k.status == 1]
    orders += [k for k in DoubanOrder.all() if (k.client_start.year ==
                                                now_year or k.client_end.year == now_year) and k.status == 1]
    order_obj = []
    for k in orders:
        order_dict = {}
        if k.__tablename__ == 'bra_client_order':
            order_dict['outsource_obj'] = [o for o in outsources if o[
                'order_type'] == 'client_order' and o['order_id'] == k.id]
        else:
            order_dict['outsource_obj'] = [o for o in outsources if o[
                'order_type'] == 'douban_order' and o['order_id'] == k.id]
        order_dict['contract'] = k.contract
        order_dict['campaign'] = k.campaign
        order_dict['money'] = k.money
        order_dict['locations_cn'] = k.locations_cn
        order_dict['outsources_sum'] = k.outsources_sum
        order_dict['outsources_percent'] = k.outsources_percent
        order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji('all')
        if order_dict['outsource_obj']:
            order_obj.append(order_dict)
    if request.values.get('action', '') == 'download':
        return write_outsource_order_info_excel(order_obj)
    return tpl('/data_query/outsource/order_info.html', orders=order_obj, now_year=now_year)
Exemple #5
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(DoubanOrder.all())
    if request.args.get('selected_status'):
        status_id = int(request.args.get('selected_status'))
    else:
        status_id = -1

    orderby = request.args.get('orderby', '')
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))
    year = int(request.values.get('year', datetime.datetime.now().year))
    # page = max(1, page)
    # start = (page - 1) * ORDER_PAGE_NUM
    if location_id >= 0:
        orders = [o for o in orders if location_id in o.locations]
    if status_id >= 0:
        orders = [o for o in orders if o.contract_status == status_id]
    orders = [
        k for k in orders
        if k.client_start.year == year or k.client_end.year == year
    ]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.search_info.lower()
        ]
    if orderby and len(orders):
        orders = sorted(orders,
                        key=lambda x: getattr(x, orderby),
                        reverse=True)
    select_locations = TEAM_LOCATION_CN.items()
    select_locations.insert(0, (-1, u'全部区域'))
    select_statuses = CONTRACT_STATUS_CN.items()
    select_statuses.insert(0, (-1, u'全部合同状态'))
    paginator = Paginator(orders, ORDER_PAGE_NUM)
    try:
        orders = paginator.page(page)
    except:
        orders = paginator.page(paginator.num_pages)

    return tpl(
        '/finance/douban_order/back_money/index.html',
        orders=orders,
        locations=select_locations,
        location_id=location_id,
        statuses=select_statuses,
        status_id=status_id,
        orderby=orderby,
        now_date=datetime.date.today(),
        search_info=search_info,
        page=page,
        year=year,
        params=
        '&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s'
        % (orderby, search_info, location_id, status_id, str(year)))
Exemple #6
0
def douban_order_json():
    if not (g.user.is_super_leader() or g.user.is_aduit()
            or g.user.is_finance()):
        abort(403)
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'orders': [],
            'order_count': 0,
            'order_pre_money': 0
        }
    # 获取所有合同
    orders = DoubanOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(client_params.iteritems(), key=lambda x: x[0])
    # 初始化highcharts数据
    data = []
    data.append({'name': u'客户成交数量', 'data': []})
    data.append({'name': u'客户平均成交额', 'data': []})
    # 根据时间组装合同
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum(
            [_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        # 主装highcharts数据
        day_time_stamp = int(
            datetime.datetime.strptime(str(k),
                                       '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, order_count])
        data[1]['data'].append([day_time_stamp, order_pre_money])
    return jsonify({'data': data, 'title': u'直签豆瓣订单客户数量分析'})
Exemple #7
0
def fix_data_douban():
    if not g.user.is_super_leader():
        abort(403)
    year = int(request.values.get('year', 2015))
    orders = [k for k in DoubanOrder.all() if k.client_start.year ==
              year and k.contract_status not in [0, 7, 8, 9] and k.status == 1 and k.contract]
    for k in orders:
        if int(k.self_agent_rebate.split('-')[0]) == 1:
            k.agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
        else:
            agent_rebate = k.agent_rebate
            k.agent_rebate_value = k.money * agent_rebate / 100
    if request.values.get('action') == 'download':
        return write_fix_date(orders, 'douban_order')
    return tpl('/fix_data_douban.html', orders=orders, year=year)
Exemple #8
0
def order_info():
    now_year = int(request.values.get('year', datetime.datetime.now().year))
    outsources = [
        _target_outsource_to_dict(k, 'client_order') for k in OutSource.all()
    ]
    outsources += [
        _target_outsource_to_dict(k, 'douban_order')
        for k in DoubanOutSource.all()
    ]
    outsources = [k for k in outsources if k]
    orders = [
        k for k in ClientOrder.all()
        if (k.client_start.year == now_year or k.client_end.year == now_year)
        and k.status == 1
    ]
    orders += [
        k for k in DoubanOrder.all()
        if (k.client_start.year == now_year or k.client_end.year == now_year)
        and k.status == 1
    ]
    order_obj = []
    for k in orders:
        order_dict = {}
        if k.__tablename__ == 'bra_client_order':
            order_dict['outsource_obj'] = [
                o for o in outsources
                if o['order_type'] == 'client_order' and o['order_id'] == k.id
            ]
        else:
            order_dict['outsource_obj'] = [
                o for o in outsources
                if o['order_type'] == 'douban_order' and o['order_id'] == k.id
            ]
        order_dict['contract'] = k.contract
        order_dict['campaign'] = k.campaign
        order_dict['money'] = k.money
        order_dict['locations_cn'] = k.locations_cn
        order_dict['outsources_sum'] = k.outsources_sum
        order_dict['outsources_percent'] = k.outsources_percent
        order_dict['outsources_paied_sum'] = k.outsources_paied_sum_by_shenji(
            'all')
        if order_dict['outsource_obj']:
            order_obj.append(order_dict)
    if request.values.get('action', '') == 'download':
        return write_outsource_order_info_excel(order_obj)
    return tpl('/data_query/outsource/order_info.html',
               orders=order_obj,
               now_year=now_year)
Exemple #9
0
def douban_order_excle_data():
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {
            'orders': [],
            'order_count': 0,
            'order_pre_money': 0
        }
    # 获取所有合同
    orders = DoubanOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(client_params.iteritems(), key=lambda x: x[0])

    headings = [u'月份', u'成单客户数', u'平均客户金额']
    data = []
    data.append([str(k + 1) + u'月' for k in range(len(client_params))])

    # 成单客户数
    count_client = []
    # 平均客户金额
    pre_money_client = []
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum(
            [_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        count_client.append(order_count)
        pre_money_client.append(order_pre_money)
    data.append(count_client)
    data.append(pre_money_client)
    return {'data': data, 'title': u'直签豆瓣订单客户数量分析', 'headings': headings}
Exemple #10
0
def douban_order_json():
    if not (g.user.is_super_leader() or g.user.is_aduit() or g.user.is_finance()):
        abort(403)
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'orders': [],
                                            'order_count': 0,
                                            'order_pre_money': 0}
    # 获取所有合同
    orders = DoubanOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(
        client_params.iteritems(), key=lambda x: x[0])
    # 初始化highcharts数据
    data = []
    data.append({'name': u'客户成交数量',
                 'data': []})
    data.append({'name': u'客户平均成交额',
                 'data': []})
    # 根据时间组装合同
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum([_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        # 主装highcharts数据
        day_time_stamp = int(datetime.datetime.strptime(
            str(k), '%Y-%m-%d').strftime('%s')) * 1000
        data[0]['data'].append([day_time_stamp, order_count])
        data[1]['data'].append([day_time_stamp, order_pre_money])
    return jsonify({'data': data, 'title': u'直签豆瓣订单客户数量分析'})
Exemple #11
0
def douban_order_excle_data():
    now_date = datetime.datetime.now()
    location = int(request.values.get('location', 0))
    year = int(request.values.get('year', now_date.year))
    now_year_start = datetime.datetime.strptime(
        str(year) + '-01-01', '%Y-%m-%d')
    now_year_end = datetime.datetime.strptime(str(year) + '-12-01', '%Y-%m-%d')
    client_params = {}
    now_monthes = get_monthes_pre_days(now_year_start, now_year_end)
    for k in now_monthes:
        client_params[k['month'].date()] = {'orders': [],
                                            'order_count': 0,
                                            'order_pre_money': 0}
    # 获取所有合同
    orders = DoubanOrder.all()
    for k in orders:
        if k.contract_status in [2, 4, 5, 10, 19, 20]:
            create_month = k.client_start.replace(day=1)
            if create_month in client_params:
                if location == 0:
                    client_params[create_month]['orders'].append(k)
                elif location in k.locations:
                    client_params[create_month]['orders'].append(k)
    client_params = sorted(
        client_params.iteritems(), key=lambda x: x[0])

    headings = [u'月份', u'成单客户数', u'平均客户金额']
    data = []
    data.append([str(k + 1) + u'月' for k in range(len(client_params))])

    # 成单客户数
    count_client = []
    # 平均客户金额
    pre_money_client = []
    for k, v in client_params:
        order_count = len(v['orders'])
        sum_order_money = sum([_get_money_by_location(i, location) for i in v['orders']])
        if order_count:
            order_pre_money = sum_order_money / order_count
        else:
            order_pre_money = 0
        count_client.append(order_count)
        pre_money_client.append(order_pre_money)
    data.append(count_client)
    data.append(pre_money_client)
    return {'data': data, 'title': u'直签豆瓣订单客户数量分析', 'headings': headings}
Exemple #12
0
def fix_data_douban():
    if not g.user.is_super_leader():
        abort(403)
    year = int(request.values.get('year', 2015))
    orders = [
        k for k in DoubanOrder.all() if k.client_start.year == year and
        k.contract_status not in [0, 7, 8, 9] and k.status == 1 and k.contract
    ]
    for k in orders:
        if int(k.self_agent_rebate.split('-')[0]) == 1:
            k.agent_rebate_value = float(k.self_agent_rebate.split('-')[1])
        else:
            agent_rebate = k.agent_rebate
            k.agent_rebate_value = k.money * agent_rebate / 100
    if request.values.get('action') == 'download':
        return write_fix_date(orders, 'douban_order')
    return tpl('/fix_data_douban.html', orders=orders, year=year)
Exemple #13
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(DoubanOrder.all())
    if request.args.get('selected_status'):
        status_id = int(request.args.get('selected_status'))
    else:
        status_id = -1

    orderby = request.args.get('orderby', '')
    search_info = request.args.get('searchinfo', '').strip()
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))
    year = int(request.values.get('year', datetime.datetime.now().year))
    # page = max(1, page)
    # start = (page - 1) * ORDER_PAGE_NUM
    if location_id >= 0:
        orders = [o for o in orders if location_id in o.locations]
    if status_id >= 0:
        orders = [o for o in orders if o.contract_status == status_id]
    orders = [k for k in orders if k.client_start.year == year or k.client_end.year == year]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.search_info.lower()]
    if orderby and len(orders):
        orders = sorted(
            orders, key=lambda x: getattr(x, orderby), reverse=True)
    select_locations = TEAM_LOCATION_CN.items()
    select_locations.insert(0, (-1, u'全部区域'))
    select_statuses = CONTRACT_STATUS_CN.items()
    select_statuses.insert(0, (-1, u'全部合同状态'))
    paginator = Paginator(orders, ORDER_PAGE_NUM)
    try:
        orders = paginator.page(page)
    except:
        orders = paginator.page(paginator.num_pages)

    return tpl('/finance/douban_order/back_money/index.html', orders=orders,
               locations=select_locations, location_id=location_id,
               statuses=select_statuses, status_id=status_id,
               orderby=orderby, now_date=datetime.date.today(),
               search_info=search_info, page=page, year=year,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&selected_status=%s&year=%s' %
                      (orderby, search_info, location_id, status_id, str(year)))
Exemple #14
0
def index():
    if not g.user.is_finance():
        abort(404)
    orders = list(DoubanOrder.all())
    orderby = request.args.get('orderby', '')
    search_info = request.args.get('searchinfo', '')
    location_id = int(request.args.get('selected_location', '-1'))
    page = int(request.args.get('p', 1))
    year = int(request.values.get('year', datetime.datetime.now().year))
    if location_id >= 0:
        orders = [o for o in orders if location_id in o.locations]
    orders = [k for k in orders if k.client_start.year == year or k.client_end.year == year]
    if search_info != '':
        orders = [
            o for o in orders if search_info.lower() in o.search_info.lower()]
    if orderby and len(orders):
        orders = sorted(
            orders, key=lambda x: getattr(x, orderby), reverse=True)
    select_locations = TEAM_LOCATION_CN.items()
    select_locations.insert(0, (-1, u'全部区域'))
    select_statuses = CONTRACT_STATUS_CN.items()
    select_statuses.insert(0, (-1, u'全部合同状态'))
    paginator = Paginator(orders, ORDER_PAGE_NUM)
    try:
        orders = paginator.page(page)
    except:
        orders = paginator.page(paginator.num_pages)
    for k in orders.object_list:
        k.ex_money = sum(
            [i.ex_money for i in DoubanOutsourceInvoice.query.filter_by(douban_order=k)])
        k.pay_num = sum([i.pay_num for i in k.get_outsources_by_status(4)])
        apply_outsources = []
        for i in [1, 2, 3, 5]:
            apply_outsources += k.get_outsources_by_status(i)
        k.apply_money = sum([j.pay_num for j in apply_outsources])
    return tpl('/finance/douban_order/outsource/invoice.html', orders=orders, locations=select_locations,
               location_id=location_id, statuses=select_statuses, orderby=orderby,
               now_date=datetime.date.today(), search_info=search_info, page=page, year=year,
               params='&orderby=%s&searchinfo=%s&selected_location=%s&year=%s' %
                      (orderby, search_info, location_id, str(year)))
Exemple #15
0
def outsource():
    if not (g.user.is_leader() or g.user.is_super_leader()):
        abort(403)
    orders = list(ClientOrder.all())
    orders += list(DoubanOrder.all())
    orders = [k for k in orders if k.status == 1]
    search_info = request.values.get('search_info', '')
    location = int(request.values.get('location', 0))
    if search_info:
        orders = [k for k in orders if search_info.lower().strip()
                  in k.search_info.lower()]
    if location:
        orders = [k for k in orders if location in k.locations]
    if g.user.team.type == TEAM_TYPE_LEADER:
        orders = [
            o for o in orders if g.user.location in o.locations and o.get_outsources_by_status(1)]
    elif g.user.team.type == TEAM_TYPE_SUPER_LEADER:
        orders = [o for o in orders if o.get_outsources_by_status(5)]
    if g.user.is_super_admin():
        orders = [o for o in orders if o.get_outsources_by_status(
            5) or o.get_outsources_by_status(1)]
    return tpl('/manage/apply/order.html', title=u'外包费用报备审批', orders=orders,
               search_info=search_info, location=location, a_type="outsource")
Exemple #16
0
def order():
    sn = request.values.get('sn', '')
    client_order = [
        _order_to_dict(k) for k in ClientOrder.all()
        if k.contract.lower().strip() == sn.lower().strip()
    ]
    douban_order = [
        _order_to_dict(k) for k in DoubanOrder.all()
        if k.contract.lower().strip() == sn.lower().strip()
    ]
    client_order += [
        _order_to_dict(k.client_order) for k in Order.all()
        if k.medium_contract.lower().strip() == sn.lower().strip()
    ]
    client_order += [
        _order_to_dict(k.client_order, k) for k in AssociatedDoubanOrder.all()
        if k.contract.lower().strip() == sn.lower().strip()
    ]
    if client_order:
        return jsonify({'ret': True, 'data': client_order[0]})
    elif douban_order:
        return jsonify({'ret': True, 'data': douban_order[0]})
    else:
        return jsonify({'ret': False, 'data': {}})
Exemple #17
0
def index():
    query_type = int(request.args.get('query_type', 4))
    query_month = request.args.get('query_month', '')
    page = int(request.args.get('page', 1))
    if query_month:
        query_month = datetime.datetime.strptime(query_month, '%Y-%m')
    else:
        query_month = datetime.datetime.strptime(
            datetime.datetime.now().strftime('%Y-%m'), '%Y-%m')
    # 全部客户订单
    if query_type == 1:
        query_orders = [o for o in ClientOrder.all() if o.client_end.strftime('%Y-%m') >=
                        query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST]
        orders = [{'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign,
                   'start': o.client_start, 'end': o.client_end, 'money': o.money} for o in query_orders]
    # 全部媒体订单
    elif query_type == 2:
        query_orders = [o for o in Order.all() if o.medium_end.strftime('%Y-%m') >=
                        query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST]
        orders = [{'medium_name': o.medium.name, 'campaign': o.campaign, 'start': o.medium_start,
                   'end': o.medium_end, 'money': o.medium_money} for o in query_orders]
    # 全部关联豆瓣订单
    elif query_type == 3:
        query_orders = [o for o in AssociatedDoubanOrder.all() if o.end_date.strftime('%Y-%m') >=
                        query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST]
        orders = [{'jiafang_name': o.jiafang_name, 'client_name': o.client.name, 'campaign': o.campaign,
                   'start': o.start_date, 'end': o.end_date, 'money': o.money} for o in query_orders]
    # 全部直签豆瓣订单
    else:
        query_orders = [o for o in DoubanOrder.all() if o.client_end.strftime('%Y-%m') >=
                        query_month.strftime('%Y-%m') and o.contract_status in ECPM_CONTRACT_STATUS_LIST]
        orders = [{'agent_name': o.agent.name, 'client_name': o.client.name, 'campaign': o.campaign,
                   'start': o.client_start, 'end': o.client_end, 'money': o.money} for o in query_orders]
    th_count = 0
    th_obj = []
    for order in orders:
        if order['money']:
            pre_money = float(order['money']) / \
                ((order['end'] - order['start']).days + 1)
        else:
            pre_money = 0
        monthes_pre_days = get_monthes_pre_days(query_month, datetime.datetime.fromordinal(order['start'].toordinal()),
                                                datetime.datetime.fromordinal(order['end'].toordinal()))
        order['order_pre_money'] = [{'month': k['month'].strftime('%Y-%m'),
                                     'money': '%.2f' % (pre_money * k['days'])}
                                    for k in monthes_pre_days]
        if len(monthes_pre_days) > th_count:
            th_obj = [
                {'month': k['month'].strftime('%Y-%m')}for k in monthes_pre_days]
            th_count = len(monthes_pre_days)
    if 'excel' == request.args.get('extype', ''):
        if query_type == 1:
            filename = (
                "%s-%s.xls" % (u"月度客户订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')
        elif query_type == 2:
            filename = (
                "%s-%s.xls" % (u"月度媒体订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')
        elif query_type == 3:
            filename = ("%s-%s.xls" % (u"月度关联豆瓣订单金额",
                                       datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')
        else:
            filename = ("%s-%s.xls" % (u"月度直签豆瓣订单金额",
                                       datetime.datetime.now().strftime('%Y%m%d%H%M%S'))).encode('utf-8')
        xls = write_excel(orders, query_type, th_obj)
        response = get_download_response(xls, filename)
        return response
    return tpl('/data_query/order/index.html',
               orders=orders,
               page=page,
               query_type=query_type,
               query_month=query_month.strftime('%Y-%m'),
               th_obj=th_obj)
                                                    order=order,
                                                    medium_money=i[
                                                        'medium_money'],
                                                    medium_money2=i[
                                                        'medium_money2'],
                                                    sale_money=i[
                                                        'sale_money'],
                                                    month_day=i['month'],
                                                    days=i['days'],
                                                    create_time=None)
                er.save()
    return True

if __name__ == '__main__':
    client_orders = ClientOrder.all()
    douban_orders = DoubanOrder.all()
    framework_orders = FrameworkOrder.all()
    medium_framework_orders = MediumFrameworkOrder.all()
    search_client_orders = searchAdClientOrder.all()
    search_rebate_orders = searchAdRebateOrder.all()
    search_framework_orders = searchAdFrameworkOrder.all()

    for c in client_orders:
        c.client_start_year = c.client_start.year
        c.client_end_year = c.client_end.year
        c.save()
        _insert_zhiqu_executive_report(c, 'reload')

    for d in douban_orders:
        d.client_start_year = d.client_start.year
        d.client_end_year = d.client_end.year
Exemple #19
0
def index():
    query_type = int(request.args.get('query_type', 4))
    query_month = request.args.get('query_month', '')
    page = int(request.args.get('page', 1))
    if query_month:
        query_month = datetime.datetime.strptime(query_month, '%Y-%m')
    else:
        query_month = datetime.datetime.strptime(
            datetime.datetime.now().strftime('%Y-%m'), '%Y-%m')
    # 全部客户订单
    if query_type == 1:
        query_orders = [
            o for o in ClientOrder.all()
            if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m')
            and o.contract_status in ECPM_CONTRACT_STATUS_LIST
        ]
        orders = [{
            'agent_name': o.agent.name,
            'client_name': o.client.name,
            'campaign': o.campaign,
            'start': o.client_start,
            'end': o.client_end,
            'money': o.money
        } for o in query_orders]
    # 全部媒体订单
    elif query_type == 2:
        query_orders = [
            o for o in Order.all()
            if o.medium_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m')
            and o.contract_status in ECPM_CONTRACT_STATUS_LIST
        ]
        orders = [{
            'medium_name': o.medium.name,
            'campaign': o.campaign,
            'start': o.medium_start,
            'end': o.medium_end,
            'money': o.medium_money
        } for o in query_orders]
    # 全部关联豆瓣订单
    elif query_type == 3:
        query_orders = [
            o for o in AssociatedDoubanOrder.all()
            if o.end_date.strftime('%Y-%m') >= query_month.strftime('%Y-%m')
            and o.contract_status in ECPM_CONTRACT_STATUS_LIST
        ]
        orders = [{
            'jiafang_name': o.jiafang_name,
            'client_name': o.client.name,
            'campaign': o.campaign,
            'start': o.start_date,
            'end': o.end_date,
            'money': o.money
        } for o in query_orders]
    # 全部直签豆瓣订单
    else:
        query_orders = [
            o for o in DoubanOrder.all()
            if o.client_end.strftime('%Y-%m') >= query_month.strftime('%Y-%m')
            and o.contract_status in ECPM_CONTRACT_STATUS_LIST
        ]
        orders = [{
            'agent_name': o.agent.name,
            'client_name': o.client.name,
            'campaign': o.campaign,
            'start': o.client_start,
            'end': o.client_end,
            'money': o.money
        } for o in query_orders]
    th_count = 0
    th_obj = []
    for order in orders:
        if order['money']:
            pre_money = float(order['money']) / \
                ((order['end'] - order['start']).days + 1)
        else:
            pre_money = 0
        monthes_pre_days = get_monthes_pre_days(
            query_month,
            datetime.datetime.fromordinal(order['start'].toordinal()),
            datetime.datetime.fromordinal(order['end'].toordinal()))
        order['order_pre_money'] = [{
            'month': k['month'].strftime('%Y-%m'),
            'money': '%.2f' % (pre_money * k['days'])
        } for k in monthes_pre_days]
        if len(monthes_pre_days) > th_count:
            th_obj = [{
                'month': k['month'].strftime('%Y-%m')
            } for k in monthes_pre_days]
            th_count = len(monthes_pre_days)
    if 'excel' == request.args.get('extype', ''):
        if query_type == 1:
            filename = (
                "%s-%s.xls" %
                (u"月度客户订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
            ).encode('utf-8')
        elif query_type == 2:
            filename = (
                "%s-%s.xls" %
                (u"月度媒体订单金额", datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
            ).encode('utf-8')
        elif query_type == 3:
            filename = ("%s-%s.xls" %
                        (u"月度关联豆瓣订单金额",
                         datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
                        ).encode('utf-8')
        else:
            filename = ("%s-%s.xls" %
                        (u"月度直签豆瓣订单金额",
                         datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
                        ).encode('utf-8')
        xls = write_excel(orders, query_type, th_obj)
        response = get_download_response(xls, filename)
        return response
    return tpl('/data_query/order/index.html',
               orders=orders,
               page=page,
               query_type=query_type,
               query_month=query_month.strftime('%Y-%m'),
               th_obj=th_obj)
Exemple #20
0
def index():
    if not (g.user.is_super_leader() or g.user.is_aduit()
            or g.user.is_finance()):
        abort(403)
    location = int(request.values.get('location', 1))
    now_date = datetime.datetime.now()
    year = int(request.values.get('year', now_date.year))
    # 获取所有关联豆瓣订单,用于判断媒体订单是否是关联豆瓣订单,全部取出减少链接数据库时间
    ass_douban_order_ids = [
        k.medium_order_id for k in AssociatedDoubanOrder.all()
    ]
    orders = [
        _format_douban_order(k, year) for k in DoubanOrder.all()
        if k.client_start.year >= year - 2 and k.client_start.year <= year
    ]
    orders += [
        _format_client_order(k, year, ass_douban_order_ids)
        for k in Order.all()
        if k.medium_start.year >= year - 2 and k.medium_start.year <= year
    ]
    # 去掉撤单、申请中的合同
    orders = [
        k for k in orders if k['contract_status'] in [2, 4, 5, 10, 19, 20]
        and k['status'] == 1 and k['contract']
    ]
    if location == 1:
        money, data = _fix_client_data(HB_data, orders, location)
    elif location == 2:
        money, data = _fix_client_data(HD_data, orders, location)
    elif location == 3:
        money, data = _fix_client_data(HN_data, orders, location)
    action = request.values.get('action', '')
    if action == 'excel':
        return write_client_total_excel(year=year,
                                        data=data,
                                        money=money,
                                        location=location)
    # 组装数据用于画图
    categories_1 = []
    series_1 = [{
        'name': str(year - 2) + u'年新媒体',
        'data': [],
        'stack': str(year - 2)
    }, {
        'name': str(year - 2) + u'年豆瓣',
        'data': [],
        'stack': str(year - 2)
    }, {
        'name': str(year - 1) + u'年新媒体',
        'data': [],
        'stack': str(year - 1)
    }, {
        'name': str(year - 1) + u'年豆瓣',
        'data': [],
        'stack': str(year - 1)
    }, {
        'name': str(year) + u'年新媒体',
        'data': [],
        'stack': str(year)
    }, {
        'name': str(year) + u'年豆瓣',
        'data': [],
        'stack': str(year)
    }]
    categories_2 = []
    series_2 = [{
        'name': str(year - 2) + u'年新媒体',
        'data': [],
        'stack': str(year - 2)
    }, {
        'name': str(year - 2) + u'年豆瓣',
        'data': [],
        'stack': str(year - 2)
    }, {
        'name': str(year - 1) + u'年新媒体',
        'data': [],
        'stack': str(year - 1)
    }, {
        'name': str(year - 1) + u'年豆瓣',
        'data': [],
        'stack': str(year - 1)
    }, {
        'name': str(year) + u'年新媒体',
        'data': [],
        'stack': str(year)
    }, {
        'name': str(year) + u'年豆瓣',
        'data': [],
        'stack': str(year)
    }]
    for k in data:
        clients = k['clients']
        for c in range(len(clients)):
            if c <= len(clients) / 2:
                categories_1.append(clients[c]['name'])
                series_1[0]['data'].append(clients[c]['client_money'][0])
                series_1[1]['data'].append(clients[c]['client_money'][1])
                series_1[2]['data'].append(clients[c]['client_money'][3])
                series_1[3]['data'].append(clients[c]['client_money'][4])
                series_1[4]['data'].append(clients[c]['client_money'][7] +
                                           clients[c]['client_money'][9] +
                                           clients[c]['client_money'][11] +
                                           clients[c]['client_money'][13])
                series_1[5]['data'].append(clients[c]['client_money'][8] +
                                           clients[c]['client_money'][10] +
                                           clients[c]['client_money'][12] +
                                           clients[c]['client_money'][14])
            else:
                categories_2.append(clients[c]['name'])
                series_2[0]['data'].append(clients[c]['client_money'][0])
                series_2[1]['data'].append(clients[c]['client_money'][1])
                series_2[2]['data'].append(clients[c]['client_money'][3])
                series_2[3]['data'].append(clients[c]['client_money'][4])
                series_2[4]['data'].append(clients[c]['client_money'][7] +
                                           clients[c]['client_money'][9] +
                                           clients[c]['client_money'][11] +
                                           clients[c]['client_money'][13])
                series_2[5]['data'].append(clients[c]['client_money'][8] +
                                           clients[c]['client_money'][10] +
                                           clients[c]['client_money'][12] +
                                           clients[c]['client_money'][14])
    return tpl('/data_query/super_leader/client_total.html',
               year=year,
               data=data,
               money=money,
               location=location,
               categories_1=json.dumps(categories_1),
               series_1=json.dumps(series_1),
               categories_2=json.dumps(categories_2),
               series_2=json.dumps(series_2))