|
@@ -1,24 +1,20 @@
|
|
|
-#!/usr/bin/env python3
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-"""
|
|
|
-@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
-@AUTHOR: ASJRD018
|
|
|
-@NAME: AnsjerFormal
|
|
|
-@software: PyCharm
|
|
|
-@DATE: 2020/2/27 9:38
|
|
|
-@Version: python3.6
|
|
|
-@MODIFY DECORD:ansjer dev
|
|
|
-@file: AppSetController.py
|
|
|
-@Contact: chanjunkai@163.com
|
|
|
-"""
|
|
|
-from Ansjer.config import SERVER_TYPE
|
|
|
-from Model.models import AppSetModel, PromotionRuleModel, PopupsConfig, RedDotsConfig
|
|
|
+import json
|
|
|
+import logging
|
|
|
+import time
|
|
|
+
|
|
|
+from django.db import transaction
|
|
|
from django.views.generic.base import View
|
|
|
+
|
|
|
+from Ansjer.config import SERVER_TYPE
|
|
|
+from Model.models import AppSetModel, PromotionRuleModel, PopupsConfig, RedDotsConfig, Device_Info, UidSetModel, \
|
|
|
+ UserOperationLog, Order_Model
|
|
|
from Object.RedisObject import RedisObject
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
|
from Service.ModelService import ModelService
|
|
|
-import time, json
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
+
|
|
|
+LOGGER = logging.getLogger('info')
|
|
|
|
|
|
|
|
|
class AppSetView(View):
|
|
@@ -36,34 +32,32 @@ class AppSetView(View):
|
|
|
response = ResponseObject()
|
|
|
if operation == 'query':
|
|
|
return self.do_query(request_dict, response)
|
|
|
- if operation == 'admin_query':
|
|
|
- token = request_dict.get('token', None)
|
|
|
- tko = TokenObject(token)
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- return self.do_admin_query(userID, request_dict, response)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ user_id = tko.userID
|
|
|
+ if operation == 'page_set': # app弹窗标记红点设置
|
|
|
+ return self.do_page_set(user_id, request_dict, response)
|
|
|
+ elif operation == 'ai-preview':
|
|
|
+ return self.save_user_popups_log(user_id, request_dict, response)
|
|
|
+ elif operation == 'admin_query':
|
|
|
+ return self.do_admin_query(user_id, request_dict, response)
|
|
|
elif operation == 'admin_update':
|
|
|
- token = request_dict.get('token', None)
|
|
|
- tko = TokenObject(token)
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- return self.do_admin_update(userID, request_dict, response)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ return self.do_admin_update(user_id, request_dict, response)
|
|
|
else:
|
|
|
- token = request_dict.get('token', None)
|
|
|
- tko = TokenObject(token)
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if operation == 'page_set': # app弹窗标记红点设置
|
|
|
- return self.do_page_set(userID, request_dict, response)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
-
|
|
|
- # 查询
|
|
|
- def do_query(self, request_dict, response):
|
|
|
+ return response.json(414)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def do_query(request_dict, response):
|
|
|
+ """
|
|
|
+ 查询app配置
|
|
|
+ @param request_dict: 请求数据
|
|
|
+ @request_dict lang: 语言
|
|
|
+ @request_dict appBundleId: app包id
|
|
|
+ @param response: 响应
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
lang = request_dict.get('lang', None)
|
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
|
if not appBundleId:
|
|
@@ -72,6 +66,7 @@ class AppSetView(View):
|
|
|
app_set_qs = AppSetModel.objects.filter(appBundleId=appBundleId).values('content')
|
|
|
if not app_set_qs.exists():
|
|
|
return response.json(173)
|
|
|
+
|
|
|
try:
|
|
|
if not app_set_qs[0]['content']:
|
|
|
return response.json(0)
|
|
@@ -85,39 +80,17 @@ class AppSetView(View):
|
|
|
dict_json['popupsContent'] = json.loads(promotion[0]['popups']).get(lang, '')
|
|
|
dict_json['nowTime'] = int(time.time())
|
|
|
if 'editionUpgrading' in dict_json:
|
|
|
+ dict_json['editionUpgrading'] = ''
|
|
|
if dict_json['editionUpgrading'] == 1:
|
|
|
if lang == 'cn':
|
|
|
dict_json['editionUpgrading'] = '正在升级,请稍后登录'
|
|
|
else:
|
|
|
dict_json['editionUpgrading'] = 'Upgrading, please sign in later'
|
|
|
- else:
|
|
|
- dict_json['editionUpgrading'] = ''
|
|
|
-
|
|
|
return response.json(0, dict_json)
|
|
|
except Exception as e:
|
|
|
- return response.json(500, "错误行数:{errLine}, 错误信息: {errmsg}".format(errLine=e.__traceback__.tb_lineno,
|
|
|
+ return response.json(500, '错误行数:{errLine}, 错误信息: {errmsg}'.format(errLine=e.__traceback__.tb_lineno,
|
|
|
errmsg=repr(e)))
|
|
|
|
|
|
- # res = {}
|
|
|
- # res['grade'] = 1
|
|
|
- # # # 用户帮助
|
|
|
- # res['usingHelp'] = 0
|
|
|
- # # # AP添加方式
|
|
|
- # res['apAdd'] = 1
|
|
|
- # # # AP工具
|
|
|
- # res['apTool'] = 1
|
|
|
- # # # 广告模块
|
|
|
- # res['ad_module'] = {
|
|
|
- # "time": 0,
|
|
|
- # "ad_path": [
|
|
|
- # "https://test.dvema.com/web/static/image/default_ad1",
|
|
|
- # "https://test.dvema.com/web/static/image/default_ad2",
|
|
|
- # "https://test.dvema.com/web/static/image/default_ad3",
|
|
|
- # ]
|
|
|
- # }
|
|
|
- # res['init_img'] = 'https://test.dvema.com/web/static/image/default_start'
|
|
|
- # return response.json(0, res)
|
|
|
-
|
|
|
def do_admin_query(self, userID, request_dict, response):
|
|
|
# 查询和添加权限
|
|
|
own_perm = ModelService.check_perm(userID, 40)
|
|
@@ -159,42 +132,144 @@ class AppSetView(View):
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
|
|
|
- def do_page_set(self, userID, request_dict, response):
|
|
|
- lang = request_dict.get('lang', 'en')
|
|
|
- dict_json = {}
|
|
|
- now_time = int(time.time())
|
|
|
- dict_json['popups'] = {
|
|
|
- 'title': '',
|
|
|
- 'content': '',
|
|
|
- 'status': 0,
|
|
|
- 'tag': 1,
|
|
|
- }
|
|
|
- #弹窗
|
|
|
- popups_obj = PopupsConfig.objects.filter(lang=lang).values('title','content','start_time','end_time','tag')
|
|
|
- if popups_obj.exists():
|
|
|
- popups_status = 0
|
|
|
- if now_time >= popups_obj[0]['start_time'] and now_time <= popups_obj[0]['end_time']:
|
|
|
- popups_status = 1
|
|
|
+ @staticmethod
|
|
|
+ def do_page_set(userID, request_dict, response):
|
|
|
+ """
|
|
|
+ 初始化加载红点以及弹窗数据
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
+ dict_json = {}
|
|
|
+ now_time = int(time.time())
|
|
|
dict_json['popups'] = {
|
|
|
- 'title': popups_obj[0]['title'],
|
|
|
- 'content': popups_obj[0]['content'],
|
|
|
- 'status': popups_status,
|
|
|
- 'tag': popups_obj[0]['tag'],
|
|
|
+ 'title': '',
|
|
|
+ 'content': '',
|
|
|
+ 'status': 0,
|
|
|
+ 'tag': 1,
|
|
|
}
|
|
|
+ with transaction.atomic():
|
|
|
+ # AI弹窗
|
|
|
+ dict_json['aiPopups'] = AppSetView.get_ai_init_data(userID, lang)
|
|
|
+ # 弹窗
|
|
|
+ popups_obj = PopupsConfig.objects.filter(lang=lang).values('title', 'content', 'start_time', 'end_time',
|
|
|
+ 'tag')
|
|
|
+ if popups_obj.exists():
|
|
|
+ popups_status = 0
|
|
|
+ if popups_obj[0]['start_time'] <= now_time <= popups_obj[0]['end_time']:
|
|
|
+ popups_status = 1
|
|
|
+ dict_json['popups'] = {
|
|
|
+ 'title': popups_obj[0]['title'],
|
|
|
+ 'content': popups_obj[0]['content'],
|
|
|
+ 'status': popups_status,
|
|
|
+ 'tag': popups_obj[0]['tag'],
|
|
|
+ }
|
|
|
+ # 红点标记
|
|
|
+ dict_json['red_dots'] = []
|
|
|
+ red_dots_obj = RedDotsConfig.objects.values('module', 'start_time', 'end_time')
|
|
|
+ is_show_red_dots = AppSetView.check_user_is_show_red_dot(userID) # 是否显示红点
|
|
|
+ for red_dots in red_dots_obj:
|
|
|
+ red_dots_status = 0
|
|
|
+ if red_dots['start_time'] <= now_time <= red_dots['end_time']:
|
|
|
+ red_dots_status = 1
|
|
|
+ ai_detection = red_dots['module']
|
|
|
+ if ai_detection == 'ai_detects_purchases':
|
|
|
+ red_dots_status = 1 if is_show_red_dots else 0
|
|
|
+ dict_json['red_dots'].append({
|
|
|
+ 'module': red_dots['module'],
|
|
|
+ 'status': red_dots_status,
|
|
|
+ })
|
|
|
+ dict_json['red_dots'] = list(dict_json['red_dots'])
|
|
|
+ return response.json(0, dict_json)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|
|
|
|
|
|
- #红点标记
|
|
|
- dict_json['red_dots'] = []
|
|
|
- red_dots_obj = RedDotsConfig.objects.values('module','start_time','end_time')
|
|
|
- for red_dots in red_dots_obj:
|
|
|
- red_dots_status = 0
|
|
|
- if now_time >= red_dots['start_time'] and now_time <= red_dots['end_time']:
|
|
|
- red_dots_status = 1
|
|
|
- dict_json['red_dots'].append({
|
|
|
- 'module': red_dots['module'],
|
|
|
- 'status': red_dots_status,
|
|
|
- })
|
|
|
+ @staticmethod
|
|
|
+ def get_ai_init_data(user_id, lang):
|
|
|
+ """
|
|
|
+ 初始化获取AI弹窗数据
|
|
|
+ @param user_id: 用户id
|
|
|
+ @param lang: 语言
|
|
|
+ @return: popups_qs
|
|
|
+ """
|
|
|
+ now_time = int(time.time())
|
|
|
+ popups_qs = PopupsConfig.objects.filter(tag=2, lang=lang) \
|
|
|
+ .values('title', 'content', 'start_time', 'end_time', 'tag')
|
|
|
+ if not popups_qs.exists():
|
|
|
+ return ''
|
|
|
+ ai_device = AppSetView.get_user_ai_device(user_id)
|
|
|
+ if not ai_device:
|
|
|
+ return ''
|
|
|
+ # 当前时间小于弹窗开始时间或者大于结束时间 则返回空字符串
|
|
|
+ if not popups_qs[0]['start_time'] <= now_time <= popups_qs[0]['end_time']:
|
|
|
+ return ''
|
|
|
+ user_ai_log_qs = UserOperationLog.objects.filter(user_id=user_id, type=2).values('created_time')
|
|
|
+ user_log = {'user_id': user_id, 'status': 1, 'type': 2, 'created_time': now_time, 'updated_time': now_time}
|
|
|
+ popups_status = 0
|
|
|
+ # 用户有AI设备 没有操作过弹窗则显示
|
|
|
+ if not user_ai_log_qs.exists():
|
|
|
+ popups_status = 1
|
|
|
+ UserOperationLog.objects.create(**user_log)
|
|
|
+ else:
|
|
|
+ now_date = int(LocalDateTimeUtil.time_stamp_to_time(now_time, '%Y%m%d'))
|
|
|
+ created_date = int(LocalDateTimeUtil.time_stamp_to_time(user_ai_log_qs[0]['created_time'], '%Y%m%d'))
|
|
|
+ if user_ai_log_qs.count() == 1 and now_date > created_date:
|
|
|
+ popups_status = 1
|
|
|
+ UserOperationLog.objects.create(**user_log)
|
|
|
+ return {
|
|
|
+ 'title': popups_qs[0]['title'],
|
|
|
+ 'content': popups_qs[0]['content'],
|
|
|
+ 'status': popups_status,
|
|
|
+ 'tag': popups_qs[0]['tag'],
|
|
|
+ }
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def get_user_ai_device(user_id):
|
|
|
+ """
|
|
|
+ 获取用户设备是否有有支持AI功能
|
|
|
+ @param user_id: 用户ID
|
|
|
+ @return: True|False
|
|
|
+ """
|
|
|
+ device_info = Device_Info.objects.filter(userID_id=user_id, isExist=1).values('UID')
|
|
|
+ if not device_info.exists():
|
|
|
+ return False
|
|
|
+ uid_list = []
|
|
|
+ for item in device_info:
|
|
|
+ uid_list.append(item['UID'])
|
|
|
+ uid_info_qs = UidSetModel.objects.filter(uid__in=uid_list).values('is_ai')
|
|
|
+ if not uid_info_qs.exists():
|
|
|
+ return False
|
|
|
+ if 1 or 0 in uid_info_qs:
|
|
|
+ return True
|
|
|
+ return False
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def check_user_is_show_red_dot(user_id):
|
|
|
+ """
|
|
|
+ 获取用户是否显示红点
|
|
|
+ 用户体验过AI免费套餐不显示 OR 用户操作记录阅读过AI介绍界面不显示
|
|
|
+ @param user_id: 用户ID
|
|
|
+ @return: True | False
|
|
|
+ """
|
|
|
+ order_qs = Order_Model.objects.filter(userID_id=user_id, order_type=2, status=1, payType=10)
|
|
|
+ ai_red_dot_qs = UserOperationLog.objects.filter(user_id=user_id, type=4)
|
|
|
+ return not ai_red_dot_qs.exists() and not order_qs.exists()
|
|
|
|
|
|
- dict_json['red_dots'] = list(dict_json['red_dots'])
|
|
|
- return response.json(0, dict_json)
|
|
|
+ @classmethod
|
|
|
+ def save_user_popups_log(cls, user_id, request_dict, response):
|
|
|
+ """
|
|
|
+ 保存用户预览AI介绍页面记录
|
|
|
+ @param request_dict: type
|
|
|
+ @param user_id: 用户id
|
|
|
+ @param response: 响应对象
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ rq_type = request_dict.get('type', 0)
|
|
|
+ now_time = int(time.time())
|
|
|
+ user_log = {'user_id': user_id, 'status': 1, 'type': int(rq_type), 'created_time': now_time,
|
|
|
+ 'updated_time': now_time}
|
|
|
+ UserOperationLog.objects.create(**user_log)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|
|
|
+ return response.json(0)
|