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