Exemple #1
0
def set():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        info = None
        if uid:
            info = User.query.filter_by(uid=uid).first()
        current_user = g.current_user
        communities = Community.query.filter(
            Community.platform_id == current_user.platform_id)
        resp_data['info'] = info
        resp_data['communities'] = communities
        return ops_render("account/set.html", resp_data)

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    req = request.values

    id = req['id'] if 'id' in req else 0
    platform_id = req['platform_id'] if 'platform_id' in req else ''
    platform_name = req['platform_name'] if 'platform_name' in req else ''
    community_id = req['community_id'] if 'community_id' in req else ''
    community_name = req['community_name'] if 'community_name' in req else ''
    nickname = req['nickname'] if 'nickname' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    email = req['email'] if 'email' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    benefit = req['benefit'] if 'benefit' in req else 0

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名~~"
        return jsonify(resp)

    if mobile is None or len(mobile) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的手机号码~~"
        return jsonify(resp)

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录用户名~~"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd) < 3:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的登录密码~~"
        return jsonify(resp)

    has_in = User.query.filter(User.login_name == login_name,
                               User.uid != id).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该登录名已存在,请换一个试试~~"
        return jsonify(resp)

    benefit = Decimal(benefit).quantize(Decimal('0.00'))
    if benefit < 0:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的售卖价格~~"
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    if user_info:
        model_user = user_info
    else:
        model_user = User()
        model_user.platform_id = platform_id
        model_user.platform_name = platform_name
        model_user.community_id = community_id
        model_user.community_name = community_name
        model_user.email = email
        model_user.benefit = 0.00
        model_user.created_time = getCurrentDate()
        model_user.login_salt = UserService.geneSalt()

    model_user.nickname = nickname
    model_user.mobile = mobile
    model_user.login_name = login_name
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.benefit = benefit

    model_user.updated_time = getCurrentDate()
    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
Exemple #2
0
def leaderApplicationApprove():
    resp = {'code': 200, 'msg': '审核操作成功~~', 'data': {}}
    print(request)
    req = request.values
    id = int(req['id']) if 'id' in req else 0
    member_id = int(req['member_id']) if 'member_id' in req else 0
    community_name = req['community_name'] if 'community_name' in req else ''
    province = req['province'] if 'province' in req else ''
    city = req['city'] if 'city' in req else ''
    description = req['description'] if 'description' in req else ''
    pickups = req['pickups'] if 'pickups' in req else ''
    name = req['name'] if 'name' in req else ''
    mobile = req['mobile'] if 'mobile' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    email = req['email'] if 'email' in req else ''

    has_in = Community.query.filter(Community.name == community_name).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "该社区名已存在,请换一个试试~~"
        return jsonify(resp)

    model_community = Community()
    model_community.platform_id = g.current_user.platform_id
    model_community.platform_name = g.current_user.platform_name
    model_community.name = community_name
    model_community.province = province
    model_community.city = city
    model_community.description = description
    model_community.pickups = pickups

    db.session.add(model_community)
    db.session.commit()

    community = Community.query.filter_by(
        platform_id=g.current_user.platform_id, name=community_name).first()

    model_user = User()
    model_user.platform_id = community.platform_id
    model_user.platform_name = community.platform_name
    model_user.community_id = community.id
    model_user.community_name = community.name
    model_user.email = email
    model_user.benefit = 0.00
    model_user.created_time = getCurrentDate()
    model_user.login_salt = UserService.geneSalt()
    model_user.nickname = name
    model_user.mobile = mobile
    model_user.login_name = login_name
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.updated_time = getCurrentDate()

    db.session.add(model_user)
    db.session.commit()

    member = Member.query.filter_by(id=member_id).first()
    ApplicationService.changeCommunity(member.platform_id, member_id,
                                       community.id, community.name)

    application = Application.query.filter_by(id=id).first()
    application.status = 1
    db.session.add(application)
    db.session.commit()

    return jsonify(resp)