/** * 退出登陆 * @param int $mem_id 用户id * @param string $mem_mark 用户单点标识 * @return int */ public function logout($mem_id, $mem_mark) { //查询用户是否存在 $sql = 'select mem_id from member where mem_id=? and mem_mark=?'; $member = $this->fetchOne($sql, [$mem_id, $mem_mark]); if (!$member) { return NOT_FOUND_USER; } //修改用户在线状态,并修改单点标识 $sql = 'update member set mem_mark=?,mem_online=2 where mem_id=?'; if (!$this->execute($sql, [Func::getRandomStr(), $mem_id])) { return SERVER_ERROR; } return OK; }
/** * 用户登陆记录 * @param array $member 用户数据 * @param int $login_system 手机操作系统 * @param string $login_number 手机序列号 * @param string $mem_client_id 推送key * @return int */ private function addLoginLog(&$member, $login_system, $login_number, $mem_client_id) { //查询登陆信息 $sql = 'select max(login_id) login_id,login_number from login_log where mem_id=?'; $login = $this->fetchOne($sql, [$member['mem_id']]); //用户没有退出,并且设备序列号发生了改变 if ($member['mem_online'] != 1 && $login['login_number'] != $login_number) { /*需执行的方法,预留*/ } //只有设备号发生改变时 if ($login['login_number'] != $login_number) { /*需执行的方法,预留*/ } //开启事物 $this->begin(); //记录登陆数据 $sql = 'insert into login_log (mem_id,login_system,login_number,login_addtime) value (?,?,?,?)'; if (!$this->execute($sql, [$member['mem_id'], $login_system, $login_number, time()])) { $this->rollback(); return SERVER_ERROR; } //改变用户单点登陆标记,在线状态,推送服务系统以及key $member['mem_mark'] = \Func::getRandomStr(); $sql = 'update member set mem_mark=?,mem_online=1,mem_client_system=?,mem_client_id=? where mem_id=?'; if (!$this->execute($sql, [$member['mem_mark'], $login_system, $mem_client_id, $member['mem_id']])) { $this->rollback(); return SERVER_ERROR; } //提交事物 $this->commit(); return OK; }