def bind_phone_num(self): assert self._userid == 0 #初次绑定手机,从anonymous_device转移到user_device anony = db_helper.query_anonymous_device(self._device_id) if anony is None: logger.error('query_anonymous_device failed!! device_id:%s' %self._device_id) return {'rtn': 1} elif anony.flag == 1: #已被绑定 logger.info('query_anonymous_device, flag=1, device_id:%s, userid:%d' %self._device_id, self._userid) user = db_helper.query_user_info(self._userid) n = db_helper.count_user_device(self.userid) return {'rtn': 0, 'userid': self._userid, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'total_device': n} else: invite_code = self.gen_invite_code() user = db_helper.insert_user_info(self._phone_num, anony.sex, anony.age, anony.interest, invite_code) assert user is not None and user.userid != 0 n = db_helper.count_user_device(user.userid) if (user.userid in VIP_LIST and n >= 50) or (user.userid not in VIP_LIST and n >= 3): logger.info('too many devices, userid: %d' %user.userid) return {'rtn': 2} else: db_helper.insert_user_device(user.userid, self._device_id, anony.idfa, anony.mac, anony.platform) db_helper.update_anonymous_device_flag(self._device_id, 1) return {'rtn': 0, 'userid': user.userid, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'total_device': n}
def query_userid(self, device_id): #先查anonymous_device device = db_helper.query_anonymous_device(device_id) if device is None: return -1 elif device.flag == 0: return 0 else: #已绑定,查user_device device = db_helper.query_user_device(device_id) assert device is not None return device.userid
def bind_phone_num(self): assert self._userid == 0 #初次绑定手机,从anonymous_device转移到user_device anony = db_helper.query_anonymous_device(self._device_id) if anony is None: logger.error('query_anonymous_device failed!! device_id:%s' % self._device_id) return {'rtn': 1} elif anony.flag == 1: #已被绑定 logger.info( 'query_anonymous_device, flag=1, device_id:%s, userid:%d' % self._device_id, self._userid) user = db_helper.query_user_info(self._userid) n = db_helper.count_user_device(self.userid) return { 'rtn': 0, 'userid': self._userid, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'total_device': n } else: invite_code = self.gen_invite_code() user = db_helper.insert_user_info(self._phone_num, anony.sex, anony.age, anony.interest, invite_code) assert user is not None and user.userid != 0 n = db_helper.count_user_device(user.userid) if (user.userid in VIP_LIST and n >= 50) or (user.userid not in VIP_LIST and n >= 3): logger.info('too many devices, userid: %d' % user.userid) return {'rtn': 2} else: db_helper.insert_user_device(user.userid, self._device_id, anony.idfa, anony.mac, anony.platform) db_helper.update_anonymous_device_flag(self._device_id, 1) if n > 0: #扣减多送的一元钱 self.recharge(self._device_id, -100, '非首次安装小猪回收', 0) return { 'rtn': 0, 'userid': user.userid, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'total_device': n }
def GET(self): logger = logging.getLogger('root') self.init() #未绑定手机,直接查anonymous_device if self._userid == 0: anony = db_helper.query_anonymous_device(self._device_id) if anony is None: logger.error('query_anonymous_device failed!! device_id:%s' % self._device_id) else: resp = { 'rtn': 0, 'userid': 0, 'phone_num': '', 'sex': anony.sex, 'age': anony.age, 'interest': anony.interest, 'invite_code': '', 'inviter': '', 'activate_time': '' } else: user = db_helper.query_user_info(self._userid) if user is None: logger.debug('query_user_info failed!! userid:%d' % self._userid) else: resp = { 'rtn': 0, 'userid': self._userid, 'phone_num': user.phone_num, 'sex': user.sex, 'age': user.age, 'interest': user.interest, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'activate_time': user.create_time } return json.dumps(resp)
def GET(self): logger = logging.getLogger('root') self.init() #未绑定手机,直接查anonymous_device if self._userid == 0: anony = db_helper.query_anonymous_device(self._device_id) if anony is None: logger.error('query_anonymous_device failed!! device_id:%s' %self._device_id) else: resp = { 'rtn': 0, 'userid': 0, 'phone_num': '', 'sex': anony.sex, 'age': anony.age, 'interest': anony.interest, 'invite_code': '', 'inviter': '', 'activate_time': '' } else: user = db_helper.query_user_info(self._userid) if user is None: logger.debug('query_user_info failed!! userid:%d' %self._userid) else: resp = { 'rtn': 0, 'userid': self._userid, 'phone_num': user.phone_num, 'sex': user.sex, 'age': user.age, 'interest': user.interest, 'invite_code': user.invite_code, 'inviter': user.inviter_code, 'activate_time': user.create_time } return json.dumps(resp)
def POST(self): self.init() #判断当前ip登陆设备数,3台以上屏蔽 # if self._ip != '14.127.235.24': # device_list = db_helper.query_ip_history(self._ip) # if self._device_id not in device_list and len(device_list) >= 3: # logger.info('too many devices on ip: %s, total_device: %d' %(self._ip, len(device_list))) # return json.dumps({'rtn': 1}) #判断当前ip登陆过的设备,每个类型的设备只能登陆1次 if self._ip not in ['183.14.0.221', '121.14.98.49', '14.153.253.143', '113.92.102.40']: mm = db_helper.query_ip_history(self._ip) if self._device_id not in mm and self._platform in set(mm.values()): logger.info('too many devices on ip: %s, device_list: %s' %(self._ip, str(mm))) return json.dumps({'rtn': 1}) #先查anonymous_device device = db_helper.query_anonymous_device(self._device_id) if device is None: #查不到,直接插入 db_helper.insert_anonymous_device(self._device_id, self._mac, self._idfa, self._platform) self._new_device = True logger.debug('new device, %s' %self._device_id) #初次安装奖励1元 self.recharge(self._device_id, 100, '初次安装奖励') elif device.flag == 0: #未绑定 pass else: #已绑定,查user_device与user_info device = db_helper.query_user_device(self._device_id) #能查到 assert device is not None #被屏蔽用户 if self.is_banned(device.userid): logger.info('banned user!! userid:%d' %device.userid) return json.dumps({'rtn': 2}) user = db_helper.query_user_info(device.userid) assert user is not None logger.debug('user: %s' %str(user.__dict__)) self._userid = user.userid self._phone_num = user.phone_num self._invite_code = user.invite_code self._inviter = user.inviter_code #记录login_history self._login_history_entry.userid = self._userid db_helper.record_login_history(self._login_history_entry) resp = { 'rtn': 0, 'userid': self._userid, 'device_id': self._device_id, 'new_device': self._new_device, 'invite_code': self._invite_code, 'phone_num': self._phone_num, 'inviter': self._inviter } logger.debug('resp: %s' %str(resp)) return json.dumps(resp)
def POST(self): self.init() #判断当前ip登陆设备数,3台以上屏蔽 # if self._ip != '14.127.235.24': # device_list = db_helper.query_ip_history(self._ip) # if self._device_id not in device_list and len(device_list) >= 3: # logger.info('too many devices on ip: %s, total_device: %d' %(self._ip, len(device_list))) # return json.dumps({'rtn': 1}) #判断当前ip登陆过的设备,每个类型的设备只能登陆1次 if False: if self._ip not in [ '127.0.0.1', '183.14.0.221', '121.14.98.49', '14.153.253.143', '113.92.102.40' ]: mm = db_helper.query_ip_history(self._ip) if self._device_id not in mm and self._platform in set( mm.values()): logger.info('too many devices on ip: %s, device_list: %s' % (self._ip, str(mm))) return json.dumps({'rtn': 1}) #先查anonymous_device device = db_helper.query_anonymous_device(self._device_id) if device is None: #查不到,直接插入 db_helper.insert_anonymous_device(self._device_id, self._mac, self._idfa, self._platform) self._new_device = True logger.debug('new device, %s' % self._device_id) #初次安装奖励1元 self.recharge(self._device_id, 100, '初次安装奖励', 0) elif device.flag == 0: #未绑定 pass else: #已绑定,查user_device与user_info device = db_helper.query_user_device(self._device_id) #能查到 assert device is not None #被屏蔽用户 if self.is_banned(device.userid): logger.info('banned user!! userid:%d' % device.userid) return json.dumps({'rtn': 2}) user = db_helper.query_user_info(device.userid) assert user is not None logger.debug('user: %s' % str(user.__dict__)) self._userid = user.userid self._phone_num = user.phone_num self._invite_code = user.invite_code self._inviter = user.inviter_code #记录login_history self._login_history_entry.userid = self._userid db_helper.record_login_history(self._login_history_entry) resp = { 'rtn': 0, 'userid': self._userid, 'device_id': self._device_id, 'new_device': self._new_device, 'invite_code': self._invite_code, 'phone_num': self._phone_num, 'inviter': self._inviter } logger.debug('resp: %s' % str(resp)) return json.dumps(resp)