|
@@ -29,7 +29,8 @@ from Controller.PaymentCycle import Paypal
|
|
|
from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, UID_Bucket, StsCrdModel, \
|
|
|
ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMsgModel, Unused_Uid_Meal, PromotionRuleModel, \
|
|
|
VideoPlaybackTimeModel, CouponModel, VodBucketModel, VodHlsSummary, AiService, UidSetModel, UidPushModel, \
|
|
|
- VodHlsTagType, ICloudStoreMeal, IcloudUseDetails, IcloudService, StsFrequency
|
|
|
+ VodHlsTagType, ICloudStoreMeal, IcloudUseDetails, IcloudService, StsFrequency, DeviceApplePackage, \
|
|
|
+ InAppPurchasePackage
|
|
|
from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.AliPayObject import AliPayObject
|
|
@@ -1673,20 +1674,49 @@ class CloudStorageView(View):
|
|
|
if store_qs[0]['cycle_config_id']:
|
|
|
# 检查Paypal订阅
|
|
|
check_subscribe_Paypal = Paypal.checkSubscriptions(user_id, uid, rank)
|
|
|
- # 检查内购订阅
|
|
|
- in_app_subscription = InAppSubscription()
|
|
|
- check_subscribe_InApp = in_app_subscription.check_subscriptions(uid)
|
|
|
- if not check_subscribe_Paypal or check_subscribe_InApp:
|
|
|
- logger.info(f'设备订阅过套餐Paypal:{not check_subscribe_Paypal}, AppleInApp:{check_subscribe_InApp}')
|
|
|
- return response.json(10050)
|
|
|
+ # 查设备是否有绑定套餐
|
|
|
+ device_apple_package_qs = DeviceApplePackage.objects.filter(userID=user_id, uid=uid).values(
|
|
|
+ "package_id__product_id", "package_id__subscription_group")
|
|
|
+ if device_apple_package_qs.exists():
|
|
|
+ product_id = device_apple_package_qs[0]["package_id__product_id"]
|
|
|
+ subscription_group = device_apple_package_qs[0]["package_id__subscription_group"]
|
|
|
+ # 检查内购订阅
|
|
|
+ in_app_subscription = InAppSubscription()
|
|
|
+ check_subscribe_InApp = in_app_subscription.check_subscriptions(uid, product_id, subscription_group)
|
|
|
+ if not check_subscribe_Paypal or check_subscribe_InApp:
|
|
|
+ logger.info(f'设备订阅过套餐Paypal:{not check_subscribe_Paypal}, AppleInApp:{check_subscribe_InApp}')
|
|
|
+ return response.json(10050)
|
|
|
+ else:
|
|
|
+ # 查询所有符合条件的订阅套餐的 id 列表
|
|
|
+ package_list = InAppPurchasePackage.objects.filter(is_ai=is_ai, package_type=1).values_list("id", flat=True)
|
|
|
+ # 查询用户和设备已绑定的套餐 id 列表
|
|
|
+ bound_packages = DeviceApplePackage.objects.filter(userID=user_id, uid=uid).values_list("package_id", flat=True)
|
|
|
+ # 找到未绑定的套餐 id
|
|
|
+ unbound_packages = set(package_list) - set(bound_packages)
|
|
|
+ if not unbound_packages:
|
|
|
+ return response.json(10050)
|
|
|
+ # 选择一个未绑定的套餐 id
|
|
|
+ package_id = unbound_packages.pop()
|
|
|
+ # 绑定一个套餐
|
|
|
+ DeviceApplePackage.objects.create(
|
|
|
+ userID=user_id,
|
|
|
+ uid=uid,
|
|
|
+ package_id_id=package_id,
|
|
|
+ created_time=int(time.time()),
|
|
|
+ update_time=int(time.time())
|
|
|
+ )
|
|
|
+ product_id = InAppPurchasePackage.objects.filter(id=package_id).values("product_id")[0]["product_id"]
|
|
|
+ else:
|
|
|
+ product_id = InAppPurchasePackage.objects.filter(is_ai=is_ai, package_type=0).values("product_id")[0]["product_id"]
|
|
|
+
|
|
|
Order_Model.objects.create(
|
|
|
orderID=order_id, UID=uid, channel=channel, userID_id=user_id, desc=content, payType=pay_type,
|
|
|
payTime=now_time, price=price, currency=currency, addTime=now_time, updTime=now_time,
|
|
|
isSelectDiscounts=is_select_discount, order_type=order_type, commodity_code=commodity_code,
|
|
|
commodity_type=commodity_type, rank_id=rank, ai_rank_id=1, store_meal_name=store_meal_name)
|
|
|
- return JsonResponse(status=200,
|
|
|
- data={'result_code': 0, 'reason': 'success', 'result': {"orderID": order_id},
|
|
|
- 'error_code': 0})
|
|
|
+ return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
|
+ 'result': {"orderID": order_id, "productId": product_id},
|
|
|
+ 'error_code': 0})
|
|
|
|
|
|
def do_experience_order(self, request_dict, user_id, response): # 生成体验订单
|
|
|
"""
|