def storage(): dates_info = {} start_str = request.args.get('start_date', datetime.now().strftime(DATE_FORMAT)) start = datetime.strptime(start_str, DATE_FORMAT).date() m_dict = defaultdict(list) dates_list = [] for x in range(0, 30): current = start + timedelta(days=x) m_dict[current.month].append(current) dates_list.append(current) dates_info['dates'] = dates_list dates_info['months'] = [(m, len(d_list)) for m, d_list in m_dict.items()] medium_id = int(request.args.get('selected_medium', 0)) select_medium = [(m.id, m.name) for m in Medium.all()] select_medium.insert(0, (0, u'全部媒体')) positions_info = AdPosition.all_positions_info_by_date() if medium_id: medium = Medium.get(medium_id) positions_info = medium.positions_info_by_date() return tpl( 'storage.html', dates_info=dates_info, medium=select_medium, medium_id=medium_id, positions_info=positions_info, start_date=start_str, per_start_date=(start - timedelta(days=30)).strftime(DATE_FORMAT), next_start_date=(start + timedelta(days=30)).strftime(DATE_FORMAT))
def index(type): page = int(request.values.get('p', 1)) industry = request.values.get('industry', '') medium = int(request.values.get('medium', 0)) info = request.values.get('info', '') cases = list(Case.query.filter_by(type=type)) if medium: cases = [case for case in cases if medium in case.mediums_id] if info: cases = [case for case in cases if info in case.info] if industry: cases = [case for case in cases if industry == case.industry] paginator = Paginator(cases, 50) try: cases = paginator.page(page) except: cases = paginator.page(paginator.num_pages) return tpl('/mediums/planning/index.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), medium=medium, cases=cases, type=type, info=info, params="&info=%s&medium=%s&industry=%s" % (info, str(medium), industry), INDUSTRY=INDUSTRY, page=page, tags=Tag.all(), industry=industry)
def index(): page = int(request.values.get('p', 1)) medium_id = int(request.values.get('medium_id', 0)) product_id = int(request.values.get('product_id', 0)) type = int(request.values.get('type', 0)) number = request.values.get('number', '') filters = {} if medium_id: filters['medium_id'] = medium_id if product_id: filters['product'] = product_id if type: filters['type'] = type if filters: resources = MediumResource.query.filter_by(**filters) else: resources = MediumResource.all() if number: resources = resources.filter( MediumResource.number.startswith(number.strip())) paginator = Paginator(list(resources), 50) try: resources = paginator.page(page) except: resources = paginator.page(paginator.num_pages) for k in resources.object_list: if k.type == 1: k.product_obj = MediumProductPC.get(k.product) elif k.type == 2: k.product_obj = MediumProductApp.get(k.product) elif k.type == 3: k.product_obj = MediumProductDown.get(k.product) return tpl('/mediums/resource/index.html', resources=resources, mediums=Medium.all(), type=type, product_id=product_id, number=number, medium_id=medium_id, params="&medium_id=%s&number=%s&type=%s&product_id=%s" % (medium_id, number, type, product_id))
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 mediums(): medium_rebate = MediumRebate.all() medium_rebate_data = {} for k in medium_rebate: if str(k.medium.id) + '_' + str(k.year.year) not in medium_rebate_data: medium_rebate_data[str(k.medium.id) + '_' + str(k.year.year)] = str(k.rebate) + '%' medium_data = [] for medium in Medium.all(): dict_medium = {} dict_medium['files_update_time'] = medium.files_update_time dict_medium['abbreviation'] = medium.abbreviation dict_medium['level_cn'] = medium.level_cn dict_medium['id'] = medium.id dict_medium['name'] = medium.name dict_medium['level'] = medium.level or 100 if str(medium.id) + '_2014' in medium_rebate_data: dict_medium['rebate_2014'] = medium_rebate_data[str(medium.id) + '_2014'] else: dict_medium['rebate_2014'] = u'无' if str(medium.id) + '_2015' in medium_rebate_data: dict_medium['rebate_2015'] = medium_rebate_data[str(medium.id) + '_2015'] else: dict_medium['rebate_2015'] = u'无' if str(medium.id) + '_2016' in medium_rebate_data: dict_medium['rebate_2016'] = medium_rebate_data[str(medium.id) + '_2016'] else: dict_medium['rebate_2016'] = u'无' medium_data.append(dict_medium) medium_data = sorted(medium_data, key=operator.itemgetter('level'), reverse=False) if request.values.get('action') == 'excel': return write_medium_excel(mediums=medium_data) return tpl('/client/medium/index.html', mediums=medium_data)
def index(): if not g.user.is_super_admin(): abort(403) form = ClientOrderForm(request.form) mediums = [(m.id, m.name) for m in Medium.all()] if request.method == 'POST' and form.validate(): if ClientOrder.query.filter_by(contract=request.values.get('contract')).count() > 0: flash(u'合同号已存在', 'danger') return redirect(url_for('util_insert_orders.index')) order = ClientOrder.add(agent=Agent.get(form.agent.data), client=Client.get(form.client.data), campaign=form.campaign.data, money=int("%.0f" % (form.money.data or 0)), client_start=form.client_start.data, client_end=form.client_end.data, reminde_date=form.reminde_date.data, direct_sales=User.gets(form.direct_sales.data), agent_sales=User.gets(form.agent_sales.data), contract_type=form.contract_type.data, resource_type=form.resource_type.data, sale_type=form.sale_type.data, contract=request.values.get('contract', ''), creator=g.user, contract_status=2, create_time=datetime.now()) order.add_comment(g.user, u"导入了客户订单:%s - %s - %s" % ( order.agent.name, order.client.name, order.campaign )) medium_ids = request.values.getlist('medium') medium_moneys = request.values.getlist('medium_money') medium_moneys2 = request.values.getlist('medium_money2') medium_contracts = request.values.getlist('medium_contract') if medium_ids and medium_moneys and len(medium_ids) == len(medium_moneys): for x in range(len(medium_ids)): medium = Medium.get(medium_ids[x]) mo = Order.add(campaign=order.campaign, medium=medium, sale_money=int("%.0f" % (form.money.data or 0)), medium_money=int(medium_moneys[x] or 0), medium_money2=int(medium_moneys2[x] or 0), medium_contract=medium_contracts[x], medium_start=order.client_start, medium_end=order.client_end, creator=g.user) order.medium_orders = order.medium_orders + [mo] order.add_comment(g.user, u"导入了媒体订单: %s %s元" % (medium.name, mo.sale_money)) order.save() flash(u'导入客户订单成功!', 'success') insert_executive_report(order, '') return redirect(order.info_path()) else: form.client_start.data = datetime.now().date() form.client_end.data = datetime.now().date() form.reminde_date.data = datetime.now().date() return tpl('insert_order.html', form=form, mediums=mediums)
def __init__(self, *args, **kwargs): super(UnitForm, self).__init__(*args, **kwargs) self.target.choices = TARGET_CN.items() self.status.choices = STATUS_CN.items() self.size.choices = [(x.id, x.name) for x in AdSize.all()] self.positions.choices = [(x.id, x.display_name) for x in AdPosition.all()] self.medium.choices = [(x.id, x.name) for x in Medium.all()]
def index(): info = request.values.get('info', '') mediums = [{'files_update_time': k.files_update_time, 'level_cn': k.medium_group.level_cn, 'id': k.id, 'name': k.medium_group.name + "-" + k.name, 'level': k.medium_group.level or 100 }for k in Medium.all()] if info: mediums = [m for m in mediums if info in m['name']] mediums = sorted(mediums, key=operator.itemgetter('level'), reverse=False) return tpl('/mediums/files/index.html', mediums=mediums, info=info)
def __init__(self, *args, **kwargs): super(PositionForm, self).__init__(*args, **kwargs) self.status.choices = STATUS_CN.items() self.size.choices = [(x.id, x.name) for x in AdSize.all()] self.medium.choices = [(x.id, x.name) for x in Medium.all()] self.level.choices = POSITION_LEVEL_CN.items() self.ad_type.choices = AD_TYPE_CN.items() self.units.choices = [(x.id, x.display_name) for x in AdUnit.all()] self.estimate_num.readonly = True self.estimate_num.hidden = False self.launch_strategy.choices = LAUNCH_STRATEGY.items()
def index_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') medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_date = [_format_order(k) for k in medium_orders if k.status == 1] douban_date = [_format_order(k, 'douban') for k in douban_orders] medium_info_params = {} medium_info_params[u'豆瓣'] = 0 for k in Medium.all(): medium_info_params[k.name] = 0 for k in medium_date + douban_date: if k['medium_name'] in medium_info_params: medium_info_params[k['medium_name']] += _get_money_by_location(k, location) medium_info_params = sorted( medium_info_params.iteritems(), key=lambda x: x[1]) medium_info_params.reverse() data = [{ "name": u"媒体执行额占比", "data": [] }] sum_saler_money = sum([v for k, v in medium_info_params]) for k, v in medium_info_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(MediumOrderForm, self).__init__(*args, **kwargs) self.medium.choices = [(m.id, m.name) for m in Medium.all()] 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.designers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_DESIGNER) ] self.planers.choices = [ (m.id, m.name) for m in User.gets_by_team_type(TEAM_TYPE_PLANNER) ] self.discount.choices = DISCOUNT_SALE.items()
def index_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') medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) medium_date = [_format_order(k) for k in medium_orders if k.status == 1] douban_date = [_format_order(k, 'douban') for k in douban_orders] medium_info_params = {} medium_info_params[u'豆瓣'] = 0 for k in Medium.all(): medium_info_params[k.name] = 0 for k in medium_date + douban_date: if k['medium_name'] in medium_info_params: medium_info_params[k['medium_name']] += _get_money_by_location(k, location) medium_info_params = sorted( medium_info_params.iteritems(), key=lambda x: x[1]) medium_info_params = [(k, v) for k, v in medium_info_params if v > 0] medium_info_params.reverse() headings = ['#', u'媒体名称', u'执行额', u'占比'] data = [] data.append([k + 1 for k in range(len(medium_info_params))]) data.append([k for k, v in medium_info_params]) data.append([v for k, v in medium_info_params]) sum_saler_money = sum([v for k, v in medium_info_params]) if sum_saler_money: data.append(['%.2f%%' % (v / sum_saler_money * 100) for k, v in medium_info_params]) else: data.append(['0.00%' for k, v in medium_info_params]) return {'data': data, 'title': u'致趣媒体执行额分析', 'total': float(sum_saler_money), 'headings': headings}
def update(type, cid): if not (g.user.is_planner() or g.user.is_operater()): abort(403) case = Case.get(cid) mediums_form = MediumsForm(request.form) mediums_form.mediums.data = [u.id for u in case.mediums] if request.method == 'POST': name = request.values.get('name', '') url = request.values.get('url', '') brand = request.values.get('brand', '') industry = request.values.get('industry', '') desc = request.values.get('desc', '') tags = request.values.get('tags', '').split(',') is_win = int(request.values.get('is_win', 0)) pwd = request.values.get('pwd', '') case.name = name case.url = url case.medium = Medium.get(1) case.mediums = Medium.gets(request.values.getlist('mediums')) case.brand = brand case.industry = industry case.desc = desc case.is_win = is_win case.creator = g.user case.create_time = datetime.datetime.now() case.pwd = pwd case.save() TagCase.query.filter_by(case=case).delete() for k in tags: if k: tag = Tag.query.filter_by(name=k) if tag.count() > 0: tag = tag.first() else: tag = Tag.add(name=k) tag = Tag.get(tag.id) TagCase.add(tag=tag, case=case) flash(u'修改成功', 'success') return redirect(url_for('mediums_planning.update', type=type, cid=cid)) return tpl('/mediums/planning/update.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), type=type, case=case, mediums_form=mediums_form, INDUSTRY=INDUSTRY)
def create(type): if not (g.user.is_planner() or g.user.is_operater()): abort(403) mediums_form = MediumsForm(request.form) if request.method == 'POST': name = request.values.get('name', '') url = request.values.get('url', '') brand = request.values.get('brand', '') industry = request.values.get('industry', '') desc = request.values.get('desc', '') pwd = request.values.get('pwd', '') tags = request.values.get('tags', '').split(',') is_win = int(request.values.get('is_win', 0)) if Case.query.filter_by(name=name, type=type).count() > 0: flash(u'名称已存在', 'danger') return redirect(url_for('mediums_planning.create', type=type)) case = Case.add(name=name, url=url, medium=Medium.get(1), mediums=Medium.gets(request.values.getlist('mediums')), brand=brand, industry=industry, desc=desc, creator=g.user, type=type, is_win=is_win, pwd=pwd) case = Case.get(case.id) for k in tags: if k: tag = Tag.query.filter_by(name=k) if tag.count() > 0: tag = tag.first() else: tag = Tag.add(name=k) tag = Tag.get(tag.id) TagCase.add(tag=tag, case=case) flash(u'添加成功', 'success') return redirect(url_for('mediums_planning.index', type=type)) return tpl('/mediums/planning/create.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), type=type, mediums_form=mediums_form, INDUSTRY=INDUSTRY)
def __init__(self, *args, **kwargs): super(NewMediumResourceForm, self).__init__(*args, **kwargs) self.medium.choices = [(k.id, k.name) for k in Medium.all()] self.type.choices = [(1, u'PC端'), (2, u'移动端'), (3, u'线下活动')] self.shape.choices = [(1, u'互联网')] self.product.choices = [(k.id, k.name) for k in list(MediumProductPC.all( )) + list(MediumProductApp.all()) + list(MediumProductDown.all())] self.resource_type.choices = [ (1, u'硬广'), (2, u'互动'), (3, u'特殊'), (4, u'其他')] self.b_click.choices = [(0, u'否'), (1, u'是')] self.buy_unit.choices = [ (0, u'无'), (1, u'CPM'), (2, u'千份(周)'), (3, u'期'), (4, u'千份'), (5, u'天')] self.b_directional.choices = [(0, u'否'), (1, u'是')] self.directional_type.choices = [ (0, u'无'), (1, u'地域'), (2, u'话题'), (3, u'地域、话题'), (10, u'其他')] self.less_buy.choices = [(0, u'无限制'), (1, u'不低于1000CPM')] self.b_give.choices = [(0, u'否'), (1, u'是')] self.b_check_exposure.choices = [(0, u'否'), (1, u'是')] self.b_check_click.choices = [(0, u'否'), (1, u'是')] self.b_out_link.choices = [(0, u'否'), (1, u'是')] self.b_in_link.choices = [(0, u'否'), (1, u'是')]
def index(type): page = int(request.values.get('p', 1)) industry = request.values.get('industry', '') medium = int(request.values.get('medium', 0)) info = request.values.get('info', '') cases = list(Case.query.filter_by(type=type)) if medium: cases = [case for case in cases if medium in case.mediums_id] if info: cases = [case for case in cases if info in case.info] if industry: cases = [case for case in cases if industry == case.industry] paginator = Paginator(cases, 50) try: cases = paginator.page(page) except: cases = paginator.page(paginator.num_pages) return tpl('/mediums/planning/index.html', title=CASE_TYPE_CN[int(type)], mediums=Medium.all(), medium=medium, cases=cases, type=type, info=info, params="&info=%s&medium=%s&industry=%s" % ( info, str(medium), industry), INDUSTRY=INDUSTRY, page=page, tags=Tag.all(), industry=industry)
def __init__(self, *args, **kwargs): super(NewMediumResourceForm, self).__init__(*args, **kwargs) self.medium.choices = [(k.id, k.name) for k in Medium.all()] self.type.choices = [(1, u'PC端'), (2, u'移动端'), (3, u'线下活动')] self.shape.choices = [(1, u'互联网')] self.product.choices = [ (k.id, k.name) for k in list(MediumProductPC.all()) + list(MediumProductApp.all()) + list(MediumProductDown.all()) ] self.resource_type.choices = [(1, u'硬广'), (2, u'互动'), (3, u'特殊'), (4, u'其他')] self.b_click.choices = [(0, u'否'), (1, u'是')] self.buy_unit.choices = [(0, u'无'), (1, u'CPM'), (2, u'千份(周)'), (3, u'期'), (4, u'千份'), (5, u'天')] self.b_directional.choices = [(0, u'否'), (1, u'是')] self.directional_type.choices = [(0, u'无'), (1, u'地域'), (2, u'话题'), (3, u'地域、话题'), (10, u'其他')] self.less_buy.choices = [(0, u'无限制'), (1, u'不低于1000CPM')] self.b_give.choices = [(0, u'否'), (1, u'是')] self.b_check_exposure.choices = [(0, u'否'), (1, u'是')] self.b_check_click.choices = [(0, u'否'), (1, u'是')] self.b_out_link.choices = [(0, u'否'), (1, u'是')] self.b_in_link.choices = [(0, u'否'), (1, u'是')]
def storage(): dates_info = {} start_str = request.args.get('start_date', datetime.now().strftime(DATE_FORMAT)) start = datetime.strptime(start_str, DATE_FORMAT).date() m_dict = defaultdict(list) dates_list = [] for x in range(0, 30): current = start + timedelta(days=x) m_dict[current.month].append(current) dates_list.append(current) dates_info['dates'] = dates_list dates_info['months'] = [(m, len(d_list)) for m, d_list in m_dict.items()] medium_id = int(request.args.get('selected_medium', 0)) select_medium = [(m.id, m.name) for m in Medium.all()] select_medium.insert(0, (0, u'全部媒体')) positions_info = AdPosition.all_positions_info_by_date() if medium_id: medium = Medium.get(medium_id) positions_info = medium.positions_info_by_date() return tpl('storage.html', dates_info=dates_info, medium=select_medium, medium_id=medium_id, positions_info=positions_info, start_date=start_str, per_start_date=(start - timedelta(days=30)).strftime(DATE_FORMAT), next_start_date=(start + timedelta(days=30)).strftime(DATE_FORMAT))
def apply(): if not g.user.is_finance(): abort(404) medium_id = int(request.args.get('medium_id', 0)) search_info = request.args.get('searchinfo', '').strip() location_id = int(request.args.get('selected_location', '-1')) page = int(request.args.get('p', 1)) orders = list(MediumInvoicePay.query.filter_by(pay_status=4)) if location_id >= 0: orders = [ o for o in orders if location_id in o.medium_invoice.client_order.locations] if search_info != '': orders = [ o for o in orders if search_info.lower() in o.medium_invoice.client_order.search_invoice_info.lower()] if medium_id: orders = [o for o in orders if medium_id == o.medium_invoice.medium_id] select_locations = TEAM_LOCATION_CN.items() select_locations.insert(0, (-1, u'全部区域')) paginator = Paginator(orders, ORDER_PAGE_NUM) try: orders = paginator.page(page) except: orders = paginator.page(paginator.num_pages) for i in orders.object_list: client_order = i.medium_invoice.client_order medium_invoices = [k.id for k in MediumInvoice.query.filter_by(client_order=client_order)] pays = [k for k in MediumInvoicePay.all() if k.medium_invoice_id in medium_invoices] i.apply_num = len([k for k in pays if k.pay_status == 4]) i.pay_num = len([k for k in pays if k.pay_status == 0]) return tpl('/finance/client_order/medium_pay/index.html', orders=orders, title=u'申请中的媒体付款', locations=select_locations, location_id=location_id, now_date=datetime.date.today(), search_info=search_info, page=page, mediums=[(k.id, k.name) for k in Medium.all()], medium_id=medium_id, params='&searchinfo=%s&selected_location=%s&medium_id=%s' % (search_info, location_id, str(medium_id)))
def __init__(self, *args, **kwargs): super(MediumsForm, self).__init__(*args, **kwargs) self.mediums.choices = [(m.id, m.medium_group.name + '-' + m.name) for m in Medium.all()]
def mediums(): mediums = [] for medium in Medium.all(): mediums.append(_medium_to_dict(medium)) return jsonify({'data': mediums})
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)
def index(mtype): page = int(request.values.get('p', 1)) medium_id = int(request.values.get('medium_id', 0)) reg_count = request.values.get('reg_count', '') or 0 active_count = request.values.get('active_count', '') or 0 pv_count = request.values.get('pv_count', '') or 0 time_count = request.values.get('time_count', '') or 0 location = request.values.get('location', '') now_year_count = request.values.get('now_year_count', '') or 0 filters = {} if medium_id: filters['medium_id'] = medium_id if mtype == 'pc': if filters: products = MediumProductPC.query.filter_by(**filters) else: products = MediumProductPC.all() if reg_count: products = products.filter( MediumProductPC.register_count >= int(reg_count)) if active_count: products = products.filter( MediumProductPC.active_count_by_day >= int(active_count)) if pv_count: products = products.filter( MediumProductPC.pv_by_day >= int(pv_count)) if time_count: products = products.filter( MediumProductPC.access_time >= int(time_count)) elif mtype == 'app': if filters: products = MediumProductApp.query.filter_by(**filters) else: products = MediumProductApp.all() if reg_count: products = products.filter( MediumProductApp.register_count >= int(reg_count)) if active_count: products = products.filter( MediumProductApp.active_count_by_day >= int(active_count)) if pv_count: products = products.filter( MediumProductApp.pv_by_day >= int(pv_count)) if time_count: products = products.filter( MediumProductApp.access_time >= int(time_count)) elif mtype == 'down': if location: filters['location'] = location if filters: products = MediumProductDown.query.filter_by(**filters) else: products = MediumProductDown.all() if now_year_count: products = products.filter( MediumProductDown.now_year_count >= int(now_year_count)) paginator = Paginator(list(products), 50) try: products = paginator.page(page) except: products = paginator.page(paginator.num_pages) mediums = Medium.all() params = "&medium_id=%s" % (str(medium_id)) if mtype in ['pc', 'app']: params += "®_count=%s&active_count=%s&pv_count=%s&time_count=%s" % ( reg_count or '', active_count or '', pv_count or '', time_count or '') else: params += "&location=%s&now_year_count=%s" % (location, now_year_count or '') return tpl('/mediums/product/index.html', mtype=mtype, products=products, mediums=mediums, medium_id=medium_id, params=params, reg_count=reg_count or '', active_count=active_count or '', pv_count=pv_count or '', time_count=time_count or '', location=location, now_year_count=now_year_count or '', MEDIUM_RESOURCE_TYPE_INT=MEDIUM_RESOURCE_TYPE_INT)
def __init__(self, *args, **kwargs): super(NewMediumProductAppForm, self).__init__(*args, **kwargs) self.medium.choices = [(k.id, k.name) for k in Medium.all()] self.cooperation_type.choices = [(0, u'否'), (1, u'是')] self.policies.choices = [(k, str(k) + u'折') for k in range(1, 10)]
def money(): now_date = datetime.datetime.now() year = int(request.values.get('year', now_date.year)) start_date_month = datetime.datetime.strptime( str(year) + '-01' + '-01', '%Y-%m-%d') end_date_month = datetime.datetime.strptime( str(year) + '-12' + '-31', '%Y-%m-%d') pre_monthes = get_monthes_pre_days(start_date_month, end_date_month) # 获取代理返点系数 all_agent_rebate = _all_agent_rebate() # 获取媒体返点系数 all_medium_rebate = _all_medium_rebate() # 直签豆瓣订单开始 douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) douban_orders = [_douban_order_to_dict(k, all_agent_rebate) for k in douban_orders if k.status == 1] douban_orders = [k for k in douban_orders if k[ 'contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1] douban_money = _get_medium_moneys( douban_orders, pre_monthes, 0, 'zhiqian_order', year) # 直签豆瓣订单结束 # 媒体订单开始 medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) # 关联豆瓣订单开始 ass_douban_order = [_ass_medium_order_to_dict( k, all_agent_rebate, all_medium_rebate) for k in medium_orders if k.order.associated_douban_order] ass_douban_order = [k for k in ass_douban_order if k[ 'contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1] ass_douban_money = _get_medium_moneys( ass_douban_order, pre_monthes, 0, 'medium_order', year) # 关联豆瓣订单结束 # 普通媒体订单 medium_orders = [_client_order_to_dict(k, all_agent_rebate, all_medium_rebate) for k in medium_orders if k.status == 1] medium_orders = [k for k in medium_orders if k[ 'contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1] youli_money = _get_medium_moneys( medium_orders, pre_monthes, [3], 'medium_order', year) wuxian_money = _get_medium_moneys( medium_orders, pre_monthes, [8], 'medium_order', year) momo_money = _get_medium_moneys( medium_orders, pre_monthes, [7], 'medium_order', year) zhihu_money = _get_medium_moneys( medium_orders, pre_monthes, [5], 'medium_order', year) xiachufang_money = _get_medium_moneys( medium_orders, pre_monthes, [6], 'medium_order', year) xueqiu_money = _get_medium_moneys( medium_orders, pre_monthes, [9], 'medium_order', year) huxiu_money = _get_medium_moneys( medium_orders, pre_monthes, [14, 57], 'medium_order', year) kecheng_money = _get_medium_moneys( medium_orders, pre_monthes, [4], 'medium_order', year) midi_money = _get_medium_moneys( medium_orders, pre_monthes, [21], 'medium_order', year) weipiao_money = _get_medium_moneys( medium_orders, pre_monthes, [52], 'medium_order', year) one_money = _get_medium_moneys( medium_orders, pre_monthes, [51], 'medium_order', year) # ---计算大于100W的媒体 up_money = {} other_money = {'sale_money': [0 for k in range(48)], 'money2': [0 for k in range(48)], 'm_ex_money': [0 for k in range(48)], 'a_rebate': [0 for k in range(48)], 'profit': [0 for k in range(48)]} # 用于计算合计的其他媒体售卖金额 total_except_money = [0 for k in range(48)] total_a_rebate = [0 for k in range(48)] for k in Medium.all(): if int(k.id) not in except_medium_ids: u_medium = _get_medium_moneys( medium_orders, pre_monthes, [int(k.id)], 'medium_order', year) if sum(u_medium['sale_money']) >= 1000000: up_money[k.name] = u_medium else: other_money['sale_money'] = numpy.array( other_money['sale_money']) + numpy.array(u_medium['sale_money']) other_money['money2'] = numpy.array( other_money['money2']) + numpy.array(u_medium['money2']) other_money['m_ex_money'] = numpy.array( other_money['m_ex_money']) + numpy.array(u_medium['m_ex_money']) other_money['a_rebate'] = numpy.array( other_money['a_rebate']) + numpy.array(u_medium['a_rebate']) other_money['profit'] = numpy.array( other_money['profit']) + numpy.array(u_medium['profit']) total_except_money = numpy.array( total_except_money) + numpy.array(u_medium['sale_money']) total_a_rebate = numpy.array( total_a_rebate) + numpy.array(u_medium['a_rebate']) # 计算大于100W的媒体结束--- # 媒体订单结束 # 搜索直签订单开始 searchAd_medium_orders = searchAdMediumOrderExecutiveReport.query.filter( searchAdMediumOrderExecutiveReport.month_day >= start_date_month, searchAdMediumOrderExecutiveReport.month_day <= end_date_month) searchAd_medium_orders = [_search_order_to_dict( k) for k in searchAd_medium_orders] searchAd_medium_orders = [k for k in searchAd_medium_orders if k[ 'contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1] searchAD_money = _get_medium_moneys( searchAd_medium_orders, pre_monthes, 0, 's_medium_order', year) # 搜索直签订单结束 # 搜索返点订单开始 searchAd_rebate_orders = searchAdRebateOrderExecutiveReport.query.filter( searchAdMediumOrderExecutiveReport.month_day >= start_date_month, searchAdMediumOrderExecutiveReport.month_day <= end_date_month) searchAd_rebate_orders = [_search_rebate_order_to_dict(k) for k in searchAd_rebate_orders if k.status == 1] searchAd_rebate_orders = [k for k in searchAd_rebate_orders if k[ 'contract_status'] in [2, 4, 5, 10, 19, 20]] rebate_order_money = _get_medium_moneys( searchAd_rebate_orders, pre_monthes, 0, '', year) # 搜索返点订单结束 # 搜索业务毛利+返点收入 searchAD_money['profit'] = numpy.array( searchAD_money['profit']) + numpy.array(rebate_order_money['sale_money']) # 豆瓣收入、服务费、返点、毛利为直签豆瓣+优力和无线总和 douban_money['sale_money'] = numpy.array( douban_money['sale_money']) + numpy.array(ass_douban_money['money2']) if year == 2016: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array([k * 0.18 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = [0 for k in range(48)] douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) elif year == 2014: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array([k * 0.426 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = numpy.array( douban_money['a_rebate']) + numpy.array(ass_douban_money['a_rebate']) douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) else: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array([k * 0.4 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = numpy.array( douban_money['a_rebate']) + numpy.array(ass_douban_money['a_rebate']) douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) # 计算豆瓣收入、服务费、返点、毛利为直签豆瓣+优力和无线总和 if g.user.is_aduit() and str(year) == '2014': total = numpy.array(momo_money['sale_money']) +\ numpy.array(zhihu_money['sale_money']) +\ numpy.array(xiachufang_money['sale_money']) +\ numpy.array(xueqiu_money['sale_money']) +\ numpy.array(huxiu_money['sale_money']) +\ numpy.array(kecheng_money['sale_money']) +\ numpy.array(midi_money['sale_money']) +\ numpy.array(weipiao_money['sale_money']) +\ numpy.array(one_money['sale_money']) +\ numpy.array(total_except_money) +\ numpy.array(searchAD_money['sale_money']) +\ numpy.array(rebate_order_money['sale_money']) else: total = numpy.array(douban_money['profit']) +\ numpy.array(momo_money['sale_money']) +\ numpy.array(zhihu_money['sale_money']) +\ numpy.array(xiachufang_money['sale_money']) +\ numpy.array(xueqiu_money['sale_money']) +\ numpy.array(huxiu_money['sale_money']) +\ numpy.array(kecheng_money['sale_money']) +\ numpy.array(midi_money['sale_money']) +\ numpy.array(weipiao_money['sale_money']) +\ numpy.array(one_money['sale_money']) +\ numpy.array(total_except_money) +\ numpy.array(searchAD_money['sale_money']) +\ numpy.array(rebate_order_money['sale_money']) if request.values.get('action', '') == 'download': response = write_medium_money_excel(pre_monthes=pre_monthes, douban_money=douban_money, youli_money=youli_money, wuxian_money=wuxian_money, momo_money=momo_money, zhihu_money=zhihu_money, xiachufang_money=xiachufang_money, xueqiu_money=xueqiu_money, huxiu_money=huxiu_money, kecheng_money=kecheng_money, weipiao_money=weipiao_money, one_money=one_money, midi_money=midi_money, other_money=other_money, searchAD_money=searchAD_money, rebate_order_money=rebate_order_money, total=total, up_money=up_money, year=str( year) ) return response return tpl('/data_query/super_leader/medium_money.html', pre_monthes=pre_monthes, douban_money=douban_money, youli_money=youli_money, wuxian_money=wuxian_money, momo_money=momo_money, zhihu_money=zhihu_money, xiachufang_money=xiachufang_money, xueqiu_money=xueqiu_money, huxiu_money=huxiu_money, kecheng_money=kecheng_money, weipiao_money=weipiao_money, one_money=one_money, midi_money=midi_money, other_money=other_money, total=total, searchAD_money=searchAD_money, rebate_order_money=rebate_order_money, year=str(year), up_money=up_money)
def money(): now_date = datetime.datetime.now() year = int(request.values.get('year', now_date.year)) start_date_month = datetime.datetime.strptime( str(year) + '-01' + '-01', '%Y-%m-%d') end_date_month = datetime.datetime.strptime( str(year) + '-12' + '-31', '%Y-%m-%d') pre_monthes = get_monthes_pre_days(start_date_month, end_date_month) # 获取代理返点系数 all_agent_rebate = _all_agent_rebate() # 获取媒体返点系数 all_medium_rebate = _all_medium_rebate() # 直签豆瓣订单开始 douban_orders = DoubanOrderExecutiveReport.query.filter( DoubanOrderExecutiveReport.month_day >= start_date_month, DoubanOrderExecutiveReport.month_day <= end_date_month) douban_orders = [ _douban_order_to_dict(k, all_agent_rebate) for k in douban_orders if k.status == 1 ] douban_orders = [ k for k in douban_orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 ] douban_money = _get_medium_moneys(douban_orders, pre_monthes, 0, 'zhiqian_order', year) # 直签豆瓣订单结束 # 媒体订单开始 medium_orders = MediumOrderExecutiveReport.query.filter( MediumOrderExecutiveReport.month_day >= start_date_month, MediumOrderExecutiveReport.month_day <= end_date_month) # 关联豆瓣订单开始 ass_douban_order = [ _ass_medium_order_to_dict(k, all_agent_rebate, all_medium_rebate) for k in medium_orders if k.order.associated_douban_order ] ass_douban_order = [ k for k in ass_douban_order if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 ] ass_douban_money = _get_medium_moneys(ass_douban_order, pre_monthes, 0, 'medium_order', year) # 关联豆瓣订单结束 # 普通媒体订单 medium_orders = [ _client_order_to_dict(k, all_agent_rebate, all_medium_rebate) for k in medium_orders if k.status == 1 ] medium_orders = [ k for k in medium_orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 ] youli_money = _get_medium_moneys(medium_orders, pre_monthes, [3], 'medium_order', year) wuxian_money = _get_medium_moneys(medium_orders, pre_monthes, [8], 'medium_order', year) momo_money = _get_medium_moneys(medium_orders, pre_monthes, [7], 'medium_order', year) zhihu_money = _get_medium_moneys(medium_orders, pre_monthes, [5], 'medium_order', year) xiachufang_money = _get_medium_moneys(medium_orders, pre_monthes, [6], 'medium_order', year) xueqiu_money = _get_medium_moneys(medium_orders, pre_monthes, [9], 'medium_order', year) huxiu_money = _get_medium_moneys(medium_orders, pre_monthes, [14, 57], 'medium_order', year) kecheng_money = _get_medium_moneys(medium_orders, pre_monthes, [4], 'medium_order', year) midi_money = _get_medium_moneys(medium_orders, pre_monthes, [21], 'medium_order', year) weipiao_money = _get_medium_moneys(medium_orders, pre_monthes, [52], 'medium_order', year) one_money = _get_medium_moneys(medium_orders, pre_monthes, [51], 'medium_order', year) # ---计算大于100W的媒体 up_money = {} other_money = { 'sale_money': [0 for k in range(48)], 'money2': [0 for k in range(48)], 'm_ex_money': [0 for k in range(48)], 'a_rebate': [0 for k in range(48)], 'profit': [0 for k in range(48)] } # 用于计算合计的其他媒体售卖金额 total_except_money = [0 for k in range(48)] total_a_rebate = [0 for k in range(48)] for k in Medium.all(): if int(k.id) not in except_medium_ids: u_medium = _get_medium_moneys(medium_orders, pre_monthes, [int(k.id)], 'medium_order', year) if sum(u_medium['sale_money']) >= 1000000: up_money[k.name] = u_medium else: other_money['sale_money'] = numpy.array( other_money['sale_money']) + numpy.array( u_medium['sale_money']) other_money['money2'] = numpy.array( other_money['money2']) + numpy.array(u_medium['money2']) other_money['m_ex_money'] = numpy.array( other_money['m_ex_money']) + numpy.array( u_medium['m_ex_money']) other_money['a_rebate'] = numpy.array( other_money['a_rebate']) + numpy.array( u_medium['a_rebate']) other_money['profit'] = numpy.array( other_money['profit']) + numpy.array(u_medium['profit']) total_except_money = numpy.array(total_except_money) + numpy.array( u_medium['sale_money']) total_a_rebate = numpy.array(total_a_rebate) + numpy.array( u_medium['a_rebate']) # 计算大于100W的媒体结束--- # 媒体订单结束 # 搜索直签订单开始 searchAd_medium_orders = searchAdMediumOrderExecutiveReport.query.filter( searchAdMediumOrderExecutiveReport.month_day >= start_date_month, searchAdMediumOrderExecutiveReport.month_day <= end_date_month) searchAd_medium_orders = [ _search_order_to_dict(k) for k in searchAd_medium_orders ] searchAd_medium_orders = [ k for k in searchAd_medium_orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] and k['status'] == 1 ] searchAD_money = _get_medium_moneys(searchAd_medium_orders, pre_monthes, 0, 's_medium_order', year) # 搜索直签订单结束 # 搜索返点订单开始 searchAd_rebate_orders = searchAdRebateOrderExecutiveReport.query.filter( searchAdMediumOrderExecutiveReport.month_day >= start_date_month, searchAdMediumOrderExecutiveReport.month_day <= end_date_month) searchAd_rebate_orders = [ _search_rebate_order_to_dict(k) for k in searchAd_rebate_orders if k.status == 1 ] searchAd_rebate_orders = [ k for k in searchAd_rebate_orders if k['contract_status'] in [2, 4, 5, 10, 19, 20] ] rebate_order_money = _get_medium_moneys(searchAd_rebate_orders, pre_monthes, 0, '', year) # 搜索返点订单结束 # 搜索业务毛利+返点收入 searchAD_money['profit'] = numpy.array( searchAD_money['profit']) + numpy.array( rebate_order_money['sale_money']) # 豆瓣收入、服务费、返点、毛利为直签豆瓣+优力和无线总和 douban_money['sale_money'] = numpy.array( douban_money['sale_money']) + numpy.array(ass_douban_money['money2']) if year == 2016: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array( [k * 0.18 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = [0 for k in range(48)] douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) elif year == 2014: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array( [k * 0.426 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = numpy.array( douban_money['a_rebate']) + numpy.array( ass_douban_money['a_rebate']) douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) else: douban_money['money2'] = numpy.array( douban_money['money2']) + numpy.array( [k * 0.4 for k in ass_douban_money['money2']]) douban_money['a_rebate'] = numpy.array( douban_money['a_rebate']) + numpy.array( ass_douban_money['a_rebate']) douban_money['profit'] = numpy.array( douban_money['money2']) - numpy.array(douban_money['a_rebate']) # 计算豆瓣收入、服务费、返点、毛利为直签豆瓣+优力和无线总和 if g.user.is_aduit() and str(year) == '2014': total = numpy.array(momo_money['sale_money']) +\ numpy.array(zhihu_money['sale_money']) +\ numpy.array(xiachufang_money['sale_money']) +\ numpy.array(xueqiu_money['sale_money']) +\ numpy.array(huxiu_money['sale_money']) +\ numpy.array(kecheng_money['sale_money']) +\ numpy.array(midi_money['sale_money']) +\ numpy.array(weipiao_money['sale_money']) +\ numpy.array(one_money['sale_money']) +\ numpy.array(total_except_money) +\ numpy.array(searchAD_money['sale_money']) +\ numpy.array(rebate_order_money['sale_money']) else: total = numpy.array(douban_money['profit']) +\ numpy.array(momo_money['sale_money']) +\ numpy.array(zhihu_money['sale_money']) +\ numpy.array(xiachufang_money['sale_money']) +\ numpy.array(xueqiu_money['sale_money']) +\ numpy.array(huxiu_money['sale_money']) +\ numpy.array(kecheng_money['sale_money']) +\ numpy.array(midi_money['sale_money']) +\ numpy.array(weipiao_money['sale_money']) +\ numpy.array(one_money['sale_money']) +\ numpy.array(total_except_money) +\ numpy.array(searchAD_money['sale_money']) +\ numpy.array(rebate_order_money['sale_money']) if request.values.get('action', '') == 'download': response = write_medium_money_excel( pre_monthes=pre_monthes, douban_money=douban_money, youli_money=youli_money, wuxian_money=wuxian_money, momo_money=momo_money, zhihu_money=zhihu_money, xiachufang_money=xiachufang_money, xueqiu_money=xueqiu_money, huxiu_money=huxiu_money, kecheng_money=kecheng_money, weipiao_money=weipiao_money, one_money=one_money, midi_money=midi_money, other_money=other_money, searchAD_money=searchAD_money, rebate_order_money=rebate_order_money, total=total, up_money=up_money, year=str(year)) return response return tpl('/data_query/super_leader/medium_money.html', pre_monthes=pre_monthes, douban_money=douban_money, youli_money=youli_money, wuxian_money=wuxian_money, momo_money=momo_money, zhihu_money=zhihu_money, xiachufang_money=xiachufang_money, xueqiu_money=xueqiu_money, huxiu_money=huxiu_money, kecheng_money=kecheng_money, weipiao_money=weipiao_money, one_money=one_money, midi_money=midi_money, other_money=other_money, total=total, searchAD_money=searchAD_money, rebate_order_money=rebate_order_money, year=str(year), up_money=up_money)
def index(): if not (g.user.is_super_leader() or g.user.is_media_leader()): return abort(403) now_date = datetime.datetime.now() year = int(request.values.get('year', now_date.year)) start_date_month = datetime.datetime.strptime( str(year) + '-01' + '-01', '%Y-%m-%d') end_date_month = datetime.datetime.strptime( str(year) + '-12' + '-31', '%Y-%m-%d') pre_monthes = get_monthes_pre_days(start_date_month, end_date_month) medium_id = int(request.values.get('medium_id', 0)) ex_medium_orders = [o for o in Order.all( ) if o.medium_start.year == year or o.medium_end.year == year] obj_data = [] for order in ex_medium_orders: pre_month_sale_money = pre_month_money(order.sale_money, order.medium_start, order.medium_end) pre_month_medium_money2 = pre_month_money(order.medium_money2, order.medium_start, order.medium_end) # 单笔返点 agent_rebate = order.client_order.agent_rebate try: self_agent_rebate = order.client_order.self_agent_rebate self_agent_rebate = float(self_agent_rebate.split('-')[0]) self_agent_rebate_value = float(self_agent_rebate.split('-')[1]) except: self_agent_rebate = 0 self_agent_rebate_value = 0 for p in range(len(pre_month_sale_money)): d_order = {} d_order['medium_id'] = order.medium.id d_order['money'] = order.client_order.money d_order['contract_status'] = order.client_order.contract_status d_order['status'] = order.client_order.status d_order['sale_money'] = pre_month_sale_money[p]['money'] d_order['medium_money2'] = pre_month_medium_money2[p]['money'] d_order['month_day'] = pre_month_sale_money[p]['month_day'] medium_rebate = order.medium_rebate_by_year(d_order['month_day']) # 媒体单笔返点 try: self_medium_rebate_data = order.self_medium_rebate self_medium_rebate = self_medium_rebate_data.split('-')[0] self_medium_rebate_value = float(self_medium_rebate_data.split('-')[1]) except: self_medium_rebate = 0 self_medium_rebate_value = 0 if int(self_medium_rebate): if d_order['sale_money']: d_order['medium_rebate_value'] = d_order['sale_money'] / d_order['money'] * self_medium_rebate_value else: d_order['medium_rebate_value'] == 0 else: d_order['medium_rebate_value'] = d_order['medium_money2'] * medium_rebate / 100 if self_agent_rebate: if d_order['money']: d_order['agent_rebate_value'] = self_agent_rebate_value * d_order['sale_money'] / d_order['money'] else: d_order['agent_rebate_value'] = 0 else: d_order['agent_rebate_value'] = d_order['sale_money'] * agent_rebate / 100 obj_data.append(d_order) ex_medium_orders = [k for k in obj_data if k[ 'contract_status'] not in [0, 1, 3, 6, 7, 8, 81, 9] and k['status'] == 1] medium_data = [] if medium_id: mediums = Medium.query.filter_by(id=medium_id) else: mediums = Medium.all() sum_sale_money = 0 for k in mediums: sale_money_data = [] medium_money2_data = [] medium_rebate_data = [] agent_rebate_data = [] for i in pre_monthes: sale_money_data.append(sum([ex['sale_money'] for ex in ex_medium_orders if ex[ 'medium_id'] == k.id and ex['month_day'].date() == i['month'].date()])) medium_money2_data.append(sum([ex['medium_money2'] for ex in ex_medium_orders if ex[ 'medium_id'] == k.id and ex['month_day'].date() == i['month'].date()])) medium_rebate_data.append(sum([ex['medium_rebate_value'] for ex in ex_medium_orders if ex[ 'medium_id'] == k.id and ex['month_day'].date() == i['month'].date()])) agent_rebate_data.append(sum([ex['agent_rebate_value'] for ex in ex_medium_orders if ex[ 'medium_id'] == k.id and ex['month_day'].date() == i['month'].date()])) sum_sale_money += sum(sale_money_data) medium_data.append({'id': k.id, 'name': k.name, 'level': k.level or 100, 'sale_money_data': sale_money_data, 'medium_money2_data': medium_money2_data, 'medium_rebate_data': medium_rebate_data, 'agent_rebate_data': agent_rebate_data}) print sum_sale_money medium_data = sorted( medium_data, key=operator.itemgetter('level'), reverse=False) if request.values.get('action', '') == 'download': return write_client_excel(medium_data, year) return tpl('/data_query/medium/index.html', medium_data=medium_data, medium_id=medium_id, year=year, params="?medium_id=%s&year=%s" % ( medium_id, str(year)), s_mediums=Medium.all())
def mediums_json(): return jsonify({'ret': True, 'data': [{'name': m.name} for m in Medium.all()]})
def __init__(self, *args, **kwargs): super(MediumFrameworkOrderForm, self).__init__(*args, **kwargs) self.mediums.choices = [(a.id, a.medium_group.name + '-' + a.name) for a in Medium.all()] self.medium_users.choices = [(m.id, m.name) for m in User.medias()] self.contract_type.choices = CONTRACT_TYPE_CN.items()