Ejemplo n.º 1
0
def chat_html(friend_open_id):
    """
    聊天页面
    :param friend_open_id: 好友openid
    :return:
    """

    own_card = BusinessCardModel.get_name_card(g.open_id)
    friend_card = BusinessCardModel.get_name_card(friend_open_id)
    obj = {"own_card": own_card, "friend_card": friend_card}

    title = friend_card['name']

    return render_template("v1/chat.html", title=title, friend_open_id=friend_open_id, obj=obj)
Ejemplo n.º 2
0
def get_card_of_a_prople(open_id):
    """
    获取某位用户的信息
    :param open_id: 用户openid
    :return:
    """

    if not BusinessCardModel.has_card(open_id):
        return abort(404)

    card = BusinessCardModel.get_name_card(open_id)
    card = BusinessCardModel.handle_data_use_in_json(card)

    if card['redundancy_labels']:
        card['keys'] = card['redundancy_labels'].split('#')
    else:
        card['keys'] = []

    if FriendModel.is_friend(g.open_id, open_id) or open_id == g.open_id:
        card['is_friend'] = 0
    else:
        card['is_friend'] = 1

    # 判断是不是自己
    if open_id == g.open_id:
        card['is_me'] = 0
    else:
        card['is_me'] = 1

    response = make_response(json.dumps(card))
    response.headers['Content-Type'] = 'application/json'
    return response
Ejemplo n.º 3
0
def get_own_card_in_make_card():
    """
    拉取制作名片的相关信息
    :return:
    """
    obj = BusinessCardModel.get_name_card(g.open_id)

    if not obj:
        obj = {
            "avatar": session['user_data']['headimgurl'],
            "name": '',
            "company": '',
            "industry": u'互联网/软件',
            "role": u'产品',
            "resources_key": '',
            "invitation_code": '',
            "province": '',
            "city": '',
            "area": '',
        }
        obj['target_url'] = '/api/v1/generatedNameCard'
    else:
        obj['target_url'] = '/api/v1/updateNameCard'

    # 处理登录跳转接口
    if 'group_token' in session:
        obj['after_login_url'] = url_for('web_app.all_cards',
                                         group_token=session['group_token'])
    else:
        obj['after_login_url'] = url_for('web_app.contact_list')

    obj = BusinessCardModel.handle_data_use_in_json(obj)
    response = make_response(json.dumps(obj))
    response.headers['Content-Type'] = 'application/json'
    return response
Ejemplo n.º 4
0
def chat_html(friend_open_id):
    """
    聊天页面
    :param friend_open_id: 好友openid
    :return:
    """

    own_card = BusinessCardModel.get_name_card(g.open_id)
    friend_card = BusinessCardModel.get_name_card(friend_open_id)
    obj = {"own_card": own_card, "friend_card": friend_card}

    title = friend_card['name']

    return render_template("v1/chat.html",
                           title=title,
                           friend_open_id=friend_open_id,
                           obj=obj)
Ejemplo n.º 5
0
def get_chat_need_message():
    """
    获取聊天页面初始化信息
    :return:
    """

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

    own_card = BusinessCardModel.get_name_card(g.open_id)
    own_card = BusinessCardModel.handle_data_use_in_json(own_card)
    friend_card = BusinessCardModel.get_name_card(friend_open_id)
    friend_card = BusinessCardModel.handle_data_use_in_json(friend_card)
    obj = {"own_card": own_card, "friend_card": friend_card}

    title = friend_card['name']

    r = {'own_card': own_card, 'title': title, 'obj': obj}

    response = make_response(json.dumps(r))
    response.headers['Content-Type'] = 'application/json'
    return response
Ejemplo n.º 6
0
def update_card():
    """
    修改名片页面
    :return:
    """

    if not BusinessCardModel.has_card(g.open_id):
        return redirect(url_for('web_app.build_card'))

    card = BusinessCardModel.get_name_card(g.open_id)
    g.target_url = '/api/v1/updateNameCard'
    return send_file('templates/v1/build_card.html', cache_timeout=0)
Ejemplo n.º 7
0
def card(open_id):
    """
    获取个人名片
    :param open_id: 名片openid
    :return:
    """
    card = BusinessCardModel.get_name_card(open_id)

    if not card:
        return abort(404)

    url = url_for("api.add_friend", _external=True, friend_open_id=open_id)
    url = urllib.quote(url)

    if card['redundancy_labels']:
        card['keys'] = card['redundancy_labels'].split('#')
    else:
        card['keys'] = []
    return render_template('v1/card.html', card=card, url=url)
Ejemplo n.º 8
0
def get_contacts():
    """
    获取联系人接口
    @author: yubang
    :return: str
    """
    open_id = g.open_id

    objs = FriendModel.get_all_friends(open_id)

    # 处理搜索条件
    search_key = request.form.get('search_key', None).encode("UTF-8")
    industry = request.form.get('industry', None).encode("UTF-8")
    role = request.form.get('role', None).encode("UTF-8")
    output_objs = []
    for obj in objs:

        if obj['name'].encode('UTF-8').find(
                search_key) == -1 and obj['company'].encode('UTF-8').find(
                    search_key) == -1 and obj['redundancy_labels'].encode(
                        'UTF-8').find(search_key) == -1:
            continue

        if obj['industry'].encode('UTF-8').find(industry) == -1:
            continue

        if obj['role'].encode('UTF-8').find(role) == -1:
            continue

        output_objs.append(obj)
    objs = output_objs

    # 添加自己的信息
    card = BusinessCardModel.get_name_card(g.open_id)
    card['name_pinyin'] = ''
    card = BusinessCardModel.handle_data_use_in_json(card)
    objs.insert(0, card)

    result = {"code": 0, "msg": 'ok', "content": objs}
    response = make_response(json.dumps(result))
    response.headers['Content-Type'] = 'application/json'
    return response
Ejemplo n.º 9
0
def get_name_card():
    """
    拉取个人名片信息
    @author: yubang
    :return:
    """
    open_id = g.open_id
    obj = BusinessCardModel.get_name_card(open_id)

    result = {"code": 0, "msg": 'ok'}

    if not obj:
        result['code'] = -1
        result['msg'] = u'还没生成名片'
    else:
        obj['create_time'] = obj['create_time'].strftime("%Y-%m-%d %H:%M:%S")
        obj['update_time'] = obj['update_time'].strftime("%Y-%m-%d %H:%M:%S")
        result['content'] = obj

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

    return response
Ejemplo n.º 10
0
def get_name_card():
    """
    拉取个人名片信息
    @author: yubang
    :return:
    """
    open_id = g.open_id
    obj = BusinessCardModel.get_name_card(open_id)

    result = {"code": 0, "msg": 'ok'}

    if not obj:
        result['code'] = -1
        result['msg'] = u'还没生成名片'
    else:
        obj['create_time'] = obj['create_time'].strftime("%Y-%m-%d %H:%M:%S")
        obj['update_time'] = obj['update_time'].strftime("%Y-%m-%d %H:%M:%S")
        result['content'] = obj

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

    return response
Ejemplo n.º 11
0
def poster(open_id):
    """
    用户海报页面
    (注意,该页面不需要登录校验~~~~)
    :return:
    """
    if not BusinessCardModel.has_card(open_id):
        return abort(404)

    card = BusinessCardModel.get_name_card(open_id)

    if card['redundancy_labels']:
        card['keys'] = card['redundancy_labels'].split('#')
        # 只取前5个
        if len(card['keys']) > 5:
            card['keys'] = card['keys'][:5]
    else:
        card['keys'] = []

    # 生成二维码地址
    url = url_for('web_app.join_card_by_user_code', _external=True)+ "?from_open_id=" + card['open_id'] + "&invitation_code=" + card['invitation_code']
    card['url'] = urllib.quote(url)

    return render_template('v1/poster.html', card=card)
Ejemplo n.º 12
0
    def get_last_chat_message(cls, open_id):
        """
        获取最后一条联系人信息
        :param open_id:
        :return:
        """
        temp_str = "(select * from %s order by create_time desc) temp_table" % cls.table_name
        sql = "select * from " + temp_str + " where to_open_id = %s group by from_open_id order by create_time desc"
        objs = cls.get_db_lib().query_for_list(sql, [open_id])

        r = list()
        for obj in objs:
            r.append(obj)

        sql = "select * from " + temp_str + " where from_open_id = %s group by to_open_id"
        objs = cls.get_db_lib().query_for_list(sql, [open_id])
        new_objs = []

        for obj in objs:
            index = 0
            exist_sign = False
            while index < len(r):
                if obj['to_open_id'] == r[index]['from_open_id']:
                    if obj['create_time'].now() > r[index]['create_time'].now():
                        r[index] = obj
                    exist_sign = True
                    break
                index += 1
            if not exist_sign:
                new_objs.append(obj)

        r.extend(new_objs)

        # 填充联系人信息
        index = 0
        while index < len(r):

            if r[index]['to_open_id'] != open_id:
                r[index]['user'] = BusinessCardModel.get_name_card(r[index]['to_open_id'])
            else:
                r[index]['user'] = BusinessCardModel.get_name_card(r[index]['from_open_id'])

            r[index]['user'] = BusinessCardModel.handle_data_use_in_json(r[index]['user'])
            r[index]['message_nums'] = cls.get_message_number(open_id, r[index]['user']['open_id'])

            index += 1

        # 特殊处理资源小助手
        reource_obj = model_manager['ResourceHelperMessageModel'].get_last_message(open_id)
        if reource_obj:
            reource_obj['user'] = {'name': u'资源小助手', "avatar": '/static/v1/img/webwxgetmsgimg.jpg', 'open_id': ''}
            reource_obj['message_nums'] = (model_manager['ResourceHelperMessageModel'].get_not_read_message_number(open_id), 0)

            r.append(reource_obj)

        # 按时间排序
        i = 0
        while i < len(r):
            j = i + 1
            while j < len(r):
                if r[i]['create_time'] < r[j]['create_time']:
                    temp_obj = r[i]
                    r[i] = r[j]
                    r[j] = temp_obj
                j += 1
            i += 1

        r = map(cls.handle_data_use_in_json, r)

        return r