def run(): alllog = UserInviteLog.objects(uid=BackEndEnvData.uid) loglist = [] for one in alllog: loglist.append(one.toJson()) return Res({"invites": loglist})
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)
def run(phone,nick,headpic=None,sex=None,birthday = None,marriage = 0,height = 0,position = None,join_cid=None,join_roleid=None): with dbconfig.Session() as session: user=session.query(User).filter(User.phone==phone).first() if user is not None: return Res({'user':user.toJson()},errno=2002,error=u"手机号对应的用户已存在") uinl=UserInviteLog.objects(uid=BackEndEnvData.uid,phone=phone).first() if uinl is None: uinl=UserInviteLog() uinl.uid=BackEndEnvData.uid uinl.nick=nick uinl.phone=phone if headpic: uinl.headpic=headpic if sex: uinl.sex=sex if birthday: uinl.birthday=birthday if marriage: uinl.marriage=marriage if height: uinl.height=height if position: uinl.position=position if join_cid: uinl.join_cid=join_cid with dbconfig.Session() as session: cdef=session.query(CircleDef).filter(CircleDef.cid==join_cid).first() uinl.join_roleid= cdef.default_roleid if (uinl.sms_send_time is None or (datetime.datetime.now()-uinl.sms_send_time).days>1): uinl.sms_send_time=datetime.datetime.now() userself=session.query(User).filter(User.uid==BackEndEnvData.uid).first() json_msg=DefJsonEncoder.encode({'phone':str(phone), "content":u"手机号%s(%s)的用户邀请你一起玩『来信』,点这里下载 http://t.cn/RvYAd47 "%(userself.phone,userself.nick)}) BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2, exchange='sys.sms',routing_key='sms.ad',compression='gzip') uinl.save() return Res({})