where('user_id',$userId)->find(); $token = md5($userId.'-'.time().rand(1000,9999)); if($info){ $ret = $this->save(['code'=>$token],['id'=>$info['id']]); }else{ $ret = $this->save([ 'code' => $token, 'user_id' => $userId ]); } if(!$ret){ return false; } $data = $this->where('user_id',$userId)->find(); return $data->toArray(); } public function logout($userId){ $this->where('user_id',$userId)->setField('code',''); return true; } }