Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)