123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Token extends Model
- {
- public function updateToken($userId){
- $info = $this->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;
- }
- }
|