|
@@ -1,12 +1,20 @@
|
|
|
-import time
|
|
|
import json
|
|
|
-from Ansjer.config import SERVER_TYPE
|
|
|
-from Model.models import AppSetModel, PromotionRuleModel, PopupsConfig, RedDotsConfig
|
|
|
+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
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
+
|
|
|
+LOGGER = logging.getLogger('info')
|
|
|
|
|
|
|
|
|
class AppSetView(View):
|
|
@@ -122,42 +130,124 @@ 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_detection':
|
|
|
+ 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)
|
|
|
+ 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
|
|
|
|
|
|
- dict_json['red_dots'] = list(dict_json['red_dots'])
|
|
|
- return response.json(0, dict_json)
|
|
|
+ @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()
|