AdminTokenModel.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\model;
  3. use think\facade\Config;
  4. use think\Model;
  5. class AdminTokenModel extends Model
  6. {
  7. protected $table = 'fc_admin_token';
  8. protected $pk = 'id';
  9. protected $autoWriteTimestamp = false;
  10. //获取token
  11. //@param $admin_id int 运营账号表id
  12. //@param $username string 账户
  13. public static function handleToken(int $adminid = 0, string $token = '')
  14. {
  15. $rs = self::field('id')->where('adminid', $adminid)->findOrEmpty()->isEmpty();
  16. $expire = Config::get('common.expire');
  17. if ($rs) {
  18. return self::create([
  19. 'token' => $token,
  20. 'expiretime' => date('Y-m-d H:i:s', time() + $expire),
  21. 'addtime' => date('Y-m-d H:i:s'),
  22. 'adminid' => $adminid
  23. ]);
  24. } else {
  25. return self::where(['adminid' => $adminid])
  26. ->update([
  27. 'token' => $token,
  28. 'expiretime' => date('Y-m-d H:i:s', time() + $expire)
  29. ]);
  30. }
  31. }
  32. }