可更新事件

This commit is contained in:
wuaho 2021-04-08 15:21:41 +08:00
parent 3ced2a2ba8
commit 1a472956d4
2 changed files with 61 additions and 13 deletions

View File

@ -18,14 +18,14 @@ class TaHandler:
v = data.get(k)
if v is not None:
msg[k] = data.pop(k)
msg['properties'] = data.pop('properties')
if msg['#type'] == 'track':
msg['properties'] = data.pop('properties') # type:dict
if msg['#type'] in ('track', 'track_update'):
msg['properties'].update(data)
if 'event_id' in msg['properties']:
msg['#event_id'] = msg['properties']['event_id']
elif msg['#type'] == 'user':
msg['#type'] = 'user_' + msg['#event_name']
if msg.get('#user_id'):
msg['properties']['#user_id'] = msg['#user_id']
if "#event_name" in msg:
del msg["#event_name"]
if "#event_time" in msg:
@ -61,7 +61,33 @@ async def to_date(request, rdb, data):
@TaHandler
async def device_label(request, rdb, data):
async def order_idx(request, rdb, data):
"""
充值编号
:param request:
:param rdb:
:param data:
:return:
"""
# 条件
if data.get('#type') == 'track_update' and data.get('#event_name') == 'order_event':
# key = $appid.$binduid.orders v : order_id
order_complete_time = data.get('properties', {}).get('order_complete_time')
event_id = data.get('properties', {}).get('event_id')
order_id = data.get('properties', {}).get("order_id")
account_id = data.get('#account_id')
if order_complete_time and account_id and order_id and event_id:
del data['properties']['order_id']
key = f'{data["#app_id"]}_{account_id}_orders'
v = await rdb.execute('sadd', key, order_id)
# 订单 编号
if v == 1:
data['properties']['order_num'] = await rdb.execute('scard', key)
@TaHandler
async def role_idx(request, rdb, data):
"""
标记新设备
:param request:
@ -70,9 +96,31 @@ async def device_label(request, rdb, data):
:return:
"""
# 条件
if data.get('#type') == 'user' and data.get('#event_name') == 'add':
v = await rdb.execute('sadd', f'{data["#app_id"]}.devices', data.get('#device_id', ''))
if v:
data['properties']['is_new_device'] = 1
else:
data['properties']['is_new_device'] = 0
if data.get('#type') == 'user' and data.get('#event_name') == 'setOnce':
# key = $appid.$binduid v : uid
binduid = data.get("properties", {}).get("binduid")
account_id = data.get("#account_id")
if binduid and account_id:
key = f'{data["#app_id"]}_{binduid}_roles'
v = await rdb.execute('sadd', key, account_id)
# 新角色 编号
if v == 1:
data['properties']['role_idx'] = await rdb.execute('scard', key)
# @TaHandler
# async def device_label(request, rdb, data):
# """
# 标记新设备
# :param request:
# :param rdb:
# :param data:
# :return:
# """
# # 条件
# if data.get('#type') == 'user' and data.get('#event_name') == 'add':
# v = await rdb.execute('sadd', f'{data["#app_id"]}.devices', data.get('#device_id', ''))
# if v:
# data['properties']['is_new_device'] = 1
# else:
# data['properties']['is_new_device'] = 0

View File

@ -54,7 +54,7 @@ class Config:
"b06": "#event_time"
}
TA_OUTER = {'#time', '#ip', '#type', '#distinct_id', '#account_id', '#event_name'}
TA_OUTER = {'#time', '#ip', '#type', '#distinct_id', '#account_id', '#event_name','#event_id'}
REDIS_CONF = {
'address': ('192.168.0.161', 6379),