0
0

Token.php 803 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class Token extends Model
  7. {
  8. public function updateToken($userId){
  9. $info = Db::name('token')->where('user_id',$userId)->find();
  10. $token = create_token($userId);
  11. if($info){
  12. $ret = Db::name('token')->where('id',$info['id'])->setField('token',$token);
  13. }else{
  14. $ret = Db::name('token')->insert([
  15. 'token' => $token,
  16. 'user_id' => $userId
  17. ]);
  18. }
  19. if(!$ret){
  20. $this->error = 'token更新失败';
  21. return false;
  22. }
  23. return $token;
  24. }
  25. public function logout($userId){
  26. $this->where('user_id',$userId)->setField('token','');
  27. return true;
  28. }
  29. }