mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:24:17 +00:00
no message
This commit is contained in:
parent
e68daf870f
commit
9d9e22451d
@ -2532,4 +2532,42 @@ class UsersController extends AbstractController
|
||||
//
|
||||
return Base::retSuccess('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/users/device/edit 41. 编辑设备
|
||||
*
|
||||
* @apiDescription 需要token身份
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup users
|
||||
* @apiName device__edit
|
||||
*
|
||||
* @apiParam {Object} detail 设备信息
|
||||
* @apiParam {String} detail.app_brand 设备品牌
|
||||
* @apiParam {String} detail.app_model 设备型号
|
||||
* @apiParam {String} detail.app_os 设备操作系统
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
* @apiSuccess {Object} data 返回数据
|
||||
*/
|
||||
public function device__edit()
|
||||
{
|
||||
User::auth();
|
||||
//
|
||||
$detail = Base::json2array(Request::input('detail'));
|
||||
$detail = array_intersect_key($detail, array_flip(['app_brand', 'app_model', 'app_os']));
|
||||
if (empty($detail)) {
|
||||
return Base::retError('参数错误');
|
||||
}
|
||||
//
|
||||
$row = UserDevice::record();
|
||||
if (empty($row)) {
|
||||
return Base::retError('设备不存在或已被删除');
|
||||
}
|
||||
$deviceInfo = array_merge(Base::json2array($row->detail), $detail);
|
||||
$row->detail = Base::array2json($deviceInfo);
|
||||
$row->save();
|
||||
//
|
||||
return Base::retSuccess('保存成功');
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,45 +234,47 @@ class UserDevice extends AbstractModel
|
||||
*/
|
||||
public static function record(string $token = null): ?self
|
||||
{
|
||||
if (empty($token)) {
|
||||
$token = Doo::userToken();
|
||||
$userid = Doo::userId();
|
||||
$expiredAt = Doo::userExpiredAt();
|
||||
} else {
|
||||
$info = Doo::tokenDecode($token);
|
||||
$userid = $info['userid'] ?? 0;
|
||||
$expiredAt = $info['expired_at'];
|
||||
}
|
||||
$deviceData = [
|
||||
'detail' => Base::array2json(self::getDeviceInfo($_SERVER['HTTP_USER_AGENT'] ?? '')),
|
||||
'expired_at' => $expiredAt,
|
||||
];
|
||||
|
||||
$hash = md5($token);
|
||||
$row = self::updateInsert([
|
||||
'userid' => $userid,
|
||||
'hash' => $hash,
|
||||
], function() use ($deviceData) {
|
||||
if (!Request::hasHeader('version')) {
|
||||
unset($deviceData['detail']);
|
||||
return AbstractModel::transaction(function () use ($token) {
|
||||
if (empty($token)) {
|
||||
$token = Doo::userToken();
|
||||
$userid = Doo::userId();
|
||||
$expiredAt = Doo::userExpiredAt();
|
||||
} else {
|
||||
$info = Doo::tokenDecode($token);
|
||||
$userid = $info['userid'] ?? 0;
|
||||
$expiredAt = $info['expired_at'];
|
||||
}
|
||||
return $deviceData;
|
||||
}, $deviceData, $isInsert);
|
||||
if ($isInsert) {
|
||||
$currentDeviceCount = self::whereUserid($userid)->count();
|
||||
if ($currentDeviceCount > self::$deviceLimit) {
|
||||
|
||||
$hash = md5($token);
|
||||
$row = self::whereHash($hash)->lockForUpdate()->first();
|
||||
if (empty($row)) {
|
||||
// 生成一个新的设备记录
|
||||
$row = self::createInstance([
|
||||
'userid' => $userid,
|
||||
'hash' => $hash,
|
||||
]);
|
||||
if (!$row->save()) {
|
||||
return null;
|
||||
}
|
||||
// 删除多余的设备记录
|
||||
$rows = self::whereUserid($userid)->orderBy('id')->take($currentDeviceCount - self::$deviceLimit)->get();
|
||||
foreach ($rows as $row) {
|
||||
UserDevice::forget($row);
|
||||
$currentDeviceCount = self::whereUserid($userid)->count();
|
||||
if ($currentDeviceCount > self::$deviceLimit) {
|
||||
$rows = self::whereUserid($userid)->orderBy('id')->take($currentDeviceCount - self::$deviceLimit)->get();
|
||||
foreach ($rows as $row) {
|
||||
UserDevice::forget($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($row) {
|
||||
$row->expired_at = $expiredAt;
|
||||
if (Request::hasHeader('version')) {
|
||||
$deviceInfo = array_merge(Base::json2array($row->detail), self::getDeviceInfo($_SERVER['HTTP_USER_AGENT'] ?? ''));
|
||||
$row->detail = Base::array2json($deviceInfo);
|
||||
}
|
||||
$row->save();
|
||||
|
||||
Cache::put(self::ck($hash), $row->userid, now()->addHour());
|
||||
return $row;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<div class="info">
|
||||
<div class="title">
|
||||
<span class="name">{{ getName(device.detail) }}</span>
|
||||
<span class="device">{{ device.detail.os }}</span>
|
||||
<span class="device">{{ getOs(device.detail) }}</span>
|
||||
</div>
|
||||
<div class="time">
|
||||
<EPopover placement="bottom-start" trigger="click">
|
||||
@ -92,11 +92,20 @@ export default {
|
||||
return 'web';
|
||||
},
|
||||
|
||||
getName({app_type, app_name, browser}) {
|
||||
getName({app_brand, app_model, app_type, app_name, browser}) {
|
||||
const array = [];
|
||||
if (/web/i.test(app_type)) {
|
||||
return browser + " " + this.$L("浏览器")
|
||||
array.push(...[browser, this.$L("浏览器")]);
|
||||
} else if (app_brand) {
|
||||
array.push(...[app_brand, app_model])
|
||||
} else {
|
||||
array.push(...[app_name || app_type, this.$L("客户端")])
|
||||
}
|
||||
return (app_name || app_type) + " " + this.$L("客户端")
|
||||
return array.join(' ');
|
||||
},
|
||||
|
||||
getOs({app_os, os}) {
|
||||
return app_os || os;
|
||||
},
|
||||
|
||||
onLogout(device) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user