mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
no message
This commit is contained in:
parent
f7206c1603
commit
52c389edd8
@ -1202,30 +1202,27 @@ class UsersController extends AbstractController
|
||||
}
|
||||
//
|
||||
$user = User::auth();
|
||||
$version = $data['appVersion'] ? ($data['appVersionName'] . " ({$data['appVersion']})") : '';
|
||||
$isNotified = trim($data['isNotified']) === 'true' || $data['isNotified'] === true ? 1 : intval($data['isNotified']);
|
||||
$inArray = [
|
||||
'userid' => $user->userid,
|
||||
'alias' => $data['alias'],
|
||||
'platform' => Base::platform(),
|
||||
];
|
||||
$version = $data['appVersion'] ? ($data['appVersionName'] . " ({$data['appVersion']})") : '';
|
||||
$isNotified = trim($data['isNotified']) === 'true' || $data['isNotified'] === true ? 1 : intval($data['isNotified']);
|
||||
$row = UmengAlias::where($inArray);
|
||||
if ($row->exists()) {
|
||||
$row->update([
|
||||
'ua' => $data['userAgent'],
|
||||
'device' => $data['deviceModel'],
|
||||
'version' => $version,
|
||||
'is_notified' => $isNotified,
|
||||
'updated_at' => Carbon::now()
|
||||
]);
|
||||
return Base::retSuccess('别名已存在');
|
||||
}
|
||||
$row = UmengAlias::createInstance(array_merge($inArray, [
|
||||
$upArray = [
|
||||
'ua' => $data['userAgent'],
|
||||
'device' => $data['deviceModel'],
|
||||
'device_hash' => UserDevice::check(),
|
||||
'version' => $version,
|
||||
'is_notified' => $isNotified,
|
||||
]));
|
||||
];
|
||||
$row = UmengAlias::where($inArray);
|
||||
if ($row->exists()) {
|
||||
$upArray['updated_at'] = Carbon::now();
|
||||
$row->update($upArray);
|
||||
return Base::retSuccess('别名已存在');
|
||||
}
|
||||
$row = UmengAlias::createInstance(array_merge($inArray, $upArray));
|
||||
if ($row->save()) {
|
||||
return Base::retSuccess('添加成功');
|
||||
} else {
|
||||
|
||||
@ -15,6 +15,8 @@ use Hedeqiang\UMeng\IOS;
|
||||
* @property string|null $alias 别名
|
||||
* @property string|null $platform 平台类型
|
||||
* @property string|null $device 设备类型
|
||||
* @property string|null $device_hash 设备哈希值,用于关联UserDevice表
|
||||
* @property string|null $user_lang 用户语言
|
||||
* @property string|null $version 应用版本号
|
||||
* @property string|null $ua userAgent
|
||||
* @property int|null $is_notified 通知权限
|
||||
@ -32,11 +34,13 @@ use Hedeqiang\UMeng\IOS;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereAlias($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereDevice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereDeviceHash($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereIsNotified($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias wherePlatform($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereUa($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereUserLang($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereUserid($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|UmengAlias whereVersion($value)
|
||||
* @mixin \Eloquent
|
||||
|
||||
@ -21,6 +21,7 @@ use Request;
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property \Illuminate\Support\Carbon|null $deleted_at
|
||||
* @property-read int $is_current
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelHidden()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel change($array)
|
||||
@ -173,36 +174,35 @@ class UserDevice extends AbstractModel
|
||||
|
||||
/**
|
||||
* 检查用户是否存在
|
||||
* @return bool
|
||||
* @return string|null
|
||||
*/
|
||||
public static function check(): bool
|
||||
public static function check(): ?string
|
||||
{
|
||||
$token = Doo::userToken();
|
||||
$userid = Doo::userId();
|
||||
|
||||
$hash = md5($token);
|
||||
if (Cache::has(self::ck($hash))) {
|
||||
return true;
|
||||
return $hash;
|
||||
}
|
||||
|
||||
$row = self::whereHash($hash)->first();
|
||||
if ($row) {
|
||||
// 判断是否过期
|
||||
if (Carbon::parse($row->expired_at)->isPast()) {
|
||||
Cache::forget(self::ck($hash));
|
||||
$row->delete();
|
||||
return false;
|
||||
self::forget($row);
|
||||
return null;
|
||||
}
|
||||
// 更新缓存
|
||||
self::record();
|
||||
return true;
|
||||
return $hash;
|
||||
}
|
||||
// 没有记录,尝试创建一个(防止升级后所有登录都失效,保证留一个可以保持登录) // todo 后期删除
|
||||
return AbstractModel::transaction(function () use ($userid) {
|
||||
return AbstractModel::transaction(function () use ($hash, $userid) {
|
||||
if (self::whereUserid($userid)->withoutTrashed()->lockForUpdate()->exists()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
return (bool)self::record();
|
||||
return self::record() ? $hash : null;
|
||||
});
|
||||
}
|
||||
|
||||
@ -285,6 +285,7 @@ class UserDevice extends AbstractModel
|
||||
}
|
||||
if (isset($hash)) {
|
||||
Cache::forget(self::ck($hash));
|
||||
UmengAlias::whereDeviceHash($hash)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDeviceHashAndUserLangToUmengAliasTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('umeng_alias', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('umeng_alias', 'device_hash')) {
|
||||
$table->string('device_hash')->index()->nullable()->after('device')->comment('设备哈希值,用于关联UserDevice表');
|
||||
$table->string('user_lang', 10)->nullable()->after('device_hash')->comment('用户语言');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('umeng_alias', function (Blueprint $table) {
|
||||
$table->dropColumn(['device_hash', 'user_lang']);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -231,8 +231,8 @@ services:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '1'
|
||||
memory: 1G
|
||||
cpus: '2'
|
||||
memory: 4G
|
||||
networks:
|
||||
extnetwork:
|
||||
ipv4_address: "${APP_IPPR}.15"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user