diff --git a/app/service/statement_service.py b/app/service/statement_service.py index f552933b10deaf4008033c1571a73ab9112f0772..c8f637e20694e93844ef1f7d9ad15398c3f04075 100644 --- a/app/service/statement_service.py +++ b/app/service/statement_service.py @@ -23,41 +23,38 @@ 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']) +def get_fund_name(fund): + 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']) 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) + 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_product_session.execute(sql) + cur = tamp_fund_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 len(df) == 0: + 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] @@ -188,7 +185,10 @@ class Statement(object): def order_history(self): ifa_order = get_order_info(self.user_id) - ifa_name = ifa_order['user_name'].values[0] + try: + ifa_name = ifa_order['user_name'].values[0] + except: + ifa_name = '用户' try: ifa_gender = ifa_order['value_sex'].values[0] except: @@ -293,7 +293,7 @@ class Statement(object): end_date = get_end_date(year, max(month_list)) order_quarterly = self.ifa_order[(self.ifa_order['pay_date'] >= start_date) & (self.ifa_order['pay_date'] < end_date) & - (self.ifa_order['order_type'] != 4)] + (self.ifa_order['order_type'] == 1)] ifa_cus_order_monthly = list(order_quarterly.groupby(order_quarterly.customer_id)) for customer in ifa_cus_order_monthly: @@ -304,6 +304,8 @@ class Statement(object): detail = [] for i in range(df_length): tax_rate = get_tax_rate() + if customer_df['subscription_fee'].values[i] is None: + continue detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]), 'confirm_amount': customer_df['confirm_amount'].values[i], @@ -419,16 +421,16 @@ class Statement(object): customer_name = self.ifa_order[self.ifa_order['customer_id'] == customer_id]['customer_name'].values[0] order_id = row['order_id'] order_type = type2note(self.ifa_order[self.ifa_order['order_id'] == order_id]['order_type'].values[0]) - confirm_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0] + confirm_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_share_date'].values[0] nav = self.ifa_order[self.ifa_order['order_id'] == order_id]['nav'].values[0] native_amount = nav - provision_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0] + provision_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_share_date'].values[0] detail.append({'customer': customer_name, 'order_type': order_type, - 'confirm_date': confirm_date, + 'confirm_date': np.datetime_as_string(confirm_date, unit='D'), 'native_amount': native_amount, 'nav': nav, - 'provision_date': provision_date, + 'provision_date': np.datetime_as_string(provision_date, unit='D'), 'provision_carry': provision_carry} )