コード例 #1
0
ファイル: order.py プロジェクト: cash2one/braavos
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': {}})
コード例 #2
0
ファイル: order.py プロジェクト: cash2one/braavos
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)
コード例 #3
0
ファイル: contract.py プロジェクト: giveme168/braavos
def associated_douban_apply(order_id):
    order = AssociatedDoubanOrder.get(order_id)
    order.medium_order.client_order.add_comment(
        g.user, u"向豆瓣发送合同号申请邮件 %s" % order.name)
    return contract_apply(order)
コード例 #4
0
ファイル: files.py プロジェクト: giveme168/braavos
def finish_associated_douban_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_FINISH)
コード例 #5
0
ファイル: client_total.py プロジェクト: cash2one/braavos
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))
コード例 #6
0
ファイル: files.py プロジェクト: giveme168/braavos
def associated_douban_schedule_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_SCHEDULE)
コード例 #7
0
ファイル: files.py プロジェクト: giveme168/braavos
def associated_douban_order_files(order_id):
    fo = AssociatedDoubanOrder.get(order_id)
    return tpl("order_files.html", order=fo)
コード例 #8
0
ファイル: order.py プロジェクト: giveme168/braavos
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)
コード例 #9
0
ファイル: files.py プロジェクト: giveme168/braavos
def associated_douban_contract_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_CONTRACT)
コード例 #10
0
ファイル: files.py プロジェクト: cash2one/braavos
def finish_associated_douban_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_FINISH)
コード例 #11
0
ファイル: files.py プロジェクト: cash2one/braavos
def associated_douban_order_files(order_id):
    fo = AssociatedDoubanOrder.get(order_id)
    return tpl("order_files.html", order=fo)
コード例 #12
0
ファイル: files.py プロジェクト: cash2one/braavos
def associated_douban_schedule_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_SCHEDULE)
コード例 #13
0
ファイル: files.py プロジェクト: cash2one/braavos
def associated_douban_contract_upload():
    order_id = request.values.get('order')
    order = AssociatedDoubanOrder.get(order_id)
    return attachment_upload(order, FILE_TYPE_CONTRACT)
コード例 #14
0
ファイル: contract.py プロジェクト: cash2one/braavos
def associated_douban_apply(order_id):
    order = AssociatedDoubanOrder.get(order_id)
    order.medium_order.client_order.add_comment(
        g.user, u"向豆瓣发送合同号申请邮件 %s" % order.name)
    return contract_apply(order)