def up_data(request):
    """上传数据"""
    # 状态判断
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.method == "POST":
        # 渠道集合,上传人id,当日日期
        t = today()
        user_id = request.session['user_id']
        channel = Channel.objects.all().values()
        channel = {i['name']: i['id'] for i in channel}
        # 处理数据
        for file in get_up_data(request.FILES):
            data = handle_up_data(file)
            res = check_up_data(data, channel)
            if res:
                return HttpResponse(res)
            else:
                pass
            data = reload_up_data(data, channel)
            insert_up_data(data, user_id, t)
        return HttpResponse('success')
    return render_to_response('up_load/up_load.html')
def show_today_form(request):
    """展示当日分配表单"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 9:
        t = today()
        consult = User.objects.filter(user_limit=1).values()
        consult = {i['id']: i['user_name'] for i in consult}
        active = Active.objects.all().values('title', 'active')
        active = {i['title']: i['active'] for i in active}
        channel = Channel.objects.all().values('id', 'name')
        channel = {i['id']: i['name'] for i in channel}
        form = Form.objects.filter(distribute_time=t).values(
            'phone', 'active', 'consult', 'title', 'channel')
        for i in form:
            i['channel'] = channel[i['channel']]
            if i['consult']:
                i['name'] = consult[i['consult']]
            else:
                i['name'] = '未分配'
            if i['active']:
                i['active'] = active[i['active']]
        return render(request, 'base_form.html', {'form': form})
    else:
        return redirect('/index/')
def up_load(request):
    """渠道主页入口"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') in [2, 10, 11]:
        return render(request, 'up_load/up_load.html')
    else:
        return redirect('/index/')
예제 #4
0
def get_charts(request):
    """数据可视化"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    # if request.session.get('user_limit') >= 9:
    channels_ = Channel.objects.all().values()
    channels = dict()
    for i in channels_:
        if i['channel_main'] in channels:
            pass
        else:
            channels[i['channel_main']] = i['name']
    consult = User.objects.filter(user_limit=1).values()
    consult = {i['id']: i['user_name'] for i in consult}
    dates, sale, channel = get_condition(request)
    # dates = ['2020-10-01', '2020-10-31']
    turnover, arrive, order = get_data(dates, sale, channel)
    chart = dict()
    chart['channels'] = channels
    chart['consult'] = consult
    try:
        chart['turnover_time_bar'] = get_turnover_time_bar(
            turnover).render_embed()
    except AttributeError:
        pass
    try:
        chart['arrive_order_time_line'] = get_arrive_order_time_line(
            arrive, order).render_embed()
    except AttributeError:
        pass
    if not channel:
        try:
            chart['turnover_channel_pie'] = get_turnover_channel_pie(
                turnover, channels).render_embed()
        except AttributeError:
            pass
    if not sale:
        try:
            chart['turnover_sale_pie'] = get_turnover_sale_pie(
                turnover, consult).render_embed()
        except AttributeError:
            pass
        try:
            chart['arrive_sale_pie'] = get_arrive_sale_pie(
                arrive, consult).render_embed()
        except AttributeError:
            pass
        try:
            chart['order_sale_pie'] = get_order_sale_pie(
                order, consult).render_embed()
        except AttributeError:
            pass
    return render(request, 'base_chart.html', chart)
def talk_work(request):
    """易聊提交对话页"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 1 and request.session.get(
            'user_limit') != 2:
        return render(request, 'consult/talk_work.html')
    else:
        return redirect('/index/')
def all_no_consult(request):
    """全部未咨询表单"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 9:
        data = get_all_no_consult()
        return render(request, 'base_form.html', data)
    else:
        return redirect('/index/')
def no_line(request):
    """未联系上表单"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 1 and request.session.get(
            'user_limit') != 2:
        sale = request.session.get('user_id')
        data = get_no_line(sale)
        return render(request, 'consult/consult.html', data)
    else:
        return redirect('/index/')
def consult(request):
    """任务页入口"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 1 and request.session.get(
            'user_limit') != 2:
        sale = request.session.get('user_id')
        data = get_consult_form(sale)
        data['turnover'] = get_sale_turnover(request)
        return render(request, 'consult/consult.html', data)
    else:
        return redirect('/index/')
def distribute(request):
    """分配主页入口"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 9:
        re_data = distribute_data()
        re_data['form_data'] = get_form()
        re_data['complete_rate'] = complete_rate(re_data)
        re_data['active_rate'] = active_rate(re_data)
        re_data['turnover'] = get_sale_turnover(request)
        return render(request, 'distribute/distribute.html', re_data)
    else:
        return redirect('/index/')
예제 #10
0
def longqi(request):
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') == 11:
        pass
    else:
        return redirect('/index/')
    re_data = distribute_data()
    re_data['form_data'] = get_form()
    re_data['complete_rate'] = complete_rate(re_data)
    re_data['active_rate'] = active_rate(re_data)
    re_data['turnover'] = get_sale_turnover(request)
    return render(request, 'longqi/longqi.html', re_data)
def handle(request):
    """管理详情页"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 2:
        pass
    else:
        return redirect('/index/')
    time_class, start, end = request_class(request)
    user_limit = request.session.get('user_limit')
    if user_limit != 2:
        sale = None
        no_distribute = Form.objects.filter(consult=None).count()  # 未分配
        no_consult = Form.objects.filter(active=None).count()  # 未咨询
        up_num_today = Form.objects.filter(up_time=today()).count()  # 当日上传
    else:
        sale = request.session.get('user_id')
        no_distribute = Form.objects.filter(promoter=sale,
                                            consult=None).count()  # 未分配
        no_consult = Form.objects.filter(promoter=sale,
                                         active=None).count()  # 未咨询
        up_num_today = Form.objects.filter(promoter=sale,
                                           up_time=today()).count()  # 当日上传
    # 渠道集合
    channel = Channel.objects.all().values()
    channel = {i['id']: i['name'] for i in channel}
    # 表单详情
    form_quality_data = get_form_quality_data(channel, start, end, sale,
                                              time_class)
    # 有效率
    form_quality_rate = calculate_form_quality_rate(form_quality_data)
    # 堆叠图
    form_quality_bar_ = form_quality_bar(form_quality_data).render_embed()
    return render(
        request, 'handle/form_quality.html', {
            'form_quality_data': form_quality_data,
            'no_distribute': no_distribute,
            'no_consult': no_consult,
            'up_num_today': up_num_today,
            'form_quality_rate': form_quality_rate,
            'channel': channel,
            't': str(start) + '至' + str(end),
            't_': str(start) + '&' + str(end) + '&' + str(time_class) + '&',
            'form_quality_bar_': form_quality_bar_
        })
def mouth_statistical(request):
    """月统计函数"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 9:
        pass
    else:
        return redirect('/index/')
    # 日期和渠道
    sale = None
    dates = get_dates()
    channel_data = Channel.objects.all().values()
    channel = {}
    for i in channel_data:
        if i['channel_main'] in channel.keys():
            pass
        else:
            channel[i['channel_main']] = i['name']
    channel_main = {i['id']: i['channel_main'] for i in channel_data}
    mouth_info_hz, mouth_info_data = get_info_statistical(
        channel_main, channel, dates, sale)
    mouth_swt_hz, mouth_swt_data = get_swt_statistical(dates, sale)
    mouth_rate_data = get_rate_statistical(dates, mouth_info_hz, mouth_swt_hz,
                                           sale)
    week_data = sale_week_rate()
    return render(
        request, 'distribute/statistical.html', {
            'channel': channel,
            'swt_xm': [1, 2, 3, 4, 5, 6],
            'mouth_info_hz': mouth_info_hz,
            'mouth_info_data': mouth_info_data,
            'mouth_swt_hz': mouth_swt_hz,
            'mouth_swt_data': mouth_swt_data,
            'mouth_rate_data': mouth_rate_data,
            'week_data': week_data,
            'frame_data': {
                'zz_active': mouth_rate_data['汇总'][1],
                'another_active': mouth_rate_data['汇总'][5],
                'form_active_rate': mouth_rate_data['汇总'][-4],
                'order_rate': mouth_rate_data['汇总'][-2],
                'arrive_rate': mouth_rate_data['汇总'][-1],
            }
        })
def all_no_line(request):
    """全部未联系"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 9:
        data, sale_no_line_num = get_all_no_line()
        sale_no_line_num = sorted(sale_no_line_num.items(),
                                  key=lambda x: x[1],
                                  reverse=True)
        sale_no_line_num = collections.OrderedDict(sale_no_line_num)
        return render(request, 'base_form.html', {
            'form': data['form'],
            'sale_no_line_num': sale_no_line_num
        })
    else:
        return redirect('/index/')
def get_actives_form(request, a, b, c, d):
    """获取有效性的表单"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 2:
        pass
    else:
        return redirect('/index/')
    arg = a + b + c + d
    channels = Channel.objects.all().values('id', 'name')
    channels_ = {i['name']: i['id'] for i in channels}
    channels = {i['id']: i['name'] for i in channels}
    user = User.objects.filter(user_limit=1).values()
    user = {i['id']: i['user_name'] for i in user}
    actives = Active.objects.all().values('title', 'active')
    actives = {i['title']: i['active'] for i in actives}
    arg = arg.split('&')
    start = arg[0]
    end = arg[1]
    time_class = arg[2]
    active = arg[3]
    active_ = actives[int(active)]
    channel = arg[4]
    channel = channels_[channel]
    data = {'form': []}
    if int(time_class):
        form = Form.objects.filter(submit_time__range=[start, end], active=active, channel=channel).values(
            'consult', 'phone', 'channel', 'submit_time', 'distribute_time')
        for i in form:
            i['channel'] = channels[i['channel']]
            i['name'] = user[i['consult']]
            i['active'] = active_
            data['form'].append(i)
    else:
        form = Form.objects.filter(up_time__range=[start, end], active=active, channel=channel).values(
             'consult', 'phone', 'channel', 'submit_time', 'distribute_time')
        for i in form:
            i['channel'] = channels[i['channel']]
            i['name'] = user[i['consult']]
            i['active'] = active_
            data['form'].append(i)
    return render(request, 'base_form.html', data)
def get_today_form(request):
    """展示当日上传表单"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 2:
        t = today()
        channel = Channel.objects.all().values('id', 'name')
        channel = {i['id']: i['name'] for i in channel}
        active = Active.objects.all().values('title', 'active')
        active = {i['title']: i['active'] for i in active}
        form = Form.objects.filter(up_time=t).values('id', 'phone', 'active', 'title', 'channel', 'submit_time')
        for i in form:
            i['channel'] = channel[i['channel']]
            if i['active']:
                i['active'] = active[i['active']]
            else:
                i['active'] = '未咨询'
        return render(request, 'base_form.html', {'form': form})
    else:
        return redirect('/index/')
예제 #16
0
def search_phone_local(request):
    """手机号查询"""
    # 状态判断
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') >= 2:
        pass
    else:
        return redirect('/index/')
    data = request.POST.lists()
    data = dict((x, y) for x, y in data)
    phone = data['phone'][0]
    # 渠道集合
    channel = Channel.objects.all().values()
    channel = {i['id']: i['name'] for i in channel}
    # 咨询人集合
    consultant = User.objects.filter(user_limit=1).values()
    consultant = {i['id']: i['user_name'] for i in consultant}
    # 有效集合
    active = Active.objects.all().values()
    active = {i['title']: i['active'] for i in active}
    # 查询
    form = Form.objects.filter(phone=phone).values('channel', 'id',
                                                   'consult',
                                                   'phone',
                                                   'active',
                                                   'distribute_time')
    for i in form:
        i['channel'] = channel[i['channel']]
        try:
            i['name'] = consultant[i['consult']]
        except:
            i['name'] = None
        if i['active']:
            i['active'] = active[i['active']]
    return render(request, 'base_form.html', {'form': form})
def sale_statistical(request, sale):
    """个人月统计函数"""
    if is_login(request):
        pass
    else:
        return redirect('/login/')
    if request.session.get('user_limit') != 2:
        pass
    else:
        return redirect('/index/')
    # 日期和渠道
    # sale = request.session.get('user_id')
    dates = get_dates()
    channel_data = Channel.objects.all().values()
    channel = {}
    for i in channel_data:
        if i['channel_main'] in channel.keys():
            pass
        else:
            channel[i['channel_main']] = i['name']
    channel_main = {i['id']: i['channel_main'] for i in channel_data}
    # 统计数据
    mouth_info_hz, mouth_info_data = get_info_statistical(
        channel_main, channel, dates, sale)
    mouth_swt_hz, mouth_swt_data = get_swt_statistical(dates, sale)
    mouth_rate_data = get_rate_statistical(dates, mouth_info_hz, mouth_swt_hz,
                                           sale)
    return render(
        request, 'distribute/statistical.html', {
            'channel': channel,
            'swt_xm': [1, 2, 3, 4, 5, 6],
            'mouth_info_hz': mouth_info_hz,
            'mouth_info_data': mouth_info_data,
            'mouth_swt_hz': mouth_swt_hz,
            'mouth_swt_data': mouth_swt_data,
            'mouth_rate_data': mouth_rate_data
        })
예제 #18
0
def search_phone(request):
    if is_login(request):
        return render(request, 'search_phone.html')