123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\model;
- use think\facade\Config;
- use think\Model;
- class AdminTokenModel extends Model
- {
- protected $table = 'fc_admin_token';
- protected $pk = 'id';
- protected $autoWriteTimestamp = false;
- //获取token
- //@param $admin_id int 运营账号表id
- //@param $username string 账户
- public static function handleToken(int $adminid = 0, string $token = '')
- {
- $rs = self::field('id')->where('adminid', $adminid)->findOrEmpty()->isEmpty();
- $expire = Config::get('common.expire');
- if ($rs) {
- return self::create([
- 'token' => $token,
- 'expiretime' => date('Y-m-d H:i:s', time() + $expire),
- 'addtime' => date('Y-m-d H:i:s'),
- 'adminid' => $adminid
- ]);
- } else {
- return self::where(['adminid' => $adminid])
- ->update([
- 'token' => $token,
- 'expiretime' => date('Y-m-d H:i:s', time() + $expire)
- ]);
- }
- }
- }
|