Exemple #1
0
    def get(self, params):
        if not params["user_id"]:
            params["user_id"] = g.account["user_id"]

        share_list = ShareModel.query_offer_share_list(params["user_id"],
                                                       params["last_id"])
        return json_success_response(
            ShareModel.format_share_model(share_list, g.account["user_id"]))
Exemple #2
0
    def get(self, params):
        login_user_id = g.account["user_id"]

        is_self = params["user_id"] == login_user_id

        share_model_list = ShareModel.query_user_share_list(
            params["user_id"] if not is_self else None,
            login_user_id if is_self else 0, 20, params["last_id"])
        result = ShareModel.format_share_model(share_model_list, login_user_id)
        return json_success_response(result)
Exemple #3
0
    def post(self, params):
        img_upload = UploadImage()
        video_upload = UploadVideo()

        if params["type"] == 10:
            if not img_upload.images:
                return json_fail_response(2201)
            img_upload.save_images()
        elif params["type"] == 30:
            if not video_upload.videos:
                return json_fail_response(2202)
            if not img_upload.images:
                return json_fail_response(2203)
            img_upload.save_images()
            video_upload.save_videos()

        share = ShareModel()
        share.content = params["content"]
        share.user_id = g.account["user_id"]
        share.type_id = params["type"]
        share.price = params["price"] * 100
        share.position = params["position"]
        # 默认需要进入审核状态
        share.status = 3
        share.data = params["at_info"]

        db.session.add(share)
        db.session.commit()

        # 更新图片数据
        if params["type"] == 10:
            self.update_image(img_upload.images, share)

        # 更新视频动态数据
        elif params["type"] == 30:
            img_model = img_upload.images[0]["image"]
            video_model = video_upload.videos[0]["video"]
            self.update_video(video_model, share, img_model)

        # 更新social_meta
        SocialMetaModel.update_social_meta_model(share.user_id, ["share"],
                                                 meta_add=True)

        # 更新share_meta
        ShareMetaModel.update_share_meta_model(share.share_id, share.user_id)

        # 创建首页推荐数据
        ShareRecommendModel(share.share_id,
                            share.user_id,
                            position=0,
                            status=3)

        share_info = ShareModel.format_share_model([share])

        return json_success_response(share_info)
    def get(self, params):

        user_id = g.account["user_id"]

        follow_user_id_list = FollowModel.query_follow_user_list(user_id)
        follow_user_id_list = list(set(follow_user_id_list))
        share_model_list = ShareModel.query_user_share_list(
            follow_user_id_list, user_id, 20, params["last_id"], 0)
        share_info_list = ShareModel.format_share_model(
            share_model_list, user_id)
        return json_success_response(share_info_list)
Exemple #5
0
 def get(self, params):
     # 查询到被推荐动态的id
     share_id_list = ShareRecommendModel.query_share_recommend_id_list(
         params["position"], g.account.get("user_id", 0),
         params["share_id"])
     # 根据动态id查询动态详细信息
     share_list = ShareModel.query_share_info_list(share_id_list)
     # 格式化动态
     result = ShareModel.format_share_model(share_list,
                                            account=g.account["user_id"])
     # 返回结果
     return json_success_response(result)
Exemple #6
0
    def get(self, params):
        share_model = ShareModel.query_share_model(params["share_id"],
                                                   status=status_private)
        if not share_model:
            return json_fail_response(2405)

        share_info = ShareModel.format_share_model([share_model],
                                                   g.account["user_id"])[0]
        like_list = LikeModel.query_like_list(params["share_id"], 0)
        share_info["like_list"] = like_list

        del share_info["price"]
        del share_info["product_id"]

        return json_success_response(share_info)
Exemple #7
0
    def format_offer_info(offer_model, share_model, login_user_id):
        if not offer_model:
            return dict()

        icon_info = RewardIconModel.query_icon_with_id(offer_model.present_id)

        if not share_model:
            from app.models.social.share import ShareModel
            share_model = ShareModel.query_share_model(offer_model.share_id)

        result = dict()

        result["present_url"] = icon_info.url if icon_info else ""
        result["price"] = share_model.price / 100
        result["total_number"] = offer_model.total_number
        result["join_number"] = offer_model.join_number
        result["status"] = offer_model.status
        result["offer_status"] = offer_model.offer_status
        result["limit_time"] = (offer_model.due_time - datetime.datetime.now()).seconds

        offer_enter = OfferListModel.check_offer_enter_status(offer_model.offer_id, login_user_id)
        result["enter_status"] = 1 if offer_enter else 0

        if offer_model.offer_status == 3:
            winner_info = UserInfoModel.query_user_model_by_id(offer_model.winner_user_id)
            result["winner"] = UserInfoModel.format_user_info(winner_info)
        elif offer_model.offer_status in [1, 2]:
            result["list"] = OfferListModel.query_offer_list(offer_model.offer_id)

        return result
Exemple #8
0
    def query_share_info(share_id):
        share_info = ShareModel.query_share_model(share_id)
        if not share_info or share_info.status not in status_public:
            return None

        user_info = UserInfoModel.query_user_model_by_id(share_info.user_id)
        if share_info.type_id == 10:
            image = ImageModel.query.filter_by(
                share_id=share_id,
                status=1).order_by(ImageModel.image_id.asc()).first()
            image_url = ImageModel.generate_image_url(image, 'c')
        elif share_info.type_id == 11:
            image = ImageModel.query.filter_by(
                share_id=share_id,
                status=1).order_by(ImageModel.image_id.asc()).first()
            image_url = ImageModel.generate_image_url(image, 'x')
        elif share_info.type_id == 30:
            image_url = ""
        else:
            image_url = UserInfoModel.format_user_info(user_info)["avatar"]

        result = {
            "image": image_url,
            "content": share_info.content,
            "nickname": user_info.nickname,
        }
        return result
Exemple #9
0
 def check_share_info(share_id):
     order_meta = dict()
     share_model = ShareModel.query_share_model(share_id)
     if share_model:
         order_meta["seller_id"] = share_model.user_id
         order_meta["share_id"] = share_model.share_id
         order_meta["price"] = share_model.price
         order_meta["product_id"] = share_model.product_id
         order_meta["user_id"] = share_model.user_id
     return order_meta
Exemple #10
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)
Exemple #11
0
    def query_share_comment_list(share_id,
                                 login_user_id=0,
                                 last_id=0,
                                 per_page=20):
        """
        TODO:待完成
        """
        query = CommentModel.query.filter_by(share_id=share_id, status=1)

        if last_id:
            query = query.filter(CommentModel.comment_id < last_id)

        share_model = ShareModel.query_share_model(share_id,
                                                   status=status_private)

        # 如果访问者不是发帖者,则只能显示自己的悄悄话和公开评论
        if share_model.user_id != login_user_id:
            query = query.filter(
                or_(
                    CommentModel.type == 0,
                    and_(CommentModel.type == 1,
                         CommentModel.user_id == login_user_id),
                ))

        comment_list = query.filter(CommentModel.status == 1).order_by(
            CommentModel.comment_id.desc()).limit(per_page).all()
        if not comment_list:
            return []

        comment_dict_list = array_column_key(comment_list, "comment_id")

        # 获取所有的父评论id并去重
        layer_comment_id_list = list(
            set(array_column(comment_list, "layer_comment_id")))

        # 查找所有父评论的详情
        query = CommentModel.query.filter(
            CommentModel.comment_id.in_(layer_comment_id_list),
            CommentModel.status == 1)
        layer_comment_model_list = query.order_by(
            CommentModel.comment_id.desc()).all()

        for layer_comment_model in layer_comment_model_list:
            if layer_comment_model.type == 1 and login_user_id not in [
                    layer_comment_model.user_id
            ]:
                continue

            comment_model = comment_dict_list.get(
                layer_comment_model.comment_id, None)
            if not comment_model:
                continue

        result = list()
        for comment_model in comment_list:
            item = comment_model.to_dict()
            user_model = UserInfoModel.query_user_model_by_id(
                comment_model.user_id)
            item["user_info"] = UserInfoModel.format_user_info(user_model)
            if not item.get("layer_info", None):
                item["layer_info"] = []
            result.append(item)

        return result
Exemple #12
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)
Exemple #13
0
    def post(self, params):

        share_model = ShareModel.query_share_model(params["share_id"],
                                                   status=status_private)
        if not share_model:
            return json_fail_response(2405)

        like_model = LikeModel.query_like_model(g.account["user_id"],
                                                params["share_id"])
        user_info = UserInfoModel.query_user_model_by_id(g.account["user_id"])
        if not like_model:

            if params["status"] != 1:
                result = {
                    "data": 0,
                    "message": "操作失败",
                }
                return json_success_response(result)

            like_model = LikeModel()
            like_model.share_id = params["share_id"]
            like_model.user_id = g.account["user_id"]
            like_model.status = 1
            db.session.add(like_model)
            db.session.commit()

            result = {
                "data": 1,
                "status": params["status"],
                "user_info": UserInfoModel.format_user_info(user_info),
                "message": "点赞成功",
            }
            ShareMetaModel.update_share_meta_model(share_model.share_id,
                                                   share_model.user_id,
                                                   ["like"])
        elif like_model.status != params["status"]:
            like_model.status = params["status"]
            db.session.commit()

            result = {
                "data": 1,
                "status": params["status"],
                "user_info": UserInfoModel.format_user_info(user_info),
                "message": "点赞成功" if params["status"] == 1 else "取消点赞成功",
            }
            ShareMetaModel.update_share_meta_model(share_model.share_id,
                                                   share_model.user_id,
                                                   ["like"],
                                                   params["status"] == 1)
        else:
            if params["status"] == 1:
                result = {
                    "data": 0,
                    "status": params["status"],
                    "user_info": UserInfoModel.format_user_info(user_info),
                    "message": "已点赞",
                }
            else:
                result = {
                    "data": 0,
                    "status": params["status"],
                    "user_info": UserInfoModel.format_user_info(user_info),
                    "message": "未点赞",
                }

        share_meta = ShareMetaModel.query.filter_by(
            share_id=share_model.share_id).first()
        result["like_count"] = share_meta.like
        return json_success_response(result)
Exemple #14
0
    def post(self, params):
        user = UserInfoModel.query_user_model_by_id(g.account["user_id"])
        if user.gender != 1:
            return json_fail_response(2125)

        if not OfferModel.check_offer_publish(g.account["user_id"]):
            return json_fail_response(2126)

        # 礼物信息
        icon_model = RewardIconModel.query_icon_with_id(params["present_id"])

        offer_params = {
            "user_id": g.account["user_id"],
            "share_id": 0,
            "present_id": params["present_id"],
            "total_number": icon_model.join,
            "status": 1,
            "offer_status": 1
        }
        offer = OfferModel(params=offer_params)
        if not offer:
            return json_fail_response(2127)

        share = ShareModel()
        share.user_id = g.account["user_id"]
        share.type_id = 90
        share.content = params["content"]
        share.price = icon_model.price
        share.status = 0
        share.offer_id = offer.offer_id
        share.data = params["at_info"]

        db.session.add(share)
        try:
            db.session.commit()
        except:
            return json_fail_response(2127)

        params["price"] = icon_model.price
        params["message"] = ""
        params["type_id"] = 90

        order_meta = {
            "buyer_id": g.account["user_id"],
            "seller_id": 0,
            "share_id": share.share_id,
            "price": icon_model.price
        }

        # 创建订单
        result = IndexHandler.generate_order(params, order_meta)

        # 修改offer表
        offer.share_id = share.share_id
        offer.order_id = result["order_info"]["order_id"]
        db.session.commit()

        success, result = IndexHandler.generate_payment_params(
            params, result["payment_param"], result["order_info"])

        if not success:
            return json_fail_response(result)

        return json_success_response(result)