mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 11:09:27 +00:00
Clean delete process
This commit is contained in:
@@ -42,7 +42,6 @@ class LabelController extends Controller
|
||||
{
|
||||
try {
|
||||
Label::whereId($id)->delete();
|
||||
NodeLabel::whereLabelId($id)->delete(); // 删除节点关联
|
||||
|
||||
return Response::json(['status' => 'success', 'message' => '删除成功']);
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -97,7 +97,6 @@ class RuleGroupController extends Controller
|
||||
{
|
||||
try {
|
||||
RuleGroup::whereId($id)->delete();
|
||||
RuleGroupNode::whereRuleGroupId($id)->delete();
|
||||
} catch (Exception $e) {
|
||||
return Response::json(['status' => 'fail', 'message' => '删除失败,'.$e->getMessage()]);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Jobs\VNet;
|
||||
|
||||
use App\Models\Node;
|
||||
use App\Models\User;
|
||||
use Arr;
|
||||
use Http;
|
||||
@@ -23,9 +24,9 @@ class addUser implements ShouldQueue
|
||||
private $data;
|
||||
private $nodes;
|
||||
|
||||
public function __construct($userIds, $nodes)
|
||||
public function __construct($userIds, $nodeIds)
|
||||
{
|
||||
$this->nodes = $nodes;
|
||||
$this->nodes = Node::findMany($nodeIds);
|
||||
$data = [];
|
||||
foreach (User::findMany($userIds) as $user) {
|
||||
$data[] = [
|
||||
|
||||
@@ -46,7 +46,7 @@ class editUser implements ShouldQueue
|
||||
if ($list && in_array($this->data['uid'], $list)) {
|
||||
$this->send($host, $secret);
|
||||
} else {
|
||||
addUser::dispatch($this->data['uid'], $node);
|
||||
addUser::dispatch($this->data['uid'], $node->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ class User extends Authenticatable
|
||||
|
||||
public function scopeUserAccessNodes()
|
||||
{
|
||||
return Node::userAllowNodes($this->attributes['group_id'], $this->attributes['level']);
|
||||
return Node::userAllowNodes($this->attributes['group_id'] ?? 0, $this->attributes['level'] ?? 0);
|
||||
}
|
||||
|
||||
public function getIsAvailableAttribute(): bool
|
||||
@@ -225,19 +225,16 @@ class User extends Authenticatable
|
||||
return $this->credit >= 0 && $this->save();
|
||||
}
|
||||
|
||||
// 添加用户余额
|
||||
|
||||
public function incrementData(int $data): bool
|
||||
{
|
||||
{// 添加用户流量
|
||||
$this->transfer_enable += $data;
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
// 添加用户流量
|
||||
|
||||
public function isNotCompleteOrderByUserId(int $userId): bool
|
||||
{
|
||||
{ // 添加用户余额
|
||||
|
||||
return Order::uid($userId)->whereIn('status', [0, 1])->exists();
|
||||
}
|
||||
|
||||
@@ -263,21 +260,18 @@ class User extends Authenticatable
|
||||
return $expired_status;
|
||||
}
|
||||
|
||||
public function isTrafficWarning()
|
||||
{
|
||||
public function isTrafficWarning(): bool
|
||||
{// 流量异常警告
|
||||
return $this->recentTrafficUsed() >= (sysConfig('traffic_ban_value') * GB);
|
||||
}
|
||||
|
||||
// 流量异常警告
|
||||
|
||||
public function recentTrafficUsed()
|
||||
{
|
||||
return UserHourlyDataFlow::userRecentUsed($this->id)->sum('total');
|
||||
}
|
||||
|
||||
//付费用户判断
|
||||
public function activePayingUser()
|
||||
{
|
||||
{ //付费用户判断
|
||||
return $this->orders()->active()->where('origin_amount', '>', 0)->exists();
|
||||
}
|
||||
|
||||
|
||||
@@ -83,17 +83,6 @@ class NodeObserver
|
||||
|
||||
public function deleted(Node $node): void
|
||||
{
|
||||
// 删除分组关联、节点标签、节点相关日志
|
||||
$node->labels()->delete();
|
||||
$node->heartBeats()->delete();
|
||||
$node->onlineLogs()->delete();
|
||||
$node->pingLogs()->delete();
|
||||
$node->dailyDataFlows()->delete();
|
||||
$node->hourlyDataFlows()->delete();
|
||||
$node->rules()->delete();
|
||||
$node->ruleGroup()->delete();
|
||||
$node->auth()->delete();
|
||||
|
||||
// 断开审计规则分组节点联系
|
||||
foreach (RuleGroup::all() as $ruleGroup) {
|
||||
$nodes = $ruleGroup->nodes;
|
||||
|
||||
@@ -6,13 +6,9 @@ use App\Components\Helpers;
|
||||
use App\Jobs\VNet\addUser;
|
||||
use App\Jobs\VNet\delUser;
|
||||
use App\Jobs\VNet\editUser;
|
||||
use App\Models\Node;
|
||||
use App\Models\User;
|
||||
use App\Models\UserSubscribe;
|
||||
use Arr;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Log;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
@@ -23,8 +19,8 @@ class UserObserver
|
||||
$subscribe->code = Helpers::makeSubscribeCode();
|
||||
$subscribe->save();
|
||||
|
||||
$allowNodes = Node::userAllowNodes($user->group_id, $user->level)->whereType(4)->get();
|
||||
if ($allowNodes->isNotEmpty()) {
|
||||
$allowNodes = $user->userAccessNodes()->whereType(4)->pluck('id');
|
||||
if ($allowNodes) {
|
||||
addUser::dispatch($user->id, $allowNodes);
|
||||
}
|
||||
}
|
||||
@@ -32,51 +28,15 @@ class UserObserver
|
||||
public function updated(User $user): void
|
||||
{
|
||||
$changes = $user->getChanges();
|
||||
$allowNodes = Node::userAllowNodes($user->group_id, $user->level)->whereType(4)->get();
|
||||
$allowNodes = $user->userAccessNodes()->whereType(4)->get();
|
||||
if ($allowNodes->isNotEmpty() && Arr::hasAny($changes, ['level', 'group_id', 'port', 'passwd', 'speed_limit', 'enable'])) {
|
||||
editUser::dispatch($user, $allowNodes);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleting(User $user): void
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
// 邀请关系脱钩
|
||||
$user->invites()->delete();
|
||||
$user->invitees()->update(['inviter_id' => 0]);
|
||||
$user->commissionSettlements()->delete();
|
||||
$user->commissionLogs()->delete();
|
||||
|
||||
$user->subscribe()->delete();
|
||||
$user->subscribeLogs()->delete();
|
||||
|
||||
// 清理日志
|
||||
$user->orders()->delete();
|
||||
$user->payments()->delete();
|
||||
$user->onlineIpLogs()->delete();
|
||||
$user->ruleLogs()->delete();
|
||||
$user->tickets()->delete();
|
||||
$user->ticketReplies()->delete();
|
||||
$user->banedLogs()->delete();
|
||||
$user->creditLogs()->delete();
|
||||
$user->dailyDataFlows()->delete();
|
||||
$user->dataFlowLogs()->delete();
|
||||
$user->dataModifyLogs()->delete();
|
||||
$user->hourlyDataFlows()->delete();
|
||||
$user->loginLogs()->delete();
|
||||
$user->verify()->delete();
|
||||
|
||||
DB::commit();
|
||||
} catch (Exception $e) {
|
||||
Log::error('删除用户相关信息错误:'.$e->getMessage());
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleted(User $user): void
|
||||
{
|
||||
$allowNodes = Node::userAllowNodes($user->group_id, $user->level)->whereType(4)->get();
|
||||
$allowNodes = $user->userAccessNodes()->whereType(4)->get();
|
||||
if ($allowNodes->isNotEmpty()) {
|
||||
delUser::dispatch($user->id, $allowNodes);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,10 @@ class ImproveTable extends Migration
|
||||
$table->foreign('ticket_id')->references('id')->on('ticket')->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('user', function (Blueprint $table) {
|
||||
$table->foreign('inviter_id')->references('id')->on('user')->nullOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('user_baned_log', function (Blueprint $table) {
|
||||
$table->foreign('user_id')->references('id')->on('user')->cascadeOnDelete();
|
||||
});
|
||||
@@ -336,6 +340,11 @@ class ImproveTable extends Migration
|
||||
$table->unsignedInteger('admin_id')->default(0)->nullable(false)->change();
|
||||
});
|
||||
|
||||
Schema::table('user', function (Blueprint $table) {
|
||||
$table->dropForeign(['inviter_id']);
|
||||
$table->dropIndex('user_inviter_id_foreign');
|
||||
});
|
||||
|
||||
Schema::table('user_baned_log', function (Blueprint $table) {
|
||||
$table->dropForeign(['user_id']);
|
||||
$table->dropIndex('user_baned_log_user_id_foreign');
|
||||
|
||||
Reference in New Issue
Block a user