def get_participate_club_list(self, info): ''' 我参加的俱乐部列表 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] query = db.session.query(Participate, Activity).outerjoin( Activity, Participate.activity_id == Activity.activity_id).filter( and_(Participate.user_id == user_id, Activity.type_id == ACTIVITY_CLUB)) all_result = query.order_by(desc(Activity.createtime)).all() club_id_tuple = (result.Activity.club_id for result in all_result) club_query = db.session.query(Club).filter( Club.club_id.in_(club_id_tuple)) all_club_result = club_query.all() callback_data = [] img_request = {} img_request['directory'] = 'club' imagemanager = ImageManager() for club_result in all_club_result: (status, club_info) = club_result.generate(result=club_result) img_request['foreign_id'] = club_result.club_id (status, image_info) = imagemanager.get_image(info=img_request) club_info.update(image_info) callback_data.append(club_info) return (True, callback_data)
def get_score_list(self, info): ''' 积分列表 第一步: 验证用户身份 第二步: 获取积分列表 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] start_index = info['start_index'] page_count = info['page_count'] query = db.session.query(UserInfo) all_result = query.order_by(desc( UserInfo.user_score)).offset(start_index).limit(page_count).all() callback_data = [] imagemanager = ImageManager() img_request = {} for result in all_result: (status, user_info) = UserInfo.generate(result=result) count = db.session.query(func.count(UserInfo.user_id)).filter( UserInfo.user_score > user_info['user_score']).first() user_info['index_number'] = count[0] + 1 img_request['foreign_id'] = result.user_id if result.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter( ImgPath.foreign_id == result.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) user_info.update(image_info) callback_data.append(user_info) return (True, callback_data)
def get_participate_club_list(self, info): ''' 我参加的俱乐部列表 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] query = db.session.query(Participate, Activity).outerjoin( Activity, Participate.activity_id == Activity.activity_id ).filter(and_(Participate.user_id == user_id, Activity.type_id == ACTIVITY_CLUB)) all_result = query.order_by(desc(Activity.createtime)).all() club_id_tuple = (result.Activity.club_id for result in all_result) club_query = db.session.query(Club).filter(Club.club_id.in_(club_id_tuple)) all_club_result = club_query.all() callback_data = [] img_request = {} img_request['directory'] = 'club' imagemanager = ImageManager() for club_result in all_club_result: (status, club_info) = club_result.generate(result=club_result) img_request['foreign_id'] = club_result.club_id (status, image_info) = imagemanager.get_image(info=img_request) club_info.update(image_info) callback_data.append(club_info) return (True, callback_data)
def get_participate_activity_list(self, info): ''' 我参加的活动列表 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' start_index = info['start_index'] page_count = info['page_count'] user_id = info['user_id'] query = db.session.query(Participate, Activity).outerjoin( Activity, Participate.activity_id == Activity.activity_id).filter( Participate.user_id == user_id) all_result = query.order_by(desc( Activity.createtime)).offset(start_index).limit(page_count).all() callback_data = [] img_request = {} img_request['directory'] = 'activity' imagemanager = ImageManager() for result in all_result: (status, activity_info) = result.Activity.generate(result=result.Activity) img_request['foreign_id'] = result.Activity.activity_id (status, image_info) = imagemanager.get_image(info=img_request) activity_info.update(image_info) callback_data.append(activity_info) return (True, callback_data)
def get_score_list(self, info): ''' 积分列表 第一步: 验证用户身份 第二步: 获取积分列表 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] start_index = info['start_index'] page_count = info['page_count'] query = db.session.query(UserInfo) all_result = query.order_by(desc(UserInfo.user_score)).offset(start_index).limit(page_count).all() callback_data = [] imagemanager = ImageManager() img_request = {} for result in all_result: (status, user_info) = UserInfo.generate(result=result) count = db.session.query( func.count(UserInfo.user_id) ).filter( UserInfo.user_score > user_info['user_score'] ).first() user_info['index_number'] = count[0] + 1 img_request['foreign_id'] = result.user_id if result.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter(ImgPath.foreign_id == result.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) user_info.update(image_info) callback_data.append(user_info) return (True, callback_data)
def get_participate_activity_list(self, info): ''' 我参加的活动列表 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' start_index = info['start_index'] page_count = info['page_count'] user_id = info['user_id'] query = db.session.query(Participate, Activity).outerjoin( Activity, Participate.activity_id == Activity.activity_id ).filter(Participate.user_id == user_id) all_result = query.order_by(desc(Activity.createtime)).offset(start_index).limit(page_count).all() callback_data = [] img_request = {} img_request['directory'] = 'activity' imagemanager = ImageManager() for result in all_result: (status, activity_info) = result.Activity.generate(result=result.Activity) img_request['foreign_id'] = result.Activity.activity_id (status, image_info) = imagemanager.get_image(info=img_request) activity_info.update(image_info) callback_data.append(activity_info) return (True, callback_data)
def get_score_info(self, info): ''' 获取活动成绩 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' activity_id = info['activity_id'] part_query = db.session.query(Participate, UserInfo).outerjoin( UserInfo, Participate.user_id == UserInfo.user_id ).filter(and_(Participate.activity_id == activity_id, Participate.score != SCORE_EMPTY)) all_result = part_query.order_by(desc(Participate.score)).all() callback_data = [] img_request = {} imagemanager = ImageManager() for score_result in all_result: user = score_result.UserInfo participate = score_result.Participate img_request['foreign_id'] = participate.user_id if user.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter(ImgPath.foreign_id == user.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) (status, part_info) = Participate.generate(result=participate) (status, user_info) = UserInfo.generate(result=user) part_info.update(user_info) part_info.update(image_info) callback_data.append(part_info) return (True, callback_data)
def get_club_score_list(self, info): ''' 俱乐部积分列表 第一步: 验证用户身份 第二步: 获取积分最多的俱乐部积分列表 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] start_index = info['start_index'] page_count = info['page_count'] if info['club_id'] == '-1': club_query = db.session.query(ClubScore).filter( ClubScore.user_id == user_id) club_result = club_query.order_by(desc( ClubScore.club_number)).first() else: club_result = db.session.query(ClubScore).filter( ClubScore.club_id == info['club_id']).first() print(club_result) if club_result: club_id = club_result.club_id query = db.session.query(UserInfo, ClubScore).outerjoin( ClubScore, UserInfo.user_id == ClubScore.user_id).filter( ClubScore.club_id == club_id) all_result = query.order_by(desc(ClubScore.club_number)).offset( start_index).limit(page_count).all() callback_data = [] imagemanager = ImageManager() img_request = {} for result in all_result: user = result.UserInfo clubscore = result.ClubScore (status, _club) = ClubScore.generate(result=clubscore) (status, _user_info) = UserInfo.generate(result=user) count = db.session.query(func.count( ClubScore.score_id)).filter( and_(ClubScore.club_id == club_id, ClubScore.club_number > _club['club_number'])).first() _club['index_number'] = count[0] + 1 img_request['foreign_id'] = user.user_id if user.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter( ImgPath.foreign_id == user.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) _club.update(image_info) _club.update(_user_info) callback_data.append(_club) return (True, callback_data) else: return (False, None)
def _get_activity_detail(self, info): activity_id = info['activity_id'] query = db.session.query(Activity).filter(Activity.activity_id == activity_id) result = query.first() img_request = {} img_request['directory'] = 'activity' img_request['foreign_id'] = activity_id imagemanager = ImageManager() (status, activity_info) = Activity.generate(result=result) (status, image_info) = imagemanager.get_image(info=img_request) activity_info.update(image_info) return (True, activity_info)
def get_club_score_list(self, info): ''' 俱乐部积分列表 第一步: 验证用户身份 第二步: 获取积分最多的俱乐部积分列表 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' user_id = info['user_id'] start_index = info['start_index'] page_count = info['page_count'] if info['club_id'] == '-1': club_query = db.session.query(ClubScore).filter(ClubScore.user_id == user_id) club_result = club_query.order_by(desc(ClubScore.club_number)).first() else: club_result = db.session.query(ClubScore).filter(ClubScore.club_id == info['club_id']).first() print(club_result) if club_result: club_id = club_result.club_id query = db.session.query(UserInfo, ClubScore).outerjoin( ClubScore, UserInfo.user_id == ClubScore.user_id ).filter(ClubScore.club_id == club_id) all_result = query.order_by(desc(ClubScore.club_number)).offset(start_index).limit(page_count).all() callback_data = [] imagemanager = ImageManager() img_request = {} for result in all_result: user = result.UserInfo clubscore = result.ClubScore (status, _club) = ClubScore.generate(result=clubscore) (status, _user_info) = UserInfo.generate(result=user) count = db.session.query( func.count(ClubScore.score_id) ).filter( and_( ClubScore.club_id == club_id, ClubScore.club_number > _club['club_number'] ) ).first() _club['index_number'] = count[0] + 1 img_request['foreign_id'] = user.user_id if user.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter(ImgPath.foreign_id == user.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) _club.update(image_info) _club.update(_user_info) callback_data.append(_club) return (True, callback_data) else: return (False, None)
def _get_activity_detail(self, info): activity_id = info['activity_id'] query = db.session.query(Activity).filter( Activity.activity_id == activity_id) result = query.first() img_request = {} img_request['directory'] = 'activity' img_request['foreign_id'] = activity_id imagemanager = ImageManager() (status, activity_info) = Activity.generate(result=result) (status, image_info) = imagemanager.get_image(info=img_request) activity_info.update(image_info) return (True, activity_info)
def upload_file(): data = {} data['status'] = 'FAILED' data['data'] = 'NULL' imageManager = ImageManager() upload_info = {} upload_info['img_file'] = request.files['file'] upload_info['directory'] = 'activity' (status, jsonlist) = imageManager.upload_image(upload_info=upload_info) if status is not False: data['status'] = 'SUCCESS' data['data'] = jsonlist return json.dumps(data)
def get_room_detail(self, info): ''' 活动详情 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' activity_id = info['activity_id'] user_id = info['user_id'] (status, activity_detail) = self._get_activity_detail(info) (status, judge_info) = self._get_activity_judge(info) part_query = db.session.query(Participate, UserInfo).outerjoin( UserInfo, Participate.user_id == UserInfo.user_id).filter( Participate.activity_id == activity_id) all_result = part_query.order_by(Participate.location).all() role_list = [] callback_data = {} my_info = {} img_request = {} imagemanager = ImageManager() for result in all_result: participate = result.Participate user = result.UserInfo img_request['foreign_id'] = participate.user_id (status, part_info) = Participate.generate(result=participate) if user.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter( ImgPath.foreign_id == user.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) (status, user_info) = UserInfo.generate(result=user) part_info.update(image_info) part_info.update(user_info) if part_info['user_id'] == user_id: my_info.update(part_info) role_list.append(part_info) callback_data['role_list'] = role_list callback_data['activity_detail'] = activity_detail callback_data['judge_info'] = judge_info callback_data['my_info'] = my_info return (True, callback_data)
def get_room_detail(self, info): ''' 活动详情 第一步: 验证用户身份 第二步: 判断活动是否存在,是否已经加入,是否已经满员 第三步: 自动分配活动位置, 创建参加记录 :param info: {'token_id': '', 'user_id': '', 'activity_id': ''} :return: {'data': '', 'status': 'SUCCESS'} ''' activity_id = info['activity_id'] user_id = info['user_id'] (status, activity_detail) = self._get_activity_detail(info) (status, judge_info) = self._get_activity_judge(info) part_query = db.session.query(Participate, UserInfo).outerjoin( UserInfo, Participate.user_id == UserInfo.user_id ).filter(Participate.activity_id == activity_id) all_result = part_query.order_by(Participate.location).all() role_list = [] callback_data = {} my_info = {} img_request = {} imagemanager = ImageManager() for result in all_result: participate = result.Participate user = result.UserInfo img_request['foreign_id'] = participate.user_id (status, part_info) = Participate.generate(result=participate) if user.open_id is None: (status, image_info) = imagemanager.get_image(info=img_request) else: imgpath = db.session.query(ImgPath).filter(ImgPath.foreign_id == user.user_id).first() (status, image_info) = ImgPath.generate(result=imgpath) (status, user_info) = UserInfo.generate(result=user) part_info.update(image_info) part_info.update(user_info) if part_info['user_id'] == user_id: my_info.update(part_info) role_list.append(part_info) callback_data['role_list'] = role_list callback_data['activity_detail'] = activity_detail callback_data['judge_info'] = judge_info callback_data['my_info'] = my_info return (True, callback_data)