parent
abbe709d27
commit
9d3b5c582e
@ -0,0 +1,54 @@ |
||||
# Generated by Django 3.2.3 on 2021-10-29 18:59 |
||||
|
||||
from django.conf import settings |
||||
from django.db import migrations, models |
||||
import django.db.models.deletion |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
dependencies = [ |
||||
('api', '0014_alter_useraddisplayinfo_unique_together'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='RemoteClientInfo', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('remote_addr', models.GenericIPAddressField(verbose_name='远程IP地址')), |
||||
('user_agent', models.CharField(max_length=512, verbose_name='客户端agent')), |
||||
('method', models.CharField(max_length=16, verbose_name='请求方式')), |
||||
('uri_info', models.CharField(max_length=256, verbose_name='访问的URI')), |
||||
('a_domain', models.CharField(max_length=128, verbose_name='前端域名')), |
||||
('description', models.CharField(max_length=256, verbose_name='访问描述')), |
||||
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='访问时间')), |
||||
], |
||||
options={ |
||||
'verbose_name': '客户端访问记录', |
||||
'verbose_name_plural': '客户端访问记录', |
||||
}, |
||||
), |
||||
migrations.CreateModel( |
||||
name='IosDeveloperPublicPoolBill', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('action', models.SmallIntegerField(choices=[(0, '消费'), (1, '充值'), (2, '转账')], default=0, |
||||
help_text='0 消费 1 充值 2 转账', verbose_name='资金类型')), |
||||
('number', models.IntegerField(default=1, verbose_name='消耗次数')), |
||||
('app_info', models.JSONField(blank=True, max_length=256, null=True, verbose_name='属于哪个APP')), |
||||
('udid_info', models.JSONField(blank=True, max_length=256, null=True, verbose_name='设备id信息')), |
||||
('developer_info', models.JSONField(blank=True, max_length=256, null=True, verbose_name='开发者信息')), |
||||
('description', models.CharField(blank=True, default='', max_length=128, verbose_name='操作描述')), |
||||
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='添加时间')), |
||||
('to_user_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, |
||||
related_name='to_user_id', to=settings.AUTH_USER_MODEL, |
||||
verbose_name='用户ID')), |
||||
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='org_user_id', |
||||
to=settings.AUTH_USER_MODEL, verbose_name='用户ID')), |
||||
], |
||||
options={ |
||||
'verbose_name': '资金流转账单', |
||||
'verbose_name_plural': '资金流转账单', |
||||
}, |
||||
), |
||||
] |
@ -1,27 +0,0 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding:utf-8 -*- |
||||
# project: 3月 |
||||
# author: liuyu |
||||
# date: 2020/3/6 |
||||
import uuid |
||||
|
||||
|
||||
def make_from_user_uuid(userinfo): |
||||
user_id = userinfo.uid |
||||
random_str = uuid.uuid1().__str__().split("-")[0:-1] |
||||
user_ran_str = uuid.uuid5(uuid.NAMESPACE_DNS, user_id).__str__().split("-") |
||||
user_ran_str.extend(random_str) |
||||
new_str = "".join(user_ran_str) |
||||
return new_str |
||||
|
||||
|
||||
def make_app_uuid(userinfo, bundleid): |
||||
user_id = userinfo.uid |
||||
app_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, "%s" % (user_id + bundleid)).__str__().split("-") |
||||
fapp_uuid = "".join(app_uuid) |
||||
return fapp_uuid |
||||
|
||||
|
||||
def make_random_uuid(): |
||||
random_str = uuid.uuid1().__str__().split("-") |
||||
return "".join(random_str) |
@ -0,0 +1,122 @@ |
||||
#!/usr/bin/env python |
||||
# -*- coding:utf-8 -*- |
||||
# project: 4月 |
||||
# author: NinEveN |
||||
# date: 2021/4/16 |
||||
|
||||
|
||||
from django.db.models import Count |
||||
import random |
||||
from api.models import AppReleaseInfo, UserDomainInfo, DomainCnameInfo, UserAdDisplayInfo, RemoteClientInfo |
||||
import logging |
||||
from urllib.parse import urljoin |
||||
|
||||
from api.utils.baseutils import get_server_domain_from_request, get_user_default_domain_name, get_real_ip_address, \ |
||||
get_origin_domain_name |
||||
|
||||
logger = logging.getLogger(__name__) |
||||
|
||||
|
||||
def get_app_d_count_by_app_id(app_id): |
||||
d_count = 1 |
||||
binary_size = AppReleaseInfo.objects.filter(is_master=True, app_id__app_id=app_id).values('binary_size').first() |
||||
if binary_size and binary_size.get('binary_size', 0) > 0: |
||||
d_count += binary_size.get('binary_size') // 1024 // 1024 // 100 |
||||
return d_count |
||||
|
||||
|
||||
def get_user_domain_name(obj, domain_type=1): |
||||
domain_name = UserDomainInfo.objects.filter(user_id=obj, is_enable=True, app_id=None, |
||||
domain_type=domain_type).values_list('domain_name').first() |
||||
if domain_name: |
||||
return domain_name[0] |
||||
return '' |
||||
|
||||
|
||||
def get_app_domain_name(obj): |
||||
domain_name = UserDomainInfo.objects.filter(app_id=obj, is_enable=True, domain_type=2).values_list( |
||||
'domain_name').first() |
||||
if domain_name: |
||||
return domain_name[0] |
||||
return '' |
||||
|
||||
|
||||
def get_min_default_domain_cname_obj(is_system=True): |
||||
return min(DomainCnameInfo.objects.annotate(Count('userinfo')).filter(is_enable=True, is_system=is_system), |
||||
key=lambda x: x.userinfo__count) |
||||
|
||||
|
||||
def get_filename_form_file(filename): |
||||
file_id_list = filename.split('.') |
||||
if file_id_list[-1] in ['ipa', 'apk']: |
||||
app_release_obj = AppReleaseInfo.objects.filter(release_id='.'.join(file_id_list[0:-1])).first() |
||||
if app_release_obj: |
||||
app_obj = app_release_obj.app_id |
||||
if app_obj.type == 0: |
||||
f_type = '.apk' |
||||
else: |
||||
f_type = '.ipa' |
||||
return f"{app_obj.name}-{app_release_obj.app_version}-{app_obj.short}{f_type}" |
||||
return filename |
||||
|
||||
|
||||
def ad_random_weight(user_obj): |
||||
ad_info_list = UserAdDisplayInfo.objects.filter(user_id=user_obj, is_enable=True).order_by('-created_time') |
||||
total = sum([ad_info.weight for ad_info in ad_info_list]) # 权重求和 |
||||
ra = random.uniform(0, total) # 在0与权重和之前获取一个随机数 |
||||
curr_sum = 0 |
||||
ret = ad_info_list.first() |
||||
for ad_info in ad_info_list: |
||||
curr_sum += ad_info.weight # 在遍历中,累加当前权重值 |
||||
if ra <= curr_sum: # 当随机数<=当前权重和时,返回权重key |
||||
ret = ad_info |
||||
break |
||||
return ret |
||||
|
||||
|
||||
def add_remote_info_from_request(request, description): |
||||
meta_info = request.META |
||||
remote_info = { |
||||
'user_agent': meta_info.get('HTTP_USER_AGENT'), |
||||
'remote_addr': get_real_ip_address(request), |
||||
'method': meta_info.get('REQUEST_METHOD'), |
||||
'uri_info': urljoin(meta_info.get('PATH_INFO'), meta_info.get('QUERY_STRING')), |
||||
'a_domain': get_origin_domain_name(request), |
||||
'description': description |
||||
} |
||||
RemoteClientInfo.objects.create(**remote_info) |
||||
|
||||
|
||||
def get_redirect_server_domain(request, user_obj=None, app_domain_name=None): |
||||
is_https = False |
||||
if user_obj: |
||||
if app_domain_name and len(app_domain_name) > 3: |
||||
domain_name = app_domain_name |
||||
else: |
||||
domain_name = get_user_domain_name(user_obj) |
||||
if not domain_name: |
||||
is_https, domain_name = get_user_default_domain_name(user_obj.default_domain_name) |
||||
elif app_domain_name and len(app_domain_name) > 3: |
||||
domain_name = app_domain_name |
||||
else: |
||||
is_https, domain_name = get_user_default_domain_name(get_min_default_domain_cname_obj(True)) |
||||
protocol = 'http' |
||||
if is_https: |
||||
protocol = 'https' |
||||
server_domain = "%s://%s" % (protocol, domain_name) |
||||
return get_server_domain_from_request(request, server_domain) |
||||
|
||||
|
||||
def check_app_domain_name_access(app_obj, access_domain_name, user_obj, extra_domain=None): |
||||
if app_obj and access_domain_name: |
||||
domain_list = [] |
||||
if extra_domain: |
||||
domain_list.append(extra_domain) |
||||
app_domain_name = get_app_domain_name(app_obj) |
||||
if app_domain_name: domain_list.append(app_domain_name) |
||||
user_domain_name = get_user_domain_name(user_obj) |
||||
if user_domain_name: domain_list.append(user_domain_name) |
||||
user_qr_domain_name = get_user_domain_name(user_obj, 0) |
||||
if user_qr_domain_name: domain_list.append(user_qr_domain_name) |
||||
if access_domain_name in domain_list: |
||||
return True |
Loading…
Reference in new issue