|
@@ -12,6 +12,7 @@
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
import os
|
|
|
+import threading
|
|
|
import time
|
|
|
|
|
|
from django.http import HttpResponse
|
|
@@ -19,9 +20,15 @@ from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
-from Model.models import SysMsgModel, Device_Info, Ai_Push_Info
|
|
|
+from Controller.CouponController import CouponView
|
|
|
+from Model.models import SysMsgModel, Device_Info, Ai_Push_Info, UidSetModel, ExperienceContextModel, Order_Model, \
|
|
|
+ UID_Bucket
|
|
|
+from Object.Enums.ConstantEnum import ConstantEnum
|
|
|
+from Object.Enums.RedisKeyConstant import RedisKeyConstant
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService
|
|
|
|
|
|
|
|
@@ -130,4 +137,76 @@ def initMsgFunc(request):
|
|
|
'ai_count': ai_count, # AI消息总数
|
|
|
'uid_reset_count': uid_reset_count, # 复位的设备数量
|
|
|
}
|
|
|
+ # 如果没有发放过云存优惠券,异步发放
|
|
|
+ now_time = int(time.time())
|
|
|
+ start_time, end_time = ConstantEnum.PROMOTION_START_TIME.value, ConstantEnum.PROMOTION_END_TIME.value
|
|
|
+ # 缓存过期时间
|
|
|
+ expire = end_time - now_time
|
|
|
+ if expire > 0:
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ distribute_key = RedisKeyConstant.CLOUD_STORAGE_COUPONS.value + userID
|
|
|
+ is_distributed = redis_obj.get_data(distribute_key)
|
|
|
+ if not is_distributed:
|
|
|
+ thread_kwargs = {
|
|
|
+ 'user_id': userID,
|
|
|
+ 'redis_obj': redis_obj,
|
|
|
+ 'distribute_key': distribute_key,
|
|
|
+ 'expire': expire,
|
|
|
+ 'end_time': end_time
|
|
|
+ }
|
|
|
+ del_push_info_thread = threading.Thread(
|
|
|
+ target=distribute_cloud_storage_coupons,
|
|
|
+ kwargs=thread_kwargs)
|
|
|
+ del_push_info_thread.start()
|
|
|
return response.json(0, res)
|
|
|
+
|
|
|
+
|
|
|
+def distribute_cloud_storage_coupons(user_id, redis_obj, distribute_key, expire, end_time):
|
|
|
+ """
|
|
|
+ 发放云存优惠券
|
|
|
+ 满足条件,用户存在以下三种类型的设备:
|
|
|
+ 1. 未体验云存设备
|
|
|
+ 2. 体验过未购买过
|
|
|
+ 3. 购买过且已过期
|
|
|
+ @param user_id: 用户id
|
|
|
+ @param redis_obj: redis对象
|
|
|
+ @param distribute_key: 发放优惠券缓存key
|
|
|
+ @param expire: distribute_key过期时间
|
|
|
+ @param end_time: 活动结束时间
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ generate_success = False
|
|
|
+ uid_list = Device_Info.objects.filter(userID_id=user_id).values_list('UID', flat=True)
|
|
|
+ if uid_list:
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list).values('uid', 'ucode', 'device_type')
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ for uid_set in uid_set_qs:
|
|
|
+ uid = uid_set['uid']
|
|
|
+ # 判断设备是否支持云存
|
|
|
+ is_cloud_vod = CommonService.is_cloud_device(uid_set['ucode'], uid_set['device_type'])
|
|
|
+ if is_cloud_vod:
|
|
|
+ # 未体验云存
|
|
|
+ experience_qs = ExperienceContextModel.objects.filter(uid=uid, experience_type=0)
|
|
|
+ if not experience_qs.exists():
|
|
|
+ # 发放
|
|
|
+ generate_success = CouponView.generate_coupon_by_user(user_id)
|
|
|
+ else:
|
|
|
+ # 体验过未购买过
|
|
|
+ orders_qs = Order_Model.objects.filter(UID=uid, status=1, payType__in=[1, 4, 5])
|
|
|
+ if not orders_qs.exists():
|
|
|
+ # 发放
|
|
|
+ generate_success = CouponView.generate_coupon_by_user(user_id)
|
|
|
+ else:
|
|
|
+ # 购买过且已过期
|
|
|
+ # 没有未使用套餐,且过期时间在2024-12-29前
|
|
|
+ vod_uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, has_unused=0, endTime__lte=end_time)
|
|
|
+ if vod_uid_bucket_qs.exists():
|
|
|
+ # 发放
|
|
|
+ generate_success = CouponView.generate_coupon_by_user(user_id)
|
|
|
+ if generate_success:
|
|
|
+ redis_obj.set_data(distribute_key, '1', expire)
|
|
|
+ else:
|
|
|
+ redis_obj.set_data(distribute_key, '0', expire)
|
|
|
+ except Exception as e:
|
|
|
+ return
|