From 4d7ce27ff563ac91b865d399f30fb5fc8d197da7 Mon Sep 17 00:00:00 2001 From: youngS Date: Fri, 26 Mar 2021 16:30:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AD=BE=E9=9C=80=E8=A6=81=E6=B6=88=E5=8C=96?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E4=B8=8B=E8=BD=BD=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_client/src/components/FirDownload.vue | 4 +++- fir_client/src/components/ShortDownload.vue | 4 +++- .../api/migrations/0024_auto_20210324_1751.py | 1 - fir_ser/api/utils/storage/caches.py | 14 +++++++------- fir_ser/api/views/download.py | 17 +++++++++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/fir_client/src/components/FirDownload.vue b/fir_client/src/components/FirDownload.vue index 2f0a6d8..7e35d03 100644 --- a/fir_client/src/components/FirDownload.vue +++ b/fir_client/src/components/FirDownload.vue @@ -223,7 +223,7 @@
- 超级签安装教程 + iOS安装教程 关闭
@@ -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 @@
- 超级签安装教程 + iOS安装教程 关闭
@@ -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