Files
cunkebao_v3/Server/application/store/controller/LoginController.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2025-10-29 10:30:50 +08:00
<?php
namespace app\store\controller;
2025-10-29 11:48:02 +08:00
use app\common\util\JwtUtil;
2025-10-29 10:30:50 +08:00
use think\Db;
2025-10-29 11:48:02 +08:00
use think\Controller;
2025-10-29 10:30:50 +08:00
2025-10-29 11:48:02 +08:00
class LoginController extends Controller
2025-10-29 10:30:50 +08:00
{
public function index()
{
$deviceId = $this->request->param('deviceId', '');
if (empty($deviceId)) {
return errorJson('缺少必要参数');
}
2025-10-29 11:48:02 +08:00
$user = Db::name('users')->alias('u')
->field('u.*')
->join('device_user du', 'u.id = du.userId and u.companyId = du.companyId')
->join('device d', 'du.deviceId = d.id and u.companyId = du.companyId')
->where(['d.deviceImei' => $deviceId, 'u.deleteTime' => 0, 'du.deleteTime' => 0, 'd.deleteTime' => 0])
2025-10-29 10:30:50 +08:00
->find();
2025-10-29 11:48:02 +08:00
$member = array_merge($user, [
'lastLoginIp' => $this->request->ip(),
'lastLoginTime' => time()
]);
2025-10-29 10:30:50 +08:00
2025-10-29 11:48:02 +08:00
// 生成JWT令牌
$token = JwtUtil::createToken($user, 86400 * 30);
$token_expired = time() + 86400 * 30;
2025-10-29 10:30:50 +08:00
2025-10-29 11:48:02 +08:00
$data = [
'member' => $member,
'token' => $token,
'token_expired' => $token_expired
];
return successJson($data, '登录成功');
2025-10-29 10:30:50 +08:00
}
}