132 lines
4.0 KiB
Python
132 lines
4.0 KiB
Python
from lib.all import *
|
|
|
|
service_name = 'vas_calc'
|
|
log_dir = '/app/log'
|
|
logger = Logger(service_name, log_dir=log_dir)
|
|
|
|
hds = [
|
|
"时间",
|
|
"会员数", "会员流水",
|
|
"空间解锁数", "空间解锁流水",
|
|
"空间超粉数", "空间超粉流水",
|
|
"空间动态数", "空间动态流水",
|
|
"其他数(微信+金币)", "其他流水(微信+金币)",
|
|
"总流水", "主播分成", "净收入",
|
|
"利润率",
|
|
"会员流水占比",
|
|
"空间解锁占比",
|
|
"空间超粉占比",
|
|
"空间动态占比",
|
|
"其他占比",
|
|
]
|
|
csv_w = Csv("income_0415_0506.csv", header=hds)
|
|
|
|
|
|
class S:
|
|
def __init__(self, st, et):
|
|
self.st = st
|
|
self.et = et
|
|
self.mysql_db_vas = Mysql(
|
|
"rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com", 3306, "vas", "root", "Wishpal2024"
|
|
)
|
|
|
|
self.csv = Csv("income")
|
|
|
|
def __del__(self):
|
|
self.mysql_db_vas.close()
|
|
|
|
def get_product_sold_list(self):
|
|
sql = '''
|
|
select product_id,
|
|
count(1) cnt,
|
|
sum(pay_amount) money
|
|
from vas_order
|
|
where ct>={} and ct<{}
|
|
and order_status in (1,2)
|
|
group by product_id
|
|
'''.format(self.st, self.et)
|
|
docs = self.mysql_db_vas.query(sql)
|
|
return docs
|
|
|
|
def get_streamer_dias(self):
|
|
sql = '''
|
|
select sum(`change`) dias
|
|
from vas_ch_income
|
|
where ct>={} and ct<{}
|
|
and mid>0
|
|
'''.format(self.st, self.et)
|
|
docs = self.mysql_db_vas.query(sql)
|
|
if len(docs) > 0:
|
|
return safe_get_int(docs[0], "dias")
|
|
return 0
|
|
|
|
def proc(self):
|
|
total_money = 0 # 总流水
|
|
membership_cnt = 0
|
|
membership_money = 0
|
|
zone_admission_cnt = 0
|
|
zone_admission_money = 0
|
|
zone_superfan_cnt = 0
|
|
zone_superfan_money = 0
|
|
zone_moment_cnt = 0
|
|
zone_moment_money = 0
|
|
other_cnt = 0
|
|
other_money = 0
|
|
|
|
sold_list = self.get_product_sold_list()
|
|
for sold in sold_list:
|
|
product_id = safe_get_str(sold, "product_id")
|
|
cnt = safe_get_int(sold, "cnt")
|
|
money = int(safe_get_int(sold, "money") / 100)
|
|
total_money += money
|
|
if product_id == "membership":
|
|
membership_cnt += cnt
|
|
membership_money += money
|
|
elif product_id == "h5_zone_admission":
|
|
zone_admission_cnt += cnt
|
|
zone_admission_money += money
|
|
elif product_id == "h5_zone_superfanship":
|
|
zone_superfan_cnt += cnt
|
|
zone_superfan_money += money
|
|
elif product_id == "h5_zone_moment":
|
|
zone_moment_cnt += cnt
|
|
zone_moment_money += money
|
|
else:
|
|
other_cnt += cnt
|
|
other_money += money
|
|
streamer_dias = self.get_streamer_dias()
|
|
streamer_money = int(streamer_dias / 10)
|
|
official_money = total_money - streamer_money
|
|
data = [
|
|
get_time_str_by_ts(self.st)[:10],
|
|
membership_cnt, membership_money,
|
|
zone_admission_cnt, zone_admission_money,
|
|
zone_superfan_cnt, zone_superfan_money,
|
|
zone_moment_cnt, zone_moment_money,
|
|
other_cnt, other_money,
|
|
total_money, streamer_money, official_money,
|
|
"%.2f%%" % (safe_div(official_money, total_money) * 100.0),
|
|
"%.2f%%" % (safe_div(membership_money, total_money) * 100.0),
|
|
"%.2f%%" % (safe_div(zone_admission_money, total_money) * 100.0),
|
|
"%.2f%%" % (safe_div(zone_superfan_money, total_money) * 100.0),
|
|
"%.2f%%" % (safe_div(zone_moment_money, total_money) * 100.0),
|
|
"%.2f%%" % (safe_div(other_money, total_money) * 100.0)
|
|
]
|
|
csv_w.append([data])
|
|
print(data)
|
|
|
|
|
|
st_et_str_map = gen_st_et_str_map_v2(
|
|
"2024-04-15 00:00:00", "2024-05-06 00:00:00"
|
|
)
|
|
|
|
# st_et_str_map = gen_st_et_str_map(
|
|
# "2024-04-30 00:00:00", 1
|
|
# )
|
|
|
|
for st_str, et_str in st_et_str_map.items():
|
|
s = S(
|
|
get_ts_by_str(st_str), get_ts_by_str(et_str)
|
|
)
|
|
s.proc()
|