mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
modal show global
This commit is contained in:
@@ -86,14 +86,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
add_filter('ttt', function ($d) {
|
||||
$d[] = 100;
|
||||
return $d;
|
||||
});
|
||||
$a = [];
|
||||
$a[] = '1';
|
||||
$a = apply_filter('ttt', $a);
|
||||
dd($a);
|
||||
$a = Carbon::parse('2022-08-06 23:08:03');
|
||||
$b = $a->clone()->addHours(1);
|
||||
dd($a, $b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
trait ExecuteCommandTrait
|
||||
{
|
||||
protected function executeCommand($command)
|
||||
{
|
||||
$this->info("Running $command ...");
|
||||
$result = exec($command, $output, $result_code);
|
||||
do_log(sprintf('command: %s, result_code: %s, output: %s, result: %s', $command, $result_code, json_encode($output), $result));
|
||||
if ($result_code != 0) {
|
||||
throw new \RuntimeException(json_encode($output));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_GIFT_TO_SOMEONE = 10;
|
||||
const BUSINESS_TYPE_NO_AD = 11;
|
||||
const BUSINESS_TYPE_GIFT_TO_LOW_SHARE_RATIO = 12;
|
||||
const BUSINESS_TYPE_LUCKY_DRAW = 13;
|
||||
|
||||
public static array $businessTypes = [
|
||||
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
|
||||
@@ -38,6 +39,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_GIFT_TO_SOMEONE => ['text' => 'Gift to someone'],
|
||||
self::BUSINESS_TYPE_NO_AD => ['text' => 'No ad'],
|
||||
self::BUSINESS_TYPE_GIFT_TO_LOW_SHARE_RATIO => ['text' => 'Gift to low share ratio'],
|
||||
self::BUSINESS_TYPE_LUCKY_DRAW => ['text' => 'Lucky draw'],
|
||||
];
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
|
||||
@@ -23,7 +23,7 @@ class NexusModel extends Model
|
||||
*/
|
||||
protected function serializeDate(\DateTimeInterface $date)
|
||||
{
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i');
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-2
@@ -135,7 +135,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
*/
|
||||
protected function serializeDate(\DateTimeInterface $date): string
|
||||
{
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i');
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +146,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
protected $fillable = [
|
||||
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status',
|
||||
'leechwarn', 'leechwarnuntil', 'page', 'class', 'uploaded', 'downloaded', 'clientselect', 'showclienterror', 'last_home',
|
||||
'seedbonus', 'bonuscomment', 'downloadpos', 'vip_added', 'vip_until', 'title',
|
||||
'seedbonus', 'bonuscomment', 'downloadpos', 'vip_added', 'vip_until', 'title', 'invites', 'attendance_card',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -439,6 +439,16 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
return $this->hasMany(PollAnswer::class, 'userid');
|
||||
}
|
||||
|
||||
public function metas()
|
||||
{
|
||||
return $this->hasMany(UserMeta::class, 'uid');
|
||||
}
|
||||
|
||||
public function usernameChangeLogs()
|
||||
{
|
||||
return $this->hasMany(UsernameChangeLog::class, 'uid');
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserMeta extends NexusModel
|
||||
{
|
||||
protected $fillable = ['uid', 'meta_key', 'meta_value', 'status', 'deadline'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
const STATUS_NORMAL = 0;
|
||||
|
||||
|
||||
const META_KEY_PERSONALIZED_USERNAME = 'PERSONALIZED_USERNAME';
|
||||
|
||||
const META_KEY_CHANGE_USERNAME = 'CHANGE_USERNAME';
|
||||
|
||||
protected $appends = ['meta_key_text'];
|
||||
|
||||
public function getMetaKeyTextAttribute()
|
||||
{
|
||||
return nexus_trans('label.user_meta.meta_keys.' . $this->meta_key) ?? '';
|
||||
}
|
||||
|
||||
public static function consumeBenefit($uid, $metaKey)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UsernameChangeLog extends NexusModel
|
||||
{
|
||||
protected $fillable = ['uid', 'username_old', 'username_new', ];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class SeedBoxRepository extends BaseRepository
|
||||
}
|
||||
$params['version'] = $ipEnd->getVersion();
|
||||
} else {
|
||||
throw new \InvalidArgumentException("Require ip or ip_begin + ip_end");
|
||||
throw new \InvalidArgumentException(nexus_trans('label.seed_box_record.ip_help'));
|
||||
}
|
||||
|
||||
return $params;
|
||||
|
||||
@@ -10,8 +10,10 @@ use App\Models\Message;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\UserBanLog;
|
||||
use App\Models\UserMeta;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Nexus\Database\NexusDB;
|
||||
@@ -82,12 +84,12 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
$username = $params['username'];
|
||||
if (!validusername($username)) {
|
||||
throw new \InvalidArgumentException("Innvalid username: $username");
|
||||
throw new \InvalidArgumentException("Invalid username: $username");
|
||||
}
|
||||
$email = htmlspecialchars(trim($params['email']));
|
||||
$email = safe_email($email);
|
||||
if (!check_email($email)) {
|
||||
throw new \InvalidArgumentException("Innvalid email: $email");
|
||||
throw new \InvalidArgumentException("Invalid email: $email");
|
||||
}
|
||||
if (User::query()->where('email', $email)->exists()) {
|
||||
throw new \InvalidArgumentException("The email address: $email is already in use");
|
||||
@@ -96,7 +98,7 @@ class UserRepository extends BaseRepository
|
||||
throw new \InvalidArgumentException("The username: $username is already in use");
|
||||
}
|
||||
if (mb_strlen($password) < 6 || mb_strlen($password) > 40) {
|
||||
throw new \InvalidArgumentException("Innvalid password: $password, it should be more than 6 character and less than 40 character");
|
||||
throw new \InvalidArgumentException("Invalid password: $password, it should be more than 6 character and less than 40 character");
|
||||
}
|
||||
$class = !empty($params['class']) ? intval($params['class']) : User::CLASS_USER;
|
||||
if (!isset(User::$classes[$class])) {
|
||||
@@ -365,10 +367,64 @@ class UserRepository extends BaseRepository
|
||||
|
||||
private function clearCache(User $user)
|
||||
{
|
||||
\Nexus\Database\NexusDB::cache_del("user_{$user->id}_content");
|
||||
\Nexus\Database\NexusDB::cache_del('user_passkey_'.$user->passkey.'_content');
|
||||
clear_user_cache($user->id, $user->passkey);
|
||||
}
|
||||
|
||||
public function listMetas($uid, $metaKeys = [], $valid = true)
|
||||
{
|
||||
$query = UserMeta::query()->where('uid', $uid);
|
||||
if (!empty($metaKeys)) {
|
||||
$query->whereIn('meta_key', Arr::wrap($metaKeys));
|
||||
}
|
||||
if ($valid) {
|
||||
$query->where('status', 0)->where(function (Builder $query) {
|
||||
$query->whereNull('deadline')->orWhere('deadline', '>=', now());
|
||||
});
|
||||
}
|
||||
return $query->get()->groupBy('meta_key');
|
||||
}
|
||||
|
||||
public function consumeBenefit($uid, array $params): bool
|
||||
{
|
||||
$metaKey = $params['meta_key'];
|
||||
$records = $this->listMetas($uid, $metaKey);
|
||||
if (!$records->has($metaKey)) {
|
||||
throw new \RuntimeException("User do not has this metaKey: $metaKey");
|
||||
}
|
||||
/** @var UserMeta $meta */
|
||||
$meta = $records->get($metaKey)->first();
|
||||
$user = User::query()->findOrFail($uid, User::$commonFields);
|
||||
if ($metaKey == UserMeta::META_KEY_CHANGE_USERNAME) {
|
||||
NexusDB::transaction(function () use ($user, $meta, $params) {
|
||||
$this->changeUsername($user, $params['username']);
|
||||
$meta->delete();
|
||||
clear_user_cache($user->id, $user->passkey);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Invalid meta_key: $metaKey");
|
||||
}
|
||||
|
||||
private function changeUsername(User $user, $newUsername): bool
|
||||
{
|
||||
if ($user->username == $newUsername) {
|
||||
throw new \RuntimeException("New username can not be the same with current username !");
|
||||
}
|
||||
if (!validusername($newUsername)) {
|
||||
throw new \InvalidArgumentException("Invalid username, length must between 4 and 20 characters");
|
||||
}
|
||||
if (User::query()->where('username', $newUsername)->where('id', '!=', $user->id)->exists()) {
|
||||
throw new \RuntimeException("Username: $newUsername already exists !");
|
||||
}
|
||||
NexusDB::transaction(function () use ($user, $newUsername) {
|
||||
$oldUsername = $user->username;
|
||||
$user->usernameChangeLogs()->create(['username_old' => $oldUsername, 'username_new' => $newUsername]);
|
||||
$user->username = $newUsername;
|
||||
$user->save();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user