@@ -556,6 +556,8 @@
if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) {
this.signhelplist = this.inhousehelplist;
}
+ } else if (data.code === 1002) {
+ window.location.href = location.href.replace(location.search, '');
} else {
if (data.msg) {
document.title = data.msg;
diff --git a/fir_client/src/components/ShortDownload.vue b/fir_client/src/components/ShortDownload.vue
index 6502a14..a294241 100644
--- a/fir_client/src/components/ShortDownload.vue
+++ b/fir_client/src/components/ShortDownload.vue
@@ -4,7 +4,7 @@
@@ -539,6 +539,8 @@
if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) {
this.signhelplist = this.inhousehelplist;
}
+ } else if (data.code === 1002) {
+ window.location.href = location.href.replace(location.search, '');
} else {
this.iserror = true;
if (data.code === 1009) {
diff --git a/fir_ser/api/migrations/0024_auto_20210324_1751.py b/fir_ser/api/migrations/0024_auto_20210324_1751.py
index fb397aa..f212467 100644
--- a/fir_ser/api/migrations/0024_auto_20210324_1751.py
+++ b/fir_ser/api/migrations/0024_auto_20210324_1751.py
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
-
dependencies = [
('api', '0023_auto_20210316_1602'),
]
diff --git a/fir_ser/api/utils/storage/caches.py b/fir_ser/api/utils/storage/caches.py
index 6bdd09e..4215ab7 100644
--- a/fir_ser/api/utils/storage/caches.py
+++ b/fir_ser/api/utils/storage/caches.py
@@ -314,7 +314,7 @@ def set_user_download_times_flag(user_id, act):
return cache.set(user_can_download_key, act, 3600 * 24)
-def get_user_free_download_times(user_id, act='get'):
+def get_user_free_download_times(user_id, act='get', amount=1):
now = timezone.now()
user_free_download_times_key = "_".join(
[CACHE_KEY_TEMPLATE.get("user_free_download_times_key"), str(now.year), str(now.month), str(now.day),
@@ -322,26 +322,26 @@ def get_user_free_download_times(user_id, act='get'):
user_free_download_times = cache.get(user_free_download_times_key)
if user_free_download_times is not None:
if act == 'set':
- return cache.incr(user_free_download_times_key, -1)
+ return cache.incr(user_free_download_times_key, -amount)
else:
return user_free_download_times
else:
cache.set(user_free_download_times_key, USER_FREE_DOWNLOAD_TIMES, 3600 * 24)
if act == 'set':
- return cache.incr(user_free_download_times_key, -1)
+ return cache.incr(user_free_download_times_key, -amount)
else:
return USER_FREE_DOWNLOAD_TIMES
-def consume_user_download_times(user_id, app_id):
+def consume_user_download_times(user_id, app_id, amount=1):
with cache.lock("%s_%s" % ('consume_user_download_times', user_id)):
- if get_user_free_download_times(user_id) > 0:
- get_user_free_download_times(user_id, 'set')
+ if get_user_free_download_times(user_id, 'get', amount) > 0:
+ get_user_free_download_times(user_id, 'set', amount)
else:
if not check_user_can_download(user_id):
return False
try:
- UserInfo.objects.filter(pk=user_id).update(download_times=F('download_times') - 1)
+ UserInfo.objects.filter(pk=user_id).update(download_times=F('download_times') - amount)
except Exception as e:
logger.error("%s download_times less then 0. Exception:%s" % (user_id, e))
disable_user_download_times_flag(user_id)
diff --git a/fir_ser/api/views/download.py b/fir_ser/api/views/download.py
index 9d2d4fa..ed44e21 100644
--- a/fir_ser/api/views/download.py
+++ b/fir_ser/api/views/download.py
@@ -239,12 +239,17 @@ class InstallView(APIView):
else:
ip = request.META['REMOTE_ADDR']
logger.info("remote ip %s short %s download_url %s app_obj %s" % (ip, short, download_url, app_obj))
- if not consume_user_download_times(app_obj.get("user_id"), app_id):
- res.code = 1009
- res.msg = "可用下载额度不足"
- del res.data
- return Response(res.dict)
- set_app_download_by_cache(app_id)
+ set_app_download_by_cache(app_id)
+ amount = 1
+ # 超级签需要消耗2个下载次数
+ if app_obj.get("issupersign"):
+ amount += 1
+
+ if not consume_user_download_times(app_obj.get("user_id"), app_id, amount):
+ res.code = 1009
+ res.msg = "可用下载额度不足"
+ del res.data
+ return Response(res.dict)
return Response(res.dict)
else:
res.code = 1004