From f215ab98ba0dbf22588f729093e6d1d47cf55d13 Mon Sep 17 00:00:00 2001 From: luoning Date: Mon, 5 Feb 2018 21:03:05 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A5=96=E5=93=81=E6=8E=A5=E5=8F=A3remove=5Faward?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lottery.py | 10 ++++++++++ src/main.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lottery.py b/src/lottery.py index c989895..5daf91e 100644 --- a/src/lottery.py +++ b/src/lottery.py @@ -96,6 +96,16 @@ def add_awards(awards): return server_resp(200, "success") +def remove_awards(awards): + t_awards.clear_cache() + for award_id in awards: + if len(lucky_users(award_id)['data']) == 0: + t_awards.remove(d.where('award_id') == award_id) + else: + return server_resp(502, "不允许删除此奖品", {'award_id': award_id}) + return server_resp(200, "success") + + def add_users(users): t_users.clear_cache() for user in users: diff --git a/src/main.py b/src/main.py index 8e95458..6eb0e1a 100644 --- a/src/main.py +++ b/src/main.py @@ -68,6 +68,14 @@ def add_award(): return lottery.add_awards([{'award_name': name, 'award_capacity': award_capacity}]) +@app.route('/remove_award') +def remove_award(): + award_id = b.request.params.get('award_id') + if award_id is None: + b.abort(403) + return lottery.remove_awards([award_id]) + + @app.route('/reset') def reset(): return lottery.reset()