20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -3,25 +3,22 @@
|
|||
namespace App\Services;
|
||||
|
||||
use App\Models\Product;
|
||||
use Yard;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Models\UserAboOrder;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Models\UserAboOrder;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AboHelper
|
||||
{
|
||||
|
||||
|
||||
public static $txaction_filter_text = [
|
||||
'paid' => 'paymend_paid',
|
||||
'appointed' => 'paymend_open',
|
||||
'failed' => 'paymend_failed',
|
||||
'extern' => 'extern_open', //offen
|
||||
'extern' => 'extern_open', // offen
|
||||
'extern_paid' => 'extern_paid',
|
||||
'invoice_open' => 'invoice_open',
|
||||
'invoice_paid' => 'invoice_paid',
|
||||
|
|
@ -29,18 +26,19 @@ class AboHelper
|
|||
'NULL' => 'no_payment',
|
||||
];
|
||||
|
||||
|
||||
public static function userHasAbo(User $user)
|
||||
{
|
||||
$user = $user ? $user : \Auth::user();
|
||||
|
||||
return UserAbo::where('user_id', $user->id)->where('is_for', 'me')->where('status', '>', 1)->first() === null ? false : true;
|
||||
}
|
||||
|
||||
public static function memberHasAbo(ShoppingUser $shopping_user)
|
||||
{
|
||||
if (!$shopping_user) {
|
||||
if (! $shopping_user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return UserAbo::where('email', $shopping_user->billing_email)->where('is_for', 'ot')->where('status', '>', 1)->first() === null ? false : true;
|
||||
}
|
||||
|
||||
|
|
@ -52,19 +50,20 @@ class AboHelper
|
|||
public static function setAboStatus(ShoppingOrder $shopping_order, $status, $paid = false)
|
||||
{
|
||||
$user_abo = $shopping_order->getUserAbo();
|
||||
if ($user_abo && $user_abo->status < 2) { //status < 2 is not active
|
||||
if ($user_abo && $user_abo->status < 2) { // status < 2 is not active
|
||||
$user_abo->update(['status' => $status]);
|
||||
}
|
||||
UserAboOrder::where('user_abo_id', $user_abo->id)->where('shopping_order_id', $shopping_order->id)->update(['status' => $status, 'paid' => $paid]);
|
||||
}
|
||||
|
||||
public static function setAboActive(ShoppingOrder $shopping_order, $status, $paid = false)
|
||||
{
|
||||
self::setAboStatus($shopping_order, $status, $paid);
|
||||
|
||||
//delete UserAbo is not active status = 1
|
||||
//is_for = me
|
||||
// delete UserAbo is not active status = 1
|
||||
// is_for = me
|
||||
UserAbo::where('user_id', $shopping_order->auth_user_id)->where('is_for', 'me')->where('status', 1)->delete();
|
||||
//is_for = ot
|
||||
// is_for = ot
|
||||
UserAbo::where('member_id', $shopping_order->member_id)->where('email', $shopping_order->shopping_user->billing_email)->where('is_for', 'ot')->where('status', 1)->delete();
|
||||
}
|
||||
|
||||
|
|
@ -80,14 +79,29 @@ class AboHelper
|
|||
return true;
|
||||
}
|
||||
$paidOrdersCount = $user_abo->getCountPaidOrders();
|
||||
|
||||
return $paidOrdersCount >= (int) $minDuration;
|
||||
}
|
||||
|
||||
public static function isAddOnlyMode(UserAbo $user_abo, $view = 'user'): bool
|
||||
{
|
||||
if ($view === 'admin') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! self::canCancelAbo($user_abo, $view);
|
||||
}
|
||||
|
||||
public static function canEditAbo($user_abo, $view = 'user')
|
||||
{
|
||||
if ($view !== 'admin' && ($user_abo->user_id != \Auth::user()->id && $user_abo->member_id != \Auth::user()->id)) {
|
||||
if ($view === 'portal') {
|
||||
return true;
|
||||
}
|
||||
$user = \Auth::user();
|
||||
if ($view !== 'admin' && (! $user || ($user_abo->user_id != $user->id && $user_abo->member_id != $user->id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +114,10 @@ class AboHelper
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAboShowOn(Product $product)
|
||||
{
|
||||
$show_on = $product->show_on;
|
||||
|
|
@ -111,16 +127,19 @@ class AboHelper
|
|||
if (in_array('13', $show_on)) {
|
||||
return 'upgrade';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAboTypeBadge($abo_type)
|
||||
{
|
||||
if ($abo_type === 'base') {
|
||||
return '<span class="badge badge-pill badge-warning"><i class="fas fa-star"></i> ' . __('abo.' . $abo_type) . '</span></a>';
|
||||
return '<span class="badge badge-pill badge-warning"><i class="fas fa-star"></i> '.__('abo.'.$abo_type).'</span></a>';
|
||||
}
|
||||
if ($abo_type === 'upgrade') {
|
||||
return '<span class="badge badge-pill badge-info"><i class="far fa-star"></i> ' . __('abo.' . $abo_type) . '</span></a>';
|
||||
return '<span class="badge badge-pill badge-info"><i class="far fa-star"></i> '.__('abo.'.$abo_type).'</span></a>';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +147,7 @@ class AboHelper
|
|||
{
|
||||
$nextDate = Carbon::parse($date)->firstOfMonth();
|
||||
$nextDate->addDays($abo_interval - 1);
|
||||
|
||||
return $nextDate->gt($date) ? $nextDate : $nextDate->addMonth(1);
|
||||
}
|
||||
|
||||
|
|
@ -135,19 +155,20 @@ class AboHelper
|
|||
{
|
||||
$nextDate = Carbon::parse($date)->firstOfMonth()->addMonth(1);
|
||||
$nextDate->addDays($abo_interval - 1);
|
||||
|
||||
return $nextDate->gt($date) ? $nextDate : $nextDate->addMonth(1);
|
||||
}
|
||||
|
||||
public static function createNewAbo(ShoppingPayment $shopping_payment)
|
||||
{
|
||||
//is Abo - create init Abo from PP or else
|
||||
// is Abo - create init Abo from PP or else
|
||||
if ($shopping_payment->shopping_order->is_abo && $shopping_payment->shopping_order->abo_interval > 0) {
|
||||
$payment_transaction = $shopping_payment->payment_transactions->last();
|
||||
|
||||
//next_date immer im nächsten Monat starten
|
||||
//is auth_user_id = Berater bestellung
|
||||
//is member_id = Kunden bestellung
|
||||
//is for = me = mich oder ot = kunde
|
||||
// next_date immer im nächsten Monat starten
|
||||
// is auth_user_id = Berater bestellung
|
||||
// is member_id = Kunden bestellung
|
||||
// is for = me = mich oder ot = kunde
|
||||
$user_abo = UserAbo::create([
|
||||
'user_id' => $shopping_payment->shopping_order->auth_user_id,
|
||||
'member_id' => $shopping_payment->shopping_order->member_id,
|
||||
|
|
@ -188,15 +209,82 @@ class AboHelper
|
|||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$user_abo->load('user_abo_items');
|
||||
AboItemHistoryService::logInitialCreation($user_abo, 'system');
|
||||
}
|
||||
|
||||
public static function getTransStatusFilterText()
|
||||
{
|
||||
$ret = [];
|
||||
foreach (self::$txaction_filter_text as $key => $val) {
|
||||
$ret[$key] = trans('payment.' . $val);
|
||||
$ret[$key] = trans('payment.'.$val);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft effizient, ob ein User im Team eines anderen Users ist (Downline).
|
||||
* Traversiert die Sponsor-Hierarchie rekursiv (m_sponsor) statt die komplette
|
||||
* TreeCalcBot-Struktur aufzubauen.
|
||||
*
|
||||
* @param int $teamOwnerId ID des Team-Users (Berechtigter)
|
||||
* @param int $userToCheckId ID des zu prüfenden Users (z.B. Abo-Besitzer)
|
||||
* @param int $maxDepth Max. Tiefe (Schutz vor zirkulären Referenzen)
|
||||
* @return bool True wenn userToCheckId im Team von teamOwnerId ist
|
||||
*/
|
||||
public static function isUserInTeam(int $teamOwnerId, int $userToCheckId, int $maxDepth = 100): bool
|
||||
{
|
||||
if ($teamOwnerId === $userToCheckId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentId = $userToCheckId;
|
||||
$depth = 0;
|
||||
|
||||
while ($depth < $maxDepth) {
|
||||
$currentUser = User::where('id', $currentId)->select('m_sponsor')->first();
|
||||
if (! $currentUser || ! $currentUser->m_sponsor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($currentUser->m_sponsor === $teamOwnerId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentId = $currentUser->m_sponsor;
|
||||
$depth++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert alle User-IDs im Team (Downline) eines Users.
|
||||
* Traversiert die Sponsor-Hierarchie rekursiv nach unten statt TreeCalcBot.
|
||||
*
|
||||
* @param int $teamOwnerId ID des Team-Users
|
||||
* @param int $maxDepth Max. Tiefe (Schutz vor Endlosschleifen)
|
||||
* @return int[]
|
||||
*/
|
||||
public static function getTeamUserIds(int $teamOwnerId, int $maxDepth = 50): array
|
||||
{
|
||||
$teamUserIds = [];
|
||||
$toProcess = [$teamOwnerId];
|
||||
$depth = 0;
|
||||
|
||||
while (! empty($toProcess) && $depth < $maxDepth) {
|
||||
$children = User::whereIn('m_sponsor', $toProcess)
|
||||
->whereNull('deleted_at')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
$teamUserIds = array_merge($teamUserIds, $children);
|
||||
$toProcess = $children;
|
||||
$depth++;
|
||||
}
|
||||
|
||||
return array_values(array_unique($teamUserIds));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue