Beispiel #1
0
def run(eid,roleid=None):
    with dbconfig.Session() as session:
        event=session.query(Events).filter(Events.eid==eid).first()
        if event is None or event.type!="request_join_circle":
            return Res(errno=3,error="not event")

        uid=event.param1
        cid=event.param2

        cdef=session.query(CircleDef).filter(CircleDef.cid==cid).first()

        self_uc=UserCircle()
        self_uc.uid=uid
        self_uc.cid=cid
        self_uc.roleid=cdef.default_roleid
        self_uc.by_uid=BackEndEnvData.uid
        self_uc=session.merge(self_uc)
        session.commit()

        #添加好友
        friend=FriendList()
        friend.uid=self_uc.uid
        friend.friendid=self_uc.by_uid
        friend.type=2
        friend1=session.merge(friend)
        friend=FriendList()
        friend.uid=self_uc.by_uid
        friend.friendid=self_uc.uid
        friend.type=2
        friend2=session.merge(friend)
        session.commit()
        #发送通知
        event=Events()
        event.touid=friend1.uid
        event.param1=friend1.friendid
        event.type="add_friend"
        event1=session.merge(event)
        event=Events()
        event.touid=friend1.friendid
        event.param1=friend1.uid
        event.type="add_friend"
        event2=session.merge(event)

        event=Events()
        event.touid=self_uc.uid
        event.param1=self_uc.cid
        event.param2=self_uc.roleid
        event.param3=self_uc.by_uid
        event.type="accept_join_circle"
        event3=session.merge(event)

        session.commit()
        AddEventNotify(event1)
        AddEventNotify(event2)
        AddEventNotify(event3)
        return Res()
Beispiel #2
0
def run(uid,cid=None):
    if uid==BackEndEnvData.uid:
        return Res(errno=2,error="not self invite")
    with dbconfig.Session() as session:
        findparam=UserCircle.uid==uid
        if cid != None:
            findparam=and_(findparam,UserCircle.cid==cid)
        by_user_c=session.query(UserCircle).filter(findparam).order_by(UserCircle.time).first()
        if by_user_c is None:
            return Res(errno=3,error="user not in any circle")
        cdef=session.query(CircleDef).filter(CircleDef.cid==by_user_c.cid).first()

        self_uc=UserCircle()
        self_uc.uid=BackEndEnvData.uid
        self_uc.cid=by_user_c.cid
        self_uc.roleid=cdef.default_roleid
        self_uc.by_uid=by_user_c.uid
        self_uc=session.merge(self_uc)
        session.commit()

        #添加好友
        friend=FriendList()
        friend.uid=BackEndEnvData.uid
        friend.friendid=self_uc.by_uid
        friend.type=2
        friend1=session.merge(friend)
        friend=FriendList()
        friend.uid=self_uc.by_uid
        friend.friendid=BackEndEnvData.uid
        friend.type=2
        friend2=session.merge(friend)
        session.commit()
        #发送通知
        event=Events()
        event.touid=self_uc.by_uid
        event.param1=BackEndEnvData.uid
        event.type="add_friend"
        event1=session.merge(event)
        event=Events()
        event.touid=BackEndEnvData.uid
        event.param1=self_uc.by_uid
        event.type="add_friend"
        event2=session.merge(event)
        session.commit()
        AddEventNotify(event1)
        AddEventNotify(event2)

        return Res({"circle":{"cid":self_uc.cid,"roleid":self_uc.roleid}})
Beispiel #3
0
def run(vcode):
    codedata=dbconfig.memclient.get(("circleinvite:"+vcode).encode("utf-8"))
    if codedata is None:
        return Res(errno=3,error="not vcode")
    data=json.loads(codedata)
    if data['uid']==BackEndEnvData.uid:
        return Res(errno=2,error="not self invite")
    with dbconfig.Session() as session:
        cdef=session.query(CircleDef).filter(CircleDef.cid==data['cid']).first()
        self_uc=UserCircle()
        self_uc.uid=BackEndEnvData.uid
        self_uc.cid=data['cid']
        self_uc.roleid=cdef.default_roleid
        self_uc.by_uid=data['uid']
        self_uc=session.merge(self_uc)
        session.commit()
        return Res({"circle":{"cid":self_uc.cid,"roleid":self_uc.roleid}})
Beispiel #4
0
def run(sessionid):
    if BackEndEnvData.uid is None:
        data=dbconfig.redisdb.get(str('session:%s'%sessionid))
        if data is None:
            return {"errno":1,"error":"session not found","result":{}}
        data=json.loads(data)
        be_uid=int(data['uid'])
    else:
        be_uid=BackEndEnvData.uid
    beinvitelist=[]
    with dbconfig.Session() as session:
        user_data=session.query(User).filter(User.uid==be_uid).first()
        new_user=not user_data.nick
        session.execute(text('delete from connection_info where uid=:uid or (queue_id=:queue_id and connection_id=:connection_id);'+
                    'insert into connection_info(uid,queue_id,connection_id) values(:uid,:queue_id,:connection_id);'),
                             {"uid":user_data.uid,"queue_id":BackEndEnvData.reply_queue,"connection_id":BackEndEnvData.connection_id})
        session.commit()

        if new_user:
            eventpost=[]
            for one in list(UserInviteLog.objects(phone=user_data.phone).order_by('-invite_id')):
                one.joined_uid=user_data.uid
                one.save()
                if one.join_cid and one.join_roleid:
                    usercircle=UserCircle()
                    usercircle.uid=user_data.uid
                    usercircle.by_uid=one.uid
                    usercircle.cid=one.join_cid
                    usercircle.roleid=one.join_roleid
                    session.merge(usercircle)

                friend=FriendList()
                friend.uid=user_data.uid
                friend.friendid=one.uid
                friend.type=2
                session.merge(friend)

                friend=FriendList()
                friend.uid=one.uid
                friend.friendid=user_data.uid
                friend.type=3
                session.merge(friend)

                event=Events()
                event.touid=one.uid
                event.param1=user_data.uid
                event.param2=3
                event.type="add_friend"
                event=session.merge(event)
                eventpost.append(event)

                beinvitelist.append(one.toJson())
            session.commit()
            if beinvitelist:
                inviteinfo=beinvitelist[0]
                user_data.nick=inviteinfo['nick']
                user_data.headpic=inviteinfo['headpic']
                user_data.sex=inviteinfo['sex']
                user_data.birthday=inviteinfo['birthday']
                user_data.marriage=inviteinfo['marriage']
                user_data.height=inviteinfo['height']
                user_data.position=inviteinfo['position']
                user_data=session.merge(user_data)
                session.commit()
            for one in eventpost:
                AddEventNotify(one)

        uexd=UserExData.objects(uid=BackEndEnvData.uid).first()
        resultdata={"user":user_data.toJson()}
        if uexd:
            resultdata['client_data']=uexd.client_data
        if beinvitelist:
            resultdata['invite_list']=beinvitelist
        einfo=session.query(EndorsementInfo).filter(EndorsementInfo.uid==user_data.uid).first()
        if einfo:
            resultdata['endorsement']=einfo.toJson()
        return Res(resultdata)