def _all_medium_rebate(): medium_rebate_data = [{ 'medium_id': k.medium_id, 'rebate': k.rebate, 'year': k.year } for k in MediumRebate.all()] return medium_rebate_data
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 medium_groups(): info = request.values.get('info', '') medium_groups = MediumGroup.all() if info: medium_groups = [mg for mg in medium_groups if info in mg.search_info] 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_group_rebate = MediumGroupRebate.all() medium_group_rebate_data = {} for k in medium_group_rebate: if str(k.medium_group.id) + '_' + str(k.year.year) not in medium_group_rebate_data: medium_group_rebate_data[str(k.medium_group.id) + '_' + str(k.year.year)] = str(k.rebate) + '%' medium_group_data = [] for medium_group in medium_groups: dict_mg = {} dict_mg['level_cn'] = medium_group.level_cn dict_mg['id'] = medium_group.id dict_mg['name'] = medium_group.name dict_mg['level'] = medium_group.level or 100 if str(medium_group.id) + '_2014' in medium_group_rebate_data: dict_mg['rebate_2014'] = medium_group_rebate_data[str(medium_group.id) + '_2014'] else: dict_mg['rebate_2014'] = u'无' if str(medium_group.id) + '_2015' in medium_group_rebate_data: dict_mg['rebate_2015'] = medium_group_rebate_data[str(medium_group.id) + '_2015'] else: dict_mg['rebate_2015'] = u'无' if str(medium_group.id) + '_2016' in medium_group_rebate_data: dict_mg['rebate_2016'] = medium_group_rebate_data[str(medium_group.id) + '_2016'] else: dict_mg['rebate_2016'] = u'无' medium_data = [] for medium in medium_group.mediums: dict_medium = {} dict_medium['id'] = medium.id dict_medium['name'] = medium.name 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) dict_mg['mediums'] = medium_data medium_group_data.append(dict_mg) medium_group_data = sorted(medium_group_data, key=operator.itemgetter('level'), reverse=False) if request.values.get('action') == 'excel': return write_medium_group_excel(medium_group_data) return tpl('/client/medium/group/index.html', mediums=medium_group_data, info=info)
def medium_rebate_create(medium_id): medium = Medium.get(medium_id) if request.method == 'POST': rebate = float(request.values.get('rebate', 0)) year = request.values.get( 'year', datetime.datetime.now().strftime('%Y')) now_year = datetime.datetime.strptime(year, '%Y').date() if MediumRebate.query.filter_by(medium=medium, year=now_year).count() > 0: flash(u'该执行年返点信息已存在!', 'danger') return tpl('/client/medium/rebate/create.html', medium=medium) MediumRebate.add(medium=medium, rebate=rebate, year=now_year, creator=g.user, create_time=datetime.datetime.now()) flash(u'添加成功!', 'success') return redirect(url_for('client.medium_rebate', medium_id=medium_id)) return tpl('/client/medium/rebate/create.html', medium=medium)
def medium_group_detail(medium_group_id): medium_group = MediumGroup.get(medium_group_id) 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_group.mediums: dict_medium = {} dict_medium['id'] = medium.id dict_medium['name'] = medium.name 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) if request.method == 'POST': name = request.values.get('name', "") tax_num = request.values.get('tax_num', "") address = request.values.get("address", "") phone_num = request.values.get("phone_num", "") bank = request.values.get('bank', "") bank_num = request.values.get("bank_num", "") level = int(request.values.get("level", 100)) db_medium_name = MediumGroup.name_exist(name) if name != medium_group.name: if not db_medium_name: medium_group.name = name else: flash(u'%s 媒体供应商已存在!' % medium_group.name, 'danger') return redirect(url_for("client.medium_group_detail", medium_group_id=medium_group.id)) medium_group.tax_num = tax_num medium_group.address = address medium_group.phone_num = phone_num medium_group.bank = bank medium_group.bank_num = bank_num medium_group.level = level medium_group.save() medium_group.add_comment(g.user, u"修改了媒体供应商: %s\n\n税号:%s\n\n地址:%s\n\n电话:%s\n\n开户行:%s\n\n银行账号:%s\n\n" % (medium_group.name, medium_group.tax_num, medium_group.address, medium_group.phone_num, medium_group.bank, medium_group.bank_num), msg_channel=14) flash(u'修改(%s)媒体供应商成功!' % medium_group.name, 'success') return redirect(url_for("client.medium_group_detail", medium_group_id=medium_group.id)) return tpl('/client/medium/group/info.html', medium_group=medium_group, medium_data=medium_data, FILE_TYPE_CN=FILE_TYPE_CN)
def _all_medium_rebate(): medium_rebate_data = [{'medium_id': k.medium_id, 'rebate': k.rebate, 'year': k.year} for k in MediumRebate.all()] return medium_rebate_data
def medium_rebate_delete(medium_id, rebate_id): MediumRebate.get(rebate_id).delete() return redirect(url_for('client.medium_rebate', medium_id=medium_id))