From 988c0a4f782cd674c5591005647e76e754c5f061 Mon Sep 17 00:00:00 2001 From: "zongxi.li" <lizx@wealthgrow.cn> Date: Sun, 7 Feb 2021 00:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=89=BE=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E5=9F=BA=E9=87=91=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/statement.py | 8 ++-- app/service/statement_service.py | 72 +++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/app/controller/statement.py b/app/controller/statement.py index 0e4f351..8eb5e48 100644 --- a/app/controller/statement.py +++ b/app/controller/statement.py @@ -28,15 +28,15 @@ class StatementController(Resource): """.""" self.parser = reqparse.RequestParser() - # @login_require + @login_require def get(self): """""" - self.parser.add_argument('user_id', type=str, required=True, help='用户idä¸èƒ½ä¸ºç©º') + # self.parser.add_argument('user_id', type=str, required=True, help='用户idä¸èƒ½ä¸ºç©º') self.parser.add_argument('statement_time', required=False, help='å¯¹è´¦å•æ—¶é—´æˆ³') args = self.parser.parse_args() print(args.get('statement_time')) - user_id = args.get('user_id') - # user_id = g.ifa_id + # user_id = args.get('user_id') + user_id = g.ifa_id print(user_id) if args.get('statement_time') != '': year = datetime.fromtimestamp(int(args.get('statement_time')) / 1000).year diff --git a/app/service/statement_service.py b/app/service/statement_service.py index 9512122..f552933 100644 --- a/app/service/statement_service.py +++ b/app/service/statement_service.py @@ -10,10 +10,8 @@ import numpy as np from datetime import datetime, date from decimal import Decimal -from app.api.engine import tamp_order_engine, tamp_user_engine, tamp_diagnose_app_engine, TAMP_SQL -# from app.service.data_service_v2_1 import * -# from app.service.customer import get_customer_list -from app.service.portfolio_diagnose import get_fund_name +from app.api.engine import tamp_order_engine, tamp_user_engine, \ + tamp_fund_engine, tamp_product_engine, tamp_diagnose_app_engine, TAMP_SQL class DateEncoder(json.JSONEncoder): @@ -25,16 +23,58 @@ class DateEncoder(json.JSONEncoder): return json.JSONEncoder.default(self, obj) +def get_fund_name(fund, fund_type=1): + if fund_type == 0: + with TAMP_SQL(tamp_fund_engine) as tamp_fund: + tamp_fund_session = tamp_fund.session + sql = "SELECT fund_short_name FROM tx_fund_info WHERE `id`='{}'".format(fund) + # df = pd.read_sql(sql, con) + cur = tamp_fund_session.execute(sql) + data = cur.fetchall() + df = pd.DataFrame(list(data), columns=['fund_short_name']) + + elif fund_type == 1 or fund_type == 2: + with TAMP_SQL(tamp_fund_engine) as tamp_fund: + tamp_fund_session = tamp_fund.session + sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund) + # df = pd.read_sql(sql, con) + cur = tamp_fund_session.execute(sql) + data = cur.fetchall() + df = pd.DataFrame(list(data), columns=['fund_short_name']) + if len(df) == 0: + with TAMP_SQL(tamp_product_engine) as tamp_product: + tamp_product_session = tamp_product.session + sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund) + # df = pd.read_sql(sql, con) + cur = tamp_product_session.execute(sql) + data = cur.fetchall() + df = pd.DataFrame(list(data), columns=['fund_short_name']) + + else: + with TAMP_SQL(tamp_fund_engine) as tamp_fund: + tamp_fund_session = tamp_fund.session + sql = "SELECT fund_name FROM ifa_imported_fund_info WHERE id='{}'".format(fund) + # df = pd.read_sql(sql, con) + cur = tamp_fund_session.execute(sql) + data = cur.fetchall() + df = pd.DataFrame(list(data), columns=['fund_short_name']) + + if df.fund_short_name.count() > 0: + return df.fund_short_name.values[0] + else: + return fund + + def get_order_info(user_id): with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: tamp_diagnose_app_session = tamp_diagnose_app.session - sql_user = """select f1.fund_id, f2.realname, f3.customer_name, f1.customer_id, f3.valueSex,f1.type,f1.order_type,f1.pay_date,f1.subscription_fee,f1.confirm_share_date,f1.confirm_share,f1.confirm_amount,f1.nav,f1.folio_name from tamp_diagnose_app.customer_order_view f1, tamp_user.user_info f2,tamp_diagnose_app.customer_view f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.delete_tag=0 and user_id='{}'""".format( + sql_user = """select f1.id, f1.fund_id, f2.realname, f3.customer_name, f1.customer_id, f3.valueSex,f1.type,f1.order_type,f1.pay_date,f1.subscription_fee,f1.confirm_share_date,f1.confirm_share,f1.confirm_amount,f1.nav,f1.folio_name from tamp_diagnose_app.customer_order_view f1, tamp_user.user_info f2,tamp_diagnose_app.customer_view f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.delete_tag=0 and user_id='{}'""".format( user_id) cur = tamp_diagnose_app_session.execute(sql_user) data = cur.fetchall() order_df = pd.DataFrame(list(data), - columns=['fund_id', 'user_name', 'customer_name', 'customer_id', 'value_sex', 'type', - 'order_type', 'pay_date', + columns=['order_id', 'fund_id', 'user_name', 'customer_name', 'customer_id', 'value_sex', + 'type', 'order_type', 'pay_date', 'subscription_fee', 'confirm_share_date', 'confirm_share', 'confirm_amount', 'nav', 'folio_name']) return order_df @@ -79,7 +119,7 @@ def get_month_list(quarter, year): def type2note(type): - type2note_dict = {1: "è´å…¥", + type2note_dict = {1: "ä¹°å…¥", 2: "赎回", 4: "分红"} return type2note_dict.get(type) @@ -118,7 +158,7 @@ def get_tax_rate(): # 'manage_fee', 'permc_exc_fee','permc_rem_fee', 'recommend_ifa_id', # 'recommend_fee','permc_recommend_fee', 'incentive_fee_ratio', # 'deduction','retention_shares','status']) - return 0 + return 0 class Statement(object): @@ -184,7 +224,7 @@ class Statement(object): detail = [] for i in range(df_length): - detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]).values[0][0], + detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]), 'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'), 'confirm_share_date': np.datetime_as_string(customer_df['confirm_share_date'].values[i], unit='D'), @@ -265,7 +305,7 @@ class Statement(object): for i in range(df_length): tax_rate = get_tax_rate() - detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]).values[0][0], + detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]), 'confirm_amount': customer_df['confirm_amount'].values[i], 'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'), 'subscription_fee': customer_df['subscription_fee'].values[i], @@ -305,7 +345,7 @@ class Statement(object): customer_fund_df = customer_fund[1] fund_id = customer_fund_df['fund_id'].values[0] - fund_name = get_fund_name(fund_id).values[0][0] + fund_name = get_fund_name(fund_id) df_length = customer_fund_df['predict_date'].count() before_tax = 0 @@ -361,7 +401,7 @@ class Statement(object): if carry_sum == 0: continue try: - fund_name = get_fund_name(fund_id).values[0][0] + fund_name = get_fund_name(fund_id) except: fund_name = fund_id @@ -382,14 +422,14 @@ class Statement(object): confirm_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0] nav = self.ifa_order[self.ifa_order['order_id'] == order_id]['nav'].values[0] native_amount = nav - provision_date = '2020-12-31' + provision_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0] detail.append({'customer': customer_name, 'order_type': order_type, 'confirm_date': confirm_date, 'native_amount': native_amount, 'nav': nav, 'provision_date': provision_date, - 'provision_carry':provision_carry} + 'provision_carry': provision_carry} ) before_tax += provision_carry @@ -423,7 +463,7 @@ class Statement(object): customer_id = customer_fund[0][0] customer_name = self.ifa_order[self.ifa_order['customer_id'] == customer_id]['customer_name'].values[0] fund_id = customer_fund[0][1] - fund_name = get_fund_name(fund_id).values[0][0] + fund_name = get_fund_name(fund_id) customer_fund_df = customer_fund[1] incentive_rate_sum = customer_fund_df['incentive_fee_ratio'].sum() -- 2.18.1