{"action":"created","comment":{"url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/comments/234080483","pull_request_review_id":175646157,"id":234080483,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNDA4MDQ4Mw==","diff_hunk":"@@ -65,3 +68,227 @@ def check(self):\n \n     def handle(self):\n         return self.reply_text(self.get_message('book_empty'))\n+\n+#抢票\n+class BookActivityHandler(WeChatHandler):\n+\n+    def check(self):\n+        if self.is_event('CLICK'):\n+            event_key = self.view.event_keys['book_header']\n+            event_key += self.input['EventKey'][len(event_key):]\n+            return self.is_event_click(event_key)\n+        else:\n+            return self.is_text('抢票')\n+        return False\n+\n+    def handle(self):\n+        if not self.user.student_id:\n+            return self.reply_text(self.get_message('bind_account'))\n+\n+        currentTime = datetime.datetime.now().timestamp()\n+        if self.is_event('CLICK'):\n+            event_key = self.view.event_keys['book_header']\n+            event_key += self.input['EventKey'][len(event_key):]\n+            if self.is_event_click(event_key):\n+                act_id = self.input['EventKey'][len(self.view.event_keys['book_header']):]\n+                activity = self.get_activity(act_id)\n+                if not activity:\n+                    return self.reply_text('对不起，没有该项活动')\n+                if currentTime < activity.book_start.timestamp():\n+                    return self.reply_text('对不起，还未开放抢票')\n+                if currentTime > activity.book_end.timestamp():\n+                    return self.reply_text('对不起，抢票已经截止')\n+                #check if the student has book a ticket:\n+                if Ticket.objects.filter(student_id = self.user.student_id, activity = activity, status = Ticket.STATUS_VALID):\n+                    return self.reply_text('一个人只能抢一张票哦 ^口..口^')\n+                if Ticket.objects.filter(student_id = self.user.student_id, activity = activity, status = Ticket.STATUS_USED):\n+                    return self.reply_text('您已经抢过该活动的票且使用过')\n+                #lock!lock!lock!\n+                ticket = self.book_ticket(act_id)\n+                activity = self.get_activity(act_id)\n+                if ticket:\n+                    return self.reply_single_news({\n+                        'Title':activity.name,\n+                        'Description':'抢票成功',\n+                        'Url':ticket,\n+                        'PicUrl':activity.pic_url,\n+                    })\n+                else:\n+                    return self.reply_text('没有多的票了！请自行尝试劝退抢到票的朋友们~')\n+            else:\n+                return False\n+\n+        elif self.is_text('抢票'):\n+            query = self.input['Content'][3:]\n+            activity = Activity.objects.filter(key = query).first()\n+            if not activity:\n+                activity = Activity.objects.filter(name = query).first()\n+                if not activity:\n+                    return self.reply_text('对不起，没有该项活动')\n+            if currentTime < activity.book_start.timestamp():\n+                return self.reply_text('对不起，还未开放抢票')\n+            if currentTime > activity.book_end.timestamp():\n+                return self.reply_text('对不起，抢票已经截止')\n+            if Ticket.objects.filter(student_id = self.user.student_id, activity = activity, status = Ticket.STATUS_VALID):\n+                return self.reply_text('一个人只能抢一张票哦 ^口..口^')\n+            if Ticket.objects.filter(student_id = self.user.student_id, activity = activity, status = Ticket.STATUS_USED):\n+                return self.reply_text('您已经抢过该活动的票且使用过')\n+            if activity.remain_tickets == 0:\n+                return self.reply_text('没有多的票了！请自行尝试劝退抢到票的朋友们~')\n+            unique_id = uuid.uuid5(uuid.NAMESPACE_DNS,self.user.student_id + activity.name + str(currentTime))\n+            Ticket.objects.create(student_id = self.user.student_id, unique_id = unique_id,\n+            activity = activity, status = Ticket.STATUS_VALID)","path":"wechat/handlers.py","position":85,"original_position":85,"commit_id":"e84567ad86e5f39a4c1bb22ad8b88002e1891325","original_commit_id":"e84567ad86e5f39a4c1bb22ad8b88002e1891325","user":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"body":"代码缩进不太合适，应该向后空格，与student_id=对齐\r\n而且没有像上面一样调用book_ticket用锁……","created_at":"2018-11-16T03:21:40Z","updated_at":"2018-11-16T03:21:41Z","html_url":"https://github.com/fengh16/WeChatTicket/pull/1#discussion_r234080483","pull_request_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/comments/234080483"},"html":{"href":"https://github.com/fengh16/WeChatTicket/pull/1#discussion_r234080483"},"pull_request":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1","id":231398767,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxMzk4NzY3","html_url":"https://github.com/fengh16/WeChatTicket/pull/1","diff_url":"https://github.com/fengh16/WeChatTicket/pull/1.diff","patch_url":"https://github.com/fengh16/WeChatTicket/pull/1.patch","issue_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/1","number":1,"state":"open","locked":false,"title":"In class","user":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-16T02:41:53Z","updated_at":"2018-11-16T03:21:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"011f7036b20140a65e066b5fb15c4c4a78ee15fd","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1/commits","review_comments_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1/comments","review_comment_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/1/comments","statuses_url":"https://api.github.com/repos/fengh16/WeChatTicket/statuses/e84567ad86e5f39a4c1bb22ad8b88002e1891325","head":{"label":"fengh16:dev-alice","ref":"dev-alice","sha":"e84567ad86e5f39a4c1bb22ad8b88002e1891325","user":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"repo":{"id":157802402,"node_id":"MDEwOlJlcG9zaXRvcnkxNTc4MDI0MDI=","name":"WeChatTicket","full_name":"fengh16/WeChatTicket","private":false,"owner":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"html_url":"https://github.com/fengh16/WeChatTicket","description":"Ticket management system based on WeChat public platform.","fork":true,"url":"https://api.github.com/repos/fengh16/WeChatTicket","forks_url":"https://api.github.com/repos/fengh16/WeChatTicket/forks","keys_url":"https://api.github.com/repos/fengh16/WeChatTicket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fengh16/WeChatTicket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fengh16/WeChatTicket/teams","hooks_url":"https://api.github.com/repos/fengh16/WeChatTicket/hooks","issue_events_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/events{/number}","events_url":"https://api.github.com/repos/fengh16/WeChatTicket/events","assignees_url":"https://api.github.com/repos/fengh16/WeChatTicket/assignees{/user}","branches_url":"https://api.github.com/repos/fengh16/WeChatTicket/branches{/branch}","tags_url":"https://api.github.com/repos/fengh16/WeChatTicket/tags","blobs_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/refs{/sha}","trees_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fengh16/WeChatTicket/statuses/{sha}","languages_url":"https://api.github.com/repos/fengh16/WeChatTicket/languages","stargazers_url":"https://api.github.com/repos/fengh16/WeChatTicket/stargazers","contributors_url":"https://api.github.com/repos/fengh16/WeChatTicket/contributors","subscribers_url":"https://api.github.com/repos/fengh16/WeChatTicket/subscribers","subscription_url":"https://api.github.com/repos/fengh16/WeChatTicket/subscription","commits_url":"https://api.github.com/repos/fengh16/WeChatTicket/commits{/sha}","git_commits_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/commits{/sha}","comments_url":"https://api.github.com/repos/fengh16/WeChatTicket/comments{/number}","issue_comment_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/comments{/number}","contents_url":"https://api.github.com/repos/fengh16/WeChatTicket/contents/{+path}","compare_url":"https://api.github.com/repos/fengh16/WeChatTicket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fengh16/WeChatTicket/merges","archive_url":"https://api.github.com/repos/fengh16/WeChatTicket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fengh16/WeChatTicket/downloads","issues_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues{/number}","pulls_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls{/number}","milestones_url":"https://api.github.com/repos/fengh16/WeChatTicket/milestones{/number}","notifications_url":"https://api.github.com/repos/fengh16/WeChatTicket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fengh16/WeChatTicket/labels{/name}","releases_url":"https://api.github.com/repos/fengh16/WeChatTicket/releases{/id}","deployments_url":"https://api.github.com/repos/fengh16/WeChatTicket/deployments","created_at":"2018-11-16T02:39:19Z","updated_at":"2018-11-16T02:39:21Z","pushed_at":"2018-11-16T02:41:54Z","git_url":"git://github.com/fengh16/WeChatTicket.git","ssh_url":"git@github.com:fengh16/WeChatTicket.git","clone_url":"https://github.com/fengh16/WeChatTicket.git","svn_url":"https://github.com/fengh16/WeChatTicket","homepage":null,"size":919,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"fengh16:master","ref":"master","sha":"b723ca6a3fb32737b344c4d9ada3f101de26b16d","user":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"repo":{"id":157802402,"node_id":"MDEwOlJlcG9zaXRvcnkxNTc4MDI0MDI=","name":"WeChatTicket","full_name":"fengh16/WeChatTicket","private":false,"owner":{"login":"fengh16","id":22994178,"node_id":"MDQ6VXNlcjIyOTk0MTc4","avatar_url":"https://avatars0.githubusercontent.com/u/22994178?v=4","gravatar_id":"","url":"https://api.github.com/users/fengh16","html_url":"https://github.com/fengh16","followers_url":"https://api.github.com/users/fengh16/followers","following_url":"https://api.github.com/users/fengh16/following{/other_user}","gists_url":"https://api.github.com/users/fengh16/gists{/gist_id}","starred_url":"https://api.github.com/users/fengh16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengh16/subscriptions","organizations_url":"https://api.github.com/users/fengh16/orgs","repos_url":"https://api.github.com/users/fengh16/repos","events_url":"https://api.github.com/users/fengh16/events{/privacy}","received_events_url":"https://api.github.com/users/fengh16/received_events","type":"User","site_admin":false},"html_url":"https://github.com/fengh16/WeChatTicket","description":"Ticket management system based on WeChat public platform.","fork":true,"url":"https://api.github.com/repos/fengh16/WeChatTicket","forks_url":"https://api.github.com/repos/fengh16/WeChatTicket/forks","keys_url":"https://api.github.com/repos/fengh16/WeChatTicket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fengh16/WeChatTicket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fengh16/WeChatTicket/teams","hooks_url":"https://api.github.com/repos/fengh16/WeChatTicket/hooks","issue_events_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/events{/number}","events_url":"https://api.github.com/repos/fengh16/WeChatTicket/events","assignees_url":"https://api.github.com/repos/fengh16/WeChatTicket/assignees{/user}","branches_url":"https://api.github.com/repos/fengh16/WeChatTicket/branches{/branch}","tags_url":"https://api.github.com/repos/fengh16/WeChatTicket/tags","blobs_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/refs{/sha}","trees_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fengh16/WeChatTicket/statuses/{sha}","languages_url":"https://api.github.com/repos/fengh16/WeChatTicket/languages","stargazers_url":"https://api.github.com/repos/fengh16/WeChatTicket/stargazers","contributors_url":"https://api.github.com/repos/fengh16/WeChatTicket/contributors","subscribers_url":"https://api.github.com/repos/fengh16/WeChatTicket/subscribers","subscription_url":"https://api.github.com/repos/fengh16/WeChatTicket/subscription","commits_url":"https://api.github.com/repos/fengh16/WeChatTicket/commits{/sha}","git_commits_url":"https://api.github.com/repos/fengh16/WeChatTicket/git/commits{/sha}","comments_url":"https://api.github.com/repos/fengh16/WeChatTicket/comments{/number}","issue_comment_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues/comments{/number}","contents_url":"https://api.github.com/repos/fengh16/WeChatTicket/contents/{+path}","compare_url":"https://api.github.com/repos/fengh16/WeChatTicket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fengh16/WeChatTicket/merges","archive_url":"https://api.github.com/repos/fengh16/WeChatTicket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fengh16/WeChatTicket/downloads","issues_url":"https://api.github.com/repos/fengh16/WeChatTicket/issues{/number}","pulls_url":"https://api.github.com/repos/fengh16/WeChatTicket/pulls{/number}","milestones_url":"https://api.github.com/repos/fengh16/WeChatTicket/milestones{/number}","notifications_url":"https://api.github.com/repos/fengh16/WeChatTicket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fengh16/WeChatTicket/labels{/name}","releases_url":"https://api.github.com/repos/fengh16/WeChatTicket/releases{/id}","deployments_url":"https://api.github.com/repos/fengh16/WeChatTicket/deployments","created_at":"2018-11-16T02:39:19Z","updated_at":"2018-11-16T02:39:21Z","pushed_at":"2018-11-16T02:41:54Z","git_url":"git://github.com/fengh16/WeChatTicket.git","ssh_url":"git@github.com:fengh16/WeChatTicket.git","clone_url":"https://github.com/fengh16/WeChatTicket.git","svn_url":"https://github.com/fengh16/WeChatTicket","homepage":null,"size":919,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1"},"html":{"href":"https://github.com/fengh16/WeChatTicket/pull/1"},"issue":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/issues/1"},"comments":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/fengh16/WeChatTicket/statuses/e84567ad86e5f39a4c1bb22ad8b88002e1891325"}},"author_association":"OWNER"}}
{"actor":{"display_login":"fengh16"}}