コード例 #1
0
ファイル: message.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('record_id', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        board = DB.session.query(MessageBoard).\
            filter(MessageBoard.record_id == args.record_id).\
            first()
        if board is None:
            return CommonUtil.json_response(-1, '记录不存在')

        # 用户留言
        user_msgs = DB.session.query(MessageBoardMsg.message_id, MessageBoardMsg.message, MessageBoardMsg.create_at,
                                MessageBoardMsg.is_admin, User.username, User.avatar).\
            join(User). \
            filter(MessageBoardMsg.board_id == board.id).\
            order_by(MessageBoardMsg.create_at.desc()).\
            all()
        user_msgs = CommonUtil.sql_result_to_json(user_msgs)

        # 管理呐留言,因为没有user_id,所以分两次查询
        admin_msgs = DB.session.query(MessageBoardMsg.message_id, MessageBoardMsg.message, MessageBoardMsg.create_at,
                         MessageBoardMsg.is_admin). \
            filter(MessageBoardMsg.is_admin == 1). \
            filter(MessageBoardMsg.board_id == board.id). \
            order_by(MessageBoardMsg.create_at.desc()). \
            all()
        admin_msgs = CommonUtil.sql_result_to_json(admin_msgs)

        msgs = user_msgs + admin_msgs
        # 排序
        msgs = sorted(msgs, key=lambda x: x['create_at'])

        dic = {
            'message_id': fields.String,
            'message': fields.String,
            'create_at': ConvertTimeStamp(),
            'is_admin': fields.Integer,
            'username': ConvertEmptyStr(),
            'avatar': ConvertEmptyStr,
        }

        return CommonUtil.json_response(0, '获取成功', marshal(msgs, dic))
コード例 #2
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('page', required=True)
        parser.add_argument('size', required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        page = int(args.page)
        size = int(args.size)

        if Valid.is_non_empty_str(args.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'order_no':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.order_no.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).\
                    all()
                count = DB.session.query(Order).\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.order_no.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            elif args.searchType == 'from_account':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_account.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_account.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            elif args.searchType == 'from_email':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_email.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_email.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            else:
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
        else:
            orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                join(Product) .\
                filter(Product.id == Order.product_id) .\
                filter(Order.merchant_id == result.data.id). \
                order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).all()
            count = DB.session.query(Order).\
                filter(Order.merchant_id == result.data.id).\
                count()
            orders = CommonUtil.sql_result_to_json(orders)

        dic = {
            'order_no': fields.String,
            'platform_order_no': fields.String,
            'platform': fields.Integer,
            'create_at': ConvertFormatTime(),
            'confirm_at': ConvertFormatTime(),
            'cost': fields.String,
            'from_account': fields.String,
            'from_email': fields.String,
            'from_nickname': fields.String,
            'message': fields.String,
            'product_name': fields.String(attribute='name'),
            'productId': fields.String(attribute='record_id')
        }

        data = {'list': marshal(orders, dic), 'totalCount': math.ceil(count)}

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #3
0
ファイル: message.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('page', type=int, required=True)
        parser.add_argument('size', type=int, required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_non_empty_str(args.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'username':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.username.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.username.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            elif args.searchType == 'nick_name':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.nick_name.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.nick_name.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            elif args.searchType == 'message':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(MessageBoardMsg.message.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(MessageBoardMsg.message.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            else:
                boards = None
                count = 0
        else:
            boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                      User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                join(User, MessageBoardMsg). \
                filter(MessageBoard.user_id == User.id). \
                filter(MessageBoard.id == MessageBoardMsg.board_id). \
                order_by(MessageBoard.create_at.desc()). \
                limit(args.size).offset((args.page - 1) * args.size). \
                all()
            boards = CommonUtil.sql_result_to_json(boards)
            count = DB.session.query(MessageBoard).count()

        dic = {
            'record_id': fields.String,
            'create_at': ConvertTimeStamp(),
            'close_at': ConvertTimeStamp(),
            'username': fields.String,
            'message': fields.String,
            'avatar': fields.String,
            'nick_name': fields.String
        }

        data = {'list': marshal(boards, dic), 'totalCount': math.ceil(count)}

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #4
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('productId', required=True)
        parser.add_argument('page', required=True)
        parser.add_argument('size', required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        page = int(args.page)
        size = int(args.size)

        product = DB.session.query(Product).filter(
            Product.record_id == args.productId).filter(
                Product.merchant_id == result.data.id).first()
        if product is None:
            if Valid.is_non_empty_str(
                    args.searchType) and Valid.is_non_empty_str(
                        args.searchWords):
                if args.searchType == 'content':
                    stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                              ProductStock.sold_at, Product.name). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(Product.id == ProductStock.product_id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                        all()
                    count = DB.session.query(ProductStock). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(Product.id == ProductStock.product_id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        count()
                    stocks = CommonUtil.sql_result_to_json(stocks)
            else:
                stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                          ProductStock.sold_at, Product.name). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.id == ProductStock.product_id). \
                    order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(ProductStock). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.id == ProductStock.product_id). \
                    count()
                stocks = CommonUtil.sql_result_to_json(stocks)
        else:
            if Valid.is_non_empty_str(
                    args.searchType) and Valid.is_non_empty_str(
                        args.searchWords):
                if args.searchType == 'content':
                    stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                              ProductStock.sold_at, Product.name). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(ProductStock.product_id == product.id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                        all()
                    count = DB.session.query(ProductStock). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(ProductStock.product_id == product.id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        count()
                    stocks = CommonUtil.sql_result_to_json(stocks)
            else:
                stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                          ProductStock.sold_at, Product.name). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(ProductStock.product_id == product.id). \
                    order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(ProductStock).\
                    filter(ProductStock.product_id == product.id). \
                    filter(Product.merchant_id == result.data.id). \
                    count()
                stocks = CommonUtil.sql_result_to_json(stocks)

        dic = {
            'stockId': fields.String(attribute='record_id'),
            'content': fields.String,
            'create_at': ConvertFormatTime(),
            'sold_at': ConvertFormatTime(),
            'order_no': fields.String,
            'product_name': fields.String(attribute='name')
        }

        data = {'list': marshal(stocks, dic), 'totalCount': math.ceil(count)}

        return CommonUtil.json_response(0, '获取成功', data)