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

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. 17
      fir_ser/api/views/download.py

@ -223,7 +223,7 @@
<div ref="signhelp" class="signhelp screenshots-section"> <div ref="signhelp" class="signhelp screenshots-section">
<div class="signhelp-title"> <div class="signhelp-title">
超级签安装教程 iOS安装教程
<span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span> <span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span>
</div> </div>
@ -556,6 +556,8 @@
if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) { if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) {
this.signhelplist = this.inhousehelplist; this.signhelplist = this.inhousehelplist;
} }
} else if (data.code === 1002) {
window.location.href = location.href.replace(location.search, '');
} else { } else {
if (data.msg) { if (data.msg) {
document.title = data.msg; document.title = data.msg;

@ -4,7 +4,7 @@
<div ref="signhelp" class="signhelp screenshots-section"> <div ref="signhelp" class="signhelp screenshots-section">
<div class="signhelp-title"> <div class="signhelp-title">
超级签安装教程 iOS安装教程
<span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span> <span><a id="closeBtn" @click="jiaocheng('close')">关闭</a></span>
</div> </div>
@ -539,6 +539,8 @@
if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) { if (this.mcurrentappinfo.release_type === 2 && !this.currentappinfo.issupersign) {
this.signhelplist = this.inhousehelplist; this.signhelplist = this.inhousehelplist;
} }
} else if (data.code === 1002) {
window.location.href = location.href.replace(location.search, '');
} else { } else {
this.iserror = true; this.iserror = true;
if (data.code === 1009) { if (data.code === 1009) {

@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('api', '0023_auto_20210316_1602'), ('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) 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() now = timezone.now()
user_free_download_times_key = "_".join( user_free_download_times_key = "_".join(
[CACHE_KEY_TEMPLATE.get("user_free_download_times_key"), str(now.year), str(now.month), str(now.day), [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) user_free_download_times = cache.get(user_free_download_times_key)
if user_free_download_times is not None: if user_free_download_times is not None:
if act == 'set': if act == 'set':
return cache.incr(user_free_download_times_key, -1) return cache.incr(user_free_download_times_key, -amount)
else: else:
return user_free_download_times return user_free_download_times
else: else:
cache.set(user_free_download_times_key, USER_FREE_DOWNLOAD_TIMES, 3600 * 24) cache.set(user_free_download_times_key, USER_FREE_DOWNLOAD_TIMES, 3600 * 24)
if act == 'set': if act == 'set':
return cache.incr(user_free_download_times_key, -1) return cache.incr(user_free_download_times_key, -amount)
else: else:
return USER_FREE_DOWNLOAD_TIMES 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)): with cache.lock("%s_%s" % ('consume_user_download_times', user_id)):
if get_user_free_download_times(user_id) > 0: if get_user_free_download_times(user_id, 'get', amount) > 0:
get_user_free_download_times(user_id, 'set') get_user_free_download_times(user_id, 'set', amount)
else: else:
if not check_user_can_download(user_id): if not check_user_can_download(user_id):
return False return False
try: 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: except Exception as e:
logger.error("%s download_times less then 0. Exception:%s" % (user_id, e)) logger.error("%s download_times less then 0. Exception:%s" % (user_id, e))
disable_user_download_times_flag(user_id) disable_user_download_times_flag(user_id)

@ -239,12 +239,17 @@ class InstallView(APIView):
else: else:
ip = request.META['REMOTE_ADDR'] ip = request.META['REMOTE_ADDR']
logger.info("remote ip %s short %s download_url %s app_obj %s" % (ip, short, download_url, app_obj)) 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)
res.code = 1009 amount = 1
res.msg = "可用下载额度不足" # 超级签需要消耗2个下载次数
del res.data if app_obj.get("issupersign"):
return Response(res.dict) amount += 1
set_app_download_by_cache(app_id)
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) return Response(res.dict)
else: else:
res.code = 1004 res.code = 1004

Loading…
Cancel
Save