添加首次付费
This commit is contained in:
parent
c0b829dfb4
commit
0db503885b
59
task/first_recharge.py
Normal file
59
task/first_recharge.py
Normal file
@ -0,0 +1,59 @@
|
||||
from pymongo import UpdateOne
|
||||
from pydantic import BaseModel, Field, validator
|
||||
import pandas as pd
|
||||
|
||||
from .task import Task
|
||||
from utils import *
|
||||
|
||||
|
||||
class FirstRecharge(Task):
|
||||
"""
|
||||
首次充值记录
|
||||
"""
|
||||
|
||||
class Model(BaseModel):
|
||||
role_level: int = Field(None, title='角色等级')
|
||||
role_vip: int = Field(None, title='vip等级')
|
||||
role_stage: IntStr = Field(None, title='关卡')
|
||||
money: IntFloat = Field(..., title='金额')
|
||||
game_role_id: str = Field(..., title='角色id', alias='_game_role_id')
|
||||
orderid: str = Field(..., title='订单号')
|
||||
proid: str = Field(..., title='计费点')
|
||||
cdate: int = Field(..., title='当天0点')
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls):
|
||||
return [v.alias for v in cls.__fields__.values()]
|
||||
|
||||
def cleaning(self, cursor_list):
|
||||
for cursor in cursor_list: # type:dict
|
||||
for event_coll, ts in cursor.items(): # type:str,dict
|
||||
if ts['cursor_st'] == ts['cursor_et']:
|
||||
continue
|
||||
logger.info(f'开始处理{self.game_name} 处理 {event_coll} 游标 {ts}')
|
||||
where = {
|
||||
'_event_time': {
|
||||
'$gte': ts['cursor_st'],
|
||||
'$lt': ts['cursor_et'],
|
||||
}
|
||||
}
|
||||
|
||||
projection = self.Model.get_fields()
|
||||
bulk_data = []
|
||||
for item in self.local_db[event_coll].find(where, projection):
|
||||
try:
|
||||
item['cdate'] = int(pd.Timestamp(ts['cursor_st'], unit='s', tz=self.timezone) \
|
||||
.normalize().timestamp())
|
||||
model = self.Model(**item)
|
||||
data = model.dict(by_alias=True)
|
||||
_game_role_id = data.pop('_game_role_id')
|
||||
bulk_data.append(
|
||||
UpdateOne({'_game_role_id': _game_role_id, 'is_recharge': {'$exists': False}},
|
||||
{'$set': {'is_recharge': data}}))
|
||||
except Exception as e:
|
||||
logger.error(f'msg:{e}')
|
||||
# pass
|
||||
if bulk_data:
|
||||
self.remote_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
||||
self.local_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
||||
self.set_cursor(cursor_st=ts['cursor_st'], cursor_et=ts['cursor_et'])
|
Loading…
Reference in New Issue
Block a user