def douban_order_excle_data(): now_date = datetime.datetime.now() location = int(request.values.get('location', 0)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime(end_year + '-' + end_month, '%Y-%m') douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{ 'client_name': k['client'].name, 'medium_id': k['medium_id'], 'money': _get_money_by_location(k, location) } for k in medium_orders if k['medium_id'] in [3, 8]] douban_orders = [ _format_order(k, 'douban') for k in douban_orders if k.status == 1 ] douban_date = [{ 'client_name': k['client'].name, 'money': _get_money_by_location(k, location) } for k in douban_orders] client_params = {} for k in Client.all(): client_params[k.name] = 0 for k in douban_date + medium_date: if k['client_name'] in client_params: client_params[k['client_name']] += k['money'] client_params = sorted(client_params.iteritems(), key=lambda x: x[1]) client_params = [(k, v) for k, v in client_params if v > 0] client_params.reverse() headings = ['#', u'客户名称', u'执行额', u'占比'] data = [] data.append([k + 1 for k in range(len(client_params))]) data.append([k for k, v in client_params]) data.append([v for k, v in client_params]) sum_saler_money = sum([v for k, v in client_params]) if sum_saler_money: data.append( ['%.2f%%' % (v / sum_saler_money * 100) for k, v in client_params]) else: data.append(['0.00%' for k, v in client_params]) return { 'data': data, 'title': u'直签豆瓣订单(含:优力、无线)客户分析', 'total': float(sum_saler_money), 'headings': headings }
def __init__(self, *args, **kwargs): super(ClientMediumOrderForm, self).__init__(*args, **kwargs) self.agent.choices = [(m.id, m.name) for m in Agent.all()] self.client.choices = [(c.id, c.name) for c in Client.all()] self.direct_sales.choices = [(m.id, m.name) for m in User.sales()] self.agent_sales.choices = [(m.id, m.name) for m in User.sales()] self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()] operaters = User.gets_by_team_type( TEAM_TYPE_OPERATER) + User.gets_by_team_type( TEAM_TYPE_OPERATER_LEADER) self.operaters.choices = [(m.id, m.name) for m in operaters] self.operaters.hidden = True self.designers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_DESIGNER) ] self.designers.hidden = True self.planers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_PLANNER) ] self.planers.hidden = True self.sale_CPM.hidden = True self.medium_CPM.hidden = True self.contract_type.choices = CONTRACT_TYPE_CN.items() self.resource_type.choices = RESOURCE_TYPE_CN.items() self.sale_type.choices = SALE_TYPE_CN.items() self.medium_group.choices = [(m.id, m.name) for m in MediumGroup.all()] self.medium.choices = [(m.id, m.name) for m in Medium.all()]
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)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime(end_year + '-' + end_month, '%Y-%m') douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{ 'client_name': k['client'].name, 'medium_id': k['medium_id'], 'money': _get_money_by_location(k, location) } for k in medium_orders if k['medium_id'] in [3, 8]] douban_orders = [ _format_order(k, 'douban') for k in douban_orders if k.status == 1 ] douban_date = [{ 'client_name': k['client'].name, 'money': _get_money_by_location(k, location) } for k in douban_orders] client_params = {} for k in Client.all(): client_params[k.name] = 0 for k in douban_date + medium_date: if k['client_name'] in client_params: client_params[k['client_name']] += k['money'] client_params = sorted(client_params.iteritems(), key=lambda x: x[1]) client_params.reverse() data = [{"name": u"占比", "data": []}] sum_saler_money = sum([v for k, v in client_params]) for k, v in client_params: if v > 0: if sum_saler_money == 0: percent = u'0.00%' else: percent = v / sum_saler_money * 100 data[0]['data'].append({'name': k, 'y': v, 'percent': percent}) return jsonify({ 'data': data, 'title': u'直签豆瓣订单(含:优力、无线)客户分析', 'total': float(sum_saler_money) })
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)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime( end_year + '-' + end_month, '%Y-%m') douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{'client_name': k['client'].name, 'medium_id': k['medium_id'], 'money':_get_money_by_location(k, location)} for k in medium_orders if k['medium_id'] in [3, 8]] douban_orders = [_format_order(k, 'douban') for k in douban_orders if k.status == 1] douban_date = [{'client_name': k['client'].name, 'money':_get_money_by_location(k, location)} for k in douban_orders] client_params = {} for k in Client.all(): client_params[k.name] = 0 for k in douban_date + medium_date: if k['client_name'] in client_params: client_params[k['client_name']] += k['money'] client_params = sorted(client_params.iteritems(), key=lambda x: x[1]) client_params.reverse() data = [{ "name": u"占比", "data": [] }] sum_saler_money = sum([v for k, v in client_params]) for k, v in client_params: if v > 0: if sum_saler_money == 0: percent = u'0.00%' else: percent = v / sum_saler_money * 100 data[0]['data'].append({'name': k, 'y': v, 'percent': percent}) return jsonify({'data': data, 'title': u'直签豆瓣订单(含:优力、无线)客户分析', 'total': float(sum_saler_money)})
def __init__(self, *args, **kwargs): super(ClientOrderForm, self).__init__(*args, **kwargs) self.agent.choices = [(m.id, m.name) for m in Agent.all()] self.client.choices = [(c.id, c.name) for c in Client.all()] self.direct_sales.choices = [(m.id, m.name) for m in User.sales()] self.agent_sales.choices = [(m.id, m.name) for m in User.sales()] self.assistant_sales.choices = [(m.id, m.name) for m in User.sales()] self.contract_type.choices = CONTRACT_TYPE_CN.items() self.resource_type.choices = RESOURCE_TYPE_CN.items() self.sale_type.choices = SALE_TYPE_CN.items()
def douban_order_excle_data(): now_date = datetime.datetime.now() location = int(request.values.get('location', 0)) start_year = str(request.values.get('start_year', now_date.year)) start_month = str(request.values.get('start_month', now_date.month)) end_year = str(request.values.get('end_year', now_date.year - 1)) end_month = str(request.values.get('end_month', now_date.month)) start_date_month = datetime.datetime.strptime( start_year + '-' + start_month, '%Y-%m') end_date_month = datetime.datetime.strptime( end_year + '-' + end_month, '%Y-%m') douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) medium_orders = [_format_order(k) for k in medium_orders if k.status == 1] medium_date = [{'client_name': k['client'].name, 'medium_id': k['medium_id'], 'money':_get_money_by_location(k, location)} for k in medium_orders if k['medium_id'] in [3, 8]] douban_orders = [_format_order(k, 'douban') for k in douban_orders if k.status == 1] douban_date = [{'client_name': k['client'].name, 'money':_get_money_by_location(k, location)} for k in douban_orders] client_params = {} for k in Client.all(): client_params[k.name] = 0 for k in douban_date + medium_date: if k['client_name'] in client_params: client_params[k['client_name']] += k['money'] client_params = sorted(client_params.iteritems(), key=lambda x: x[1]) client_params = [(k, v) for k, v in client_params if v > 0] client_params.reverse() headings = ['#', u'客户名称', u'执行额', u'占比'] data = [] data.append([k + 1 for k in range(len(client_params))]) data.append([k for k, v in client_params]) data.append([v for k, v in client_params]) sum_saler_money = sum([v for k, v in client_params]) if sum_saler_money: data.append(['%.2f%%' % (v / sum_saler_money * 100) for k, v in client_params]) else: data.append(['0.00%' for k, v in client_params]) return {'data': data, 'title': u'直签豆瓣订单(含:优力、无线)客户分析', 'total': float(sum_saler_money), 'headings': headings}
'agent_name':k['agent_name'], 'money':k['medium_money2'], 'medium_id':k['medium_id'], 'medium_name':k['medium_name']} for k in medium_orders] douban_date = [{'client_id': k['client_id'], 'client': k['client'], 'agent_id': k['agent_id'], 'agent': k['agent'], 'agent_name':k['agent_name'], 'client_name':k['client_name'], 'money':k['money']} for k in douban_orders] client_data = {} for k in Client.all(): client_data[k.name] = 0 for k in douban_date+youli_data+wuxian_data: if client_data.has_key(k['client'].name): client_data[k['client'].name] += k['money'] client_data = sorted(client_data.iteritems(), key=lambda x: x[1]) client_data.reverse() for k in client_data: if k[1]: print k[0], k[1] ''' medium_data = {} for k in Medium.all(): if k.id in [52, 51, 46, 14,9,7,6,5,4]: medium_data[k.name] = 0 for k in medium_date:
def clients(): info = request.values.get('info', '') clients = Client.all() if info: clients = [c for c in clients if info in c.name] return tpl('clients.html', clients=clients, info=info)
def clients(): clients = [{'id': k.id, 'name': k.name} for k in Client.all()] return jsonify({'data': clients})
def update(oid): out = Out.get(oid) joiners_form = JoinersForm(request.form) joiners_form.joiners.data = [u.id for u in out.joiners] m_persions = [] if g.user.is_out_saler: m_persions += [{'key': '1' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Client.all()] m_persions += [{'key': '2' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Agent.all()] m_persions += [{'key': '3' + '-' + str(k.id) + '-' + k.name, 'name': k.name} for k in Medium.all()] m_persions.append({'key': 100, 'name': u'其他'}) if request.method == 'POST': if g.user.is_out_saler: creator_type = 1 else: creator_type = 2 start_time = request.values.get('start_time', '') end_time = request.values.get('end_time', '') # m_person有两种类型,一种是其他所以填写,一种是代理+客户+媒体组合而成,例如:1-1,2-1,3-1(具体请查看m_persions) m_persion = request.values.get('m_persion', '') m_persion_type = int(request.values.get('m_persion_type', 1)) reason = request.values.get('reason', '') persions = request.values.get('persions', '') address = request.values.get('address', '') joiners = User.gets(request.values.getlist('joiners')) out.start_time = datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M') out.end_time = datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M') out.reason = reason out.joiners = joiners out.persions = persions out.address = address out.m_persion = m_persion out.m_persion_type = m_persion_type out.creator_type = creator_type out.status = int(request.values.get('action', 0)) out.create_time = datetime.datetime.now() out.save() # 先删除外出报表,在从新添加 OutReport.query.filter_by(out_id=oid).delete() for k in list(set(joiners + [out.creator])): OutReport.add( start_time=datetime.datetime.strptime( start_time, '%Y-%m-%d %H:%M'), end_time=datetime.datetime.strptime( end_time, '%Y-%m-%d %H:%M'), reason=reason, out=out, meeting_s='', persions=persions, address=address, m_persion=m_persion, m_persion_type=m_persion_type, creator_type=creator_type, status=int(request.values.get('action', 0)), creator=k, create_time=datetime.datetime.now() ) if int(int(request.values.get('action', 0))) == OUT_STATUS_APPLY: flash(u'已发送申请', 'success') account_out_apply_signal.send( current_app._get_current_object(), out=out, status=1) else: flash(u'添加成功,请及时申请外出报备', 'success') return redirect(url_for('account_out.index')) return tpl('/account/out/update.html', out=out, m_persions=m_persions, joiners_form=joiners_form)