|
@@ -30,11 +30,13 @@ 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, VodHlsTagType, UidSetModel, AiService, \
|
|
|
- StsFrequency, InAppPurchasePackage, CouponCombo, CouponConfigModel
|
|
|
+ StsFrequency, InAppPurchasePackage, CouponCombo, CouponConfigModel, DeviceApplePackage
|
|
|
from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.AliPayObject import AliPayObject
|
|
|
from Object.AliSmsObject import AliSmsObject
|
|
|
+from Object.AppleInAppPurchaseSubscriptionObject import InAppPurchase
|
|
|
+from Object.Enums.RedisKeyConstant import RedisKeyConstant
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -271,7 +273,9 @@ class CloudStorageView(View):
|
|
|
coupon_qs = '' if not user_id else CloudServiceController.get_user_coupon_list(user_id)
|
|
|
for area, items in groupby(store_list, key=itemgetter('bucket__area')):
|
|
|
items_list = list(items)
|
|
|
- for item in items_list:
|
|
|
+ # 使用倒序遍历避免remove()操作导致索引错乱
|
|
|
+ for i in range(len(items_list) - 1, -1, -1):
|
|
|
+ item = items_list[i]
|
|
|
pay_type_qs = Pay_Type.objects.filter(store_meal=item['id']).values("id", "payment")
|
|
|
item['pay_type'] = list(pay_type_qs)
|
|
|
item['is_pay_cycle'] = 1 if item['cycle_config_id'] else 0
|
|
@@ -294,7 +298,6 @@ class CloudStorageView(View):
|
|
|
coupon_config_qs = CouponConfigModel.objects.filter(id__in=coupon_combo_ids)
|
|
|
if coupon_config_qs.exists():
|
|
|
items_list.remove(item)
|
|
|
-
|
|
|
res_c = {'area': area, 'items': items_list}
|
|
|
res.append(res_c)
|
|
|
# 是否促销
|
|
@@ -1289,7 +1292,7 @@ class CloudStorageView(View):
|
|
|
|
|
|
now_time = int(time.time())
|
|
|
store_qs = Store_Meal.objects.filter(id=rank, pay_type=pay_type, lang__lang=lang, is_show=0). \
|
|
|
- values('currency', 'price', 'lang__content', 'day', 'commodity_type', 'lang__title', 'expire',
|
|
|
+ values('id', 'currency', 'price', 'lang__content', 'day', 'commodity_type', 'lang__title', 'expire',
|
|
|
'commodity_code', 'discount_price', 'bucket__mold', 'cycle_config_id', 'is_ai')
|
|
|
if not store_qs.exists():
|
|
|
return response.json(173)
|
|
@@ -1461,15 +1464,77 @@ class CloudStorageView(View):
|
|
|
elif pay_type == 5:
|
|
|
# 内购订阅型订单 之前订阅过任意套餐返回不可再次订阅
|
|
|
if store_qs[0]['cycle_config_id']:
|
|
|
- return response.json(173)
|
|
|
+ # 检查Paypal订阅
|
|
|
+ check_subscribe_Paypal = Paypal.checkSubscriptions(user_id, uid, rank, app_type)
|
|
|
+ # 查设备是否有绑定套餐
|
|
|
+ device_apple_package_qs = DeviceApplePackage.objects.filter(userID=user_id, uid=uid).values(
|
|
|
+ "package_id__product_id", "package_id__subscription_group_id")
|
|
|
+ if device_apple_package_qs.exists():
|
|
|
+ product_id = device_apple_package_qs[0]["package_id__product_id"]
|
|
|
+ subscription_group_id = device_apple_package_qs[0]["package_id__subscription_group_id"]
|
|
|
+
|
|
|
+ # 检查内购订阅
|
|
|
+ bundle_id = "com.ansjer.zccloud"
|
|
|
+ if app_type == 2:
|
|
|
+ bundle_id = "com.cloudlife.commissionf"
|
|
|
+ in_app_subscription = InAppPurchase(bundle_id=bundle_id)
|
|
|
+ check_subscribe_InApp = in_app_subscription.check_subscriptions(uid, subscription_group_id)
|
|
|
+
|
|
|
+ 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).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(rank_id=rank).values("product_id")[0]["product_id"]
|
|
|
+ in_app_purchase_qs = InAppPurchasePackage.objects.filter(rank_id=rank).values("product_id", "is_coupon")
|
|
|
+ product_id = in_app_purchase_qs[0]["product_id"]
|
|
|
+ is_coupon = in_app_purchase_qs[0]["is_coupon"]
|
|
|
+ # 判断是否为优惠订单锁优惠券
|
|
|
+ if is_coupon:
|
|
|
+ coupon_combo_qs = CouponCombo.objects.filter(combo_id=store_qs[0]['id']).values("coupon_id")
|
|
|
+ coupon_ids = CouponModel.objects.filter(userID=user_id, use_status=0,
|
|
|
+ coupon_config__id=coupon_combo_qs[0]["coupon_id"],
|
|
|
+ valid_time__gte=now_time).values_list("id", flat=True)
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ for c_id in coupon_ids:
|
|
|
+ key_coupon = f"{RedisKeyConstant.COUPON_ID_LOCK.value}{c_id}"
|
|
|
+ coupon_lock = redis_obj.get_data(key_coupon)
|
|
|
+ if not coupon_lock:
|
|
|
+ redis_obj.set_data(key_coupon, 1, 60)
|
|
|
+ coupon_id = c_id
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ return response.json(5)
|
|
|
|
|
|
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)
|
|
|
+ commodity_type=commodity_type, rank_id=rank, ai_rank_id=1, store_meal_name=store_meal_name,
|
|
|
+ app_type=app_type, coupon_id=coupon_id
|
|
|
+ )
|
|
|
return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
|
'result': {"orderID": order_id, "productId": product_id},
|
|
|
'error_code': 0})
|