20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -2,7 +2,6 @@
namespace App\Services;
use App\Http\Controllers\Api\KasController;
use App\Models\ShoppingUser;
use App\Models\ShoppingUserMemberLog;
@ -12,8 +11,6 @@ use App\User;
class UserUtil
{
public static function setShoppingUserToNewMember($pre_member_id, $new_member_id)
{
$ShoppingUsers = ShoppingUser::where('member_id', $pre_member_id)->get();
@ -21,7 +18,7 @@ class UserUtil
ShoppingUserMemberLog::create([
'pre_member_id' => $shopping_user->member_id,
'shopping_user_id' => $shopping_user->id,
'new_member_id' => $new_member_id
'new_member_id' => $new_member_id,
]);
$shopping_user->member_id = $new_member_id;
$shopping_user->save();
@ -30,8 +27,8 @@ class UserUtil
public static function setNewSponsorToChilds($inactive_sponsor_id, $new_sponsor_id)
{
//alle User die diesen inaktivien Sponsor haben
$child_users = User::where('m_sponsor', $inactive_sponsor_id)->get(); //auch deaktiverte
// alle User die diesen inaktivien Sponsor haben
$child_users = User::where('m_sponsor', $inactive_sponsor_id)->get(); // auch deaktiverte
foreach ($child_users as $child_user) {
UserCleanUpLog::create([
'inactive_sponsor_id' => $inactive_sponsor_id,
@ -45,12 +42,12 @@ class UserUtil
public static function resetChildsToSponsor($re_sponsor_id)
{
//alle alten Childs vom re_sponsor_id / User wieder herstellen
// alle alten Childs vom re_sponsor_id / User wieder herstellen
$UserCleanUpUsers = UserCleanUpLog::where('inactive_sponsor_id', $re_sponsor_id)->get();
foreach ($UserCleanUpUsers as $UserCleanUpUser) {
$child_user = User::find($UserCleanUpUser->child_user_id);
if ($child_user) {
//delete Logs from user child where is newer then this
// delete Logs from user child where is newer then this
$deleteUserCleanUpLogs = UserCleanUpLog::where('child_user_id', $UserCleanUpUser->child_user_id)->where('created_at', '>', $UserCleanUpUser->created_at)->get();
foreach ($deleteUserCleanUpLogs as $deleteUserCleanUpLog) {
$deleteUserCleanUpLog->delete();
@ -58,11 +55,11 @@ class UserUtil
if ($child_user->m_sponsor) { // child is active
$child_user->m_sponsor = $re_sponsor_id;
}
if ($child_user->pre_sponsor) { //child is inactive
if ($child_user->pre_sponsor) { // child is inactive
$child_user->pre_sponsor = $re_sponsor_id;
}
$child_user->save();
//delete this log
// delete this log
$UserCleanUpUser->delete();
}
}
@ -72,10 +69,22 @@ class UserUtil
{
$user = User::find($user_id);
if ($user) {
if (! $user) {
\Log::channel('cleanup')->error('setUserToClient: User not found, user_id: '.$user_id);
return false;
}
if (! $user->account) {
\Log::channel('cleanup')->error('setUserToClient: User has no account data, user_id: '.$user_id);
return false;
}
try {
$data = [
'member_id' => $sponsor_id,
'language' => $user->lang ? $user->lang : 'de',
'language' => $user->lang ?? 'de',
'billing_salutation' => $user->account->salutation,
'billing_company' => $user->account->company,
'billing_firstname' => $user->account->first_name,
@ -87,6 +96,7 @@ class UserUtil
'billing_country_id' => $user->account->country_id,
'billing_phone' => $user->account->getPhoneNumber(),
'billing_email' => $user->email,
'language' => $user->account->getLocale(),
'same_as_billing' => $user->account->same_as_billing,
'shipping_salutation' => $user->account->shipping_salutation,
'shipping_company' => $user->account->shipping_company,
@ -100,11 +110,17 @@ class UserUtil
'shipping_phone' => $user->account->getShippingPhoneFull(),
'shipping_postnumber' => $user->account->shipping_postnumber,
];
ShoppingUser::create($data);
return true;
} catch (\Exception $e) {
\Log::channel('cleanup')->error('setUserToClient failed for user_id: '.$user_id.' | Error: '.$e->getMessage());
return false;
}
}
/*
find next activ sponsor on user id
first $sponsor_id can user_id, looks has m_sponsor or pre_sponsor.
@ -113,27 +129,28 @@ class UserUtil
{
$user = User::withTrashed()->find($sponsor_id);
if (!$user) { //kein User unter der ID - to root
if (! $user) { // kein User unter der ID - to root
return User::find(6);
}
//user ist aktiv
// user ist aktiv
if ($user->isActiveAccount()) {
return $user;
}
if ($user->m_sponsor) { //hat der User einen m_sponsor
if ($user->m_sponsor) { // hat der User einen m_sponsor
return self::findNextActiveSponsor($user->m_sponsor);
}
if ($user->pre_sponsor) { //hat der User einen pre_sponsor - schon inaktiv
if ($user->pre_sponsor) { // hat der User einen pre_sponsor - schon inaktiv
return self::findNextActiveSponsor($user->pre_sponsor);
}
//dump('not sponsor');
// dump('not sponsor');
return $user;
}
public static function deactiveUser($user)
{
$user->pre_sponsor = $user->m_sponsor; //den sponsor speichern für wiederherstellung
$user->pre_sponsor = $user->m_sponsor; // den sponsor speichern für wiederherstellung
$user->m_sponsor = null;
$user->active = false;
$user->save();
@ -143,7 +160,7 @@ class UserUtil
{
if ($user->pre_sponsor) {
$pre_sponsor = self::findNextActiveSponsor($user->pre_sponsor);
$user->m_sponsor = $pre_sponsor->id; //den sponsor wiederherstellen
$user->m_sponsor = $pre_sponsor->id; // den sponsor wiederherstellen
$user->pre_sponsor = null;
}
$user->active = true;
@ -152,14 +169,14 @@ class UserUtil
public static function deleteUser(User $user, $complete = false)
{
//shop wird gelöscht
// shop wird gelöscht
if ($user->shop) {
// $subdomain_name = $user->shop->slug . '.mivita.care';
$user->shop->name = "delete" . $user->shop->id;
$user->shop->slug = "delete" . $user->shop->id;
$user->shop->name = 'delete'.$user->shop->id;
$user->shop->slug = 'delete'.$user->shop->id;
$user->shop->save();
$user->shop->delete();
//isset KAS - delete Subdomain
// isset KAS - delete Subdomain
/*if (!Util::isTestSystem()) {
$kas = new KasController();
$pra = array(
@ -169,12 +186,12 @@ class UserUtil
}*/
}
//user soll nicht komplett gelöscht werden
$user->email = "delete-" . $user->email;
//password wird gelöscht
$user->password = "delete" . time();
// user soll nicht komplett gelöscht werden
$user->email = 'delete-'.$user->email;
// password wird gelöscht
$user->password = 'delete'.time();
$user->confirmed = 0;
$user->confirmation_code = "delete" . time();
$user->confirmation_code = 'delete'.time();
$user->confirmation_date = null;
$user->confirmation_code_to = null;
$user->confirmation_code_remider = 2;
@ -185,9 +202,9 @@ class UserUtil
$user->admin = 0;
$user->deleted_at = now();
$user->pre_deleted_at = now();
//user soll komplett gelöscht werden
// user soll komplett gelöscht werden
if ($complete) {
$user->email = "delete-" . time() . "-" . rand(1000, 9999);
$user->email = 'delete-'.time().'-'.rand(1000, 9999);
if ($user->account) {
$user->account->delete();
}
@ -198,14 +215,16 @@ class UserUtil
return true;
}
public static function checkEmailExists($user)
{
$email = str_replace("delete-", "", $user->email);
$email = str_replace('delete-', '', $user->email);
$user = User::where('email', $email)->first();
if ($user) {
return 'Der Account kann nicht wieder hergestellt werden, da die E-Mail-Adresse <b>' . $email . '</b> bereits in Verwendung ist.';
return 'Der Account kann nicht wieder hergestellt werden, da die E-Mail-Adresse <b>'.$email.'</b> bereits in Verwendung ist.';
}
return null;
}
@ -213,11 +232,11 @@ class UserUtil
{
if ($user->pre_sponsor) {
$pre_sponsor = self::findNextActiveSponsor($user->pre_sponsor);
$user->m_sponsor = $pre_sponsor->id; //den sponsor wiederherstellen
$user->m_sponsor = $pre_sponsor->id; // den sponsor wiederherstellen
$user->pre_sponsor = null;
}
$user->email = str_replace("delete-", "", $user->email);
$user->email = str_replace('delete-', '', $user->email);
$user->confirmed = 1;
$user->confirmation_date = now();
$user->confirmation_code = null;
@ -242,13 +261,13 @@ class UserUtil
}
}
public static function reactiveUserResetChilds($user_id, $info = '')
{
$user = User::find($user_id);
if (!$user) {
\Log::channel('cleanup')->error('reactiveUserResetChilds find no user by user_id:' . $user_id);
if (! $user) {
\Log::channel('cleanup')->error('reactiveUserResetChilds find no user by user_id:'.$user_id);
return 0;
}
$data = [
@ -258,7 +277,7 @@ class UserUtil
'm_first_name' => $user->account ? $user->account->m_first_name : '',
'm_last_name' => $user->account ? $user->account->m_last_name : '',
];
\Log::channel('cleanup')->info('reactiveUserResetChilds ' . $info . ' : ' . json_encode($data));
\Log::channel('cleanup')->info('reactiveUserResetChilds '.$info.' : '.json_encode($data));
self::reactiveUser($user);
self::resetChildsToSponsor($user->id);
@ -268,8 +287,9 @@ class UserUtil
{
$user = User::find($user_id);
if (!$user) {
\Log::channel('cleanup')->error('deactiveUserNewSponsorChilds find no user by user_id:' . $user_id);
if (! $user) {
\Log::channel('cleanup')->error('deactiveUserNewSponsorChilds find no user by user_id:'.$user_id);
return 0;
}
$data = [
@ -284,9 +304,9 @@ class UserUtil
if ($active_sponsor) {
self::setNewSponsorToChilds($user->id, $active_sponsor->id);
} else {
\Log::channel('cleanup')->error('cleanUpInActiveUser find no active_sponsor by inactive_user:' . $user->id);
\Log::channel('cleanup')->error('cleanUpInActiveUser find no active_sponsor by inactive_user:'.$user->id);
}
\Log::channel('cleanup')->info('deactiveUserNewSponsorChilds ' . $info . ' : ' . json_encode($data));
\Log::channel('cleanup')->info('deactiveUserNewSponsorChilds '.$info.' : '.json_encode($data));
self::deactiveUser($user);
}
}