代码优化,超级签需要消化两个下载次数

pull/12/head
youngS 4 years ago
parent 4b2a3c7508
commit 4d7ce27ff5
  1. 4
      fir_client/src/components/FirDownload.vue
  2. 4
      fir_client/src/components/ShortDownload.vue
  3. 1
      fir_ser/api/migrations/0024_auto_20210324_1751.py
  4. 14
      fir_ser/api/utils/storage/caches.py
  5. 9
      fir_ser/api/views/download.py

@ -223,7 +223,7 @@
<div ref="signhelp" class="signhelp screenshots-section">
<div class="signhelp-title">
超级签安装教程
iOS安装教程
<span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span>
</div>
@ -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;

@ -4,7 +4,7 @@
<div ref="signhelp" class="signhelp screenshots-section">
<div class="signhelp-title">
超级签安装教程
iOS安装教程
<span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span>
</div>
@ -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) {

@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0023_auto_20210316_1602'),
]

@ -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)

@ -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):
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)
set_app_download_by_cache(app_id)
return Response(res.dict)
else:
res.code = 1004

Loading…
Cancel
Save