mivita/app/Models/UserShop.php
Kevin ac3bd6e8ea Statistiken/Abo: Kundenfeedback 2026-07-24 komplett umgesetzt + Steuern: DATEV-Fixes 08+09/2025 (Sammel-Commit Branch-WIP)
Feedback-Umsetzung (dev/2026-07-22/feedback-analyse-2026-07-24.md, alle 10 Punkte):
- VIP-Statistik: eigener Berater ('ich', Linie 0) in Neue-Kundenabos- und beiden Top-10-Listen; Top-10-Umsatz sortiert nach abgerechneten Ist-Punkten + Abo-Anzahl-Spalte; Fußnote nicht-payline-wirksame Punkte (SalesVolumePoints::nonPaylinePoints)
- Führungskräfte-Liste: beide Sichten 'direkt' (an nächster FK abgeschnitten, additiv) und 'gesamt' (komplette Downline), Gesamt-Spalte nach Kundenzählweise
- Team-Abos: je Ebene 'abgerechnet (Monat)' und 'bis zum 25. erwartet'; Payline-Karte mit Teamabo-/Kundenabo-Zählern
- Incentive-Live-Ranking: Qualifizierte zuerst nummeriert (fixt auch isWinner rank<=max_winners)
- Porto: Netto-/Brutto-Kennzeichnung (Berater netto, Endkunden inkl. MwSt., portal_view-Flag; auch CRM-/Shop-Warenkorb + Checkout), Yard::shipping_tax-Fix
- Struktur-Ansicht: Abo-Badges 'A' (eigenes Abo) und '(n)' (Kundenabos) je Teampartner, gebatcht
- Abo-Löschung: Softdelete setzt active=0 (UserAbo deleting-Hook) + Bereinigungs-Migration für gelöschte-aber-aktive Abos
- Doku: technische Analyse + Kundinnen-Feedback-Dokument unter dev/2026-07-22/
- Tests: IncentiveRankingTest, TeamStructureAboBadgesTest, YardShippingTaxTest (neu); BackofficeStatisticsListsTest, TeamAboOverviewTest, PaylineForecastServiceTest, AboAdminDeleteTest, AboOneTimeViewTest erweitert

Außerdem enthalten (Branch-WIP vor dem Feedback): DATEV-Abgleich-Fixes 08+09/2025, USt-ID-Live-Validierung sowie restliche unkommittete Stände (u. a. Abo-Pause-Sprachkeys).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 13:56:02 +00:00

213 lines
7.3 KiB
PHP

<?php
namespace App\Models;
use App\User;
use Carbon\Carbon;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* App\Models\UserShop
*
* @property int $id
* @property int $user_id
* @property string $name
* @property string $slug
* @property int $active
* @property int|null $set_defaults
* @property string|null $active_date
* @property string|null $title
* @property string|null $contact
* @property string|null $accessibility
* @property string|null $about
* @property array|null $featured
* @property string|null $filename
* @property string|null $originalname
* @property string|null $ext
* @property string|null $mine
* @property int|null $size
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read Collection|UserShopOnSite[] $on_sites
* @property-read int|null $on_sites_count
* @property-read User $user
*
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop findSimilarSlugs($attribute, $config, $slug)
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop newQuery()
* @method static \Illuminate\Database\Query\Builder|\App\Models\UserShop onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop query()
* @method static bool|null restore()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereAbout($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereAccessibility($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereActiveDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereContact($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereFeatured($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereOriginalname($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereSetDefaults($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserShop whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\UserShop withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\UserShop withoutTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*
* @property array|null $trans
*
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereTrans($value)
*
* @mixin \Eloquent
*/
class UserShop extends Model
{
protected $table = 'user_shops';
protected $casts = [
'featured' => 'array',
'trans' => 'array',
];
protected $fillable = [
'user_id', 'name', 'active', 'active_date',
];
use SoftDeletes;
protected $dates = ['deleted_at'];
use Sluggable;
public function sluggable(): array
{
return [
'slug' => [
'source' => 'name',
],
];
}
public function user()
{
return $this->belongsTo('App\User', 'user_id');
}
public function on_sites()
{
return $this->hasMany('App\Models\UserShopOnSite', 'user_shop_id', 'id');
}
public function getActiveDateFormat()
{
if (! $this->attributes['active_date']) {
return '';
}
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
}
public function getActiveDateFormatSmall()
{
if (! $this->attributes['active_date']) {
return '';
}
return Carbon::parse($this->attributes['active_date'])->format('d.m.Y');
}
public function getLang($key, $default = true)
{
$lang = \App::getLocale();
if ($lang == 'de') {
return $this->{$key};
}
return $this->getTrans($key, $lang, $default);
}
public function getTrans($key, $lang, $default = true)
{
if ($lang == 'de') {
return $this->{$key};
}
if (! empty($this->trans[$lang][$key])) {
return $this->trans[$lang][$key];
}
if ($default) {
return ! empty($this->{$key}) ? $this->{$key} : '';
}
return '';
}
public function getSubdomain($session = true)
{
if ($session && \Session::has('user_shop_domain')) {
return \Session::get('user_shop_domain');
}
return config('app.protocol').$this->attributes['slug'].'.'.config('app.domain').config('app.tld_care');
}
public function getSubdomainAvailable()
{
$rCurlHandle = curl_init($this->attributes['slug'].'.mivita.care');
curl_setopt($rCurlHandle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($rCurlHandle, CURLOPT_HEADER, true);
curl_setopt($rCurlHandle, CURLOPT_NOBODY, true);
curl_setopt($rCurlHandle, CURLOPT_RETURNTRANSFER, true);
$strResponse = curl_exec($rCurlHandle);
curl_close($rCurlHandle);
if (! $strResponse) {
return false;
}
$url = 'http://'.$this->attributes['slug'].'.mivita.care/domain/check';
if (@file_get_contents($url) != 'checked') {
return false;
}
return true;
}
public function isImage()
{
if (empty($this->attributes['filename']) || @$this->attributes['filename'] == null || @$this->attributes['filename'] == '') {
return false;
}
if (! \Storage::disk('public')->has('images/shop/'.$this->filename)) {
return false;
}
return true;
}
public function getImage()
{
if ($this->isImage()) {
$link = 'images/shop/'.$this->filename;
return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link);
}
return false;
}
}