|
@@ -2,28 +2,25 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
import datetime
|
|
|
import hashlib
|
|
|
-import json
|
|
|
import time
|
|
|
-import urllib
|
|
|
import uuid
|
|
|
-import boto3
|
|
|
-import threading
|
|
|
-import logging
|
|
|
|
|
|
+import xlrd
|
|
|
import xlwt
|
|
|
-from boto3.session import Session
|
|
|
-from django.db import transaction
|
|
|
-from django.http import JsonResponse, HttpResponseRedirect, HttpResponse, StreamingHttpResponse
|
|
|
-from django.views.generic.base import View
|
|
|
+import calendar
|
|
|
|
|
|
-from Controller.Cron.CronTaskController import CronUpdateDataView
|
|
|
-from Model.models import Device_Info, Role, MenuModel, VodBucketModel, CDKcontextModel, Store_Meal, Order_Model, \
|
|
|
- UID_Bucket, ExperienceContextModel, Lang, Device_User, CloudLogModel, UidSetModel, Unused_Uid_Meal, VodHlsModel
|
|
|
+from django.db import transaction, connection
|
|
|
+from django.utils.encoding import escape_uri_path
|
|
|
+from django.http import HttpResponse, StreamingHttpResponse
|
|
|
+from django.views.generic.base import View
|
|
|
+from Model.models import VodBucketModel, CDKcontextModel, Store_Meal, Order_Model, \
|
|
|
+ UID_Bucket, ExperienceContextModel, Lang, CloudLogModel, UidSetModel, Unused_Uid_Meal, \
|
|
|
+ Device_Info, DeviceTypeModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
-from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from django.db.models import F, Sum, Count
|
|
|
+from Controller.Cron.CronTaskController import CronUpdateDataView
|
|
|
|
|
|
|
|
|
class serveManagement(View):
|
|
@@ -44,6 +41,8 @@ class serveManagement(View):
|
|
|
return self.exportCloudUserList(request_dict, response)
|
|
|
elif operation == 'getCloudDataList':
|
|
|
return self.getCloudDataList(request_dict, response)
|
|
|
+ elif operation == 'vodOrderReconcile':
|
|
|
+ return self.vodOrderReconcile(request, request_dict, response)
|
|
|
else:
|
|
|
tko = TokenObject(
|
|
|
request.META.get('HTTP_AUTHORIZATION'),
|
|
@@ -123,7 +122,7 @@ class serveManagement(View):
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
try:
|
|
|
- if bucket or mold or is_free: # 条件查询
|
|
|
+ if bucket or mold or is_free: # 条件查询
|
|
|
if bucket:
|
|
|
vod_bucket_qs = VodBucketModel.objects.filter(
|
|
|
bucket=bucket)
|
|
@@ -133,7 +132,7 @@ class serveManagement(View):
|
|
|
elif is_free:
|
|
|
vod_bucket_qs = VodBucketModel.objects.filter(
|
|
|
is_free=int(is_free))
|
|
|
- else: # 查询全部
|
|
|
+ else: # 查询全部
|
|
|
vod_bucket_qs = VodBucketModel.objects.filter().all()
|
|
|
total = len(vod_bucket_qs)
|
|
|
vod_buckets = vod_bucket_qs[(page - 1) * line:page * line]
|
|
@@ -164,7 +163,7 @@ class serveManagement(View):
|
|
|
# 添加/编辑存储桶
|
|
|
print('request_dict: ', request_dict)
|
|
|
bucketID = request_dict.get('bucketID', None)
|
|
|
- bucket = request_dict.get('bucket', '').strip() # 移除字符串头尾的空格
|
|
|
+ bucket = request_dict.get('bucket', '').strip() # 移除字符串头尾的空格
|
|
|
content = request_dict.get('content', '').strip()
|
|
|
mold = int(request_dict.get('mold', 1))
|
|
|
area = request_dict.get('area', '').strip()
|
|
@@ -240,12 +239,12 @@ class serveManagement(View):
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
try:
|
|
|
- if bucket: # 条件查询
|
|
|
+ if bucket: # 条件查询
|
|
|
bucket_id = VodBucketModel.objects.filter(
|
|
|
bucket=bucket).values('id')[0]['id']
|
|
|
store_meal_qs = Store_Meal.objects.filter(
|
|
|
bucket_id=bucket_id)
|
|
|
- else: # 查询全部
|
|
|
+ else: # 查询全部
|
|
|
store_meal_qs = Store_Meal.objects.filter()
|
|
|
store_meal_val = store_meal_qs.values(
|
|
|
'id',
|
|
@@ -307,7 +306,7 @@ class serveManagement(View):
|
|
|
commodity_type = int(request_dict.get('commodity_type', 0))
|
|
|
pay_type = request_dict.get(
|
|
|
'pay_type', '')[
|
|
|
- 1:-1].split(',') # '[1,2]' -> ['1','2']
|
|
|
+ 1:-1].split(',') # '[1,2]' -> ['1','2']
|
|
|
commodity_code = request_dict.get('commodity_code', '')
|
|
|
is_discounts = int(request_dict.get('is_discounts', 0))
|
|
|
discount_price = request_dict.get('discount_price', '')
|
|
@@ -379,9 +378,9 @@ class serveManagement(View):
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
try:
|
|
|
- if storeMealID: # 条件查询
|
|
|
+ if storeMealID: # 条件查询
|
|
|
store_meal_lang_qs = Store_Meal.objects.filter(id=storeMealID)
|
|
|
- else: # 查询全部
|
|
|
+ else: # 查询全部
|
|
|
store_meal_lang_qs = Store_Meal.objects.filter(
|
|
|
lang__isnull=False)
|
|
|
store_meal_lang_val = store_meal_lang_qs.values(
|
|
@@ -394,7 +393,7 @@ class serveManagement(View):
|
|
|
)
|
|
|
total = len(store_meal_lang_val)
|
|
|
store_meal_langs = store_meal_lang_val[(
|
|
|
- page - 1) * line:page * line]
|
|
|
+ page - 1) * line:page * line]
|
|
|
store_meal_lang_list = []
|
|
|
for store_meal_lang in store_meal_langs:
|
|
|
store_meal_lang_list.append({
|
|
@@ -440,7 +439,7 @@ class serveManagement(View):
|
|
|
title=title,
|
|
|
content=content,
|
|
|
discount_content=discount_content)
|
|
|
- else: # 添加
|
|
|
+ else: # 添加
|
|
|
lang_obj = Lang.objects.filter(
|
|
|
lang=lang,
|
|
|
title=title,
|
|
@@ -583,11 +582,13 @@ class serveManagement(View):
|
|
|
if region == 'cn':
|
|
|
# 下载国内未使用激活码
|
|
|
content += '激活码(国内)\n'
|
|
|
- cdk_inactivate_qs = CDKcontextModel.objects.filter(is_down=0, is_activate=0, rank__bucket__mold=0, rank__is_show=0).values('cdk')
|
|
|
+ cdk_inactivate_qs = CDKcontextModel.objects.filter(is_down=0, is_activate=0, rank__bucket__mold=0,
|
|
|
+ rank__is_show=0).values('cdk')
|
|
|
else:
|
|
|
# 下载国外未使用激活码
|
|
|
content += '激活码(国外)\n'
|
|
|
- cdk_inactivate_qs = CDKcontextModel.objects.filter(is_down=0, is_activate=0, rank__bucket__mold=1, rank__is_show=0).values('cdk')
|
|
|
+ cdk_inactivate_qs = CDKcontextModel.objects.filter(is_down=0, is_activate=0, rank__bucket__mold=1,
|
|
|
+ rank__is_show=0).values('cdk')
|
|
|
for cdk_inactivate in cdk_inactivate_qs:
|
|
|
content += cdk_inactivate['cdk'] + '\n'
|
|
|
# print(content)
|
|
@@ -645,30 +646,165 @@ class serveManagement(View):
|
|
|
if not omqs.exists():
|
|
|
return response.json(0, [])
|
|
|
|
|
|
+ order_list = []
|
|
|
count = omqs.count()
|
|
|
|
|
|
- order_ql = omqs.values(
|
|
|
- "orderID",
|
|
|
- "UID",
|
|
|
- "userID__username",
|
|
|
- "userID__NickName",
|
|
|
- "channel",
|
|
|
- "desc",
|
|
|
- "price",
|
|
|
- "refunded_amount",
|
|
|
- "currency",
|
|
|
- "addTime",
|
|
|
- "updTime",
|
|
|
- "paypal",
|
|
|
- "payType",
|
|
|
- "rank__day",
|
|
|
- "rank__price",
|
|
|
- "status",
|
|
|
- "order_type")
|
|
|
+ order_ql = omqs.values("orderID", "UID", "userID__username", "userID__NickName", "channel", "desc", "price",
|
|
|
+ "refunded_amount", "currency", "addTime", "updTime", "paypal", "payType",
|
|
|
+ "rank__day", "rank__price", "status", "order_type")
|
|
|
order_ql = order_ql.order_by('-addTime') # 根据CDK创建时间降序排序
|
|
|
order_ql = order_ql[(page - 1) * line:page * line]
|
|
|
+ for order in order_ql:
|
|
|
+ data = {
|
|
|
+ 'orderID': order['orderID'],
|
|
|
+ 'UID': order['UID'],
|
|
|
+ 'userID__username': order['userID__username'],
|
|
|
+ 'userID__NickName': order['userID__NickName'],
|
|
|
+ 'channel': order['channel'],
|
|
|
+ 'desc': order['desc'],
|
|
|
+ 'price': order['price'],
|
|
|
+ 'refunded_amount': order['refunded_amount'],
|
|
|
+ 'currency': order['currency'],
|
|
|
+ 'addTime': order['addTime'],
|
|
|
+ 'updTime': order['updTime'],
|
|
|
+ 'paypal': order['paypal'],
|
|
|
+ 'payType': order['payType'],
|
|
|
+ 'rank__day': order['rank__day'],
|
|
|
+ 'rank__price': order['rank__price'],
|
|
|
+ 'status': order['status'],
|
|
|
+ 'order_type': order['order_type'],
|
|
|
+ }
|
|
|
+ # 添加设备套餐使用状态
|
|
|
+ uid = order['UID']
|
|
|
+ uid_bucket = UID_Bucket.objects.filter(uid=uid).values('use_status')
|
|
|
+ user_status = uid_bucket[0]['use_status'] if uid_bucket.exists() else ''
|
|
|
+ if user_status != '':
|
|
|
+ data['user_status'] = user_status
|
|
|
+ else:
|
|
|
+ data['user_status'] = 2
|
|
|
+ order_list.append(data)
|
|
|
return response.json(
|
|
|
- 0, {'list': list(order_ql), 'total': count})
|
|
|
+ 0, {'list': order_list, 'total': count})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ def vodOrderReconcile(self, request, request_dict, response):
|
|
|
+
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
+ if not all([file]):
|
|
|
+ return response.json(444, {'error param': 'file'})
|
|
|
+
|
|
|
+ try:
|
|
|
+ rd_book = xlrd.open_workbook(filename=None, file_contents=file.read())
|
|
|
+ rd_sheet = rd_book.sheet_by_index(0)
|
|
|
+ date = rd_sheet.cell_value(1, 0)
|
|
|
+ month = int(date.split('/')[0])
|
|
|
+ year = int(date.split('/')[2])
|
|
|
+ last_day = calendar.monthrange(year, month)[1]
|
|
|
+ start_time = datetime.datetime(year, month, 1)
|
|
|
+ end_time = datetime.datetime(year, month, last_day) + datetime.timedelta(hours=24)
|
|
|
+ start_time = CommonService.str_to_timestamp(start_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
+ end_time = CommonService.str_to_timestamp(end_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
+ wt_book = xlwt.Workbook(encoding='utf-8')
|
|
|
+ wt_sheet = wt_book.add_sheet('对账结果', cell_overwrite_ok=True)
|
|
|
+ row_start = 0
|
|
|
+ # 第一部分表格填写
|
|
|
+ first_header = ['支付类型', '销售总金额', '销售总数量', '退款总额', '退款总数量', '应收金额', '平台手续费', '账务实收', '金额相差']
|
|
|
+ for index, content in enumerate(first_header):
|
|
|
+ wt_sheet.write(row_start, index, content)
|
|
|
+ row_start += 1
|
|
|
+ all_order_qs = Order_Model.objects.filter(addTime__gte=start_time, addTime__lt=end_time,
|
|
|
+ status__in=[1, 5, 6])
|
|
|
+ trade_no_list = []
|
|
|
+ paid_order_qs = all_order_qs.filter(status=1)
|
|
|
+ for i in paid_order_qs:
|
|
|
+ if i.trade_no not in rd_sheet.col_values(9, 1):
|
|
|
+ trade_no_list.append(i.trade_no)
|
|
|
+
|
|
|
+ # 已付款订单
|
|
|
+ paid = all_order_qs.filter(payType=1, status=1).aggregate(total=Sum('price'),
|
|
|
+ count=Count('UID'))
|
|
|
+ paid_total = paid['total'] if paid['total'] else 0
|
|
|
+ paid_count = paid['count'] if paid['count'] else 0
|
|
|
+ # 全额退款订单
|
|
|
+ refund = all_order_qs.filter(payType=1, status__in=[5, 6]).aggregate(total=Sum('refunded_amount'),
|
|
|
+ count=Count('UID'))
|
|
|
+ refund_total = refund['total'] if refund['total'] else 0
|
|
|
+ refund_count = refund['count'] if refund['count'] else 0
|
|
|
+ wt_sheet.write(row_start, 0, 'PayPal')
|
|
|
+ wt_sheet.write(row_start, 1, paid_total + refund_total)
|
|
|
+ wt_sheet.write(row_start, 2, paid_count + refund_count)
|
|
|
+ wt_sheet.write(row_start, 3, refund_total)
|
|
|
+ wt_sheet.write(row_start, 4, refund_count)
|
|
|
+ wt_sheet.write(row_start, 5, paid_total)
|
|
|
+ wt_sheet.write(row_start, 8, label=xlwt.Formula('f{row}-h{row}+g{row}'.format(row=row_start + 1)))
|
|
|
+ row_start += 1
|
|
|
+ # 第二部分表格填写
|
|
|
+ row_start += 2
|
|
|
+ paypal_money = 0
|
|
|
+ fee_money = 0
|
|
|
+ for row in range(rd_sheet.nrows):
|
|
|
+ if row == 0:
|
|
|
+ wt_sheet.write(row_start, 0, '是否匹配账单')
|
|
|
+ for col in range(rd_sheet.ncols):
|
|
|
+ value = rd_sheet.cell_value(row, col)
|
|
|
+ temp_col = col + 1
|
|
|
+ wt_sheet.write(row_start, temp_col, str(value))
|
|
|
+ row_start += 1
|
|
|
+ continue
|
|
|
+ if rd_sheet.cell_value(row, 0) == '合计':
|
|
|
+ break
|
|
|
+ paypal_money += rd_sheet.cell_value(row, 7)
|
|
|
+ fee_money += rd_sheet.cell_value(row, 6)
|
|
|
+ transaction_id = rd_sheet.cell_value(row, 9)
|
|
|
+ order_qs = all_order_qs.filter(trade_no=transaction_id)
|
|
|
+ if not order_qs.exists():
|
|
|
+ col_value_list = rd_sheet.row_values(row)
|
|
|
+ col_value_list.insert(0, '否')
|
|
|
+ for index, value in enumerate(col_value_list):
|
|
|
+ wt_sheet.write(row_start, index, str(value))
|
|
|
+ row_start += 1
|
|
|
+
|
|
|
+ # 第三部分表格填写
|
|
|
+ row_start += 1
|
|
|
+ third_header = ['是否匹配账单', '交易ID', '订单ID', '设备UID', '用户名', '账号昵称', '通道', '商品描述', '支付方式', '价格', '支付状态',
|
|
|
+ '已退金额', '添加时间', '更新时间']
|
|
|
+ diff_order_qs = all_order_qs.filter(trade_no__in=trade_no_list).values('trade_no', 'orderID', 'UID',
|
|
|
+ 'userID__username',
|
|
|
+ 'userID__NickName', 'channel',
|
|
|
+ 'desc', 'payType',
|
|
|
+ 'price', 'status',
|
|
|
+ 'refunded_amount', 'addTime',
|
|
|
+ 'updTime')
|
|
|
+ for index, content in enumerate(third_header):
|
|
|
+ wt_sheet.write(row_start, index, content)
|
|
|
+ row_start += 1
|
|
|
+ for item in diff_order_qs:
|
|
|
+ values_list = item.values()
|
|
|
+ for col, content in enumerate(values_list):
|
|
|
+ if col == 0:
|
|
|
+ wt_sheet.write(row_start, col, '否')
|
|
|
+ if col == 7:
|
|
|
+ content = 'PayPal'
|
|
|
+ if col == 9:
|
|
|
+ if content == 1:
|
|
|
+ content = '支付成功'
|
|
|
+ elif content == 5:
|
|
|
+ content = '全额退款'
|
|
|
+ elif content == 6:
|
|
|
+ content = '部分退款'
|
|
|
+ if col in [11, 12]:
|
|
|
+ content = CommonService.timestamp_to_str(int(content))
|
|
|
+ wt_sheet.write(row_start, col + 1, str(content))
|
|
|
+ row_start += 1
|
|
|
+ wt_sheet.write(1, 6, fee_money)
|
|
|
+ wt_sheet.write(1, 7, paypal_money)
|
|
|
+
|
|
|
+ res = HttpResponse(content_type='application/vnd.ms-excel')
|
|
|
+ res['Content-Disposition'] = 'attachment; filename={}'.format(escape_uri_path(file.name))
|
|
|
+ wt_book.save(res)
|
|
|
+ return res
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
@@ -857,16 +993,16 @@ class serveManagement(View):
|
|
|
for uid_bucket in uid_bucket_qs:
|
|
|
for order in order_qs.filter(
|
|
|
uid_bucket_id=uid_bucket.id).values(
|
|
|
- 'uid_bucket_id',
|
|
|
- 'desc',
|
|
|
- 'userID__userID',
|
|
|
- 'UID',
|
|
|
- 'price',
|
|
|
- 'payType',
|
|
|
- 'userID__username',
|
|
|
- 'userID__phone',
|
|
|
- 'userID__userEmail',
|
|
|
- 'userID__data_joined'):
|
|
|
+ 'uid_bucket_id',
|
|
|
+ 'desc',
|
|
|
+ 'userID__userID',
|
|
|
+ 'UID',
|
|
|
+ 'price',
|
|
|
+ 'payType',
|
|
|
+ 'userID__username',
|
|
|
+ 'userID__phone',
|
|
|
+ 'userID__userEmail',
|
|
|
+ 'userID__data_joined'):
|
|
|
# 套餐到期时间累加未使用套餐
|
|
|
unused_qs = Unused_Uid_Meal.objects.filter(uid=uid_bucket.uid).values('num', 'expire')
|
|
|
if unused_qs.exists():
|
|
@@ -936,7 +1072,7 @@ class serveManagement(View):
|
|
|
userEmail = request_dict.get('userEmail', None)
|
|
|
payType = request_dict.get('payType', None)
|
|
|
|
|
|
- #uid_set 表查询
|
|
|
+ # uid_set 表查询
|
|
|
ucode = request_dict.getlist('ucode', None)
|
|
|
version = request_dict.getlist('version', None)
|
|
|
|
|
@@ -1030,16 +1166,16 @@ class serveManagement(View):
|
|
|
|
|
|
for order in order_qs.filter(
|
|
|
uid_bucket_id=uid_bucket.id).values(
|
|
|
- 'uid_bucket_id',
|
|
|
- 'desc',
|
|
|
- 'userID__userID',
|
|
|
- 'UID',
|
|
|
- 'price',
|
|
|
- 'payType',
|
|
|
- 'userID__username',
|
|
|
- 'userID__phone',
|
|
|
- 'userID__userEmail',
|
|
|
- 'userID__data_joined'):
|
|
|
+ 'uid_bucket_id',
|
|
|
+ 'desc',
|
|
|
+ 'userID__userID',
|
|
|
+ 'UID',
|
|
|
+ 'price',
|
|
|
+ 'payType',
|
|
|
+ 'userID__username',
|
|
|
+ 'userID__phone',
|
|
|
+ 'userID__userEmail',
|
|
|
+ 'userID__data_joined'):
|
|
|
data['desc'] = order['desc']
|
|
|
data['payType'] = order['payType']
|
|
|
data['price'] = order['price']
|
|
@@ -1053,8 +1189,8 @@ class serveManagement(View):
|
|
|
|
|
|
for uidset in uidset_qs.filter(
|
|
|
uid=uid_bucket.uid).values(
|
|
|
- 'ucode',
|
|
|
- 'version'):
|
|
|
+ 'ucode',
|
|
|
+ 'version'):
|
|
|
data['ucode'] = uidset['ucode']
|
|
|
data['version'] = uidset['version']
|
|
|
|
|
@@ -1066,49 +1202,49 @@ class serveManagement(View):
|
|
|
sheet1 = workbook.add_sheet('UID')
|
|
|
|
|
|
headtitle = [
|
|
|
- 'id',
|
|
|
- '用户账号',
|
|
|
- '用户手机号',
|
|
|
- '用户邮箱',
|
|
|
- '注册时间',
|
|
|
- '设备UID',
|
|
|
- '设备通道',
|
|
|
- '云存状态',
|
|
|
- '添加时间',
|
|
|
- '到期时间',
|
|
|
- '使用状态',
|
|
|
- '是否有未使用套餐',
|
|
|
- '套餐描述',
|
|
|
- '支付方式',
|
|
|
- '价格',
|
|
|
- '播放次数',
|
|
|
- '产品编码',
|
|
|
- '版本'
|
|
|
+ 'id',
|
|
|
+ '用户账号',
|
|
|
+ '用户手机号',
|
|
|
+ '用户邮箱',
|
|
|
+ '注册时间',
|
|
|
+ '设备UID',
|
|
|
+ '设备通道',
|
|
|
+ '云存状态',
|
|
|
+ '添加时间',
|
|
|
+ '到期时间',
|
|
|
+ '使用状态',
|
|
|
+ '是否有未使用套餐',
|
|
|
+ '套餐描述',
|
|
|
+ '支付方式',
|
|
|
+ '价格',
|
|
|
+ '播放次数',
|
|
|
+ '产品编码',
|
|
|
+ '版本'
|
|
|
]
|
|
|
headnum = 0
|
|
|
for title in headtitle:
|
|
|
sheet1.write(0, headnum, title)
|
|
|
- headnum= headnum+1
|
|
|
+ headnum = headnum + 1
|
|
|
|
|
|
fields = [
|
|
|
- 'id',
|
|
|
- 'username',
|
|
|
- 'phone',
|
|
|
- 'userEmail',
|
|
|
- 'data_joined',
|
|
|
- 'uid',
|
|
|
- 'channel',
|
|
|
- 'status',
|
|
|
- 'addTime',
|
|
|
- 'endTime',
|
|
|
- 'use_status',
|
|
|
- 'has_unused',
|
|
|
- 'desc',
|
|
|
- 'payType',
|
|
|
- 'price',
|
|
|
- 'playcount',
|
|
|
- 'ucode',
|
|
|
- 'version'
|
|
|
+ 'id',
|
|
|
+ 'username',
|
|
|
+ 'phone',
|
|
|
+ 'userEmail',
|
|
|
+ 'data_joined',
|
|
|
+ 'uid',
|
|
|
+ 'channel',
|
|
|
+ 'status',
|
|
|
+ 'addTime',
|
|
|
+ 'endTime',
|
|
|
+ 'use_status',
|
|
|
+ 'has_unused',
|
|
|
+ 'desc',
|
|
|
+ 'payType',
|
|
|
+ 'price',
|
|
|
+ 'playcount',
|
|
|
+ 'ucode',
|
|
|
+ 'version'
|
|
|
]
|
|
|
num = 1
|
|
|
for item in list_data:
|
|
@@ -1128,8 +1264,8 @@ class serveManagement(View):
|
|
|
val = '激活码'
|
|
|
|
|
|
sheet1.write(num, fieldnum, val)
|
|
|
- fieldnum = fieldnum+1
|
|
|
- num =num+1
|
|
|
+ fieldnum = fieldnum + 1
|
|
|
+ num = num + 1
|
|
|
workbook.save(response)
|
|
|
return response
|
|
|
except Exception as e:
|
|
@@ -1150,7 +1286,7 @@ class serveManagement(View):
|
|
|
Oct = int(time.mktime(time.strptime(year + '-10-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
Nov = int(time.mktime(time.strptime(year + '-11-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
Dec = int(time.mktime(time.strptime(year + '-12-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
- Jan_next = int(time.mktime(time.strptime(str(int(year)+1) + '-1-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Jan_next = int(time.mktime(time.strptime(str(int(year) + 1) + '-1-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
|
|
|
list_data = []
|
|
|
vod_bucket_qs = VodBucketModel.objects.filter()
|
|
@@ -1159,10 +1295,11 @@ class serveManagement(View):
|
|
|
try:
|
|
|
for vod_bucket in vod_bucket_qs:
|
|
|
vod_bucket_id = vod_bucket.id
|
|
|
- store_meal = Store_Meal.objects.filter(bucket_id=vod_bucket_id, lang__lang='cn').values('lang__title', 'lang__content')
|
|
|
+ store_meal = Store_Meal.objects.filter(bucket_id=vod_bucket_id, lang__lang='cn').values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
if not store_meal.exists():
|
|
|
continue
|
|
|
- name = store_meal[0]['lang__title']+'-'+store_meal[0]['lang__content']
|
|
|
+ name = store_meal[0]['lang__title'] + '-' + store_meal[0]['lang__content']
|
|
|
order = Order_Model.objects.filter(rank__bucket_id=vod_bucket_id)
|
|
|
Jan_count = order.filter(status=1, addTime__range=[Jan, Feb]).count()
|
|
|
Feb_count = order.filter(status=1, addTime__range=[Feb, Mar]).count()
|
|
@@ -1176,7 +1313,8 @@ class serveManagement(View):
|
|
|
Oct_count = order.filter(status=1, addTime__range=[Oct, Nov]).count()
|
|
|
Nov_count = order.filter(status=1, addTime__range=[Nov, Dec]).count()
|
|
|
Dec_count = order.filter(status=1, addTime__range=[Dec, Jan_next]).count()
|
|
|
- data = [Jan_count, Feb_count, Mar_count, Apr_count, May_count, Jun_count, Jul_count, Aug_count, Sep_count,
|
|
|
+ data = [Jan_count, Feb_count, Mar_count, Apr_count, May_count, Jun_count, Jul_count, Aug_count,
|
|
|
+ Sep_count,
|
|
|
Oct_count, Nov_count, Dec_count]
|
|
|
|
|
|
cloud_data = {
|
|
@@ -1197,113 +1335,103 @@ class serveManagement(View):
|
|
|
流失预警界面
|
|
|
@param request_dict:
|
|
|
@param response:
|
|
|
+ @param userName:用户名
|
|
|
+ @param uid:设备uid
|
|
|
+ @param grade:预警等级
|
|
|
"""
|
|
|
+ userName = request_dict.get('userName', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ grade = request_dict.get('grade', None)
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
- use_status = request_dict.get('use_status', None)
|
|
|
- if not all([pageNo, pageSize]):
|
|
|
+ if not all({pageNo, pageSize}):
|
|
|
return response.json(444)
|
|
|
+ # 获取云存套餐信息表内的设备uid
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
- nowTime = int(time.time())
|
|
|
- attrition_list = []
|
|
|
- r = 0
|
|
|
- uid_buncket_qs = UID_Bucket.objects.filter(status=0).values('use_status', 'uid', 'endTime', 'addTime',
|
|
|
- 'use_status').annotate(count=Count('uid')).order_by(
|
|
|
- '-addTime')
|
|
|
- if use_status:
|
|
|
- uid_buncket_qs = uid_buncket_qs.filter(use_status=use_status)
|
|
|
- count = uid_buncket_qs.count()
|
|
|
- uid_buncket_qs = uid_buncket_qs[(page - 1) * line:page * line]
|
|
|
+ para_list = [userName, uid, grade]
|
|
|
+ not_upload_list = []
|
|
|
+ para_count = para_list.count(None)
|
|
|
try:
|
|
|
- for uid_buncket in uid_buncket_qs:
|
|
|
- day = 0
|
|
|
- endTime = uid_buncket['endTime']
|
|
|
- addTime = uid_buncket['addTime']
|
|
|
- start_time = addTime
|
|
|
- start_time = datetime.datetime.fromtimestamp(int(start_time))
|
|
|
- r += 1
|
|
|
- if r > 1:
|
|
|
- nowTime = str(nowTime)
|
|
|
- time_tuple = time.strptime(nowTime, ('%Y-%m-%d %H:%M:%S'))
|
|
|
- nowTime = time.mktime(time_tuple) # 把格式化好的时间转换成时间戳
|
|
|
- nowTime = datetime.datetime.fromtimestamp(int(nowTime))
|
|
|
- time_list = CommonService.cutting_time(start_time, nowTime, 'day')
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid=uid_buncket['uid']).values('uid')
|
|
|
- # 获取自云存开通起没有上传数据天数
|
|
|
- for date in time_list:
|
|
|
- vod_hls_qs = vod_hls_qs.filter(time__gte=date[0], time__lt=date[1])
|
|
|
- if not vod_hls_qs.exists():
|
|
|
- day += 1
|
|
|
- if day > 29:
|
|
|
- break
|
|
|
- day = day
|
|
|
- level = ''
|
|
|
- use_status = uid_buncket['use_status']
|
|
|
- if not use_status == 1:
|
|
|
- level = '八号预警'
|
|
|
+ # 筛选数据
|
|
|
+ cursor = connection.cursor()
|
|
|
+ sql = "SELECT t1.userID_id, du.username, t1.uid, t1.addTime, t1.use_status, t1.`day`, t1.grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day`, t1.grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day`,(CASE WHEN t1.`day` >= '15' AND t1.`day` < '25' THEN '一号预警' WHEN t1.use_status = '1' AND t1.`day` >= '25' THEN '二号预警' WHEN t1.use_status = 2 AND t1.`day` >= '25' THEN '八号预警' ELSE '预警取消' END ) AS grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day` FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, TIMESTAMPDIFF(DAY,FROM_UNIXTIME(t1.addTime, '%Y-%m-%d' ),DATE_FORMAT( NOW(), '%Y-%m-%d' )) AS 'day' FROM (SELECT di.userID_id, vub.uid, vub.addTime, vub.use_status FROM vod_uid_bucket AS vub, device_info AS di WHERE vub.uid = di.UID AND vub.addTime > '1669824000' GROUP BY di.userID_id) AS t1 WHERE t1.uid NOT IN (SELECT uid FROM uid_cloud_storage_count)) AS t1 WHERE t1.`day`>='15' AND t1.userID_id is NOT NULL) AS t1 ORDER BY t1.userID_id)AS t1 WHERE t1.userID_id NOT IN (SELECT di.userID_id FROM `uid_cloud_storage_count` AS vcsc LEFT JOIN device_info AS di ON vcsc.uid = di.UID WHERE di.userID_id is NOT NULL))AS t1 LEFT JOIN device_user AS du ON t1.userID_id = du.userID"
|
|
|
+ cursor.execute(sql)
|
|
|
+ uid_type_tuple = cursor.fetchall()
|
|
|
+ total = len(uid_type_tuple)
|
|
|
+ cursor.close() # 执行完,关闭
|
|
|
+ connection.close()
|
|
|
+ result_list = []
|
|
|
+ more_list = [] # 多个参数筛查结果
|
|
|
+ new_list = [] # 单独一个参数筛查结果
|
|
|
+ col_names = [desc[0] for desc in cursor.description]
|
|
|
+ for uid_type in uid_type_tuple:
|
|
|
+ uid_dict = dict(zip(col_names, uid_type))
|
|
|
+ result_list.append(uid_dict)
|
|
|
+ if para_count != 2 and para_count != 3: # 两个及以上参数进行筛查
|
|
|
+ if userName and uid and grade == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['uid'] == uid:
|
|
|
+ more_list.append(result)
|
|
|
+ if userName and grade and uid == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ if uid and grade and userName == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['uid'] == uid and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ if userName and uid and grade:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['uid'] == uid and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ result_list = more_list[(page - 1) * line:page * line]
|
|
|
+ if para_count == 2: # 一个参数进行筛查
|
|
|
+ if userName:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName:
|
|
|
+ new_list.append(result)
|
|
|
+ if uid:
|
|
|
+ for result in result_list:
|
|
|
+ if result['uid'] == uid:
|
|
|
+ new_list.append(result)
|
|
|
+ if grade:
|
|
|
+ for result in result_list:
|
|
|
+ if result['grade'] == grade:
|
|
|
+ new_list.append(result)
|
|
|
+ result_list = new_list[(page - 1) * line:page * line]
|
|
|
+ else:
|
|
|
+ result_list = result_list[(page - 1) * line:page * line]
|
|
|
+ for item in result_list: # 获取账号下的云存设备数量
|
|
|
+ userID_id = item['userID_id']
|
|
|
+ device_info_qs = Device_Info.objects.filter(userID_id=userID_id).annotate(count=Count('UID')).values(
|
|
|
+ 'UID')
|
|
|
+ count = device_info_qs.count()
|
|
|
+ if count == 1 or count == 0:
|
|
|
+ item['device_number'] = count
|
|
|
else:
|
|
|
- # 统计设备目前未上传天数
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid=uid_buncket['uid']).values('uid')
|
|
|
- if 15 <= day < 25:
|
|
|
- if vod_hls_qs.exists():
|
|
|
- level = '取消预警'
|
|
|
+ device_number = 0
|
|
|
+ for device_info in device_info_qs:
|
|
|
+ uid = device_info['UID']
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode', 'device_type')
|
|
|
+ ucode = uid_set_qs[0]['ucode'] if uid_set_qs.exists() else ''
|
|
|
+ device_type = uid_set_qs[0]['device_type'] if uid_set_qs.exists() else ''
|
|
|
+ if len(ucode) > 4:
|
|
|
+ number = ucode[-4]
|
|
|
else:
|
|
|
- level = '一号预警'
|
|
|
- if day >= 25:
|
|
|
- if vod_hls_qs.exists():
|
|
|
- level = '取消预警'
|
|
|
- else:
|
|
|
- startTime = uid_buncket['addTime'] # 开始时间
|
|
|
- nowTime = str(nowTime)
|
|
|
- time_tuple = time.strptime(nowTime, ('%Y-%m-%d %H:%M:%S'))
|
|
|
- nowTime = time.mktime(time_tuple) # 把格式化好的时间转换成时间戳
|
|
|
- startTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(startTime)) # 开始时间
|
|
|
- nowTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(nowTime)) # 结束时间
|
|
|
- startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S') # 开始时间
|
|
|
- nowTime = datetime.datetime.strptime(nowTime, '%Y-%m-%d %H:%M:%S') # 结束时间
|
|
|
- day = (nowTime - startTime).days
|
|
|
- level = '二号预警'
|
|
|
- device_user = Device_User.objects.filter(device_info__UID=uid_buncket['uid']).values('username',
|
|
|
- 'userID')
|
|
|
- username = device_user[0]['username'] if device_user.exists() else ''
|
|
|
- userID = device_user[0]['userID'] if device_user.exists() else ''
|
|
|
- order_qs = Order_Model.objects.filter(order_type=0, userID=userID).values('UID').annotate(
|
|
|
- count=Count('UID'))
|
|
|
- # 用户设备购买云存数量
|
|
|
- if not order_qs.exists():
|
|
|
- device_count = 0
|
|
|
- else:
|
|
|
- uid_count = order_qs.count()
|
|
|
- if uid_count == 1:
|
|
|
- device_count = 'N/A'
|
|
|
- else:
|
|
|
- device_count = uid_count
|
|
|
- order_uid_list = [order[uid] for order in order_qs for uid in order]
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid__in=order_uid_list).values('uid')
|
|
|
- # 套餐使用期间是否上传过数据
|
|
|
- if vod_hls_qs.exists():
|
|
|
- other = '有'
|
|
|
- else:
|
|
|
- other = '无'
|
|
|
-
|
|
|
- data = {
|
|
|
- 'userID': userID,
|
|
|
- 'uid': uid_buncket['uid'],
|
|
|
- 'endTime': CommonService.timestamp_to_str(endTime),
|
|
|
- 'addTime': CommonService.timestamp_to_str(addTime),
|
|
|
- 'status': uid_buncket['use_status'],
|
|
|
- 'level': level,
|
|
|
- 'day': day,
|
|
|
- 'other': other,
|
|
|
- 'username': username,
|
|
|
- 'count': device_count,
|
|
|
- }
|
|
|
- attrition_list.append(data)
|
|
|
- test_list = [list for list in attrition_list if list['day'] > 14] # 输出15天及以上的数据
|
|
|
- return response.json(0, {'test_list': test_list, 'total': count})
|
|
|
+ continue
|
|
|
+ device_type_qs = DeviceTypeModel.objects.filter(type=device_type).values('model')
|
|
|
+ model = device_type_qs[0]['model'] if device_type_qs.exists() else ''
|
|
|
+ # 判断设备是否为ipc设备和是否支持云存
|
|
|
+ if model == 2 and number in ['4', '5']:
|
|
|
+ device_number += 1
|
|
|
+ item['device_number'] = device_number
|
|
|
+ item['other_device'] = 0
|
|
|
+ not_upload_list.append(item)
|
|
|
+ return response.json(0, {'result_list': not_upload_list, 'total': total})
|
|
|
except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ meg = '异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e))
|
|
|
+ return response.json(500, meg)
|
|
|
|
|
|
def deactivationPackage(self, userID, request_dict, response):
|
|
|
"""
|
|
@@ -1332,17 +1460,16 @@ class serveManagement(View):
|
|
|
if not order_qs.exists():
|
|
|
return response.json(14)
|
|
|
uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, use_status=1).values('has_unused')
|
|
|
- if not uid_bucket_qs.exists():
|
|
|
- return response.json(173)
|
|
|
has_unused = uid_bucket_qs[0]['has_unused'] if uid_bucket_qs.exists() else ''
|
|
|
# 判断套餐是否唯一
|
|
|
- if has_unused == 0:
|
|
|
+ if has_unused == 0:
|
|
|
uid_bucket_qs.update(endTime=nowTime)
|
|
|
CronUpdateDataView.updateUnusedUidBucket(response)
|
|
|
return response.json(0)
|
|
|
# 当设备套餐不唯一时
|
|
|
# 判断停用套餐是否是为未使用套餐
|
|
|
- unused_uid_Meal_qs = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=order_qs[0]['rank__bucket_id'])
|
|
|
+ unused_uid_Meal_qs = Unused_Uid_Meal.objects.filter(uid=uid,
|
|
|
+ bucket_id=order_qs[0]['rank__bucket_id'])
|
|
|
unused_uid_Meal_number = unused_uid_Meal_qs.count()
|
|
|
if unused_uid_Meal_number == 1:
|
|
|
unused_uid_Meal_qs.delete()
|