mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
no message
This commit is contained in:
parent
e68daf870f
commit
9d9e22451d
@ -2532,4 +2532,42 @@ class UsersController extends AbstractController
|
|||||||
//
|
//
|
||||||
return Base::retSuccess('操作成功');
|
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,6 +234,7 @@ class UserDevice extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public static function record(string $token = null): ?self
|
public static function record(string $token = null): ?self
|
||||||
{
|
{
|
||||||
|
return AbstractModel::transaction(function () use ($token) {
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
$token = Doo::userToken();
|
$token = Doo::userToken();
|
||||||
$userid = Doo::userId();
|
$userid = Doo::userId();
|
||||||
@ -243,36 +244,37 @@ class UserDevice extends AbstractModel
|
|||||||
$userid = $info['userid'] ?? 0;
|
$userid = $info['userid'] ?? 0;
|
||||||
$expiredAt = $info['expired_at'];
|
$expiredAt = $info['expired_at'];
|
||||||
}
|
}
|
||||||
$deviceData = [
|
|
||||||
'detail' => Base::array2json(self::getDeviceInfo($_SERVER['HTTP_USER_AGENT'] ?? '')),
|
|
||||||
'expired_at' => $expiredAt,
|
|
||||||
];
|
|
||||||
|
|
||||||
$hash = md5($token);
|
$hash = md5($token);
|
||||||
$row = self::updateInsert([
|
$row = self::whereHash($hash)->lockForUpdate()->first();
|
||||||
|
if (empty($row)) {
|
||||||
|
// 生成一个新的设备记录
|
||||||
|
$row = self::createInstance([
|
||||||
'userid' => $userid,
|
'userid' => $userid,
|
||||||
'hash' => $hash,
|
'hash' => $hash,
|
||||||
], function() use ($deviceData) {
|
]);
|
||||||
if (!Request::hasHeader('version')) {
|
if (!$row->save()) {
|
||||||
unset($deviceData['detail']);
|
return null;
|
||||||
}
|
}
|
||||||
return $deviceData;
|
// 删除多余的设备记录
|
||||||
}, $deviceData, $isInsert);
|
|
||||||
if ($isInsert) {
|
|
||||||
$currentDeviceCount = self::whereUserid($userid)->count();
|
$currentDeviceCount = self::whereUserid($userid)->count();
|
||||||
if ($currentDeviceCount > self::$deviceLimit) {
|
if ($currentDeviceCount > self::$deviceLimit) {
|
||||||
// 删除多余的设备记录
|
|
||||||
$rows = self::whereUserid($userid)->orderBy('id')->take($currentDeviceCount - self::$deviceLimit)->get();
|
$rows = self::whereUserid($userid)->orderBy('id')->take($currentDeviceCount - self::$deviceLimit)->get();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
UserDevice::forget($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());
|
Cache::put(self::ck($hash), $row->userid, now()->addHour());
|
||||||
return $row;
|
return $row;
|
||||||
}
|
});
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<span class="name">{{ getName(device.detail) }}</span>
|
<span class="name">{{ getName(device.detail) }}</span>
|
||||||
<span class="device">{{ device.detail.os }}</span>
|
<span class="device">{{ getOs(device.detail) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="time">
|
<div class="time">
|
||||||
<EPopover placement="bottom-start" trigger="click">
|
<EPopover placement="bottom-start" trigger="click">
|
||||||
@ -92,11 +92,20 @@ export default {
|
|||||||
return 'web';
|
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)) {
|
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) {
|
onLogout(device) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user