Esempio n. 1
0
def upUserImage():
    """
    上传用户头像
    :return:
    """
    file_dir = os.path.join(basedir, "app_api_1_0/static/User")  # 拼接成合法文件夹地址

    if not os.path.exists(file_dir):
        os.makedirs(file_dir)  # 文件夹不存在就创建

    token = request.form["Token"]
    userid = request.form["UserId"]

    if not kCheckUser(userId=userid, token=token):
        return kResponseJosn(code=500, codeString="token 无效!")

    # 检查post请求是否含有文件
    if 'file' not in request.files:
        return kResponseJosn(code=500, codeString="No file part")

    find_my_user = db.session.query(UserDetailModel).filter_by(
        UserId=userid).first()
    if not find_my_user:
        newUserd = UserDetailModel(kUserId=userid)
        db.session.add(newUserd)
        try:
            db.session.commit()
        except:
            pass
        db.session.close()

    file = request.files['file']
    # 浏览器也会提交没有文件名的空部分 如果用户没有选择文件
    if file and allowed_file(file.filename):

        filename = secure_filename(file.filename)

        ext = filename.rsplit('.', 1)[1]  # 获取文件后缀
        # unix_time = int(time.time())
        # new_filename = userid + str(unix_time) + '.' + ext  # 修改文件名
        new_filename = userid + '.' + ext  # 修改文件名

        file.save(os.path.join(file_dir, new_filename))  # 保存文件到upload目录
        # 返回服务器的图片地址
        img_url = url_for("static",
                          _external=True,
                          filename="User/" + new_filename)

        print("----文件地址=", img_url)
        find_my_user.UserImageUrl = img_url
        db.session.add(find_my_user)
        try:
            db.session.commit()
        except:
            pass
        db.session.close()

        return kResponseJosn(code=200, codeString="上传成功!")

    return kResponseJosn(code=500, codeString="errors")
Esempio n. 2
0
def addAttention():
    """
    添加关注Type = 1 取消关注 Type = 2
    :return:
    """

    token = request.json["Token"]
    userId = request.json["UserId"]
    b_FollowersUserId = request.json["FollowersUserId"]
    type = request.json["Type"]

    if userId is None and b_FollowersUserId is None and type is None:
        return kResponseJosn(code=500, codeString="缺少参数!")

    if not kCheckUser(userId=userId, token=token):
        return kResponseJosn(code=400, codeString="token 无效")

    if userId == b_FollowersUserId:
        return kResponseJosn(code=500, codeString="自己不能关注自己!")

    if type == "1":

        find_attebon = db.session.query(AttebtonModel).filter_by(
            FollowersUserId=userId,
            B_FollowersUserId=b_FollowersUserId).first()
        if find_attebon:
            return kResponseJosn(code=500, codeString="已经关注,请不要重复关注")

        attModel = AttebtonModel()
        attModel.FollowersUserId = userId
        attModel.B_FollowersUserId = b_FollowersUserId
        attModel.FollowersTime = time.strftime('%Y-%m-%d %H:%M:%S',
                                               time.localtime())
        db.session.add(attModel)
        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()
        db.session.close()

        return kResponseJosn(code=200, codeString="关注成功!")

    else:

        find_attebon = db.session.query(AttebtonModel).filter_by(
            FollowersUserId=userId,
            B_FollowersUserId=b_FollowersUserId).first()
        if not find_attebon:
            return kResponseJosn(code=500, codeString="查询失败!")

        db.session.delete(find_attebon)
        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()
        db.session.close()

        return kResponseJosn(code=200, codeString="取消关注成功!")
Esempio n. 3
0
def fixCertifiedUser():
    """
    上级给下级审核确定认证
    :return: MTUyNjk1OTk0Ni41OTg0MTQyOjFjNGU3ODgyNGM1MWQxNDlmNWU1OTM2OWQ2YjkxOWQ0OGJlMTJmMWM=
    """
    Token = request.json.get('Token')
    CertifiedId = request.json.get('CertifiedId')
    UserId = request.json.get('UserId')

    if kCheckUser(userId=UserId, token=Token):
        return kResponseJosn(code=500, codeString="token 无效!")

    # 找到该条验证消息
    find_cer = db.session.query(CertifiedModel).filter_by(
        CertifiedId=CertifiedId).first()
    # 验证登录用户和 该条验证消息 审核人的是否一致
    if find_cer.State != 0:
        return kResponseJosn(code=400, codeString="该条认证信息有问题!")

    if int(UserId) != find_cer.ManagementId:
        return kResponseJosn(code=400, codeString="审核权限不正确")

    find_User = db.session.query(UserDetailModel).filter_by(
        UserId=UserId).first()
    # 看看确定验证申请人的权限是否问题
    if find_User.CompanyUserType < find_cer.CertifiedUserId:
        # 更改申请人的认证状态
        find_cerUser = db.session.query(UserModel).filter_by(
            UserId=find_cer.CertifiedUserId).first()
        find_cerUser.State = 1
        db.session.add(find_cerUser)

        find_cer.State = 1
        db.session.add(find_cer)
        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()

        db.session.close()
        '''
        还需要做个推送处理
        '''
        return kResponseJosn(code=200, codeString="认证成功")
Esempio n. 4
0
def getUserDetail():
    """
    获取用户详情
    :return:
    """
    token = request.json["Token"]
    userid = request.json["UserId"]

    if not kCheckUser(userId=userid, token=token):
        return kResponseJosn(code=500)
    find_my_user = db.session.query(UserDetailModel).filter_by(
        UserId=userid).first()  # 查询第一个
    if find_my_user:

        return kResponseJosn(code=200,
                             codeString="用户信息查询成功!",
                             obj=classTodic(find_my_user))
    else:
        return kResponseJosn(code=400, codeString="该用户没有用户信息!")
Esempio n. 5
0
def writeContent():
    '''
    写文章
    :return:
    '''

    Token = request.json.get('Token')
    qReleasePeopleId = request.json.get("UserId")
    qContentTitle = request.json.get('ContentTitle')
    qContentBox = request.json.get("HTMLString")
    qContentStr = request.json.get("ContentString")

    qContentId = singlerandom(16)
    qReleaseTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

    if not kCheckUser(userId=qReleasePeopleId, token=Token):
        return kResponseJosn(code=500, codeString="token 无效")

    find_User = db.session.query(UserDetailModel).filter_by(
        UserId=qReleasePeopleId).first()

    if find_User.UserType != 1:
        kResponseJosn(code=500, codeString="您的权限不是供应商身份不能发布文章!")

    installContent = ContentModel()
    installContent.ContentId = qContentId
    installContent.ReleaseTime = qReleaseTime
    installContent.ContentTitle = qContentTitle
    installContent.ReleasePeopleId = qReleasePeopleId
    installContent.ContentHtml = qContentBox
    installContent.ContentString = qContentStr

    db.session.add(installContent)
    try:
        db.session.commit()
    except:
        pass
        # db.session.rollback()
    db.session.close()

    return kResponseJosn(code=200, codeString='文章发布成功!')
Esempio n. 6
0
def getContentDetail():
    """
    获取文章详情
    :return:
    """
    token = request.json.get('Token')
    userid = request.json.get('UserId')
    contentId = request.json.get('ContentId')

    if not kCheckUser(userId=userid, token=token):
        return kResponseJosn(code=500, codeString="无效Token")

    find_my_Conten = db.session.query(ContentModel).filter_by(
        ContentId=contentId).first()

    if not find_my_Conten:
        return kResponseJosn(code=400, codeString="查询失败!")

    find_my_user = db.session.query(UserDetailModel).filter_by(
        UserId=find_my_Conten.ReleasePeopleId).first()

    if not find_my_user:
        return kResponseJosn(code=400, codeString="查询失败!")

    find_attebon = db.session.query(AttebtonModel).filter_by(
        FollowersUserId=userid,
        B_FollowersUserId=find_my_Conten.ReleasePeopleId).first()

    dic = classTodic(find_my_Conten)
    dic["UserHeader"] = find_my_user.UserImageUrl
    dic["CompanyName"] = find_my_user.CompanyName
    dic["Name"] = find_my_user.Name
    if find_attebon:
        dic["IsAttebon"] = "1"
    else:
        dic["IsAttebon"] = "0"

    return kResponseJosn(code=200, codeString="查询成功!", obj=dic)
Esempio n. 7
0
def getContList():
    '''
    获取app首页文章列表,后期添加 类目筛选等 目前分页获取全部
    :return:
    '''

    page = request.json.get('Page')
    pageSize = request.json.get('PageSize')
    token = request.json.get('Token')
    userid = request.json.get('UserId')
    # 利用flask 进行分页查询
    if kCheckUser(userId=userid, token=token):

        pagination = ContentModel.query \
            .order_by(ContentModel.ReleaseTime.desc()) \
            .paginate(int(page), per_page=int(pageSize), error_out=False)

        posts = pagination.items
        tList = []

        for t in posts:
            find_my_user = db.session.query(UserDetailModel).filter_by(
                UserId=t.ReleasePeopleId).first()

            dic = {
                "ContentTitle": t.ContentTitle,
                "ReleaseTime": t.ReleaseTime,
                "ContentId": t.ContentId,
                "Content": t.ContentString,
                "UserHeader": find_my_user.UserImageUrl,
                "Name": find_my_user.Name,
                "CompanyName": find_my_user.CompanyName
            }
            tList.append(dic)

        return kResponseJosn(code=200, codeString="查询成功!", obj=tList)
    else:
        return kResponseJosn(code=500, codeString="无效Token")
Esempio n. 8
0
def getMyContList():
    """
    获取用户的发布的文章
    :return:
    """

    page = request.json.get('Page')
    pageSize = request.json.get('PageSize')
    token = request.json.get('Token')
    userId = request.json.get('UserId')

    if not kCheckUser(userId=userId, token=token):
        return kResponseJosn(code=400, codeString="token 无效")
    """
     filter_by 查找
     order_by 排序
     paginate  分页
    """
    pagination = ContentModel.query \
        .filter_by(ReleasePeopleId=userId) \
        .order_by(ContentModel.ReleaseTime.desc()) \
        .paginate(int(page), per_page=int(pageSize), error_out=False)

    posts = pagination.items
    tList = []
    for t in posts:
        # obj = classTodic(t)
        obj = {
            "ContentTitle": t.ContentTitle,
            "ReleaseTime": t.ReleaseTime,
            "ContentId": t.ContentId,
            "Content": t.ContentString,
        }

        tList.append(obj)

    return kResponseJosn(code=200, codeString="查询成功!", obj=tList)
Esempio n. 9
0
def deleteContet():
    """
    删除文章
    :return:
    """

    token = request.json.get('Token')
    userId = request.json.get('UserId')
    contentId = request.json["ContentId"]
    if not kCheckUser(userId=userId, token=token):
        return kResponseJosn(code=400, codeString="token 无效")

    find_my_Conten = db.session.query(ContentModel).filter_by(
        ContentId=contentId).first()
    if not find_my_Conten:
        return kResponseJosn(code=400, codeString="查询失败!")

    db.session.delete(find_my_Conten)
    try:
        db.session.commit()
    except:
        pass
    db.session.close()
    return kResponseJosn(code=200, codeString="删除文章成功!")
Esempio n. 10
0
def getMyAttention():
    """
    获取我的关注列表
    :return:
    """
    token = request.json["Token"]
    userId = request.json["UserId"]
    page = request.json.get('Page')
    pageSize = request.json.get('PageSize')

    if not kCheckUser(userId=userId, token=token):
        return kResponseJosn(code=500, codeString="token 无效!")

    pagination = AttebtonModel.query \
        .filter_by(FollowersUserId=userId) \
        .order_by(AttebtonModel.FollowersTime.desc()) \
        .paginate(int(page), per_page=int(pageSize), error_out=False)

    posts = pagination.items
    tList = []
    for t in posts:

        find_my_user = db.session.query(UserDetailModel).filter_by(
            UserId=t.B_FollowersUserId).first()

        obj = {
            "FollowersTime": t.FollowersTime,
            "Name": find_my_user.Name,
            "HeaderUrl": find_my_user.UserImageUrl,
            "UserId": find_my_user.UserId
        }

        # obj = classTodic(t)
        tList.append(obj)

    return kResponseJosn(code=200, codeString="查询成功!", obj=tList)
Esempio n. 11
0
def certifiedUser():
    """
    高管或者员工进行实名认证
    :return:
    """

    Token = request.json.get("Token")
    UserId = request.json.get('UserId')
    BossId = request.json.get('BossId')  # 上级领导的id
    UserType = request.json.get('UserType')

    if not kCheckUser(userId=UserId, token=Token):
        return kResponseJosn(code="900", codeString="token 无效!")

    find_boss_user = db.session.query(UserDetailModel).filter_by(
        UserId=BossId).first()  # 查询上级的状态是否正常
    print(find_boss_user.CompanyUserType)
    print(find_boss_user.State)

    if int(find_boss_user.CompanyUserType) == 1 and int(
            find_boss_user.State) == 1:
        '''
        将请求认证人的信息状态 临时存起来
        '''
        find_my_user = db.session.query(UserDetailModel).filter_by(
            UserId=UserId).first()
        find_my_user.UserType = UserType
        find_my_user.CompanyUserType = UserType
        find_my_user.State = 2
        db.session.add(find_my_user)
        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()
        '''
        插入一条验证消息
        '''
        install_certif = CertifiedModel()
        install_certif.SendTime = time.strftime('%Y-%m-%d %H:%M:%S',
                                                time.localtime())
        install_certif.Title = "您有一条请求认证消息!"
        install_certif.CertifiedId = singlerandom(12)
        install_certif.CertifiedUserId = UserId
        install_certif.ManagementId = BossId
        install_certif.State = 0
        install_certif.CertifiedType = UserType
        db.session.add(install_certif)
        try:
            db.session.commit()
        except:
            db.session.rollback()

        db.session.close()
        '''
        这还得做个推送处理
        '''

        return kResponseJosn(code=200, codeString="申请认证成功!等待领导确定")
    else:
        return kResponseJosn(codeString="无效申请", code=400)
Esempio n. 12
0
def addUserDetail():
    """
    完善用户信息或修改用户信息
    :return:
    """

    Token = request.json.get("Token")
    UserId = request.json.get('UserId')

    Name = request.json.get("Name")
    Birthday = request.json.get("Birthday")
    Adresss = request.json.get("Adress")
    Sex = request.json.get("Sex")
    PhoneNum = request.json.get("PhoneNum")
    CompanyName = request.json.get("CompanyName")
    Education = request.json.get("Education")
    Age = request.json.get("Age")

    # UserType = request.json.get('UserType')
    # CompanyId = request.json.get("CompanyId")
    # CompanyUserType = request.json.get("CompanyUserType")
    # IDNum = request.json.get("IDNum")

    if UserId is None or Token is None:
        return kResponseJosn(code='500', codeString="缺少参数")

    if not kCheckUser(userId=UserId, token=Token):
        return kResponseJosn(code="900", codeString="token 无效!")

    find_my_user = db.session.query(UserDetailModel).filter_by(
        UserId=UserId).first()  # 查询第一个

    if find_my_user is None:

        newUserd = UserDetailModel(kUserId=UserId)
        newUserd.Sex = Sex
        newUserd.Adress = Adresss
        newUserd.PhoneNum = PhoneNum
        newUserd.State = 0
        newUserd.CompanyName = CompanyName
        newUserd.Name = Name
        newUserd.Birthday = Birthday
        newUserd.Education = Education
        newUserd.Age = Age

        # newUserd.UserType = UserType
        # newUserd.IDNum = IDNum
        # newUserd.CompanyId = CompanyId
        # newUserd.CompanyUserType = CompanyUserType

        db.session.add(newUserd)
        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()
        db.session.close()
        return kResponseJosn(code=200, codeString="完善信息成功!")
    else:

        find_my_user.PhoneNum = PhoneNum
        find_my_user.State = 0
        find_my_user.CompanyName = CompanyName
        find_my_user.Name = Name
        find_my_user.Birthday = Birthday
        find_my_user.Sex = Sex
        find_my_user.Adress = Adresss
        find_my_user.Education = Education
        find_my_user.Age = Age

        # find_my_user.UserType = UserType
        # find_my_user.IDNum = IDNum
        # find_my_user.CompanyId = CompanyId
        # find_my_user.CompanyUserType = CompanyUserType

        db.session.add(find_my_user)
        # db.session.commit()

        try:
            db.session.commit()
        except:
            pass
            # db.session.rollback()
        db.session.close()

        return kResponseJosn(code=200, codeString="修改信息成功!")