def get(self, params): login_user_id = g.account["user_id"] RedisModel.reset_new_message(login_user_id, RedisModel.new_visitor) visitor_list = list() while not visitor_list: visitor_list = VisitorRecordModel.query_visitor_list_by_day( login_user_id, 20, params["last_id"]) params["last_id"] += 1 # 最多查询30天 if params["last_id"] > 30: break visitor_dict_list = list() for visitor in visitor_list: item = dict() user_info = UserInfoModel.query_user_model_by_id( visitor.visitor_user_id) item["user_info"] = UserInfoModel.format_user_info( user_info) if user_info else {} item["time"] = visitor.created_time visitor_dict_list.append(item) return json_success_response({ "last_id": params["last_id"], "list": visitor_dict_list })
def post(self, params): # 处理自己关注自己的情况 if params["user_id"] == params["follow_id"]: return json_fail_response(2301) user_follow = FollowModel.query_user_follow(user_id=params["user_id"], follow_id=params["follow_id"]) result = dict() if not user_follow: user_follow = FollowModel() user_follow.user_id = params["user_id"] user_follow.follow_id = params["follow_id"] user_follow.status = params["status"] db.session.add(user_follow) db.session.commit() # 添加新的关注的redis if params["status"] == 1: RedisModel.add_new_message(params["follow_id"], RedisModel.new_follow) result = { "data": 1, "message": "关注成功" if params["status"] == 1 else "取消成功" } IndexHandler.update_social_meta(params["user_id"], params["follow_id"], params["status"]) elif user_follow.status != params["status"]: user_follow.status = params["status"] db.session.commit() # 添加新的关注的redis if params["status"] == 1: RedisModel.add_new_message(params["follow_id"], RedisModel.new_follow) result = { "data": 1, "message": "关注成功" if params["status"] == 1 else "取消成功" } IndexHandler.update_social_meta(params["user_id"], params["follow_id"], params["status"]) elif user_follow.status == 1: result = { "data": 1, "message": "已关注", } follow_status = FollowModel.query_relation_to_user_list(params["user_id"], [params["follow_id"]]) result["follow_status"] = follow_status[params["follow_id"]] UserInfoModel.query_user_model_by_id(params["user_id"], True) UserInfoModel.query_user_model_by_id(params["follow_id"], True) return json_success_response(result)
def post(self, params): if params["user_id"] == g.account["user_id"]: return json_fail_response(2411) result = dict() RedisModel.add_new_message( params["user_id"], RedisModel.private_image_want if params["type"] == 11 else RedisModel.private_video_want) result["data"] = 1 result["message"] = "邀请成功" return json_success_response(result)
def get(self, *args): user_id = g.account["user_id"] user_info = UserInfoModel.query_user_model_by_id(user_id) if not user_info: return json_success_response({}) result = dict() result["user_info"] = UserInfoModel.format_user_info(user_info) result["profit_today"] = 0 result["ok_percent"] = UserInfoModel.calculate_ok_percent(user_id) invite_code = UserInviteCodeModel.query_user_invite_code(user_id) result["invite_url"] = user_invite_url + invite_code result["new_visitor"] = RedisModel.query_new_message( user_id, RedisModel.new_visitor) result["follow_add"] = 0 social_meta = SocialMetaModel.query_social_meta_info( g.account["user_id"]) result["wechat_info"] = MeHandler.format_wechat_info( g.account["user_id"], social_meta.wechat_want if social_meta else 0) return json_success_response(result)
def get(self, params): RedisModel.reset_new_message(g.account["user_id"], RedisModel.new_comment) comment_list = CommentRelationModel.query_relation_info( g.account["user_id"], 20, params["last_id"]) if not comment_list: return json_success_response(list()) comment_id_list = array_column(comment_list, "comment_id") comment_info_list = CommentModel.query_comment_list(comment_id_list) comment_info_dict = array_column_key(comment_info_list, "comment_id") if not comment_info_list: return json_success_response(list()) result = list() for comment_relation_model in comment_list: share_info = GetCommentHandler.query_share_info( comment_relation_model.share_id) if not share_info: continue if comment_info_dict[comment_relation_model. comment_id].user_id == g.account["user_id"]: continue user_info = UserInfoModel.query_user_model_by_id( comment_relation_model.user_id) item = dict() item["share_id"] = comment_relation_model.share_id item["share_img"] = share_info["image"] item["share_content"] = share_info["content"] item["share_nickname"] = share_info["nickname"] item["content"] = comment_info_dict[ comment_relation_model.comment_id].content item["created_time"] = comment_relation_model.created_time item["status"] = comment_relation_model.status item["comment_id"] = comment_relation_model.comment_id item["user_info"] = UserInfoModel.format_user_info(user_info) result.append(item) return json_success_response(result)
def update_order(params, order_info, meta_info): # 更新OrderInfoModel AliHandler.update_order_info(params, order_info) # 更新OrderMeta AliHandler.update_order_meta(meta_info) # 更新Payment payment_info = AliHandler.update_payment(meta_info, order_info) if meta_info.share_id: AliHandler.update_share_meta(params, meta_info) # 想卖家推送新订单消息 if meta_info.product_type in (50, 51, 60, 70, 80, 90): RedisModel.push_list(RedisModel.order_push_list, order_info.order_id) # 通知卖家有新订单消息 if meta_info.product_type in (50, 51): RedisModel.add_new_message(meta_info.seller_id, RedisModel.new_order)
def get(self, params): result = {"offset": 0, "want_buy": 0, "result_data": list()} # 私密照片 if params["type"] == 11: # 自己看自己的私密照片 if params["user_id"] == g.account["user_id"]: result["result_data"] = ImageModel.query_private_image( params["user_id"], g.account["user_id"], params["last_id"]) # 查看别人的私密照片 else: # 第一次请求,需要生成一个随机量 if params["offset"] == 0 and params["last_id"] == 0: params["offset"] = int( PrivateLibraryHandler.random_private_library_offset( params["type"], params["user_id"])) result["result_data"] = ImageModel.query_random_private_image( params["user_id"], g.account["user_id"], params["last_id"], params["offset"]) result["want_buy"] = RedisModel.query_new_message( params["user_id"], RedisModel.private_image_want) # 私密视频 else: if params["user_id"] == g.account["user_id"]: result["result_data"] = VideoModel.query_private_video( params["user_id"], g.account["user_id"], params["last_id"]) else: if params["offset"] == 0 and params["last_id"] == 0: params["offset"] = int( PrivateLibraryHandler.random_private_library_offset( params["type"], params["user_id"])) result["result_data"] = VideoModel.query_random_private_video( params["user_id"], g.account["user_id"], params["last_id"], params["offset"]) result["want_buy"] = RedisModel.query_new_message( params["user_id"], RedisModel.private_video_want) return json_success_response(result)
def post(self, params): img_uploader = UploadImage() result = [] if params["type"] == 11: if not img_uploader.images: return json_fail_response(2402) img_uploader.save_images() result = UploadPrivateLibraryHandler.upload_private_images( img_uploader.images, g.account["user_id"]) RedisModel.reset_new_message(g.account["user_id"], RedisModel.private_image_want) elif params["type"] == 31: if not img_uploader.images: return json_fail_response(2203) video_uploader = UploadVideo() if not video_uploader.videos: return json_fail_response(2410) img_uploader.save_images() video_uploader.save_videos() result = UploadPrivateLibraryHandler.upload_private_video( video_uploader.videos[0]["video"], img_uploader.images[0]["image"], g.account["user_id"], params["price"]) RedisModel.reset_new_message(g.account["user_id"], RedisModel.private_video_want) PrivateLibraryHandler.random_private_library_offset( params["type"], g.account["user_id"], True) return json_success_response(result)
def get(self): result = {"new_comment": 0, "image_url": ""} new_comment = RedisModel.query_new_message(g.account["user_id"], RedisModel.new_comment) result["new_comment"] = new_comment if new_comment: relation_list = CommentRelationModel.query_relation_info( g.account["user_id"], per_page=3, last_cid=0) for model in relation_list: if model.user_id != g.account["user_id"]: user_info = UserInfoModel.query_user_model_by_id( model.user_id) result["image_url"] = UserInfoModel.format_user_info( user_info)["avatar"] break return json_success_response(result)
def get(self, params): if params["user_id"] == 0: return json_fail_response(2101) user_info = UserInfoModel.query_user_model_by_id(params["user_id"]) result = UserInfoModel.format_user_info(user_info) social_meta_info = SocialMetaModel.query_social_meta_info( params["user_id"]) result["share_num"] = social_meta_info.share if social_meta_info else 0 result[ "follow_num"] = social_meta_info.following if social_meta_info else 0 result[ "fans_num"] = social_meta_info.follower if social_meta_info else 0 result["follow_status"] = FollowModel.query_relation_to_user( g.account["user_id"], params["user_id"]) result["album"] = UserInfoModel.query_user_album(params["user_id"]) social_page_info = SocialPageModel.query_social_page_model( params["user_id"]) result["user_banner"] = social_page_info.get("cover", "") result["user_banner_type"] = social_page_info.get("cover_type", 1) if result["user_banner_type"] == 2: result["orientation"] = "" result["user_banner_cover"] = "" if params["user_id"] == g.account["user_id"]: result["profit"] = IndexHandler.query_user_profit( params["user_id"]) if result["identified"] == 1: result["identify_title"] = "官方认证:" + result["identify_title"] result["wechat_info"] = MeHandler.format_wechat_info( params["user_id"], social_meta_info.wechat_want if social_meta_info else 0) user_location = UserLocationModel.query.filter( UserLocationModel.id == user_info.location_id).first() result["latitude"] = user_location.latitude if user_location else 0 result["longitude"] = user_location.longitude if user_location else 0 result["changeable_aha"] = 1 result["aha_id"] = '' aha_info = AhaAccountModel.query_aha_account_by_id(params['user_id'], auto_formated=False) if aha_info: result["changeable_aha"] = aha_info.changeable_aha if aha_info.changeable_aha == 0: result["aha_id"] = aha_info.aha_id # 最近的动态 result["share_info"] = ShareModel.query_recent_share_photo( params['user_id'], g.account["user_id"]) # 是否有交易记录 result["had_trade"] = 1 # 备注昵称 result["remark_name"] = "" last_login = OpenLogModel.query_last_login(params["user_id"]) result["last_login"] = 0 if last_login: result["last_login"] = time.time() - time.mktime( last_login.created_time.timetuple()) # 插入访客记录 if g.account["user_id"] != 0 and g.account["user_id"] != params[ "user_id"]: RedisModel.add_new_message(params["user_id"], RedisModel.new_visitor) VisitorRecordModel(user_id=params["user_id"], visitor_user_id=g.account["user_id"]) return json_success_response(result)
def post(self, params): share_info = ShareModel.query_share_model(params["share_id"], status=status_private) if not share_info: return json_fail_response(2405) comment_model = None # 回复某一条评论 if params["reply_comment_id"]: comment_model = CommentModel.query_comment_by_id(params["reply_comment_id"]) if not comment_model: return json_fail_response(2406) if comment_model.layer_comment_id: layer_comment_model = CommentModel.query_comment_by_id(comment_model.layer_comment_id) if not layer_comment_model: return json_fail_response(2406) comment = CommentModel() comment.share_id = params["share_id"] comment.user_id = g.account["user_id"] comment.reply_comment_id = params["reply_comment_id"] comment.content = params["content"] comment.type = params["type"] comment.status = 1 if params["reply_comment_id"]: if not comment_model.layer_comment_id: comment.layer_comment_id = comment_model.comment_id else: comment.layer_comment_id = comment_model.layer_comment_id if comment_model.type == 1: comment.type = 1 db.session.add(comment) db.session.commit() ShareMetaModel.update_share_meta_model(params["share_id"], share_info.user_id, ["comment"]) result = comment.to_dict() user = UserInfoModel.query_user_model_by_id(g.account["user_id"]) result["user_info"] = UserInfoModel.format_user_info(user) if comment.reply_comment_id: reply_user_info = UserInfoModel.query_user_model_by_id(comment_model.user_id) result["reply_user_info"] = UserInfoModel.format_user_info(reply_user_info) # 回复的动态的所有者不是自己 if comment_model.user_id != g.account["user_id"]: CommentRelationModel(g.account["user_id"], comment_model.user_id, share_info.share_id, comment.comment_id, comment_model.comment_id) RedisModel.add_new_message(comment_model.user_id, RedisModel.new_comment) # 动态的主人不是自己 if share_info.user_id != g.account["user_id"]: if comment_model and comment_model.user_id == share_info.user_id: pass else: CommentRelationModel(g.account["user_id"], share_info.user_id, share_info.share_id, comment.comment_id, params["reply_comment_id"]) RedisModel.add_new_message(share_info.user_id, RedisModel.new_comment) share_meta = ShareMetaModel.query_share_meta_model(params["share_id"]) result["comment_count"] = share_meta.comment if share_meta else 0 # 回复的数据结构 if params["reply_comment_id"]: result = { "comment_id": comment.comment_id, "share_id": comment.share_id, "user_id": comment.user_id, "reply_comment_id": comment.reply_comment_id, "content": comment.content, "type": comment.type, "status": comment.status, "created_time": comment.created_time, "nickname": user.nickname, "reply_nickname": reply_user_info.nickname, } return json_success_response(result)