Esempio n. 1
0
def generated_name_card():
    """
    生成名片接口
    @author: yubang
    :return: str
    """
    open_id = g.open_id
    name = request.form.get('name', None)
    company = request.form.get('company', None)
    industry = request.form.get('industry', None)
    resources_key = request.form.get('resources_key', None)
    avatar = request.form.get('avatar', None)
    role = request.form.get('role', None)
    invitation_code = request.form.get('invitation_code', None)

    # 省市
    province = request.form.get('province', None)
    city = request.form.get('city', None)
    area = request.form.get('area', None)

    # 检测邀请码
    if not BusinessCardModel.check_invitation_code(invitation_code):
        response = make_response(json.dumps({"code": -5, "msg": u'邀请码不正确!'}))
        response.headers['Content-Type'] = 'application/json'
        return response

    r = BusinessCardModel.make_a_card(open_id, name, company, industry,
                                      resources_key, avatar, role,
                                      invitation_code, province, city, area)

    result = dict()

    if r:
        result['code'] = 0
        result['msg'] = 'ok'
    else:
        result['code'] = 0
        result['msg'] = u'请勿重复生成名片!'

    # 处理加入群情况
    if 'group_token' in session:
        try:
            GroupRecordModel.join_group(g.open_id, session['group_token'])
        except:
            pass

    # 特殊处理扫描海报二维码后生成名片的情况
    from_open_id = request.form.get('from_open_id', None)
    if from_open_id and BusinessCardModel.has_card(from_open_id):
        ApplyFriendsModel.apply_friend(g.open_id, from_open_id,
                                       u'通过扫描您的海报申请资源对接')

    response = make_response(json.dumps(result))
    response.headers['Content-Type'] = 'application/json'
    return response
Esempio n. 2
0
def update_name_card():
    """
    更新个人名片信息
    :return:
    """
    open_id = g.open_id
    name = request.form.get('name', None)
    company = request.form.get('company', None)
    industry = request.form.get('industry', None)
    resources_key = request.form.get('resources_key', None)
    avatar = request.form.get('avatar', None)
    role = request.form.get('role', None)
    result = {"code": 0, "msg": 'ok'}

    invitation_code = request.form.get('invitation_code', None)

    # 省市
    province = request.form.get('province', None)
    city = request.form.get('city', None)
    area = request.form.get('area', None)

    # 检测邀请码
    if not BusinessCardModel.check_invitation_code(invitation_code):
        response = make_response(json.dumps({"code": -5, "msg": u'邀请码不正确!'}))
        response.headers['Content-Type'] = 'application/json'
        return response

    r = BusinessCardModel.update_a_card(open_id, name, company, industry,
                                        resources_key, avatar, role,
                                        invitation_code, province, city, area)

    if not r:
        # 防止什么都没修改
        result['code'] = 0
        result['msg'] = u'修改失败!'

    response = make_response(json.dumps(result))
    response.headers['Content-Type'] = 'application/json'
    return response