예제 #1
0
 def get(self):
     """
     input:  self.input['openid'] -------- 微信用户OpenID
             self.input['ticket'] -------- 电子票unique_id
     """
     self.check_input('openid', 'ticket')
     ticket = Ticket.get_by_unique_id(self.input['ticket'])
     activity = Activity.get_by_id(ticket.activity_id)
     return {
         'activityName': activity.name,
         'place': activity.place,
         'activityKey': activity.key,
         'uniqueId': ticket.unique_id,
         'startTime': time.mktime(time.strptime(activity.start_time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')),
         'endTime': time.mktime(time.strptime(activity.end_time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')),
         'currentTime': int(time.time()),  # 当前时间的秒级时间戳
         'status': ticket.status,
     }
예제 #2
0
    def post(self):
        """
        input:  self.input['actId'] -------- 活动ID
                self.input['ticket'] -------- 电子票ID
                self.input['studentId'] -------- 学号
                检票
                需要登录
        """
        if not self.request.user.is_authenticated():
            raise ValidateError("admin-user not login!")
        else:
            self.check_input('actId')
            result = None
            valid_ticket = None
            if 'ticket' not in self.input:
                self.check_input('studentId')
                result = Ticket.get_by_activity_and_student_number(
                    self.input['actId'], self.input['studentId'])
                if len(result) > 0:
                    for tic in result:
                        if tic.status == Ticket.STATUS_VALID:
                            valid_ticket = tic
                if not valid_ticket:
                    raise LogicError("The user don't have valid ticket!")
            elif 'studentId' not in self.input:
                self.check_input('ticket')
                result = Ticket.get_by_unique_id(self.input['ticket'])
                if result.status == Ticket.STATUS_VALID:
                    valid_ticket = result
                else:
                    raise LogicError("The ticket is not valid!")

            if valid_ticket:
                valid_ticket.status = Ticket.STATUS_USED
                valid_ticket.save()
                return {
                    'ticket': valid_ticket.unique_id,
                    'studentId': valid_ticket.student_id,
                }
            else:
                return LogicError('Ticket not found')