Ergebnis des Senior-Reviews über dev/2026-07-22 (Konzept 22.07., Feedback 24.07.,
Plan 19.08.). Rechnerisch war nichts zu korrigieren: Payline-Punkte und Provision
des Prognose-Blocks (N4) stimmen exakt mit der Provisions-Engine überein
(54.718,5 P. bzw. 3.772,88 EUR gegengerechnet an User 454). Behoben sind
Darstellungs- und Konsistenzfehler, die der Beraterin als falsche Zahlen
aufgefallen wären:
- "+N neu" schrumpfte rückwirkend, der Bestand daneben nicht: newAboCount() nutzte
weiter activeAbo(), während aboStockCount() auf das Monatsende zurückrechnet.
Beide teilen sich jetzt aboStockQuery(); die Jahres-Wachstumstabelle ebenso.
- Level-Kachel widersprach sich ("Zum nächsten Level Diamant fehlen X" über
"Karriere-Level: Diamant"): Text auf die Monats-Qualifikation umformuliert
(de/en/es/fr), Überschrift "Qualifikation in diesem Monat", Karriere-Level nur
noch bei Abweichung.
- Firstlines-Kachel zählte alle direkten Partner, "Teampartner gesamt" daneben nur
aktive (F1): Kachel nutzt jetzt isActiveConsultant(), die Detailseite listet
weiter alle und weist beide Zahlen aus.
- Neupartnerzahlen vergangener Monate sanken auf dem Home-Dashboard, sobald
Jahresgebühren ausliefen: neue User::newPartnerReferenceDate() (laufender Monat =
heute, abgeschlossener Monat = Monatsende). Dabei die drei Inline-Kopien der
Neupartner-Regel auf scopeNewPartnerIn()/isNewPartnerIn() zusammengeführt.
- Top-3-Karte ließ den Betrachter aus, obwohl "ich gehört in die Liste" in der
Juli-Runde für alle anderen Ranglisten umgesetzt wurde: zählt jetzt mit, inkl.
is_self und "ich"-Badge.
- Neues Profilfoto zeigte bis zu 6 h ein totes Bild: die URL steckt nicht mehr im
Cache, sondern entsteht beim Lesen (withProfileImages()).
- Test-Regression seit der Juli-Runde: Unit/Services/BackofficeDashboardServiceTest
fiel über die fehlende Spalte status_points (kam mit nonPaylinePoints() dazu).
- Kleinigkeiten: ProfileImageController gab die komplette Exception als
Flash-Message aus (jetzt Log + Sprachkey), BackofficeDrilldownService formatierte
Datumsangaben hart auf d.m.Y statt über Util::formatDateDB().
Tests: neuer HomeMonthlyStatsTest (buildMonthlyStats war ungetestet) plus Tests für
Stichtags-Zählung und Foto-Cache. Fünf Tests kodierten das alte Verhalten
(Betrachter zählt nicht mit, abgelaufener Account zählt nie) und wurden auf die
neue Semantik umgestellt, jeweils mit Gegenprobe. Suite: 861 grün (vorher 855),
89 rot — ausschließlich die in docs/2026-06-11-test-suite-vorbestehende-fehler.md
dokumentierten Altlasten.
Offen und bewusst nicht enthalten:
- Deploy-Schritt: backoffice:store-statistics-snapshots --force (vorher dumpen).
Kein vorhandener Snapshot enthält recruiter_ranking, Mai/Juni zusätzlich weder
non_payline_points noch die Führungskräfte-"gesamt"-Spalten; der Cron überspringt
vorhandene Snapshots ohne --force. Achtung: die Neuberechnung ist nicht
verlustfrei.
- TreeHtmlRendererTest/TreeCalcBotIntegrationTest: die Abo-Badges machten den
Renderer datenbankabhängig; die Dateien waren schon vorher rot und gehören in die
separate Test-Aufräumaufgabe.
- deleteImage bleibt ein GET-Route (gleiches Muster wie das Shop-Bild).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
754 lines
23 KiB
PHP
754 lines
23 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Mail\MailResetPassword;
|
|
use App\Models\Account;
|
|
use App\Models\File;
|
|
use App\Models\PaymentMethod;
|
|
use App\Models\Product;
|
|
use App\Models\ShoppingOrder;
|
|
use App\Models\ShoppingUser;
|
|
use App\Models\UserBusiness;
|
|
use App\Models\UserHistory;
|
|
use App\Models\UserLevel;
|
|
use App\Models\UserSalesVolume;
|
|
use App\Models\UserShop;
|
|
use App\Models\UserUpdateEmail;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
use Illuminate\Notifications\DatabaseNotificationCollection;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Laravel\Passport\Client;
|
|
use Laravel\Passport\HasApiTokens;
|
|
use Laravel\Passport\Token;
|
|
|
|
/**
|
|
* App\User
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property string $password
|
|
* @property string|null $remember_token
|
|
* @property string|null $token
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read DatabaseNotificationCollection|DatabaseNotification[] $notifications
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereToken($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
|
|
*
|
|
* @property int $confirmed
|
|
* @property string|null $confirmation_code
|
|
* @property string|null $confirmation_date
|
|
* @property string|null $confirmation_code_to
|
|
* @property int $confirmation_code_remider
|
|
* @property int $active
|
|
* @property string|null $active_date
|
|
* @property string|null $agreement
|
|
* @property int $admin
|
|
* @property string $lang
|
|
* @property string|null $notes
|
|
* @property string|null $last_login
|
|
* @property \Illuminate\Support\Carbon|null $deleted_at
|
|
* @property-read Account $account
|
|
* @property-read Collection|UserUpdateEmail[] $user_update_email
|
|
*
|
|
* @method static bool|null forceDelete()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User onlyTrashed()
|
|
* @method static bool|null restore()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActiveDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAdmin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAgreement($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCode($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeRemider($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeTo($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmed($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLang($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLastLogin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereNotes($value)
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User withTrashed()
|
|
* @method static \Illuminate\Database\Query\Builder|\App\User withoutTrashed()
|
|
*
|
|
* @property int|null $account_id
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAccountId($value)
|
|
*
|
|
* @property int|null $wizard
|
|
* @property int|null $blocked
|
|
* @property string|null $payment_account
|
|
* @property string|null $payment_shop
|
|
* @property-read int|null $notifications_count
|
|
* @property-read UserShop $shop
|
|
* @property-read int|null $user_update_email_count
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereBlocked($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentAccount($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentShop($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereWizard($value)
|
|
*
|
|
* @property int|null $m_level
|
|
* @property int|null $m_sponsor
|
|
* @property-read UserLevel|null $user_level
|
|
* @property-read User|null $user_sponsor
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereMLevel($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereMSponsor($value)
|
|
*
|
|
* @property string|null $release_account
|
|
* @property int|null $payment_order_id
|
|
* @property int|null $abo_options
|
|
* @property-read Collection|File[] $files
|
|
* @property-read int|null $files_count
|
|
* @property-read Product|null $payment_order
|
|
* @property-read Collection|ShoppingOrder[] $shopping_orders
|
|
* @property-read int|null $shopping_orders_count
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAboOptions($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentOrderId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereReleaseAccount($value)
|
|
*
|
|
* @property-read Collection|UserHistory[] $user_histories
|
|
* @property-read int|null $user_histories_count
|
|
* @property int|null $test_mode
|
|
* @property array|null $settings
|
|
* @property-read Collection|ShoppingOrder[] $member_shopping_orders
|
|
* @property-read int|null $member_shopping_orders_count
|
|
* @property-read Collection|ShoppingUser[] $member_shopping_users
|
|
* @property-read int|null $member_shopping_users_count
|
|
* @property-read Product|null $payment_order_product
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereSettings($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTestMode($value)
|
|
*
|
|
* @property-read Collection|Client[] $clients
|
|
* @property-read int|null $clients_count
|
|
* @property-read Collection|Token[] $tokens
|
|
* @property-read int|null $tokens_count
|
|
* @property array|null $payment_methods
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentMethods($value)
|
|
*
|
|
* @property int|null $pre_sponsor
|
|
* @property-read User|null $user_pre_sponsor
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder|User wherePreSponsor($value)
|
|
*
|
|
* @property \Illuminate\Support\Carbon|null $pre_deleted_at
|
|
*
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|User wherePreDeletedAt($value)
|
|
*
|
|
* @property-read Collection<int, UserBusiness> $userBusiness
|
|
* @property-read int|null $user_business_count
|
|
*
|
|
* @mixin \Eloquent
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, Notifiable;
|
|
use SoftDeletes;
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
protected $table = 'users';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'email',
|
|
'password',
|
|
'token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'settings' => 'array',
|
|
'payment_methods' => 'array',
|
|
'pre_deleted_at' => 'datetime',
|
|
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
'token',
|
|
];
|
|
|
|
private $userSalesVolume = false;
|
|
|
|
public function account()
|
|
{
|
|
return $this->belongsTo('App\Models\UserAccount', 'account_id');
|
|
}
|
|
|
|
public function user_level()
|
|
{
|
|
return $this->belongsTo('App\Models\UserLevel', 'm_level');
|
|
}
|
|
|
|
public function user_sponsor()
|
|
{
|
|
return $this->belongsTo('App\User', 'm_sponsor');
|
|
}
|
|
|
|
/**
|
|
* Firstlines (direkte Teampartner) eines oder mehrerer Sponsoren —
|
|
* die eine autoritative Definition für Dashboard-Kachel, Firstlines-Seite
|
|
* und Team-Auswertungen.
|
|
*
|
|
* @param Builder $query
|
|
* @param int|int[] $sponsorIds
|
|
* @return Builder
|
|
*/
|
|
public function scopeFirstlinesOf($query, int|array $sponsorIds)
|
|
{
|
|
return $query->whereIn('m_sponsor', (array) $sponsorIds)
|
|
->whereColumn('id', '!=', 'm_sponsor')
|
|
->whereNull('deleted_at');
|
|
}
|
|
|
|
/**
|
|
* Stichtag der Neupartner-Prüfung: im laufenden (oder einem zukünftigen)
|
|
* Monat gilt „heute", für abgeschlossene Monate das Monatsende. Sonst würde
|
|
* die Neupartnerzahl eines vergangenen Monats rückwirkend sinken, sobald
|
|
* Jahresgebühren auslaufen — die Zahl muss aber stabil bleiben.
|
|
*/
|
|
public static function newPartnerReferenceDate(int $month, int $year): Carbon
|
|
{
|
|
$endOfMonth = Carbon::create($year, $month, 1)->endOfMonth();
|
|
|
|
return $endOfMonth->isFuture() ? now() : $endOfMonth;
|
|
}
|
|
|
|
/**
|
|
* Neupartner-Definition der Statistik (eine Regel für KPI, Recruiter-Ranking
|
|
* und Top-3-Karte): Mitgliedsebene gesetzt, Abrechnungskonto zum Stichtag
|
|
* gültig ({@see newPartnerReferenceDate()}), im Monat aktiv geworden.
|
|
*
|
|
* @param Builder $query
|
|
* @return Builder
|
|
*/
|
|
public function scopeNewPartnerIn($query, int $month, int $year)
|
|
{
|
|
$startDate = Carbon::create($year, $month, 1)->startOfMonth();
|
|
$endDate = $startDate->copy()->endOfMonth();
|
|
|
|
return $query->whereNotNull('m_level')
|
|
->whereNotNull('payment_account')
|
|
->where('payment_account', '>', self::newPartnerReferenceDate($month, $year))
|
|
->whereBetween('active_date', [$startDate, $endDate]);
|
|
}
|
|
|
|
/**
|
|
* PHP-seitiges Gegenstück zu {@see scopeNewPartnerIn()} für bereits geladene
|
|
* User-Collections (Linien-Auswertung, Recruiter-Ranking) — damit die
|
|
* Neupartner-Regel nur an einer Stelle definiert ist.
|
|
*/
|
|
public function isNewPartnerIn(int $month, int $year): bool
|
|
{
|
|
if ($this->m_level === null || $this->active_date === null || $this->payment_account === null) {
|
|
return false;
|
|
}
|
|
|
|
if (Carbon::parse($this->payment_account)->lte(self::newPartnerReferenceDate($month, $year))) {
|
|
return false;
|
|
}
|
|
|
|
$startDate = Carbon::create($year, $month, 1)->startOfMonth();
|
|
|
|
return Carbon::parse($this->active_date)->betweenIncluded($startDate, $startDate->copy()->endOfMonth());
|
|
}
|
|
|
|
public function user_pre_sponsor()
|
|
{
|
|
return $this->belongsTo('App\User', 'pre_sponsor');
|
|
}
|
|
|
|
public function payment_order_product()
|
|
{
|
|
return $this->belongsTo('App\Models\Product', 'payment_order_id');
|
|
}
|
|
|
|
public function files()
|
|
{
|
|
return $this->hasMany('App\Models\File', 'user_id', '');
|
|
}
|
|
|
|
public function shopping_orders()
|
|
{
|
|
return $this->hasMany('App\Models\ShoppingOrder', 'auth_user_id', '');
|
|
}
|
|
|
|
public function user_histories()
|
|
{
|
|
return $this->hasMany('App\Models\UserHistory', 'user_id', '');
|
|
}
|
|
|
|
public function shop()
|
|
{
|
|
return $this->hasOne('App\Models\UserShop', 'user_id', 'id');
|
|
}
|
|
|
|
public function user_update_email()
|
|
{
|
|
return $this->hasMany('App\Models\UserUpdateEmail', 'user_id', 'id');
|
|
}
|
|
|
|
public function member_shopping_orders()
|
|
{
|
|
return $this->hasMany('App\Models\ShoppingOrder', 'member_id', 'id');
|
|
}
|
|
|
|
public function member_shopping_users()
|
|
{
|
|
return $this->hasMany('App\Models\ShoppingUser', 'member_id', 'id');
|
|
}
|
|
|
|
public function userBusiness()
|
|
{
|
|
return $this->hasMany('App\Models\UserBusiness', 'user_id', 'id');
|
|
}
|
|
|
|
public function getLocale()
|
|
{
|
|
return $this->lang ? $this->lang : \App::getLocale();
|
|
}
|
|
|
|
public function getMUserSponsor()
|
|
{
|
|
if ($this->user_sponsor && $this->user_sponsor->account) {
|
|
return $this->user_sponsor->account->first_name.' '.$this->user_sponsor->account->last_name.' | '.$this->user_sponsor->email;
|
|
}
|
|
}
|
|
|
|
public function getFullName($email = true)
|
|
{
|
|
$ret = '';
|
|
if ($this->account) {
|
|
$ret = $this->account->first_name.' '.$this->account->last_name;
|
|
}
|
|
if ($email && $this->id > 1) {
|
|
$ret .= ' | '.$this->email;
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isPasswort()
|
|
{
|
|
if ($this->password == env('APP_KEY')) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isVIP()
|
|
{
|
|
if ($this->admin >= 1) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isAdmin()
|
|
{
|
|
if ($this->admin >= 2) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isSuperAdmin()
|
|
{
|
|
if ($this->admin >= 3) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isSySAdmin()
|
|
{
|
|
if ($this->admin >= 4) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function isUserHasApi()
|
|
{
|
|
if ($this->id === 3) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isApiUser()
|
|
{
|
|
if ($this->admin >= 5) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isTestMode()
|
|
{
|
|
return $this->test_mode ? true : false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function showSideNav()
|
|
{
|
|
if ($this->blocked != 0 || $this->wizard < 10) {
|
|
return false;
|
|
}
|
|
|
|
if ($this->active == 1) {
|
|
return true;
|
|
}
|
|
|
|
// Nach Account-Ablauf setzt u. a. cleanUpInActiveUser active=0; Zahlung/Mitgliedschaft
|
|
// muss im CRM weiterhin erreichbar sein (Navigation „Mein Konto“).
|
|
if ($this->payment_account && ! $this->isActiveAccount()) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function isAboOption()
|
|
{
|
|
return false;
|
|
// Abo Option deaktiviert ($this->abo_options && $this->account && $this->account->payment_data) ? true : false;
|
|
}
|
|
|
|
public function isActive()
|
|
{
|
|
return ($this->active == 1 && $this->blocked == 0) ? true : false;
|
|
}
|
|
|
|
public function isActiveAccount()
|
|
{
|
|
return $this->payment_account ? Carbon::parse($this->payment_account)->gt(Carbon::now()) : false;
|
|
}
|
|
|
|
public function isActiveShop()
|
|
{
|
|
return $this->payment_shop ? Carbon::parse($this->payment_shop)->gt(Carbon::now()) : false;
|
|
}
|
|
|
|
public function isRenewalAccount()
|
|
{
|
|
if ($this->payment_account) {
|
|
return Carbon::parse($this->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days')->lt(Carbon::now());
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function nextRenewalAccount()
|
|
{
|
|
return $this->payment_account ? Carbon::parse($this->payment_account)->modify('-'.config('mivita.renewal_days').' days')->format(\Util::formatDateTimeDB()) : false;
|
|
}
|
|
|
|
public function daysActiveAccount()
|
|
{
|
|
return Carbon::now()->diffInDays(Carbon::parse($this->payment_account), false);
|
|
}
|
|
|
|
public function modifyActiveAccount($add = '1 year')
|
|
{
|
|
return Carbon::parse($this->payment_account)->modify($add)->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function daysHumansActiveAccount()
|
|
{
|
|
return Carbon::now()->diffForHumans(Carbon::parse($this->payment_account));
|
|
}
|
|
|
|
public function daysActiveShop()
|
|
{
|
|
return Carbon::now()->diffInDays(Carbon::parse($this->payment_shop), false);
|
|
}
|
|
|
|
public function modifyActiveShop($add = '1 year')
|
|
{
|
|
return Carbon::parse($this->payment_shop)->modify($add)->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function daysHumansActiveShop()
|
|
{
|
|
return Carbon::now()->diffForHumans(Carbon::parse($this->payment_shop));
|
|
}
|
|
|
|
public function isAcountAboPayDate()
|
|
{
|
|
if ($this->isAboOption()) {
|
|
$pay_days = Carbon::parse($this->payment_account)->modify('- '.config('mivita.abo_booking_days').' days');
|
|
$diff_days = Carbon::now()->diffInDays($pay_days, false);
|
|
if ($diff_days <= 0) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getConfirmationDateFormat()
|
|
{
|
|
if (! $this->attributes['confirmation_date']) {
|
|
return '';
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['confirmation_date'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getActiveDateFormat($time = true)
|
|
{
|
|
if (! $this->attributes['active_date']) {
|
|
return '';
|
|
}
|
|
if (! $time) {
|
|
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getAgreementFormat()
|
|
{
|
|
if (! $this->attributes['agreement']) {
|
|
return '';
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['agreement'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function getPaymentAccountDateFormat($time = true)
|
|
{
|
|
if (! $this->attributes['payment_account']) {
|
|
return '';
|
|
}
|
|
if (! $time) {
|
|
return Carbon::parse($this->attributes['payment_account'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['payment_account'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function getPaymentShopDateFormat($time = true)
|
|
{
|
|
if (! $this->attributes['payment_shop']) {
|
|
return '';
|
|
}
|
|
if (! $time) {
|
|
return Carbon::parse($this->attributes['payment_shop'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['payment_shop'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function getReleaseAccountFormat($time = true)
|
|
{
|
|
if (! $this->attributes['release_account']) {
|
|
return '';
|
|
}
|
|
if (! $time) {
|
|
return Carbon::parse($this->attributes['release_account'])->format(\Util::formatDateDB());
|
|
}
|
|
|
|
return Carbon::parse($this->attributes['release_account'])->format(\Util::formatDateTimeDB());
|
|
}
|
|
|
|
public function setSetting(array $revisions, bool $save = true)
|
|
{
|
|
if (! $this->settings) {
|
|
$this->settings = [];
|
|
}
|
|
$this->settings = array_merge($this->settings, $revisions);
|
|
if ($save) {
|
|
$this->save();
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getSetting($key, $default = null)
|
|
{
|
|
return isset($this->settings[$key]) ? $this->settings[$key] : $default;
|
|
}
|
|
|
|
public function getPaymentMethodsShort()
|
|
{
|
|
$ret = '';
|
|
if ($this->payment_methods !== null) {
|
|
foreach ($this->payment_methods as $payment_method) {
|
|
if ($find = PaymentMethod::find($payment_method)) {
|
|
$ret .= $find->short.' | ';
|
|
}
|
|
}
|
|
$ret = rtrim($ret, ' | ');
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getLandByCountry()
|
|
{
|
|
if ($this->account && $this->account->country_id) {
|
|
$code = $this->account->country->code;
|
|
if ($code == 'FR') {
|
|
return 'fr';
|
|
}
|
|
if ($code == 'CH') {
|
|
return 'de';
|
|
}
|
|
if ($code == 'NL') {
|
|
return 'nl';
|
|
}
|
|
if ($code == 'DE') {
|
|
return 'de';
|
|
}
|
|
}
|
|
|
|
return 'de';
|
|
}
|
|
|
|
/**
|
|
* Send the password reset notification.
|
|
*
|
|
* @param string $token
|
|
* @return void
|
|
*/
|
|
public function sendPasswordResetNotification($token)
|
|
{
|
|
// $bcc[] = "kevin.adametz@me.com"; //config('app.checkout_mail');
|
|
// Mail::to($this->email)->bcc($bcc)->locale(\App::getLocale())->send(new MailResetPassword($token, $this));
|
|
Mail::to($this->email)->locale(\App::getLocale())->send(new MailResetPassword($token, $this));
|
|
// $this->notify(new ResetPasswordNotification($token));
|
|
}
|
|
|
|
public function getUserSalesVolumeBy($month, $year, $key)
|
|
{
|
|
|
|
// NOTE check ist, cant change month year !
|
|
if ($this->userSalesVolume === false) {
|
|
$this->userSalesVolume = $this->getUserSalesVolume($month, $year, 'first');
|
|
}
|
|
if ($this->userSalesVolume) {
|
|
switch ($key) {
|
|
case 'sales_volume_KP_points':
|
|
return $this->userSalesVolume->month_KP_points;
|
|
break;
|
|
case 'sales_volume_TP_points':
|
|
return $this->userSalesVolume->month_TP_points;
|
|
break;
|
|
case 'sales_volume_points_shop':
|
|
return $this->userSalesVolume->month_shop_points;
|
|
break;
|
|
|
|
case 'sales_volume_points_KP_sum':
|
|
return $this->userSalesVolume->getPointsKPSum();
|
|
break;
|
|
case 'sales_volume_points_TP_sum':
|
|
return $this->userSalesVolume->getPointsTPSum();
|
|
break;
|
|
// price net
|
|
case 'sales_volume_total':
|
|
return $this->userSalesVolume->month_total_net;
|
|
break;
|
|
|
|
case 'sales_volume_total_shop':
|
|
return $this->userSalesVolume->month_shop_total_net;
|
|
break;
|
|
|
|
case 'sales_volume_total_sum':
|
|
return $this->userSalesVolume->getTotalNetSum();
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// with = ['shopping_order.shopping_user'] <- optional wenn es noch weitere relations gibt
|
|
public function getUserSalesVolume($month, $year, $record = 'get', $with = [])
|
|
{
|
|
$relations = array_merge(['shopping_order'], $with);
|
|
$query = UserSalesVolume::with($relations)->where('user_id', $this->id)->where('month', $month)->where('year', $year)->orderBy('id', 'DESC');
|
|
switch ($record) {
|
|
case 'get':
|
|
return $query->get();
|
|
break;
|
|
case 'first':
|
|
return $query->first();
|
|
break;
|
|
}
|
|
}
|
|
}
|