示例#1
0
文件: admin.py 项目: testjie/Lux
def query_paging_articles():
    """
    文章分页查询
    :arg {"page":1,"token": "lup5gvda-5vwa-q3yp-kub5-sz69v6qxtgr3"}
    :return: json
    详细格式如下,此接口受前端限制,可能会更改
    {
        "code":200                                              # 状态码
        "msg":"ok",                                             # msg
        "data":{                                                 # 返回数据对象
            {"articles":[                                       # 文章列表
                [文章1],[文章2],[文章3],[文章4], ....[文章10]
            ]},
            {
                "current_page":1                                # 当前页码
            },
            {
                "dic_list":[1,4]                                # 通过这个循环来标注下一页 下下一页的参数 例如 articles?p=2;在这里需要post传json格式{"page":1}
            },
            {
                "show_index_status":0                          # 是否显示首页,0为不显示
            },
            {
                "total":3                                       # 共有几页
            }
        }
    }
    """
    paging_info = request.get_json()
    current_page = paging_info.get("page")  # 当前页面
    show_shouye_status = 0  # 显示首页状态
    if current_page == '':
        current_page = 1
    else:
        current_page = int(current_page)
        if current_page > 1:
            show_shouye_status = 1

    limit_start = (int(current_page) - 1) * 10

    # 查询n-10*n条记录,首页
    sql = "select * from tbl_article limit %d,10" % limit_start
    article_list = query(sql)

    # 查询总记录和计算总页数
    sql = "select * from tbl_article"
    count = len(query(sql))  # 总记录
    total = int(math.ceil(count / 10.0))  # 总页数

    dic = _get_page(total, current_page)

    datas = {
        "articles": article_list,
        "current_page": int(current_page),
        'total': total,
        'show_index_status': show_shouye_status,
        'show_range': dic  # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range
    }

    return json(get_json(data=datas))
示例#2
0
def index():
    """
    首页接口
    :arg
    :return json
    """
    datas = {}  # 返回的数据集,包括用户信息、文章分类和信息、跑马灯、轮播图

    # 查询文章信息
    articles = []
    for type in range(1, 6):
        title = "article" + str(type)
        query_article_sql = "select * from tbl_article where type=%s LIMIT 10" % str(
            type)
        articles.append({title: query(query_article_sql)})
    # 查询跑马灯信息
    query_anno_sql = "select * from tbl_announcement where status=1 LIMIT 10"
    # 查询轮播图信息
    query_all_carouses_sql = "select a.*, b.path as imgPath " \
                             "from tbl_carouse as a JOIN tbl_image_sources as b " \
                             "where a.imgId=b.id and b.status=1 and a.status=1;"

    datas = {
        "articles": articles,
        "annos": query(query_anno_sql),
        "carouses": query(query_all_carouses_sql),
        "userInfo": session.get("user")
    }

    return json(get_json(data=datas))
示例#3
0
文件: admin.py 项目: testjie/Lux
def query_paging_users():
    """
    用户分页查询
    :arg {"page":2,"token": "te4uzdia-gkee-ziiy-5cjg-zz8qji20z7a6"}
    :return: json
    详细格式如下,此接口受前端限制,可能会更改
    {
        "code":200                                              # 状态码
        "msg":"ok",                                             # msg
        "data":{                                                 # 返回数据对象
            {"articles":[                                       # 文章列表
                [用户1],[用户2],[用户3],[用户4], ....[用户10]
            ]},
            {
                "current_page":1                                # 当前页码
            },
            {
                "dic_list":[1,4]                                # 通过这个循环来标注下一页 下下一页的参数 例如 articles?p=2;在这里需要post传json格式{"page":1}
            },
            {
                "show_index_status":0                          # 是否显示首页,0为不显示
            },
            {
                "total":3                                       # 共有几页
            }
        }
    }
    """
    paging_info = request.get_json()
    current_page = paging_info.get("page")  # 当前页面
    show_shouye_status = 0  # 显示首页状态
    if current_page == '':
        current_page = 1
    else:
        current_page = int(current_page)
        if current_page > 1:
            show_shouye_status = 1

    limit_start = (int(current_page) - 1) * 10

    # 查询n-10*n条记录,首页
    sql = "select * from tbl_user limit %d,10" % limit_start
    user_list = query(sql)

    # 查询总记录和计算总页数
    sql = "select * from tbl_user"
    count = len(query(sql))  # 总记录
    total = int(math.ceil(count / 10.0))  # 总页数

    dic = _get_page(total, current_page)

    datas = {
        "users": user_list,
        "currentPage": int(current_page),
        'total': total,
        'showIndexStatus': show_shouye_status,
        'showRange': dic  # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range
    }

    return json(get_json(data=datas))
示例#4
0
def cancel_article_collent():
    """
    取消文章关注
    :arg {"articleId":1,"token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"}
    :return:
    """
    article_info = request.get_json()
    article_id = article_info.get("articleId")
    # 参数校验
    if not _parameters_filter([article_id]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 检查是否已经收藏过了
    user_id = session.get("user").get("id")
    query_article_collect_detail = "select * from tbl_article_collect as a " \
                                   "where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id)
    if not query(query_article_collect_detail):
        return json(get_json(code=-100, msg="您还没有收藏此文章!"))

    # 修改状态,如果存在记录就修改,没有就增加
    query_article_like_detail = "select * from tbl_article_collect as a" \
                                " where a.userId=%d and a.articleId=%d" % (user_id, article_id)
    if query(query_article_like_detail):
        update_article_collect_sql = "update tbl_article_collect as a set a.status=1 " \
                                     "where a.userId=%d and a.articleId=%d" % (user_id, article_id)
    else:
        update_article_collect_sql = "update tbl_article_collect as a set a.status=0 " \
                                     "where userId=%d and articleId=%d" % (user_id, article_id)
    if excute(update_article_collect_sql):
        return json(get_json(msg="成功取消收藏此文章!"))

    return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
示例#5
0
def article_collect():
    """
    收藏文章
    :arg {"articleId":1,"token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"}
    :return: json
    """
    article_info = request.get_json()
    article_id = article_info.get("articleId")
    # 参数校验
    if not _parameters_filter([article_id]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 检查是否已经收藏过文章
    user_id = session.get("user").get("id")
    query_article_collect_detail = "select * from tbl_article_collect as a " \
                                   "where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id)
    if query(query_article_collect_detail):
        return json(get_json(code=-100, msg="您已经收藏过此文章了!"))

    # 检查是否存在文章
    query_article_sql = "select * from tbl_article where id=%d and status=1" % article_id
    if not query(query_article_sql):
        return json(get_json(code=-100, msg="文章不在了...!"))

    # 增加文章收藏记录
    insert_article_collect_sql = "insert into tbl_article_collect " \
                                 "values(NULL, %d, %d, 1, '%s', NULL )" % (user_id, article_id, get_current_time())
    if excute(insert_article_collect_sql):
        return json(get_json(msg="收藏文章成功!"))

    return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
示例#6
0
def user_index():
    """
    :params {"token":"pmqkp62j-n5pw-w882-zk3e-qh8722mivo4u"}
    获取用户个人中心信息,包括历史评论、收藏文章、浏览记录、个人资料
    :return: json
    """
    # 历史浏览
    user = _get_user_session()["userInfo"]
    query_comment_his_sql = "select * from tbl_article_comment as " \
                            "a join tbl_article as b where a.articleId=b.id " \
                            "and a.userId=%d and a.status=1 and b.status=1 limit 10" % user.get("id")
    # 收藏文章
    query_collect_sql = "select a.* from tbl_article as a JOIN " \
                        "tbl_article_collect as b on a.id=b.articleId " \
                        "and b.userId=%s and a.status=1 and b.status=1 " \
                        "limit 10" % user.get("id")
    # 浏览记录
    query_browsing_his_sql = "select a.* from tbl_article as a JOIN " \
                             "tbl_article_browsing_history as b on a.id=b.articleId " \
                             "and b.userId=%d and a.status=1 and b.status=1 limit 10" % user.get("id")
    # 个人喜欢
    query_like_sql = "select a.* from tbl_article as a JOIN " \
                     "tbl_article_like as b on a.id=b.articleId " \
                     "and b.userId=%d and a.status = 1 and b.status=1 limit 10" % user.get("id")

    # 构造响应数据
    datas = {
        "userInfo": _get_user_session().get("userInfo"),
        "likes": query(query_like_sql),
        "comments": query(query_comment_his_sql),
        "collects": query(query_collect_sql),
        "browsing": query(query_browsing_his_sql)
    }
    return json(get_json(data=datas))
示例#7
0
def article_detailes():
    """
    查询文章详情和评论
    :arg:   {"articleId":1}
    :return:
    """
    article_info = request.get_json()
    article_id = article_info.get("id")
    # id为空不允许
    if not _parameters_filter([article_id]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # -1:未登录用户
    user = session.get("user")
    if user:
        user_id = user.get("id")
    else:
        user_id = -1

    # 首先默认请求此接口为浏览了该文章
    try:
        # 增加浏览数量,如果没有浏览,则增加一条浏览数据,否则修改浏览时间
        query_article_sql = "select * from tbl_article_browsing_history " \
                            "as a where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id)
        if query(query_article_sql):
            article_browsing_sql = "update tbl_article_browsing_history set updateDate='%s'" % get_current_time(
            )
            excute(article_browsing_sql)
        else:
            article_browsing_sql = "INSERT INTO tbl_article_browsing_history " \
                                   "VALUES (NULL, %d, %d, 1, '%s',NULL)" % (user_id, article_id, get_current_time())
            excute(article_browsing_sql)

        # 查询article阅读总数
        query_article_readcount_sql = "select * from tbl_article where id=%d" % article_id
        read_counts = query(query_article_readcount_sql)[0].get(
            "readCount") + 1

        # 更新readCount总数
        update_article_browsing_count = "update tbl_article set readCount=%d, " \
                                        "updateDate='%s' where id=%d" % (read_counts, get_current_time(), article_id)
        excute(update_article_browsing_count)
    except Exception as e:
        print(e)
        pass

    # 查询文章和对应的评论
    query_article_sql = "select * from tbl_article where id=%s and status=1" % article_id
    query_comments_sql = "select * from tbl_article_comment where articleId=%s and status=1" % article_id
    results = {
        "article": query(query_article_sql),
        "comments": query(query_comments_sql)
    }

    return json(get_json(data=results))
示例#8
0
def user_regist():
    """
    用户注册
    :arg {"username":"******", "password":"******", "nickname":"nickname"}
    :return json
    """
    user_info = request.get_json()
    nickname = user_info.get("nickname")
    username = user_info.get("username")
    password = user_info.get("password")
    create_date = get_current_time()

    # 参数校验
    if not _parameters_filter([username, password, nickname]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 判断用户名是否已被占用
    query_user_sql = "select * from tbl_user where username='******'" % username
    if query(query_user_sql):
        return json(get_json(code=-300, msg="用户名已存在!"))

    # 没被占用,进行注册
    user_reg_sql = "insert into tbl_user values(NULL, '%s', '%s', '%s'," \
                   "NULL, 1,'','','',NULL,'','','','',NULL,'','%s',NULL)" % (username, password, nickname, create_date)
    if excute(user_reg_sql):
        return json(get_json(msg="注册成功!"))

    return json(get_json(code=-100, msg="注册失败,用户名可能已经存在了!"))
示例#9
0
文件: admin.py 项目: testjie/Lux
def add_user():
    """
    新增用户
    :arg {"username":"******", "password":"******", "nickname":"nickname", "token": "4cmhr7a8-t0zw-sskr-3e5i-o9sdxv48878p"}
    :return: json
    """
    user_info = request.get_json()
    nickname = user_info.get("nickname")
    username = user_info.get("username")
    password = user_info.get("password")
    create_date = get_current_time()

    # 参数校验
    if not _admin_parameters_filter([username, password, nickname]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 判断用户名是否已被占用
    query_user_sql = "select * from tbl_user where username='******'" % username
    if query(query_user_sql):
        return json(get_json(code=-300, msg="用户名已存在!"))

    # 没被占用,进行注册
    user_reg_sql = "insert into tbl_user values" \
                   "(NULL, '%s', '%s', '%s',NULL,1,'','','',NULL,'','','','',NULL,'','%s',NULL)" \
                   % (username, password, nickname, create_date)
    print(user_reg_sql)
    if excute(user_reg_sql):
        return json(get_json(msg="新增用户成功!"))

    return json(get_json(code=-100, msg="新增用户失败!"))
示例#10
0
def upload():
    """
    公共上传资源接口
    :arg file:上传文件格式;source:图片资源,详细请求数据参见uploadDemo.html
    :return:
    """
    # 检验来源
    file_source = request.form.get("source")
    if not _parameters_filter([file_source]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 保存图片文件到服务器
    file = request.files['file']
    file_name = create_token() + "." + file.filename.split(".")[1]
    if _upload_files(file, file_name):
        # 执行插入数据库操作
        insert_img_source_sql = "INSERT INTO tbl_image_sources " \
                                "values(NULL, '%s', 1, '%s', NULL)" % (file_name, get_current_time())
        # 执行成功返回该img信息
        if excute(insert_img_source_sql):
            query_img_sql = "select * from tbl_image_sources where path='%s'" % file_name
            datas = {"imgInfo": query(query_img_sql)}
            return json(get_json(data=datas))

    return json(get_json(code=-100, msg="操作失败!"))
示例#11
0
文件: admin.py 项目: testjie/Lux
def query_paging_comments():
    """
    用户分页查询
    :arg {"page":1}
    :return: json
    详细格式如上述接口
    """
    paging_info = request.get_json()
    current_page = paging_info.get("page")  # 当前页面
    show_shouye_status = 0  # 显示首页状态
    if current_page == '':
        current_page = 1
    else:
        current_page = int(current_page)
        if current_page > 1:
            show_shouye_status = 1

    limit_start = (int(current_page) - 1) * 10

    # 查询n-10*n条记录,首页
    sql = "select a.*, " \
          "b.content as aContent " \
          "from tbl_article_comment as a join tbl_article as b " \
          "where a.articleId = b.id limit %d,10" % limit_start
    comments_list = query(sql)

    # 查询总记录和计算总页数
    sql = "select a.*, " \
          "b.content as aContent " \
          "from tbl_article_comment as a join tbl_article as b " \
          "where a.articleId = b.id"
    count = len(query(sql))  # 总记录
    total = int(math.ceil(count / 10.0))  # 总页数

    dic = _get_page(total, current_page)

    datas = {
        "comments": comments_list,
        "currentPage": int(current_page),
        'total': total,
        'showIndexStatus': show_shouye_status,
        'showRange': dic  # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range
    }

    return json(get_json(data=datas))
示例#12
0
文件: admin.py 项目: testjie/Lux
def query_all_users():
    """
    查询所有用户
    :args {"token": "ol5r2k0p-0fn0-kbyd-1xpe-zq4n6sgk5wa5"}
    :return: json
    """
    query_users_sql = "select * from tbl_user"
    datas = {"users": query(query_users_sql)}
    return json(get_json(data=datas))
示例#13
0
文件: admin.py 项目: testjie/Lux
def query_all_articles():
    """
    查询所有文章
    :args {"token": "hq1bjvcc-o4ub-dwlv-1uok-lhmixq5lvkl3"}
    :return: json
    """
    query_articles_sql = "select * from tbl_article order by createDate desc"
    datas = {"articles": query(query_articles_sql)}
    return json(get_json(data=datas))
示例#14
0
def user_login():
    """
    用户登录
    :arg {"username":"******", "password":"******", "captcha":"123456"}
    :return json
    """
    user_info = request.get_json()
    captcha = user_info.get("captcha")
    username = user_info.get("username")
    password = user_info.get("password")

    # 参数校验
    if not _parameters_filter([username, password, captcha]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))
    # todo
    # 修改验证码
    if captcha == "123456":
        query_login_sql = "select * from tbl_user where username='******' and password='******'" % (
            username, password)
        result = query(query_login_sql)
        if result:
            if result[0].get("status") == 1:
                # 生成并插入token
                user_token = create_token()
                insert_token_sql = "update tbl_user set token='%s' where id=%d" % (
                    user_token, result[0]["id"])
                excute(insert_token_sql)

                # 查询IMG并更新Token
                query_img_sql = "select * from tbl_image_sources where id=%d" % result[
                    0].get("imgId")
                result[0]["img"] = query(query_img_sql)[0].get("path")
                result[0]["token"] = user_token

                # 保存用户信息
                _set_user_session(result[0])
                return json(get_json(data={"token": user_token}, msg="登录成功!"))
            else:
                return json(get_json(msg="登录失败, 您已经禁止登陆网站, 请联系管理员处理!"))

    return json(get_json(
        code="-100",
        msg="登录失败,用户名或密码不正确!",
    ))
示例#15
0
文件: admin.py 项目: testjie/Lux
def query_all_carouses():
    """
    :arg {"token": "qzh84z4m-vsl7-ltkq-6xzq-wur2tkts2ppw"}
    :return:
    """
    query_all_carouses_sql = "select a.*, b.path as imgPath " \
                             "from tbl_carouse as a JOIN tbl_image_sources as b " \
                             "where a.imgId=b.id;"
    datas = {"carouses": query(query_all_carouses_sql)}
    return json(get_json(data=datas))
示例#16
0
文件: admin.py 项目: testjie/Lux
def query_conditions_users():
    """
    多条件联合查询用户
    :arg
    {
        "username":"******","nickname":"user, "status":1, "sex":"男",
        "email":"*****@*****.**", "phone_num":"15000000000", "wechat":1,
        "startDate":"2017-03-23 23:59:52", "endDate":"2018-03-28 23:59:52",
        "token": "te4uzdia-gkee-ziiy-5cjg-zz8qji20z7a6"
    }
    :return: json
    """
    # 文章title查询、状态查询、来源、创建时间范围查询
    conditions = request.get_json()
    username = conditions.get("username")  # 用户名
    nickname = conditions.get("nickname")  # 昵称
    status = conditions.get("status")  # 状态
    sex = conditions.get("sex")  # 性别
    email = conditions.get("email")  # 邮箱
    phone_num = conditions.get("cellphone")  # 电话
    wechat = conditions.get("wechat")  # 微信号

    end_date = conditions.get("endDate")  # 结束时间
    start_date = conditions.get("startDate")  # 开始时间

    # 开始构造查询语句,分别根据参数是否为空来构造sql语句
    conditions_sql = "select * from tbl_user where 1=1 "
    if _admin_parameters_filter([username]):
        conditions_sql += "and username like '%" + username + "%' "
    if _admin_parameters_filter([nickname]):
        conditions_sql += "and nickname like '%" + nickname + "%' "
    if _admin_parameters_filter([status]):
        conditions_sql += "and status=%d " % status
    if _admin_parameters_filter([sex]):
        conditions_sql += "and sex='%s' " % sex
    if _admin_parameters_filter([email]):
        conditions_sql += "and email like '%" + email + "%' "
    if _admin_parameters_filter([phone_num]):
        conditions_sql += "and phone_num like '%" + phone_num + "%' "
    if _admin_parameters_filter([wechat]):
        conditions_sql += "and wechat like '%" + wechat + "%' "

    # 创建文章的开始和结束时间
    if _admin_parameters_filter([start_date]):
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and createDate > '%s' and createDate < '%s'" % (
                start_date, end_date)
        else:
            conditions_sql += "and createDate > '%s'" % start_date
    else:
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and createDate < '%s'" % end_date
    datas = {"users": query(conditions_sql)}
    return json(get_json(data=datas))
示例#17
0
文件: admin.py 项目: testjie/Lux
def query_all_announcements():
    """
    查询所有跑马灯公告:
    arg {"token": "qzh84z4m-vsl7-ltkq-6xzq-wur2tkts2ppw"}
    :return: json
    """
    query_all_anno_sql = "select a.*, " \
                         "b.username as adminName " \
                         "from tbl_announcement as a JOIN tbl_admin as b where a.userId=b.id"
    annos = {"announcements": query(query_all_anno_sql)}
    return json(get_json(data=annos))
示例#18
0
文件: admin.py 项目: testjie/Lux
def query_paging_carouses():
    """
    轮播图分页查询
    :arg {"page":1,"token": "mz3ofz13-rgph-sbi9-gg8t-xiemoczr0i9s"}
    :return: json
    详细格式如上述接口
    """
    paging_info = request.get_json()
    current_page = paging_info.get("page")  # 当前页面
    show_shouye_status = 0  # 显示首页状态
    if current_page == '':
        current_page = 1
    else:
        current_page = int(current_page)
        if current_page > 1:
            show_shouye_status = 1

    limit_start = (int(current_page) - 1) * 10

    # 查询n-10*n条记录,首页
    sql = "select a.*, b.path as imgPath  " \
          "from tbl_carouse as a JOIN tbl_image_sources as b where a.imgId=b.id limit %d,10" % limit_start
    carouses_list = query(sql)

    # 查询总记录和计算总页数
    sql = "select a.*, b.path as imgPath from tbl_carouse " \
          "as a JOIN tbl_image_sources as b where a.imgId=b.id"
    count = len(query(sql))  # 总记录
    total = int(math.ceil(count / 10.0))  # 总页数

    dic = _get_page(total, current_page)

    datas = {
        "comments": carouses_list,
        "currentPage": int(current_page),
        'total': total,
        'showIndexStatus': show_shouye_status,
        'showRange': dic  # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range
    }

    return json(get_json(data=datas))
示例#19
0
def article_like():
    """
    文章点赞
    :arg {"articleId":1,"token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"}
    :return: json
    """
    article_info = request.get_json()
    article_id = article_info.get("articleId")
    # 参数校验
    if not _parameters_filter([article_id]):
        return json(get_json(code=-200, msg="参数存在空值,请检查参数!"))

    # 检查是否已经赞过了
    user_id = session.get("user").get("id")
    query_article_like_detail = "select * from tbl_article_like as a  " \
                                "where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id)
    if query(query_article_like_detail):
        return json(get_json(code=-100, msg="您已经赞过了此文章!"))

    # 检查是否存在文章
    query_article_sql = "select * from tbl_article as a where a.id=%d and a.status=1" % article_id
    if not query(query_article_sql):
        return json(get_json(code=-100, msg="文章不在了...!"))

    # 如果存在记录则修改时间,如果没有记录则增加记录
    query_article_like_detail = "select * from tbl_article_like as a  where " \
                                "a.userId=%d and a.articleId=%d" % (user_id, article_id)
    if query(query_article_like_detail):
        update_article_collect_sql = "update tbl_article_like as a " \
                                     "set a.status=1 where a.userId=%d and a.articleId=%d" % (user_id, article_id)
    else:
        update_article_collect_sql = "insert into tbl_article_like " \
                                     "values(NULL, %d, %d, 1, '%s', NULL )" % (user_id, article_id, get_current_time())
    if excute(update_article_collect_sql):
        return json(get_json(msg="文章点赞成功!"))

    return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
示例#20
0
文件: admin.py 项目: testjie/Lux
def query_conditions_articles():
    """
    多条件联合查询文章
    :arg :
    {
    "title":"测试","status":1, "source":"测试",
    "startDate":"2017-03-23 23:59:52", "endDate":"2018-03-28 23:59:52",
    "token": "x8txta6o-rbmx-sc43-6hc4-u0prik5s8yay"
    }
    :return: json
    """
    # 文章title查询、状态查询、来源、创建时间范围查询
    conditions = request.get_json()
    title = conditions.get("title")  # 文章标题
    status = conditions.get("status")  # 状态
    source = conditions.get("source")  # 来源

    end_date = conditions.get("endDate")  # 结束时间
    start_date = conditions.get("startDate")  # 开始时间

    # 开始构造查询语句,分别根据参数是否为空来构造sql语句
    conditions_sql = "select * from tbl_article where 1=1 "
    if _admin_parameters_filter([title]):
        conditions_sql += "and title like '%" + title + "%' "
    if _admin_parameters_filter([status]):
        conditions_sql += "and status=%d " % status
    if _admin_parameters_filter([source]):
        conditions_sql += "and source like '%" + source + "%' "

    # 创建文章的开始和结束时间
    if _admin_parameters_filter([start_date]):
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and createDate > '%s' and createDate < '%s'" % (
                start_date, end_date)
        else:
            conditions_sql += "and createDate > '%s'" % start_date
    else:
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and createDate < '%s'" % end_date

    datas = {"articles": query(conditions_sql)}
    return json(get_json(data=datas))
示例#21
0
文件: admin.py 项目: testjie/Lux
def query_conditions_annos():
    """
    多条件联合查询公告
    :arg {
        "token": "qzh84z4m-vsl7-ltkq-6xzq-wur2tkts2ppw",
        "title":"公告", "status":1, "username":"******",
        "startDate":"2017-03-23 23:59:52", "endDate":"2018-04-28 23:59:52"
    }
    :return: json
    """
    # 公告标题 状态 开始时间 结束时间
    conditions = request.get_json()
    title = conditions.get("title")
    status = conditions.get("status")
    create_user = conditions.get("username")
    end_date = conditions.get("endDate")  # 结束时间
    start_date = conditions.get("startDate")  # 开始时间

    # 开始构造查询语句,分别根据参数是否为空来构造sql语句
    conditions_sql = "select a.*, " \
                     "b.username as adminName " \
                     "from tbl_announcement as a JOIN tbl_admin as b where a.userId=b.id "
    if _admin_parameters_filter([title]):
        conditions_sql += "and a.title like '%" + title + "%' "
    if _admin_parameters_filter([status]):
        conditions_sql += "and a.status=%d " % status
    if _admin_parameters_filter([create_user]):
        conditions_sql += "and b.username='******' " % create_user

    # 创建公告的开始和结束时间
    if _admin_parameters_filter([start_date]):
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate > '%s' and a.createDate < '%s'" % (
                start_date, end_date)
        else:
            conditions_sql += "and a.createDate > '%s'" % start_date
    else:
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate < '%s'" % end_date

    datas = {"comments": query(conditions_sql)}
    return json(get_json(data=datas))
示例#22
0
文件: admin.py 项目: testjie/Lux
def query_all_user_comments():
    """
    查询所有用户文章及评论
    :arg {"token": "2fvblixe-mxqg-weu5-mvqo-48ick796k009"}
    :return: cId,cUserId ... = comment表中的数据,重命名comments表是为了防止查询的字段冲突不显示
    """
    query_all_user_comments_sql = "select b.*," \
                                  "a.id as cId," \
                                  "a.userId as cUserId, " \
                                  "a.articleId as cArticleId, " \
                                  "a.content as cContent, " \
                                  "a.status as cStatus, " \
                                  "a.createDate as cCreateDate," \
                                  "a.updateDate as cUpdateDate, " \
                                  "a.fid as cFid " \
                                  "from tbl_article_comment as a join tbl_article as b where a.articleId=b.id"

    comments = {"articlesAndComments": query(query_all_user_comments_sql)}

    return json(get_json(data=comments))
示例#23
0
def update_user_info():
    """
    编辑用户信息
    :arg {
        "sex":"男","imgId":1, "age":22, "email":"*****@*****.**", "wechat":"snake", "remark":"greate full!",
        "address":"test", "nickname":"snake", "signature":"signature", "cellphone":"15000000000",
        "education":"education","token":"pmqkp62j-n5pw-w882-zk3e-qh8722mivo4u"
    }
    :return: json
    """
    user_info = request.get_json()
    sex = user_info.get("sex")
    age = user_info.get("age")
    token = user_info.get("token")
    email = user_info.get("email")
    img_id = user_info.get("imgId")
    wechat = user_info.get("wechat")
    remark = user_info.get("remark")
    address = user_info.get("address")
    nickname = user_info.get("nickname")
    signature = user_info.get("signature")
    cellphone = user_info.get("cellphone")
    education = user_info.get("education")
    updateDate = get_current_time()

    # 执行用户信息更新
    update_user_sql = "update tbl_user set nickname='%s', imgId=%d, sex='%s'," \
                      "age=%d, email='%s', wechat='%s',remark='%s',address='%s'," \
                      "nickname='%s',signature='%s',cellphone='%s',education='%s',updateDate='%s' where token='%s'" % \
                      (nickname, img_id, sex, age, email, wechat, remark, address, nickname, signature, cellphone,
                       education, updateDate, token)
    # 更新成功则重置session并返回最新的用户信息
    if excute(update_user_sql):
        user = query("select * from tbl_user where token='%s'" % token)[0]
        _set_user_session(user)

        # 返回用户信息
        return json(get_json(msg="修改成功", data=_get_user_session()))

    return json(get_json(code=-100, msg="修改失败!"))
示例#24
0
文件: admin.py 项目: testjie/Lux
def query_conditions_carouses():
    """
    多条件联合查询轮播图
    :arg
    {
        "type":1, "status":1, "startDate":"2017-03-23 23:59:52",
        "endDate":"2018-04-28 23:59:52","token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"
    }
    :return: json
    """
    # 公告标题 状态 开始时间 结束时间
    conditions = request.get_json()
    type = conditions.get("type")
    status = conditions.get("status")
    end_date = conditions.get("endDate")  # 结束时间
    start_date = conditions.get("startDate")  # 开始时间

    # 开始构造查询语句,分别根据参数是否为空来构造sql语句
    conditions_sql = "select a.*, b.path as imgPath from tbl_carouse" \
                     " as a JOIN tbl_image_sources as b where a.imgId=b.id "
    if _admin_parameters_filter([type]):
        conditions_sql += "and a.type=%d " % type
    if _admin_parameters_filter([status]):
        conditions_sql += "and a.status=%d " % status

    # 创建公告的开始和结束时间
    if _admin_parameters_filter([start_date]):
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate > '%s' and a.createDate < '%s'" % (
                start_date, end_date)
        else:
            conditions_sql += "and a.createDate > '%s'" % start_date
    else:
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate < '%s'" % end_date

    datas = {"carouses": query(conditions_sql)}
    return json(get_json(data=datas))
示例#25
0
文件: admin.py 项目: testjie/Lux
def adminlogin():
    '''
    管理员登陆
    arg:{"username":"******","password":"******"}
    return: json
    '''
    admininfo = request.get_json()
    username = admininfo["username"]
    password = admininfo["password"]
    if username != None and password != None:
        result = query(
            "SELECT * FROM tbl_admin where username = '******' and password = '******';"
            % (username, password))
        if result:
            token = create_token()
            result[0]["token"] = token
            _set_admin_session(result[0])
            excute(
                "UPDATE `tbl_admin` SET `token`='%s' WHERE (`id`='%d') LIMIT 1"
                % (token, result[0].get("id")))
            response = {}
            response["code"] = 200
            response["data"] = {"token": token}
            response["msg"] = "登陆成功!"
            return json(response)
        else:
            response = {}
            response["code"] = 200
            response["data"] = 0
            response["msg"] = "账号或者密码错误!"
            return json(response)
    else:
        response = {}
        response["code"] = 200
        response["data"] = 0
        response["msg"] = "账号或者密码不能为空。"
        return json(response)
示例#26
0
文件: admin.py 项目: testjie/Lux
def query_conditions_comments():
    """
    多条件联合查询评论
    :arg {"aContent":"测试", "cContent":"文章", "status":1, "startDate":"2017-03-23 23:59:52", "endDate":"2018-03-28 23:59:52"}
    :return: json
    """
    # 文章名字 评论内容 评论状态 创建时间
    conditions = request.get_json()
    status = conditions.get("status")
    article_content = conditions.get("aContent")
    comment_content = conditions.get("cContent")
    end_date = conditions.get("endDate")  # 结束时间
    start_date = conditions.get("startDate")  # 开始时间

    # 开始构造查询语句,分别根据参数是否为空来构造sql语句
    conditions_sql = "select a.*, b.content as aContent from tbl_article_comment as a join tbl_article as b where 1=1 "
    if _admin_parameters_filter([status]):
        conditions_sql += "and a.status=%d " % status
    if _admin_parameters_filter([article_content]):
        conditions_sql += "and b.content like '%" + article_content + "%' "
    if _admin_parameters_filter([comment_content]):
        conditions_sql += "and a.content like '%" + comment_content + "%' "

    # 创建文章的开始和结束时间
    if _admin_parameters_filter([start_date]):
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate > '%s' and a.createDate < '%s'" % (
                start_date, end_date)
        else:
            conditions_sql += "and a.createDate > '%s'" % start_date
    else:
        if _admin_parameters_filter([end_date]):
            conditions_sql += "and a.createDate < '%s'" % end_date

    datas = {"comments": query(conditions_sql)}
    return json(get_json(data=datas))