def get(self): user_id = int(self.current_user_id) data = [] records = [] apply_records = FriendStatusRecord.objects.filter(to_user_id=user_id, friend_status=1) success_records = FriendStatusRecord.objects.filter( oper_user_id=user_id, friend_status=2) if apply_records: for r in apply_records: record = FriendStatusRecord.objects.filter( oper_user_id=user_id, to_user_id=r.oper_user_id, friend_status=2) if not record: user = User.objects.filter(id=r.oper_user_id).first() friended = Friend.objects.filter(user_id=user_id, friend_id=user.id, friend_status=2).first() if friended: date_time = friended.update_time.strftime( '%Y-%m-%d %H:%M:%S') dic = { "record_id": str(r.id), "user": convert_user(user), "status": 2, "date_time": date_time } else: date_time = r.create_time.strftime('%Y-%m-%d %H:%M:%S') dic = { "record_id": str(r.id), "user": convert_user(user), "status": r.friend_status, "date_time": date_time } data.append(dic) if success_records: for r in success_records: user = User.objects.filter(id=r.to_user_id).first() date_time = r.create_time.strftime('%Y-%m-%d %H:%M:%S') dic = { "record_id": str(r.id), "user": convert_user(user), "status": r.friend_status, "date_time": date_time } data.append(dic) self.write({"status": "success", "data": data})
def get(self): user = self.current_user invite_list = UserInviteCode.get_invite_list(invite_id=user.id) data = [] """ 原有代码 留作参考 for invite_user in invite_list: account = Account.objects.get(user=invite_user) dic = { "user": convert_user(invite_user), "charge": account.charge*0.1, "friend_total_revenue": (invite_user.ticket-invite_user.ticket_bonus) * 0.1 + account.charge * 0.1, "friend_revenue": (invite_user.ticket - invite_user.ticket_bonus) * 0.1, } data.append(dic) """ for invite_user in invite_list: ticket_account = TicketAccount.objects.get(user=invite_user) account = Account.objects.get(user=invite_user) dic ={ "user": convert_user(invite_user), "charge": account.charge * 0.1, "friend_total_revenue": (ticket_account.call_ticket + ticket_account.gift_ticket) * 0.1 + account.charge * 0.1, "friend_revenue": (ticket_account.call_ticket + ticket_account.gift_ticket) * 0.1, } data.append(dic) return self.write({"status": "success", "data": data, })
def get(self): user = self.current_user page = self.arg_int('page') page_count = self.arg_int('page_count') friend_users = FriendUser.objects.filter( to_id=user.id)[(page - 1) * page_count:page * page_count] data = [] for friend_user in friend_users: u = User.objects.filter(id=friend_user.from_id).first() user_vip = UserVip.objects.filter(user_id=u.id).first() if not user_vip: dic = {"user": convert_user(u)} else: vip = Vip.objects.filter(id=user_vip.vip_id).first() dic = {"user": convert_user(u), "vip": convert_vip(vip)} data.append(dic) return self.write({"status": "success", "data": data})
def get(self): room_id = self.arg("room_id") record = RoomRecord.objects.get(id=room_id) room_user = User.objects.get(id=record.user_id) join_user = User.objects.get(id=record.join_id) room_info = {} room_info['id'] = str(record.id) room_info['user_id'] = record.user_id room_info['is_video'] = record.room_type room_info['join_id'] = record.join_id room_info['now_price'] = record.price data = { "audioroom": room_info, "user": convert_user(room_user), "join": convert_user(join_user), } self.write({"status": "success", "data": data})
def get(self): user_id = self.current_user_id page = self.arg_int('page') page_count = self.arg_int('page_count') pictures = PictureInfo.get_picture_list(page=page, page_count=page_count) data = [] for picture in pictures: user = PictureInfo.get_picture_user(user_id=picture.user_id) if not user_id: is_purchase = False is_like = False else: is_purchase = PictureInfo.check_is_purchase( picture.id, user_id) is_like = PictureInfo.check_is_like(picture.id, user_id) picture_count = PictureInfo.objects.filter(user_id=user.id, status=0).count() if picture.lock_type == 0: is_purchase = True if is_purchase: dic = { "user": convert_user(user), "picture": convert_real_picture(picture), "is_like": is_like, "is_purchase": is_purchase, "picture_count": picture_count, } else: dic = { "user": convert_user(user), "picture": convert_picture(picture), "is_like": is_like, "is_purchase": is_purchase, "picture_count": picture_count, } data.append(dic) self.write({ "status": "success", "data": data, })
def get(self): access_token = self.arg("user_key") openid = self.arg("openid") phone = self.arg("phone") sms_code = self.arg("sms_code") if access_token == "" or openid == "": return self.write({"status": "fail", "error": "access_token or openid null!", "message_code": 3, }) ucpass = SMS() result = ucpass.getCacheData(phone) ucpass.delSmsCodeCache(phone) if result != None: createDate = result['createDate'] user_key = ucpass.get_access_token(phone, openid, createDate) if user_key != access_token: return self.write({"status": "fail", "error": _(u"非法用户"), "message_code": 3, }) if sms_code != result['smsCode']: return self.write({"status": "fail", "error": _(u"验证码错误,请输入正确的验证码"), "message_code": 2, }) else: return self.write({"status": "fail", "error": _(u"验证码失效"), "message_code": 2, }) user = User.objects.filter(phone=phone).order_by("created_at").first() if not user: return self.write({"status": "fail", "error": _(u"未绑定手机号"), "message_code": 4}) invite_list = UserInviteCode.get_invite_list(invite_id=user.id) friend_revenue = 0 for invite_user in invite_list: friend_revenue += invite_user.ticket * 0.1 month_money = WithdrawRequest.compute_month_has_withdrawed(user.id) day_money = WithdrawRequest.compute_day_has_withdrawed(user.id) realname_status = RealNameVerify.check_user_verify(user.id) ticket_account = TicketAccount.objects.get(user=user) user_data = convert_user(user) user_data["ticket"] = ticket_account.total_ticket data = { "user": user_data, "total_revenue": ticket_account.total_ticket, "my_revenue": ticket_account.call_ticket + ticket_account.gift_ticket, "friend_revenue": ticket_account.friend_benifit_ticket + ticket_account.friend_charge_ticket, "withdraw_money": int(ticket_account.money - ticket_account.money_withdrawed-ticket_account.money_requesting), "month_limit": WithdrawRequest.class_MONTH_MONEY_TAX_LIMIT, "day_limit": WithdrawRequest.class_DAY_MONEY_LIMIT, "month_has_withdrawed":month_money, "day_has_withdrawed":day_money, "realname_status": realname_status, } self.auth_login(user.id) return self.write({"status": "success", "data": data, })
def get(self): user_id = int(self.current_user_id) data = [] friends = Friend.objects.filter(user_id=user_id, friend_status=2) if friends: for friend in friends: user = User.objects.filter(id=friend.friend_id).first() dic = {"user": convert_user(user)} data.append(dic) self.write({"status": "success", "data": data})
def get(self): picture_id = self.arg('picture_id') PictureInfo.add_viewcount(picture_id) picture = PictureInfo.get_picture_info(picture_id=picture_id) comments = picture.comment comments.reverse() data = [] for comment_id in comments: comment = CommentInfo.comment_view(comment_id=comment_id) user = CommentInfo.get_comment_user(user_id=comment.user_id) if comment.reply_id: reply_user = CommentInfo.get_comment_user( user_id=comment.reply_id) dic = { "id": str(comment.id), "user": convert_user(user), "reply": convert_user(reply_user), "comment": comment.comment, "like_count": comment.like_count, "created_at": datetime_to_timestamp(comment.created_at), "status": comment.status, "picture_id": comment.picture_id, } else: dic = { "id": str(comment.id), "user": convert_user(user), "comment": comment.comment, "like_count": comment.like_count, "created_at": datetime_to_timestamp(comment.created_at), "status": comment.status, "picture_id": comment.picture_id, } data.append(dic) self.write({ "status": "success", "picture": convert_real_picture(picture), "data": data, })
def get(self): picture_id = self.arg('picture_id') page = self.arg_int('page') page_count = self.arg_int('page_count') user_list = PictureInfo.get_unlock_user_list(picture_id=picture_id, page=page, page_count=page_count) data = [] for user_id in user_list: user = PictureInfo.get_picture_user(user_id) data.append(convert_user(user)) self.write({ "status": "success", "data": data, })
def get(self): user_id = int(self.current_user_id) user = self.current_user # 测试 # user_id = 3 # user = User.objects.filter(id=user_id).first() vip_user = UserVip.objects.filter(user_id=user_id).first() vip_type = 0 # 0:非会员 1:高级会员 2: 超级会员 allow_buy = 1 # 0: 不允许购买 1:允许 endtime_str = "" # 会员会显示截止日期 vip_pic = VipIntroPic.objects.filter( pic_status=1).first() # vip会员介绍说明图 vips = Vip.objects.filter(is_valid=1).order_by("vip_type") vip_list = [] # 会员列表 vip_name = "" # 会员名称 vip_icon = "" # 会员icon for v in vips: vip_list.append(convert_vip(v)) now = datetime.datetime.now() if vip_user: end = vip_user.end_time days = (end - now).days # 截止时间 endtime_str = end.strftime('%Y年%m月%d日') vip = Vip.objects.filter(id=vip_user.vip_id).first() vip_type = vip.vip_type if days > 3: allow_buy = 0 vip_name = vip.name vip_icon = Vip.convert_http_to_https(vip.icon_url) data = { 'vip_type': vip_type, 'allow_buy': allow_buy, 'user': convert_user(user), 'endtime': endtime_str, 'vip_name': vip_name, 'vip_icon': vip_icon, 'vip_list': vip_list, 'vip_detail_pic': VipIntroPic.convert_http_to_https( vip_pic.pic_url), # 注意HTTPS!!!! 记得convert! } self.write({"status": "success", "data": data})
def push_hot_anchor(cls): """ push user_id into redis key: "user_id" """ anchor_redis = HotAnchorRedis() hot_list = [] now_time = int(time.time()) pre_time = now_time - 120 heartbeats = UserHeartBeat.objects.filter( last_report_time__gte=pre_time) hots = [] anchors = Anchor.objects.all() hot_ids = [] for anchor in anchors: user = User.objects.get(id=anchor.sid) user_heart = UserHeartBeat.objects.get(user=user) if user_heart.last_report_time > pre_time and user.disturb_mode != 1: hots.append(user) hot_ids.append(user.id) for heartbeat in heartbeats: if heartbeat.user.charm_value > 2500 and heartbeat.user.disturb_mode != 1 \ and heartbeat.user.id not in hot_ids: hots.append(heartbeat.user) if not hots: hots = User.objects.all().order_by("-charm_value")[0:4] for user in hots: room = AudioRoomRecord.objects.get(id=user.audio_room_id) personal_tags = UserTags.get_usertags(user_id=room.user_id) if not personal_tags: personal_tags = [] dic = { "audioroom": convert_audioroom(room), "user": convert_user(user), "personal_tags": personal_tags, "time_stamp": int(time.time()) } hot_list.append(dic) user_id_list.append(user.id)
def oldcommonlist(): now_time = int(time.time()) pre_time = now_time - 120 heartbeats = UserHeartBeat.objects.filter(last_report_time__gte=pre_time) hots = [] anchors = Anchor.objects.all() hot_ids = [] hot_list = [] for anchor in anchors: user = User.objects.get(id=anchor.sid) user_heart = UserHeartBeat.objects.get(user=user) if user_heart.last_report_time > pre_time and user.disturb_mode != 1: hots.append(user) hot_ids.append(user.id) for heartbeat in heartbeats: if heartbeat.user.charm_value > 3500 and heartbeat.user.disturb_mode != 1 \ and heartbeat.user.id not in hot_ids and heartbeat.user.is_video_auth == 1: hots.append(heartbeat.user) if not hots: hots = User.objects.filter( is_video_auth=1).order_by("-charm_value")[0:4] for user in hots: room = AudioRoomRecord.objects.get(id=user.audio_room_id) personal_tags = UserTags.get_usertags(user_id=room.user_id) if not personal_tags: personal_tags = [] user_vip = UserVip.objects.filter(user_id=user.id).first() # time = int(time.time()) # pre_time = time - 120 user_beat = UserHeartBeat.objects.filter( user=user, last_report_time__gte=pre_time).first() if user_beat: is_online = 1 else: is_online = 0 if not user_vip: dic = { "audioroom": convert_audioroom(room), "user": convert_user(user), "personal_tags": personal_tags, "time_stamp": int(time.time()), "is_online": is_online } else: vip = Vip.objects.filter(id=user_vip.vip_id).first() dic = { "audioroom": convert_audioroom(room), "user": convert_user(user), "personal_tags": personal_tags, "time_stamp": int(time.time()), "vip": convert_vip(vip), "is_online": is_online } show_video = RealVideoVerify.objects( user_id=user.id, status=1).order_by("-update_time").first() if show_video: dic["check_real_video"] = show_video.status else: real_video = RealVideoVerify.objects( user_id=user.id, status__ne=2).order_by("-update_time").first() if real_video: dic["check_real_video"] = real_video.status else: dic["check_real_video"] = 3 hot_list.append(json.dumps(dic)) return hot_list
def get(self): user_id = self.current_user_id is_old = True if user_id: is_target = (self.current_user.is_video_auth != 1 and UserRedis.is_target_user(user_id)) or \ (self.current_user.is_video_auth == 1 and not UserRedis.is_pure_anchor(user_id)) if not is_target: is_old = False else: is_old = False column_type = self.arg_int('column_type') page = self.arg_int('page') page_count = self.arg_int('page_count') nodisplay = "59956dfb18ce427fa83c9cec" data = [] if is_old: if column_type == 2: # 新人驾到 anchor_list = NewAnchorRank.objects.all() if anchor_list: anchor_list = anchor_list[(page - 1) * page_count:page * page_count] for anchor in anchor_list: user = User.objects.filter(id=anchor.user_id, is_video_auth=1).first() if not user: continue if user.disturb_mode != 1: if nodisplay not in user.label: if user.id == 1 or user.id == 2: continue if not user.audio_room_id: continue # 是否在线 查看心跳 import time time = int(time.time()) pre_time = time - 3600 user_beat = UserHeartBeat.objects.filter( user=user, last_report_time__gte=pre_time).first() if user_beat: is_online = 1 if not user.audio_room_id: AudioRoomRecord.create_roomrecord( user.id, datetime.datetime.now()) audioroom = AudioRoomRecord.objects.get( id=user.audio_room_id) personal_tags = UserTags.get_usertags( user_id=user.id) user_vip = UserVip.objects.filter( user_id=user.id).first() if user_vip: vip = Vip.objects.filter( id=user_vip.vip_id).first() dic = { "audioroom": convert_audioroom(audioroom), "user": convert_user(user), "personal_tags": personal_tags, "vip": convert_vip(vip), "is_online": is_online } else: dic = { "audioroom": convert_audioroom(audioroom), "user": convert_user(user), "is_online": is_online, "personal_tags": personal_tags } # 视频认证状态 real_video = RealVideoVerify.objects( user_id=user.id, status__ne=2).order_by( "-update_time").first() show_video = RealVideoVerify.objects( user_id=user.id, status=1).order_by( "-update_time").first() if show_video: dic["check_real_video"] = show_video.status else: if real_video: dic["check_real_video"] = real_video.status else: dic["check_real_video"] = 3 data.append(dic) else: recommed_list = UserRedis.get_recommed_list_pure() anchor_list = UserRedis.get_index_anchor_list_pure(0, -1) finaluser = recommed_list + anchor_list finaluser = finaluser[(page - 1) * page_count:page * page_count] if len(finaluser) > 0: for anchorid in finaluser: user = User.objects.filter(id=int(anchorid)).first() import time time = int(time.time()) pre_time = time - 3600 user_beat = UserHeartBeat.objects.filter( user=user, last_report_time__gte=pre_time).first() if user_beat: is_online = 1 else: is_online = 0 if not user.audio_room_id: AudioRoomRecord.create_roomrecord( user.id, datetime.datetime.now()) audioroom = AudioRoomRecord.objects.get( id=user.audio_room_id) personal_tags = UserTags.get_usertags(user_id=user.id) user_vip = UserVip.objects.filter(user_id=user.id).first() if user_vip: vip = Vip.objects.filter(id=user_vip.vip_id).first() dic = { "audioroom": convert_audioroom(audioroom), "user": convert_user(user), "personal_tags": personal_tags, "vip": convert_vip(vip), "is_online": is_online } else: dic = { "audioroom": convert_audioroom(audioroom), "user": convert_user(user), "is_online": is_online, "personal_tags": personal_tags } # 视频认证状态 real_video = RealVideoVerify.objects( user_id=user.id, status__ne=2).order_by("-update_time").first() show_video = RealVideoVerify.objects( user_id=user.id, status=1).order_by("-update_time").first() if show_video: dic["check_real_video"] = show_video.status else: if real_video: dic["check_real_video"] = real_video.status else: dic["check_real_video"] = 3 data.append(dic) return self.write({ "status": "success", "data": data, })