|
@@ -188,105 +188,119 @@ class CloudStorageView(View):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
lang = request_dict.get('lang', 'en')
|
|
lang = request_dict.get('lang', 'en')
|
|
is_ai = request_dict.get('is_ai', 0)
|
|
is_ai = request_dict.get('is_ai', 0)
|
|
|
|
+ app_type = request_dict.get('app_type', None)
|
|
if not all([uid]):
|
|
if not all([uid]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
+ # 苹果内购,app_type:1
|
|
|
|
+ is_ios = False
|
|
|
|
+ if app_type is not None:
|
|
|
|
+ if int(app_type) == 1:
|
|
|
|
+ is_ios = True
|
|
is_ai = int(is_ai)
|
|
is_ai = int(is_ai)
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
# DVR/NVR设备暂不返回云存套餐列表
|
|
# DVR/NVR设备暂不返回云存套餐列表
|
|
device_info_qs = Device_Info.objects.filter(Q(UID=uid), Q(Type__lte=4) | Q(Type=10001))
|
|
device_info_qs = Device_Info.objects.filter(Q(UID=uid), Q(Type__lte=4) | Q(Type=10001))
|
|
if device_info_qs.exists():
|
|
if device_info_qs.exists():
|
|
return response.json(0)
|
|
return response.json(0)
|
|
- # 查询设备像素
|
|
|
|
- uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode', 'is_ai')
|
|
|
|
- if not uid_set_qs.exists():
|
|
|
|
- return response.json(173)
|
|
|
|
- ucode = uid_set_qs[0]['ucode']
|
|
|
|
- pixel_level = 1 if ucode and int(ucode[-5]) >= 8 else 0
|
|
|
|
- store_qs = Store_Meal.objects.filter(Q(lang__lang=lang), Q(is_show=0), ~Q(pay_type='11')) # 过滤激活码、隐藏套餐
|
|
|
|
- experience_context_qs = ExperienceContextModel.objects.filter(uid=uid, experience_type=0)
|
|
|
|
-
|
|
|
|
- if mold:
|
|
|
|
- store_qs = store_qs.filter(bucket__mold=mold)
|
|
|
|
-
|
|
|
|
- # 没体验过的设备只返回体验套餐,体验过的不返回体验套餐
|
|
|
|
- if experience_context_qs.exists():
|
|
|
|
- if not is_ai: # 返回云存套餐
|
|
|
|
- store_qs = store_qs.filter(~Q(pay_type='10'), Q(is_ai=0)) # 筛选像素等级
|
|
|
|
- else: # 返回云存+AI套餐
|
|
|
|
|
|
+ try:
|
|
|
|
+ # 查询设备像素
|
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode', 'is_ai')
|
|
|
|
+ if not uid_set_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+ ucode = uid_set_qs[0]['ucode']
|
|
|
|
+ pixel_level = 1 if ucode and int(ucode[-5]) >= 8 else 0
|
|
|
|
+ store_qs = Store_Meal.objects.filter(Q(lang__lang=lang), Q(is_show=0), ~Q(pay_type='11')) # 过滤激活码、隐藏套餐
|
|
|
|
+ experience_context_qs = ExperienceContextModel.objects.filter(uid=uid, experience_type=0)
|
|
|
|
+
|
|
|
|
+ if mold:
|
|
|
|
+ store_qs = store_qs.filter(bucket__mold=mold)
|
|
|
|
+
|
|
|
|
+ # 没体验过的设备只返回体验套餐,体验过的不返回体验套餐
|
|
|
|
+ if experience_context_qs.exists():
|
|
|
|
+ if not is_ai: # 返回云存套餐
|
|
|
|
+ store_qs = store_qs.filter(~Q(pay_type='10'), Q(is_ai=0)) # 筛选像素等级
|
|
|
|
+ else: # 返回云存+AI套餐
|
|
|
|
+ is_ai = uid_set_qs[0]['is_ai']
|
|
|
|
+ is_ai = 1 if is_ai != 2 and CONFIG_INFO != CONFIG_CN else 0 # 国内不支持AI服务
|
|
|
|
+ if not is_ai:
|
|
|
|
+ return response.json(0)
|
|
|
|
+ store_qs = store_qs.filter(~Q(pay_type='10'), Q(is_ai=1)) # 筛选像素等级
|
|
|
|
+
|
|
|
|
+ if CONFIG_INFO != CONFIG_CN: # 国内生产环境不筛选像素 加载所有上架套餐
|
|
|
|
+ store_qs = store_qs.filter(Q(pixel_level=pixel_level))
|
|
|
|
+ else:
|
|
is_ai = uid_set_qs[0]['is_ai']
|
|
is_ai = uid_set_qs[0]['is_ai']
|
|
is_ai = 1 if is_ai != 2 and CONFIG_INFO != CONFIG_CN else 0 # 国内不支持AI服务
|
|
is_ai = 1 if is_ai != 2 and CONFIG_INFO != CONFIG_CN else 0 # 国内不支持AI服务
|
|
- if not is_ai:
|
|
|
|
- return response.json(0)
|
|
|
|
- store_qs = store_qs.filter(~Q(pay_type='10'), Q(is_ai=1)) # 筛选像素等级
|
|
|
|
-
|
|
|
|
- if CONFIG_INFO != CONFIG_CN: # 国内生产环境不筛选像素 加载所有上架套餐
|
|
|
|
- store_qs = store_qs.filter(Q(pixel_level=pixel_level))
|
|
|
|
- else:
|
|
|
|
- is_ai = uid_set_qs[0]['is_ai']
|
|
|
|
- is_ai = 1 if is_ai != 2 and CONFIG_INFO != CONFIG_CN else 0 # 国内不支持AI服务
|
|
|
|
- store_qs = store_qs.filter(pay_type='10') # 体验套餐不区分像素等级
|
|
|
|
-
|
|
|
|
- store_qs = store_qs.annotate(title=F('lang__title'), content=F('lang__content'),
|
|
|
|
- new_title=F('lang__new_title'),
|
|
|
|
- discount_content=F('lang__discount_content'))
|
|
|
|
- store_qs = store_qs.order_by('sort').values("id", "title", "content", "price", "day", "currency",
|
|
|
|
- "bucket__storeDay", "new_title",
|
|
|
|
- "bucket__bucket", "bucket__area", "commodity_code",
|
|
|
|
- "commodity_type", "is_discounts", "virtual_price", "expire",
|
|
|
|
- "discount_price", "discount_content", "symbol", "cycle_config_id")
|
|
|
|
|
|
+ store_qs = store_qs.filter(pay_type='10') # 体验套餐不区分像素等级
|
|
|
|
+
|
|
|
|
+ store_qs = store_qs.annotate(title=F('lang__title'), content=F('lang__content'),
|
|
|
|
+ new_title=F('lang__new_title'),
|
|
|
|
+ discount_content=F('lang__discount_content'))
|
|
|
|
+ if is_ios:
|
|
|
|
+ store_qs = store_qs.order_by('sort').values(
|
|
|
|
+ "id", "title", "content", "price", "day", "currency", "bucket__storeDay", "new_title", "bucket__bucket",
|
|
|
|
+ "bucket__area", "commodity_code", "commodity_type", "is_discounts", "virtual_price", "expire",
|
|
|
|
+ "discount_price", "discount_content", "symbol", "cycle_config_id", "product_id")
|
|
|
|
+ else:
|
|
|
|
+ store_qs = store_qs.order_by('sort').values(
|
|
|
|
+ "id", "title", "content", "price", "day", "currency", "bucket__storeDay", "new_title", "bucket__bucket",
|
|
|
|
+ "bucket__area", "commodity_code", "commodity_type", "is_discounts", "virtual_price", "expire",
|
|
|
|
+ "discount_price", "discount_content", "symbol", "cycle_config_id")
|
|
|
|
|
|
- if not store_qs.exists():
|
|
|
|
- return response.json(0)
|
|
|
|
- store_list = list(store_qs)
|
|
|
|
- store_list.sort(key=itemgetter('bucket__area'))
|
|
|
|
- res = []
|
|
|
|
- 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:
|
|
|
|
- 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
|
|
|
|
- del item['cycle_config_id']
|
|
|
|
- item['isCoupon'] = False if not coupon_qs or not coupon_qs.exists() else \
|
|
|
|
- CloudStorageView.check_user_coupon_is_available(coupon_qs, item['id'])
|
|
|
|
- for each in item['pay_type']:
|
|
|
|
- if each['id'] == 10 and CONFIG_INFO != CONFIG_CN:
|
|
|
|
- if is_ai == 0:
|
|
|
|
- item['content'] = item['new_title'].get('1', '')
|
|
|
|
- elif is_ai == 1:
|
|
|
|
- item['content'] = item['new_title'].get('2', '')
|
|
|
|
- res_c = {'area': area, 'items': items_list}
|
|
|
|
- res.append(res_c)
|
|
|
|
- # 是否促销
|
|
|
|
- promotion_rule_qs = PromotionRuleModel.objects.filter(status=1, startTime__lte=now_time,
|
|
|
|
- endTime__gte=now_time).values('id', 'ruleConfig',
|
|
|
|
- 'ruleName',
|
|
|
|
- 'startTime', 'endTime',
|
|
|
|
- 'ruleDesc')
|
|
|
|
- if promotion_rule_qs.exists():
|
|
|
|
- promotion = {
|
|
|
|
- 'is_promotion': 1,
|
|
|
|
- 'promotionStartTime': promotion_rule_qs[0]['startTime'],
|
|
|
|
- 'promotionEndTime': promotion_rule_qs[0]['endTime'],
|
|
|
|
- 'promotionName': json.loads(promotion_rule_qs[0]['ruleName']).get(lang, ''),
|
|
|
|
- 'promotionDesc': json.loads(promotion_rule_qs[0]['ruleDesc']).get(lang, ''),
|
|
|
|
- 'nowTime': now_time
|
|
|
|
- }
|
|
|
|
- else:
|
|
|
|
- promotion = {
|
|
|
|
- 'is_promotion': 0
|
|
|
|
|
|
+ if not store_qs.exists():
|
|
|
|
+ return response.json(0)
|
|
|
|
+ store_list = list(store_qs)
|
|
|
|
+ store_list.sort(key=itemgetter('bucket__area'))
|
|
|
|
+ res = []
|
|
|
|
+ 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:
|
|
|
|
+ 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
|
|
|
|
+ del item['cycle_config_id']
|
|
|
|
+ item['isCoupon'] = False if not coupon_qs or not coupon_qs.exists() else \
|
|
|
|
+ CloudStorageView.check_user_coupon_is_available(coupon_qs, item['id'])
|
|
|
|
+ for each in item['pay_type']:
|
|
|
|
+ if each['id'] == 10 and CONFIG_INFO != CONFIG_CN:
|
|
|
|
+ if is_ai == 0:
|
|
|
|
+ item['content'] = item['new_title'].get('1', '')
|
|
|
|
+ elif is_ai == 1:
|
|
|
|
+ item['content'] = item['new_title'].get('2', '')
|
|
|
|
+ res_c = {'area': area, 'items': items_list}
|
|
|
|
+ res.append(res_c)
|
|
|
|
+ # 是否促销
|
|
|
|
+ promotion_rule_qs = PromotionRuleModel.objects.filter(status=1, startTime__lte=now_time,
|
|
|
|
+ endTime__gte=now_time).values('id', 'ruleConfig',
|
|
|
|
+ 'ruleName',
|
|
|
|
+ 'startTime', 'endTime',
|
|
|
|
+ 'ruleDesc')
|
|
|
|
+ if promotion_rule_qs.exists():
|
|
|
|
+ promotion = {
|
|
|
|
+ 'is_promotion': 1,
|
|
|
|
+ 'promotionStartTime': promotion_rule_qs[0]['startTime'],
|
|
|
|
+ 'promotionEndTime': promotion_rule_qs[0]['endTime'],
|
|
|
|
+ 'promotionName': json.loads(promotion_rule_qs[0]['ruleName']).get(lang, ''),
|
|
|
|
+ 'promotionDesc': json.loads(promotion_rule_qs[0]['ruleDesc']).get(lang, ''),
|
|
|
|
+ 'nowTime': now_time
|
|
|
|
+ }
|
|
|
|
+ else:
|
|
|
|
+ promotion = {
|
|
|
|
+ 'is_promotion': 0
|
|
|
|
+ }
|
|
|
|
+ result = {
|
|
|
|
+ 'meals': res,
|
|
|
|
+ 'extra':
|
|
|
|
+ {
|
|
|
|
+ 'cloud_banner': SERVER_DOMAIN + 'web/images/cloud_cn_banner.png',
|
|
|
|
+ 'cloud_en_baner': SERVER_DOMAIN_SSL + 'web/images/cloud_en_banner.png'
|
|
|
|
+ },
|
|
|
|
+ 'promotion': promotion,
|
|
}
|
|
}
|
|
- result = {
|
|
|
|
- 'meals': res,
|
|
|
|
- 'extra':
|
|
|
|
- {
|
|
|
|
- 'cloud_banner': SERVER_DOMAIN + 'web/images/cloud_cn_banner.png',
|
|
|
|
- 'cloud_en_baner': SERVER_DOMAIN_SSL + 'web/images/cloud_en_banner.png'
|
|
|
|
- },
|
|
|
|
- 'promotion': promotion,
|
|
|
|
- }
|
|
|
|
- return response.json(0, result)
|
|
|
|
|
|
+ return response.json(0, result)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def check_user_coupon_is_available(coupon_qs, combo_id):
|
|
def check_user_coupon_is_available(coupon_qs, combo_id):
|