| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 | 
							- #!/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
 
- from django.views.generic.base import View
 
- from Object.RedisObject import RedisObject
 
- from Object.TokenObject import TokenObject
 
- from Service.ModelService import ModelService
 
- import time, json
 
- from Object.ResponseObject import ResponseObject
 
- class AppSetView(View):
 
-     def get(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation', None)
 
-         return self.validation(request.GET, operation)
 
-     def post(self, request, *args, **kwargs):
 
-         request.encoding = 'utf-8'
 
-         operation = kwargs.get('operation', None)
 
-         return self.validation(request.POST, operation)
 
-     def validation(self, request_dict, operation):
 
-         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)
 
-         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)
 
-         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):
 
-         lang = request_dict.get('lang', None)
 
-         appBundleId = request_dict.get('appBundleId', None)
 
-         if not appBundleId:
 
-             return response.json(444, 'appBundleId')
 
-         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)
 
-             dict_json = json.loads(app_set_qs[0]['content'])
 
-             # 加入促销弹窗
 
-             promotion = PromotionRuleModel.objects.filter(status=1).values('startTime', 'endTime', 'popups')
 
-             if promotion.exists():
 
-                 dict_json['popupsStartTime'] = promotion[0]['startTime']
 
-                 dict_json['popupsEndTime'] = promotion[0]['endTime']
 
-                 dict_json['popupsContent'] = json.loads(promotion[0]['popups']).get(lang, '')
 
-                 dict_json['nowTime'] = int(time.time())
 
-             if 'editionUpgrading' in dict_json:
 
-                 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,
 
-                                                                               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)
 
-         if not own_perm:
 
-             return response.json(404)
 
-         appBundleId = request_dict.get('appBundleId', None)
 
-         sm_qs = AppSetModel.objects.filter(appBundleId=appBundleId)
 
-         count = sm_qs.count()
 
-         nowTime = int(time.time())
 
-         if count > 0:
 
-             sm_qs = sm_qs.values('id', 'appBundleId', 'content', 'addTime', 'updTime')
 
-             return response.json(0, {'data': list(sm_qs), 'count': count})
 
-         else:
 
-             AppSetModel.objects.create(
 
-                 appBundleId=appBundleId,
 
-                 addTime=nowTime,
 
-                 updTime=nowTime
 
-             )
 
-             return response.json(0)
 
-     def do_admin_update(self, userID, request_dict, response):
 
-         # 修改的权限
 
-         own_perm = ModelService.check_perm(userID, 50)
 
-         if not own_perm:
 
-             return response.json(404)
 
-         appBundleId = request_dict.get('appBundleId', None)
 
-         content = request_dict.get('content', None)
 
-         nowTime = int(time.time())
 
-         sm_qs = AppSetModel.objects.filter(appBundleId=appBundleId)
 
-         redis = RedisObject()
 
-         if SERVER_TYPE != "Ansjer.formal_settings":
 
-             key_id = "www" + appBundleId
 
-         else:
 
-             key_id = "test" + appBundleId
 
-         redis.del_data(key=key_id)
 
-         if sm_qs.exists():
 
-             sm_qs.update(content=content, updTime=nowTime)
 
-             return response.json(0)
 
-         else:
 
-             return response.json(173)
 
-     def do_page_set(self, userID, request_dict, response):
 
-         dict_json = {}
 
-         # 弹窗 后续根据数据库配置
 
-         dict_json['popups'] = {
 
-             'title': '20% off',
 
-             'content': 'on Cloud Storage Subscription',
 
-             # 'start_time': 1653275226,
 
-             # 'end_time': 1753275226,
 
-             'status': 1,
 
-             'tag': 1,
 
-         }
 
-         dict_json['now_time'] = int(time.time())
 
-         # 红点标记 后续根据数据库配置
 
-         dict_json['red_dots'] = [
 
-             {
 
-                 'module': 'cloud_storage',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,  # 跳转页面,1:云存储购 2:AI购买 3:优惠券
 
-             },
 
-             {
 
-                 'module': 'ai_detection',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'coupon',
 
-                 'status': 1,
 
-                 # 'start_time': 1653275226,
 
-                 # 'end_time': '1753275226',
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'add',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'setting',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'my',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'cloud_storage_purchases',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-             {
 
-                 'module': 'ai_detects_purchases',
 
-                 'status': 0,
 
-                 # 'start_time': 0,
 
-                 # 'end_time': 0,
 
-                 'tag': 1,
 
-             },
 
-         ]
 
-         dict_json['red_dots'] = list(dict_json['red_dots'])
 
-         return response.json(0, dict_json)
 
 
  |