update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
2
.devcontainer.env
Normal file
2
.devcontainer.env
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
WWWUSER=501
|
||||
WWWGROUP=20
|
||||
2
.devcontainer/.env
Normal file
2
.devcontainer/.env
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
WWWUSER=501
|
||||
WWWGROUP=20
|
||||
231
.devcontainer/Readme.md
Normal file
231
.devcontainer/Readme.md
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
# Laravel Sail DevContainer Setup
|
||||
|
||||
Diese Dokumentation beschreibt die Einrichtung und Verwendung des DevContainers für das Laravel Sail-Projekt.
|
||||
|
||||
## Übersicht
|
||||
|
||||
Der DevContainer ermöglicht es, das Laravel-Projekt in einer vollständig konfigurierten Docker-Umgebung zu entwickeln, ohne dass lokale PHP-, Node.js- oder andere Abhängigkeiten installiert werden müssen.
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Docker Desktop installiert und laufend
|
||||
- Cursor.ai oder VS Code mit DevContainer-Erweiterung
|
||||
- Git (für Repository-Zugriff)
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### 1. DevContainer-Konfiguration (`devcontainer.json`)
|
||||
|
||||
Die Hauptkonfiguration befindet sich in `.devcontainer/devcontainer.json`:
|
||||
|
||||
- **Eigenständiges Docker-Image**: Verwendet `sail-8.4/app` direkt ohne Docker Compose
|
||||
- **Build-Konfiguration**: Definiert Build-Argumente für `WWWUSER` und `WWWGROUP`
|
||||
- **Workspace**: `/var/www/html` (Standard-Laravel-Verzeichnis)
|
||||
- **Benutzer**: `sail` (Laravel Sail Standard-Benutzer)
|
||||
- **Features**: Leer (Tools werden über postCreateCommand installiert)
|
||||
- **Extensions**: PHP, Laravel Blade, Tailwind CSS Extensions
|
||||
- **Port-Forwarding**: Automatisch für wichtige Services (5173, 33061, 6380, 8025)
|
||||
|
||||
### 2. Dockerfile-Anpassungen (`docker/8.4/Dockerfile`)
|
||||
|
||||
Das Dockerfile wurde angepasst um:
|
||||
|
||||
- `ARG WWWUSER` hinzugefügt für korrekte Benutzer-ID
|
||||
- Benutzererstellung mit dynamischen IDs (`$WWWUSER` statt feste `1337`)
|
||||
- Vollständige Laravel-Umgebung mit PHP 8.4, Composer, NPM, Git
|
||||
|
||||
## Installation
|
||||
|
||||
### Automatische Installation (Empfohlen)
|
||||
|
||||
1. Öffnen Sie das Projekt in Cursor.ai oder VS Code
|
||||
2. Klicken Sie auf "Reopen in Container" wenn die DevContainer-Benachrichtigung erscheint
|
||||
3. Warten Sie bis der Container gebaut und gestartet ist
|
||||
|
||||
### Manuelle Installation
|
||||
|
||||
Falls die automatische Installation fehlschlägt, können Sie den Container manuell bauen:
|
||||
|
||||
```bash
|
||||
cd /Users/pandora/Sites/mivita.care
|
||||
docker build --build-arg WWWUSER=501 --build-arg WWWGROUP=20 -f docker/8.4/Dockerfile -t sail-8.4/app docker/8.4
|
||||
```
|
||||
|
||||
## Verfügbare Tools
|
||||
|
||||
Nach der Installation sind folgende Tools verfügbar:
|
||||
|
||||
- **PHP 8.4.12**: Mit Xdebug für Debugging
|
||||
- **Composer**: Für Laravel-Abhängigkeiten
|
||||
- **NPM**: Für Frontend-Assets
|
||||
- **Git**: Für Versionskontrolle
|
||||
- **Node.js**: Für JavaScript-Entwicklung
|
||||
|
||||
Überprüfen Sie die Installation:
|
||||
|
||||
```bash
|
||||
which git
|
||||
which npm
|
||||
which composer
|
||||
php --version
|
||||
```
|
||||
|
||||
## Post-Create-Befehle
|
||||
|
||||
Nach dem Erstellen des Containers werden automatisch ausgeführt:
|
||||
|
||||
1. Composer-Abhängigkeiten (`composer install`)
|
||||
|
||||
## Entwicklung
|
||||
|
||||
### Erste Schritte
|
||||
|
||||
1. **Composer-Abhängigkeiten**: Werden automatisch installiert
|
||||
2. **Laravel-Konfiguration**: `.env` Datei muss manuell erstellt werden (siehe Laravel-Dokumentation)
|
||||
3. **Datenbank-Migrationen**: `php artisan migrate`
|
||||
4. **Asset-Kompilierung**: `npm install && npm run dev`
|
||||
|
||||
### Häufige Befehle
|
||||
|
||||
```bash
|
||||
# Laravel-Befehle
|
||||
php artisan migrate
|
||||
php artisan serve
|
||||
php artisan tinker
|
||||
|
||||
# Composer
|
||||
composer install
|
||||
composer update
|
||||
|
||||
# NPM/Node
|
||||
npm install
|
||||
npm run dev
|
||||
npm run build
|
||||
|
||||
# Sail-Befehle (falls verfügbar)
|
||||
./vendor/bin/sail up
|
||||
./vendor/bin/sail artisan migrate
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container startet nicht
|
||||
|
||||
1. Überprüfen Sie ob Docker Desktop läuft
|
||||
2. Stellen Sie sicher, dass keine anderen Container die benötigten Ports blockieren
|
||||
3. Versuchen Sie einen Clean-Build: `docker build --no-cache ...`
|
||||
|
||||
### Berechtigungsprobleme
|
||||
|
||||
Die Container sind so konfiguriert, dass sie mit Ihrer lokalen Benutzer-ID (`501`) laufen, um Berechtigungsprobleme zu vermeiden.
|
||||
|
||||
### NPM Global Install Probleme
|
||||
|
||||
Falls Sie globale NPM-Pakete installieren möchten, verwenden Sie lokale Installation:
|
||||
|
||||
```bash
|
||||
# Lokale Installation (empfohlen)
|
||||
npm install package-name
|
||||
|
||||
# Oder NPM-Prefix ändern
|
||||
mkdir ~/.npm-global
|
||||
npm config set prefix '~/.npm-global'
|
||||
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
### Claude CLI Kompatibilitätsprobleme
|
||||
|
||||
**Problem**: Das `@anthropic-ai/claude-code` Paket ist nicht mit modernen Node.js-Versionen kompatibel.
|
||||
|
||||
**Symptome**:
|
||||
|
||||
- Viele veraltete Abhängigkeiten (deprecated packages)
|
||||
- PhantomJS ARM64 Kompatibilitätsprobleme
|
||||
- Engine-Konflikte mit Node.js v22
|
||||
|
||||
**Lösung**:
|
||||
|
||||
- Verwenden Sie die Cursor.ai-Integration direkt (empfohlen)
|
||||
- Oder verwenden Sie alternative CLI-Tools
|
||||
- Das Paket ist für die Laravel-Entwicklung nicht notwendig
|
||||
|
||||
### Port-Konflikte
|
||||
|
||||
Falls Ports bereits belegt sind, können Sie die Port-Mapping in der DevContainer-Konfiguration anpassen.
|
||||
|
||||
## Erweiterte Konfiguration
|
||||
|
||||
### Zusätzliche Extensions hinzufügen
|
||||
|
||||
Bearbeiten Sie `devcontainer.json` und fügen Sie Extensions zum `extensions` Array hinzu:
|
||||
|
||||
```json
|
||||
"extensions": [
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"onecentlin.laravel-blade",
|
||||
"shufo.vscode-blade-formatter",
|
||||
"bradlc.vscode-tailwindcss",
|
||||
"ihrc.vscode-php-cs-fixer"
|
||||
]
|
||||
```
|
||||
|
||||
### Zusätzliche Tools installieren
|
||||
|
||||
Fügen Sie Tools zum `postCreateCommand` hinzu:
|
||||
|
||||
```json
|
||||
"postCreateCommand": "composer install --no-interaction --prefer-dist --optimize-autoloader && npm install -g your-tool"
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Bei Problemen mit dem DevContainer:
|
||||
|
||||
1. Überprüfen Sie die Docker-Logs: `docker logs <container-name>`
|
||||
2. Stellen Sie sicher, dass alle Umgebungsvariablen korrekt gesetzt sind
|
||||
3. Versuchen Sie einen Neustart des DevContainers
|
||||
|
||||
## Bekannte Probleme und Lösungen
|
||||
|
||||
### DevContainer-CLI Kompatibilität
|
||||
|
||||
**Problem**: DevContainer-CLI erstellt temporäre Docker-Compose-Dateien die mit der Konfiguration kollidieren.
|
||||
|
||||
**Lösung**: Verwendung eines eigenständigen Docker-Images ohne Docker Compose-Abhängigkeit.
|
||||
|
||||
### Features-Installation
|
||||
|
||||
**Problem**: DevContainer Features können zu Build-Fehlern führen.
|
||||
|
||||
**Lösung**: Tools werden über `postCreateCommand` installiert statt über Features.
|
||||
|
||||
### Root-Berechtigungen
|
||||
|
||||
**Problem**: Der `sail`-Benutzer hat keine Root-Rechte für Paket-Installation.
|
||||
|
||||
**Lösung**: Alle notwendigen Tools sind bereits im Docker-Image installiert.
|
||||
|
||||
### Claude CLI Kompatibilität
|
||||
|
||||
**Problem**: Das `@anthropic-ai/claude-code` Paket ist veraltet und nicht mit Node.js v22 kompatibel.
|
||||
|
||||
**Symptome**:
|
||||
|
||||
- Hunderte von deprecated package warnings
|
||||
- PhantomJS ARM64 Kompatibilitätsprobleme
|
||||
- Engine-Konflikte mit modernen Node.js-Versionen
|
||||
|
||||
**Lösung**:
|
||||
|
||||
- **Verwenden Sie Cursor.ai direkt** (empfohlen) - keine CLI nötig
|
||||
- Das Paket ist für Laravel-Entwicklung nicht notwendig
|
||||
- Alle wichtigen Tools (PHP, Composer, NPM, Git) sind bereits verfügbar
|
||||
|
||||
---
|
||||
|
||||
**Letzte Aktualisierung**: September 2025
|
||||
**Laravel Version**: 11.x
|
||||
**PHP Version**: 8.4.12
|
||||
**Docker Version**: 2.x
|
||||
**Status**: ✅ Vollständig funktionsfähig
|
||||
78
.devcontainer/devcontainer.json
Normal file
78
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"name": "Mivita Care (Dev Container)",
|
||||
// 1. DIES IST DER WICHTIGSTE TEIL:
|
||||
// Wir verwenden Docker Compose für alle Services
|
||||
"dockerComposeFile": [
|
||||
"../docker-compose.yml"
|
||||
],
|
||||
"service": "laravel.test",
|
||||
// 3. WIR DEFINIEREN DEN ARBEITSBEREICH:
|
||||
// Das ist der Pfad, in dem Ihr Code *innerhalb* des Containers liegt.
|
||||
"workspaceFolder": "/var/www/html",
|
||||
// 4. WIR LEGEN DEN BENUTZER FEST:
|
||||
// Laravel Sail führt Befehle standardmäßig als 'sail'-Benutzer aus, um Berechtigungsprobleme zu vermeiden.
|
||||
"remoteUser": "sail",
|
||||
// 5. ZUSÄTZLICHE ENTWICKLER-TOOLS (FEATURES):
|
||||
// Features werden über postCreateCommand installiert um Kompatibilitätsprobleme zu vermeiden
|
||||
"features": {},
|
||||
// 6. BEFEHLE NACH DEM ERSTELLEN:
|
||||
// Installiert nur die Tools die ohne Root-Rechte funktionieren
|
||||
//"postCreateCommand": "composer install --no-interaction --prefer-dist --optimize-autoloader",
|
||||
// 7. EDITOR-ANPASSUNGEN (Optional, aber sehr empfohlen):
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"onecentlin.laravel-blade",
|
||||
"shufo.vscode-blade-formatter",
|
||||
"bradlc.vscode-tailwindcss"
|
||||
]
|
||||
}
|
||||
},
|
||||
// 8. ZU STARTENDE DIENSTE:
|
||||
// Legt fest, welche Dienste aus der docker-compose.yml gestartet werden sollen.
|
||||
"runServices": [
|
||||
"laravel.test",
|
||||
"mysql",
|
||||
"redis",
|
||||
"mailpit"
|
||||
],
|
||||
// 9. ZUSÄTZLICHE KONFIGURATION:
|
||||
// Umgebungsvariablen für den DevContainer
|
||||
"containerEnv": {
|
||||
"WWWUSER": "501",
|
||||
"WWWGROUP": "20",
|
||||
"LARAVEL_SAIL": "1"
|
||||
},
|
||||
// 10. MOUNT-KONFIGURATION:
|
||||
// Stellt sicher, dass der Code korrekt gemountet wird
|
||||
"mounts": [
|
||||
"source=${localWorkspaceFolder},target=/var/www/html,type=bind,consistency=cached"
|
||||
],
|
||||
// 11. FORWARD PORTS:
|
||||
// Ports die automatisch weitergeleitet werden sollen
|
||||
"forwardPorts": [
|
||||
5173,
|
||||
33061,
|
||||
6380,
|
||||
8025
|
||||
],
|
||||
"portsAttributes": {
|
||||
"5173": {
|
||||
"label": "Vite Dev Server",
|
||||
"onAutoForward": "notify"
|
||||
},
|
||||
"33061": {
|
||||
"label": "MySQL",
|
||||
"onAutoForward": "silent"
|
||||
},
|
||||
"6380": {
|
||||
"label": "Redis",
|
||||
"onAutoForward": "silent"
|
||||
},
|
||||
"8025": {
|
||||
"label": "Mailpit Dashboard",
|
||||
"onAutoForward": "notify"
|
||||
}
|
||||
}
|
||||
}
|
||||
125
.devcontainer/docker-compose.dev.yml
Normal file
125
.devcontainer/docker-compose.dev.yml
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
services:
|
||||
laravel.test:
|
||||
build:
|
||||
context: '../docker/8.4'
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
# Führen Sie in Ihrem normalen Terminal `id -u` aus und tragen Sie die Zahl hier ein.
|
||||
WWWUSER: '501'
|
||||
# Führen Sie in Ihrem normalen Terminal `id -g` aus und tragen Sie die Zahl hier ein.
|
||||
WWWGROUP: '20'
|
||||
image: 'sail-8.4/app'
|
||||
extra_hosts:
|
||||
- 'host.docker.internal:host-gateway'
|
||||
ports:
|
||||
- '5173:5173'
|
||||
environment:
|
||||
# Laravel Sail Environment Variables
|
||||
WWWUSER: '501'
|
||||
WWWGROUP: '20'
|
||||
LARAVEL_SAIL: 1
|
||||
XDEBUG_MODE: 'develop,debug'
|
||||
XDEBUG_CONFIG: 'client_host=host.docker.internal'
|
||||
IGNITION_LOCAL_SITES_PATH: '/var/www/html'
|
||||
# Database Configuration
|
||||
DB_CONNECTION: mysql
|
||||
DB_HOST: mysql
|
||||
DB_PORT: 3306
|
||||
DB_DATABASE: mivita
|
||||
DB_USERNAME: sail
|
||||
DB_PASSWORD: password
|
||||
# Application Configuration
|
||||
APP_NAME: Mivita
|
||||
APP_ENV: local
|
||||
APP_DEBUG: true
|
||||
APP_URL: http://localhost
|
||||
# Mail Configuration
|
||||
MAIL_MAILER: smtp
|
||||
MAIL_HOST: mailpit
|
||||
MAIL_PORT: 1025
|
||||
MAIL_USERNAME: null
|
||||
MAIL_PASSWORD: null
|
||||
MAIL_ENCRYPTION: null
|
||||
MAIL_FROM_ADDRESS: hello@example.com
|
||||
MAIL_FROM_NAME: Mivita
|
||||
# Redis Configuration
|
||||
REDIS_HOST: redis
|
||||
REDIS_PASSWORD: null
|
||||
REDIS_PORT: 6379
|
||||
# Vite Configuration
|
||||
VITE_PORT: 5173
|
||||
# Forward Ports
|
||||
FORWARD_DB_PORT: 33061
|
||||
FORWARD_REDIS_PORT: 6380
|
||||
FORWARD_MAILPIT_PORT: 1025
|
||||
FORWARD_MAILPIT_DASHBOARD_PORT: 8025
|
||||
# MySQL Extra Options
|
||||
MYSQL_EXTRA_OPTIONS: --default-authentication-plugin=mysql_native_password
|
||||
volumes:
|
||||
- '../:/var/www/html'
|
||||
networks:
|
||||
- sail
|
||||
depends_on:
|
||||
- mysql
|
||||
- redis
|
||||
- mailpit
|
||||
|
||||
mysql:
|
||||
image: 'mysql/mysql-server:8.0'
|
||||
ports:
|
||||
- '33061:3306'
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
MYSQL_ROOT_HOST: '%'
|
||||
MYSQL_DATABASE: mivita
|
||||
MYSQL_USER: sail
|
||||
MYSQL_PASSWORD: password
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: 1
|
||||
MYSQL_EXTRA_OPTIONS: --default-authentication-plugin=mysql_native_password
|
||||
volumes:
|
||||
- 'sail-mysql:/var/lib/mysql'
|
||||
- '../docker/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
|
||||
networks:
|
||||
- sail
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD
|
||||
- mysqladmin
|
||||
- ping
|
||||
- '-ppassword'
|
||||
retries: 3
|
||||
timeout: 5s
|
||||
|
||||
redis:
|
||||
image: 'redis:alpine'
|
||||
ports:
|
||||
- '6380:6379'
|
||||
volumes:
|
||||
- 'sail-redis:/data'
|
||||
networks:
|
||||
- sail
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD
|
||||
- redis-cli
|
||||
- ping
|
||||
retries: 3
|
||||
timeout: 5s
|
||||
|
||||
mailpit:
|
||||
image: 'axllent/mailpit:latest'
|
||||
ports:
|
||||
- '1025:1025'
|
||||
- '8025:8025'
|
||||
networks:
|
||||
- sail
|
||||
|
||||
networks:
|
||||
sail:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
sail-mysql:
|
||||
driver: local
|
||||
sail-redis:
|
||||
driver: local
|
||||
8
.env
8
.env
|
|
@ -73,7 +73,7 @@ QUEUE_DRIVER=redis
|
|||
QUEUE_CONNECTION=redis
|
||||
REDIS_HOST=redis
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
REDIS_PORT=6380
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
|
|
@ -91,6 +91,7 @@ PUSHER_APP_CLUSTER=mt1
|
|||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
|
||||
MIVITA_RENEWAL_DAYS=29
|
||||
MIVITA_REMIND_FIRST_DAYS=21
|
||||
MIVITA_REMIND_SEC_DAYS=14
|
||||
|
|
@ -106,6 +107,8 @@ MIVITA_ADD_NUMBER_ID=946
|
|||
|
||||
# DHL API Zugangsdaten (konsolidiert)
|
||||
DHL_BASE_URL=https://api-eu.dhl.com
|
||||
DHL_SANDBOX_URL=https://api-sandbox.dhl.com
|
||||
|
||||
DHL_API_KEY=AxGBdF8DBdIAmuhqvG0ASBRKFvyV7ypX
|
||||
DHL_USERNAME=riwa-tec
|
||||
DHL_PASSWORD=MivitaCare!!2025
|
||||
|
|
@ -130,6 +133,9 @@ DHL_ACCOUNT_NUMBER_V62WP=63144073556201 # Warenpost National
|
|||
DHL_ACCOUNT_NUMBER_V53PAK=63144073555301 # DHL Paket International
|
||||
DHL_ACCOUNT_NUMBER_V07PAK=63144073550701 # DHL Retoure Online
|
||||
#sandbox
|
||||
DHL_USERNAME=user-valid
|
||||
DHL_PASSWORD=SandboxPasswort2023!
|
||||
DHL_BILLING_NUMBER=33333333330101
|
||||
DHL_ACCOUNT_NUMBER_DEFAULT=33333333330101
|
||||
DHL_ACCOUNT_NUMBER_V01PAK=33333333330102 # DHL Paket National
|
||||
DHL_ACCOUNT_NUMBER_V62WP=33333333336601 # Warenpost National
|
||||
|
|
|
|||
187
CLAUDE.md
Normal file
187
CLAUDE.md
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
This is a Laravel 11 business e-commerce application called "mivita.care" that handles multi-level marketing structures, product sales, payments, and DHL shipping integration. The application supports multi-tenancy through domain resolution and includes comprehensive business analytics and commission calculations.
|
||||
|
||||
## Development Commands
|
||||
|
||||
### Core Laravel Commands
|
||||
```bash
|
||||
# Run development server
|
||||
php artisan serve
|
||||
|
||||
# Run scheduled tasks
|
||||
php artisan schedule:run
|
||||
|
||||
# Clear application cache
|
||||
php artisan cache:clear
|
||||
php artisan config:clear
|
||||
php artisan route:clear
|
||||
php artisan view:clear
|
||||
|
||||
# Generate IDE helper files
|
||||
php artisan ide-helper:generate
|
||||
php artisan ide-helper:models
|
||||
php artisan ide-helper:meta
|
||||
|
||||
# Database migrations
|
||||
php artisan migrate
|
||||
php artisan migrate:rollback
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Run tests using Pest
|
||||
./vendor/bin/pest
|
||||
|
||||
# Run specific test
|
||||
./vendor/bin/pest --filter=TestName
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
```bash
|
||||
# Format code using Laravel Pint
|
||||
./vendor/bin/pint
|
||||
composer run format
|
||||
```
|
||||
|
||||
### Asset Compilation
|
||||
```bash
|
||||
# Install node dependencies
|
||||
npm install
|
||||
|
||||
# Development build
|
||||
npm run dev
|
||||
npm run watch
|
||||
|
||||
# Production build
|
||||
npm run production
|
||||
|
||||
# Asset postinstall (rebuilds node-sass)
|
||||
npm run postinstall
|
||||
```
|
||||
|
||||
### Business-Specific Commands
|
||||
```bash
|
||||
# Business structure calculations (optimized version - recommended)
|
||||
php artisan business:store-optimized {month} {year}
|
||||
php artisan business:store-optimized {month} {year} --clear
|
||||
|
||||
# Legacy business structure command
|
||||
php artisan business:store {month} {year}
|
||||
|
||||
# Clear business data
|
||||
php artisan business:clear-data {month} {year}
|
||||
php artisan business:clear-data {month} {year} --force
|
||||
|
||||
# User management
|
||||
php artisan user:cleanup
|
||||
php artisan user:make_abo_order
|
||||
|
||||
# Payment processing
|
||||
php artisan payments:check-accounts
|
||||
|
||||
# Level reports (new feature)
|
||||
php artisan business:level-reports {month} {year}
|
||||
|
||||
# Test account management
|
||||
php artisan business:test-account
|
||||
```
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
### Multi-Level Marketing Structure
|
||||
- **TreeCalcBot/TreeCalcBotOptimized**: Core business logic for calculating commission structures and multi-level hierarchies
|
||||
- **BusinessPlan Services**: Handle commission calculations, sales volumes, and business structure management
|
||||
- **BusinessController/BusinessControllerOptimized**: Handle business administration and analytics
|
||||
|
||||
### Domain Architecture
|
||||
- **Multi-tenant setup** using domain resolution
|
||||
- **DomainService**: Manages domain-specific configurations and routing
|
||||
- **DomainResolver Middleware**: Routes requests based on domain
|
||||
|
||||
### Key Service Classes
|
||||
- **Payment Services**: Handle various payment methods (Payone, credit systems, invoices)
|
||||
- **DHL Integration**: Complete shipping solution with label generation and tracking
|
||||
- **Shopping Cart Systems**: Multiple cart implementations (AboOrderCart, HomepartyCart, ShopApiOrderCart)
|
||||
- **User Management**: Comprehensive user hierarchy and team management
|
||||
|
||||
### Database Structure
|
||||
- Business users with hierarchical relationships
|
||||
- Product catalog with categories and ingredients
|
||||
- Order and payment tracking
|
||||
- Commission and sales volume calculations
|
||||
- Multi-domain configurations
|
||||
|
||||
### Custom Packages
|
||||
- **Gloudemans\Shoppingcart**: Custom shopping cart implementation
|
||||
- **Acme\Dhl**: DHL shipping integration package
|
||||
- **Alban\LaravelCollectiveSpatieHtmlParser**: HTML parsing utilities
|
||||
|
||||
## Scheduled Tasks (Cron Jobs)
|
||||
The application runs several daily scheduled tasks (defined in `app/Console/Kernel.php`):
|
||||
- `02:00` - Payment account checks (`payments:check-accounts`)
|
||||
- `03:00` - Business structure optimization (`store-optimized 0 0`)
|
||||
- `03:30` - User cleanup (`user:cleanup`)
|
||||
- `04:00` - Automated subscription orders (`user:make_abo_order`)
|
||||
|
||||
## Important File Locations
|
||||
- **Business Commands**: `app/Console/Commands/Business*.php`
|
||||
- **Service Classes**: `app/Services/` (extensive service layer)
|
||||
- **Controllers**: `app/Http/Controllers/` (40+ controllers)
|
||||
- **Custom Packages**: `packages/` directory
|
||||
- **Dev Documentation**: `dev/code/Services/*.md` (contains optimization guides)
|
||||
|
||||
## Development Notes
|
||||
|
||||
### Business Optimization Features
|
||||
- Use `TreeCalcBotOptimized` for all new business calculation features
|
||||
- Memory monitoring and automatic garbage collection built into optimized commands
|
||||
- Comprehensive error handling with graceful degradation
|
||||
- Performance logging and monitoring capabilities
|
||||
|
||||
### DHL Shipping Integration
|
||||
- Full DHL API integration with both Developer API and Business Customer API support
|
||||
- Automatic label generation and tracking
|
||||
- Sandbox/production mode switching
|
||||
- Complete shipping workflow integration
|
||||
|
||||
### Multi-Domain Support
|
||||
- Each domain can have different configurations
|
||||
- Domain-specific routing and middleware
|
||||
- Subdomain management through console commands
|
||||
|
||||
### Asset Management
|
||||
- Laravel Mix for asset compilation
|
||||
- Appwork theme integration with Bootstrap 4
|
||||
- Vendor assets management with SASS compilation
|
||||
- Custom node-sass rebuild process for compatibility
|
||||
|
||||
## Docker Development Environment
|
||||
The project uses Laravel Sail with Docker Compose:
|
||||
```bash
|
||||
# Start services
|
||||
docker-compose up -d
|
||||
|
||||
# Execute artisan commands in container
|
||||
./vendor/bin/sail artisan [command]
|
||||
|
||||
# Access container shell
|
||||
./vendor/bin/sail shell
|
||||
```
|
||||
|
||||
### Services:
|
||||
- **laravel.test**: Main application (Traefik-enabled with SSL)
|
||||
- **horizon**: Laravel Horizon queue worker
|
||||
- **mysql**: MySQL 8.0 database server
|
||||
- **redis**: Redis cache/session store
|
||||
- **mailpit**: Email testing interface (accessible at mivita-mail.test)
|
||||
|
||||
### Domain Configuration:
|
||||
- Main domain: `mivita.test`
|
||||
- Wildcard subdomain support: `*.mivita.test`
|
||||
- Mail interface: `mivita-mail.test`
|
||||
- Uses Traefik reverse proxy with SSL
|
||||
|
|
@ -189,8 +189,6 @@ namespace App\Models{
|
|||
|
||||
namespace App\Models{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $name
|
||||
* @property string $email
|
||||
|
|
@ -221,6 +219,8 @@ namespace App\Models{
|
|||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereShoppingUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
* @property string|null $user_shop_domain
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Customer whereUserShopDomain($value)
|
||||
*/
|
||||
class Customer extends \Eloquent {}
|
||||
}
|
||||
|
|
@ -412,111 +412,6 @@ namespace App\Models{
|
|||
class DcTag extends \Eloquent {}
|
||||
}
|
||||
|
||||
namespace App\Models{
|
||||
/**
|
||||
* DHL Shipment Model
|
||||
*
|
||||
* Represents a DHL shipment for a shopping order, including both outbound and return shipments.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $shopping_order_id
|
||||
* @property string|null $shipment_number DHL shipment number
|
||||
* @property string|null $tracking_number DHL tracking number
|
||||
* @property string $type Type: 'outbound' or 'return'
|
||||
* @property int|null $related_shipment_id For returns: reference to original shipment
|
||||
* @property float $weight Package weight in kg
|
||||
* @property int|null $length Package length in cm
|
||||
* @property int|null $width Package width in cm
|
||||
* @property int|null $height Package height in cm
|
||||
* @property string $product_code DHL product code (e.g., V01PAK)
|
||||
* @property array|null $services Additional DHL services
|
||||
* @property string|null $label_path Path to generated label file
|
||||
* @property string $label_format Label format (PDF or ZPL)
|
||||
* @property bool $label_printed Whether label has been printed
|
||||
* @property string $status Shipment status
|
||||
* @property string|null $tracking_status Current tracking status from DHL
|
||||
* @property string|null $tracking_details Detailed tracking information (JSON)
|
||||
* @property Carbon|null $last_tracked_at Last tracking update
|
||||
* @property string $recipient_name Recipient name
|
||||
* @property string|null $recipient_company Recipient company
|
||||
* @property string $recipient_street Recipient street
|
||||
* @property string $recipient_street_number Recipient street number
|
||||
* @property string $recipient_postal_code Recipient postal code
|
||||
* @property string $recipient_city Recipient city
|
||||
* @property string|null $recipient_state Recipient state
|
||||
* @property string $recipient_country Recipient country code
|
||||
* @property string|null $recipient_email Recipient email
|
||||
* @property string|null $recipient_phone Recipient phone
|
||||
* @property array|null $api_request_data API request data for debugging
|
||||
* @property array|null $api_response_data API response data for debugging
|
||||
* @property string|null $api_errors API error messages
|
||||
* @property float|null $shipping_cost Shipping cost
|
||||
* @property string $currency Currency code
|
||||
* @property string|null $notes Internal notes
|
||||
* @property array|null $metadata Additional metadata
|
||||
* @property Carbon|null $shipped_at When the package was shipped
|
||||
* @property Carbon|null $delivered_at When the package was delivered
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read ShoppingOrder $shoppingOrder
|
||||
* @property-read DhlShipment|null $relatedShipment
|
||||
* @property-read DhlShipment|null $returnShipment
|
||||
* @property-read string|null $dimensions
|
||||
* @property-read string|null $label_url
|
||||
* @property-read string $recipient_address
|
||||
* @property-read string $status_label
|
||||
* @property-read string $type_label
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment active()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment outbound()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment returns()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment trackable()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiErrors($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiRequestData($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereApiResponseData($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereCurrency($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereDeliveredAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereHeight($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelFormat($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelPath($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLabelPrinted($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLastTrackedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereLength($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereMetadata($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereNotes($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereProductCode($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCity($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCompany($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientCountry($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientEmail($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientPhone($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientPostalCode($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientState($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientStreet($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRecipientStreetNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereRelatedShipmentId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereServices($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShipmentNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShippedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShippingCost($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereShoppingOrderId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingDetails($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereTrackingStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereWeight($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|DhlShipment whereWidth($value)
|
||||
*/
|
||||
class DhlShipment extends \Eloquent {}
|
||||
}
|
||||
|
||||
namespace App\Models{
|
||||
/**
|
||||
* Class File
|
||||
|
|
@ -1614,13 +1509,13 @@ namespace App\Models{
|
|||
* @property int|null $abo_interval
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereAboInterval($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereIsAbo($value)
|
||||
* @mixin \Eloquent
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlOutboundShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlOutboundShipments
|
||||
* @property-read int|null $dhl_outbound_shipments_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlReturnShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlReturnShipments
|
||||
* @property-read int|null $dhl_return_shipments_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlShipments
|
||||
* @property-read int|null $dhl_shipments_count
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ShoppingOrder extends \Eloquent {}
|
||||
}
|
||||
|
|
@ -3100,9 +2995,9 @@ namespace App{
|
|||
* @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)
|
||||
* @mixin \Eloquent
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\UserBusiness> $userBusiness
|
||||
* @property-read int|null $user_business_count
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends \Eloquent {}
|
||||
}
|
||||
|
|
|
|||
136
app/Console/Commands/BusinessClearData.php
Normal file
136
app/Console/Commands/BusinessClearData.php
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Models\UserBusiness;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BusinessClearData extends Command
|
||||
{
|
||||
/**
|
||||
* php artisan business:clear-data {month} {year}
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:clear-data {month} {year} {--force : Force deletion without confirmation}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clear stored business structure data for a specific month/year';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$month = (int) $this->argument('month');
|
||||
$year = (int) $this->argument('year');
|
||||
|
||||
// Validierung
|
||||
if ($month < 1 || $month > 12) {
|
||||
$this->error('Invalid month. Must be between 1 and 12.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$currentYear = (int) date('Y');
|
||||
if ($year < 2020 || $year > $currentYear + 1) {
|
||||
$this->error('Invalid year. Must be between 2020 and ' . ($currentYear + 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->info("Preparing to clear business data for month: {$month} | year: {$year}");
|
||||
|
||||
// Finde bestehende Struktur
|
||||
$existingStructure = UserBusinessStructure::where('year', $year)
|
||||
->where('month', $month)
|
||||
->first();
|
||||
|
||||
if (!$existingStructure) {
|
||||
$this->info('No stored business structure found for the specified month/year');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$structureId = $existingStructure->id;
|
||||
$userBusinessCount = UserBusiness::where('b_structure_id', $structureId)->count();
|
||||
$userCount = is_array($existingStructure->users) ? count($existingStructure->users) : 0;
|
||||
|
||||
$this->info("Found structure ID: {$structureId}");
|
||||
$this->info("- UserBusiness records: {$userBusinessCount}");
|
||||
$this->info("- Users in structure: {$userCount}");
|
||||
$this->info("- Completed: " . ($existingStructure->completed ? 'Yes' : 'No'));
|
||||
|
||||
// Bestätigung (außer bei --force)
|
||||
if (!$this->option('force')) {
|
||||
if (!$this->confirm('Are you sure you want to delete this business structure data?')) {
|
||||
$this->info('Operation cancelled by user');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
// Lösche UserBusiness Einträge
|
||||
if ($userBusinessCount > 0) {
|
||||
$this->info("Deleting {$userBusinessCount} UserBusiness records...");
|
||||
UserBusiness::where('b_structure_id', $structureId)->delete();
|
||||
$this->info('✓ UserBusiness records deleted');
|
||||
}
|
||||
|
||||
// Lösche UserBusinessStructure
|
||||
$this->info('Deleting UserBusinessStructure...');
|
||||
$existingStructure->delete();
|
||||
$this->info('✓ UserBusinessStructure deleted');
|
||||
|
||||
// Garbage Collection
|
||||
gc_collect_cycles();
|
||||
|
||||
$endTime = microtime(true);
|
||||
$duration = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
$this->info("✅ Successfully cleared all business data in {$duration}ms");
|
||||
$this->logMemoryUsage();
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error clearing business data: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loggt aktuelle Memory-Nutzung
|
||||
*/
|
||||
private function logMemoryUsage(): void
|
||||
{
|
||||
$currentMemory = memory_get_usage();
|
||||
$peakMemory = memory_get_peak_usage();
|
||||
|
||||
$currentFormatted = $this->formatBytes($currentMemory);
|
||||
$peakFormatted = $this->formatBytes($peakMemory);
|
||||
|
||||
$this->info("Memory - Current: {$currentFormatted} | Peak: {$peakFormatted}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Bytes in lesbare Einheiten
|
||||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
}
|
||||
149
app/Console/Commands/BusinessLevelReports.php
Normal file
149
app/Console/Commands/BusinessLevelReports.php
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\LevelReportService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class BusinessLevelReports extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:level-reports {--month= : Filter by specific month} {--year= : Filter by specific year} {--user-id= : Filter by specific user ID} {--csv : Export as CSV file} {--not-updated : Show only users not yet updated to their new level}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate reports showing who achieved new career levels and when';
|
||||
|
||||
private $levelReportService;
|
||||
|
||||
public function __construct(LevelReportService $levelReportService)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->levelReportService = $levelReportService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$this->info('Generiere Level-Aufstieg-Report...');
|
||||
|
||||
// Filter Parameter
|
||||
$filters = [
|
||||
'month' => $this->option('month'),
|
||||
'year' => $this->option('year'),
|
||||
'user_id' => $this->option('user-id'),
|
||||
'only_not_updated' => $this->option('not-updated')
|
||||
];
|
||||
|
||||
$exportCsv = $this->option('csv');
|
||||
|
||||
// Lade Level-Aufstiege über Service
|
||||
$levelPromotions = $this->levelReportService->getLevelPromotions($filters);
|
||||
|
||||
if ($levelPromotions->isEmpty()) {
|
||||
$this->info('Keine Level-Aufstiege gefunden.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($exportCsv) {
|
||||
$filepath = $this->levelReportService->exportToCsv($levelPromotions);
|
||||
$this->info('');
|
||||
$this->info('CSV-Export erstellt: ' . $filepath);
|
||||
$this->info('Anzahl Datensätze: ' . $levelPromotions->count());
|
||||
} else {
|
||||
$this->displayReport($levelPromotions);
|
||||
}
|
||||
|
||||
$this->info('Report erfolgreich generiert.');
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Fehler beim Generieren des Reports: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function displayReport($promotions)
|
||||
{
|
||||
$statistics = $this->levelReportService->getStatistics($promotions);
|
||||
|
||||
$this->info('');
|
||||
$this->info('=== LEVEL-AUFSTIEG REPORT ===');
|
||||
$this->info('');
|
||||
|
||||
if ($promotions->isEmpty()) {
|
||||
$this->info('Keine Level-Aufstiege gefunden.');
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Datum',
|
||||
'User ID',
|
||||
'Name',
|
||||
'E-Mail',
|
||||
'Von Level',
|
||||
'Zu Level',
|
||||
'Aktueller Level',
|
||||
'Margin',
|
||||
'KP Req',
|
||||
'PP Req',
|
||||
'Growth Bonus',
|
||||
'User PP',
|
||||
'User KP',
|
||||
'Level Update',
|
||||
'Aktiv'
|
||||
];
|
||||
|
||||
$rows = [];
|
||||
foreach ($promotions->toArray() as $promotion) {
|
||||
$rows[] = [
|
||||
$promotion['date'],
|
||||
$promotion['user_id'],
|
||||
$promotion['first_name'] . ' ' . $promotion['last_name'],
|
||||
$promotion['email'],
|
||||
$promotion['from_level_name'] . ' (ID:' . $promotion['from_level_id'] . ')',
|
||||
$promotion['to_level_name'] . ' (ID:' . $promotion['to_level_id'] . ')',
|
||||
$promotion['current_user_level_name'] . ' (ID:' . ($promotion['current_user_level_id'] ?? 'N/A') . ')',
|
||||
$promotion['to_level_margin'] . '%',
|
||||
number_format($promotion['to_level_qual_kp'], 0, ',', '.'),
|
||||
number_format($promotion['to_level_qual_pp'], 0, ',', '.'),
|
||||
$promotion['to_level_growth_bonus'] . '%',
|
||||
number_format($promotion['total_pp'], 0, ',', '.'),
|
||||
number_format($promotion['sales_volume_points_sum'], 0, ',', '.'),
|
||||
$promotion['level_updated'],
|
||||
$promotion['active_account'],
|
||||
];
|
||||
}
|
||||
|
||||
$this->table($headers, $rows);
|
||||
|
||||
// Zusammenfassung
|
||||
$this->info('');
|
||||
$this->info('=== ZUSAMMENFASSUNG ===');
|
||||
$this->info('Anzahl Level-Aufstiege: ' . $statistics['total_count']);
|
||||
|
||||
$this->info('');
|
||||
$this->info('Aufstiege nach Ziel-Level:');
|
||||
foreach ($statistics['level_stats'] as $level => $count) {
|
||||
$this->info(" - {$level}: {$count}");
|
||||
}
|
||||
|
||||
$this->info('');
|
||||
$this->info('Aufstiege nach Zeitraum:');
|
||||
foreach ($statistics['period_stats'] as $period => $count) {
|
||||
$this->info(" - {$period}: {$count}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ class BusinessStore extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create Business Structur and UserDetails';
|
||||
protected $description = 'Create Business Structure and UserDetails with optimized performance';
|
||||
|
||||
private $timeStart;
|
||||
private $month;
|
||||
|
|
@ -52,121 +52,140 @@ class BusinessStore extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$executeDay = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
$presentDay = (int) date('d');
|
||||
|
||||
$this->info('RUN Command BusinessStore on Day: ' . $executeDay);
|
||||
$this->info('RUN Command BusinessStore present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore on Day: ' . $executeDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore present Day: ' . $presentDay);
|
||||
$this->logMemoryUsage('Command Start');
|
||||
|
||||
if ($executeDay !== $presentDay) {
|
||||
$this->info('NOT RUN Command BusinessStore is not present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('NOT RUN Command BusinessStore is not present Day: ' . $presentDay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
// Argumente mit Standardwerten für den Vormonat
|
||||
$this->month = $this->argument('month') ?: (int) date("m", strtotime("-1 month"));
|
||||
$this->year = $this->argument('year') ?: (int) date("Y", strtotime("-1 month"));
|
||||
|
||||
$this->info('RUN Command BusinessStore on month: ' . $this->month . ' | year: ' . $this->year);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStore on month: ' . $this->month . ' | year: ' . $this->year);
|
||||
$this->logMemoryUsage('Parameters initialized');
|
||||
|
||||
// Prozesse ausführen mit Fehlerbehandlung
|
||||
$this->executeWithErrorHandling('Business Structure Storage', function () {
|
||||
$this->storeBusinessStructureUsersDetailMonth();
|
||||
});
|
||||
|
||||
$this->executeWithErrorHandling('Commission Calculation', function () {
|
||||
$this->userBusinessCommissionsToCredit();
|
||||
});
|
||||
|
||||
// Auskommentierte Prozesse bleiben inaktiv
|
||||
// $this->userCreatePaymentCreditsPDF();
|
||||
// $this->userLevelUpdate();
|
||||
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
|
||||
|
||||
$this->logExecutionTime('COMMAND COMPLETED SUCCESSFULLY');
|
||||
$this->logMemoryUsage('Command End');
|
||||
\Log::channel('cron')->info('COMMAND COMPLETED SUCCESSFULLY');
|
||||
|
||||
$executeDay = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
$presentDay = (int) date('d');
|
||||
|
||||
$this->info('RUN Command BusinessStore on Day: '. $executeDay);
|
||||
$this->info('RUN Command BusinessStore present Day: '. $presentDay);
|
||||
|
||||
if($executeDay !== $presentDay){
|
||||
$this->info('NOT RUN Command BusinessStore is not present Day: '. $presentDay);
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Command failed with error: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
$this->logExecutionTime('COMMAND FAILED');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
// Argumente mit Standardwerten für den Vormonat
|
||||
$this->month = $this->argument('month') ?: (int) date("m", strtotime("-1 month"));
|
||||
$this->year = $this->argument('year') ?: (int) date("Y", strtotime("-1 month"));
|
||||
|
||||
$this->info('RUN Command BusinessStore on month: '.$this->month.' | year: '.$this->year);
|
||||
|
||||
// Prozesse ausführen
|
||||
$this->storeBusinessStructureUsersDetailMonth();
|
||||
$this->userBusinessCommissionsToCredit();
|
||||
|
||||
// Auskommentierte Prozesse
|
||||
// $this->userCreatePaymentCreditsPDF();
|
||||
// $this->userLevelUpdate();
|
||||
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function storeBusinessStructureUsersDetailMonth(){
|
||||
private function storeBusinessStructureUsersDetailMonth()
|
||||
{
|
||||
|
||||
$this->info('storeBusinessStructureUsersDetailMonth month: '.$this->month.' year:'.$this->year);
|
||||
$businessUsersStore = new BusinessUsersStore($this->month, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('END Command storeBusinessStructureUsersDetailMonth: '.$bool);
|
||||
$this->info('storeBusinessStructureUsersDetailMonth month: ' . $this->month . ' year:' . $this->year);
|
||||
$businessUsersStore = new BusinessUsersStore($this->month, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('END Command storeBusinessStructureUsersDetailMonth: ' . $bool);
|
||||
}
|
||||
|
||||
private function userBusinessCommissionsToCredit(){
|
||||
private function userBusinessCommissionsToCredit()
|
||||
{
|
||||
|
||||
$this->info('userBusinessCommissionsToCredit month: '.$this->month.' year:'.$this->year);
|
||||
$this->info('userBusinessCommissionsToCredit month: ' . $this->month . ' year:' . $this->year);
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$userBusinesses = $userPaymentCredits->getUserBusinessByMonthYear();
|
||||
|
||||
foreach($userBusinesses as $userBusiness){
|
||||
foreach ($userBusinesses as $userBusiness) {
|
||||
$ret = $userPaymentCredits->addUserCreditItem($userBusiness);
|
||||
$this->info('userBusinessCredit: '.$ret->user_id.' : Team: '.$ret->commission_pp_total.' | Shop: '.$ret->commission_shop_sales);
|
||||
$this->info('userBusinessCredit: ' . $ret->user_id . ' : Team: ' . $ret->commission_pp_total . ' | Shop: ' . $ret->commission_shop_sales);
|
||||
}
|
||||
$this->logExecutionTime('END Command userBusinessCommissionsToCredit:');
|
||||
|
||||
}
|
||||
|
||||
private function userCreatePaymentCreditsPDF(){
|
||||
private function userCreatePaymentCreditsPDF()
|
||||
{
|
||||
|
||||
$this->info('userCreatePaymentCreditsPDF month: '.$this->month.' year:'.$this->year);
|
||||
$this->info('userCreatePaymentCreditsPDF month: ' . $this->month . ' year:' . $this->year);
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$creditItemUsers = $userPaymentCredits->getUserCreditItemUsersByMonthYear();
|
||||
|
||||
foreach($creditItemUsers as $creditItemUser){
|
||||
foreach ($creditItemUsers as $creditItemUser) {
|
||||
$bool = $userPaymentCredits->makeCreditPaymentPDF($creditItemUser->user_id, $this->sendCreditMail);
|
||||
$this->info('creditsPDF: '.$bool.' user_id: '.$creditItemUser->user_id);
|
||||
$this->info('creditsPDF: ' . $bool . ' user_id: ' . $creditItemUser->user_id);
|
||||
}
|
||||
|
||||
$this->logExecutionTime('END Command userCreatePaymentCreditsPDF:');
|
||||
|
||||
$this->logExecutionTime('END Command userCreatePaymentCreditsPDF:');
|
||||
}
|
||||
|
||||
private function userLevelUpdate(){
|
||||
private function userLevelUpdate()
|
||||
{
|
||||
|
||||
$this->info('userLevelUpdate month: '.$this->month.' year:'.$this->year);
|
||||
$this->info('userLevelUpdate month: ' . $this->month . ' year:' . $this->year);
|
||||
|
||||
$userLevelUpdate = new UserLevelUpdate($this->month, $this->year);
|
||||
$levelUpdateUsers = $userLevelUpdate->getUserBusinessByMonthYear();
|
||||
|
||||
foreach($levelUpdateUsers as $userBusiness){
|
||||
|
||||
foreach ($levelUpdateUsers as $userBusiness) {
|
||||
$ret = $userLevelUpdate->makeUserLevelUpdate($userBusiness, $this->sendUpdateMail);
|
||||
if($ret){
|
||||
$this->info('updateLevel: '.$userBusiness->user->id.' | '.$userBusiness->user->email.' | '.
|
||||
'from: '.$userBusiness->m_level_id.' '.$userBusiness->user_level_name.' | '.
|
||||
'to: '.$ret);
|
||||
if ($ret) {
|
||||
$this->info('updateLevel: ' . $userBusiness->user->id . ' | ' . $userBusiness->user->email . ' | ' .
|
||||
'from: ' . $userBusiness->m_level_id . ' ' . $userBusiness->user_level_name . ' | ' .
|
||||
'to: ' . $ret);
|
||||
}
|
||||
|
||||
}
|
||||
$this->logExecutionTime('END Command userLevelUpdate:');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function storeBusinessStructureUsersDetailPeriod($from, $to)
|
||||
private function storeBusinessStructureUsersDetailPeriod($from, $to)
|
||||
{
|
||||
for($i = $from; $i <= $to; $i++){
|
||||
$this->info('Store Business Structure Users Detail month: '.$i.' year:'.$this->year);
|
||||
for ($i = $from; $i <= $to; $i++) {
|
||||
$this->info('Store Business Structure Users Detail month: ' . $i . ' year:' . $this->year);
|
||||
$businessUsersStore = new BusinessUsersStore($i, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('Period BusinessStore: '.$bool);
|
||||
$this->logExecutionTime('Period BusinessStore: ' . $bool);
|
||||
}
|
||||
}
|
||||
|
||||
private function logExecutionTime($message)
|
||||
private function logExecutionTime($message)
|
||||
{
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info($message. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
|
||||
$this->info($message . ' | Time: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
368
app/Console/Commands/BusinessStoreOptimized.php
Normal file
368
app/Console/Commands/BusinessStoreOptimized.php
Normal file
|
|
@ -0,0 +1,368 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Models\UserBusiness;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Cron\BusinessUsersStoreOptimized;
|
||||
use App\Cron\UserLevelUpdate;
|
||||
use App\Cron\UserPaymentCredits;
|
||||
|
||||
class BusinessStoreOptimized extends Command
|
||||
{
|
||||
/**
|
||||
* ln -sfv /usr/bin/php73 /usr/bin/php
|
||||
* php artisan business:store-optimized month year
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:store-optimized {month} {year} {--clear : Clear stored data before processing}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create Business Structure and UserDetails with optimized performance and monitoring';
|
||||
|
||||
private $timeStart;
|
||||
private $month;
|
||||
private $year;
|
||||
|
||||
private $sendCreditMail = false;
|
||||
private $sendUpdateMail = false;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$executeDay = (int) Setting::getContentBySlug('day-exectute-business-structur');
|
||||
$presentDay = (int) date('d');
|
||||
|
||||
$this->info('RUN Command BusinessStoreOptimized on Day: ' . $executeDay);
|
||||
$this->info('RUN Command BusinessStoreOptimized present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStoreOptimized on Day: ' . $executeDay);
|
||||
\Log::channel('cron')->info('RUN Command BusinessStoreOptimized present Day: ' . $presentDay);
|
||||
$this->logMemoryUsage('Command Start');
|
||||
|
||||
if ($executeDay !== $presentDay) {
|
||||
$this->info('NOT RUN Command BusinessStoreOptimized is not present Day: ' . $presentDay);
|
||||
\Log::channel('cron')->info('NOT RUN Command BusinessStoreOptimized is not present Day: ' . $presentDay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
// Argumente mit Standardwerten für den Vormonat
|
||||
$this->month = $this->argument('month') ?: (int) date("m", strtotime("-1 month"));
|
||||
$this->year = $this->argument('year') ?: (int) date("Y", strtotime("-1 month"));
|
||||
|
||||
$this->info('RUN Command BusinessStoreOptimized on month: ' . $this->month . ' | year: ' . $this->year);
|
||||
$this->logMemoryUsage('Parameters initialized');
|
||||
|
||||
// Prüfe --clear Option und lösche gespeicherte Daten falls gewünscht
|
||||
if ($this->option('clear')) {
|
||||
$this->executeWithErrorHandling('Clear Stored Data', function () {
|
||||
$this->clearStoredData();
|
||||
});
|
||||
}
|
||||
|
||||
// Prozesse ausführen mit optimierter Fehlerbehandlung
|
||||
$this->executeWithErrorHandling('Business Structure Storage', function () {
|
||||
\Log::channel('cron')->info('RUN Command BusinessStoreOptimized Business Structure Storage');
|
||||
$this->storeBusinessStructureUsersDetailMonth();
|
||||
});
|
||||
|
||||
$this->executeWithErrorHandling('Commission Calculation', function () {
|
||||
\Log::channel('cron')->info('RUN Command BusinessStoreOptimized Commission Calculation');
|
||||
$this->userBusinessCommissionsToCredit();
|
||||
});
|
||||
|
||||
// Auskommentierte Prozesse bleiben inaktiv
|
||||
// $this->userCreatePaymentCreditsPDF();
|
||||
// $this->userLevelUpdate();
|
||||
// $this->storeBusinessStructureUsersDetailPeriod(1, 6);
|
||||
|
||||
$this->logExecutionTime('COMMAND COMPLETED SUCCESSFULLY');
|
||||
$this->logMemoryUsage('Command End');
|
||||
\Log::channel('cron')->info('COMMAND COMPLETED SUCCESSFULLY');
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Command failed with error: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
$this->logExecutionTime('COMMAND FAILED');
|
||||
\Log::channel('cron')->info('COMMAND FAILED');
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function storeBusinessStructureUsersDetailMonth()
|
||||
{
|
||||
$this->info('storeBusinessStructureUsersDetailMonth month: ' . $this->month . ' year:' . $this->year);
|
||||
|
||||
try {
|
||||
$businessUsersStore = new BusinessUsersStoreOptimized($this->month, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('END Command storeBusinessStructureUsersDetailMonth: ' . $bool);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error in storeBusinessStructureUsersDetailMonth: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function userBusinessCommissionsToCredit()
|
||||
{
|
||||
$this->info('userBusinessCommissionsToCredit month: ' . $this->month . ' year:' . $this->year);
|
||||
|
||||
try {
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$userBusinesses = $userPaymentCredits->getUserBusinessByMonthYear();
|
||||
|
||||
$processedCount = 0;
|
||||
foreach ($userBusinesses as $userBusiness) {
|
||||
$ret = $userPaymentCredits->addUserCreditItem($userBusiness);
|
||||
$this->info('userBusinessCredit: ' . $ret->user_id . ' : Team: ' . $ret->commission_pp_total . ' | Shop: ' . $ret->commission_shop_sales);
|
||||
$processedCount++;
|
||||
|
||||
// Memory-Check alle 100 User
|
||||
if ($processedCount % 100 === 0) {
|
||||
$this->logMemoryUsage("After processing {$processedCount} users");
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Processed {$processedCount} user businesses total");
|
||||
$this->logExecutionTime('END Command userBusinessCommissionsToCredit:');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error in userBusinessCommissionsToCredit: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function userCreatePaymentCreditsPDF()
|
||||
{
|
||||
$this->info('userCreatePaymentCreditsPDF month: ' . $this->month . ' year:' . $this->year);
|
||||
|
||||
try {
|
||||
$userPaymentCredits = new UserPaymentCredits($this->month, $this->year);
|
||||
$creditItemUsers = $userPaymentCredits->getUserCreditItemUsersByMonthYear();
|
||||
|
||||
$processedCount = 0;
|
||||
foreach ($creditItemUsers as $creditItemUser) {
|
||||
$bool = $userPaymentCredits->makeCreditPaymentPDF($creditItemUser->user_id, $this->sendCreditMail);
|
||||
$this->info('creditsPDF: ' . $bool . ' user_id: ' . $creditItemUser->user_id);
|
||||
$processedCount++;
|
||||
|
||||
// Memory-Check alle 50 PDFs
|
||||
if ($processedCount % 50 === 0) {
|
||||
$this->logMemoryUsage("After processing {$processedCount} PDFs");
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Created {$processedCount} PDF files total");
|
||||
$this->logExecutionTime('END Command userCreatePaymentCreditsPDF:');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error in userCreatePaymentCreditsPDF: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function userLevelUpdate()
|
||||
{
|
||||
$this->info('userLevelUpdate month: ' . $this->month . ' year:' . $this->year);
|
||||
|
||||
try {
|
||||
$userLevelUpdate = new UserLevelUpdate($this->month, $this->year);
|
||||
$levelUpdateUsers = $userLevelUpdate->getUserBusinessByMonthYear();
|
||||
|
||||
$updatedCount = 0;
|
||||
foreach ($levelUpdateUsers as $userBusiness) {
|
||||
$ret = $userLevelUpdate->makeUserLevelUpdate($userBusiness, $this->sendUpdateMail);
|
||||
if ($ret) {
|
||||
$this->info('updateLevel: ' . $userBusiness->user->id . ' | ' . $userBusiness->user->email . ' | ' .
|
||||
'from: ' . $userBusiness->m_level_id . ' ' . $userBusiness->user_level_name . ' | ' .
|
||||
'to: ' . $ret);
|
||||
$updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info("Updated {$updatedCount} user levels total");
|
||||
$this->logExecutionTime('END Command userLevelUpdate:');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error in userLevelUpdate: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function storeBusinessStructureUsersDetailPeriod($from, $to)
|
||||
{
|
||||
try {
|
||||
for ($i = $from; $i <= $to; $i++) {
|
||||
$this->info('Store Business Structure Users Detail month: ' . $i . ' year:' . $this->year);
|
||||
$this->logMemoryUsage("Before month {$i}");
|
||||
|
||||
$businessUsersStore = new BusinessUsersStoreOptimized($i, $this->year);
|
||||
$businessUsersStore->storeUserBusinessStructure();
|
||||
$businessUsersStore->storeBusinessUsersDetail();
|
||||
$bool = $businessUsersStore->storeBusinessCompleted();
|
||||
|
||||
$this->logExecutionTime('Period BusinessStore: ' . $bool);
|
||||
$this->logMemoryUsage("After month {$i}");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error in storeBusinessStructureUsersDetailPeriod: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht gespeicherte Business Structure Daten für den angegebenen Monat/Jahr
|
||||
*/
|
||||
private function clearStoredData()
|
||||
{
|
||||
try {
|
||||
$this->info("Clearing stored business data for month: {$this->month} | year: {$this->year}");
|
||||
|
||||
// Finde bestehende UserBusinessStructure
|
||||
$existingStructure = UserBusinessStructure::where('year', $this->year)
|
||||
->where('month', $this->month)
|
||||
->first();
|
||||
|
||||
if (!$existingStructure) {
|
||||
$this->info('No stored business structure found to clear');
|
||||
return;
|
||||
}
|
||||
|
||||
$structureId = $existingStructure->id;
|
||||
$this->info("Found existing structure with ID: {$structureId}");
|
||||
|
||||
// Lösche zugehörige UserBusiness Einträge
|
||||
$deletedUserBusinesses = UserBusiness::where('b_structure_id', $structureId)->count();
|
||||
if ($deletedUserBusinesses > 0) {
|
||||
UserBusiness::where('b_structure_id', $structureId)->delete();
|
||||
$this->info("Deleted {$deletedUserBusinesses} UserBusiness records");
|
||||
}
|
||||
|
||||
// Lösche die UserBusinessStructure
|
||||
$existingStructure->delete();
|
||||
$this->info("Deleted UserBusinessStructure with ID: {$structureId}");
|
||||
|
||||
// Garbage Collection nach dem Löschen
|
||||
gc_collect_cycles();
|
||||
|
||||
$this->info('Successfully cleared all stored business data');
|
||||
$this->logMemoryUsage('After clearing data');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error clearing stored data: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function logExecutionTime($message)
|
||||
{
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info($message . ' | Time: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt eine Funktion mit Fehlerbehandlung aus
|
||||
*/
|
||||
private function executeWithErrorHandling(string $processName, callable $callback): void
|
||||
{
|
||||
try {
|
||||
$startTime = microtime(true);
|
||||
$this->info("Starting: {$processName}");
|
||||
$this->logMemoryUsage("Before {$processName}");
|
||||
|
||||
$callback();
|
||||
|
||||
$endTime = microtime(true);
|
||||
$duration = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->info("Completed: {$processName} in {$duration}ms");
|
||||
$this->logMemoryUsage("After {$processName}");
|
||||
} catch (\Exception $e) {
|
||||
$this->error("Error in {$processName}: " . $e->getMessage());
|
||||
$this->error("Stack trace: " . $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loggt aktuelle Memory-Nutzung
|
||||
*/
|
||||
private function logMemoryUsage(string $checkpoint): void
|
||||
{
|
||||
$currentMemory = memory_get_usage();
|
||||
$peakMemory = memory_get_peak_usage();
|
||||
$memoryLimit = $this->parseMemoryLimit(ini_get('memory_limit'));
|
||||
|
||||
$currentFormatted = $this->formatBytes($currentMemory);
|
||||
$peakFormatted = $this->formatBytes($peakMemory);
|
||||
$limitFormatted = $this->formatBytes($memoryLimit);
|
||||
$usagePercent = round(($currentMemory / $memoryLimit) * 100, 2);
|
||||
|
||||
$this->info("[{$checkpoint}] Memory: {$currentFormatted} / {$limitFormatted} ({$usagePercent}%) | Peak: {$peakFormatted}");
|
||||
|
||||
if ($usagePercent > 80) {
|
||||
$this->warn("High memory usage detected at {$checkpoint}: {$usagePercent}%");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Konvertiert Memory-Limit String zu Bytes
|
||||
*/
|
||||
private function parseMemoryLimit(string $limit): int
|
||||
{
|
||||
$limit = trim($limit);
|
||||
$last = strtolower($limit[strlen($limit) - 1]);
|
||||
$number = (int) $limit;
|
||||
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$number *= 1024;
|
||||
case 'm':
|
||||
$number *= 1024;
|
||||
case 'k':
|
||||
$number *= 1024;
|
||||
}
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Bytes in lesbare Einheiten
|
||||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
}
|
||||
182
app/Console/Commands/BusinessTestAccount.php
Normal file
182
app/Console/Commands/BusinessTestAccount.php
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\User;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Services\BusinessPlan\BusinessUserItemOptimized;
|
||||
use App\Cron\UserPaymentCredits;
|
||||
use Illuminate\Console\Command;
|
||||
use stdClass;
|
||||
|
||||
class BusinessTestAccount extends Command
|
||||
{
|
||||
/**
|
||||
* php artisan business:test-account {user_id} {month} {year}
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'business:test-account {user_id} {month} {year} {--commissions : Calculate and show user commissions}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Test account data loading for a specific user in business calculations, with optional commission calculation';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$userId = (int) $this->argument('user_id');
|
||||
$month = (int) $this->argument('month');
|
||||
$year = (int) $this->argument('year');
|
||||
|
||||
$this->info("Testing account data for User ID: {$userId}, Month: {$month}, Year: {$year}");
|
||||
$this->line('');
|
||||
|
||||
// Lade User mit Account
|
||||
$user = User::with('account', 'user_level')->find($userId);
|
||||
|
||||
if (!$user) {
|
||||
$this->error("User {$userId} not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->info("User found: {$user->email}");
|
||||
$this->info("Account ID: " . ($user->account_id ?? 'NULL'));
|
||||
|
||||
if ($user->account) {
|
||||
$this->info("Account loaded: YES");
|
||||
$this->info("Account m_account: " . ($user->account->m_account ?? 'NULL'));
|
||||
$this->info("Account first_name: " . ($user->account->first_name ?? 'NULL'));
|
||||
$this->info("Account last_name: " . ($user->account->last_name ?? 'NULL'));
|
||||
$this->info("Account birthday: " . ($user->account->birthday ?? 'NULL'));
|
||||
$this->info("Account phone: " . ($user->account->getPhoneNumber() ?? 'NULL'));
|
||||
} else {
|
||||
$this->warn("Account loaded: NO");
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
$this->info('Testing BusinessUserItemOptimized...');
|
||||
|
||||
// Erstelle Date Object
|
||||
$date = new stdClass();
|
||||
$date->month = $month;
|
||||
$date->year = $year;
|
||||
$date->start_date = "{$year}-{$month}-01 00:00:00";
|
||||
$date->end_date = date('Y-m-t 23:59:59', strtotime("{$year}-{$month}-01"));
|
||||
|
||||
// Teste BusinessUserItemOptimized
|
||||
$businessUserItem = new BusinessUserItemOptimized($date);
|
||||
$businessUserItem->makeUserFromModel($user, true);
|
||||
|
||||
$bUser = $businessUserItem->getBUser();
|
||||
|
||||
$this->line('');
|
||||
$this->info('Results from BusinessUserItemOptimized:');
|
||||
$this->info("m_account: " . ($bUser->m_account ?? 'NULL'));
|
||||
$this->info("first_name: " . ($bUser->first_name ?? 'NULL'));
|
||||
$this->info("last_name: " . ($bUser->last_name ?? 'NULL'));
|
||||
$this->info("user_birthday: " . ($bUser->user_birthday ?? 'NULL'));
|
||||
$this->info("user_phone: " . ($bUser->user_phone ?? 'NULL'));
|
||||
$this->info("email: " . ($bUser->email ?? 'NULL'));
|
||||
|
||||
$this->line('');
|
||||
$this->info('Sales Volume Fields:');
|
||||
$this->info("sales_volume_KP_points: " . ($bUser->sales_volume_KP_points ?? 'NULL'));
|
||||
$this->info("sales_volume_TP_points: " . ($bUser->sales_volume_TP_points ?? 'NULL'));
|
||||
$this->info("sales_volume_points_shop: " . ($bUser->sales_volume_points_shop ?? 'NULL'));
|
||||
$this->info("sales_volume_points_KP_sum: " . ($bUser->sales_volume_points_KP_sum ?? 'NULL'));
|
||||
$this->info("sales_volume_points_TP_sum: " . ($bUser->sales_volume_points_TP_sum ?? 'NULL'));
|
||||
$this->info("sales_volume_total: " . ($bUser->sales_volume_total ?? 'NULL'));
|
||||
$this->info("sales_volume_total_shop: " . ($bUser->sales_volume_total_shop ?? 'NULL'));
|
||||
$this->info("sales_volume_total_sum: " . ($bUser->sales_volume_total_sum ?? 'NULL'));
|
||||
|
||||
$this->line('');
|
||||
$this->info('Commission Fields:');
|
||||
$this->info("payline_points: " . ($bUser->payline_points ?? 'NULL'));
|
||||
$this->info("commission_pp_total: " . ($bUser->commission_pp_total ?? 'NULL'));
|
||||
$this->info("commission_shop_sales: " . ($bUser->commission_shop_sales ?? 'NULL'));
|
||||
$this->info("commission_growth_total: " . ($bUser->commission_growth_total ?? 'NULL'));
|
||||
|
||||
// Test UserSalesVolume directly
|
||||
$this->line('');
|
||||
$this->info('Testing UserSalesVolume data directly:');
|
||||
$userSalesVolume = $user->getUserSalesVolume($month, $year, 'first');
|
||||
if ($userSalesVolume) {
|
||||
$this->info("UserSalesVolume found: ID {$userSalesVolume->id}");
|
||||
$this->info("month_KP_points: " . ($userSalesVolume->month_KP_points ?? 'NULL'));
|
||||
$this->info("month_TP_points: " . ($userSalesVolume->month_TP_points ?? 'NULL'));
|
||||
$this->info("month_shop_points: " . ($userSalesVolume->month_shop_points ?? 'NULL'));
|
||||
$this->info("month_total_net: " . ($userSalesVolume->month_total_net ?? 'NULL'));
|
||||
$this->info("month_shop_total_net: " . ($userSalesVolume->month_shop_total_net ?? 'NULL'));
|
||||
} else {
|
||||
$this->warn("No UserSalesVolume found for month {$month}/{$year}");
|
||||
|
||||
// Check if any UserSalesVolume exists for this user
|
||||
$anyVolume = \App\Models\UserSalesVolume::where('user_id', $userId)->orderBy('year', 'desc')->orderBy('month', 'desc')->first();
|
||||
if ($anyVolume) {
|
||||
$this->info("Latest UserSalesVolume found: {$anyVolume->month}/{$anyVolume->year}");
|
||||
} else {
|
||||
$this->warn("No UserSalesVolume records found for this user at all");
|
||||
}
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
|
||||
// Prüfe ob UserBusiness bereits gespeichert ist
|
||||
$existingUserBusiness = UserBusiness::where('user_id', $userId)
|
||||
->where('month', $month)
|
||||
->where('year', $year)
|
||||
->first();
|
||||
|
||||
if ($existingUserBusiness) {
|
||||
$this->info('Existing UserBusiness found:');
|
||||
$this->info("m_account: " . ($existingUserBusiness->m_account ?? 'NULL'));
|
||||
$this->info("first_name: " . ($existingUserBusiness->first_name ?? 'NULL'));
|
||||
$this->info("last_name: " . ($existingUserBusiness->last_name ?? 'NULL'));
|
||||
$this->info("user_birthday: " . ($existingUserBusiness->user_birthday ?? 'NULL'));
|
||||
$this->info("user_phone: " . ($existingUserBusiness->user_phone ?? 'NULL'));
|
||||
$this->info("email: " . ($existingUserBusiness->email ?? 'NULL'));
|
||||
} else {
|
||||
$this->info('No existing UserBusiness found for this period');
|
||||
}
|
||||
|
||||
if ($this->option('commissions')) {
|
||||
$this->line('');
|
||||
$this->info('Testing UserBusiness Commissions to Credit...');
|
||||
|
||||
if ($existingUserBusiness) {
|
||||
try {
|
||||
$userPaymentCredits = new UserPaymentCredits($month, $year);
|
||||
$ret = $userPaymentCredits->addUserCreditItem($existingUserBusiness);
|
||||
$this->info('UserBusinessCredit calculated:');
|
||||
$this->info('User ID: ' . $ret->user_id);
|
||||
$this->info('Team Commission: ' . $ret->commission_pp_total);
|
||||
$this->info('Shop Commission: ' . $ret->commission_shop_sales);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Error calculating commissions: ' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$this->warn('No UserBusiness record found, cannot calculate commissions.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->line('');
|
||||
$this->info('✅ Test completed successfully');
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Test failed with error: ' . $e->getMessage());
|
||||
$this->error('Stack trace: ' . $e->getTraceAsString());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,22 +46,24 @@ class UserCleanUp extends Command
|
|||
{
|
||||
|
||||
$this->info('RUN Command user:cleanup');
|
||||
\Log::channel('cleanup')->info('COMMAND [user:cleanup] started.');
|
||||
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
$this->deleteInavtiveUsers();
|
||||
//alle inaktive User werden deaktivert, die childs werden dem nächsten aktiven Berater (parent) zugewiesen.
|
||||
$this->cleanUpInActiveUser();
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
//\Log::info('Cron is running');
|
||||
|
||||
\Log::channel('cleanup')->info('COMMAND [user:cleanup] finished.');
|
||||
//return 0;
|
||||
}
|
||||
|
||||
|
||||
//gibt es gelöschte Berater mit Kunden und childs???
|
||||
|
||||
private function deleteInavtiveUsers(){
|
||||
private function deleteInavtiveUsers()
|
||||
{
|
||||
|
||||
$this->info('START Command deleteInavtiveUsers');
|
||||
$count = 0;
|
||||
|
|
@ -69,20 +71,20 @@ class UserCleanUp extends Command
|
|||
$date = Carbon::now()->modify('-2 month');
|
||||
$delete_users = User::where('admin', 0)->where('payment_account', '<', $date)->get();
|
||||
|
||||
foreach($delete_users as $delete_user){
|
||||
foreach ($delete_users as $delete_user) {
|
||||
/*
|
||||
dump('delete_users ---------- ');
|
||||
dump($delete_user->id);
|
||||
dump($delete_user->email);
|
||||
*/
|
||||
//finde nächsten aktiven Sponsor $delete_user->id kann sponsor oder pre sponsor sein
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($delete_user->id);
|
||||
if($active_sponsor){
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($delete_user->id);
|
||||
if ($active_sponsor) {
|
||||
//setze alle Berater vom Sponsor für alle childs
|
||||
UserUtil::setNewSponsorToChilds($delete_user->id, $active_sponsor->id);
|
||||
UserUtil::setNewSponsorToChilds($delete_user->id, $active_sponsor->id);
|
||||
UserUtil::setShoppingUserToNewMember($delete_user->id, $active_sponsor->id);
|
||||
}else{
|
||||
\Log::channel('cleanup')->error('deleteInavtiveUsers find no active_sponsor by delete_user_id:'.$delete_user->id);
|
||||
} else {
|
||||
\Log::channel('cleanup')->error('deleteInavtiveUsers find no active_sponsor by delete_user_id:' . $delete_user->id);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
|
|
@ -99,8 +101,8 @@ class UserCleanUp extends Command
|
|||
'm_first_name' => $delete_user->account ? $delete_user->account->m_first_name : '',
|
||||
'm_last_name' => $delete_user->account ? $delete_user->account->m_last_name : '',
|
||||
];
|
||||
$count ++;
|
||||
\Log::channel('cleanup')->info('deleteUser: '.json_encode($data));
|
||||
$count++;
|
||||
\Log::channel('cleanup')->info('deleteUser: ' . json_encode($data));
|
||||
UserUtil::deleteUser($delete_user);
|
||||
}
|
||||
|
||||
|
|
@ -108,52 +110,52 @@ class UserCleanUp extends Command
|
|||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command deleteInavtiveUsers: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
$this->info('END Command deleteInavtiveUsers: ' . $count . ' | Time: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
|
||||
private function cleanUpInActiveUser(){
|
||||
private function cleanUpInActiveUser()
|
||||
{
|
||||
|
||||
$this->info('START Command cleanUpInActiveUser');
|
||||
$count = 0;
|
||||
|
||||
|
||||
//clean up user where inactive since 2 weeks
|
||||
$date = Carbon::now()->modify('-2 weeks');
|
||||
|
||||
$inactive_users = User::where('active', true)->where('m_sponsor', '!=', null)->where('payment_account', '<', $date)->get();
|
||||
foreach($inactive_users as $inactive_user){
|
||||
foreach ($inactive_users as $inactive_user) {
|
||||
/*
|
||||
dump('inactive_user ---------- ');
|
||||
dump($inactive_user->id);
|
||||
dump($inactive_user->email);
|
||||
*/
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($inactive_user->m_sponsor);
|
||||
if($active_sponsor){
|
||||
if ($active_sponsor) {
|
||||
UserUtil::setNewSponsorToChilds($inactive_user->id, $active_sponsor->id);
|
||||
}else{
|
||||
\Log::channel('cleanup')->error('cleanUpInActiveUser find no active_sponsor by inactive_user:'.$inactive_user->id);
|
||||
} else {
|
||||
\Log::channel('cleanup')->error('cleanUpInActiveUser find no active_sponsor by inactive_user:' . $inactive_user->id);
|
||||
}
|
||||
/*
|
||||
dump('findNextActiveSponsor');
|
||||
dump($active_sponsor->email);
|
||||
*/
|
||||
$data = [
|
||||
'user_id' => $inactive_user->id,
|
||||
'user_id' => $inactive_user->id,
|
||||
'email' => $inactive_user->email,
|
||||
'm_account' => $inactive_user->account ? $inactive_user->account->m_account : '',
|
||||
'm_first_name' => $inactive_user->account ? $inactive_user->account->m_first_name : '',
|
||||
'm_last_name' => $inactive_user->account ? $inactive_user->account->m_last_name : '',
|
||||
];
|
||||
$count ++;
|
||||
$count++;
|
||||
|
||||
\Log::channel('cleanup')->info('inactive_user: '.json_encode($data));
|
||||
\Log::channel('cleanup')->info('inactive_user: ' . json_encode($data));
|
||||
UserUtil::deactiveUser($inactive_user);
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command cleanUpInActiveUser: '.$count. ' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
$this->info('END Command cleanUpInActiveUser: ' . $count . ' | Time: ' . $sec . 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,18 +56,18 @@ class UserMakeAboOrder extends Command
|
|||
public function handle()
|
||||
{
|
||||
$this->timeStart = microtime(true);
|
||||
Log::info('UserMakeAboOrder: Befehl gestartet');
|
||||
\Log::channel('cron')->info('UserMakeAboOrder: Befehl gestartet');
|
||||
$this->info('RUN Command user:make_abo_order');
|
||||
|
||||
try {
|
||||
$this->checkAbosToOrder();
|
||||
$executionTime = $this->getExecutionTime();
|
||||
Log::info("UserMakeAboOrder: Befehl erfolgreich abgeschlossen in {$executionTime}");
|
||||
\Log::channel('cron')->info("UserMakeAboOrder: Befehl erfolgreich abgeschlossen in {$executionTime}");
|
||||
$this->info("Befehl erfolgreich abgeschlossen in {$executionTime}");
|
||||
|
||||
|
||||
return 0;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('UserMakeAboOrder: Fehler beim Ausführen des Befehls', [
|
||||
\Log::channel('cron')->error('UserMakeAboOrder: Fehler beim Ausführen des Befehls', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
|
@ -84,40 +84,40 @@ class UserMakeAboOrder extends Command
|
|||
private function checkAbosToOrder()
|
||||
{
|
||||
$dateNow = Carbon::now()->format('Y-m-d');
|
||||
|
||||
Log::info('UserMakeAboOrder: Suche nach fälligen Abos für Datum', ['date' => $dateNow]);
|
||||
|
||||
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Suche nach fälligen Abos für Datum', ['date' => $dateNow]);
|
||||
|
||||
$userAbos = UserAbo::where('next_date', '=', $dateNow)
|
||||
->where('active', true)
|
||||
->get();
|
||||
|
||||
->where('active', true)
|
||||
->get();
|
||||
|
||||
$count = $userAbos->count();
|
||||
Log::info("UserMakeAboOrder: {$count} fällige Abos gefunden");
|
||||
\Log::channel('abo_order')->info("UserMakeAboOrder: {$count} fällige Abos gefunden");
|
||||
$this->info("Gefundene fällige Abos: {$count}");
|
||||
|
||||
foreach ($userAbos as $userAbo) {
|
||||
Log::info('UserMakeAboOrder: Verarbeite Abo', [
|
||||
'abo_id' => $userAbo->id,
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Verarbeite Abo', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'payone_userid' => $userAbo->payone_userid
|
||||
]);
|
||||
|
||||
|
||||
$this->info("Verarbeite Abo: {$userAbo->id} (PayoneUserid: {$userAbo->payone_userid})");
|
||||
|
||||
|
||||
try {
|
||||
$shoppingOrder = $this->makeOrder($userAbo);
|
||||
|
||||
|
||||
if ($shoppingOrder) {
|
||||
Log::info('UserMakeAboOrder: Bestellung erstellt', [
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Bestellung erstellt', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id
|
||||
]);
|
||||
$this->info("Bestellung erstellt: {$shoppingOrder->id}");
|
||||
} else {
|
||||
Log::warning('UserMakeAboOrder: Keine Bestellung erstellt für Abo', ['abo_id' => $userAbo->id]);
|
||||
\Log::channel('abo_order')->warning('UserMakeAboOrder: Keine Bestellung erstellt für Abo', ['abo_id' => $userAbo->id]);
|
||||
$this->warn("Keine Bestellung erstellt für Abo: {$userAbo->id}");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('UserMakeAboOrder: Fehler bei der Verarbeitung des Abos', [
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Fehler bei der Verarbeitung des Abos', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
|
|
@ -135,36 +135,36 @@ class UserMakeAboOrder extends Command
|
|||
*/
|
||||
private function makeOrder($userAbo)
|
||||
{
|
||||
Log::info('UserMakeAboOrder: Starte Bestellungserstellung', ['abo_id' => $userAbo->id]);
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Starte Bestellungserstellung', ['abo_id' => $userAbo->id]);
|
||||
$this->info('Starte Bestellungserstellung für Abo: ' . $userAbo->id);
|
||||
|
||||
|
||||
$shoppingOrder = null;
|
||||
$userOrder = new UserMakeOrder($userAbo);
|
||||
|
||||
|
||||
try {
|
||||
if (!$userOrder->createShoppingUser()) {
|
||||
Log::error('UserMakeAboOrder: Konnte Shopping-User nicht erstellen', ['abo_id' => $userAbo->id]);
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Konnte Shopping-User nicht erstellen', ['abo_id' => $userAbo->id]);
|
||||
$this->error("Konnte Shopping-User für Abo {$userAbo->id} nicht erstellen");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$shoppingOrder = $userOrder->makeShoppingOrder();
|
||||
if (!$shoppingOrder) {
|
||||
Log::error('UserMakeAboOrder: Konnte Bestellung nicht erstellen', ['abo_id' => $userAbo->id]);
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Konnte Bestellung nicht erstellen', ['abo_id' => $userAbo->id]);
|
||||
$this->error("Konnte Bestellung für Abo {$userAbo->id} nicht erstellen");
|
||||
return null;
|
||||
}
|
||||
|
||||
Log::info('UserMakeAboOrder: Bestellung erstellt, starte Zahlungsvorgang', [
|
||||
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Bestellung erstellt, starte Zahlungsvorgang', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id
|
||||
]);
|
||||
|
||||
|
||||
$response = $userOrder->makePayment();
|
||||
$this->info('makePayment response: ' . json_encode($response));
|
||||
|
||||
if (!isset($response['status'])) {
|
||||
Log::error('UserMakeAboOrder: Ungültige Zahlungsantwort', [
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Ungültige Zahlungsantwort', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id,
|
||||
'response' => $response
|
||||
|
|
@ -172,9 +172,9 @@ class UserMakeAboOrder extends Command
|
|||
$this->error("Ungültige Zahlungsantwort für Abo {$userAbo->id}");
|
||||
return $shoppingOrder;
|
||||
}
|
||||
|
||||
|
||||
if ($response['status'] === 'APPROVED') {
|
||||
Log::info('UserMakeAboOrder: Zahlung erfolgreich', [
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Zahlung erfolgreich', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id,
|
||||
'response' => $response
|
||||
|
|
@ -182,22 +182,22 @@ class UserMakeAboOrder extends Command
|
|||
$this->info("Zahlung erfolgreich für Abo {$userAbo->id}");
|
||||
$this->updateAbo($userAbo, $shoppingOrder, 1);
|
||||
} elseif ($response['status'] === 'ERROR') {
|
||||
Log::error('UserMakeAboOrder: Zahlungsfehler', [
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Zahlungsfehler', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id,
|
||||
'error' => $response
|
||||
]);
|
||||
$this->error("Zahlungsfehler für Abo {$userAbo->id}");
|
||||
|
||||
|
||||
MyLog::writeLog(
|
||||
'userabo',
|
||||
'error',
|
||||
'Error:3002 App\Console\Commands\UserMakeAboOrder::makeOrder / makePayment Error response',
|
||||
'userabo',
|
||||
'error',
|
||||
'Error:3002 App\Console\Commands\UserMakeAboOrder::makeOrder / makePayment Error response',
|
||||
$response
|
||||
);
|
||||
|
||||
|
||||
$this->updateAbo($userAbo, $shoppingOrder, 3);
|
||||
|
||||
|
||||
$shoppingPayment = $userOrder->getShoppingPayment();
|
||||
$data = [
|
||||
'mode' => $shoppingPayment->mode,
|
||||
|
|
@ -205,10 +205,10 @@ class UserMakeAboOrder extends Command
|
|||
'send_link' => false,
|
||||
'payment_error' => $response,
|
||||
];
|
||||
|
||||
|
||||
Payment::paymentStatusSendMail($shoppingOrder, $shoppingPayment, $data);
|
||||
} else {
|
||||
Log::warning('UserMakeAboOrder: Unbekannter Zahlungsstatus', [
|
||||
\Log::channel('abo_order')->warning('UserMakeAboOrder: Unbekannter Zahlungsstatus', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id,
|
||||
'status' => $response['status']
|
||||
|
|
@ -216,14 +216,14 @@ class UserMakeAboOrder extends Command
|
|||
$this->warn("Unbekannter Zahlungsstatus für Abo {$userAbo->id}: {$response['status']}");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('UserMakeAboOrder: Ausnahme bei der Bestellungserstellung', [
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Ausnahme bei der Bestellungserstellung', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
$this->error("Ausnahme bei Abo {$userAbo->id}: " . $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
return $shoppingOrder;
|
||||
}
|
||||
|
||||
|
|
@ -237,38 +237,38 @@ class UserMakeAboOrder extends Command
|
|||
*/
|
||||
private function updateAbo($userAbo, $shoppingOrder, $status = 1)
|
||||
{
|
||||
Log::info('UserMakeAboOrder: Aktualisiere Abo', [
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Aktualisiere Abo', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'order_id' => $shoppingOrder->id,
|
||||
'status' => $status
|
||||
]);
|
||||
|
||||
|
||||
$this->info("Aktualisiere Abo: {$userAbo->id} mit Status {$status}");
|
||||
|
||||
|
||||
$updateData = [
|
||||
'next_date' => AboHelper::setNextDate(now(), $userAbo->abo_interval),
|
||||
'last_date' => now(),
|
||||
];
|
||||
|
||||
|
||||
if ($status !== 1) {
|
||||
$updateData['status'] = $status;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$userAbo->update($updateData);
|
||||
|
||||
|
||||
UserAboOrder::create([
|
||||
'user_abo_id' => $userAbo->id,
|
||||
'shopping_order_id' => $shoppingOrder->id,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
Log::info('UserMakeAboOrder: Abo erfolgreich aktualisiert', [
|
||||
|
||||
\Log::channel('abo_order')->info('UserMakeAboOrder: Abo erfolgreich aktualisiert', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'next_date' => $updateData['next_date']
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('UserMakeAboOrder: Fehler beim Aktualisieren des Abos', [
|
||||
\Log::channel('abo_order')->error('UserMakeAboOrder: Fehler beim Aktualisieren des Abos', [
|
||||
'abo_id' => $userAbo->id,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
|
|
@ -286,7 +286,7 @@ class UserMakeAboOrder extends Command
|
|||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
|
||||
|
||||
return $sec . ' Sekunden und ' . round($micro * 1000, 2) . ' ms';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
app/Console/Kernel.php
Executable file → Normal file
18
app/Console/Kernel.php
Executable file → Normal file
|
|
@ -31,15 +31,15 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// Job 1: Überprüft täglich um 02:00 Uhr die Zahlungskonten.
|
||||
$schedule->command('payments:check-accounts')->dailyAt('02:00');
|
||||
// Job 1: Überprüft täglich um 02:00 Uhr die Zahlungskonten.
|
||||
$schedule->command('payments:check-accounts')->dailyAt('02:00');
|
||||
// Jobs 2, 3, 4: Die Befehle aus deinem alten Shell-Skript.
|
||||
// Werden nacheinander täglich zu unterschiedlichen Zeiten ausgeführt,
|
||||
// um die Serverlast zu verteilen.
|
||||
$schedule->command('store-optimized 0 0')->dailyAt('03:00');
|
||||
|
||||
// Jobs 2, 3, 4: Die Befehle aus deinem alten Shell-Skript.
|
||||
// Werden nacheinander täglich zu unterschiedlichen Zeiten ausgeführt,
|
||||
// um die Serverlast zu verteilen.
|
||||
$schedule->command('business:store 0 0')->dailyAt('03:00');
|
||||
$schedule->command('user:cleanup')->dailyAt('03:30');
|
||||
$schedule->command('user:make_abo_order')->dailyAt('04:00');
|
||||
$schedule->command('user:cleanup')->dailyAt('03:30');
|
||||
$schedule->command('user:make_abo_order')->dailyAt('04:00');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +49,7 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Cron;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
|
||||
class BusinessUsersStore
|
||||
{
|
||||
|
|
@ -14,7 +15,7 @@ class BusinessUsersStore
|
|||
private $user_business_structure;
|
||||
private $users_structure = [];
|
||||
|
||||
|
||||
|
||||
public function __construct($month, $year)
|
||||
{
|
||||
$this->month = $month;
|
||||
|
|
@ -22,16 +23,17 @@ class BusinessUsersStore
|
|||
}
|
||||
|
||||
|
||||
public function getStoreUserBusinessStructure(){
|
||||
public function getStoreUserBusinessStructure()
|
||||
{
|
||||
return UserBusinessStructure::where('year', $this->year)->where('month', $this->month)->first();
|
||||
}
|
||||
|
||||
public function storeUserBusinessStructure()
|
||||
{
|
||||
if($this->user_business_structure = $this->getStoreUserBusinessStructure()){
|
||||
if ($this->user_business_structure = $this->getStoreUserBusinessStructure()) {
|
||||
return $this->user_business_structure;
|
||||
}
|
||||
$treeCalcBot = new TreeCalcBot($this->month, $this->year, 'admin');
|
||||
$treeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin');
|
||||
//only load, when no structur is save
|
||||
$treeCalcBot->initStructureAdmin(false);
|
||||
$this->storeStructure($treeCalcBot);
|
||||
|
|
@ -39,19 +41,19 @@ class BusinessUsersStore
|
|||
|
||||
public function storeBusinessUsersDetail()
|
||||
{
|
||||
if(!$this->user_business_structure){
|
||||
if (!$this->user_business_structure) {
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
if(!$this->user_business_structure){
|
||||
if (!$this->user_business_structure) {
|
||||
abort(403, 'not found UserBusinessStructure');
|
||||
}
|
||||
}
|
||||
foreach($this->user_business_structure->users as $user_id=>$completed){
|
||||
if($completed === 0){
|
||||
$user = User::find($user_id);
|
||||
if($user){
|
||||
$TreeCalcBot = new TreeCalcBot($this->month, $this->year, 'admin');
|
||||
foreach ($this->user_business_structure->users as $user_id => $completed) {
|
||||
if ($completed === 0) {
|
||||
$user = User::find($user_id);
|
||||
if ($user) {
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin');
|
||||
$TreeCalcBot->initBusinesslUserDetail($user);
|
||||
if(!$TreeCalcBot->business_user){
|
||||
if (!$TreeCalcBot->business_user) {
|
||||
abort(403, 'not found TreeCalcBot->business_user');
|
||||
}
|
||||
$this->storeBusinesslUser($TreeCalcBot->business_user);
|
||||
|
|
@ -60,13 +62,13 @@ class BusinessUsersStore
|
|||
$this->user_business_structure->users = $users;
|
||||
$this->user_business_structure->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function storeBusinesslUser($business_user){
|
||||
public function storeBusinesslUser($business_user)
|
||||
{
|
||||
$b_user = $business_user->getBUser();
|
||||
$b_user->user_items = $this->storeUserItems($business_user->businessUserItems, 1);
|
||||
$b_user->b_structure_id = $this->user_business_structure->id;
|
||||
|
|
@ -74,12 +76,13 @@ class BusinessUsersStore
|
|||
}
|
||||
|
||||
|
||||
public function storeBusinessCompleted(){
|
||||
if(!$this->user_business_structure){
|
||||
public function storeBusinessCompleted()
|
||||
{
|
||||
if (!$this->user_business_structure) {
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
}
|
||||
foreach($this->user_business_structure->users as $user_id=>$completed){
|
||||
if($completed === 0){
|
||||
foreach ($this->user_business_structure->users as $user_id => $completed) {
|
||||
if ($completed === 0) {
|
||||
return false;
|
||||
}
|
||||
$this->user_business_structure->completed = 1;
|
||||
|
|
@ -87,21 +90,22 @@ class BusinessUsersStore
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function storeUserItems($userItems, $line){
|
||||
|
||||
private function storeUserItems($userItems, $line)
|
||||
{
|
||||
$ret = [];
|
||||
foreach($userItems as $userItem){
|
||||
foreach ($userItems as $userItem) {
|
||||
$temp = null;
|
||||
if(count($userItem->businessUserItems) > 0){
|
||||
$temp = $this->storeUserItems($userItem->businessUserItems, $line+1);
|
||||
if (count($userItem->businessUserItems) > 0) {
|
||||
$temp = $this->storeUserItems($userItem->businessUserItems, $line + 1);
|
||||
}
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $userItem->user_id;
|
||||
$obj->line = $line;
|
||||
$obj->points = $userItem->sales_volume_points_sum;
|
||||
$obj->parents = $temp;
|
||||
$ret[] = $obj;
|
||||
$ret[] = $obj;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
|
@ -114,13 +118,13 @@ class BusinessUsersStore
|
|||
}*/
|
||||
|
||||
$structure = [];
|
||||
foreach($treeCalcBot->business_users as $business_user){
|
||||
foreach ($treeCalcBot->business_users as $business_user) {
|
||||
$structure[] = $this->storeStructureItem($business_user, 0);
|
||||
}
|
||||
|
||||
$parentless = [];
|
||||
if($treeCalcBot->parentless){
|
||||
foreach($treeCalcBot->parentless as $pless){
|
||||
if ($treeCalcBot->parentless) {
|
||||
foreach ($treeCalcBot->parentless as $pless) {
|
||||
$parentless[] = $this->storeStructureItem($pless, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -137,14 +141,15 @@ class BusinessUsersStore
|
|||
return $this->user_business_structure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function storeStructureItem($item, $deep){
|
||||
|
||||
private function storeStructureItem($item, $deep)
|
||||
{
|
||||
$temp = null;
|
||||
if($item->businessUserItems){
|
||||
foreach($item->businessUserItems as $parent){
|
||||
$temp[] = $this->storeStructureItem($parent, $deep+1);
|
||||
}
|
||||
if ($item->businessUserItems) {
|
||||
foreach ($item->businessUserItems as $parent) {
|
||||
$temp[] = $this->storeStructureItem($parent, $deep + 1);
|
||||
}
|
||||
}
|
||||
$this->users_structure[$item->user_id] = 0;
|
||||
$obj = new stdClass();
|
||||
|
|
@ -156,7 +161,4 @@ class BusinessUsersStore
|
|||
$obj->parents = $temp;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
263
app/Cron/BusinessUsersStoreOptimized.php
Normal file
263
app/Cron/BusinessUsersStoreOptimized.php
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
|
||||
namespace App\Cron;
|
||||
|
||||
use App\User;
|
||||
use stdClass;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use App\Services\BusinessPlan\TreeCalcBotOptimized;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class BusinessUsersStoreOptimized
|
||||
{
|
||||
private $month;
|
||||
private $year;
|
||||
private $user_business_structure;
|
||||
private $users_structure = [];
|
||||
private $logger;
|
||||
|
||||
public function __construct($month, $year, ?LoggerInterface $logger = null)
|
||||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
$this->logger = $logger ?? app(LoggerInterface::class);
|
||||
}
|
||||
|
||||
public function getStoreUserBusinessStructure()
|
||||
{
|
||||
return UserBusinessStructure::where('year', $this->year)
|
||||
->where('month', $this->month)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function storeUserBusinessStructure()
|
||||
{
|
||||
if ($this->user_business_structure = $this->getStoreUserBusinessStructure()) {
|
||||
$this->logger->info("Found existing business structure for {$this->month}/{$this->year}");
|
||||
return $this->user_business_structure;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->logger->info("Creating new business structure for {$this->month}/{$this->year}");
|
||||
$startTime = microtime(true);
|
||||
|
||||
// Verwende TreeCalcBotOptimized mit Live-Berechnung für aktuelle Daten
|
||||
$treeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin', true);
|
||||
$treeCalcBot->initStructureAdmin(false, true); // forceLiveCalculation = true
|
||||
|
||||
$this->storeStructure($treeCalcBot);
|
||||
|
||||
$endTime = microtime(true);
|
||||
$duration = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->logger->info("Business structure created in {$duration}ms with " . count($this->users_structure) . " users");
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error creating business structure: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function storeBusinessUsersDetail()
|
||||
{
|
||||
if (!$this->user_business_structure) {
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
if (!$this->user_business_structure) {
|
||||
throw new \Exception('UserBusinessStructure not found');
|
||||
}
|
||||
}
|
||||
|
||||
$totalUsers = count($this->user_business_structure->users);
|
||||
$processedUsers = 0;
|
||||
|
||||
$this->logger->info("Processing {$totalUsers} business user details");
|
||||
|
||||
foreach ($this->user_business_structure->users as $user_id => $completed) {
|
||||
if ($completed === 0) {
|
||||
try {
|
||||
$user = User::find($user_id);
|
||||
if ($user) {
|
||||
$this->processBusinessUser($user, $user_id);
|
||||
$processedUsers++;
|
||||
|
||||
// Log progress every 50 users
|
||||
if ($processedUsers % 50 === 0) {
|
||||
$this->logger->info("Processed {$processedUsers}/{$totalUsers} business users");
|
||||
}
|
||||
} else {
|
||||
$this->logger->warning("User {$user_id} not found, skipping");
|
||||
$this->markUserCompleted($user_id);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error processing user {$user_id}: " . $e->getMessage());
|
||||
// Mark as completed to avoid infinite retry loops
|
||||
$this->markUserCompleted($user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->info("Completed processing {$processedUsers} business user details");
|
||||
}
|
||||
|
||||
private function processBusinessUser(User $user, int $user_id): void
|
||||
{
|
||||
try {
|
||||
$startTime = microtime(true);
|
||||
|
||||
// Verwende TreeCalcBotOptimized für detaillierte Benutzerberechnung
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin', true);
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, true); // forceLiveCalculation = true
|
||||
|
||||
if (!$TreeCalcBot->business_user) {
|
||||
throw new \Exception("business_user not found for user {$user_id}");
|
||||
}
|
||||
|
||||
$this->storeBusinesslUser($TreeCalcBot->business_user);
|
||||
$this->markUserCompleted($user_id);
|
||||
|
||||
$endTime = microtime(true);
|
||||
$duration = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->logger->debug("Processed user {$user_id} in {$duration}ms");
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error in processBusinessUser for {$user_id}: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function markUserCompleted(int $user_id): void
|
||||
{
|
||||
$users = $this->user_business_structure->users;
|
||||
$users[$user_id] = 1;
|
||||
$this->user_business_structure->users = $users;
|
||||
$this->user_business_structure->save();
|
||||
}
|
||||
|
||||
public function storeBusinesslUser($business_user)
|
||||
{
|
||||
try {
|
||||
$b_user = $business_user->getBUser();
|
||||
$b_user->user_items = $this->storeUserItems($business_user->businessUserItems, 1);
|
||||
$b_user->b_structure_id = $this->user_business_structure->id;
|
||||
$b_user->save();
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error storing business user: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function storeBusinessCompleted()
|
||||
{
|
||||
if (!$this->user_business_structure) {
|
||||
$this->user_business_structure = $this->getStoreUserBusinessStructure();
|
||||
}
|
||||
|
||||
$incompleteCount = 0;
|
||||
foreach ($this->user_business_structure->users as $user_id => $completed) {
|
||||
if ($completed === 0) {
|
||||
$incompleteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($incompleteCount === 0) {
|
||||
$this->user_business_structure->completed = 1;
|
||||
$this->user_business_structure->save();
|
||||
$this->logger->info("Business structure marked as completed");
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->info("{$incompleteCount} users still incomplete");
|
||||
return false;
|
||||
}
|
||||
|
||||
private function storeUserItems($userItems, $line)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
try {
|
||||
foreach ($userItems as $userItem) {
|
||||
$temp = null;
|
||||
if (count($userItem->businessUserItems) > 0) {
|
||||
$temp = $this->storeUserItems($userItem->businessUserItems, $line + 1);
|
||||
}
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $userItem->user_id;
|
||||
$obj->line = $line;
|
||||
$obj->points = $userItem->sales_volume_points_sum ?? 0;
|
||||
$obj->parents = $temp;
|
||||
$ret[] = $obj;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error storing user items at line {$line}: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function storeStructure($treeCalcBot)
|
||||
{
|
||||
try {
|
||||
$structure = [];
|
||||
$businessUsers = $treeCalcBot->business_users;
|
||||
|
||||
if (!is_array($businessUsers)) {
|
||||
throw new \Exception("business_users is not an array");
|
||||
}
|
||||
|
||||
foreach ($businessUsers as $business_user) {
|
||||
$structure[] = $this->storeStructureItem($business_user, 0);
|
||||
}
|
||||
|
||||
$parentless = [];
|
||||
$parentlessUsers = $treeCalcBot->parentless;
|
||||
|
||||
if ($parentlessUsers && is_array($parentlessUsers)) {
|
||||
foreach ($parentlessUsers as $pless) {
|
||||
$parentless[] = $this->storeStructureItem($pless, 0);
|
||||
}
|
||||
}
|
||||
|
||||
$fill = [
|
||||
'month' => $this->month,
|
||||
'year' => $this->year,
|
||||
'structure' => $structure,
|
||||
'parentless' => $parentless,
|
||||
'users' => $this->users_structure,
|
||||
'completed' => false,
|
||||
'status' => 0
|
||||
];
|
||||
|
||||
$this->user_business_structure = UserBusinessStructure::create($fill);
|
||||
$this->logger->info("Stored structure with " . count($structure) . " root users and " . count($parentless) . " parentless users");
|
||||
|
||||
return $this->user_business_structure;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error storing structure: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
private function storeStructureItem($item, $deep)
|
||||
{
|
||||
try {
|
||||
$temp = null;
|
||||
if (isset($item->businessUserItems) && is_array($item->businessUserItems)) {
|
||||
foreach ($item->businessUserItems as $parent) {
|
||||
$temp[] = $this->storeStructureItem($parent, $deep + 1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->users_structure[$item->user_id] = 0;
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->user_id = $item->user_id;
|
||||
$obj->email = $item->email ?? 'unknown';
|
||||
$obj->deep = $deep;
|
||||
$obj->parents = $temp;
|
||||
|
||||
return $obj;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error storing structure item for user {$item->user_id}: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
277
app/Domain/EarlyDomainParser.php
Normal file
277
app/Domain/EarlyDomainParser.php
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
|
||||
namespace App\Domain;
|
||||
|
||||
/**
|
||||
* Early Domain Parser Service
|
||||
*
|
||||
* Provides domain parsing functionality that can be used during
|
||||
* bootstrap phase (RouteServiceProvider) and runtime (Middleware).
|
||||
*
|
||||
* This service caches parsing results per request to avoid duplicate work.
|
||||
*/
|
||||
class EarlyDomainParser
|
||||
{
|
||||
/**
|
||||
* Cache for parsed domain information per request
|
||||
* @var array|null
|
||||
*/
|
||||
private static ?array $cachedDomainInfo = null;
|
||||
|
||||
/**
|
||||
* Cache key (host) for cache invalidation
|
||||
* @var string|null
|
||||
*/
|
||||
private static ?string $cachedHost = null;
|
||||
|
||||
/**
|
||||
* Parse domain information from config/domains.php
|
||||
*
|
||||
* Results are cached per request to avoid duplicate parsing.
|
||||
*
|
||||
* @param string|null $host If null, uses HTTP_HOST or SERVER_NAME
|
||||
* @return array Domain information array
|
||||
*/
|
||||
public static function parseDomain(?string $host = null): array
|
||||
{
|
||||
// Get host from request if not provided
|
||||
if ($host === null) {
|
||||
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
|
||||
}
|
||||
|
||||
// Remove protocol if present
|
||||
$host = preg_replace('/^https?:\/\//', '', $host);
|
||||
|
||||
// Return cached result if available for same host
|
||||
if (self::$cachedHost === $host && self::$cachedDomainInfo !== null) {
|
||||
return self::$cachedDomainInfo;
|
||||
}
|
||||
// Load domains configuration
|
||||
$domains = self::getDomainsConfig();
|
||||
$reservedSubdomains = self::getReservedSubdomains();
|
||||
|
||||
// Check exact matches first (main, shop, crm, portal, checkout)
|
||||
foreach ($domains as $key => $domainConfig) {
|
||||
if ($key === 'user-shop') {
|
||||
continue; // Handle user-shop separately
|
||||
}
|
||||
|
||||
if ($host === $domainConfig['host']) {
|
||||
$domainInfo = [
|
||||
'type' => $domainConfig['type'],
|
||||
'host' => $host,
|
||||
'subdomain' => null,
|
||||
'config_key' => $key,
|
||||
];
|
||||
|
||||
// Cache the result for this request
|
||||
self::$cachedHost = $host;
|
||||
self::$cachedDomainInfo = $domainInfo;
|
||||
|
||||
return $domainInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for user-shop pattern (dynamic subdomains)
|
||||
if (isset($domains['user-shop'])) {
|
||||
$userShopPattern = $domains['user-shop']['host'];
|
||||
$baseDomain = str_replace('{subdomain}.', '', $userShopPattern);
|
||||
|
||||
if (str_ends_with($host, '.' . $baseDomain)) {
|
||||
$subdomain = str_replace('.' . $baseDomain, '', $host);
|
||||
|
||||
// Check if subdomain is not reserved
|
||||
if (!empty($subdomain) && !in_array($subdomain, $reservedSubdomains)) {
|
||||
$domainInfo = [
|
||||
'type' => 'user-shop',
|
||||
'host' => $host,
|
||||
'subdomain' => $subdomain,
|
||||
'config_key' => 'user-shop',
|
||||
];
|
||||
|
||||
// Cache the result for this request
|
||||
self::$cachedHost = $host;
|
||||
self::$cachedDomainInfo = $domainInfo;
|
||||
|
||||
return $domainInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown domain
|
||||
$domainInfo = [
|
||||
'type' => 'unknown',
|
||||
'host' => $host,
|
||||
'subdomain' => null,
|
||||
'config_key' => null,
|
||||
];
|
||||
|
||||
// Cache the result for this request
|
||||
self::$cachedHost = $host;
|
||||
self::$cachedDomainInfo = $domainInfo;
|
||||
|
||||
return $domainInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current domain type quickly (for RouteServiceProvider)
|
||||
*/
|
||||
public static function getCurrentDomainType(): string
|
||||
{
|
||||
$domainInfo = self::parseDomain();
|
||||
return $domainInfo['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current domain is a user shop
|
||||
*/
|
||||
public static function isUserShop(): bool
|
||||
{
|
||||
return self::getCurrentDomainType() === 'user-shop';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subdomain for user shops
|
||||
*/
|
||||
public static function getSubdomain(): ?string
|
||||
{
|
||||
$domainInfo = self::parseDomain();
|
||||
return $domainInfo['subdomain'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get domains configuration (early bootstrap safe)
|
||||
*/
|
||||
private static function getDomainsConfig(): array
|
||||
{
|
||||
// Try Laravel config first (if available)
|
||||
if (function_exists('config')) {
|
||||
$config = config('domains.domains');
|
||||
if ($config) {
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Read config file directly
|
||||
$configPath = __DIR__ . '/../../../../config/domains.php';
|
||||
if (file_exists($configPath)) {
|
||||
$config = include $configPath;
|
||||
return $config['domains'] ?? [];
|
||||
}
|
||||
|
||||
// Last resort: Build from environment variables
|
||||
return self::buildConfigFromEnv();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reserved subdomains configuration
|
||||
*/
|
||||
private static function getReservedSubdomains(): array
|
||||
{
|
||||
// Try Laravel config first (if available)
|
||||
if (function_exists('config')) {
|
||||
$reserved = config('domains.reserved_subdomains');
|
||||
if ($reserved) {
|
||||
return $reserved;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Read config file directly
|
||||
$configPath = __DIR__ . '/../../../../config/domains.php';
|
||||
if (file_exists($configPath)) {
|
||||
$config = include $configPath;
|
||||
return $config['reserved_subdomains'] ?? [];
|
||||
}
|
||||
|
||||
// Default reserved subdomains
|
||||
return ['my', 'in', 'checkout', 'www', 'api', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build basic domain configuration from environment variables
|
||||
* Used as fallback when config file is not available
|
||||
*/
|
||||
private static function buildConfigFromEnv(): array
|
||||
{
|
||||
$domain = $_ENV['APP_DOMAIN'] ?? 'mivita';
|
||||
$tldCare = $_ENV['APP_TLD_CARE'] ?? '.care';
|
||||
$tldShop = $_ENV['APP_TLD_SHOP'] ?? '.shop';
|
||||
$crmPrefix = $_ENV['APP_PRE_URL_CRM'] ?? 'my.';
|
||||
$portalPrefix = $_ENV['APP_PRE_URL_PORTAL'] ?? 'in.';
|
||||
$checkoutPrefix = $_ENV['APP_URL_CHECKOUT'] ?? 'checkout.';
|
||||
|
||||
return [
|
||||
'main' => [
|
||||
'host' => $domain . $tldCare,
|
||||
'type' => 'main',
|
||||
],
|
||||
'shop' => [
|
||||
'host' => $domain . $tldShop,
|
||||
'type' => 'main-shop',
|
||||
'default_user_shop' => 'aloevera',
|
||||
],
|
||||
'crm' => [
|
||||
'host' => $crmPrefix . $domain . $tldCare,
|
||||
'type' => 'crm',
|
||||
],
|
||||
'portal' => [
|
||||
'host' => $portalPrefix . $domain . $tldCare,
|
||||
'type' => 'portal',
|
||||
],
|
||||
'checkout' => [
|
||||
'host' => $checkoutPrefix . $domain . $tldCare,
|
||||
'type' => 'checkout',
|
||||
],
|
||||
'user-shop' => [
|
||||
'host' => '{subdomain}.' . $domain . $tldCare,
|
||||
'type' => 'user-shop',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get protocol from configuration
|
||||
*/
|
||||
public static function getProtocol(): string
|
||||
{
|
||||
if (function_exists('config')) {
|
||||
return config('domains.protocol', 'https://');
|
||||
}
|
||||
|
||||
return $_ENV['APP_PROTOCOL'] ?? 'https://';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get main domain URL for redirects
|
||||
*/
|
||||
public static function getMainUrl(): string
|
||||
{
|
||||
$domains = self::getDomainsConfig();
|
||||
$mainHost = $domains['main']['host'] ?? 'localhost';
|
||||
$protocol = self::getProtocol();
|
||||
|
||||
return $protocol . $mainHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the internal cache (useful for testing or special cases)
|
||||
*/
|
||||
public static function clearCache(): void
|
||||
{
|
||||
self::$cachedDomainInfo = null;
|
||||
self::$cachedHost = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if result is cached for current/given host
|
||||
*/
|
||||
public static function isCached(?string $host = null): bool
|
||||
{
|
||||
if ($host === null) {
|
||||
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
|
||||
$host = preg_replace('/^https?:\/\//', '', $host);
|
||||
}
|
||||
|
||||
return self::$cachedHost === $host && self::$cachedDomainInfo !== null;
|
||||
}
|
||||
}
|
||||
18
app/Exceptions/Handler.php
Executable file → Normal file
18
app/Exceptions/Handler.php
Executable file → Normal file
|
|
@ -75,15 +75,17 @@ class Handler extends ExceptionHandler
|
|||
}
|
||||
|
||||
try {
|
||||
// Versuche domain-spezifische Login-Route
|
||||
$context = app(\App\Domain\DomainContext::class);
|
||||
$loginRoute = match($context->type) {
|
||||
'portal' => 'portal.login.form',
|
||||
'crm' => 'login', // CRM hat eine eigene login route
|
||||
default => 'login'
|
||||
};
|
||||
// HOTFIX: DomainContext temporär deaktiviert
|
||||
// TODO: Nach Claude v2 Implementation wieder aktivieren
|
||||
// $context = app(\App\Domain\DomainContext::class);
|
||||
// $loginRoute = match($context->type) {
|
||||
// 'portal' => 'portal.login.form',
|
||||
// 'crm' => 'login', // CRM hat eine eigene login route
|
||||
// default => 'login'
|
||||
// };
|
||||
|
||||
return redirect()->guest(route($loginRoute));
|
||||
// Temporär: Verwende Standard-Login-Route
|
||||
return redirect()->guest(route('login'));
|
||||
} catch (\Exception $e) {
|
||||
// Fallback: Weiterleitung zur Hauptdomain
|
||||
return redirect()->guest('https://' . config('app.domain') . config('app.tld_care') . '/login');
|
||||
|
|
|
|||
162
app/Http/Controllers/AdminUserController.php
Executable file → Normal file
162
app/Http/Controllers/AdminUserController.php
Executable file → Normal file
|
|
@ -26,7 +26,6 @@ class AdminUserController extends Controller
|
|||
{
|
||||
$this->middleware('superadmin');
|
||||
$this->userRepo = $userRepo;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +43,7 @@ class AdminUserController extends Controller
|
|||
public function edit($user_id)
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
if(!$user->account){
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
}
|
||||
|
||||
|
|
@ -52,8 +51,6 @@ class AdminUserController extends Controller
|
|||
'user' => $user,
|
||||
];
|
||||
return view('admin.user.edit', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,77 +61,77 @@ class AdminUserController extends Controller
|
|||
{
|
||||
$data = Request::all();
|
||||
$user = User::findOrFail($data['id']);
|
||||
|
||||
/* if(isset($data['user-delete'])){
|
||||
|
||||
/* if(isset($data['user-delete'])){
|
||||
if(isset($data['realy_delete_user'])){
|
||||
return redirect(route('admin_user_delete', [$user->id]));
|
||||
}
|
||||
}*/
|
||||
if(isset($data['save-admin'])){
|
||||
if (isset($data['save-admin'])) {
|
||||
$user->admin = $data['admin'];
|
||||
SysLog::action('save-admin', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user admin value: '.HTMLHelper::getLabel($user->admin))
|
||||
->setMessage('Set user admin value: ' . HTMLHelper::getLabel($user->admin))
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-confirmed'])){
|
||||
if (isset($data['save-confirmed'])) {
|
||||
$data['confirmed'] = isset($data['confirmed']) ? true : false;
|
||||
$user->confirmed = $data['confirmed'];
|
||||
if($data['confirmed']){
|
||||
if(!isset($data['confirmation_date']) || $data['confirmation_date'] == ""){
|
||||
if ($data['confirmed']) {
|
||||
if (!isset($data['confirmation_date']) || $data['confirmation_date'] == "") {
|
||||
$user->confirmation_date = now();
|
||||
}else{
|
||||
} else {
|
||||
$user->confirmation_date = \Carbon::parse(str_replace("- ", "", $data['confirmation_date']));
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$user->confirmation_date = null;
|
||||
}
|
||||
SysLog::action('save-confirmed', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user confirmed value: '.$user->confirmed." to date: ".$data['confirmation_date'])
|
||||
->setMessage('Set user confirmed value: ' . $user->confirmed . " to date: " . $data['confirmation_date'])
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-active'])){
|
||||
if (isset($data['save-active'])) {
|
||||
$data['active'] = isset($data['active']) ? true : false;
|
||||
$user->active = $data['active'];
|
||||
if($data['active'] === true && $user->wizard < 20){
|
||||
if ($data['active'] === true && $user->wizard < 20) {
|
||||
$user->wizard = 20;
|
||||
}
|
||||
if($data['active']){
|
||||
if(!isset($data['active_date']) || $data['active_date'] == ""){
|
||||
if ($data['active']) {
|
||||
if (!isset($data['active_date']) || $data['active_date'] == "") {
|
||||
$user->active_date = now();
|
||||
}else{
|
||||
} else {
|
||||
$user->active_date = \Carbon::parse(str_replace("- ", "", $data['active_date']));
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$user->active_date = null;
|
||||
}
|
||||
SysLog::action('save-active', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user active value: '.$user->active." to date: ".$data['active_date'])
|
||||
->setMessage('Set user active value: ' . $user->active . " to date: " . $data['active_date'])
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-account'])){
|
||||
if (isset($data['save-account'])) {
|
||||
$old = $user->getPaymentAccountDateFormat(true);
|
||||
if(!isset($data['payment_account']) || $data['payment_account'] == ""){
|
||||
if (!isset($data['payment_account']) || $data['payment_account'] == "") {
|
||||
$user->payment_account = null;
|
||||
}else{
|
||||
} else {
|
||||
$user->wizard = 100;
|
||||
$payment_account = \Carbon::parse(str_replace("- ", "", $data['payment_account']));
|
||||
$user->payment_account = $payment_account;
|
||||
if($payment_account > Carbon::now()){
|
||||
if($user->active === 0){
|
||||
if ($payment_account > Carbon::now()) {
|
||||
if ($user->active === 0) {
|
||||
$user->active = true;
|
||||
UserUtil::reactiveUserResetChilds($user->id, 'on save-account AdminUserController');
|
||||
}
|
||||
}else{
|
||||
if($user->active === 1){
|
||||
} else {
|
||||
if ($user->active === 1) {
|
||||
$user->active = false;
|
||||
UserUtil::deactiveUserNewSponsorChilds($user->id, 'on save-account AdminUserController');
|
||||
}
|
||||
|
|
@ -144,40 +141,40 @@ class AdminUserController extends Controller
|
|||
SysLog::action('save-account', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user payment_account from date: '.$old." to date: ".$data['payment_account'])
|
||||
->setMessage('Set user payment_account from date: ' . $old . " to date: " . $data['payment_account'])
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-shop'])){
|
||||
if (isset($data['save-shop'])) {
|
||||
$old = $user->getPaymentShopDateFormat(true);
|
||||
if(!isset($data['payment_shop']) || $data['payment_shop'] == ""){
|
||||
if (!isset($data['payment_shop']) || $data['payment_shop'] == "") {
|
||||
$user->payment_shop = null;
|
||||
}else{
|
||||
} else {
|
||||
$user->wizard = 100;
|
||||
$user->payment_shop = \Carbon::parse(str_replace("- ", "", $data['payment_shop']));
|
||||
}
|
||||
SysLog::action('save-shop', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user payment_shop from date: '.$old." to date: ".$data['payment_shop'])
|
||||
->setMessage('Set user payment_shop from date: ' . $old . " to date: " . $data['payment_shop'])
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-test_mode'])){
|
||||
if (isset($data['save-test_mode'])) {
|
||||
$user->test_mode = isset($data['test_mode']) ? true : false;
|
||||
SysLog::action('save-test_mode', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user test_mode value: '.$user->test_mode)
|
||||
->setMessage('Set user test_mode value: ' . $user->test_mode)
|
||||
->save();
|
||||
}
|
||||
|
||||
if(isset($data['save-payment_methods'])){
|
||||
if (isset($data['save-payment_methods'])) {
|
||||
$user->payment_methods = isset($data['payment_methods']) ? array_map('intval', $data['payment_methods']) : null;
|
||||
SysLog::action('save-payment_methods', 'admin_user', 3)
|
||||
->setUserId(Auth::user()->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Set user payment_methods value: '.$user->getPaymentMethodsShort())
|
||||
->setMessage('Set user payment_methods value: ' . $user->getPaymentMethodsShort())
|
||||
->save();
|
||||
}
|
||||
|
||||
|
|
@ -191,22 +188,22 @@ class AdminUserController extends Controller
|
|||
{
|
||||
$data = Request::all();
|
||||
$user = User::withTrashed()->findOrFail($data['id']);
|
||||
if(isset($data['realy_delete_user'])){
|
||||
if (isset($data['realy_delete_user'])) {
|
||||
$this->userRepo->deleteUser($user);
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
}
|
||||
if(isset($data['realy_delete_user_complete'])){
|
||||
// $this->userRepo->deleteUserComplete($user);
|
||||
$this->userRepo->deleteUser($user, true);
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
if (isset($data['realy_delete_user_complete'])) {
|
||||
// $this->userRepo->deleteUserComplete($user);
|
||||
$this->userRepo->deleteUser($user, true);
|
||||
\Session()->flash('alert-success', __('msg.contact_delete'));
|
||||
}
|
||||
return redirect('/admin/users');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function userLoginAs($userId){
|
||||
if(Auth::user()->isSuperAdmin()){
|
||||
public function userLoginAs($userId)
|
||||
{
|
||||
if (Auth::user()->isSuperAdmin()) {
|
||||
$user = User::find($userId);
|
||||
Auth::login($user);
|
||||
return redirect('/home');
|
||||
|
|
@ -216,12 +213,12 @@ class AdminUserController extends Controller
|
|||
public function getUsers()
|
||||
{
|
||||
$query = User::withTrashed()
|
||||
->where(function($q) {
|
||||
->where(function ($q) {
|
||||
$q->where('pre_deleted_at', '!=', null)
|
||||
->orWhere(function($query) {
|
||||
$query->whereNull('deleted_at')
|
||||
->orWhere(function ($query) {
|
||||
$query->whereNull('deleted_at')
|
||||
->whereNull('pre_deleted_at');
|
||||
});
|
||||
});
|
||||
})
|
||||
->with('account')
|
||||
->select('users.*')
|
||||
|
|
@ -232,8 +229,8 @@ class AdminUserController extends Controller
|
|||
return $user->account ? $user->account->first_name : '';
|
||||
})
|
||||
->addColumn('email', function (User $user) {
|
||||
if($user->pre_deleted_at){
|
||||
return '<span class="badge badge-pill badge-danger">'.$user->email.'</span>';
|
||||
if ($user->pre_deleted_at) {
|
||||
return '<span class="badge badge-pill badge-danger">' . $user->email . '</span>';
|
||||
}
|
||||
return $user->email;
|
||||
})
|
||||
|
|
@ -244,43 +241,46 @@ class AdminUserController extends Controller
|
|||
return '<a href="' . route('admin_lead_edit', [$user->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('admin', function (User $user) {
|
||||
return '<a href="#" data-toggle="modal" data-target="#modals-admin" data-id="'.$user->id.'" data-email="'.$user->email.'" data-admin="'.$user->admin.'">'.HTMLHelper::getRoleLabel($user->admin).'</a>';
|
||||
return '<a href="#" data-toggle="modal" data-target="#modals-admin" data-id="' . $user->id . '" data-email="' . $user->email . '" data-admin="' . $user->admin . '">' . HTMLHelper::getRoleLabel($user->admin) . '</a>';
|
||||
})
|
||||
->addColumn('confirmed', function (User $user) {
|
||||
$date = $user->getConfirmationDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-confirmed" data-id="'.$user->id.'" data-email="'.$user->email.'" data-confirmed="'.$user->confirmed.'" data-confirmation_date="'.$date.'">';
|
||||
return $user->confirmed ? $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>' : $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-confirmed" data-id="' . $user->id . '" data-email="' . $user->email . '" data-confirmed="' . $user->confirmed . '" data-confirmation_date="' . $date . '">';
|
||||
return $user->confirmed ? $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>' : $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('active', function (User $user) {
|
||||
$date = $user->getActiveDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-active" data-id="'.$user->id.'" data-email="'.$user->email.'" data-active="'.$user->active.'" data-active_date="'.$date.'">';
|
||||
return $user->active ? $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>' : $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-active" data-id="' . $user->id . '" data-email="' . $user->email . '" data-active="' . $user->active . '" data-active_date="' . $date . '">';
|
||||
return $user->active ? $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>' : $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('account', function (User $user) {
|
||||
$date = $user->getPaymentAccountDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-account" data-id="'.$user->id.'" data-email="'.$user->email.'" data-payment_account="'.$date.'">';
|
||||
if($user->payment_account){
|
||||
if($user->isActiveAccount()){
|
||||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-account" data-id="' . $user->id . '" data-email="' . $user->email . '" data-payment_account="' . $date . '">';
|
||||
if ($user->payment_account) {
|
||||
if ($user->isActiveAccount()) {
|
||||
return $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>';
|
||||
}
|
||||
return $link.'<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> '.$date.'</span></a>';
|
||||
return $link . '<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> ' . $date . '</span></a>';
|
||||
}
|
||||
return $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
return $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('shop', function (User $user) {
|
||||
$date = $user->getPaymentShopDateFormat();
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-shop" data-id="'.$user->id.'" data-email="'.$user->email.'" data-payment_shop="'.$date.'">';
|
||||
if($user->payment_shop){
|
||||
if($user->isActiveShop()){
|
||||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$date.'</span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-shop" data-id="' . $user->id . '" data-email="' . $user->email . '" data-payment_shop="' . $date . '">';
|
||||
if ($user->payment_shop) {
|
||||
if ($user->isActiveShop()) {
|
||||
return $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $date . '</span></a>';
|
||||
}
|
||||
return $link.'<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> '.$date.'</span></a>';
|
||||
return $link . '<span class="badge badge-pill badge-warning"><i class="fa fa-ban"></i> ' . $date . '</span></a>';
|
||||
}
|
||||
return $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
return $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->addColumn('shop_domain', function (User $user) {
|
||||
return $user->shop ? '<a href="' . $user->shop->getSubdomain(false) . '" target="_blank">' . $user->shop->getSubdomain(false) . '</a>' : '';
|
||||
})
|
||||
->addColumn('since', function (User $user) {
|
||||
if($user->shop){
|
||||
if($user->shop->active){
|
||||
if ($user->shop) {
|
||||
if ($user->shop->active) {
|
||||
return $user->shop->getActiveDateFormatSmall();
|
||||
}
|
||||
return $user->shop->getActiveDateFormatSmall();
|
||||
|
|
@ -292,23 +292,21 @@ class AdminUserController extends Controller
|
|||
})
|
||||
->addColumn('my_payment_methods', function (User $user) {
|
||||
$payment_methods = json_encode($user->payment_methods);
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-payment_methods" data-id="'.$user->id.'" data-email="'.$user->email.'" data-payment_methods="'.htmlspecialchars($payment_methods).'">';
|
||||
if(!$user->payment_methods){
|
||||
return $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-payment_methods" data-id="' . $user->id . '" data-email="' . $user->email . '" data-payment_methods="' . htmlspecialchars($payment_methods) . '">';
|
||||
if (!$user->payment_methods) {
|
||||
return $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
}
|
||||
return $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user->getPaymentMethodsShort().'</span></a>';
|
||||
|
||||
return $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> ' . $user->getPaymentMethodsShort() . '</span></a>';
|
||||
})
|
||||
->addColumn('action_login', function (User $user) {
|
||||
return '<a href="' . route('admin_user_login_as', [$user->id]) . '" class="btn icon-btn btn-sm btn-warning" onclick="return confirm(\''.__('Login as User?').'\');"><span class="fa fa-sign-in-alt"></span></a>';
|
||||
return '<a href="' . route('admin_user_login_as', [$user->id]) . '" class="btn icon-btn btn-sm btn-warning" onclick="return confirm(\'' . __('Login as User?') . '\');"><span class="fa fa-sign-in-alt"></span></a>';
|
||||
})
|
||||
->addColumn('action_delete', function (User $user) {
|
||||
return '<a class="btn icon-btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#modals-user-delete" data-id="'.$user->id.'" data-email="'.$user->email.'"><span class="fa fa-trash"></span></a>';
|
||||
})
|
||||
return '<a class="btn icon-btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#modals-user-delete" data-id="' . $user->id . '" data-email="' . $user->email . '"><span class="fa fa-trash"></span></a>';
|
||||
})
|
||||
->addColumn('test_mode', function (User $user) {
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-test_mode" data-id="'.$user->id.'" data-email="'.$user->email.'" data-test_mode="'.$user->test_mode.'">';
|
||||
return $user->test_mode ? $link.'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span></a>' : $link.'<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
|
||||
$link = '<a href="#" data-toggle="modal" data-target="#modals-test_mode" data-id="' . $user->id . '" data-email="' . $user->email . '" data-test_mode="' . $user->test_mode . '">';
|
||||
return $user->test_mode ? $link . '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span></a>' : $link . '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span></a>';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('email', 'email $1')
|
||||
|
|
@ -316,7 +314,7 @@ class AdminUserController extends Controller
|
|||
->orderColumn('active', 'active $1')
|
||||
->orderColumn('shop', 'shop $1')
|
||||
->orderColumn('admin', 'active $1')
|
||||
->rawColumns(['id', 'email', 'admin', 'confirmed', 'active', 'account', 'shop', 'my_payment_methods', 'test_mode', 'action_login', 'action_delete'])
|
||||
->rawColumns(['id', 'email', 'admin', 'confirmed', 'active', 'account', 'shop', 'shop_domain', 'my_payment_methods', 'test_mode', 'action_login', 'action_delete'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/Api/AuthController.php
Executable file → Normal file
0
app/Http/Controllers/Api/AuthController.php
Executable file → Normal file
0
app/Http/Controllers/Api/KasController.php
Executable file → Normal file
0
app/Http/Controllers/Api/KasController.php
Executable file → Normal file
0
app/Http/Controllers/Api/KasSLLController.php
Executable file → Normal file
0
app/Http/Controllers/Api/KasSLLController.php
Executable file → Normal file
0
app/Http/Controllers/Api/PayoneController.php
Executable file → Normal file
0
app/Http/Controllers/Api/PayoneController.php
Executable file → Normal file
0
app/Http/Controllers/Api/ShoppingUserController.php
Executable file → Normal file
0
app/Http/Controllers/Api/ShoppingUserController.php
Executable file → Normal file
0
app/Http/Controllers/AttributeController.php
Executable file → Normal file
0
app/Http/Controllers/AttributeController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/ForgotPasswordController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/LoginController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/LoginController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/RegisterController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/RegisterController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file → Normal file
0
app/Http/Controllers/Auth/ResetPasswordController.php
Executable file → Normal file
|
|
@ -25,6 +25,7 @@ class BusinessController extends Controller
|
|||
|
||||
public function show()
|
||||
{
|
||||
abort(403, 'This page is removed');
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
|
|
@ -36,6 +37,7 @@ class BusinessController extends Controller
|
|||
|
||||
public function structure()
|
||||
{
|
||||
//abort(403, 'This page is removed');
|
||||
$this->setFilterVars();
|
||||
$this->month = session('business_user_filter_month');
|
||||
$this->year = session('business_user_filter_year');
|
||||
|
|
@ -53,6 +55,7 @@ class BusinessController extends Controller
|
|||
|
||||
public function userDetail($user_id)
|
||||
{
|
||||
abort(403, 'This page is removed');
|
||||
$user = User::findOrFail($user_id);
|
||||
$this->setFilterVars();
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class BusinessControllerOptimized extends Controller
|
|||
private $filter_next_level = [
|
||||
0 => 'Alle Status',
|
||||
1 => 'Qualifiziert (grün)',
|
||||
2 => 'In Arbeit (gelb)',
|
||||
2 => 'In Arbeit (gelb)',
|
||||
3 => 'Kein Level (rot)'
|
||||
];
|
||||
private $month;
|
||||
|
|
@ -49,7 +49,7 @@ class BusinessControllerOptimized extends Controller
|
|||
public function show()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(),
|
||||
|
|
@ -58,7 +58,7 @@ class BusinessControllerOptimized extends Controller
|
|||
'filter_next_level' => $this->filter_next_level,
|
||||
'optimized' => true, // Flag für View um zu zeigen, dass optimierte Version läuft
|
||||
];
|
||||
|
||||
|
||||
return view('admin.business_optimized.show', $data);
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class BusinessControllerOptimized extends Controller
|
|||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
|
||||
try {
|
||||
$this->setFilterVars();
|
||||
$this->month = session('business_user_filter_month');
|
||||
|
|
@ -79,25 +79,26 @@ class BusinessControllerOptimized extends Controller
|
|||
|
||||
// Verwende optimierte TreeCalcBot-Version
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'admin');
|
||||
|
||||
|
||||
// Prüfe ob Live-Berechnung für Struktur erzwungen wird
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live_structure', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live_structure', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
Log::info("BusinessControllerOptimized: Force live calculation requested");
|
||||
$TreeCalcBot->initStructureAdmin(true, $forceLiveCalculation); // check=true, forceLiveCalculation=true
|
||||
} else {
|
||||
Log::info("BusinessControllerOptimized: Force live calculation not requested");
|
||||
$TreeCalcBot->initStructureAdmin(); // Standard: verwende gespeicherte wenn verfügbar
|
||||
}
|
||||
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
Log::info("BusinessControllerOptimized: Structure built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
|
|
@ -115,12 +116,11 @@ class BusinessControllerOptimized extends Controller
|
|||
'optimized' => true,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
|
||||
return view('admin.business_optimized.structure', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in structure: " . $e->getMessage());
|
||||
|
||||
|
||||
return view('admin.business_optimized.error', [
|
||||
'error' => $e->getMessage(),
|
||||
'month' => $this->month,
|
||||
|
|
@ -135,7 +135,7 @@ class BusinessControllerOptimized extends Controller
|
|||
public function userDetail($user_id)
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
|
||||
try {
|
||||
$user = User::with(['account', 'user_level', 'user_sponsor.account'])->findOrFail($user_id);
|
||||
$this->setFilterVars();
|
||||
|
|
@ -143,22 +143,22 @@ class BusinessControllerOptimized extends Controller
|
|||
$data = [];
|
||||
$data['month'] = session('business_user_filter_month');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
|
||||
|
||||
Log::info("BusinessControllerOptimized: Building user detail for user {$user_id}");
|
||||
|
||||
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($data['month'], $data['year'], 'admin');
|
||||
|
||||
|
||||
// Prüfe ob Live-Berechnung über URL-Parameter erzwungen wird
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) ||
|
||||
Request::get('force_live', false) ||
|
||||
Request::get('live', false);
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
Log::info("BusinessControllerOptimized: Force live calculation requested for user {$user_id}");
|
||||
}
|
||||
|
||||
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, $forceLiveCalculation);
|
||||
|
||||
|
||||
if (!$TreeCalcBot->__get('business_user')) {
|
||||
Log::warning("BusinessControllerOptimized: No business user found for {$user_id}");
|
||||
abort(403, 'No business user found');
|
||||
|
|
@ -166,23 +166,22 @@ class BusinessControllerOptimized extends Controller
|
|||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
|
||||
$data['performance'] = [
|
||||
'execution_time' => $executionTime,
|
||||
'user_id' => $user_id,
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
];
|
||||
|
||||
|
||||
$data['forceLiveCalculation'] = $forceLiveCalculation;
|
||||
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
Log::info("BusinessControllerOptimized: User detail built in {$executionTime}ms{$calculationType}");
|
||||
|
||||
|
||||
return view('admin.business_optimized.user_detail', compact('TreeCalcBot', 'user', 'data'));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in userDetail for {$user_id}: " . $e->getMessage());
|
||||
|
||||
|
||||
return view('admin.business_optimized.error', [
|
||||
'error' => $e->getMessage(),
|
||||
'user_id' => $user_id
|
||||
|
|
@ -215,10 +214,9 @@ class BusinessControllerOptimized extends Controller
|
|||
} else {
|
||||
return $this->userCurrentlyDatatableOptimized();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessControllerOptimized: Error in userDatatable: " . $e->getMessage());
|
||||
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Datatable could not be loaded: ' . $e->getMessage()
|
||||
], 500);
|
||||
|
|
@ -231,7 +229,7 @@ class BusinessControllerOptimized extends Controller
|
|||
private function userStoredDatatableOptimized(): JsonResponse
|
||||
{
|
||||
$query = $this->initStoredSearchOptimized();
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (UserBusiness $userBusiness) {
|
||||
return TreeHelperOptimized::generateActionButtons($userBusiness->user_id);
|
||||
|
|
@ -308,10 +306,10 @@ class BusinessControllerOptimized extends Controller
|
|||
private function userCurrentlyDatatableOptimized(): JsonResponse
|
||||
{
|
||||
$repository = new BusinessUserRepository($this->month, $this->year);
|
||||
|
||||
|
||||
// Nutze Repository für optimierte Abfragen
|
||||
$query = $this->initCurrentlySearchOptimized();
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $user) {
|
||||
return TreeHelperOptimized::generateActionButtons($user->id);
|
||||
|
|
@ -352,11 +350,11 @@ class BusinessControllerOptimized extends Controller
|
|||
->where('month', $this->month)
|
||||
->where('year', $this->year)
|
||||
->first();
|
||||
|
||||
|
||||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->addColumn('payment_account_date', function (User $user) {
|
||||
|
|
@ -364,28 +362,28 @@ class BusinessControllerOptimized extends Controller
|
|||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.m_account LIKE ?", '%' . $keyword . '%');
|
||||
$query->whereRaw("user_accounts.m_account LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.first_name LIKE ?", '%' . $keyword . '%');
|
||||
$query->whereRaw("user_accounts.first_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.last_name LIKE ?", '%' . $keyword . '%');
|
||||
$query->whereRaw("user_accounts.last_name LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->filterColumn('email', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereRaw("user_businesses.email LIKE ?", '%' . $keyword . '%');
|
||||
$query->whereRaw("users.email LIKE ?", '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->orderColumn('id', 'users.id $1')
|
||||
->orderColumn('m_account', 'user_accounts.m_account $1')
|
||||
->orderColumn('first_name', 'first_name $1')
|
||||
->orderColumn('last_name', 'last_name $1')
|
||||
->orderColumn('first_name', 'user_accounts.first_name $1')
|
||||
->orderColumn('last_name', 'user_accounts.last_name $1')
|
||||
->orderColumn('email', 'users.email $1')
|
||||
->orderColumn('active_account', 'users.payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
|
|
@ -423,26 +421,26 @@ class BusinessControllerOptimized extends Controller
|
|||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
$query->whereNotNull('user_businesses.next_qual_user_level')
|
||||
->where('user_businesses.next_qual_user_level', '!=', '[]');
|
||||
->where('user_businesses.next_qual_user_level', '!=', '[]');
|
||||
break;
|
||||
case 2: // In Arbeit (gelb) - hat next_can_user_level aber kein next_qual_user_level
|
||||
$query->where(function($q) {
|
||||
$query->where(function ($q) {
|
||||
$q->whereNull('user_businesses.next_qual_user_level')
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
})
|
||||
->whereNotNull('user_businesses.next_can_user_level')
|
||||
->where('user_businesses.next_can_user_level', '!=', '[]');
|
||||
->whereNotNull('user_businesses.next_can_user_level')
|
||||
->where('user_businesses.next_can_user_level', '!=', '[]');
|
||||
break;
|
||||
case 3: // Kein Level (rot) - hat weder next_qual noch next_can
|
||||
$query->where(function($q) {
|
||||
$q->where(function($q1) {
|
||||
$query->where(function ($q) {
|
||||
$q->where(function ($q1) {
|
||||
$q1->whereNull('user_businesses.next_qual_user_level')
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
->orWhere('user_businesses.next_qual_user_level', '=', '[]');
|
||||
})
|
||||
->where(function($q2) {
|
||||
$q2->whereNull('user_businesses.next_can_user_level')
|
||||
->orWhere('user_businesses.next_can_user_level', '=', '[]');
|
||||
});
|
||||
->where(function ($q2) {
|
||||
$q2->whereNull('user_businesses.next_can_user_level')
|
||||
->orWhere('user_businesses.next_can_user_level', '=', '[]');
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -563,15 +561,15 @@ class BusinessControllerOptimized extends Controller
|
|||
private function getFilterLevels(): array
|
||||
{
|
||||
$levels = [0 => 'Alle Level'];
|
||||
|
||||
|
||||
$userLevels = \App\Models\UserLevel::orderBy('pos')->get(['id', 'name']);
|
||||
foreach ($userLevels as $level) {
|
||||
$levels[$level->id] = $level->name;
|
||||
}
|
||||
|
||||
|
||||
return $levels;
|
||||
}
|
||||
|
||||
|
||||
// Performance-optimierte Badge-Generierung wurde in NextLevelBadgeHelper ausgelagert
|
||||
// Alte performance-lastige Methoden wurden entfernt um die Datatable-Performance zu verbessern
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/CategoryController.php
Executable file → Normal file
0
app/Http/Controllers/CategoryController.php
Executable file → Normal file
0
app/Http/Controllers/Controller.php
Executable file → Normal file
0
app/Http/Controllers/Controller.php
Executable file → Normal file
0
app/Http/Controllers/CountryController.php
Executable file → Normal file
0
app/Http/Controllers/CountryController.php
Executable file → Normal file
0
app/Http/Controllers/CustomerController.php
Executable file → Normal file
0
app/Http/Controllers/CustomerController.php
Executable file → Normal file
|
|
@ -11,16 +11,19 @@ use Acme\Dhl\Models\DhlShipment;
|
|||
use App\Models\ShoppingOrder;
|
||||
use App\Services\DhlModalService;
|
||||
use App\Services\DhlShipmentService;
|
||||
use App\Services\DhlTrackingService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use ZipArchive;
|
||||
|
||||
// Import new DHL package and SettingController
|
||||
use Acme\Dhl\DhlManager;
|
||||
|
|
@ -141,11 +144,15 @@ class DhlShipmentController extends Controller
|
|||
if ($request->filled('search')) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('dhl_shipment_no', 'LIKE', "%{$search}%")
|
||||
->orWhere('id', 'LIKE', "%{$search}%")
|
||||
->orWhereHas('shoppingOrder', function ($orderQuery) use ($search) {
|
||||
$orderQuery->where('id', $search);
|
||||
});
|
||||
// Search in shipment fields
|
||||
$q->where('order_id', 'LIKE', "%{$search}%")
|
||||
->orWhere('dhl_shipment_no', 'LIKE', "%{$search}%")
|
||||
->orWhere('routing_code', 'LIKE', "%{$search}%")
|
||||
->orWhere('related_shipment_id', 'LIKE', "%{$search}%")
|
||||
->orWhere('billing_number', 'LIKE', "%{$search}%")
|
||||
->orWhere('firstname', 'LIKE', "%{$search}%")
|
||||
->orWhere('lastname', 'LIKE', "%{$search}%")
|
||||
->orWhere('company', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +177,7 @@ class DhlShipmentController extends Controller
|
|||
return '<span class="text-muted">N/A</span>';
|
||||
})
|
||||
->addColumn('customer', function ($shipment) {
|
||||
if ($shipment->shoppingOrder && $shipment->shoppingOrder->shopping_user) {
|
||||
return e($shipment->shoppingOrder->shopping_user->billing_firstname) . ' ' . e($shipment->shoppingOrder->shopping_user->billing_lastname) .
|
||||
'<br><small class="text-muted">' . e($shipment->shoppingOrder->shopping_user->billing_email) . '</small>';
|
||||
}
|
||||
return '<span class="text-muted">Unbekannt</span>';
|
||||
return $shipment->firstname . ' ' . $shipment->lastname;
|
||||
})
|
||||
->editColumn('dhl_shipment_no', function ($shipment) {
|
||||
return $shipment->dhl_shipment_no ? '<code class="text-success">' . e($shipment->dhl_shipment_no) . '</code>' : '<span class="text-muted">-</span>';
|
||||
|
|
@ -210,12 +213,14 @@ class DhlShipmentController extends Controller
|
|||
if ($shipment->label_path) {
|
||||
$buttons .= '<a href="' . route('admin.dhl.download-label', $shipment) . '" class="btn btn-sm btn-outline-success" data-toggle="tooltip" title="Label herunterladen"><i class="fas fa-download"></i></a>';
|
||||
}
|
||||
/* Todo: Add tracking button
|
||||
if ($shipment->canCancel()) {
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-warning cancel-shipment-btn" data-shipment-id="' . $shipment->id . '" data-toggle="tooltip" title="Sendung stornieren"><i class="fas fa-ban"></i></button>';
|
||||
}
|
||||
if ($shipment->type == 'outbound' && !$shipment->returns()->count()) {
|
||||
$buttons .= '<button type="button" class="btn btn-sm btn-outline-info create-return-btn" data-shipment-id="' . $shipment->id . '" data-toggle="tooltip" title="Retourenlabel erstellen"><i class="fas fa-undo"></i></button>';
|
||||
}
|
||||
*/
|
||||
$buttons .= '</div>';
|
||||
return $buttons;
|
||||
})
|
||||
|
|
@ -465,27 +470,27 @@ class DhlShipmentController extends Controller
|
|||
public function updateTracking(DhlShipment $shipment): JsonResponse
|
||||
{
|
||||
try {
|
||||
if (!$shipment->tracking_number) {
|
||||
if (!$shipment->dhl_shipment_no) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Keine Tracking-Nummer verfügbar.'
|
||||
'message' => 'Keine DHL-Sendungsnummer verfügbar.'
|
||||
], 422);
|
||||
}
|
||||
|
||||
// Dispatch tracking update job
|
||||
TrackShipmentJob::dispatch($shipment, ['auto_retrack' => false]);
|
||||
// Use DhlTrackingService (handles queue/sync automatically based on config)
|
||||
$dhlTrackingService = new DhlTrackingService();
|
||||
$result = $dhlTrackingService->updateTracking($shipment, ['auto_retrack' => false]);
|
||||
|
||||
Log::info('[DHL Controller] Tracking update job dispatched', [
|
||||
Log::info('[DHL Controller] Tracking update processed', [
|
||||
'shipment_id' => $shipment->id,
|
||||
'tracking_number' => $shipment->tracking_number,
|
||||
'dhl_shipment_no' => $shipment->dhl_shipment_no,
|
||||
'queued' => $result['queued'] ?? false,
|
||||
'success' => $result['success'] ?? false,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tracking-Informationen werden aktualisiert...'
|
||||
]);
|
||||
return response()->json($result);
|
||||
} catch (Exception $e) {
|
||||
Log::error('[DHL Controller] Failed to dispatch tracking update', [
|
||||
Log::error('[DHL Controller] Failed to process tracking update', [
|
||||
'error' => $e->getMessage(),
|
||||
'shipment_id' => $shipment->id,
|
||||
]);
|
||||
|
|
@ -511,11 +516,9 @@ class DhlShipmentController extends Controller
|
|||
}
|
||||
|
||||
$labelContent = Storage::get($shipment->label_path);
|
||||
$filename = sprintf(
|
||||
'dhl-label-%s-%s.pdf',
|
||||
$shipment->type,
|
||||
$shipment->shipment_number ?: $shipment->id
|
||||
);
|
||||
|
||||
// Generate descriptive filename
|
||||
$filename = $this->generateLabelFilename($shipment);
|
||||
|
||||
return response($labelContent, 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
|
|
@ -531,13 +534,63 @@ class DhlShipmentController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate descriptive filename for DHL label
|
||||
* Format: DHL-Kundenname-Sendungsnummer-Datum.pdf
|
||||
* Example: DHL-Geraldine-Seebacher-0034043333301020015589177-15092025.pdf
|
||||
*
|
||||
* @param DhlShipment $shipment
|
||||
* @return string
|
||||
*/
|
||||
private function generateLabelFilename(DhlShipment $shipment): string
|
||||
{
|
||||
// Load order with customer data
|
||||
$customerName = $shipment->firstname . '_' . $shipment->lastname;
|
||||
if ($shipment->company) {
|
||||
$customerName = $shipment->company;
|
||||
}
|
||||
|
||||
// Clean customer name for filename (remove special characters)
|
||||
$customerName = preg_replace('/[^a-zA-Z0-9\-]/', '', $customerName);
|
||||
$customerName = preg_replace('/-+/', '-', $customerName); // Remove multiple dashes
|
||||
$customerName = trim($customerName, '-'); // Remove leading/trailing dashes
|
||||
|
||||
// Get shipment number
|
||||
$shipmentNumber = $shipment->dhl_shipment_no ?: $shipment->id;
|
||||
|
||||
// Get creation date
|
||||
$date = $shipment->created_at->format('d_m_Y');
|
||||
|
||||
// Build filename
|
||||
$filename = sprintf(
|
||||
'DHL-%s-%s-%s.pdf',
|
||||
$customerName,
|
||||
$shipmentNumber,
|
||||
$date
|
||||
);
|
||||
|
||||
// Ensure filename is not too long (max 255 characters)
|
||||
if (strlen($filename) > 255) {
|
||||
$maxCustomerLength = 255 - strlen('DHL--' . $shipmentNumber . '-' . $date . '.pdf');
|
||||
$customerName = substr($customerName, 0, max(10, $maxCustomerLength));
|
||||
$filename = sprintf(
|
||||
'DHL-%s-%s-%s.pdf',
|
||||
$customerName,
|
||||
$shipmentNumber,
|
||||
$date
|
||||
);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch operations (multiple shipments)
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @return JsonResponse|BinaryFileResponse
|
||||
*/
|
||||
public function batchAction(Request $request): JsonResponse
|
||||
public function batchAction(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
|
|
@ -550,6 +603,7 @@ class DhlShipmentController extends Controller
|
|||
$action = $request->action;
|
||||
$processed = 0;
|
||||
$errors = [];
|
||||
$labels = []; // For batch label download
|
||||
|
||||
foreach ($shipmentIds as $shipmentId) {
|
||||
try {
|
||||
|
|
@ -566,17 +620,31 @@ class DhlShipmentController extends Controller
|
|||
break;
|
||||
|
||||
case 'update_tracking':
|
||||
if ($shipment->tracking_number) {
|
||||
TrackShipmentJob::dispatch($shipment, ['auto_retrack' => false]);
|
||||
$processed++;
|
||||
if ($shipment->dhl_shipment_no) {
|
||||
$dhlTrackingService = new DhlTrackingService();
|
||||
$trackingResult = $dhlTrackingService->updateTracking($shipment, ['auto_retrack' => false]);
|
||||
|
||||
if ($trackingResult['success']) {
|
||||
$processed++;
|
||||
} else {
|
||||
$errors[] = "Sendung #{$shipment->id}: " . $trackingResult['message'];
|
||||
}
|
||||
} else {
|
||||
$errors[] = "Sendung {$shipment->shipment_number} hat keine Tracking-Nummer.";
|
||||
$errors[] = "Sendung #{$shipment->id} hat keine DHL-Sendungsnummer.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'download_labels':
|
||||
// This would require ZIP creation - implement if needed
|
||||
$errors[] = "Stapel-Download noch nicht implementiert.";
|
||||
if ($shipment->label_path && Storage::exists($shipment->label_path)) {
|
||||
$labels[] = [
|
||||
'shipment' => $shipment,
|
||||
'filename' => $this->generateLabelFilename($shipment),
|
||||
'path' => $shipment->label_path
|
||||
];
|
||||
$processed++;
|
||||
} else {
|
||||
$errors[] = "Sendung #{$shipment->id} hat kein verfügbares Label.";
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -584,6 +652,11 @@ class DhlShipmentController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
// Handle batch label download
|
||||
if ($action === 'download_labels' && !empty($labels)) {
|
||||
return $this->createLabelsZip($labels);
|
||||
}
|
||||
|
||||
Log::info('[DHL Controller] Batch action executed', [
|
||||
'action' => $action,
|
||||
'processed' => $processed,
|
||||
|
|
@ -623,7 +696,7 @@ class DhlShipmentController extends Controller
|
|||
]);
|
||||
|
||||
try {
|
||||
$shipment = DhlShipment::where('tracking_number', $request->tracking_number)->first();
|
||||
$shipment = DhlShipment::where('dhl_shipment_no', $request->tracking_number)->first();
|
||||
|
||||
if (!$shipment) {
|
||||
return response()->json([
|
||||
|
|
@ -632,13 +705,15 @@ class DhlShipmentController extends Controller
|
|||
], 404);
|
||||
}
|
||||
|
||||
// Dispatch tracking update
|
||||
TrackShipmentJob::dispatch($shipment, ['auto_retrack' => false]);
|
||||
// Use DhlTrackingService for tracking update
|
||||
$dhlTrackingService = new DhlTrackingService();
|
||||
$trackingResult = $dhlTrackingService->updateTracking($shipment, ['auto_retrack' => false]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'success' => $trackingResult['success'],
|
||||
'message' => $trackingResult['message'],
|
||||
'data' => [
|
||||
'tracking_number' => $shipment->tracking_number,
|
||||
'dhl_shipment_no' => $shipment->dhl_shipment_no,
|
||||
'status' => $shipment->status,
|
||||
'tracking_status' => $shipment->tracking_status,
|
||||
'last_tracked_at' => $shipment->last_tracked_at?->format('d.m.Y H:i'),
|
||||
|
|
@ -659,4 +734,65 @@ class DhlShipmentController extends Controller
|
|||
|
||||
return view('public.tracking');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create ZIP file with multiple labels
|
||||
*
|
||||
* @param array $labels Array of label data
|
||||
* @return Response|BinaryFileResponse
|
||||
*/
|
||||
private function createLabelsZip(array $labels)
|
||||
{
|
||||
try {
|
||||
$zip = new ZipArchive();
|
||||
$zipFilename = 'dhl_labels_' . date('Y-m-d_H-i-s') . '.zip';
|
||||
$zipPath = storage_path('app/temp/' . $zipFilename);
|
||||
|
||||
// Ensure temp directory exists
|
||||
if (!file_exists(storage_path('app/temp'))) {
|
||||
mkdir(storage_path('app/temp'), 0755, true);
|
||||
}
|
||||
|
||||
if ($zip->open($zipPath, ZipArchive::CREATE) !== TRUE) {
|
||||
throw new Exception('ZIP-Datei konnte nicht erstellt werden.');
|
||||
}
|
||||
|
||||
$addedFiles = 0;
|
||||
foreach ($labels as $labelData) {
|
||||
$shipment = $labelData['shipment'];
|
||||
$filename = $labelData['filename'];
|
||||
$filePath = $labelData['path'];
|
||||
|
||||
if (Storage::exists($filePath)) {
|
||||
$content = Storage::get($filePath);
|
||||
$zip->addFromString($filename, $content);
|
||||
$addedFiles++;
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
if ($addedFiles === 0) {
|
||||
throw new Exception('Keine Labels konnten zur ZIP-Datei hinzugefügt werden.');
|
||||
}
|
||||
|
||||
Log::info('[DHL Controller] Labels ZIP created', [
|
||||
'zip_file' => $zipFilename,
|
||||
'files_count' => $addedFiles,
|
||||
'total_labels' => count($labels)
|
||||
]);
|
||||
|
||||
return response()->download($zipPath, $zipFilename)->deleteFileAfterSend(true);
|
||||
} catch (Exception $e) {
|
||||
Log::error('[DHL Controller] Failed to create labels ZIP', [
|
||||
'error' => $e->getMessage(),
|
||||
'labels_count' => count($labels)
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Fehler beim Erstellen der ZIP-Datei: ' . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,33 +15,34 @@ class FileController extends Controller
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct() {}
|
||||
|
||||
private function isPermissionShoppingOrder($shopping_order)
|
||||
{
|
||||
}
|
||||
|
||||
private function isPermissionShoppingOrder($shopping_order){
|
||||
$user_id = $shopping_order->auth_user_id ? $shopping_order->auth_user_id : $shopping_order->member_id;
|
||||
if(Auth::user()->isAdmin() || $user_id == Auth::user()->id){
|
||||
if (Auth::user()->isAdmin() || $user_id == Auth::user()->id) {
|
||||
return true;
|
||||
}
|
||||
abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function isPermissionUserCredit($user_credit){
|
||||
if(Auth::user()->isAdmin() || $user_credit->user_id == Auth::user()->id){
|
||||
private function isPermissionUserCredit($user_credit)
|
||||
{
|
||||
if (Auth::user()->isAdmin() || $user_credit->user_id == Auth::user()->id) {
|
||||
return true;
|
||||
}
|
||||
abort(404);
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function isPermissionAuth(){
|
||||
if(Auth::check()){
|
||||
private function isPermissionAuth()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return true;
|
||||
}
|
||||
abort(404);
|
||||
abort(403, "Nicht autorisiert");
|
||||
}
|
||||
|
||||
public function show($id = null, $from = null, $do='file')
|
||||
public function show($id = null, $from = null, $do = 'file')
|
||||
{
|
||||
|
||||
$path = "";
|
||||
|
|
@ -56,69 +57,68 @@ class FileController extends Controller
|
|||
return Response::file($path);
|
||||
}
|
||||
}*/
|
||||
if ($from === 'invoice'){
|
||||
if ($from === 'invoice') {
|
||||
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->user_invoice){
|
||||
if ($shopping_order->user_invoice) {
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPath();
|
||||
$filename = $user_invoice->filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($from === 'delivery'){
|
||||
if ($from === 'delivery') {
|
||||
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->user_invoice){
|
||||
if ($shopping_order->user_invoice) {
|
||||
$this->isPermissionShoppingOrder($shopping_order);
|
||||
$user_invoice = $shopping_order->user_invoice;
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$filename = $user_invoice->delivery_filename;
|
||||
$disk = $user_invoice->disk;
|
||||
$path = $user_invoice->getDownloadPathDelivery();
|
||||
}
|
||||
}
|
||||
|
||||
if ($from === 'credit'){
|
||||
if ($from === 'credit') {
|
||||
$user_credit = \App\Models\UserCredit::findOrFail($id);
|
||||
$this->isPermissionUserCredit($user_credit);
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
}
|
||||
|
||||
if ($from === 'credit_detail'){
|
||||
if ($from === 'credit_detail') {
|
||||
$user_credit = \App\Models\UserCredit::findOrFail($id);
|
||||
$this->isPermissionUserCredit($user_credit);
|
||||
|
||||
|
||||
return $this->create_credit_detail($user_credit, $do);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
$filename = $user_credit->filename;
|
||||
$disk = $user_credit->disk;
|
||||
$path = $user_credit->getDownloadPath();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
if ($from === 'dc_file'){
|
||||
$this->isPermissionAuth();
|
||||
|
||||
if ($from === 'dc_file') {
|
||||
// $this->isPermissionAuth();
|
||||
$dc_file = \App\Models\DcFile::findOrFail($id);
|
||||
$filename = $dc_file->filename;
|
||||
$disk = 'public';
|
||||
$path = $dc_file->getFile();
|
||||
}
|
||||
if ($from === 'dc_thumb'){
|
||||
$this->isPermissionAuth();
|
||||
if ($from === 'dc_thumb') {
|
||||
// $this->isPermissionAuth();
|
||||
$dc_file = \App\Models\DcFile::findOrFail($id);
|
||||
$filename = $dc_file->filename;
|
||||
$disk = 'public';
|
||||
$path = $dc_file->getThumb();
|
||||
}
|
||||
|
||||
if ($from === 'dc_big'){
|
||||
$this->isPermissionAuth();
|
||||
if ($from === 'dc_big') {
|
||||
// $this->isPermissionAuth();
|
||||
$dc_file = \App\Models\DcFile::findOrFail($id);
|
||||
$filename = $dc_file->filename;
|
||||
$disk = 'public';
|
||||
|
|
@ -127,7 +127,7 @@ class FileController extends Controller
|
|||
|
||||
|
||||
|
||||
if(!Storage::disk($disk)->exists($path)){
|
||||
if (!Storage::disk($disk)->exists($path)) {
|
||||
return Response::make('Datei nicht gefunden.', 404);
|
||||
}
|
||||
|
||||
|
|
@ -138,40 +138,41 @@ class FileController extends Controller
|
|||
$file = Storage::disk($disk)->get($path);
|
||||
$mime = Storage::disk($disk)->mimeType($path);
|
||||
|
||||
if(isset($file)){
|
||||
if($do === 'stream'){
|
||||
if (isset($file)) {
|
||||
if ($do === 'stream') {
|
||||
return Storage::disk($disk)->response($path, $filename);
|
||||
}
|
||||
|
||||
if($do === 'file'){
|
||||
if ($do === 'file') {
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
->header("Content-Length", strlen($file))
|
||||
->header('Content-disposition', 'filename="'.$filename.'"');
|
||||
->header('Content-disposition', 'filename="' . $filename . '"');
|
||||
}
|
||||
if($do === 'image'){
|
||||
if ($do === 'image') {
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime);
|
||||
}
|
||||
if($do === 'pdf'){
|
||||
$path = storage_path().'/app/public/' . $path;
|
||||
if ($do === 'pdf') {
|
||||
$path = storage_path() . '/app/public/' . $path;
|
||||
|
||||
$headers = array(
|
||||
'Content-Type:'. $mime,
|
||||
// 'Content-Length: ' . $file->size
|
||||
// 'Content-Disposition: ' . $stream . '; filename=' . $file->original_name
|
||||
);
|
||||
|
||||
return Response::download($path, $filename, $headers);
|
||||
'Content-Type:' . $mime,
|
||||
// 'Content-Length: ' . $file->size
|
||||
// 'Content-Disposition: ' . $stream . '; filename=' . $file->original_name
|
||||
);
|
||||
|
||||
return Response::download($path, $filename, $headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function create_credit_detail(UserCredit $user_credit, $do){
|
||||
private function create_credit_detail(UserCredit $user_credit, $do)
|
||||
{
|
||||
|
||||
$credit_repo = new CreditRepository($user_credit->user);
|
||||
return $credit_repo->create_report($user_credit, $do);
|
||||
//\Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
|
||||
$credit_repo = new CreditRepository($user_credit->user);
|
||||
return $credit_repo->create_report($user_credit, $do);
|
||||
//\Session()->flash('alert-success', "Gutschrift erstellt");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
117
app/Http/Controllers/HomeController.php
Executable file → Normal file
117
app/Http/Controllers/HomeController.php
Executable file → Normal file
|
|
@ -4,7 +4,7 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Request;
|
||||
|
|
@ -17,26 +17,23 @@ class HomeController extends Controller
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(!Auth::check()){
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
return redirect('home');
|
||||
|
||||
}
|
||||
|
||||
//login / Dashboard
|
||||
public function show()
|
||||
{
|
||||
|
||||
if(!Auth::check()){
|
||||
return redirect('login');
|
||||
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
@ -47,12 +44,13 @@ class HomeController extends Controller
|
|||
}
|
||||
|
||||
|
||||
public function loadingModal(){
|
||||
public function loadingModal()
|
||||
{
|
||||
|
||||
$data = Request::get('data');
|
||||
$target = Request::get('target');
|
||||
$response = "";
|
||||
if($data === "data_protection"){
|
||||
if ($data === "data_protection") {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => true,
|
||||
|
|
@ -60,34 +58,34 @@ class HomeController extends Controller
|
|||
];
|
||||
$response = view('legal.data_protect_de', $data)->render();
|
||||
}
|
||||
if($data === "imprint"){
|
||||
if ($data === "imprint") {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.imprint_de', $data)->render();
|
||||
}
|
||||
if($data === "shop_term_of_use"){
|
||||
if ($data === "shop_term_of_use") {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.shop_term_of_use_de', $data)->render();
|
||||
}
|
||||
if($data === "agb"){
|
||||
if ($data === "agb") {
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.agb_de', $data)->render();
|
||||
}
|
||||
if(Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target'=>$target]);
|
||||
if (Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target' => $target]);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
/* public function checkLogin($identify, $token)
|
||||
/* public function checkLogin($identify, $token)
|
||||
{
|
||||
if($identify){
|
||||
//user find by $identify
|
||||
|
|
@ -129,7 +127,8 @@ class HomeController extends Controller
|
|||
return abort(404);
|
||||
}
|
||||
*/
|
||||
public function zahlungsarten(){
|
||||
public function zahlungsarten()
|
||||
{
|
||||
return view('web.templates.zahlungsarten', [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
|
|
@ -137,7 +136,8 @@ class HomeController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function versandkosten(){
|
||||
public function versandkosten()
|
||||
{
|
||||
return view('web.templates.versandkosten', [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'isMivitaShop' => Util::isMivitaShop(),
|
||||
|
|
@ -170,7 +170,7 @@ class HomeController extends Controller
|
|||
|
||||
public function legalImprint()
|
||||
{
|
||||
|
||||
|
||||
$data = [
|
||||
'modal' => false,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
|
|
@ -179,44 +179,51 @@ class HomeController extends Controller
|
|||
return view('legal.imprint', $data);
|
||||
}
|
||||
|
||||
public function verify($confirmation_code){
|
||||
if( ! $confirmation_code)
|
||||
{
|
||||
public function verify($confirmation_code)
|
||||
{
|
||||
if (! $confirmation_code) {
|
||||
return redirect('/status/error');
|
||||
}
|
||||
|
||||
$user = User::whereConfirmationCode($confirmation_code)->first();
|
||||
|
||||
if ( ! $user)
|
||||
{
|
||||
return redirect('/status/not/found');
|
||||
if (! $user) {
|
||||
return redirect('/status/not/found');
|
||||
}
|
||||
if($user->confirmed === 0){
|
||||
$user_auto_login = false;
|
||||
if ($user->confirmed === 0) {
|
||||
$user->confirmed = 1;
|
||||
$user->confirmation_date = now();
|
||||
$user_auto_login = true;
|
||||
//nur bei der ersten Verifizierung den user auto login
|
||||
}
|
||||
|
||||
// $user->confirmation_code = null;
|
||||
// $user->confirmation_code_to = null;
|
||||
// $user->confirmation_code_remider = 0;
|
||||
//wird nun in WizardController::releaseAccount() auf null gesetzt
|
||||
//$user->confirmation_code = null;
|
||||
//$user->confirmation_code_to = null;
|
||||
//$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
|
||||
//Login!
|
||||
Auth::login($user);
|
||||
|
||||
return redirect('/home');
|
||||
if ($user_auto_login) {
|
||||
Auth::login($user);
|
||||
}
|
||||
$url = Util::getMyMivitaUrl();
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
public function statusRegister(){
|
||||
public function statusRegister()
|
||||
{
|
||||
return view('status.status_register');
|
||||
}
|
||||
public function statusVerify(){
|
||||
public function statusVerify()
|
||||
{
|
||||
return view('status.status_verify');
|
||||
}
|
||||
public function statusError(){
|
||||
public function statusError()
|
||||
{
|
||||
return view('status.status_error');
|
||||
}
|
||||
public function notFound(){
|
||||
public function notFound()
|
||||
{
|
||||
return view('status.not_found');
|
||||
}
|
||||
|
||||
|
|
@ -224,15 +231,16 @@ class HomeController extends Controller
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function checkMail(){
|
||||
public function checkMail()
|
||||
{
|
||||
|
||||
$data = Request::all();
|
||||
if($data['user_id'] === "new"){
|
||||
if(User::where('email', $data['email'])->count()){
|
||||
if ($data['user_id'] === "new") {
|
||||
if (User::where('email', $data['email'])->count()) {
|
||||
return json_encode(false);
|
||||
}
|
||||
}else{
|
||||
if(User::where('email', $data['email'])->where('id', '!=', $data['user_id'])->count()){
|
||||
} else {
|
||||
if (User::where('email', $data['email'])->where('id', '!=', $data['user_id'])->count()) {
|
||||
return json_encode(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -244,24 +252,23 @@ class HomeController extends Controller
|
|||
return view('status.user_blocked');
|
||||
}
|
||||
|
||||
public function backToShop($reference = ""){
|
||||
public function backToShop($reference = "")
|
||||
{
|
||||
|
||||
if($reference){
|
||||
if ($reference) {
|
||||
$ShoppingPayment = ShoppingPayment::where('reference', $reference)->first();
|
||||
if($ShoppingPayment && $ShoppingPayment->status === 'success'){
|
||||
if ($ShoppingPayment && $ShoppingPayment->status === 'success') {
|
||||
$user = Auth::user();
|
||||
//is form wizard create payment
|
||||
if($user && ($user->wizard == 13 || $user->wizard == 20)){
|
||||
$user->wizard = 15; //realese Payments
|
||||
$user->save();
|
||||
return redirect(route('wizard_create', [15]));
|
||||
if ($user && ($user->wizard == 13 || $user->wizard == 20)) {
|
||||
$user->wizard = 15; //realese Payments
|
||||
$user->save();
|
||||
return redirect(route('wizard_create', [15]));
|
||||
}
|
||||
|
||||
}else{
|
||||
} else {
|
||||
\Session()->flash('alert-error', __('msg.error_occurred_with_order'));
|
||||
return redirect(route('/'));
|
||||
return redirect(url('/'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/ImportProductController.php
Executable file → Normal file
0
app/Http/Controllers/ImportProductController.php
Executable file → Normal file
0
app/Http/Controllers/IngredientController.php
Executable file → Normal file
0
app/Http/Controllers/IngredientController.php
Executable file → Normal file
0
app/Http/Controllers/LeadController.php
Executable file → Normal file
0
app/Http/Controllers/LeadController.php
Executable file → Normal file
88
app/Http/Controllers/LevelReportsController.php
Normal file
88
app/Http/Controllers/LevelReportsController.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\LevelReportService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class LevelReportsController extends Controller
|
||||
{
|
||||
private $levelReportService;
|
||||
|
||||
public function __construct(LevelReportService $levelReportService)
|
||||
{
|
||||
$this->levelReportService = $levelReportService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeige Level-Aufstieg Reports
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Filter aus Request extrahieren
|
||||
$filters = [
|
||||
'month' => $request->get('month'),
|
||||
'year' => $request->get('year'),
|
||||
'user_id' => $request->get('user_id'),
|
||||
'only_not_updated' => $request->boolean('not_updated')
|
||||
];
|
||||
|
||||
// Lade Level-Aufstiege
|
||||
$promotions = $this->levelReportService->getLevelPromotions($filters);
|
||||
$statistics = $this->levelReportService->getStatistics($promotions);
|
||||
|
||||
// Verfügbare Jahre für Filter
|
||||
$availableYears = range(date('Y'), date('Y') - 5);
|
||||
$availableMonths = [
|
||||
1 => 'Januar',
|
||||
2 => 'Februar',
|
||||
3 => 'März',
|
||||
4 => 'April',
|
||||
5 => 'Mai',
|
||||
6 => 'Juni',
|
||||
7 => 'Juli',
|
||||
8 => 'August',
|
||||
9 => 'September',
|
||||
10 => 'Oktober',
|
||||
11 => 'November',
|
||||
12 => 'Dezember'
|
||||
];
|
||||
|
||||
return view('admin.level-reports.index', compact(
|
||||
'promotions',
|
||||
'statistics',
|
||||
'filters',
|
||||
'availableYears',
|
||||
'availableMonths'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* CSV Export
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
// Filter aus Request extrahieren
|
||||
$filters = [
|
||||
'month' => $request->get('month'),
|
||||
'year' => $request->get('year'),
|
||||
'user_id' => $request->get('user_id'),
|
||||
'only_not_updated' => $request->boolean('not_updated')
|
||||
];
|
||||
|
||||
// Lade Level-Aufstiege
|
||||
$promotions = $this->levelReportService->getLevelPromotions($filters);
|
||||
|
||||
if ($promotions->isEmpty()) {
|
||||
return redirect()->back()->with('error', 'Keine Daten für Export gefunden.');
|
||||
}
|
||||
|
||||
// Erstelle CSV
|
||||
$filename = 'level_promotions_' . date('Y-m-d_H-i-s') . '.csv';
|
||||
$filepath = $this->levelReportService->exportToCsv($promotions, $filename);
|
||||
|
||||
// Download CSV
|
||||
return response()->download($filepath, $filename)->deleteFileAfterSend(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -27,100 +27,101 @@ class ModalController extends Controller
|
|||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function load(){
|
||||
public function load()
|
||||
{
|
||||
$data = Request::all();
|
||||
$ret = "";
|
||||
$status = false;
|
||||
if(Request::ajax()){
|
||||
if($data['action'] === 'shopping-order-change-member'){
|
||||
if (Request::ajax()) {
|
||||
if ($data['action'] === 'shopping-order-change-member') {
|
||||
$value = ShoppingOrder::find($data['id']);
|
||||
$route = route('admin_sales_customers_detail', [$value->id]);
|
||||
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'shopping-user-change-member'){
|
||||
if ($data['action'] === 'shopping-user-change-member') {
|
||||
$value = ShoppingUser::find($data['id']);
|
||||
$route = route('admin_customer_edit', [$value->id]);
|
||||
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'shopping-user-is-like-member'){
|
||||
if ($data['action'] === 'shopping-user-is-like-member') {
|
||||
$current = ShoppingUser::find($data['id']); //current user form order
|
||||
$possibles = [];
|
||||
if($current->is_like){
|
||||
if ($current->is_like) {
|
||||
$likes = $current->getNotice('like');
|
||||
foreach ($likes as $like_id=>$number){
|
||||
foreach ($likes as $like_id => $number) {
|
||||
$possibles[] = ShoppingUser::find($like_id);
|
||||
}
|
||||
}
|
||||
$ret = view("admin.modal.is_like_member", compact('current', 'possibles', 'data'))->render();
|
||||
}
|
||||
if($data['action'] === 'shopping-order-change-points'){
|
||||
if ($data['action'] === 'shopping-order-change-points') {
|
||||
$value = ShoppingOrder::find($data['id']);
|
||||
$route = route('admin_sales_customers_detail', [$value->id]);
|
||||
$ret = view("admin.modal.change_points", compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'user-order-show-product'){
|
||||
if ($data['action'] === 'user-order-show-product') {
|
||||
$product = Product::find($data['id']); //current user form order
|
||||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user-order-show-product'){
|
||||
if ($data['action'] === 'user-order-show-product') {
|
||||
$product = Product::find($data['id']); //current user form order
|
||||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'shop-user-order-detail'){
|
||||
$user = \Auth::user();
|
||||
if ($data['action'] === 'shop-user-order-detail') {
|
||||
$user = \Auth::user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if(!$user->isAdmin() && $shopping_order->member_id !== $user->id){
|
||||
if (!$user->isAdmin() && $shopping_order->member_id !== $user->id) {
|
||||
abort(404);
|
||||
}
|
||||
$isAdmin = false ;
|
||||
$isAdmin = false;
|
||||
$ret = view("user.shop.sales.modal_api_order_detail", compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'shop-user-order-shipping-detail'){
|
||||
$user = \Auth::user();
|
||||
if ($data['action'] === 'shop-user-order-shipping-detail') {
|
||||
$user = \Auth::user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if(!$user->isAdmin() && $shopping_order->auth_user_id !== $user->id){
|
||||
if (!$user->isAdmin() && $shopping_order->auth_user_id !== $user->id) {
|
||||
abort(404);
|
||||
}
|
||||
$isAdmin = false ;
|
||||
$isAdmin = false;
|
||||
$ret = view("user.shop.sales.modal_api_order_shipping_detail", compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user-order-my-delivery-show'){
|
||||
if ($data['action'] === 'user-order-my-delivery-show') {
|
||||
$user = \Auth::user();
|
||||
$ret = view("admin.modal.show_user_customers", compact('user', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user-order-my-delivery-add'){
|
||||
|
||||
if ($data['action'] === 'user-order-my-delivery-add') {
|
||||
$user = \Auth::user();
|
||||
/* $product = Product::find($data['id']); //current user form order
|
||||
/* $product = Product::find($data['id']); //current user form order
|
||||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render(); */
|
||||
}
|
||||
if($data['action'] === 'homeparty-add-product') {
|
||||
if ($data['action'] === 'homeparty-add-product') {
|
||||
$homeparty = Homeparty::find($data['id']);
|
||||
$homeparty_user = HomepartyUser::find($data['user_id']);
|
||||
$data['homeparty'] = $homeparty;
|
||||
$ret = view("user.homeparty.modal_hp_show_products", compact( 'data', 'homeparty', 'homeparty_user'))->render();
|
||||
$ret = view("user.homeparty.modal_hp_show_products", compact('data', 'homeparty', 'homeparty_user'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user-level-edit'){
|
||||
if ($data['action'] === 'user-level-edit') {
|
||||
$value = UserLevel::find($data['id']);
|
||||
$route = route('admin_level_store', [$value->id]);
|
||||
$ret = view("admin.modal.user_level_edit", compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'user-level-add'){
|
||||
if ($data['action'] === 'user-level-add') {
|
||||
$value = new UserLevel();
|
||||
$route = route('admin_level_store', ['new']);
|
||||
$ret = view("admin.modal.user_level_edit", compact('value', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'business-user-detail'){
|
||||
if ($data['action'] === 'business-user-detail') {
|
||||
$user = User::findOrFail($data['id']);
|
||||
if($data['init_from'] === 'admin'){
|
||||
if ($data['init_from'] === 'admin') {
|
||||
$data['month'] = session('business_user_filter_month');
|
||||
$data['year'] = session('business_user_filter_year');
|
||||
}else{
|
||||
} else {
|
||||
$data['month'] = session('team_user_filter_month');
|
||||
$data['year'] = session('team_user_filter_year');
|
||||
}
|
||||
|
|
@ -131,74 +132,72 @@ class ModalController extends Controller
|
|||
$ret = view("admin.modal.business_user_detail", compact('TreeCalcBot', 'user', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'business-user-show'){
|
||||
if ($data['action'] === 'business-user-show') {
|
||||
$user = User::find($data['id']);
|
||||
if($user && $user->account){
|
||||
if ($user && $user->account) {
|
||||
$route = "";
|
||||
$ret = view("admin.modal.business_user_show", compact('user', 'data'))->render();
|
||||
}
|
||||
$ret = view("admin.modal.business_user_notfound", compact('data'))->render();
|
||||
|
||||
}
|
||||
if($data['action'] === 'edit_user_sales_volume'){
|
||||
if ($data['action'] === 'edit_user_sales_volume') {
|
||||
$userSalesVolume = UserSalesVolume::findOrFail($data['id']);
|
||||
$route = route('admin_business_points_store', );
|
||||
$route = route('admin_business_points_store',);
|
||||
$ret = view("admin.business.modal_edit_points", compact('userSalesVolume', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'add_user_sales_volume'){
|
||||
if ($data['action'] === 'add_user_sales_volume') {
|
||||
$userSalesVolume = new UserSalesVolume();
|
||||
$route = route('admin_business_points_store', );
|
||||
$route = route('admin_business_points_store',);
|
||||
$ret = view("admin.business.modal_add_points", compact('userSalesVolume', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'add-user-credit'){
|
||||
}
|
||||
if ($data['action'] === 'add-user-credit') {
|
||||
$value = [];
|
||||
$ret = view("admin.payment.modal_add_credit", compact('value', 'data'))->render();
|
||||
}
|
||||
if($data['action'] === 'user-credit-status'){
|
||||
}
|
||||
if ($data['action'] === 'user-credit-status') {
|
||||
$UserCredit = UserCredit::find($data['id']); //current user form order
|
||||
$ret = view("admin.payment.modal_credit_status", compact('UserCredit', 'data'))->render();
|
||||
}
|
||||
if($data['action'] === 'abo_update_settings'){
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
if($data['view'] === 'admin'){
|
||||
if ($data['view'] === 'admin') {
|
||||
$route = route('admin_abos_update', [$user_abo->id]);
|
||||
}else{
|
||||
} else {
|
||||
$route = route('user_abos_update', [$data['view'], $user_abo->id]);
|
||||
}
|
||||
$ret = view("admin.abo.modal_abo_update", compact('user_abo', 'data', 'route'))->render();
|
||||
}
|
||||
if($data['action'] === 'abo-add-product') {
|
||||
if ($data['action'] === 'abo-add-product') {
|
||||
$user_abo = UserAbo::find($data['id']);
|
||||
$ret = view("user.abo.modal_abo_show_products", compact( 'data', 'user_abo'))->render();
|
||||
$ret = view("user.abo.modal_abo_show_products", compact('data', 'user_abo'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'create-dhl-shipment') {
|
||||
|
||||
if ($data['action'] === 'create-dhl-shipment') {
|
||||
$id = $data['id'] ?? null;
|
||||
$ret = $this->handleDhlShipmentModal($id, $data);
|
||||
}
|
||||
|
||||
}
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
return response()->json(['response' => $data, 'html' => $ret, 'status' => $status]);
|
||||
}
|
||||
|
||||
private function getForBusinessUserDetail(User $user, $data){
|
||||
private function getForBusinessUserDetail(User $user, $data)
|
||||
{
|
||||
|
||||
//$auth_user = \Auth::user();
|
||||
//if($auth_user->isAdmin() || $auth_user->id === $user->id){
|
||||
if($data['optimized']){
|
||||
if ($data['optimized']) {
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($data['month'], $data['year'], $data['init_from'], $data['live']);
|
||||
}else{
|
||||
} else {
|
||||
$TreeCalcBot = new TreeCalcBot($data['month'], $data['year'], $data['init_from']);
|
||||
}
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, $data['live']);
|
||||
//TODO is not Admin, read is user in Parent tree ...
|
||||
if(!$TreeCalcBot->business_user){
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
return $TreeCalcBot;
|
||||
$TreeCalcBot->initBusinesslUserDetail($user, $data['live']);
|
||||
//TODO is not Admin, read is user in Parent tree ...
|
||||
if (!$TreeCalcBot->business_user) {
|
||||
abort(403, 'no user found');
|
||||
}
|
||||
return $TreeCalcBot;
|
||||
//}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,22 +212,21 @@ class ModalController extends Controller
|
|||
try {
|
||||
$dhlModalService = new DhlModalService();
|
||||
$modalData = $dhlModalService->prepareModalData($id, $data);
|
||||
|
||||
|
||||
// Merge the prepared data with the original request data
|
||||
$viewData = array_merge($data, $modalData, [
|
||||
'id' => $id,
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
|
||||
return view("admin.dhl.modal_create_shipment", $viewData)->render();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('[ModalController] Error in DHL shipment modal', [
|
||||
'order_id' => $id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
|
||||
// Return error view or fallback
|
||||
$errorData = [
|
||||
'id' => $id,
|
||||
|
|
@ -240,16 +238,14 @@ class ModalController extends Controller
|
|||
'productCodes' => [
|
||||
'V01PAK' => 'DHL Paket (National)',
|
||||
'V53WPAK' => 'DHL Paket International',
|
||||
'V54EPAK' => 'DHL Express'
|
||||
],
|
||||
'errors' => ['Fehler beim Laden der Daten: ' . $e->getMessage()],
|
||||
'warnings' => []
|
||||
];
|
||||
|
||||
|
||||
return view("admin.dhl.modal_create_shipment", $errorData)->render();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
0
app/Http/Controllers/PaymentMethodController.php
Executable file → Normal file
0
app/Http/Controllers/PaymentMethodController.php
Executable file → Normal file
61
app/Http/Controllers/Portal/Auth/LoginController.php
Executable file → Normal file
61
app/Http/Controllers/Portal/Auth/LoginController.php
Executable file → Normal file
|
|
@ -23,7 +23,7 @@ class LoginController extends Controller
|
|||
public function showLoginForm()
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if(Auth::guard('user')->check()){
|
||||
if (Auth::guard('user')->check()) {
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann direkt zum Dashboard
|
||||
|
|
@ -41,15 +41,18 @@ class LoginController extends Controller
|
|||
|
||||
// 1. Prüfen, ob die E-Mail im System bekannt ist über Kunden-Tabelle)
|
||||
$customer = Customer::firstOrCreate(['email' => $email]); // Erstellt Kunden, wenn nicht vorhanden
|
||||
if($customer && $customer->language){
|
||||
if ($customer && $customer->language) {
|
||||
\App::setLocale($customer->language);
|
||||
}
|
||||
|
||||
//add user_shop_domain for back
|
||||
$customer->user_shop_domain = session('user_shop_domain');
|
||||
$customer->save();
|
||||
|
||||
// if (!$customerExists && !$orderExists) { // Oder nur eine Prüfung, je nach Logik
|
||||
if (!$customer) { // Prüfung anhand des Customer-Models
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed_customer'), // Generische Fehlermeldung
|
||||
]);
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed_customer'), // Generische Fehlermeldung
|
||||
]);
|
||||
}
|
||||
// 2. Alten Token löschen (optional, aber empfohlen)
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
|
@ -70,10 +73,10 @@ class LoginController extends Controller
|
|||
try {
|
||||
Mail::to($email)->locale(\App::getLocale())->send(new MailOTPCustomer($otp, $email));
|
||||
} catch (\Exception $e) {
|
||||
// Logge den Fehler
|
||||
\Log::error('OTP Send Error: ' . $e->getMessage());
|
||||
// Gib eine Fehlermeldung zurück, ohne Details preiszugeben
|
||||
return back()->withErrors(['email' => 'Konnte E-Mail nicht senden. Bitte versuchen Sie es später erneut.'])->withInput();
|
||||
// Logge den Fehler
|
||||
\Log::error('OTP Send Error: ' . $e->getMessage());
|
||||
// Gib eine Fehlermeldung zurück, ohne Details preiszugeben
|
||||
return back()->withErrors(['email' => 'Konnte E-Mail nicht senden. Bitte versuchen Sie es später erneut.'])->withInput();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -86,26 +89,26 @@ class LoginController extends Controller
|
|||
public function showOtpForm(Request $request, $email = null, $otp = null)
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if(Auth::guard('user')->check()){
|
||||
if (Auth::guard('user')->check()) {
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann zum Dashboard wechseln
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
// E-Mail aus der Session holen (oder als Request-Parameter erwarten)
|
||||
if($email) {
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
// E-Mail aus der Session holen (oder als Request-Parameter erwarten)
|
||||
if ($email) {
|
||||
$email = $email;
|
||||
} else {
|
||||
} else {
|
||||
$email = session('otp_email', $request->query('email'));
|
||||
}
|
||||
}
|
||||
if (!$email) {
|
||||
return redirect()->route('portal.login.form')->withErrors(['message' => 'Sitzung abgelaufen oder E-Mail fehlt.']);
|
||||
}
|
||||
|
||||
|
||||
// CSRF-Token regenerieren für neue Session
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
|
||||
// Übergebe sowohl 'email' als auch 'otp' an die View
|
||||
return view('portal.auth.verify-otp', ['email' => $email, 'otp_value' => $otp]); // Variable umbenannt zu otp_value für Klarheit
|
||||
}
|
||||
|
|
@ -135,24 +138,24 @@ class LoginController extends Controller
|
|||
|
||||
if (!$customer) {
|
||||
// Sollte eigentlich nicht passieren, wenn sendOtp korrekt funktioniert hat
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
return back()->withErrors(['otp' => __('auth.failed')])->withInput(['email' => $email]);
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
return back()->withErrors(['otp' => __('auth.failed')])->withInput(['email' => $email]);
|
||||
}
|
||||
// 4. Kunden einloggen über den 'customers'-Guard
|
||||
Auth::guard('customers')->login($customer); // Loggt den gefundenen Kunden ein
|
||||
|
||||
|
||||
// 5. Explizite Session-Speicherung
|
||||
$request->session()->save();
|
||||
|
||||
|
||||
// 6. OTP-Eintrag löschen
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
||||
// 7. Session Token regenerieren (statt komplette Session)
|
||||
$request->session()->regenerate();
|
||||
$request->session()->regenerate();
|
||||
|
||||
// 8. customer DB aktualisieren
|
||||
$shopping_user = ShoppingUser::where('billing_email', $email)->latest()->first();
|
||||
if($shopping_user){
|
||||
if ($shopping_user) {
|
||||
$data = [
|
||||
'name' => $shopping_user->billing_firstname . ' ' . $shopping_user->billing_lastname,
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
|
|
@ -161,7 +164,7 @@ class LoginController extends Controller
|
|||
'language' => session('locale') ?? 'de',
|
||||
];
|
||||
$customer->update($data);
|
||||
}else{
|
||||
} else {
|
||||
$data = [
|
||||
'name' => __('portal.guest'),
|
||||
'shopping_user_id' => null,
|
||||
|
|
@ -185,7 +188,7 @@ class LoginController extends Controller
|
|||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
// Logout für Berater
|
||||
public function logoutChange(Request $request)
|
||||
|
|
@ -200,4 +203,4 @@ class LoginController extends Controller
|
|||
session(['locale' => $locale]);
|
||||
return redirect()->route('portal.login.form');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/Portal/InController.php
Executable file → Normal file
0
app/Http/Controllers/Portal/InController.php
Executable file → Normal file
0
app/Http/Controllers/ProductController.php
Executable file → Normal file
0
app/Http/Controllers/ProductController.php
Executable file → Normal file
193
app/Http/Controllers/SalesController.php
Executable file → Normal file
193
app/Http/Controllers/SalesController.php
Executable file → Normal file
|
|
@ -16,25 +16,25 @@ use App\Services\BusinessPlan\SalesPointsVolume;
|
|||
class SalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(){
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function users(){
|
||||
public function users()
|
||||
{
|
||||
|
||||
if(Request::get('reset') === 'filter'){
|
||||
if (Request::get('reset') === 'filter') {
|
||||
return redirect(route('admin_sales_users'));
|
||||
}
|
||||
$data = [
|
||||
|
||||
];
|
||||
$data = [];
|
||||
return view('admin.sales.users', $data);
|
||||
}
|
||||
|
||||
public function usersDetail($id)
|
||||
{
|
||||
$ShoppingOrder = ShoppingOrder::find($id);
|
||||
if( $ShoppingOrder->payment_for === 6 || $ShoppingOrder->payment_for === 7){
|
||||
if ($ShoppingOrder->payment_for === 6 || $ShoppingOrder->payment_for === 7) {
|
||||
return redirect(route('admin_sales_customers_detail', [$ShoppingOrder->id]));
|
||||
abort(403, 'Kundenbestellung');
|
||||
}
|
||||
|
|
@ -44,9 +44,9 @@ class SalesController extends Controller
|
|||
}*/
|
||||
|
||||
$data = [
|
||||
'shopping_order' => $ShoppingOrder,
|
||||
'isAdmin' => true,
|
||||
'isView' => 'sales_user',
|
||||
'shopping_order' => $ShoppingOrder,
|
||||
'isAdmin' => true,
|
||||
'isView' => 'sales_user',
|
||||
];
|
||||
return view('admin.sales.user_detail', $data);
|
||||
}
|
||||
|
|
@ -61,7 +61,8 @@ class SalesController extends Controller
|
|||
return view('admin.sales.user_detail', $data);
|
||||
}
|
||||
|
||||
public function usersDatatable(){
|
||||
public function usersDatatable()
|
||||
{
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user', 'user_shop', 'shopping_payments')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', '!=', NULL);
|
||||
|
||||
|
|
@ -76,29 +77,35 @@ class SalesController extends Controller
|
|||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->payment_for === 8){
|
||||
if ($ShoppingOrder->payment_for === 8) {
|
||||
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-action="shop-user-order-shipping-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-eye"></span></button>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
})
|
||||
->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn btn-xs btn-' . ($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary') . '" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-action="create-dhl-shipment"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-shipping-fast"></span></button>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
|
|
@ -107,11 +114,11 @@ class SalesController extends Controller
|
|||
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
return $ShoppingOrder->user_shop ? '<a href="' . $ShoppingOrder->user_shop->getSubdomain(false) . '" target="_blank">' . $ShoppingOrder->user_shop->getSubdomain(false) . '</span>' : '';
|
||||
})
|
||||
->addColumn('auth_user_shop', function (ShoppingOrder $ShoppingOrder) {
|
||||
$auth_user_shop = UserShop::whereUserId($ShoppingOrder->auth_user_id)->first();
|
||||
return $auth_user_shop ? '<a href="'.$auth_user_shop->getSubdomain(false).'" target="_blank">'.$auth_user_shop->getSubdomain(false).'</span>' : '-';
|
||||
return $auth_user_shop ? '<a href="' . $auth_user_shop->getSubdomain(false) . '" target="_blank">' . $auth_user_shop->getSubdomain(false) . '</span>' : '-';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
|
|
@ -120,27 +127,27 @@ class SalesController extends Controller
|
|||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
|
||||
->rawColumns(['id', 'txaction', 'user_shop_id', 'auth_user_shop', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
|
||||
->rawColumns(['id', 'dhl_button', 'txaction', 'user_shop_id', 'auth_user_shop', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function customers()
|
||||
{
|
||||
if(Request::get('reset') === 'filter'){
|
||||
if (Request::get('reset') === 'filter') {
|
||||
set_user_attr('filter_user_shop_id', null);
|
||||
set_user_attr('filter_txaction', null);
|
||||
set_user_attr('filter_member_id', null);
|
||||
return redirect(route('admin_sales_customers'));
|
||||
}
|
||||
$filter_user_shops = ShoppingOrder::select('user_shops.id', 'user_shops.slug')
|
||||
->join('user_shops', 'shopping_orders.user_shop_id', '=', 'user_shops.id')
|
||||
->orderBy('user_shops.slug')
|
||||
->distinct()
|
||||
->pluck('slug', 'id')
|
||||
->toArray();
|
||||
$filter_members = ShoppingOrder::join('users', 'member_id', '=', 'users.id')->groupBy('member_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get();
|
||||
->join('user_shops', 'shopping_orders.user_shop_id', '=', 'user_shops.id')
|
||||
->orderBy('user_shops.slug')
|
||||
->distinct()
|
||||
->pluck('slug', 'id')
|
||||
->toArray();
|
||||
$filter_members = ShoppingOrder::join('users', 'member_id', '=', 'users.id')->groupBy('member_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get();
|
||||
//->pluck('email', 'id')->unique()->toArray();
|
||||
|
||||
|
||||
|
||||
|
||||
$data = [
|
||||
|
|
@ -153,14 +160,14 @@ class SalesController extends Controller
|
|||
public function customersDetail($id)
|
||||
{
|
||||
$ShoppingOrder = ShoppingOrder::find($id);
|
||||
if(!$ShoppingOrder){
|
||||
if (!$ShoppingOrder) {
|
||||
abort(404);
|
||||
}
|
||||
if( $ShoppingOrder->payment_for !== 6 && $ShoppingOrder->payment_for !== 7){
|
||||
if ($ShoppingOrder->payment_for !== 6 && $ShoppingOrder->payment_for !== 7) {
|
||||
return redirect(route('admin_sales_users_detail', [$ShoppingOrder->id]));
|
||||
abort(403, 'Beraterbestellung');
|
||||
}
|
||||
/*
|
||||
/*
|
||||
if($ShoppingOrder->shipped === 0){
|
||||
$ShoppingOrder->shipped = 1;
|
||||
$ShoppingOrder->save();
|
||||
|
|
@ -178,10 +185,10 @@ class SalesController extends Controller
|
|||
{
|
||||
$data = Request::all();
|
||||
$change_member_error = false;
|
||||
if($data['action']==='shopping-order-change-member'){
|
||||
if(!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')){
|
||||
if ($data['action'] === 'shopping-order-change-member') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
$change_member_error = "Das Passwort ist falsch.";
|
||||
}else{
|
||||
} else {
|
||||
//change
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
CustomerPriority::newMemberForOrder($shopping_order, $data['change_member_id'], $data['customer_set_member_for']);
|
||||
|
|
@ -189,12 +196,12 @@ class SalesController extends Controller
|
|||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
}
|
||||
if($data['action']==='shopping-user-is-like-member'){
|
||||
if(!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')){
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
return redirect($data['back']);
|
||||
}else{
|
||||
if(!isset($data['is_like_shopping_user_id'])){
|
||||
if ($data['action'] === 'shopping-user-is-like-member') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
return redirect($data['back']);
|
||||
} else {
|
||||
if (!isset($data['is_like_shopping_user_id'])) {
|
||||
\Session()->flash('alert-error', 'Keine Änderung ausgewählt');
|
||||
return redirect($data['back']);
|
||||
}
|
||||
|
|
@ -208,12 +215,12 @@ class SalesController extends Controller
|
|||
return redirect($data['back']);
|
||||
}
|
||||
}
|
||||
if($data['action']==='shopping-order-change-points'){
|
||||
if(!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')){
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
return back();
|
||||
}else{
|
||||
if(!isset($data['change_points'])){
|
||||
if ($data['action'] === 'shopping-order-change-points') {
|
||||
if (!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')) {
|
||||
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
|
||||
return back();
|
||||
} else {
|
||||
if (!isset($data['change_points'])) {
|
||||
\Session()->flash('alert-error', 'Keine Änderung ausgewählt');
|
||||
return back();
|
||||
}
|
||||
|
|
@ -231,24 +238,24 @@ class SalesController extends Controller
|
|||
return view('admin.sales.customer_detail', $data);
|
||||
}
|
||||
|
||||
public function customersDatatable(){
|
||||
public function customersDatatable()
|
||||
{
|
||||
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', NULL);
|
||||
set_user_attr('filter_user_shop_id', Request::get('filter_user_shop_id'));
|
||||
if(Request::get('filter_user_shop_id') != ""){
|
||||
if (Request::get('filter_user_shop_id') != "") {
|
||||
$query->where('user_shop_id', '=', Request::get('filter_user_shop_id'));
|
||||
}
|
||||
set_user_attr('filter_txaction', Request::get('filter_txaction'));
|
||||
if(Request::get('filter_txaction') != ""){
|
||||
if(Request::get('filter_txaction') === 'NULL'){
|
||||
if (Request::get('filter_txaction') != "") {
|
||||
if (Request::get('filter_txaction') === 'NULL') {
|
||||
$query->where('txaction', '=', NULL);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
$query->where('txaction', '=', Request::get('filter_txaction'));
|
||||
}
|
||||
}
|
||||
set_user_attr('filter_member_id', Request::get('filter_member_id'));
|
||||
if(Request::get('filter_member_id') != ""){
|
||||
if (Request::get('filter_member_id') != "") {
|
||||
$query->where('member_id', '=', Request::get('filter_member_id'));
|
||||
}
|
||||
|
||||
|
|
@ -263,74 +270,81 @@ class SalesController extends Controller
|
|||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
return '<span class="no-line-break">' . $ShoppingOrder->getFormattedTotalShipping() . " €</span>";
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->txaction === 'extern_paid'){
|
||||
if ($ShoppingOrder->txaction === 'extern_paid') {
|
||||
$shopping_oder_id = isset($ShoppingOrder->api_notice['shopping_order_id']) ? $ShoppingOrder->api_notice['shopping_order_id'] : null;
|
||||
if($shopping_oder_id){
|
||||
return '<a class="btn btn-xs btn-default btn-round" href="'.route('admin_sales_users_detail', [$shopping_oder_id]).'"><i class="fa fa-check fa-check-circle-o"> '.$shopping_oder_id.'</a>';
|
||||
if ($shopping_oder_id) {
|
||||
return '<a class="btn btn-xs btn-default btn-round" href="' . route('admin_sales_users_detail', [$shopping_oder_id]) . '"><i class="fa fa-check fa-check-circle-o"> ' . $shopping_oder_id . '</a>';
|
||||
}
|
||||
}
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
return '<span class="badge badge-pill badge-' . $ShoppingOrder->getShippedColor() . '">' . $ShoppingOrder->getShippedType() . '</span>';
|
||||
})
|
||||
->addColumn('dhl_button', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn btn-xs btn-' . ($ShoppingOrder->hasDhlShipments() ? 'primary' : 'secondary') . '" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="' . $ShoppingOrder->id . '"
|
||||
data-action="create-dhl-shipment"
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-shipping-fast"></span></button>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
if(($ShoppingOrder->txaction === 'extern' || $ShoppingOrder->txaction === 'extern_paid') && $ShoppingOrder->wp_invoice_path){
|
||||
return '<span class="no-line-break"><a href="'.$ShoppingOrder->wp_invoice_path.'" class="btn btn-secondary btn-xs"><i class="fa fa-external-link-alt"></i> <i class="fa fa-download"></i></a> </div>';
|
||||
}
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
if (($ShoppingOrder->txaction === 'extern' || $ShoppingOrder->txaction === 'extern_paid') && $ShoppingOrder->wp_invoice_path) {
|
||||
return '<span class="no-line-break"><a href="' . $ShoppingOrder->wp_invoice_path . '" class="btn btn-secondary btn-xs"><i class="fa fa-external-link-alt"></i> <i class="fa fa-download"></i></a> </div>';
|
||||
}
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']) . '" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="' . route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']) . '" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
})
|
||||
->addColumn('member_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->member_id && $ShoppingOrder->member) {
|
||||
if ($ShoppingOrder->member_id && $ShoppingOrder->member) {
|
||||
return $ShoppingOrder->member ? '<a href="' . route('admin_lead_edit', [$ShoppingOrder->member_id]) . '">' . $ShoppingOrder->member->getFullName() . '</a>' : 'gelöscht';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like){
|
||||
if ($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like) {
|
||||
return '<button type="button" class="btn btn-xs btn-outline-info" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->shopping_user->id.'"
|
||||
data-id="' . $ShoppingOrder->shopping_user->id . '"
|
||||
data-action="shopping-user-is-like-member"
|
||||
data-back="'.route('admin_sales_customers').'"
|
||||
data-back="' . route('admin_sales_customers') . '"
|
||||
data-modal="modal-xl"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
data-route="' . route('modal_load') . '"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
}
|
||||
return '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
return $ShoppingOrder->user_shop ? '<a href="' . $ShoppingOrder->user_shop->getSubdomain(false) . '" target="_blank">' . $ShoppingOrder->user_shop->getSubdomain(false) . '</span>' : '';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('user_shop_id', 'user_shop_id $1')
|
||||
->orderColumn('member_id', 'member_id $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->rawColumns(['id', 'member_id', 'txaction', 'user_shop_id', 'payment_for', 'payment', 'total_shipping', 'invoice', 'shipped'])
|
||||
->rawColumns(['id', 'dhl_button', 'member_id', 'txaction', 'user_shop_id', 'payment_for', 'payment', 'total_shipping', 'invoice', 'shipped'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function store(){
|
||||
public function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
if(!isset($data['id'])){
|
||||
if (!isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'store_shipped' && isset($data['shipped'])){
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'store_shipped' && isset($data['shipped'])) {
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
$shopping_order->shipped = $data['shipped'];
|
||||
$shopping_order->save();
|
||||
}
|
||||
|
||||
if($data['action'] === 'store_txaction' && isset($data['txaction']) && isset($data['payment_id'])){
|
||||
if ($data['action'] === 'store_txaction' && isset($data['txaction']) && isset($data['payment_id'])) {
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
$shopping_payment = ShoppingPayment::findOrFail($data['payment_id']);
|
||||
|
||||
|
|
@ -356,37 +370,36 @@ class SalesController extends Controller
|
|||
//wenn muss hier die Storno erstellt werden
|
||||
//Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
|
||||
}
|
||||
if(isset($data['back'])){
|
||||
if (isset($data['back'])) {
|
||||
return redirect($data['back']);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Manuelle Rechnung erstellen.*/
|
||||
public function invoice(){
|
||||
public function invoice()
|
||||
{
|
||||
$data = Request::all();
|
||||
if(!isset($data['id'])){
|
||||
if (!isset($data['id'])) {
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'create_invoice'){
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'create_invoice') {
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
|
||||
|
||||
$invoice_repo = new InvoiceRepository($shopping_order);
|
||||
if($shopping_order->isInvoice()){
|
||||
if ($shopping_order->isInvoice()) {
|
||||
$invoice_repo->update($data);
|
||||
}else{
|
||||
} else {
|
||||
$invoice_repo->createAndSalesVolume($data);
|
||||
}
|
||||
|
||||
if(isset($data['view']) && $data['view'] === 'sales_customer'){
|
||||
|
||||
if (isset($data['view']) && $data['view'] === 'sales_customer') {
|
||||
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
|
||||
}
|
||||
return redirect(route('admin_sales_users_detail', [$shopping_order->id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,13 @@ class SettingController extends Controller
|
|||
*/
|
||||
public function getDhlConfig()
|
||||
{
|
||||
// Check if we're in test/sandbox mode
|
||||
$isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false);
|
||||
$baseUrl = $isTestMode ? config('dhl.sandbox_url') : config('dhl.base_url');
|
||||
|
||||
return [
|
||||
// API Settings
|
||||
'base_url' => Setting::getContentBySlug('dhl_base_url') ?: config('dhl.base_url'),
|
||||
'base_url' => $isTestMode ? $baseUrl : (Setting::getContentBySlug('dhl_base_url') ?: $baseUrl),
|
||||
'api_key' => Setting::getContentBySlug('dhl_api_key') ?: config('dhl.api_key'),
|
||||
'username' => Setting::getContentBySlug('dhl_username') ?: config('dhl.username'),
|
||||
'password' => Setting::getContentBySlug('dhl_password') ?: config('dhl.password'),
|
||||
|
|
@ -91,6 +95,15 @@ class SettingController extends Controller
|
|||
'default' => config('dhl.account_numbers.default'),
|
||||
],
|
||||
|
||||
|
||||
// Dimensions
|
||||
'dimensions' => [
|
||||
'V01PAK' => config('dhl.dimensions.V01PAK'),
|
||||
'V62WP' => config('dhl.dimensions.V62WP'),
|
||||
'V53PAK' => config('dhl.dimensions.V53PAK'),
|
||||
'V07PAK' => config('dhl.dimensions.V07PAK'),
|
||||
'default' => config('dhl.dimensions.default'),
|
||||
],
|
||||
// Static config values (webhook, profile, legacy)
|
||||
'profile' => config('dhl.profile'),
|
||||
'webhook' => config('dhl.webhook'),
|
||||
|
|
|
|||
0
app/Http/Controllers/ShippingController.php
Executable file → Normal file
0
app/Http/Controllers/ShippingController.php
Executable file → Normal file
0
app/Http/Controllers/SitesController.php
Executable file → Normal file
0
app/Http/Controllers/SitesController.php
Executable file → Normal file
0
app/Http/Controllers/SyS/SettingController.php
Executable file → Normal file
0
app/Http/Controllers/SyS/SettingController.php
Executable file → Normal file
0
app/Http/Controllers/TemplateController.php
Executable file → Normal file
0
app/Http/Controllers/TemplateController.php
Executable file → Normal file
0
app/Http/Controllers/TranslationController.php
Executable file → Normal file
0
app/Http/Controllers/TranslationController.php
Executable file → Normal file
0
app/Http/Controllers/TranslationFileController.php
Executable file → Normal file
0
app/Http/Controllers/TranslationFileController.php
Executable file → Normal file
0
app/Http/Controllers/User/CustomerController.php
Executable file → Normal file
0
app/Http/Controllers/User/CustomerController.php
Executable file → Normal file
0
app/Http/Controllers/User/HomepartyController.php
Executable file → Normal file
0
app/Http/Controllers/User/HomepartyController.php
Executable file → Normal file
0
app/Http/Controllers/User/MembershipController.php
Executable file → Normal file
0
app/Http/Controllers/User/MembershipController.php
Executable file → Normal file
0
app/Http/Controllers/User/OrderController.php
Executable file → Normal file
0
app/Http/Controllers/User/OrderController.php
Executable file → Normal file
0
app/Http/Controllers/User/ShopSalesController.php
Executable file → Normal file
0
app/Http/Controllers/User/ShopSalesController.php
Executable file → Normal file
475
app/Http/Controllers/User/TeamController.php
Executable file → Normal file
475
app/Http/Controllers/User/TeamController.php
Executable file → Normal file
|
|
@ -45,7 +45,7 @@ class TeamController extends Controller
|
|||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Zeigt die Team-Übersicht mit optimierter TreeCalcBotOptimized-Datenverarbeitung
|
||||
|
|
@ -55,60 +55,58 @@ class TeamController extends Controller
|
|||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
|
||||
try {
|
||||
$this->setFilterVars();
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$this->month = session('team_user_filter_month');
|
||||
$this->year = session('team_user_filter_year');
|
||||
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation ? " with forced live calculation" : ""));
|
||||
|
||||
$forceLiveCalculation = false;
|
||||
|
||||
\Log::info("TeamController: Building optimized team overview for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation === true ? " with forced live calculation" : "not live calculation"));
|
||||
|
||||
// Verwende TreeCalcBotOptimized für bessere Performance
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
|
||||
//$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
//$TreeCalcBot->initStructureUser($user->id);
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
|
||||
$calculationType = $forceLiveCalculation ? " (LIVE)" : " (CACHE)";
|
||||
\Log::info("TeamController: Optimized team overview built in {$executionTime}ms, Memory: {$memoryUsed}{$calculationType}");
|
||||
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
'filter_active' => $this->getFilterActive(),
|
||||
'filter_levels' => $this->getFilterLevels(),
|
||||
'filter_next_level' => $this->getFilterNextLevel(),
|
||||
'TreeCalcBot' => $TreeCalcBot,
|
||||
//'TreeCalcBot' => $TreeCalcBot,
|
||||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_id' => $user->id,
|
||||
'user_count' => $TreeCalcBot->getTotalUserCount(),
|
||||
'user_count' => 0, //$TreeCalcBot->getTotalUserCount(),
|
||||
'version' => 'Optimized',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
],
|
||||
'optimized' => true,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
return view('user.team.show', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized show for user {$user->id}: " . $e->getMessage());
|
||||
|
||||
|
||||
// Fallback mit minimalen Daten
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
|
|
@ -124,7 +122,7 @@ class TeamController extends Controller
|
|||
],
|
||||
'optimized' => false,
|
||||
];
|
||||
|
||||
|
||||
return view('user.team.show', $data);
|
||||
}
|
||||
}
|
||||
|
|
@ -133,55 +131,54 @@ class TeamController extends Controller
|
|||
{
|
||||
$startTime = microtime(true);
|
||||
$startMemory = memory_get_usage();
|
||||
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if(config('app.debug')){
|
||||
if (config('app.debug')) {
|
||||
$user = User::find(454);
|
||||
}
|
||||
$this->setFilterVars();
|
||||
|
||||
|
||||
// Prüfe ob optimierte Version explizit angefordert wird
|
||||
$useOptimized = Request::get('use_optimized', true);
|
||||
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
|
||||
try {
|
||||
if ($useOptimized) {
|
||||
// Verwende User-spezifische optimierte Version
|
||||
$TreeCalcBot = new TreeCalcBotOptimized(
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
'member',
|
||||
$forceLiveCalculation
|
||||
);
|
||||
$TreeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
$optimizedUsed = true;
|
||||
|
||||
} else {
|
||||
// Standard TreeCalcBot mit Performance-Monitoring
|
||||
$TreeCalcBot = new TreeCalcBot(
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
session('team_user_filter_month'),
|
||||
session('team_user_filter_year'),
|
||||
'member'
|
||||
);
|
||||
|
||||
|
||||
// Standard TreeCalcBot unterstützt forceLiveCalculation nicht
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
$optimizedUsed = false;
|
||||
}
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
$endMemory = memory_get_usage();
|
||||
|
||||
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
$versionInfo = ($optimizedUsed ? "OPTIMIZED" : "STANDARD") .
|
||||
($forceLiveCalculation ? " + LIVE" : " + CACHE");
|
||||
|
||||
|
||||
$versionInfo = ($optimizedUsed ? "OPTIMIZED" : "STANDARD") .
|
||||
($forceLiveCalculation ? " + LIVE" : " + CACHE");
|
||||
|
||||
\Log::info("TeamController: Structure built for user {$user->id} in {$executionTime}ms, Memory: {$memoryUsed} ({$versionInfo})");
|
||||
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
|
|
@ -189,28 +186,27 @@ class TeamController extends Controller
|
|||
'performance' => [
|
||||
'execution_time' => $executionTime,
|
||||
'memory_used' => $memoryUsed,
|
||||
'user_count' => $optimizedUsed && method_exists($TreeCalcBot, 'getTotalUserCount')
|
||||
? $TreeCalcBot->getTotalUserCount()
|
||||
: '-',
|
||||
'user_count' => $optimizedUsed && method_exists($TreeCalcBot, 'getTotalUserCount')
|
||||
? $TreeCalcBot->getTotalUserCount()
|
||||
: '-',
|
||||
'version' => $optimizedUsed ? 'Optimized' : 'Standard',
|
||||
'calculation_type' => $forceLiveCalculation ? 'Live' : 'Cache'
|
||||
],
|
||||
'optimized' => $optimizedUsed,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in structure for user {$user->id}: " . $e->getMessage());
|
||||
|
||||
|
||||
// Fallback zur Standard-Implementierung
|
||||
$TreeCalcBot = new TreeCalcBot(session('team_user_filter_month'), session('team_user_filter_year'), 'member');
|
||||
$TreeCalcBot->initStructureUser($user->id);
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
|
||||
$data = [
|
||||
'filter_months' => HTMLHelper::getTransMonths(),
|
||||
'filter_years' => HTMLHelper::getYearRange(2022),
|
||||
|
|
@ -226,14 +222,15 @@ class TeamController extends Controller
|
|||
'optimized' => false,
|
||||
'forceLiveCalculation' => $forceLiveCalculation,
|
||||
];
|
||||
|
||||
|
||||
return view('user.team.structure', $data);
|
||||
}
|
||||
}
|
||||
public function structureOld()
|
||||
{
|
||||
abort(403, 'This page is removed');
|
||||
$user = User::find(\Auth::user()->id);
|
||||
if(config('app.debug')){
|
||||
if (config('app.debug')) {
|
||||
$user = User::find(454);
|
||||
}
|
||||
$this->setFilterVars();
|
||||
|
|
@ -263,27 +260,29 @@ class TeamController extends Controller
|
|||
$user = User::find(\Auth::user()->id);
|
||||
$this->month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$this->year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
|
||||
|
||||
// Prüfe ob Live-Berechnung erzwungen werden soll
|
||||
$forceLiveCalculation = Request::get('force_live_calculation', false) || Request::get('live', false);
|
||||
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation == true ? " with forced live calculation" : ""));
|
||||
|
||||
$forceLiveCalculation = false;
|
||||
\Log::info("TeamController: Building optimized datatable for user {$user->id} ({$this->month}/{$this->year})" .
|
||||
($forceLiveCalculation == true ? " with forced live calculation" : ""));
|
||||
|
||||
// Lade TreeCalcBotOptimized-Daten
|
||||
$TreeCalcBot = new TreeCalcBotOptimized($this->month, $this->year, 'member', $forceLiveCalculation);
|
||||
$TreeCalcBot->initStructureUser($user->id, $forceLiveCalculation);
|
||||
|
||||
// Extrahiere alle User aus der Struktur
|
||||
$teamUsers = collect($this->getTeamUsersFromStructure($TreeCalcBot));
|
||||
// \Log::info("TeamController: TeamUsers: " . $teamUsers->count());
|
||||
|
||||
$teamUsersRaw = $this->getTeamUsersFromStructure($TreeCalcBot);
|
||||
|
||||
// KRITISCH: Bereinige die Objekte für DataTables (entferne zirkuläre Referenzen)
|
||||
$teamUsers = collect($this->cleanBusinessUserItemsForDataTable($teamUsersRaw));
|
||||
|
||||
\Log::info("TeamController: TeamUsers cleaned for DataTable: " . $teamUsers->count());
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
|
||||
\Log::info("TeamController: Optimized datatable data prepared in {$executionTime}ms for " . $teamUsers->count() . " users");
|
||||
|
||||
|
||||
return \DataTables::of($teamUsers)
|
||||
->addColumn('id', function ($teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
|
|
@ -310,7 +309,6 @@ class TeamController extends Controller
|
|||
})
|
||||
->addColumn('user_level', function ($teamUser) {
|
||||
return $teamUser->user_level_name ? TranslationHelper::transUserLevelName($teamUser->user_level_name) : '';
|
||||
|
||||
})
|
||||
->addColumn('is_qual_kp', function ($teamUser) {
|
||||
$user = User::find($teamUser->user_id);
|
||||
|
|
@ -320,12 +318,11 @@ class TeamController extends Controller
|
|||
return formatNumber($teamUser->sales_volume_points_KP_sum, 0);
|
||||
})
|
||||
->addColumn('sales_volume_total', function ($teamUser) {
|
||||
|
||||
return formatNumber($teamUser->payline_points_qual_kp, 0);
|
||||
|
||||
return formatNumber($teamUser->payline_points_qual_kp, 0);
|
||||
})
|
||||
->addColumn('next_level_qualified', function ($teamUser) {
|
||||
|
||||
|
||||
$userBusiness = UserBusiness::where('user_id', $teamUser->user_id)
|
||||
->where('month', $this->month)
|
||||
->where('year', $this->year)
|
||||
|
|
@ -334,7 +331,6 @@ class TeamController extends Controller
|
|||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
|
||||
})
|
||||
->addColumn('active_account', function ($teamUser) {
|
||||
return get_active_badge($teamUser->active_account);
|
||||
|
|
@ -344,10 +340,9 @@ class TeamController extends Controller
|
|||
})
|
||||
->rawColumns(['id', 'next_level_qualified', 'active_account', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total'])
|
||||
->make(true);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in optimized datatable: " . $e->getMessage());
|
||||
|
||||
|
||||
// Fallback zur Standard-DataTable
|
||||
return $this->datatable();
|
||||
}
|
||||
|
|
@ -361,7 +356,7 @@ class TeamController extends Controller
|
|||
try {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = $this->initTeamSearch($user);
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (User $teamUser) {
|
||||
return '<button type="button" class="btn icon-btn btn-xs btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
|
|
@ -397,7 +392,7 @@ class TeamController extends Controller
|
|||
$individual = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_KP_points');
|
||||
$shop = (int) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_points_shop');
|
||||
return '<div class="no-line-break">' . $total . '</div>' .
|
||||
'<span class="small no-line-break">E: ' . $individual . ' | S: ' . $shop . '</span>';
|
||||
'<span class="small no-line-break">E: ' . $individual . ' | S: ' . $shop . '</span>';
|
||||
})
|
||||
->addColumn('sales_volume_total', function (User $teamUser) {
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
|
|
@ -406,7 +401,7 @@ class TeamController extends Controller
|
|||
$individual = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total');
|
||||
$shop = (float) $teamUser->getUserSalesVolumeBy($month, $year, 'sales_volume_total_shop');
|
||||
return '<div class="no-line-break">' . formatNumber($total) . ' €</div>' .
|
||||
'<span class="small no-line-break">E: ' . formatNumber($individual) . ' | S: ' . formatNumber($shop) . ' €</span>';
|
||||
'<span class="small no-line-break">E: ' . formatNumber($individual) . ' | S: ' . formatNumber($shop) . ' €</span>';
|
||||
})
|
||||
->addColumn('email', function (User $teamUser) {
|
||||
return e($teamUser->email);
|
||||
|
|
@ -441,35 +436,35 @@ class TeamController extends Controller
|
|||
// Verwende bereits berechnete UserBusiness-Daten für bessere Performance
|
||||
$month = Request::get('team_user_filter_month') ?: session('team_user_filter_month');
|
||||
$year = Request::get('team_user_filter_year') ?: session('team_user_filter_year');
|
||||
|
||||
|
||||
$userBusiness = UserBusiness::where('user_id', $teamUser->id)
|
||||
->where('month', $month)
|
||||
->where('year', $year)
|
||||
->first();
|
||||
|
||||
|
||||
if ($userBusiness) {
|
||||
return NextLevelBadgeHelper::generateBadgeFromUserBusiness($userBusiness);
|
||||
}
|
||||
|
||||
|
||||
return NextLevelBadgeHelper::renderNoDataBadge();
|
||||
})
|
||||
->filterColumn('m_account', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('m_account', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('first_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('first_name', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
})
|
||||
->filterColumn('last_name', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->whereHas('account', function($q) use ($keyword) {
|
||||
$query->whereHas('account', function ($q) use ($keyword) {
|
||||
$q->where('last_name', 'LIKE', '%' . $keyword . '%');
|
||||
});
|
||||
}
|
||||
|
|
@ -487,10 +482,9 @@ class TeamController extends Controller
|
|||
->orderColumn('active_account', 'users.payment_account $1')
|
||||
->rawColumns(['id', 'is_qual_kp', 'sales_volume_KP_points', 'sales_volume_total', 'sponsor', 'active_account', 'next_level_qualified'])
|
||||
->make(true);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error in userDatatable: " . $e->getMessage());
|
||||
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Team-Datatable konnte nicht geladen werden: ' . $e->getMessage()
|
||||
], 500);
|
||||
|
|
@ -504,21 +498,21 @@ class TeamController extends Controller
|
|||
public function marketingplan()
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
|
||||
|
||||
try {
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$currentLevel = $user->user_level;
|
||||
|
||||
|
||||
// Lade alle aktiven User Level, sortiert nach Position
|
||||
$userLevels = \App\Models\UserLevel::where('active', true)
|
||||
->orderBy('pos', 'asc')
|
||||
->get();
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
|
||||
|
||||
\Log::info("TeamController: Marketingplan loaded for user {$user->id} in {$executionTime}ms");
|
||||
|
||||
|
||||
$data = [
|
||||
'userLevels' => $userLevels,
|
||||
'currentUser' => $user,
|
||||
|
|
@ -527,12 +521,11 @@ class TeamController extends Controller
|
|||
'execution_time' => $executionTime
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
return view('user.team.marketingplan', $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error loading marketingplan: " . $e->getMessage());
|
||||
|
||||
|
||||
return view('user.team.marketingplan', [
|
||||
'error' => __('marketingplan.loading_error') . ' ' . $e->getMessage(),
|
||||
'userLevels' => collect(),
|
||||
|
|
@ -580,7 +573,7 @@ class TeamController extends Controller
|
|||
// Filtere Team-Mitglieder basierend auf Sponsor-Hierarchie
|
||||
// TODO: Hier müsste die Logik implementiert werden, um nur Team-Mitglieder des aktuellen Users zu finden
|
||||
// Für jetzt zeigen wir alle aktiven User (kann später spezifiziert werden)
|
||||
|
||||
|
||||
$activeFilter = Request::get('team_user_filter_active') ?: session('team_user_filter_active', 1);
|
||||
if ($activeFilter == 1) {
|
||||
$query->where('users.payment_account', '>=', now());
|
||||
|
|
@ -591,7 +584,7 @@ class TeamController extends Controller
|
|||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function points()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
|
@ -718,12 +711,12 @@ class TeamController extends Controller
|
|||
}
|
||||
if (Request::get('team_user_filter_level')) {
|
||||
session(['team_user_filter_level' => Request::get('team_user_filter_level')]);
|
||||
}else{
|
||||
} else {
|
||||
session(['team_user_filter_level' => 0]);
|
||||
}
|
||||
if (Request::get('team_user_filter_next_level')) {
|
||||
session(['team_user_filter_next_level' => Request::get('team_user_filter_next_level')]);
|
||||
}else{
|
||||
} else {
|
||||
session(['team_user_filter_next_level' => 0]);
|
||||
}
|
||||
}
|
||||
|
|
@ -812,96 +805,120 @@ class TeamController extends Controller
|
|||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt verfügbare User Level für Filter
|
||||
*/
|
||||
private function getFilterLevels(): array
|
||||
{
|
||||
$levels = [0 => 'Alle Level'];
|
||||
|
||||
$userLevels = \App\Models\UserLevel::orderBy('pos')->get(['id', 'name']);
|
||||
foreach ($userLevels as $level) {
|
||||
$levels[$level->id] = $level->name;
|
||||
}
|
||||
|
||||
return $levels;
|
||||
/**
|
||||
* Holt verfügbare User Level für Filter
|
||||
*/
|
||||
private function getFilterLevels(): array
|
||||
{
|
||||
$levels = [0 => 'Alle Level'];
|
||||
|
||||
$userLevels = \App\Models\UserLevel::orderBy('pos')->get(['id', 'name']);
|
||||
foreach ($userLevels as $level) {
|
||||
$levels[$level->id] = $level->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt übersetzte Filter für Aktiv-Status
|
||||
*/
|
||||
private function getFilterActive(): array
|
||||
{
|
||||
return [
|
||||
1 => __('team.filter_active'),
|
||||
2 => __('team.filter_not_active'),
|
||||
3 => __('team.filter_all')
|
||||
];
|
||||
}
|
||||
return $levels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt übersetzte Filter für Next Level Status
|
||||
*/
|
||||
private function getFilterNextLevel(): array
|
||||
{
|
||||
return [
|
||||
0 => __('team.all_status'),
|
||||
1 => __('team.qualified_green'),
|
||||
2 => __('team.in_progress_yellow'),
|
||||
3 => __('team.no_level_red')
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Holt übersetzte Filter für Aktiv-Status
|
||||
*/
|
||||
private function getFilterActive(): array
|
||||
{
|
||||
return [
|
||||
1 => __('team.filter_active'),
|
||||
2 => __('team.filter_not_active'),
|
||||
3 => __('team.filter_all')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt übersetzte Filter für Next Level Status
|
||||
*/
|
||||
private function getFilterNextLevel(): array
|
||||
{
|
||||
return [
|
||||
0 => __('team.all_status'),
|
||||
1 => __('team.qualified_green'),
|
||||
2 => __('team.in_progress_yellow'),
|
||||
3 => __('team.no_level_red')
|
||||
];
|
||||
}
|
||||
|
||||
// Performance-optimierte Badge-Generierung wurde in NextLevelBadgeHelper ausgelagert
|
||||
// Alte performance-lastige Methoden wurden entfernt um die Datatable-Performance zu verbessern
|
||||
|
||||
/**
|
||||
* Extrahiert alle User aus TreeCalcBotOptimized-Struktur für DataTable-Anzeige
|
||||
* Sammelt rekursiv alle User aus der Struktur und macht sie als flache Liste verfügbar
|
||||
* Sammelt rekursiv alle User aus der Struktur und macht sie als FLACHE Liste verfügbar
|
||||
*/
|
||||
public function getTeamUsersFromStructure(TreeCalcBotOptimized $treeCalcBot): array
|
||||
{
|
||||
$allUsers = [];
|
||||
$deep = 0;
|
||||
$processedIds = [];
|
||||
|
||||
// Debug: Prüfe TreeCalcBot-Inhalt
|
||||
$businessUsers = $treeCalcBot->getItems();
|
||||
\Log::info("TeamController: TreeCalcBot items count: " . count($businessUsers));
|
||||
|
||||
// Sammle alle Root-User
|
||||
\Log::info("TeamController: TreeCalcBot root items count: " . count($businessUsers));
|
||||
|
||||
// Sammle alle Root-User UND deren verschachtelte businessUserItems
|
||||
foreach ($businessUsers as $businessUser) {
|
||||
\Log::debug("TeamController: Processing businessUser", [
|
||||
'user_id' => ($businessUser->user_id),
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $businessUser->user_id; // Über __get() Method
|
||||
|
||||
\Log::debug("TeamController: Processing root businessUser", [
|
||||
'user_id' => $userId,
|
||||
'businessUserItems_count' => count($businessUser->businessUserItems ?? []),
|
||||
]);
|
||||
$businessUser->deep = $deep;
|
||||
$allUsers[] = $businessUser;
|
||||
$this->collectUserIdsFromBusinessUser($businessUser, $allUsers, $deep+1, false);
|
||||
// WICHTIG: Root-User selbst hinzufügen (korrigierte user_id Prüfung)
|
||||
//nur User können auch children haben - businessUserItems
|
||||
if ($userId && !isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
$this->collectAllBusinessUserItemsFlat($businessUser->businessUserItems ?? [], $allUsers, $processedIds, 1);
|
||||
\Log::debug("TeamController: Root-User hinzugefügt: {$userId}");
|
||||
}
|
||||
}
|
||||
// Sammle parentless User
|
||||
// Sammle parentless User, kann bei usern eigenlich nicht vorkommen, da sie immer teil des baums sind
|
||||
if ($treeCalcBot->isParentless()) {
|
||||
$parentless = $treeCalcBot->__get('parentless');
|
||||
//\Log::info("TeamController: Found " . count($parentless) . " parentless users");
|
||||
|
||||
if (is_array($parentless)) {
|
||||
foreach ($parentless as $businessUser) {
|
||||
if ($businessUser) {
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
||||
// Sammle rekursiv alle Unter-User
|
||||
$this->collectUserIdsFromBusinessUser($businessUser, $allUsers, 0, true);
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $businessUser->user_id; // Über __get() Method
|
||||
|
||||
if ($userId) {
|
||||
// Prüfe ob dieser parentless User bereits gesammelt wurde
|
||||
if (!isset($processedIds[$userId])) {
|
||||
$processedIds[$userId] = true;
|
||||
$businessUser->deep = 0;
|
||||
$allUsers[] = $businessUser;
|
||||
|
||||
\Log::debug("TeamController: Parentless-User hinzugefügt: {$userId}");
|
||||
|
||||
// Sammle ALLE verschachtelten businessUserItems rekursiv
|
||||
$this->collectAllBusinessUserItemsFlat($businessUser->businessUserItems ?? [], $allUsers, $processedIds, 1);
|
||||
} else {
|
||||
\Log::debug("TeamController: Parentless-User übersprungen: {$userId} (bereits verarbeitet)");
|
||||
}
|
||||
} else {
|
||||
\Log::warning("TeamController: Parentless BusinessUser ohne user_id übersprungen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: AllUsers before filtering: " . count($allUsers));
|
||||
|
||||
// Filter anwenden
|
||||
$filteredUsers = $this->applyTeamFiltersToBusinessUsers($allUsers);
|
||||
\Log::info("TeamController: AllUsers after filtering: " . count($filteredUsers));
|
||||
|
||||
|
||||
return $filteredUsers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wendet Team-Filter auf BusinessUser-Objekte an
|
||||
*/
|
||||
|
|
@ -910,9 +927,9 @@ class TeamController extends Controller
|
|||
$activeFilter = Request::get('team_user_filter_active') ?: session('team_user_filter_active', 1);
|
||||
$levelFilter = Request::get('team_user_filter_level') ?: session('team_user_filter_level', 0);
|
||||
$nextLevelFilter = Request::get('team_user_filter_next_level') ?: session('team_user_filter_next_level', 0);
|
||||
|
||||
|
||||
\Log::info("TeamController: Applying filters - Active: {$activeFilter}, Level: {$levelFilter}, NextLevel: {$nextLevelFilter}");
|
||||
|
||||
|
||||
// Debug: Zeige verfügbare Eigenschaften des ersten BusinessUsers
|
||||
if (!empty($businessUsers)) {
|
||||
$firstUser = $businessUsers[0];
|
||||
|
|
@ -924,8 +941,8 @@ class TeamController extends Controller
|
|||
'next_can_user_level' => isset($firstUser->next_can_user_level) ? 'set' : 'not set',
|
||||
]);
|
||||
}
|
||||
|
||||
$filtered = array_filter($businessUsers, function($businessUser) use ($activeFilter, $levelFilter, $nextLevelFilter) {
|
||||
|
||||
$filtered = array_filter($businessUsers, function ($businessUser) use ($activeFilter, $levelFilter, $nextLevelFilter) {
|
||||
// Active Filter anwenden
|
||||
if ($activeFilter == 1) { // Nur aktive
|
||||
if (!$businessUser->active_account) {
|
||||
|
|
@ -937,19 +954,19 @@ class TeamController extends Controller
|
|||
}
|
||||
}
|
||||
// activeFilter == 3 bedeutet alle (keine Einschränkung)
|
||||
|
||||
|
||||
// Level Filter anwenden
|
||||
if ($levelFilter && $levelFilter != 0) {
|
||||
if ($businessUser->m_level_id != $levelFilter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Next Level Filter anwenden
|
||||
if ($nextLevelFilter && $nextLevelFilter != 0) {
|
||||
$hasNextQual = ($businessUser->next_qual_user_level) && $businessUser->next_qual_user_level !== '[]';
|
||||
$hasNextCan = ($businessUser->next_can_user_level) && $businessUser->next_can_user_level !== '[]';
|
||||
|
||||
|
||||
switch ($nextLevelFilter) {
|
||||
case 1: // Qualifiziert (grün) - hat next_qual_user_level
|
||||
if (!$hasNextQual) {
|
||||
|
|
@ -968,35 +985,153 @@ class TeamController extends Controller
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true; // Alle Filter bestanden
|
||||
});
|
||||
|
||||
|
||||
// Array-Indizes neu setzen für korrekte DataTable-Verarbeitung
|
||||
return array_values($filtered);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hilfsmethode zum rekursiven Sammeln von User-IDs aus BusinessUser-Struktur
|
||||
* NEUE OPTIMIERTE Methode: Sammelt ALLE BusinessUserItems in einer flachen Liste
|
||||
* Perfekt für DataTable-Verarbeitung - keine verschachtelte Struktur
|
||||
*/
|
||||
private function collectUserIdsFromBusinessUser($businessUser, &$allUsers, $deep, $parentless): void
|
||||
private function collectAllBusinessUserItemsFlat(array $businessUserItems, &$allUsers, &$processedIds, $depth = 1): void
|
||||
{
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
\Log::debug("TeamController: Collecting from businessUser with " . count($businessUser->businessUserItems) . " sub-items");
|
||||
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser) {
|
||||
$subBusinessUser->deep = $deep;
|
||||
$allUsers[] = $subBusinessUser;
|
||||
if($subBusinessUser->user_id){
|
||||
\Log::debug("TeamController: Collected user ID: " . $subBusinessUser->user_id);
|
||||
// Schutz vor zu tiefer Rekursion (maximale Tiefe: 20 Levels)
|
||||
$maxDepth = 20;
|
||||
if ($depth > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht bei Tiefe {$depth}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($businessUserItems as $businessUserItem) {
|
||||
if ($businessUserItem) {
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $businessUserItem->user_id; // Über __get() Method
|
||||
if ($userId) {
|
||||
// KRITISCHER SCHUTZ: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (Duplikat verhindert)");
|
||||
continue;
|
||||
}
|
||||
// Rekursiver Aufruf für weitere Unter-User
|
||||
$newDeep = $parentless ? 0 : $deep+1;
|
||||
$this->collectUserIdsFromBusinessUser($subBusinessUser, $allUsers, $newDeep, $parentless);
|
||||
|
||||
// User zu flacher Liste hinzufügen
|
||||
$processedIds[$userId] = true;
|
||||
$businessUserItem->deep = $depth;
|
||||
$allUsers[] = $businessUserItem;
|
||||
|
||||
\Log::debug("TeamController: Flach gesammelt - User ID: {$userId} at depth {$depth}");
|
||||
|
||||
// Rekursiv ALLE verschachtelten businessUserItems sammeln
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems) && !empty($businessUserItem->businessUserItems)) {
|
||||
\Log::debug("TeamController: Sammle " . count($businessUserItem->businessUserItems) . " verschachtelte Items von User {$userId}");
|
||||
$this->collectAllBusinessUserItemsFlat($businessUserItem->businessUserItems, $allUsers, $processedIds, $depth + 1);
|
||||
}
|
||||
} else {
|
||||
\Log::warning("TeamController: BusinessUserItem ohne user_id bei Tiefe {$depth} übersprungen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: Alte Methode zum rekursiven Sammeln von User-IDs aus BusinessUser-Struktur
|
||||
* Wird durch collectAllBusinessUserItemsFlat() ersetzt
|
||||
*/
|
||||
private function collectUserIdsFromBusinessUser($businessUser, &$allUsers, $deep, $parentless, &$processedIds = []): void
|
||||
{
|
||||
// Schutz vor zu tiefer Rekursion (maximale Tiefe: 20 Levels)
|
||||
$maxDepth = 20;
|
||||
if ($deep > $maxDepth) {
|
||||
\Log::warning("TeamController: Maximale Sammlungstiefe ({$maxDepth}) erreicht");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
\Log::debug("TeamController: Collecting from businessUser with " . count($businessUser->businessUserItems) . " sub-items at depth {$deep}");
|
||||
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser) {
|
||||
// WICHTIG: user_id korrekt über b_user abrufen (Magic Method Problem mit isset())
|
||||
$userId = $subBusinessUser->user_id; // Über __get() Method
|
||||
|
||||
if ($userId) {
|
||||
// KRITISCHER BUGFIX: Prüfe ob User bereits gesammelt wurde
|
||||
if (isset($processedIds[$userId])) {
|
||||
\Log::debug("TeamController: Überspringe bereits gesammelten User {$userId} (zirkuläre Referenz verhindert)");
|
||||
continue;
|
||||
}
|
||||
|
||||
$processedIds[$userId] = true;
|
||||
$subBusinessUser->deep = $deep;
|
||||
$allUsers[] = $subBusinessUser;
|
||||
|
||||
\Log::debug("TeamController: Collected user ID: {$userId} at depth {$deep}");
|
||||
|
||||
// Rekursiver Aufruf für weitere Unter-User mit Schutz vor Zyklen
|
||||
$newDeep = $parentless ? 0 : $deep + 1;
|
||||
$this->collectUserIdsFromBusinessUser($subBusinessUser, $allUsers, $newDeep, $parentless, $processedIds);
|
||||
} else {
|
||||
\Log::warning("TeamController: SubBusinessUser ohne user_id bei Tiefe {$deep} übersprungen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* KRITISCHE METHODE: Bereinigt BusinessUserItemOptimized Objekte für DataTables
|
||||
* Entfernt zirkuläre Referenzen und extrahiert nur nötige Properties
|
||||
*/
|
||||
private function cleanBusinessUserItemsForDataTable(array $businessUserItems): array
|
||||
{
|
||||
$cleanedUsers = [];
|
||||
|
||||
foreach ($businessUserItems as $businessUserItem) {
|
||||
if (!$businessUserItem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
// Extrahiere nur die Properties, die für DataTable benötigt werden
|
||||
$cleanedUser = new \stdClass();
|
||||
|
||||
// Basis Properties (direkt über Magic Method __get)
|
||||
$cleanedUser->user_id = $businessUserItem->user_id;
|
||||
$cleanedUser->m_account = $businessUserItem->m_account;
|
||||
$cleanedUser->email = $businessUserItem->email;
|
||||
$cleanedUser->first_name = $businessUserItem->first_name;
|
||||
$cleanedUser->last_name = $businessUserItem->last_name;
|
||||
$cleanedUser->user_level_name = $businessUserItem->user_level_name;
|
||||
$cleanedUser->active_account = $businessUserItem->active_account;
|
||||
$cleanedUser->active_date = $businessUserItem->active_date;
|
||||
|
||||
// Sales Volume Properties
|
||||
$cleanedUser->sales_volume_points_KP_sum = $businessUserItem->sales_volume_points_KP_sum ?? 0;
|
||||
$cleanedUser->payline_points_qual_kp = $businessUserItem->payline_points_qual_kp ?? 0;
|
||||
|
||||
// Depth für Debug/Sortierung (falls gesetzt)
|
||||
$cleanedUser->deep = $businessUserItem->deep ?? 0;
|
||||
|
||||
// Level-Informationen für Filter
|
||||
$cleanedUser->m_level_id = $businessUserItem->m_level_id;
|
||||
$cleanedUser->next_qual_user_level = $businessUserItem->next_qual_user_level;
|
||||
$cleanedUser->next_can_user_level = $businessUserItem->next_can_user_level;
|
||||
|
||||
$cleanedUsers[] = $cleanedUser;
|
||||
|
||||
\Log::debug("TeamController: Cleaned user {$cleanedUser->user_id} for DataTable");
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("TeamController: Error cleaning BusinessUserItem for DataTable: " . $e->getMessage());
|
||||
// Skip diesen User, statt alles abzubrechen
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
\Log::info("TeamController: Cleaned " . count($cleanedUsers) . " users for DataTable (from " . count($businessUserItems) . " raw items)");
|
||||
|
||||
return $cleanedUsers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/UserDataController.php
Executable file → Normal file
0
app/Http/Controllers/UserDataController.php
Executable file → Normal file
0
app/Http/Controllers/UserDeleteController.php
Executable file → Normal file
0
app/Http/Controllers/UserDeleteController.php
Executable file → Normal file
0
app/Http/Controllers/UserLevelController.php
Executable file → Normal file
0
app/Http/Controllers/UserLevelController.php
Executable file → Normal file
0
app/Http/Controllers/UserShopController.php
Executable file → Normal file
0
app/Http/Controllers/UserShopController.php
Executable file → Normal file
0
app/Http/Controllers/UserUpdateEmailController.php
Executable file → Normal file
0
app/Http/Controllers/UserUpdateEmailController.php
Executable file → Normal file
0
app/Http/Controllers/UserUpdatePasswordController.php
Executable file → Normal file
0
app/Http/Controllers/UserUpdatePasswordController.php
Executable file → Normal file
0
app/Http/Controllers/Web/CardController.php
Executable file → Normal file
0
app/Http/Controllers/Web/CardController.php
Executable file → Normal file
4
app/Http/Controllers/Web/CheckoutController.php
Executable file → Normal file
4
app/Http/Controllers/Web/CheckoutController.php
Executable file → Normal file
|
|
@ -243,7 +243,7 @@ class CheckoutController extends Controller
|
|||
// Kreditkarte prüfen
|
||||
if ($payment_method === 'cc') {
|
||||
$result = $this->checkCreditCard($data, $shopping_user, $shopping_order);
|
||||
if (!isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
if (!is_array($result) || !isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ class CheckoutController extends Controller
|
|||
// SEPA prüfen
|
||||
if ($payment_method === 'elv') {
|
||||
$result = $this->checkSepaAccount($data, $shopping_user, $shopping_order);
|
||||
if (!isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
if (!is_array($result) || !isset($result['returnstatus']) || $result['returnstatus'] !== 'VALID') {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Controllers/Web/ContactController.php
Executable file → Normal file
0
app/Http/Controllers/Web/ContactController.php
Executable file → Normal file
0
app/Http/Controllers/Web/HomepartyController.php
Executable file → Normal file
0
app/Http/Controllers/Web/HomepartyController.php
Executable file → Normal file
55
app/Http/Controllers/Web/RegisterController.php
Executable file → Normal file
55
app/Http/Controllers/Web/RegisterController.php
Executable file → Normal file
|
|
@ -39,6 +39,18 @@ class RegisterController extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
\Log::channel('doamin')->debug('RegisterController: index - Session user_shop', [
|
||||
'session_user_shop_id' => \Session::get('user_shop')?->id,
|
||||
'session_user_shop_name' => \Session::get('user_shop')?->name,
|
||||
'session_user_shop_user_id' => \Session::get('user_shop')?->user_id,
|
||||
'session_id' => \Session::getId(),
|
||||
'session_domain' => config('session.domain'),
|
||||
'request_host' => request()->getHost(),
|
||||
'all_session_keys' => array_keys(\Session::all())
|
||||
]);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'GOOGLE_ReCAPTCHA_KEY' => $this->GOOGLE_ReCAPTCHA_KEY,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
|
|
@ -49,12 +61,12 @@ class RegisterController extends Controller
|
|||
|
||||
public function member($member_id = false)
|
||||
{
|
||||
if(!$member_id){
|
||||
if (!$member_id) {
|
||||
return redirect('/registrierung');
|
||||
}
|
||||
$user_id = (int) str_replace('m', '', $member_id) - config('mivita.add_number_id');
|
||||
$user = User::find($user_id);
|
||||
if(!$user || !$user->isActive() || !$user->isActiveAccount()){
|
||||
if (!$user || !$user->isActive() || !$user->isActiveAccount()) {
|
||||
return redirect('/registrierung');
|
||||
}
|
||||
$data = [
|
||||
|
|
@ -66,22 +78,23 @@ class RegisterController extends Controller
|
|||
return view('web.templates.registrierung', $data);
|
||||
}
|
||||
|
||||
public function register(){
|
||||
public function register()
|
||||
{
|
||||
|
||||
$rules = array(
|
||||
'salutation' => 'required',
|
||||
'first_name'=>'required',
|
||||
'last_name'=>'required',
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'email-confirm' => 'required|same:email',
|
||||
'password' => 'required|string|min:6|confirmed',
|
||||
'password_confirmation' => 'required|string|min:6',
|
||||
'g-recaptcha-response'=>'required|recaptcha',
|
||||
'g-recaptcha-response' => 'required|recaptcha',
|
||||
'accepted_data_protection' => 'required',
|
||||
);
|
||||
|
||||
Validator::extend('recaptcha', function($attribute, $value, $parameters, $validator) {
|
||||
return $this->reCaptcha_validate($attribute, $value, $parameters, $validator);
|
||||
Validator::extend('recaptcha', function ($attribute, $value, $parameters, $validator) {
|
||||
return $this->reCaptcha_validate($attribute, $value, $parameters, $validator);
|
||||
});
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
|
@ -90,16 +103,15 @@ class RegisterController extends Controller
|
|||
}
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
$data = Request::all();
|
||||
$user = $this->userRepo->create($data);
|
||||
|
||||
$confirmation_code = UserService::createConfirmationCode();
|
||||
$m_sponsor_id = 1;
|
||||
if($user_shop){
|
||||
if ($user_shop) {
|
||||
$m_sponsor_id = $user_shop->user->id;
|
||||
}
|
||||
if(isset($data['from_member_id'])){
|
||||
if (isset($data['from_member_id'])) {
|
||||
$m_sponsor_id = (int) str_replace('m', '', $data['from_member_id']) - config('mivita.add_number_id');
|
||||
}
|
||||
$user->lang = !empty(\App::getLocale()) ? \App::getLocale() : "de";
|
||||
|
|
@ -109,22 +121,19 @@ class RegisterController extends Controller
|
|||
$user->m_sponsor = $m_sponsor_id;
|
||||
|
||||
$UserLevel = UserLevel::where('default', 1)->first();
|
||||
if($UserLevel){
|
||||
if ($UserLevel) {
|
||||
$user->m_level = $UserLevel->id;
|
||||
}else{
|
||||
} else {
|
||||
$user->m_level = 10;
|
||||
|
||||
}
|
||||
|
||||
|
||||
$user->save();
|
||||
|
||||
$user->account->data_protection = now();
|
||||
$user->account->save();
|
||||
|
||||
Mail::to($user->email)->locale($user->getLocale())->send(new MailVerifyAccount($confirmation_code, $user));
|
||||
Mail::to($user->email)->locale($user->getLocale())->send(new MailVerifyAccount($confirmation_code, User::find($user->id)));
|
||||
return redirect('/registrierung/finish');
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function finish()
|
||||
|
|
@ -135,7 +144,7 @@ class RegisterController extends Controller
|
|||
];
|
||||
return view('web.templates.registrierung_finish', $data);
|
||||
}
|
||||
|
||||
|
||||
private function reCaptcha_validate($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
|
||||
|
|
@ -143,7 +152,8 @@ class RegisterController extends Controller
|
|||
|
||||
$response = $client->post(
|
||||
'https://www.google.com/recaptcha/api/siteverify',
|
||||
['form_params' =>
|
||||
[
|
||||
'form_params' =>
|
||||
[
|
||||
'secret' => $this->GOOGLE_ReCAPTCHA_SECRET,
|
||||
'response' => $value
|
||||
|
|
@ -154,7 +164,4 @@ class RegisterController extends Controller
|
|||
$body = json_decode((string)$response->getBody());
|
||||
return $body->success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
app/Http/Controllers/Web/SiteController.php
Executable file → Normal file
66
app/Http/Controllers/Web/SiteController.php
Executable file → Normal file
|
|
@ -20,7 +20,7 @@ class SiteController extends Controller
|
|||
{
|
||||
$this->setIPInfo();
|
||||
$products = ['aloe-vera-gel-99', 'aloe-vera-saft-500-ml', 'aloe-vera-lippenbalsam'];
|
||||
// $set_products = ['aloe-vera-cleaner-set', 'aloe-vera-koerper-set', 'aloe-vera-repair-set'];
|
||||
// $set_products = ['aloe-vera-cleaner-set', 'aloe-vera-koerper-set', 'aloe-vera-repair-set'];
|
||||
$set_products = ['aloe-vera-koerper-set', 'baby-set', 'aloe-vera-gel-set'];
|
||||
$data = [
|
||||
'products' => Product::whereIn('slug', $products)->where('active', true)->whereJsonContains('show_on', '1')->get(),
|
||||
|
|
@ -34,16 +34,18 @@ class SiteController extends Controller
|
|||
return view('web.index', $data);
|
||||
}
|
||||
|
||||
public function domainCheck(){
|
||||
public function domainCheck()
|
||||
{
|
||||
die("checked");
|
||||
}
|
||||
|
||||
public function changeLang(){
|
||||
public function changeLang()
|
||||
{
|
||||
$data = Request::all();
|
||||
if(isset($data['change_country_id'])){
|
||||
if (isset($data['change_country_id'])) {
|
||||
$mylangs = Shop::getLangChange('webshop');
|
||||
foreach($mylangs as $code => $country){
|
||||
if(strtolower($data['change_country_id']) === strtolower($code)){
|
||||
foreach ($mylangs as $code => $country) {
|
||||
if (strtolower($data['change_country_id']) === strtolower($code)) {
|
||||
\Session::put('user_init_country', strtolower($code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower($data['change_locale_id']));
|
||||
|
|
@ -58,41 +60,41 @@ class SiteController extends Controller
|
|||
{
|
||||
//wurde schon gesetzt //cache
|
||||
$country = strtolower(Shop::getIPDatabaseInfo());
|
||||
if(\Session::has('user_init_country')){
|
||||
if (\Session::has('user_init_country')) {
|
||||
return;
|
||||
}
|
||||
if(config('app.ipinfo')){
|
||||
if (config('app.ipinfo')) {
|
||||
$country = strtolower(Shop::getIPDatabaseInfo());
|
||||
if($country === 'de'){ //$locale de - init AT
|
||||
if ($country === 'de') { //$locale de - init AT
|
||||
\Session::put('user_init_country', $country);
|
||||
return;
|
||||
}
|
||||
if($country === 'error'){ //$locale at - init AT
|
||||
if ($country === 'error') { //$locale at - init AT
|
||||
$country = 'de';
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$country = 'de';
|
||||
}
|
||||
}
|
||||
|
||||
//$locale = strtolower(\App::getLocale());
|
||||
//ist default
|
||||
|
||||
|
||||
//sprache
|
||||
if(array_key_exists($country, \App\Services\UserService::getTransChange())){
|
||||
if (array_key_exists($country, \App\Services\UserService::getTransChange())) {
|
||||
\Session::put('user_init_country', $country);
|
||||
\Session::put('locale', $country);
|
||||
\App::setLocale($country);
|
||||
}else{
|
||||
} else {
|
||||
//default EN
|
||||
\Session::put('user_init_country', 'de');
|
||||
\Session::put('locale', 'de');
|
||||
\App::setLocale('de');
|
||||
}
|
||||
}
|
||||
|
||||
//bestelland / versandland
|
||||
if(array_key_exists($country, Shop::getLangChange('webshop'))){
|
||||
if (array_key_exists($country, Shop::getLangChange('webshop'))) {
|
||||
\Session::put('user_init_country_options', $country);
|
||||
}else{
|
||||
} else {
|
||||
\Session::put('user_init_country_options', 'de');
|
||||
}
|
||||
|
||||
|
|
@ -101,11 +103,10 @@ class SiteController extends Controller
|
|||
|
||||
public function site($site, $subsite = false, $product_slug = false)
|
||||
{
|
||||
|
||||
$this->setIPInfo();
|
||||
$subsite = trim($subsite, '/');
|
||||
$product_slug = trim($product_slug, '/');
|
||||
if($product_slug){
|
||||
if ($product_slug) {
|
||||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
$product = Product::where('slug', $product_slug)->where('active', true)->whereJsonContains('show_on', '1')->first();
|
||||
if ($category && $product) {
|
||||
|
|
@ -121,13 +122,12 @@ class SiteController extends Controller
|
|||
return view('web.templates.produkte-show', $data);
|
||||
}
|
||||
}
|
||||
|
||||
if($site === 'produkte'){
|
||||
if($subsite || $subsite !== 'alle-produkte') {
|
||||
if ($site == 'produkte') {
|
||||
if ($subsite || $subsite !== 'alle-produkte') {
|
||||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
if ($category) {
|
||||
$headline_image = false;
|
||||
if($category->headline_image_id && $category->iq_image && $category->iq_image->active){
|
||||
if ($category->headline_image_id && $category->iq_image && $category->iq_image->active) {
|
||||
$headline_image = $category->iq_image;
|
||||
}
|
||||
|
||||
|
|
@ -148,9 +148,9 @@ class SiteController extends Controller
|
|||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.' . $site, $data);
|
||||
|
||||
}
|
||||
}
|
||||
dd($subsite);
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
|
|
@ -163,22 +163,22 @@ class SiteController extends Controller
|
|||
'headline_image' => false,
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
return view('web.templates.'.$site, $data);
|
||||
return view('web.templates.' . $site, $data);
|
||||
}
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'mylangs' => Shop::getLangChange('webshop'),
|
||||
'yard_instance' => 'webshop',
|
||||
];
|
||||
if($subsite){
|
||||
if(!view()->exists('web.templates.'.$subsite)){
|
||||
];
|
||||
if ($subsite) {
|
||||
if (!view()->exists('web.templates.' . $subsite)) {
|
||||
abort(404);
|
||||
}
|
||||
return view('web.templates.'.$subsite, $data);
|
||||
return view('web.templates.' . $subsite, $data);
|
||||
}
|
||||
if(!view()->exists('web.templates.'.$site)){
|
||||
if (!view()->exists('web.templates.' . $site)) {
|
||||
abort(404);
|
||||
}
|
||||
return view('web.templates.'.$site, $data);
|
||||
return view('web.templates.' . $site, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
204
app/Http/Controllers/WizardController.php
Executable file → Normal file
204
app/Http/Controllers/WizardController.php
Executable file → Normal file
|
|
@ -38,17 +38,16 @@ class WizardController extends Controller
|
|||
public function __construct(FileRepository $fileRepo)
|
||||
{
|
||||
$this->fileRepo = $fileRepo;
|
||||
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if(!Auth::check()){
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if(!$user->account){
|
||||
if (!$user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
|
@ -57,7 +56,7 @@ class WizardController extends Controller
|
|||
|
||||
$step = !$user->wizard ? 0 : $user->wizard;
|
||||
|
||||
if($step >= 20){
|
||||
if ($step >= 20) {
|
||||
return redirect('/home');
|
||||
}
|
||||
$userHistoryWizardPayment = UserHistory::whereUserId($user->id)->whereAction('wizard_payment')->get()->last();
|
||||
|
|
@ -70,7 +69,7 @@ class WizardController extends Controller
|
|||
'userHistoryWizardPayment' => $userHistoryWizardPayment,
|
||||
];
|
||||
|
||||
if($step == 15){
|
||||
if ($step == 15) {
|
||||
return view('user.wizard.create_release', $data);
|
||||
}
|
||||
|
||||
|
|
@ -80,11 +79,11 @@ class WizardController extends Controller
|
|||
public function register()
|
||||
{
|
||||
|
||||
if(!Auth::check()){
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if(!$user->account){
|
||||
if (!$user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
|
@ -93,7 +92,7 @@ class WizardController extends Controller
|
|||
|
||||
$step = !$user->wizard ? 0 : $user->wizard;
|
||||
|
||||
if($step >= 10){
|
||||
if ($step >= 10) {
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
|
|
@ -103,8 +102,8 @@ class WizardController extends Controller
|
|||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '9')->orderBy('pos', 'ASC')->get(),
|
||||
];
|
||||
if($step == 5){
|
||||
if($user->active){
|
||||
if ($step == 5) {
|
||||
if ($user->active) {
|
||||
$user->active = false;
|
||||
$user->save();
|
||||
}
|
||||
|
|
@ -116,12 +115,12 @@ class WizardController extends Controller
|
|||
|
||||
public function payment()
|
||||
{
|
||||
if(!Auth::check()){
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if(!$user->account){
|
||||
if (!$user->account) {
|
||||
$account = UserAccount::create([]);
|
||||
$user->account_id = $account->id;
|
||||
$user->save();
|
||||
|
|
@ -129,9 +128,9 @@ class WizardController extends Controller
|
|||
}
|
||||
|
||||
$userHistoryWizardPayment = UserHistory::whereUserId($user->id)->whereAction('wizard_payment')->get()->last();
|
||||
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (!$shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
|
|
@ -149,23 +148,24 @@ class WizardController extends Controller
|
|||
];
|
||||
|
||||
|
||||
if($user->wizard == 20){
|
||||
if ($user->wizard == 20) {
|
||||
return view('user.wizard.register_payment', $data);
|
||||
}
|
||||
|
||||
return redirect(route('/'));
|
||||
return redirect(url('/'));
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($user ){
|
||||
private function checkShoppingCountry($user)
|
||||
{
|
||||
|
||||
$country_id = null;
|
||||
if($user->account->same_as_billing){
|
||||
if ($user->account->same_as_billing) {
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
} else {
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
if ($country_id) {
|
||||
if ($shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +185,7 @@ class WizardController extends Controller
|
|||
|
||||
|
||||
$data = Request::all();
|
||||
if($step == 7 && Request::get('user_country_id')){
|
||||
if ($step == 7 && Request::get('user_country_id')) {
|
||||
$user->account->country_id = Request::get('user_country_id');
|
||||
$user->account->save();
|
||||
return redirect(route('wizard_register', [1]));
|
||||
|
|
@ -209,14 +209,14 @@ class WizardController extends Controller
|
|||
return view('user.wizard.register', $data)->withErrors($validator);
|
||||
}
|
||||
$account = $user->account;
|
||||
if($account->accepted_contract === null){
|
||||
if ($account->accepted_contract === null) {
|
||||
$account->accepted_contract = now();
|
||||
}
|
||||
if($account->data_protection === null){
|
||||
if ($account->data_protection === null) {
|
||||
$account->data_protection = now();
|
||||
}
|
||||
$account->save();
|
||||
if($user->agreement === null){
|
||||
if ($user->agreement === null) {
|
||||
$user->agreement = now();
|
||||
}
|
||||
|
||||
|
|
@ -227,20 +227,20 @@ class WizardController extends Controller
|
|||
if ($step == 1) {
|
||||
|
||||
$data = Request::all();
|
||||
if(isset($data['action']) && $data['action'] == "reverse_charge_validate"){
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_validate") {
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
return $userRepo->reverse_charge_validate($data, $user, route('wizard_register', [0]));
|
||||
}
|
||||
|
||||
if(isset($data['action']) && $data['action'] == "reverse_charge_delete"){
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_delete") {
|
||||
$user->wizard = 1;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
return $userRepo->reverse_charge_delete($data, $user, route('wizard_register', [0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$rules = array(
|
||||
'salutation' => 'required',
|
||||
'first_name' => 'required',
|
||||
|
|
@ -282,31 +282,31 @@ class WizardController extends Controller
|
|||
}
|
||||
|
||||
if ($step == 2) {
|
||||
if(Request::get('submit') === 'do'){
|
||||
if(File::whereUserId($user->id)->whereIdentifier('id_card')->count() == 0){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_id_card_deposited_please_upload_first'));
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
if (Request::get('submit') === 'do') {
|
||||
if (File::whereUserId($user->id)->whereIdentifier('id_card')->count() == 0) {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_id_card_deposited_please_upload_first'));
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
return redirect(route('wizard_register'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('dir', '/' . $user->id . '/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'id_card');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
}
|
||||
|
||||
if ($step == 3) {
|
||||
if(Request::get('submit') === 'do'){
|
||||
if (Request::get('submit') === 'do') {
|
||||
$data = Request::all();
|
||||
|
||||
if($data['business_license_choose'] === "now"){
|
||||
if(File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0){
|
||||
if ($data['business_license_choose'] === "now") {
|
||||
if (File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0) {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_trade_licence_deposited_please_upload_first'));
|
||||
$user->wizard = 3;
|
||||
|
|
@ -314,17 +314,16 @@ class WizardController extends Controller
|
|||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
if($data['business_license_choose'] === "later"){
|
||||
|
||||
if ($data['business_license_choose'] === "later") {
|
||||
}
|
||||
if($data['business_license_choose'] === "non"){
|
||||
if(!$data['non_business_license_reason'] || $data['non_business_license_reason'] == ""){
|
||||
if ($data['business_license_choose'] === "non") {
|
||||
if (!$data['non_business_license_reason'] || $data['non_business_license_reason'] == "") {
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.please_enter_reason_why_you_not_need_trade_licence'));
|
||||
$user->wizard = 3;
|
||||
$user->save();
|
||||
return redirect(route('wizard_register'))->withErrors($validator)->withInput(Request::all());
|
||||
}else{
|
||||
} else {
|
||||
$user->account->setNotice('business_license_reason', $data['non_business_license_reason']);
|
||||
}
|
||||
}
|
||||
|
|
@ -336,7 +335,7 @@ class WizardController extends Controller
|
|||
return redirect(route('wizard_register'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('dir', '/' . $user->id . '/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'business_license');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
|
|
@ -371,13 +370,13 @@ class WizardController extends Controller
|
|||
$user->m_sponsor = $user->m_sponsor ? $user->m_sponsor : 1;
|
||||
$user->account->m_first_name = $user->account->m_first_name ? $user->account->m_first_name : $user->account->first_name;
|
||||
$user->account->m_last_name = $user->account->m_last_name ? $user->account->m_last_name : $user->account->last_name;
|
||||
$user->account->m_account = UserAccount::withTrashed()->max('m_account') +1;
|
||||
$user->account->m_account = UserAccount::withTrashed()->max('m_account') + 1;
|
||||
$user->account->save();
|
||||
$user->save();
|
||||
//create PDF
|
||||
$pdf = new ContractPDFRepository($user);
|
||||
$pdf->_set('disk', 'user');
|
||||
$pdf->_set('dir', '/'.$user->id.'/documents/');
|
||||
$pdf->_set('dir', '/' . $user->id . '/documents/');
|
||||
$pdf->_set('user_id', $user->id);
|
||||
$pdf->_set('identifier', 'contract');
|
||||
$pdf->createContractPDF();
|
||||
|
|
@ -393,15 +392,15 @@ class WizardController extends Controller
|
|||
$user->save();
|
||||
|
||||
//mail with code to user?
|
||||
if($user->isTestMode()){
|
||||
if ($user->isTestMode()) {
|
||||
$mail = config('app.info_test_mail');
|
||||
}else{
|
||||
} else {
|
||||
$mail = config('app.info_mail');
|
||||
}
|
||||
Mail::to($mail)->locale($user->getLocale())->send(new MailAutoReleaseAccount($user));
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'release_account', 'status'=>0]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'release_account', 'status' => 0]);
|
||||
Mail::to($user->email)->locale($user->getLocale())->send(new MailAccountActive($user));
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'released_completed', 'status'=>0]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'released_completed', 'status' => 0]);
|
||||
\Session()->flash('alert-success', __('msg.account_released'));
|
||||
return redirect(route('wizard_payment'));
|
||||
}
|
||||
|
|
@ -409,16 +408,16 @@ class WizardController extends Controller
|
|||
public function storeCreate($step = 0)
|
||||
{
|
||||
|
||||
if(!Auth::check()){
|
||||
if (!Auth::check()) {
|
||||
return redirect('login');
|
||||
}
|
||||
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
if(!$user->account){
|
||||
if (!$user->account) {
|
||||
$user->account = new UserAccount();
|
||||
}
|
||||
|
||||
if($step == 10){
|
||||
if ($step == 10) {
|
||||
$rules = array(
|
||||
'accepted_data_protection' => 'required',
|
||||
'accepted_active' => 'required',
|
||||
|
|
@ -434,17 +433,16 @@ class WizardController extends Controller
|
|||
$user->wizard = 10;
|
||||
$user->save();
|
||||
return view('user.wizard.create', $data)->withErrors($validator);
|
||||
|
||||
}
|
||||
$account = $user->account;
|
||||
if($account->accepted_contract === null){
|
||||
if ($account->accepted_contract === null) {
|
||||
$account->accepted_contract = now();
|
||||
}
|
||||
if($account->data_protection === null){
|
||||
if ($account->data_protection === null) {
|
||||
$account->data_protection = now();
|
||||
}
|
||||
$account->save();
|
||||
if($user->agreement === null){
|
||||
if ($user->agreement === null) {
|
||||
$user->agreement = now();
|
||||
}
|
||||
$user->wizard = 11;
|
||||
|
|
@ -452,9 +450,9 @@ class WizardController extends Controller
|
|||
|
||||
return redirect(route('wizard_create', [11]));
|
||||
}
|
||||
if($step == 11){
|
||||
if ($step == 11) {
|
||||
|
||||
if($user->isPasswort()){
|
||||
if ($user->isPasswort()) {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
return redirect(route('wizard_create', [12]));
|
||||
|
|
@ -481,23 +479,23 @@ class WizardController extends Controller
|
|||
$user->save();
|
||||
return redirect(route('wizard_create', [12]));
|
||||
}
|
||||
if($step == 12){
|
||||
if ($step == 12) {
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
if(isset($data['action']) && $data['action'] == "reverse_charge_validate"){
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_validate") {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
return $userRepo->reverse_charge_validate($data, $user, route('wizard_create', [12]));
|
||||
}
|
||||
|
||||
if(isset($data['action']) && $data['action'] == "reverse_charge_delete"){
|
||||
|
||||
if (isset($data['action']) && $data['action'] == "reverse_charge_delete") {
|
||||
$user->wizard = 12;
|
||||
$user->save();
|
||||
$user->save();
|
||||
$userRepo = new UserRepository($user);
|
||||
return $userRepo->reverse_charge_delete($data, $user, route('wizard_create', [12]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$rules = array(
|
||||
|
|
@ -513,12 +511,12 @@ class WizardController extends Controller
|
|||
'birthday' => 'required',
|
||||
);
|
||||
|
||||
if(!Request::get('same_as_billing')){
|
||||
if (!Request::get('same_as_billing')) {
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
|
||||
|
|
@ -541,59 +539,59 @@ class WizardController extends Controller
|
|||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
return redirect(route('wizard_create', [13]));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function storePayment($step = 0){
|
||||
public function storePayment($step = 0)
|
||||
{
|
||||
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
if (Request::get('switchers-package-wizard')) {
|
||||
$user = User::find(Auth::user()->id);
|
||||
Yard::instance('shopping')->destroy();
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
$showAboOptions = false;
|
||||
if(Request::get('abo_options')){
|
||||
if (Request::get('abo_options')) {
|
||||
$showAboOptions = false; //true Abo Option deaktivert
|
||||
$user->abo_options = false; //true Abo Option deaktivert
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
if (!$shipping_country_id) {
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
|
||||
|
||||
|
||||
if($product && $product->active){
|
||||
if ($product && $product->active) {
|
||||
//set membership product
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
if(\App\Services\UserService::getTaxFree()){
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
|
||||
|
||||
//set onboarding products
|
||||
if(Request::get('products_on_board')){
|
||||
foreach (Request::get('products_on_board') as $product_on_board_id){
|
||||
if (Request::get('products_on_board')) {
|
||||
foreach (Request::get('products_on_board') as $product_on_board_id) {
|
||||
$product_on_board = Product::find($product_on_board_id);
|
||||
$image = "";
|
||||
if($product_on_board->images->count()){
|
||||
if ($product_on_board->images->count()) {
|
||||
$image = $product_on_board->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, $product_on_board->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product_on_board->slug, 'weight' => $product_on_board->weight, 'points' => $product_on_board->points, 'no_commission' => $product_on_board->no_commission, 'show_on' => $product_on_board->show_on]);
|
||||
if(\App\Services\UserService::getTaxFree()){
|
||||
if (\App\Services\UserService::getTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
}
|
||||
|
|
@ -601,7 +599,7 @@ class WizardController extends Controller
|
|||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'wizard';
|
||||
|
|
@ -622,29 +620,27 @@ class WizardController extends Controller
|
|||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'wizard_payment', 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action' => 'wizard_payment', 'status' => 1, 'product_id' => $product->id, 'identifier' => $identifier, 'abo_options' => $showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
|
||||
}
|
||||
}
|
||||
\Session()->flash('alert-error', "Fehler beim Produkt");
|
||||
return back();
|
||||
}
|
||||
|
||||
public function delete($id, $relation){
|
||||
public function delete($id, $relation)
|
||||
{
|
||||
|
||||
if($relation === 'upload'){
|
||||
if ($relation === 'upload') {
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
$file = $user->files()->findOrFail($id);
|
||||
//remove file
|
||||
\Storage::disk('user')->delete($file->dir.$file->filename);
|
||||
\Storage::disk('user')->delete($file->dir . $file->filename);
|
||||
$file->delete();
|
||||
\Session()->flash('alert-success', __('msg.file_deleted'));
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
app/Http/Kernel.php
Executable file → Normal file
6
app/Http/Kernel.php
Executable file → Normal file
|
|
@ -19,7 +19,7 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
# \App\Http\Middleware\RemoveExcessWhitespaceMiddleware::class,
|
||||
# \App\Http\Middleware\RemoveExcessWhitespaceMiddleware::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -32,8 +32,10 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
// WICHTIG: Nach StartSession, vor VerifyCsrfToken
|
||||
\App\Http\Middleware\SubdomainResolver::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\Localization::class,
|
||||
|
|
|
|||
0
app/Http/Middleware/ActiveAccount.php
Executable file → Normal file
0
app/Http/Middleware/ActiveAccount.php
Executable file → Normal file
0
app/Http/Middleware/ActiveShop.php
Executable file → Normal file
0
app/Http/Middleware/ActiveShop.php
Executable file → Normal file
0
app/Http/Middleware/Admin.php
Executable file → Normal file
0
app/Http/Middleware/Admin.php
Executable file → Normal file
23
app/Http/Middleware/Checkout.php
Executable file → Normal file
23
app/Http/Middleware/Checkout.php
Executable file → Normal file
|
|
@ -27,33 +27,33 @@ class Checkout
|
|||
'host' => $request->getHost()
|
||||
]);
|
||||
$instance = 'checkout';
|
||||
if($shopping_instance = ShoppingInstance::where('identifier', $request->route('identifier'))->first()){
|
||||
if ($shopping_instance = ShoppingInstance::where('identifier', $request->route('identifier'))->first()) {
|
||||
//user shop
|
||||
//set Lang
|
||||
\Session::put('locale', $shopping_instance->getLocale());
|
||||
\App::setLocale($shopping_instance->getLocale());
|
||||
$user_shop = $shopping_instance->user_shop;
|
||||
|
||||
if($user_shop && $user_shop->active == 1 && $user_shop->user->isActiveShop()){
|
||||
if ($user_shop && $user_shop->active == 1 && $user_shop->user->isActiveShop()) {
|
||||
Util::setPostRoute('user/');
|
||||
\Session::put('user_shop', $user_shop);
|
||||
\Session::put('user_shop_domain', $shopping_instance->subdomain);
|
||||
\Session::put('user_shop_payment', $shopping_instance->payment);
|
||||
\Session::put('user_shop_identifier', $shopping_instance->identifier);
|
||||
|
||||
if($shopping_instance->auth_user_id){
|
||||
if ($shopping_instance->auth_user_id) {
|
||||
\Session::put('auth_user', $shopping_instance->auth_user);
|
||||
}
|
||||
}
|
||||
if($shopping_instance->back){
|
||||
if ($shopping_instance->back) {
|
||||
\Session::put('back_link', $shopping_instance->back);
|
||||
}
|
||||
\Session::put('new_session', true);
|
||||
Yard::instance($instance)->destroy();
|
||||
//restore yard
|
||||
if($shopping_instance->payment !== 6){
|
||||
if ($shopping_instance->payment !== 6) {
|
||||
Yard::instance($instance)->restore($request->route('identifier'), [], true, $instance);
|
||||
}else{
|
||||
} else {
|
||||
//dont delete shopping instance
|
||||
Yard::instance($instance)->restore($request->route('identifier'), [], false, $instance);
|
||||
}
|
||||
|
|
@ -65,21 +65,20 @@ class Checkout
|
|||
|
||||
Yard::instance($instance)->setUserPriceInfos($shopping_instance->shopping_data['user_price_infos']);
|
||||
Yard::instance($instance)->setShippingCountryWithPrice($shopping_instance->country_id, $is_for);
|
||||
|
||||
if($shopping_instance->payment !== 6){
|
||||
|
||||
if ($shopping_instance->payment !== 6) {
|
||||
//delete shopping instance is not save for restore, payment link
|
||||
ShoppingInstance::where('identifier', $request->route('identifier'))->delete();
|
||||
}
|
||||
|
||||
|
||||
$request->route()->forgetParameter('identifier');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
// \Session::has('user_shop_identifier')
|
||||
if(\Session::has('user_shop') && Yard::instance($instance)->count() > 0){
|
||||
if (\Session::has('user_shop') && Yard::instance($instance)->count() > 0) {
|
||||
return $next($request);
|
||||
}
|
||||
return redirect(Util::getUserCardBackUrl('/card/show', 'checkout'));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
app/Http/Middleware/EncryptCookies.php
Executable file → Normal file
0
app/Http/Middleware/EncryptCookies.php
Executable file → Normal file
0
app/Http/Middleware/Localization.php
Executable file → Normal file
0
app/Http/Middleware/Localization.php
Executable file → Normal file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file → Normal file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file → Normal file
0
app/Http/Middleware/RemoveExcessWhitespaceMiddleware.php
Executable file → Normal file
0
app/Http/Middleware/RemoveExcessWhitespaceMiddleware.php
Executable file → Normal file
255
app/Http/Middleware/SubdomainResolver.php
Normal file
255
app/Http/Middleware/SubdomainResolver.php
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Domain\EarlyDomainParser;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Util;
|
||||
use Closure;
|
||||
use Config;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Lightweight subdomain resolution middleware
|
||||
*
|
||||
* Uses config/domains.php for domain configuration and provides
|
||||
* simple, working subdomain handling without session timing issues.
|
||||
*/
|
||||
class SubdomainResolver
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Skip for API and asset requests
|
||||
if (!$this->shouldProcess($request)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Parse domain information using config/domains.php
|
||||
$host = $request->getHost();
|
||||
$domainInfo = EarlyDomainParser::parseDomain($host);
|
||||
Session::put('domainInfo', $domainInfo);
|
||||
\Log::info('domainInfo', $domainInfo);
|
||||
// Route to appropriate handler based on domain type
|
||||
return match ($domainInfo['type']) {
|
||||
'user-shop' => $this->handleUserShop($request, $next, $domainInfo),
|
||||
'main-shop' => $this->handleMainShop($request, $next, $domainInfo),
|
||||
'main' => $this->handleMainCare($request, $next, $domainInfo),
|
||||
'crm' => $this->handleCrm($request, $next, $domainInfo),
|
||||
'portal' => $this->handlePortal($request, $next, $domainInfo),
|
||||
'checkout' => $this->handleCheckout($request, $next, $domainInfo),
|
||||
default => $this->handleUnknownDomain($request, $domainInfo),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle user shop subdomain (e.g., user.mivita.care)
|
||||
*/
|
||||
private function handleUserShop($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
$subdomain = $domainInfo['subdomain'];
|
||||
$userShop = UserShop::where('slug', $subdomain)->first();
|
||||
|
||||
// Remove subdomain parameter from route
|
||||
if ($request->route('subdomain')) {
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
}
|
||||
|
||||
if (!$userShop) {
|
||||
return $this->handleUnknownDomain($request, $domainInfo);
|
||||
}
|
||||
|
||||
// Validate shop status
|
||||
if (!$userShop->active || !$userShop->user || !$userShop->user->isActiveShop()) {
|
||||
//hier ein routing zu shop???
|
||||
abort(503, 'Shop temporarily unavailable');
|
||||
}
|
||||
$host = $this->getHost($domainInfo);
|
||||
// Configure session domain based on domain config
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Set up application context
|
||||
$this->setupUserShopContext($userShop, $subdomain, $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle main shop domain (e.g., mivita.shop)
|
||||
*/
|
||||
private function handleMainShop($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Load default shop from domain config
|
||||
$defaultShop = isset($domainInfo['default_user_shop']) ? $domainInfo['default_user_shop'] : 'aloevera';
|
||||
$userShop = UserShop::where('slug', $defaultShop)->first();
|
||||
|
||||
// Configure session domain based on domain config, not getHost only for care domains
|
||||
$host = isset($domainInfo['host']) ? $domainInfo['host'] : config('app.domain') . config('app.tld_shop');
|
||||
Config::set('session.domain', '.' . $host);
|
||||
|
||||
if ($userShop) {
|
||||
\Session::put('user_shop', $userShop);
|
||||
\Session::put('user_shop_domain', config('app.protocol') . $host);
|
||||
Util::setPostRoute('user/');
|
||||
Config::set('app.url', $host);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle main care domain (e.g., mivita.care)
|
||||
*/
|
||||
private function handleMainCare($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain based on domain config
|
||||
$host = $this->getHost($domainInfo);
|
||||
$host = isset($domainInfo['host']) ? $domainInfo['host'] : config('app.domain') . config('app.tld_care');
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Clear any existing shop session data, not needed for main care domain
|
||||
Session::forget('user_shop');
|
||||
Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle CRM domain (e.g., my.mivita.care)
|
||||
*/
|
||||
private function handleCrm($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for CRM
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Clear shop data for CRM , not needed for crm domain
|
||||
Session::forget('user_shop');
|
||||
Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
\Log::info('Session all', Session::all());
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Portal domain (e.g., in.mivita.care)
|
||||
*/
|
||||
private function handlePortal($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for Portal
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Don't clear user_shop - checkout needs to know which shop
|
||||
// Session::forget('user_shop');
|
||||
// Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Checkout domain (e.g., checkout.mivita.care)
|
||||
*/
|
||||
private function handleCheckout($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for Checkout
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Keep existing shop session data for checkout
|
||||
// Don't clear user_shop - checkout needs to know which shop
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle unknown domains
|
||||
*/
|
||||
private function handleUnknownDomain($request, array $domainInfo)
|
||||
{
|
||||
// Redirect to main domain
|
||||
$mainDomain = config('domains.domains.main.host');
|
||||
$mainUrl = config('domains.protocol') . $mainDomain;
|
||||
|
||||
return redirect()->away($mainUrl, 301);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up user shop context in session and config
|
||||
*/
|
||||
private function setupUserShopContext(UserShop $userShop, ?string $subdomain = null, string $host = '')
|
||||
{
|
||||
// Put shop data in session
|
||||
Session::put('user_shop', $userShop);
|
||||
|
||||
// Build shop domain URL using protocol from config
|
||||
$shopDomain = config('domains.protocol') . $host;
|
||||
//$shopDomain = config('app.protocol').$user_shop->slug.".".config('app.domain').config('app.tld_care'));
|
||||
Session::put('user_shop_domain', $shopDomain);
|
||||
|
||||
// Set app URL for URL generation
|
||||
Config::set('app.url', rtrim($shopDomain, '/'));
|
||||
|
||||
// Set post route for compatibility
|
||||
Util::setPostRoute('user/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure session domain based on host
|
||||
*/
|
||||
private function configureSessionDomain(string $host): void
|
||||
{
|
||||
Config::set('session.domain', '.' . config('app.domain') . config('app.tld_care'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get host from domain info
|
||||
*/
|
||||
private function getHost(array $domainInfo): string
|
||||
{
|
||||
if (isset($domainInfo['host'])) {
|
||||
return $domainInfo['host'];
|
||||
}
|
||||
abort(503, 'Host not found in domain info');
|
||||
//throw new \Exception('Host not found in domain info');
|
||||
}
|
||||
/**
|
||||
* Check if request should be processed by this middleware
|
||||
*/
|
||||
private function shouldProcess($request): bool
|
||||
{
|
||||
// Skip API requests
|
||||
if ($request->is('api/*')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip asset requests
|
||||
if ($request->isMethod('GET') && preg_match('/\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$/i', $request->path())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip Laravel internal requests
|
||||
if ($request->is('_debugbar/*')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
0
app/Http/Middleware/SuperAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SuperAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SysAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SysAdmin.php
Executable file → Normal file
0
app/Http/Middleware/TrimStrings.php
Executable file → Normal file
0
app/Http/Middleware/TrimStrings.php
Executable file → Normal file
0
app/Http/Middleware/TrustProxies.php
Executable file → Normal file
0
app/Http/Middleware/TrustProxies.php
Executable file → Normal file
0
app/Http/Middleware/VerifyCsrfToken.php
Executable file → Normal file
0
app/Http/Middleware/VerifyCsrfToken.php
Executable file → Normal file
|
|
@ -44,7 +44,7 @@ class Customer extends Authenticatable // Erbt von Authenticatable
|
|||
use HasFactory, Notifiable;
|
||||
|
||||
protected $table = 'customers';
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
|
|
@ -52,6 +52,7 @@ class Customer extends Authenticatable // Erbt von Authenticatable
|
|||
'member_id',
|
||||
'number',
|
||||
'language',
|
||||
'user_shop_domain',
|
||||
'mode',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -101,11 +101,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property int|null $abo_interval
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereAboInterval($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereIsAbo($value)
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlOutboundShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlOutboundShipments
|
||||
* @property-read int|null $dhl_outbound_shipments_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlReturnShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlReturnShipments
|
||||
* @property-read int|null $dhl_return_shipments_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DhlShipment> $dhlShipments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Acme\Dhl\Models\DhlShipment> $dhlShipments
|
||||
* @property-read int|null $dhl_shipments_count
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
|
@ -138,7 +138,7 @@ class ShoppingOrder extends Model
|
|||
'weight',
|
||||
'paid',
|
||||
'is_abo',
|
||||
'abo_interval',
|
||||
'abo_interval',
|
||||
'txaction',
|
||||
'wp_invoice_path',
|
||||
'api_notice',
|
||||
|
|
@ -175,9 +175,9 @@ class ShoppingOrder extends Model
|
|||
];
|
||||
|
||||
public static $apiStatusTypes = [
|
||||
0 => 'ordered',
|
||||
1 => 'in_process',
|
||||
2 => 'paid',
|
||||
0 => 'ordered',
|
||||
1 => 'in_process',
|
||||
2 => 'paid',
|
||||
5 => 'removed',
|
||||
];
|
||||
public static $apiStatusColors = [
|
||||
|
|
@ -227,110 +227,120 @@ class ShoppingOrder extends Model
|
|||
|
||||
public function shopping_user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ShoppingUser','shopping_user_id');
|
||||
return $this->belongsTo('App\Models\ShoppingUser', 'shopping_user_id');
|
||||
}
|
||||
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ShippingCountry','country_id');
|
||||
return $this->belongsTo('App\Models\ShippingCountry', 'country_id');
|
||||
}
|
||||
|
||||
public function shipping_country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ShippingCountry','country_id');
|
||||
return $this->belongsTo('App\Models\ShippingCountry', 'country_id');
|
||||
}
|
||||
|
||||
public function homeparty()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Homeparty','homeparty_id');
|
||||
return $this->belongsTo('App\Models\Homeparty', 'homeparty_id');
|
||||
}
|
||||
|
||||
public function user_shop()
|
||||
{
|
||||
return $this->belongsTo('App\Models\UserShop','user_shop_id');
|
||||
return $this->belongsTo('App\Models\UserShop', 'user_shop_id');
|
||||
}
|
||||
|
||||
//can null
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo('App\User','member_id');
|
||||
return $this->belongsTo('App\User', 'member_id');
|
||||
}
|
||||
//can null
|
||||
public function auth_user()
|
||||
{
|
||||
return $this->belongsTo('App\User','auth_user_id');
|
||||
return $this->belongsTo('App\User', 'auth_user_id');
|
||||
}
|
||||
|
||||
public function user_history()
|
||||
{
|
||||
return $this->hasOne('App\Models\UserHistory','shopping_order_id')->latest();
|
||||
return $this->hasOne('App\Models\UserHistory', 'shopping_order_id')->latest();
|
||||
}
|
||||
|
||||
public function user_invoice(){
|
||||
public function user_invoice()
|
||||
{
|
||||
return $this->hasOne('App\Models\UserInvoice', 'shopping_order_id', '');
|
||||
}
|
||||
|
||||
public function shopping_collect_order(){
|
||||
public function shopping_collect_order()
|
||||
{
|
||||
return $this->hasOne('App\Models\ShoppingCollectOrder', 'shopping_order_id', '');
|
||||
}
|
||||
|
||||
public function shopping_order_items(){
|
||||
|
||||
public function shopping_order_items()
|
||||
{
|
||||
return $this->hasMany('App\Models\ShoppingOrderItem', 'shopping_order_id');
|
||||
}
|
||||
|
||||
public function shopping_payments(){
|
||||
public function shopping_payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\ShoppingPayment', 'shopping_order_id');
|
||||
}
|
||||
|
||||
public function user_sales_volume(){
|
||||
public function user_sales_volume()
|
||||
{
|
||||
return $this->hasOne('App\Models\UserSalesVolume', 'shopping_order_id');
|
||||
}
|
||||
|
||||
public function user_sales_volume_no_userid(){
|
||||
public function user_sales_volume_no_userid()
|
||||
{
|
||||
return $this->hasOne('App\Models\UserSalesVolume', 'shopping_order_id')->where('user_id', '=', NULL)->first();
|
||||
|
||||
}
|
||||
|
||||
public function getUserAbo(){
|
||||
public function getUserAbo()
|
||||
{
|
||||
$UserAboOrder = UserAboOrder::where('shopping_order_id', $this->id)->first();
|
||||
if($UserAboOrder && $UserAboOrder->user_abo){
|
||||
return $UserAboOrder->user_abo;
|
||||
}
|
||||
if ($UserAboOrder && $UserAboOrder->user_abo) {
|
||||
return $UserAboOrder->user_abo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLocale(){
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->language ? $this->language : \App::getLocale();
|
||||
}
|
||||
|
||||
public function setUserHistoryValue($values = []){
|
||||
if($user_history = $this->user_history){
|
||||
foreach ($values as $key=>$val){
|
||||
public function setUserHistoryValue($values = [])
|
||||
{
|
||||
if ($user_history = $this->user_history) {
|
||||
foreach ($values as $key => $val) {
|
||||
$user_history->{$key} = $val;
|
||||
}
|
||||
$user_history->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastShoppingPayment($key=false){
|
||||
public function getLastShoppingPayment($key = false)
|
||||
{
|
||||
$shopping_payment = $this->shopping_payments->last();
|
||||
if($shopping_payment){
|
||||
if($key === 'getPaymentType'){
|
||||
if ($shopping_payment) {
|
||||
if ($key === 'getPaymentType') {
|
||||
return $shopping_payment->getPaymentType();
|
||||
}
|
||||
if($key === 'reference'){
|
||||
if ($key === 'reference') {
|
||||
return $shopping_payment->reference;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getLastShoppingPaymentTransaction(){
|
||||
if($this->shopping_payments){
|
||||
public function getLastShoppingPaymentTransaction()
|
||||
{
|
||||
if ($this->shopping_payments) {
|
||||
$shopping_payment = $this->shopping_payments->last();
|
||||
if($shopping_payment){
|
||||
if ($shopping_payment) {
|
||||
$payt = $shopping_payment->payment_transactions->last();
|
||||
if($payt){
|
||||
if ($payt) {
|
||||
return $payt;
|
||||
}
|
||||
}
|
||||
|
|
@ -338,30 +348,36 @@ class ShoppingOrder extends Model
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getShippedType(){
|
||||
return isset(self::$shippedTypes[$this->shipped]) ? __('payment.'.self::$shippedTypes[$this->shipped]) : "";
|
||||
public function getShippedType()
|
||||
{
|
||||
return isset(self::$shippedTypes[$this->shipped]) ? __('payment.' . self::$shippedTypes[$this->shipped]) : "";
|
||||
}
|
||||
public static function getTransShippedType(){
|
||||
$ret = [];
|
||||
foreach(self::$shippedTypes as $key=>$val){
|
||||
$ret[$key] = trans('payment.'.$val);
|
||||
}
|
||||
return $ret;
|
||||
public static function getTransShippedType()
|
||||
{
|
||||
$ret = [];
|
||||
foreach (self::$shippedTypes as $key => $val) {
|
||||
$ret[$key] = trans('payment.' . $val);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getAPIShippedType(){
|
||||
public function getAPIShippedType()
|
||||
{
|
||||
return isset(self::$apiShippedTypes[$this->shipped]) ? self::$apiShippedTypes[$this->shipped] : "free";
|
||||
}
|
||||
|
||||
public function getShippedColor(){
|
||||
public function getShippedColor()
|
||||
{
|
||||
return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : "default";
|
||||
}
|
||||
|
||||
public function getAPIStatusType(){
|
||||
return isset(self::$apiStatusTypes[$this->api_status]) ? __('payment.'.self::$apiStatusTypes[$this->api_status]) : "bestellt";
|
||||
public function getAPIStatusType()
|
||||
{
|
||||
return isset(self::$apiStatusTypes[$this->api_status]) ? __('payment.' . self::$apiStatusTypes[$this->api_status]) : "bestellt";
|
||||
}
|
||||
|
||||
public function getAPIStatusColor(){
|
||||
public function getAPIStatusColor()
|
||||
{
|
||||
return isset(self::$apiStatusColors[$this->api_status]) ? self::$apiStatusColors[$this->api_status] : "warning";
|
||||
}
|
||||
|
||||
|
|
@ -389,7 +405,7 @@ class ShoppingOrder extends Model
|
|||
{
|
||||
return formatNumber($this->attributes['subtotal_ws']);
|
||||
}
|
||||
|
||||
|
||||
public function getFormattedSubtotalShipping()
|
||||
{
|
||||
return formatNumber($this->attributes['subtotal_shipping']);
|
||||
|
|
@ -407,79 +423,84 @@ class ShoppingOrder extends Model
|
|||
|
||||
public function getPriceVkNetBy($product_id)
|
||||
{
|
||||
if($product = Product::find($product_id)){
|
||||
if($this->shipping_country && $this->shipping_country->country){
|
||||
if ($product = Product::find($product_id)) {
|
||||
if ($this->shipping_country && $this->shipping_country->country) {
|
||||
return $product->getPriceWith(true, false, $this->shipping_country->country);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPaymentForType(){
|
||||
return isset(self::$paymentForTypes[$this->payment_for]) ? __('payment.'.self::$paymentForTypes[$this->payment_for]) : "";
|
||||
|
||||
public function getPaymentForType()
|
||||
{
|
||||
return isset(self::$paymentForTypes[$this->payment_for]) ? __('payment.' . self::$paymentForTypes[$this->payment_for]) : "";
|
||||
}
|
||||
public function getPaymentForColor(){
|
||||
public function getPaymentForColor()
|
||||
{
|
||||
return isset(self::$paymentForColors[$this->payment_for]) ? self::$paymentForColors[$this->payment_for] : "";
|
||||
}
|
||||
|
||||
public function getUserDiscount()
|
||||
{
|
||||
if($this->auth_user && $this->auth_user->user_level){
|
||||
if ($this->auth_user && $this->auth_user->user_level) {
|
||||
return $this->auth_user->user_level->getFormattedMargin();
|
||||
}
|
||||
if($this->member && $this->member->user_level){
|
||||
}
|
||||
if ($this->member && $this->member->user_level) {
|
||||
return $this->member->user_level->getFormattedMargin();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getItemsCount(){
|
||||
public function getItemsCount()
|
||||
{
|
||||
$count = 0;
|
||||
if($this->shopping_order_items){
|
||||
foreach ($this->shopping_order_items as $shopping_order_item){
|
||||
if ($this->shopping_order_items) {
|
||||
foreach ($this->shopping_order_items as $shopping_order_item) {
|
||||
$count += $shopping_order_item->qty;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
public function isInvoice(){
|
||||
public function isInvoice()
|
||||
{
|
||||
return $this->user_invoice ? true : false;
|
||||
}
|
||||
|
||||
public function getStatusByOrder(){
|
||||
if($this->payment_for){
|
||||
if($this->payment_for === 6){ //Kunde-Shop
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public function getStatusByOrder()
|
||||
{
|
||||
if ($this->payment_for) {
|
||||
if ($this->payment_for === 6) { //Kunde-Shop
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function makeHomepartyTaxSplit()
|
||||
{
|
||||
$tax_split = [];
|
||||
$net_split = [];
|
||||
|
||||
if($this->homeparty){
|
||||
foreach($this->homeparty->homeparty_order_items as $item){
|
||||
if ($this->homeparty) {
|
||||
foreach ($this->homeparty->homeparty_order_items as $item) {
|
||||
$tax_rate = intval($item->tax_rate);
|
||||
if($tax_rate > 0){
|
||||
if ($tax_rate > 0) {
|
||||
$vk_tax = round((($item->price - $item->price_net) * $item->qty), 2);
|
||||
$ek_tax = round((($item->ek_price - $item->ek_price_net) * $item->qty), 2);
|
||||
$vk_net = round(($item->price_net * $item->qty), 2);
|
||||
$ek_net = round(($item->ek_price_net * $item->qty), 2);
|
||||
if(isset($tax_split[$tax_rate])){
|
||||
if (isset($tax_split[$tax_rate])) {
|
||||
$tax_split[$tax_rate]['vk_tax'] = round($tax_split[$tax_rate]['vk_tax'] + $vk_tax, 2);
|
||||
$tax_split[$tax_rate]['ek_tax'] = round($tax_split[$tax_rate]['ek_tax'] + $ek_tax, 2);
|
||||
|
||||
$net_split[$tax_rate]['vk_net'] = round($net_split[$tax_rate]['vk_net'] + $vk_net, 2);
|
||||
$net_split[$tax_rate]['ek_net'] = round($net_split[$tax_rate]['ek_net'] + $ek_net, 2);
|
||||
}else{
|
||||
} else {
|
||||
$tax_split[$tax_rate] = ['vk_tax' => $vk_tax, 'ek_tax' => $ek_tax];
|
||||
$net_split[$tax_rate] = ['vk_net' => $vk_net, 'ek_net' => $ek_net];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$order_vk_tax = 0;
|
||||
|
|
@ -487,26 +508,26 @@ class ShoppingOrder extends Model
|
|||
$order_vk_net = 0;
|
||||
$order_ek_net = 0;
|
||||
|
||||
if($this->homeparty->order){
|
||||
if(isset($this->homeparty->order['ek_price_net'])){
|
||||
if ($this->homeparty->order) {
|
||||
if (isset($this->homeparty->order['ek_price_net'])) {
|
||||
$order_vk_tax = round((($this->homeparty->order['price'] - $this->homeparty->order['price_net'])), 2);
|
||||
$order_ek_tax = round((($this->homeparty->order['ek_price'] - $this->homeparty->order['ek_price_net'])), 2);
|
||||
$order_vk_net = $this->homeparty->order['price_net'];
|
||||
$order_ek_net = $this->homeparty->order['ek_price_net'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($tax_split[16])){
|
||||
|
||||
if (isset($tax_split[16])) {
|
||||
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
|
||||
$net_split[16] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
|
||||
}
|
||||
if(isset($tax_split[19])){
|
||||
if (isset($tax_split[19])) {
|
||||
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
|
||||
$net_split[19] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
|
||||
}
|
||||
|
||||
if(isset($tax_split[5])){
|
||||
if(!isset($tax_split[16])){
|
||||
if (isset($tax_split[5])) {
|
||||
if (!isset($tax_split[16])) {
|
||||
$tax_split[16] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
|
||||
$net_split[16] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
|
||||
}
|
||||
|
|
@ -514,9 +535,9 @@ class ShoppingOrder extends Model
|
|||
$tax_split[16]['ek_tax'] = round($tax_split[16]['ek_tax'] - $tax_split[5]['ek_tax'], 2);
|
||||
$net_split[16]['vk_net'] = round($net_split[16]['vk_net'] - $net_split[5]['vk_net'], 2);
|
||||
$net_split[16]['ek_net'] = round($net_split[16]['ek_net'] - $net_split[5]['ek_net'], 2);
|
||||
}
|
||||
if(isset($tax_split[7])){
|
||||
if(!isset($tax_split[19])){
|
||||
}
|
||||
if (isset($tax_split[7])) {
|
||||
if (!isset($tax_split[19])) {
|
||||
$tax_split[19] = ['vk_tax' => $order_vk_tax, 'ek_tax' => $order_ek_tax];
|
||||
$net_split[19] = ['vk_net' => $order_vk_net, 'ek_net' => $order_ek_net];
|
||||
}
|
||||
|
|
@ -524,30 +545,30 @@ class ShoppingOrder extends Model
|
|||
$tax_split[19]['ek_tax'] = round($tax_split[19]['ek_tax'] - $tax_split[7]['ek_tax'], 2);
|
||||
$net_split[19]['vk_net'] = round($net_split[19]['vk_net'] - $net_split[7]['vk_net'], 2);
|
||||
$net_split[19]['ek_net'] = round($net_split[19]['ek_net'] - $net_split[7]['ek_net'], 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach($tax_split as $key=>$value){
|
||||
|
||||
foreach ($tax_split as $key => $value) {
|
||||
$tax_split[$key]['vk_tax'] = number_format($value['vk_tax'], 2);
|
||||
$tax_split[$key]['ek_tax'] = number_format($value['ek_tax'], 2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($net_split as $key=>$value){
|
||||
foreach ($net_split as $key => $value) {
|
||||
$net_split[$key]['vk_net'] = number_format($value['vk_net'], 2);
|
||||
$net_split[$key]['ek_net'] = number_format($value['ek_net'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isset($tax_split[16]) && !isset($tax_split[19])){
|
||||
if (!isset($tax_split[16]) && !isset($tax_split[19])) {
|
||||
$tax_split = NULL;
|
||||
}
|
||||
if(!isset($net_split[16]) && !isset($net_split[19])){
|
||||
if (!isset($net_split[16]) && !isset($net_split[19])) {
|
||||
$net_split = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->tax_split = $tax_split;
|
||||
$this->net_split = $net_split;
|
||||
$this->save();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function makeTaxSplit()
|
||||
|
|
@ -555,75 +576,72 @@ class ShoppingOrder extends Model
|
|||
$tax_split = NULL;
|
||||
$net_split = NULL;
|
||||
|
||||
if($this->tax > 0){
|
||||
if ($this->tax > 0) {
|
||||
$tax_split = [];
|
||||
$net_split = [];
|
||||
|
||||
foreach($this->shopping_order_items as $item){
|
||||
foreach ($this->shopping_order_items as $item) {
|
||||
$tax_rate = intval($item->tax_rate);
|
||||
if($tax_rate > 0){
|
||||
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ?
|
||||
round($tax_split[$tax_rate] + ($item->tax * $item->qty), 2) :
|
||||
round(($item->tax * $item->qty), 2);
|
||||
if ($tax_rate > 0) {
|
||||
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ?
|
||||
round($tax_split[$tax_rate] + ($item->tax * $item->qty), 2) :
|
||||
round(($item->tax * $item->qty), 2);
|
||||
|
||||
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ?
|
||||
round($net_split[$tax_rate] + ($item->price_net * $item->qty), 2) :
|
||||
round(($item->price_net * $item->qty), 2);
|
||||
|
||||
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ?
|
||||
round($net_split[$tax_rate] + ($item->price_net * $item->qty), 2) :
|
||||
round(($item->price_net * $item->qty), 2);
|
||||
}
|
||||
}
|
||||
if(isset($tax_split[16])){
|
||||
}
|
||||
if (isset($tax_split[16])) {
|
||||
$tax_split[16] = $this->tax;
|
||||
$net_split[16] = $this->subtotal_ws;
|
||||
|
||||
}
|
||||
if(isset($tax_split[19])){
|
||||
if (isset($tax_split[19])) {
|
||||
$tax_split[19] = $this->tax;
|
||||
$net_split[19] = $this->subtotal_ws;
|
||||
}
|
||||
|
||||
if(isset($tax_split[5])){
|
||||
if(!isset($tax_split[16])){
|
||||
if (isset($tax_split[5])) {
|
||||
if (!isset($tax_split[16])) {
|
||||
$tax_split[16] = $this->tax;
|
||||
$net_split[16] = $this->subtotal_ws;
|
||||
|
||||
}
|
||||
$tax_split[16] = round($tax_split[16] - $tax_split[5], 2);
|
||||
$net_split[16] = round($net_split[16] - $net_split[5], 2);
|
||||
}
|
||||
if(isset($tax_split[7])){
|
||||
if(!isset($tax_split[19])){
|
||||
}
|
||||
if (isset($tax_split[7])) {
|
||||
if (!isset($tax_split[19])) {
|
||||
$tax_split[19] = $this->tax;
|
||||
$net_split[19] = $this->subtotal_ws;
|
||||
|
||||
}
|
||||
$tax_split[19] = round($tax_split[19] - $tax_split[7], 2);
|
||||
$net_split[19] = round($net_split[19] - $net_split[7], 2);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($tax_split as $key=>$value){
|
||||
foreach ($tax_split as $key => $value) {
|
||||
$tax_split[$key] = number_format($value, 2);
|
||||
}
|
||||
foreach($net_split as $key=>$value){
|
||||
}
|
||||
foreach ($net_split as $key => $value) {
|
||||
$net_split[$key] = number_format($value, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->tax_split = $tax_split;
|
||||
$this->net_split = $net_split;
|
||||
|
||||
$this->save();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getShoppingUserFullName(){
|
||||
|
||||
if($this->shopping_user){
|
||||
public function getShoppingUserFullName()
|
||||
{
|
||||
|
||||
if ($this->shopping_user) {
|
||||
$fullname = $this->shopping_user->getFullNameAsArray();
|
||||
$ret = "";
|
||||
$ret .= $fullname['company'] ? $fullname['company'].' | ' : '';
|
||||
$ret .= $fullname['salutation'] ? \App\Services\HTMLHelper::getSalutationLang($fullname['salutation']).' ' : '';
|
||||
$ret .= $fullname['firstname'] ? $fullname['firstname'].' ' : '';
|
||||
$ret .= $fullname['company'] ? $fullname['company'] . ' | ' : '';
|
||||
$ret .= $fullname['salutation'] ? \App\Services\HTMLHelper::getSalutationLang($fullname['salutation']) . ' ' : '';
|
||||
$ret .= $fullname['firstname'] ? $fullname['firstname'] . ' ' : '';
|
||||
$ret .= $fullname['lastname'] ? $fullname['lastname'] : '';
|
||||
$ret .= $fullname['email'] ? ' | '.$fullname['email'].'' : '';
|
||||
$ret .= $fullname['email'] ? ' | ' . $fullname['email'] . '' : '';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
|
@ -634,7 +652,7 @@ class ShoppingOrder extends Model
|
|||
*/
|
||||
public function dhlShipments()
|
||||
{
|
||||
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id');
|
||||
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -642,7 +660,7 @@ class ShoppingOrder extends Model
|
|||
*/
|
||||
public function dhlOutboundShipments()
|
||||
{
|
||||
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id')->where('type', 'outbound');
|
||||
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id')->where('type', 'outbound');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -650,7 +668,7 @@ class ShoppingOrder extends Model
|
|||
*/
|
||||
public function dhlReturnShipments()
|
||||
{
|
||||
return $this->hasMany('App\Models\DhlShipment', 'shopping_order_id')->where('type', 'return');
|
||||
return $this->hasMany('Acme\Dhl\Models\DhlShipment', 'order_id')->where('type', 'return');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -668,5 +686,4 @@ class ShoppingOrder extends Model
|
|||
{
|
||||
return $this->dhlShipments()->latest()->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
0
app/Policies/ModelPolicy.php
Executable file → Normal file
0
app/Policies/ModelPolicy.php
Executable file → Normal file
|
|
@ -22,18 +22,20 @@ class AppServiceProvider extends ServiceProvider
|
|||
}
|
||||
|
||||
// Domain-bewusster View Composer für user_shop
|
||||
// HOTFIX: DomainContext temporär deaktiviert
|
||||
// TODO: Nach Claude v2 Implementation wieder aktivieren
|
||||
\View::composer('*', function ($view) {
|
||||
try {
|
||||
$context = app(\App\Domain\DomainContext::class);
|
||||
|
||||
// Für die Main-Domain: user_shop immer auf null setzen
|
||||
if ($context->type === 'main') {
|
||||
$view->with('user_shop', null);
|
||||
} else {
|
||||
// Für alle anderen Domains: normales Verhalten
|
||||
$userShop = $context->userShop ?? \App\Services\Util::getUserShop();
|
||||
$view->with('user_shop', $userShop);
|
||||
}
|
||||
// $context = app(\App\Domain\DomainContext::class);
|
||||
// if ($context->type === 'main') {
|
||||
// $view->with('user_shop', null);
|
||||
// } else {
|
||||
// $userShop = $context->userShop ?? \App\Services\Util::getUserShop();
|
||||
// $view->with('user_shop', $userShop);
|
||||
// }
|
||||
|
||||
// Temporär: Verwende immer das normale Verhalten
|
||||
$view->with('user_shop', \App\Services\Util::getUserShop());
|
||||
} catch (\Exception $e) {
|
||||
// Fallback bei Fehlern
|
||||
$view->with('user_shop', \App\Services\Util::getUserShop());
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Domain\DomainContext;
|
||||
// use App\Domain\DomainContext; // HOTFIX: Temporär deaktiviert
|
||||
use App\Domain\EarlyDomainParser;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -32,7 +33,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
// $this->configureRateLimiting();
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
// API-Routen werden global geladen
|
||||
|
|
@ -44,65 +45,64 @@ class RouteServiceProvider extends ServiceProvider
|
|||
// Web-Routen werden domain-bewusst geladen
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(function() {
|
||||
->group(function () {
|
||||
$this->loadDomainAwareRoutes();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt Routen basierend auf dem aktuellen Domain-Kontext.
|
||||
* Lädt Routen basierend auf der domains.php Konfiguration.
|
||||
* Vereinfachter Ansatz ohne DomainContext-Abhängigkeit
|
||||
*/
|
||||
protected function loadDomainAwareRoutes(): void
|
||||
{
|
||||
/** @var DomainContext $context */
|
||||
$context = app(DomainContext::class);
|
||||
$request = $this->app->make('request');
|
||||
$this->loadSharedRoutes();
|
||||
\Log::info('loadDomainAwareRoutes', ['context' => $context]);
|
||||
match ($context->type) {
|
||||
'main' => $this->loadDomainRoutes('main', 'main.php'),
|
||||
'main-shop' => [
|
||||
$this->loadDomainRoutes('shop', 'shop.php'),
|
||||
$this->loadDomainRoutes('portal', 'portal.php'),
|
||||
],
|
||||
'user-shop' => [
|
||||
$this->loadDomainRoutes('user-shop', 'user-shop.php'),
|
||||
$this->loadDomainRoutes('portal', 'portal.php'),
|
||||
],
|
||||
'crm' => $this->loadDomainRoutes('crm', 'crm.php'),
|
||||
'portal' => $this->loadDomainRoutes('portal', 'portal.php'),
|
||||
'checkout' => $this->loadDomainRoutes('checkout', 'checkout.php'),
|
||||
default => $this->loadAllDomainRoutesForCaching(),
|
||||
// Lade alle Domain-spezifischen Routen
|
||||
// Die Domain-Logik wird von SubdomainResolver Middleware behandelt
|
||||
$domainType = EarlyDomainParser::getCurrentDomainType($request->getHost());
|
||||
|
||||
$routesToLoad = match ($domainType) {
|
||||
'main' => ['main'],
|
||||
'main-shop' => ['shop', 'portal'],
|
||||
'user-shop' => ['user-shop', 'portal'],
|
||||
'crm' => ['crm'],
|
||||
'portal' => ['portal'],
|
||||
'checkout' => ['checkout'],
|
||||
'unknown' => ['main'], // Fallback für unbekannte Domains
|
||||
default => ['main'],
|
||||
};
|
||||
foreach ($routesToLoad as $routeType) {
|
||||
$this->loadDomainRoutes($routeType, $routeType . '.php');
|
||||
}
|
||||
|
||||
if (config('app.debug')) {
|
||||
\Log::channel('domain')->info('Domain-aware routes loaded', [
|
||||
'domain_type' => $domainType,
|
||||
'routes_loaded' => $routesToLoad,
|
||||
'host' => EarlyDomainParser::parseDomain()['host'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lädt eine spezifische Routendatei für eine Domain.
|
||||
*/
|
||||
protected function loadDomainRoutes(string $domainType, string $fileName): void
|
||||
{
|
||||
$domain = config("domains.domains.{$domainType}.host");
|
||||
|
||||
Route::domain($domain)
|
||||
->group(base_path('routes/domains/' . $fileName));
|
||||
}
|
||||
$routePath = base_path('routes/domains/' . $fileName);
|
||||
|
||||
/**
|
||||
* Lädt alle domainspezifischen Routen.
|
||||
* Wird als Fallback für das Route-Caching benötigt.
|
||||
*/
|
||||
protected function loadAllDomainRoutesForCaching(): void
|
||||
{
|
||||
if (app()->routesAreCached()) {
|
||||
return;
|
||||
if (file_exists($routePath)) {
|
||||
Route::group([], $routePath);
|
||||
} else {
|
||||
if (config('app.debug')) {
|
||||
\Log::channel('domain')->warning('Domain route file not found', [
|
||||
'domain_type' => $domainType,
|
||||
'file_path' => $routePath,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadDomainRoutes('main', 'main.php');
|
||||
$this->loadDomainRoutes('shop', 'shop.php');
|
||||
$this->loadDomainRoutes('crm', 'crm.php');
|
||||
$this->loadDomainRoutes('portal', 'portal.php');
|
||||
$this->loadDomainRoutes('checkout', 'checkout.php');
|
||||
$this->loadDomainRoutes('user-shop', 'user-shop.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ use App\Models\PaymentMethod;
|
|||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Http\Controllers\Api\KasController;
|
||||
|
||||
class UserRepository extends BaseRepository {
|
||||
class UserRepository extends BaseRepository
|
||||
{
|
||||
|
||||
|
||||
public function __construct(User $model)
|
||||
|
|
@ -23,28 +24,27 @@ class UserRepository extends BaseRepository {
|
|||
public function update($data)
|
||||
{
|
||||
|
||||
if($data['user_id'] === "new" || $data['user_id'] == 0){
|
||||
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
||||
$this->model = User::create([
|
||||
'email' => $data['email'],
|
||||
'password' => env('APP_KEY'),
|
||||
]);
|
||||
$this->model->payment_methods = PaymentMethod::getDefaultAsArray();
|
||||
$this->model->save();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->model = $this->getById($data['user_id']);
|
||||
}
|
||||
|
||||
if(!$this->model->account_id){
|
||||
if (!$this->model->account_id) {
|
||||
$account = new UserAccount();
|
||||
}else{
|
||||
} else {
|
||||
$account = $this->model->account;
|
||||
}
|
||||
|
||||
$data['same_as_billing'] = !isset($data['same_as_billing']) ? 0 : 1;
|
||||
$account->fill($data)->save();
|
||||
|
||||
if(!$this->model->account_id){
|
||||
if (!$this->model->account_id) {
|
||||
$this->model->account_id = $account->id;
|
||||
$this->model->save();
|
||||
}
|
||||
|
|
@ -52,7 +52,8 @@ class UserRepository extends BaseRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
public function create($data)
|
||||
{
|
||||
|
||||
$this->model = User::create([
|
||||
'email' => $data['email'],
|
||||
|
|
@ -75,20 +76,21 @@ class UserRepository extends BaseRepository {
|
|||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
public function deleteUser(User $user, $complete = false)
|
||||
{
|
||||
$active_sponsor = UserUtil::findNextActiveSponsor($user->id);
|
||||
if($active_sponsor){
|
||||
if ($active_sponsor) {
|
||||
UserUtil::setNewSponsorToChilds($user->id, $active_sponsor->id);
|
||||
UserUtil::setShoppingUserToNewMember($user->id, $active_sponsor->id);
|
||||
}
|
||||
UserUtil::deleteUser($user, $complete);
|
||||
}
|
||||
|
||||
public function reverse_charge_validate($data, $user, $route){
|
||||
public function reverse_charge_validate($data, $user, $route)
|
||||
{
|
||||
|
||||
if(isset($data['action']) && $data['action'] == 'reverse_charge_validate'){
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_validate') {
|
||||
$rules = array(
|
||||
'tax_identification_number' => 'required',
|
||||
);
|
||||
|
|
@ -97,29 +99,30 @@ class UserRepository extends BaseRepository {
|
|||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return redirect($route.'#user-vat-validation')->withErrors($validator)->withInput($data);
|
||||
}
|
||||
return redirect($route . '#user-vat-validation')->withErrors($validator)->withInput($data);
|
||||
}
|
||||
$ret = $this->reverse_charge_activate($data, $user);
|
||||
if($ret === 'error'){
|
||||
if ($ret === 'error') {
|
||||
$validator = Validator::make($data, []);
|
||||
$validator->errors()->add('tax_identification_number_validated', __('msg.VATID_could_not_be_validated'));
|
||||
$data['reverse_charge'] = 0;
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return redirect($route.'#user-vat-validation')->withErrors($validator)->withInput($data);
|
||||
return redirect($route . '#user-vat-validation')->withErrors($validator)->withInput($data);
|
||||
}
|
||||
if($ret === 'valid'){
|
||||
if ($ret === 'valid') {
|
||||
\Session()->flash('alert-success', __('msg.VATID_successfully_entered'));
|
||||
return redirect($route.'#user-vat-validation')->withInput($data);
|
||||
return redirect($route . '#user-vat-validation')->withInput($data);
|
||||
|
||||
return redirect($route.'#user-vat-validation')->withInput($data);
|
||||
return redirect($route . '#user-vat-validation')->withInput($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reverse_charge_delete($data, $user, $route){
|
||||
if(isset($data['action']) && $data['action'] == 'reverse_charge_delete'){
|
||||
public function reverse_charge_delete($data, $user, $route)
|
||||
{
|
||||
if (isset($data['action']) && $data['action'] == 'reverse_charge_delete') {
|
||||
$user->account->tax_identification_number = '';
|
||||
$user->account->reverse_charge = 0;
|
||||
$user->account->reverse_charge_code = null;
|
||||
|
|
@ -127,11 +130,12 @@ class UserRepository extends BaseRepository {
|
|||
$user->account->save();
|
||||
$data['tax_identification_number'] = '';
|
||||
\Session()->flash('alert-success', __('msg.reverse_charge_procedure_and_VATID_deleted'));
|
||||
return redirect($route.'#user-vat-validation')->withInput($data);
|
||||
return redirect($route . '#user-vat-validation')->withInput($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function reverse_charge_activate($data, $user){
|
||||
public function reverse_charge_activate($data, $user)
|
||||
{
|
||||
|
||||
/* 'AT' => 'AT-Oesterreich',
|
||||
'BE' => 'BE-Belgien',
|
||||
|
|
@ -161,42 +165,42 @@ class UserRepository extends BaseRepository {
|
|||
'SI' => 'SI-Slowenien',
|
||||
'SK' => 'SK-Slowakei',
|
||||
'XI' => 'XI-Nordirland', */
|
||||
$countryCode = 'DE';
|
||||
|
||||
if($user->account->country_id){
|
||||
$countryCode = $user->account->country->code;
|
||||
}
|
||||
|
||||
$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($data['tax_identification_number']));
|
||||
$cc = substr($vatid, 0, 2);
|
||||
$vatNo = substr($vatid, 2);
|
||||
|
||||
$options = [
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'trace' => 1,
|
||||
'stream_context' => stream_context_create(
|
||||
[
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$client = new \SoapClient("https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", $options);
|
||||
$result = $client->checkVat(['countryCode' => $countryCode, 'vatNumber' => $vatNo]);
|
||||
|
||||
if($result->valid == true) {
|
||||
$user->account->tax_identification_number = $data['tax_identification_number'];
|
||||
$user->account->reverse_charge = 1;
|
||||
$user->account->reverse_charge_code = $countryCode;
|
||||
$user->account->reverse_charge_valid = now();
|
||||
$user->account->save();
|
||||
return 'valid';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
$countryCode = 'DE';
|
||||
|
||||
if ($user->account->country_id) {
|
||||
$countryCode = $user->account->country->code;
|
||||
}
|
||||
|
||||
$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($data['tax_identification_number']));
|
||||
$cc = substr($vatid, 0, 2);
|
||||
$vatNo = substr($vatid, 2);
|
||||
|
||||
$options = [
|
||||
'cache_wsdl' => WSDL_CACHE_NONE,
|
||||
'trace' => 1,
|
||||
'stream_context' => stream_context_create(
|
||||
[
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$client = new \SoapClient("https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl", $options);
|
||||
$result = $client->checkVat(['countryCode' => $countryCode, 'vatNumber' => $vatNo]);
|
||||
|
||||
if ($result->valid == true) {
|
||||
$user->account->tax_identification_number = $data['tax_identification_number'];
|
||||
$user->account->reverse_charge = 1;
|
||||
$user->account->reverse_charge_code = $countryCode;
|
||||
$user->account->reverse_charge_valid = now();
|
||||
$user->account->save();
|
||||
return 'valid';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ use stdClass;
|
|||
use Carbon\Carbon;
|
||||
use App\Models\UserLevel;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Models\UserAccount;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Services\TranslationHelper;
|
||||
use App\Models\UserBusinessStructure;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
|
@ -26,12 +28,14 @@ class BusinessUserItemOptimized
|
|||
|
||||
private $date;
|
||||
private $b_user;
|
||||
private ?TreeCalcBotOptimized $treeCalcBot = null;
|
||||
private $user_level_active_pos;
|
||||
private $needsQualificationRecalculation = false;
|
||||
|
||||
public function __construct($date)
|
||||
public function __construct($date, ?TreeCalcBotOptimized $treeCalcBot = null)
|
||||
{
|
||||
$this->date = $date;
|
||||
$this->treeCalcBot = $treeCalcBot;
|
||||
$this->businessUserItems = []; // Initialize array
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -51,22 +55,22 @@ class BusinessUserItemOptimized
|
|||
->where('month', $this->date->month)
|
||||
->where('year', $this->date->year)
|
||||
->first();
|
||||
|
||||
|
||||
if ($this->b_user !== null) {
|
||||
\Log::debug("BusinessUserItem: Using stored data for user {$user_id} ({$this->date->month}/{$this->date->year})");
|
||||
|
||||
|
||||
// WICHTIG: Auch bei gespeicherten Daten User-Model laden für Grunddaten
|
||||
$user = User::with(['account', 'user_level'])->find($user_id);
|
||||
if ($user) {
|
||||
$this->enrichStoredDataWithUserModel($user);
|
||||
|
||||
|
||||
// Prüfe ob Level-Qualifikationsdaten nachberechnet werden müssen
|
||||
if ($this->needsQualificationRecalculation) {
|
||||
\Log::debug("BusinessUserItem: Triggering qualification recalculation for user {$user_id}");
|
||||
$this->calcQualPP(); // Berechne fehlende Level-Qualifikationsdaten
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return; // Bereits gespeicherte Daten verwenden
|
||||
}
|
||||
} else {
|
||||
|
|
@ -75,20 +79,19 @@ class BusinessUserItemOptimized
|
|||
|
||||
// Lade User mit Relations (weniger effizient als makeUserFromModel)
|
||||
$user = User::with(['account', 'user_level'])->find($user_id);
|
||||
|
||||
|
||||
if (!$user) {
|
||||
\Log::warning("BusinessUserItem: User not found: {$user_id}");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->initializeFromUserModel($user);
|
||||
|
||||
|
||||
// WICHTIG: Bei Live-Berechnung auch Level-Qualifikationsdaten berechnen
|
||||
// (nicht bei forceLiveCalculation=false, da dort gespeicherte Daten bevorzugt werden)
|
||||
if ($forceLiveCalculation) {
|
||||
$this->calcQualPP();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error creating user {$user_id}: " . $e->getMessage());
|
||||
throw $e;
|
||||
|
|
@ -115,19 +118,19 @@ class BusinessUserItemOptimized
|
|||
->where('month', $this->date->month)
|
||||
->where('year', $this->date->year)
|
||||
->first();
|
||||
|
||||
|
||||
if ($this->b_user !== null) {
|
||||
\Log::debug("BusinessUserItem: Using stored data for user {$user->id} ({$this->date->month}/{$this->date->year})");
|
||||
|
||||
|
||||
// WICHTIG: Auch bei gespeicherten Daten User-Grunddaten anreichern
|
||||
$this->enrichStoredDataWithUserModel($user);
|
||||
|
||||
|
||||
// Prüfe ob Level-Qualifikationsdaten nachberechnet werden müssen
|
||||
if ($this->needsQualificationRecalculation) {
|
||||
\Log::debug("BusinessUserItem: Triggering qualification recalculation for user {$user->id}");
|
||||
$this->calcQualPP(); // Berechne fehlende Level-Qualifikationsdaten
|
||||
}
|
||||
|
||||
|
||||
return; // Bereits berechnete Daten verwenden
|
||||
}
|
||||
} else {
|
||||
|
|
@ -136,13 +139,12 @@ class BusinessUserItemOptimized
|
|||
|
||||
// Erstelle neuen User und führe Live-Berechnung durch
|
||||
$this->initializeFromUserModel($user);
|
||||
|
||||
|
||||
// WICHTIG: Bei Live-Berechnung auch Level-Qualifikationsdaten berechnen
|
||||
// (nicht bei forceLiveCalculation=false, da dort gespeicherte Daten bevorzugt werden)
|
||||
if ($forceLiveCalculation) {
|
||||
$this->calcQualPP();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error creating user from model {$user->id}: " . $e->getMessage());
|
||||
throw $e;
|
||||
|
|
@ -157,7 +159,7 @@ class BusinessUserItemOptimized
|
|||
// Nutze geladene Relations wenn verfügbar
|
||||
$user_level_active = null;
|
||||
if ($user->relationLoaded('user_level')) {
|
||||
$user_level_active = $user->user_level;
|
||||
$user_level_active = $user->user_level;
|
||||
} else {
|
||||
$user_level_active = $user->user_level; // Fallback auf Original-Relation
|
||||
}
|
||||
|
|
@ -166,11 +168,8 @@ class BusinessUserItemOptimized
|
|||
// Neues UserBusiness Objekt erstellen
|
||||
$this->b_user = new UserBusiness();
|
||||
|
||||
// Account-Daten (mit Error-Handling)
|
||||
$account = $user->relationLoaded('account') ? $user->account : null;
|
||||
if (!$account) {
|
||||
\Log::warning("BusinessUserItem: No account found for user {$user->id}");
|
||||
}
|
||||
// Account-Daten (mit intelligentem Laden und Error-Handling)
|
||||
$account = $this->getAccountForUser($user);
|
||||
$fill = [
|
||||
'user_id' => $user->id,
|
||||
'month' => $this->date->month,
|
||||
|
|
@ -180,12 +179,12 @@ class BusinessUserItemOptimized
|
|||
'active_account' => $this->calculateActiveAccount($user),
|
||||
'payment_account_date' => $user->payment_account ? $user->getPaymentAccountDateFormat(false) : null,
|
||||
'active_date' => $user->active_date,
|
||||
|
||||
// Account-Daten mit Fallback
|
||||
'm_account' => $account ? $account->m_account : '',
|
||||
|
||||
// Account-Daten mit korrekten Fallback-Werten
|
||||
'm_account' => $account ? ($account->m_account ?? null) : null,
|
||||
'email' => $user->email,
|
||||
'first_name' => $account ? $account->first_name : '',
|
||||
'last_name' => $account ? $account->last_name : '',
|
||||
'first_name' => $account ? ($account->first_name ?? '') : '',
|
||||
'last_name' => $account ? ($account->last_name ?? '') : '',
|
||||
'user_birthday' => $account ? $account->birthday : null,
|
||||
'user_phone' => $account ? ($account->getPhoneNumber() ?? '') : '',
|
||||
|
||||
|
|
@ -212,17 +211,18 @@ class BusinessUserItemOptimized
|
|||
'commission_growth_total' => 0,
|
||||
'version' => 2,
|
||||
];
|
||||
|
||||
|
||||
$this->b_user->fill($fill);
|
||||
$this->b_user->business_lines = [];
|
||||
$this->b_user->user_items = [];
|
||||
|
||||
// Shop-Provision berechnen (mit Boundary-Check)
|
||||
// Shop-Provision berechnen (mit verbessertem Logging)
|
||||
$shopVolume = (float) $this->b_user->sales_volume_total_shop;
|
||||
$shopMargin = (float) $this->b_user->margin_shop;
|
||||
$this->b_user->commission_shop_sales = round($shopVolume / 100 * $shopMargin, 2);
|
||||
$calculatedCommission = round($shopVolume / 100 * $shopMargin, 2);
|
||||
$this->b_user->commission_shop_sales = $calculatedCommission;
|
||||
|
||||
\Log::debug("BusinessUserItem: Created optimized user {$user->id} for {$this->date->month}/{$this->date->year}");
|
||||
\Log::debug("BusinessUserItem: Created optimized user {$user->id} for {$this->date->month}/{$this->date->year} - Shop commission: {$calculatedCommission} (Volume: {$shopVolume}, Margin: {$shopMargin}%)");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -232,38 +232,92 @@ class BusinessUserItemOptimized
|
|||
private function enrichStoredDataWithUserModel(User $user): void
|
||||
{
|
||||
try {
|
||||
$account = $user->account;
|
||||
|
||||
$account = $this->getAccountForUser($user);
|
||||
|
||||
// Ergänze fehlende User-Grunddaten in gespeicherten UserBusiness-Daten
|
||||
$this->b_user->user_id = $user->id;
|
||||
$this->b_user->email = $user->email;
|
||||
$this->b_user->first_name = $account ? $account->first_name : '';
|
||||
$this->b_user->last_name = $account ? $account->last_name : '';
|
||||
$this->b_user->first_name = $account ? ($account->first_name ?? '') : '';
|
||||
$this->b_user->last_name = $account ? ($account->last_name ?? '') : '';
|
||||
$this->b_user->user_birthday = $account ? $account->birthday : null;
|
||||
$this->b_user->user_phone = $account ? ($account->getPhoneNumber() ?? '') : '';
|
||||
$this->b_user->m_account = $account ? $account->m_account : '';
|
||||
|
||||
$this->b_user->m_account = $account ? ($account->m_account ?? null) : null;
|
||||
|
||||
// Berechne aktiven Account-Status
|
||||
$this->b_user->active_account = $this->calculateActiveAccount($user);
|
||||
$this->b_user->payment_account_date = $user->payment_account;
|
||||
|
||||
|
||||
// User-Level Informationen
|
||||
$user_level_active = $user->user_level;
|
||||
if ($user_level_active) {
|
||||
$this->b_user->user_level_name = $user_level_active->name;
|
||||
$this->user_level_active_pos = $user_level_active->pos;
|
||||
}
|
||||
|
||||
|
||||
// WICHTIG: Validiere Level-Qualifikationsdaten für Struktur-Ansicht
|
||||
$this->validateLevelQualificationData();
|
||||
|
||||
|
||||
// Prüfe ob Sales Volume Felder aktualisiert werden müssen
|
||||
$this->updateSalesVolumeFields($user);
|
||||
|
||||
\Log::debug("BusinessUserItem: Enriched stored data for user {$user->id} with current user model data");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error enriching stored data for user {$user->id}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aktualisiert Sales Volume und Commission Felder bei gespeicherten Daten
|
||||
*/
|
||||
private function updateSalesVolumeFields(User $user): void
|
||||
{
|
||||
try {
|
||||
// Prüfe ob Sales Volume Felder leer sind
|
||||
$fieldsToUpdate = [
|
||||
'sales_volume_KP_points',
|
||||
'sales_volume_TP_points',
|
||||
'sales_volume_points_shop',
|
||||
'sales_volume_points_KP_sum',
|
||||
'sales_volume_points_TP_sum',
|
||||
'sales_volume_total',
|
||||
'sales_volume_total_shop',
|
||||
'sales_volume_total_sum'
|
||||
];
|
||||
|
||||
$needsUpdate = false;
|
||||
foreach ($fieldsToUpdate as $field) {
|
||||
if (!isset($this->b_user->{$field}) || $this->b_user->{$field} === null || $this->b_user->{$field} === 0) {
|
||||
$newValue = $this->getUserSalesVolumeOptimized($user, $field);
|
||||
$this->b_user->{$field} = $newValue;
|
||||
|
||||
if ($newValue > 0) {
|
||||
$needsUpdate = true;
|
||||
\Log::debug("BusinessUserItem: Updated {$field} for user {$user->id}: {$newValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Aktualisiere Shop Commission falls nötig
|
||||
if (!isset($this->b_user->commission_shop_sales) || $this->b_user->commission_shop_sales === 0) {
|
||||
$shopVolume = (float) $this->b_user->sales_volume_total_shop;
|
||||
$shopMargin = (float) $this->b_user->margin_shop;
|
||||
|
||||
if ($shopVolume > 0 && $shopMargin > 0) {
|
||||
$calculatedCommission = round($shopVolume / 100 * $shopMargin, 2);
|
||||
$this->b_user->commission_shop_sales = $calculatedCommission;
|
||||
$needsUpdate = true;
|
||||
\Log::debug("BusinessUserItem: Updated commission_shop_sales for user {$user->id}: {$calculatedCommission}");
|
||||
}
|
||||
}
|
||||
|
||||
if ($needsUpdate) {
|
||||
\Log::info("BusinessUserItem: Updated sales volume fields for user {$user->id}");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error updating sales volume fields for user {$user->id}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert und aktualisiert Level-Qualifikationsdaten wenn nötig
|
||||
* Stellt sicher, dass next_qual_user_level und next_can_user_level für Struktur-Ansicht verfügbar sind
|
||||
|
|
@ -278,11 +332,10 @@ class BusinessUserItemOptimized
|
|||
// Wenn Level-Qualifikationsdaten fehlen, führe Neuberechnung durch
|
||||
if (!$hasNextQual && !$hasNextCan && !$hasQualUserLevel) {
|
||||
\Log::debug("BusinessUserItem: Level qualification data missing for user {$this->b_user->user_id}, triggering recalculation");
|
||||
|
||||
|
||||
// Setze Flag für notwendige Neuberechnung
|
||||
$this->needsQualificationRecalculation = true;
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::warning("BusinessUserItem: Error validating level qualification data for user {$this->b_user->user_id}: " . $e->getMessage());
|
||||
}
|
||||
|
|
@ -307,17 +360,41 @@ class BusinessUserItemOptimized
|
|||
}
|
||||
|
||||
/**
|
||||
* Optimierte Sales Volume Abfrage (mit potenziellem Caching)
|
||||
* Optimierte Sales Volume Abfrage mit detailliertem Logging
|
||||
*/
|
||||
private function getUserSalesVolumeOptimized(User $user, string $field)
|
||||
{
|
||||
try {
|
||||
// Hier könnte Caching implementiert werden
|
||||
$cacheKey = "sales_volume_{$user->id}_{$this->date->month}_{$this->date->year}_{$field}";
|
||||
|
||||
// Für jetzt: Direkter Aufruf (später durch Cache ersetzen)
|
||||
return $user->getUserSalesVolumeBy($this->date->month, $this->date->year, $field);
|
||||
|
||||
// Direkter Aufruf mit detailliertem Logging
|
||||
$value = $user->getUserSalesVolumeBy($this->date->month, $this->date->year, $field);
|
||||
|
||||
// Log nur bei ersten Aufruf für diesen User (Performance)
|
||||
static $loggedUsers = [];
|
||||
if (!isset($loggedUsers[$user->id])) {
|
||||
$loggedUsers[$user->id] = true;
|
||||
|
||||
// Prüfe ob UserSalesVolume Daten existieren
|
||||
$userSalesVolume = $user->getUserSalesVolume($this->date->month, $this->date->year, 'first');
|
||||
if (!$userSalesVolume) {
|
||||
\Log::info("BusinessUserItem: No UserSalesVolume found for user {$user->id} in {$this->date->month}/{$this->date->year}");
|
||||
|
||||
// Prüfe neueste verfügbare Daten
|
||||
$latestVolume = \App\Models\UserSalesVolume::where('user_id', $user->id)
|
||||
->orderBy('year', 'desc')
|
||||
->orderBy('month', 'desc')
|
||||
->first();
|
||||
|
||||
if ($latestVolume) {
|
||||
\Log::info("BusinessUserItem: Latest UserSalesVolume for user {$user->id}: {$latestVolume->month}/{$latestVolume->year}");
|
||||
} else {
|
||||
\Log::warning("BusinessUserItem: No UserSalesVolume records found for user {$user->id} at all");
|
||||
}
|
||||
} else {
|
||||
\Log::debug("BusinessUserItem: UserSalesVolume found for user {$user->id} in {$this->date->month}/{$this->date->year}");
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error getting sales volume {$field} for user {$user->id}: " . $e->getMessage());
|
||||
return 0; // Sicherer Fallback
|
||||
|
|
@ -333,7 +410,12 @@ class BusinessUserItemOptimized
|
|||
|
||||
public function addUserID()
|
||||
{
|
||||
TreeCalcBotOptimized::addUserID($this->b_user->user_id);
|
||||
if ($this->treeCalcBot) {
|
||||
$this->treeCalcBot->addProcessedUserId($this->b_user->user_id);
|
||||
} else {
|
||||
// Fallback für Rückwärtskompatibilität - sollte in Logs sichtbar sein
|
||||
\Log::warning("BusinessUserItemOptimized: TreeCalcBotOptimized Referenz fehlt für User ID: " . $this->b_user->user_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function getBUser()
|
||||
|
|
@ -345,7 +427,7 @@ class BusinessUserItemOptimized
|
|||
{
|
||||
$this->b_user->business_lines[$line] = $obj;
|
||||
}
|
||||
|
||||
|
||||
public function addBusinessLinePoints($line, $points)
|
||||
{
|
||||
if (!isset($this->b_user->business_lines[$line])) {
|
||||
|
|
@ -354,7 +436,7 @@ class BusinessUserItemOptimized
|
|||
}
|
||||
|
||||
$obj = $this->b_user->business_lines[$line];
|
||||
|
||||
|
||||
// Handle both array and object types (JSON deserialization inconsistency)
|
||||
if (is_array($obj)) {
|
||||
$obj['points'] = ($obj['points'] ?? 0) + (float) $points;
|
||||
|
|
@ -365,7 +447,7 @@ class BusinessUserItemOptimized
|
|||
}
|
||||
$obj->points = ($obj->points ?? 0) + (float) $points;
|
||||
}
|
||||
|
||||
|
||||
$this->b_user->business_lines[$line] = $obj;
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +455,7 @@ class BusinessUserItemOptimized
|
|||
{
|
||||
$this->b_user->total_pp += (float) $points; // Type-Safety
|
||||
}
|
||||
|
||||
|
||||
public function isQualKP(): bool
|
||||
{
|
||||
return ($this->b_user->sales_volume_points_KP_sum >= $this->b_user->qual_kp);
|
||||
|
|
@ -409,9 +491,9 @@ class BusinessUserItemOptimized
|
|||
public function getCommissionTotal(): float
|
||||
{
|
||||
return round(
|
||||
$this->b_user->commission_shop_sales +
|
||||
$this->b_user->commission_pp_total +
|
||||
$this->b_user->commission_growth_total,
|
||||
$this->b_user->commission_shop_sales +
|
||||
$this->b_user->commission_pp_total +
|
||||
$this->b_user->commission_growth_total,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
|
@ -452,8 +534,8 @@ class BusinessUserItemOptimized
|
|||
for ($i = 1; $i <= $qualUserLevel->paylines; $i++) {
|
||||
if (isset($this->b_user->business_lines[$i])) {
|
||||
$object = $this->b_user->business_lines[$i];
|
||||
$margin = (float) $this->b_user->qual_user_level['pr_line_'.$i];
|
||||
|
||||
$margin = (float) $this->b_user->qual_user_level['pr_line_' . $i];
|
||||
|
||||
// Handle both array and object types (JSON deserialization inconsistency)
|
||||
if (is_array($object)) {
|
||||
$points = (float) ($object['points'] ?? 0);
|
||||
|
|
@ -468,7 +550,7 @@ class BusinessUserItemOptimized
|
|||
$object->payline = true;
|
||||
$commission_pp_total += $object->commission;
|
||||
}
|
||||
|
||||
|
||||
$this->b_user->business_lines[$i] = $object;
|
||||
}
|
||||
}
|
||||
|
|
@ -482,7 +564,7 @@ class BusinessUserItemOptimized
|
|||
for ($i = $payline; $i <= $maxlines; $i++) {
|
||||
if (isset($this->b_user->business_lines[$i])) {
|
||||
$object = $this->b_user->business_lines[$i];
|
||||
|
||||
|
||||
// Handle both array and object types (JSON deserialization inconsistency)
|
||||
if (is_array($object)) {
|
||||
$points = (float) ($object['points'] ?? 0);
|
||||
|
|
@ -497,7 +579,7 @@ class BusinessUserItemOptimized
|
|||
$object->growth_bonus = true;
|
||||
$commission_growth_total += $object->commission;
|
||||
}
|
||||
|
||||
|
||||
$this->b_user->business_lines[$i] = $object;
|
||||
}
|
||||
}
|
||||
|
|
@ -519,7 +601,7 @@ class BusinessUserItemOptimized
|
|||
foreach ($qualUserLevels as $qualUserLevel) {
|
||||
$payline_points = $this->getPointsforPayline($qualUserLevel->paylines);
|
||||
$payline_points_qual_kp = $payline_points + $this->getRestQualKP();
|
||||
|
||||
|
||||
if ($payline_points_qual_kp >= $qualUserLevel->qual_pp) {
|
||||
$this->b_user->payline_points = $payline_points;
|
||||
$this->b_user->payline_points_qual_kp = $payline_points_qual_kp;
|
||||
|
|
@ -535,7 +617,7 @@ class BusinessUserItemOptimized
|
|||
for ($i = 1; $i <= $paylines; $i++) {
|
||||
if (isset($this->b_user->business_lines[$i])) {
|
||||
$line = $this->b_user->business_lines[$i];
|
||||
|
||||
|
||||
// Handle both array and object types (JSON deserialization inconsistency)
|
||||
if (is_array($line)) {
|
||||
$payline_points += (float) ($line['points'] ?? 0);
|
||||
|
|
@ -561,17 +643,17 @@ class BusinessUserItemOptimized
|
|||
->first();
|
||||
if ($qualUserLevelNext) {
|
||||
$this->b_user->qual_user_level_next = $qualUserLevelNext->toArray();
|
||||
}else{
|
||||
} else {
|
||||
$this->b_user->qual_user_level_next = null;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$this->b_user->qual_user_level_next = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function setNextUserLevel($force = false): void
|
||||
{
|
||||
//sucht den nächsten level, der mehr points hat als das aktuelle level
|
||||
//sucht den nächsten level, der mehr points hat als das aktuelle level
|
||||
$nextQualUserLevel = UserLevel::where('qual_pp', '<=', $this->b_user->payline_points_qual_kp)
|
||||
->where('pos', '>', $this->user_level_active_pos)
|
||||
->orderBy('qual_pp', 'desc')
|
||||
|
|
@ -608,7 +690,7 @@ class BusinessUserItemOptimized
|
|||
if (isset($this->b_user->$name)) {
|
||||
return $this->b_user->$name;
|
||||
}
|
||||
|
||||
|
||||
// Legacy-Properties
|
||||
$legacyMap = [
|
||||
'sales_volume_points_KP_sum' => 'sales_volume_points_KP_sum',
|
||||
|
|
@ -616,11 +698,11 @@ class BusinessUserItemOptimized
|
|||
'business_lines' => 'business_lines',
|
||||
'user_id' => 'user_id'
|
||||
];
|
||||
|
||||
|
||||
if (isset($legacyMap[$name]) && isset($this->b_user->{$legacyMap[$name]})) {
|
||||
return $this->b_user->{$legacyMap[$name]};
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -648,13 +730,15 @@ class BusinessUserItemOptimized
|
|||
if ($user->user_sponsor) {
|
||||
$sponsor->is_sponsor = true;
|
||||
$sponsor->user_id = $user->user_sponsor->id;
|
||||
|
||||
|
||||
if ($user->user_sponsor->account) {
|
||||
$sponsor->full_name = substr(
|
||||
'Sponsor: ' . $user->user_sponsor->account->first_name . ' ' .
|
||||
$user->user_sponsor->account->last_name . ' | ' .
|
||||
$user->user_sponsor->email . ' | ' .
|
||||
$user->user_sponsor->account->m_account, 0, 250
|
||||
'Sponsor: ' . $user->user_sponsor->account->first_name . ' ' .
|
||||
$user->user_sponsor->account->last_name . ' | ' .
|
||||
$user->user_sponsor->email . ' | ' .
|
||||
$user->user_sponsor->account->m_account,
|
||||
0,
|
||||
250
|
||||
);
|
||||
$sponsor->first_name = $user->user_sponsor->account->first_name;
|
||||
$sponsor->last_name = $user->user_sponsor->account->last_name;
|
||||
|
|
@ -676,9 +760,17 @@ class BusinessUserItemOptimized
|
|||
|
||||
/**
|
||||
* Lädt Parent Business Users rekursiv (Original-Implementation mit Optimierungen)
|
||||
* BUGFIX: Schutz vor unendlicher Rekursion durch zirkuläre Referenzen
|
||||
*/
|
||||
public function readParentsBusinessUsers($forceLiveCalculation = false): void
|
||||
public function readParentsBusinessUsers($forceLiveCalculation = false, $depth = 0): void
|
||||
{
|
||||
// Schutz vor zu tiefer Rekursion (maximale Tiefe: 20 Levels)
|
||||
$maxDepth = 20;
|
||||
if ($depth > $maxDepth) {
|
||||
Log::warning("BusinessUserItem: Maximale Rekursionstiefe ({$maxDepth}) erreicht für User {$this->b_user->user_id}");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Optimiert: Lade mit Relations
|
||||
$users = User::with(['account'])
|
||||
|
|
@ -694,45 +786,64 @@ class BusinessUserItemOptimized
|
|||
|
||||
if ($users->isNotEmpty()) {
|
||||
foreach ($users as $user) {
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
// KRITISCHER BUGFIX: Prüfe ob User bereits verarbeitet wurde
|
||||
if ($this->treeCalcBot && $this->treeCalcBot->isUserProcessed($user->id)) {
|
||||
Log::debug("BusinessUserItem: Überspringe bereits verarbeiteten User {$user->id} (zirkuläre Referenz verhindert)");
|
||||
continue;
|
||||
}
|
||||
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this->treeCalcBot);
|
||||
$businessUserItem->makeUserFromModel($user, $forceLiveCalculation);
|
||||
$businessUserItem->addUserID();
|
||||
$this->businessUserItems[] = $businessUserItem;
|
||||
}
|
||||
}
|
||||
|
||||
// Rekursiver Aufruf für alle Child-Items
|
||||
// Rekursiver Aufruf für alle Child-Items mit Tiefenprüfung
|
||||
foreach ($this->businessUserItems as $businessUserItem) {
|
||||
$businessUserItem->readParentsBusinessUsers($forceLiveCalculation);
|
||||
$businessUserItem->readParentsBusinessUsers($forceLiveCalculation, $depth + 1);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessUserItem: Error reading parent users for {$this->b_user->user_id}: " . $e->getMessage());
|
||||
Log::error("BusinessUserItem: Error reading parent users for {$this->b_user->user_id} at depth {$depth}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt Parent Business Users aus gespeicherter Struktur (Original-Implementation)
|
||||
* BUGFIX: Schutz vor unendlicher Rekursion durch zirkuläre Referenzen
|
||||
*/
|
||||
public function readStoredParentsBusinessUsers($structure): void
|
||||
public function readStoredParentsBusinessUsers($structure, $depth = 0): void
|
||||
{
|
||||
// Schutz vor zu tiefer Rekursion (maximale Tiefe: 50 Levels)
|
||||
$maxDepth = 50;
|
||||
if ($depth > $maxDepth) {
|
||||
Log::warning("BusinessUserItem: Maximale Rekursionstiefe ({$maxDepth}) erreicht für gespeicherte User {$this->b_user->user_id}");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$parents = $this->findParentsBusinessOnStored($this->b_user->user_id, $structure);
|
||||
|
||||
|
||||
if ($parents) {
|
||||
foreach ($parents as $obj) {
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
// KRITISCHER BUGFIX: Prüfe ob User bereits verarbeitet wurde
|
||||
if ($this->treeCalcBot && $this->treeCalcBot->isUserProcessed($obj->user_id)) {
|
||||
Log::debug("BusinessUserItem: Überspringe bereits verarbeiteten gespeicherten User {$obj->user_id} (zirkuläre Referenz verhindert)");
|
||||
continue;
|
||||
}
|
||||
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this->treeCalcBot);
|
||||
$businessUserItem->makeUser($obj->user_id);
|
||||
$businessUserItem->addUserID();
|
||||
$this->businessUserItems[] = $businessUserItem;
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->businessUserItems as $businessUserItem) {
|
||||
$businessUserItem->readStoredParentsBusinessUsers($parents);
|
||||
$businessUserItem->readStoredParentsBusinessUsers($parents, $depth + 1);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("BusinessUserItem: Error reading stored parent users: " . $e->getMessage());
|
||||
Log::error("BusinessUserItem: Error reading stored parent users at depth {$depth}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -749,7 +860,7 @@ class BusinessUserItemOptimized
|
|||
if ($user_id === $obj->user_id) {
|
||||
return $obj->parents ?? null;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($obj->parents)) {
|
||||
$result = $this->findParentsBusinessOnStored($user_id, $obj->parents);
|
||||
if ($result) {
|
||||
|
|
@ -757,7 +868,7 @@ class BusinessUserItemOptimized
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -794,4 +905,43 @@ class BusinessUserItemOptimized
|
|||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intelligentes Laden des UserAccount für einen User
|
||||
* Prüft zuerst geladene Relations, lädt nach wenn nötig
|
||||
*/
|
||||
private function getAccountForUser(User $user): ?UserAccount
|
||||
{
|
||||
try {
|
||||
// Prüfe ob Account-Relation bereits geladen ist
|
||||
if ($user->relationLoaded('account')) {
|
||||
$account = $user->account;
|
||||
if ($account instanceof UserAccount) {
|
||||
\Log::debug("BusinessUserItem: Using pre-loaded account for user {$user->id}");
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn User keine account_id hat, gibt es definitiv kein Account
|
||||
if (!$user->account_id) {
|
||||
\Log::info("BusinessUserItem: User {$user->id} has no account_id - no account available");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Account nachladen falls nötig
|
||||
\Log::info("BusinessUserItem: Loading account for user {$user->id} (account_id: {$user->account_id})");
|
||||
$account = UserAccount::find($user->account_id);
|
||||
|
||||
if (!$account) {
|
||||
\Log::warning("BusinessUserItem: Account {$user->account_id} not found for user {$user->id}");
|
||||
return null;
|
||||
}
|
||||
|
||||
\Log::debug("BusinessUserItem: Successfully loaded account {$account->id} for user {$user->id}");
|
||||
return $account;
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("BusinessUserItem: Error loading account for user {$user->id}: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,12 @@ class BusinessUserRepository
|
|||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
|
||||
$date = Carbon::parse($year.'-'.$month.'-1');
|
||||
|
||||
$date = Carbon::parse($year . '-' . $month . '-1');
|
||||
$this->startDate = $date->format('Y-m-d H:i:s');
|
||||
$this->endDate = $date->endOfMonth()->format('Y-m-d H:i:s');
|
||||
\Log::info("BusinessUserRepository: Start Date: " . $this->startDate);
|
||||
\Log::info("BusinessUserRepository: End Date: " . $this->endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,27 +38,26 @@ class BusinessUserRepository
|
|||
public function getRootUsers(): Collection
|
||||
{
|
||||
$cacheKey = "root_users_{$this->month}_{$this->year}";
|
||||
|
||||
return cache()->remember($cacheKey, 3600, function() {
|
||||
\Log::info("BusinessUserRepository: Loading root users from database (cache miss)");
|
||||
|
||||
//root hat keinen parent m_sponsor, hat
|
||||
return cache()->remember($cacheKey, 3600, function () {
|
||||
return User::with([
|
||||
'account',
|
||||
'account',
|
||||
'user_level',
|
||||
'userBusiness' => function($query) {
|
||||
'userBusiness' => function ($query) {
|
||||
$query->where('month', $this->month)
|
||||
->where('year', $this->year);
|
||||
->where('year', $this->year);
|
||||
}
|
||||
])
|
||||
->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.m_level', '!=', null)
|
||||
->where('users.m_sponsor', '=', null)
|
||||
->where('users.payment_account', '!=', null)
|
||||
->where('users.active_date', '<=', $this->endDate)
|
||||
->get();
|
||||
->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.m_level', '!=', null)
|
||||
->where('users.m_sponsor', '=', null)
|
||||
->where('users.payment_account', '!=', null)
|
||||
->where('users.active_date', '<=', $this->endDate)
|
||||
->where('users.payment_account', '>', $this->endDate)
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -66,19 +67,19 @@ class BusinessUserRepository
|
|||
public function getParentlessUsers(array $excludeUserIds = []): LazyCollection
|
||||
{
|
||||
$query = User::with([
|
||||
'account',
|
||||
'account',
|
||||
'user_level',
|
||||
'userBusiness' => function($query) {
|
||||
'userBusiness' => function ($query) {
|
||||
$query->where('month', $this->month)
|
||||
->where('year', $this->year);
|
||||
->where('year', $this->year);
|
||||
}
|
||||
])
|
||||
->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.payment_account', '!=', null)
|
||||
->where('users.active_date', '<=', $this->endDate);
|
||||
->select('users.*')
|
||||
->where('users.deleted_at', '=', null)
|
||||
->where('users.id', '!=', 1)
|
||||
->where('users.admin', '<', 4)
|
||||
->where('users.payment_account', '!=', null)
|
||||
->where('users.active_date', '<=', $this->endDate);
|
||||
|
||||
if (!empty($excludeUserIds)) {
|
||||
$query->whereNotIn('users.id', $excludeUserIds);
|
||||
|
|
@ -93,16 +94,16 @@ class BusinessUserRepository
|
|||
public function getUserWithRelations(int $userId): ?User
|
||||
{
|
||||
$cacheKey = "user_relations_{$userId}_{$this->month}_{$this->year}";
|
||||
|
||||
return cache()->remember($cacheKey, 1800, function() use ($userId) {
|
||||
|
||||
return cache()->remember($cacheKey, 1800, function () use ($userId) {
|
||||
\Log::debug("BusinessUserRepository: Loading user {$userId} with relations (cache miss)");
|
||||
|
||||
|
||||
return User::with([
|
||||
'account',
|
||||
'account',
|
||||
'user_level',
|
||||
'userBusiness' => function($query) {
|
||||
'userBusiness' => function ($query) {
|
||||
$query->where('month', $this->month)
|
||||
->where('year', $this->year);
|
||||
->where('year', $this->year);
|
||||
}
|
||||
])->find($userId);
|
||||
});
|
||||
|
|
@ -114,7 +115,7 @@ class BusinessUserRepository
|
|||
public function getSponsorForUser(int $userId): ?User
|
||||
{
|
||||
$user = $this->getUserWithRelations($userId);
|
||||
|
||||
|
||||
if (!$user || !$user->m_sponsor) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -128,10 +129,10 @@ class BusinessUserRepository
|
|||
public function getStoredStructure(): ?UserBusinessStructure
|
||||
{
|
||||
$cacheKey = "stored_structure_{$this->month}_{$this->year}";
|
||||
|
||||
return cache()->remember($cacheKey, 7200, function() {
|
||||
|
||||
return cache()->remember($cacheKey, 7200, function () {
|
||||
\Log::debug("BusinessUserRepository: Loading stored structure (cache miss)");
|
||||
|
||||
|
||||
$structure = UserBusinessStructure::where('year', $this->year)
|
||||
->where('month', $this->month)
|
||||
->first();
|
||||
|
|
@ -167,32 +168,48 @@ class BusinessUserRepository
|
|||
{
|
||||
foreach ($structure as $item) {
|
||||
$userIds[] = $item->user_id;
|
||||
|
||||
|
||||
if (isset($item->parents) && is_array($item->parents)) {
|
||||
$this->extractUserIdsFromStructure($item->parents, $userIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht alle Cache-Einträge für den aktuellen Monat/Jahr
|
||||
*/
|
||||
public function clearCache(): void
|
||||
{
|
||||
$cacheKeys = [
|
||||
"root_users_{$this->month}_{$this->year}",
|
||||
"stored_structure_{$this->month}_{$this->year}"
|
||||
];
|
||||
|
||||
foreach ($cacheKeys as $key) {
|
||||
cache()->forget($key);
|
||||
\Log::info("BusinessUserRepository: Cache cleared for key: {$key}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch-Loading für User-Kollektionen
|
||||
*/
|
||||
public function loadUsersInBatches(array $userIds, int $batchSize = 100): \Generator
|
||||
{
|
||||
$chunks = array_chunk($userIds, $batchSize);
|
||||
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
yield User::with([
|
||||
'account',
|
||||
'account',
|
||||
'user_level',
|
||||
'userBusiness' => function($query) {
|
||||
'userBusiness' => function ($query) {
|
||||
$query->where('month', $this->month)
|
||||
->where('year', $this->year);
|
||||
->where('year', $this->year);
|
||||
}
|
||||
])
|
||||
->whereIn('id', $chunk)
|
||||
->get()
|
||||
->keyBy('id');
|
||||
->whereIn('id', $chunk)
|
||||
->get()
|
||||
->keyBy('id');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ class TreeCalcBotOptimized
|
|||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(
|
||||
int $month,
|
||||
int $year,
|
||||
int $month,
|
||||
int $year,
|
||||
string $initFrom = 'member',
|
||||
bool $forceLiveCalculation = false,
|
||||
?BusinessUserRepository $repository = null,
|
||||
|
|
@ -47,7 +47,7 @@ class TreeCalcBotOptimized
|
|||
$this->initializeDate($month, $year);
|
||||
$this->initFrom = $initFrom;
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
|
||||
// Dependency Injection mit Fallback
|
||||
$this->repository = $repository ?? new BusinessUserRepository($month, $year);
|
||||
$this->renderer = $renderer ?? new TreeHtmlRenderer($initFrom, $forceLiveCalculation);
|
||||
|
|
@ -65,13 +65,13 @@ class TreeCalcBotOptimized
|
|||
|
||||
try {
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
$this->logger->info("Building fresh business structure for {$this->date->month}/{$this->date->year} with forced live calculation");
|
||||
$this->buildFreshStructure();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$storedStructure = null;
|
||||
if ($check) {
|
||||
$storedStructure = $this->repository->getStoredStructure();
|
||||
|
|
@ -83,7 +83,6 @@ class TreeCalcBotOptimized
|
|||
$this->logger->info("Building fresh business structure for {$this->date->month}/{$this->date->year}");
|
||||
$this->buildFreshStructure();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error initializing admin structure: " . $e->getMessage());
|
||||
throw $e;
|
||||
|
|
@ -100,7 +99,7 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
try {
|
||||
$this->forceLiveCalculation = $forceLiveCalculation;
|
||||
|
||||
|
||||
if ($forceLiveCalculation) {
|
||||
$this->logger->info("Initializing structure for user: {$userId} with forced live calculation");
|
||||
} else {
|
||||
|
|
@ -114,11 +113,11 @@ class TreeCalcBotOptimized
|
|||
return;
|
||||
}
|
||||
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this);
|
||||
$businessUserItem->makeUserFromModel($user); // Erst User-Model laden, ohne forceLiveCalculation
|
||||
$this->addUserIdToProcessed($userId);
|
||||
$this->businessUsers[] = $businessUserItem;
|
||||
|
||||
|
||||
$this->logger->info("Created businessUserItem for user {$userId}, total businessUsers: " . count($this->businessUsers));
|
||||
|
||||
// Prüfe gespeicherte Struktur nur, wenn Live-Berechnung nicht erzwungen wird
|
||||
|
|
@ -127,7 +126,7 @@ class TreeCalcBotOptimized
|
|||
$storedStructure = $this->repository->getStoredStructure();
|
||||
$this->logger->info("Stored structure " . ($storedStructure ? "found" : "not found"));
|
||||
}
|
||||
|
||||
|
||||
if ($storedStructure && !$forceLiveCalculation) {
|
||||
$this->loadStoredParentsUsers($storedStructure);
|
||||
if (isset($this->businessUsers[0]) && $this->businessUsers[0]->sponsor) {
|
||||
|
|
@ -139,13 +138,13 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
$this->loadParentsUsers();
|
||||
$this->loadSponsorUser($userId);
|
||||
|
||||
|
||||
$totalSubUsers = 0;
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
$totalSubUsers += count($businessUser->businessUserItems);
|
||||
}
|
||||
$this->logger->info("After loadParentsUsers: {$totalSubUsers} total sub-users loaded across " . count($this->businessUsers) . " business users");
|
||||
|
||||
|
||||
// WICHTIG: calcQualPP() erst NACH loadParentsUsers() aufrufen, da Points benötigt werden
|
||||
if ($forceLiveCalculation) {
|
||||
$this->logger->info("Calculating qualification levels for all business users");
|
||||
|
|
@ -156,7 +155,6 @@ class TreeCalcBotOptimized
|
|||
//$this->calculateQualPPForAllUsers(); // Auch für alle Sub-User
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error initializing user structure for {$userId}: " . $e->getMessage());
|
||||
throw $e;
|
||||
|
|
@ -173,11 +171,11 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
try {
|
||||
$this->logger->info("Initializing business user details for: {$user->id}");
|
||||
|
||||
$this->businessUser = new BusinessUserItemOptimized($this->date);
|
||||
|
||||
$this->businessUser = new BusinessUserItemOptimized($this->date, $this);
|
||||
$this->businessUser->makeUserFromModel($user, $forceLiveCalculation); // ✅ Nutzt bereits User-Objekt
|
||||
$this->businessUser->checkSponsor($user);
|
||||
|
||||
|
||||
// Führe vollständige Berechnung durch, wenn:
|
||||
// 1. Daten nicht gespeichert sind ODER
|
||||
// 2. Live-Berechnung erzwungen wird
|
||||
|
|
@ -185,19 +183,17 @@ class TreeCalcBotOptimized
|
|||
if ($forceLiveCalculation) {
|
||||
$this->logger->info("Forcing live calculation for user {$user->id}");
|
||||
}
|
||||
|
||||
|
||||
// Aufbau der Struktur für den User in die unendliche Tiefe
|
||||
$this->businessUser->readParentsBusinessUsers($forceLiveCalculation);
|
||||
|
||||
|
||||
// Calculate Points in Lines (optimiert für Memory-Effizienz)
|
||||
if (count($this->businessUser->businessUserItems) > 0) {
|
||||
$this->calculateUserPointsOptimized($this->businessUser->businessUserItems, 1, $this->businessUser);
|
||||
}
|
||||
// Qualifikation nach qual_kp (KundenPoints) und qual_pp (PaylinePoints)
|
||||
$this->businessUser->calcQualPP();
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error initializing business user details for {$user->id}: " . $e->getMessage());
|
||||
throw $e;
|
||||
|
|
@ -223,7 +219,7 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
return array_slice($bLines, 6);
|
||||
}
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
@ -242,11 +238,11 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
|
||||
$lineData = $bLines[$line];
|
||||
|
||||
|
||||
if ($lineData instanceof stdClass) {
|
||||
return $lineData->{$key} ?? 0;
|
||||
}
|
||||
|
||||
|
||||
if (is_array($lineData)) {
|
||||
return $lineData[$key] ?? 0;
|
||||
}
|
||||
|
|
@ -286,37 +282,37 @@ class TreeCalcBotOptimized
|
|||
public function getTotalUserCount(): int
|
||||
{
|
||||
$totalCount = 0;
|
||||
|
||||
|
||||
// Zähle alle Root-User
|
||||
$totalCount += count($this->businessUsers);
|
||||
|
||||
|
||||
// Zähle alle Unter-User rekursiv
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
$totalCount += $this->countBusinessUserItems($businessUser);
|
||||
}
|
||||
|
||||
|
||||
// Zähle parentless User
|
||||
$totalCount += count($this->parentless);
|
||||
|
||||
|
||||
return $totalCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Zählt BusinessUserItems rekursiv
|
||||
*/
|
||||
private function countBusinessUserItems($businessUserItem): int
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
|
||||
if (isset($businessUserItem->businessUserItems) && is_array($businessUserItem->businessUserItems)) {
|
||||
$count += count($businessUserItem->businessUserItems);
|
||||
|
||||
|
||||
// Rekursiv durch alle Unter-Items zählen
|
||||
foreach ($businessUserItem->businessUserItems as $subItem) {
|
||||
$count += $this->countBusinessUserItems($subItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
|
@ -337,10 +333,19 @@ class TreeCalcBotOptimized
|
|||
return ($structure && $structure->completed) ? $structure : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffentliche Methode zum Hinzufügen einer User ID zu den verarbeiteten IDs
|
||||
*/
|
||||
public function addProcessedUserId(int $id): void
|
||||
{
|
||||
$this->addUserIdToProcessed($id);
|
||||
}
|
||||
|
||||
public static function addUserID(int $id): void
|
||||
{
|
||||
// Deprecated: Wird durch Instanz-Methode ersetzt
|
||||
// Bleibt für Rückwärtskompatibilität erhalten
|
||||
// Deprecated: Statische Methode kann nicht auf Instanz-Variable zugreifen
|
||||
// Verwende stattdessen die Instanz-Methode addProcessedUserId()
|
||||
throw new \BadMethodCallException('addUserID ist deprecated. Verwende Instanz-Methode addProcessedUserId() stattdessen.');
|
||||
}
|
||||
|
||||
// ===== Private Methoden =====
|
||||
|
|
@ -381,7 +386,7 @@ class TreeCalcBotOptimized
|
|||
$this->loadStoredRootUsers($structure);
|
||||
$this->loadStoredParentsUsers($structure);
|
||||
$this->loadStoredParentlessUsers($structure);
|
||||
|
||||
|
||||
// Prüfe ob gespeicherte Daten vollständig sind, ansonsten berechne neu
|
||||
$this->validateAndRecalculateIfNeeded();
|
||||
$this->validateAndRecalculateParentlessIfNeeded();
|
||||
|
|
@ -395,7 +400,7 @@ class TreeCalcBotOptimized
|
|||
$this->loadRootUsers();
|
||||
$this->loadParentsUsers();
|
||||
$this->loadParentlessUsers();
|
||||
|
||||
|
||||
// WICHTIG: Berechne Punkte und Qualifikationen für alle Business-Users
|
||||
$this->calculateAllBusinessUsers();
|
||||
$this->calculateAllParentlessUsers();
|
||||
|
|
@ -408,12 +413,11 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
$startMemory = memory_get_usage();
|
||||
$users = $this->repository->getRootUsers();
|
||||
|
||||
foreach ($users as $user) {
|
||||
// Memory-Check vor jeder User-Verarbeitung
|
||||
$this->checkMemoryUsage('loadRootUsers', $user->id);
|
||||
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this);
|
||||
$businessUserItem->makeUserFromModel($user, $this->forceLiveCalculation); // ✅ Nutzt bereits geladene Relations mit forceLiveCalculation
|
||||
$this->addUserIdToProcessed($user->id);
|
||||
$this->businessUsers[] = $businessUserItem;
|
||||
|
|
@ -421,7 +425,7 @@ class TreeCalcBotOptimized
|
|||
|
||||
$endMemory = memory_get_usage();
|
||||
$memoryUsed = $this->formatBytes($endMemory - $startMemory);
|
||||
|
||||
|
||||
$this->logger->info("Loaded " . count($users) . " root users with optimized relations. Memory used: {$memoryUsed}");
|
||||
}
|
||||
|
||||
|
|
@ -431,10 +435,10 @@ class TreeCalcBotOptimized
|
|||
private function loadParentsUsers(): void
|
||||
{
|
||||
$this->logger->info("Loading parent users for " . count($this->businessUsers) . " business users");
|
||||
|
||||
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
$businessUser->readParentsBusinessUsers($this->forceLiveCalculation);
|
||||
|
||||
|
||||
$this->logger->debug("Loaded " . count($businessUser->businessUserItems) . " parent users for user " . ($businessUser->b_user->user_id ?? 'unknown'));
|
||||
}
|
||||
}
|
||||
|
|
@ -446,9 +450,9 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
$count = 0;
|
||||
$excludeIds = array_keys($this->processedUserIds);
|
||||
|
||||
|
||||
foreach ($this->repository->getParentlessUsers($excludeIds) as $user) {
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this);
|
||||
$businessUserItem->makeUserFromModel($user, $this->forceLiveCalculation); // ✅ Nutzt bereits geladene Relations mit forceLiveCalculation
|
||||
$this->parentless[] = $businessUserItem;
|
||||
$count++;
|
||||
|
|
@ -464,24 +468,23 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
$startTime = microtime(true);
|
||||
$this->logger->info("Starting calculation for " . count($this->businessUsers) . " business users");
|
||||
|
||||
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
try {
|
||||
// Berechne Punkte in Linien (wie bei initBusinesslUserDetail)
|
||||
if (count($businessUser->businessUserItems) > 0) {
|
||||
$this->calculateUserPointsOptimized($businessUser->businessUserItems, 1, $businessUser);
|
||||
}
|
||||
|
||||
|
||||
// Qualifikation nach qual_kp und qual_pp berechnen
|
||||
$businessUser->calcQualPP();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error calculating business user {$businessUser->__get('user_id')}: " . $e->getMessage());
|
||||
// Weiter mit dem nächsten User, nicht abbrechen
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->logger->info("Completed calculations for all business users in {$executionTime}ms");
|
||||
|
|
@ -495,26 +498,25 @@ class TreeCalcBotOptimized
|
|||
if (empty($this->parentless)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$startTime = microtime(true);
|
||||
$this->logger->info("Starting calculation for " . count($this->parentless) . " parentless users");
|
||||
|
||||
|
||||
foreach ($this->parentless as $parentlessUser) {
|
||||
try {
|
||||
// Berechne Punkte in Linien
|
||||
if (count($parentlessUser->businessUserItems) > 0) {
|
||||
$this->calculateUserPointsOptimized($parentlessUser->businessUserItems, 1, $parentlessUser);
|
||||
}
|
||||
|
||||
|
||||
// Qualifikation berechnen
|
||||
$parentlessUser->calcQualPP();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error calculating parentless user {$parentlessUser->__get('user_id')}: " . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
$executionTime = round(($endTime - $startTime) * 1000, 2);
|
||||
$this->logger->info("Completed calculations for all parentless users in {$executionTime}ms");
|
||||
|
|
@ -526,25 +528,24 @@ class TreeCalcBotOptimized
|
|||
private function validateAndRecalculateIfNeeded(): void
|
||||
{
|
||||
$incompleteUsers = 0;
|
||||
|
||||
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
// Prüfe ob grundlegende Berechnungen vorhanden sind
|
||||
if ($this->isBusinessUserIncomplete($businessUser)) {
|
||||
$incompleteUsers++;
|
||||
|
||||
|
||||
try {
|
||||
// Führe fehlende Berechnungen durch
|
||||
if (count($businessUser->businessUserItems) > 0) {
|
||||
$this->calculateUserPointsOptimized($businessUser->businessUserItems, 1, $businessUser);
|
||||
}
|
||||
$businessUser->calcQualPP();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error recalculating business user {$businessUser->__get('user_id')}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($incompleteUsers > 0) {
|
||||
$this->logger->info("Recalculated {$incompleteUsers} incomplete business users from stored data");
|
||||
}
|
||||
|
|
@ -559,20 +560,20 @@ class TreeCalcBotOptimized
|
|||
// Prüfe grundlegende Felder die nach Berechnungen vorhanden sein sollten
|
||||
$salesVolumeSum = $businessUser->__get('sales_volume_points_sum');
|
||||
$qualKp = $businessUser->__get('qual_kp');
|
||||
|
||||
|
||||
// Prüfe Level-Qualifikationsdaten für Struktur-Ansicht
|
||||
$nextQualUserLevel = $businessUser->__get('next_qual_user_level');
|
||||
$nextCanUserLevel = $businessUser->__get('next_can_user_level');
|
||||
$hasLevelQualificationData = !empty($nextQualUserLevel) || !empty($nextCanUserLevel);
|
||||
|
||||
|
||||
// User ist unvollständig wenn:
|
||||
// 1. Grundlegende berechnete Werte fehlen ODER
|
||||
// 2. Level-Qualifikationsdaten fehlen (wichtig für Struktur-Ansicht mit grünen Pfeilen)
|
||||
$missingBasicData = ($salesVolumeSum === null || $salesVolumeSum === 0) &&
|
||||
($qualKp === null || $qualKp === 0);
|
||||
|
||||
$missingBasicData = ($salesVolumeSum === null || $salesVolumeSum === 0) &&
|
||||
($qualKp === null || $qualKp === 0);
|
||||
|
||||
$missingLevelData = !$hasLevelQualificationData;
|
||||
|
||||
|
||||
return $missingBasicData || $missingLevelData;
|
||||
}
|
||||
|
||||
|
|
@ -584,25 +585,24 @@ class TreeCalcBotOptimized
|
|||
if (empty($this->parentless)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$incompleteUsers = 0;
|
||||
|
||||
|
||||
foreach ($this->parentless as $parentlessUser) {
|
||||
if ($this->isBusinessUserIncomplete($parentlessUser)) {
|
||||
$incompleteUsers++;
|
||||
|
||||
|
||||
try {
|
||||
if (count($parentlessUser->businessUserItems) > 0) {
|
||||
$this->calculateUserPointsOptimized($parentlessUser->businessUserItems, 1, $parentlessUser);
|
||||
}
|
||||
$parentlessUser->calcQualPP();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error recalculating parentless user {$parentlessUser->__get('user_id')}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($incompleteUsers > 0) {
|
||||
$this->logger->info("Recalculated {$incompleteUsers} incomplete parentless users from stored data");
|
||||
}
|
||||
|
|
@ -615,9 +615,9 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
try {
|
||||
$sponsorUser = $this->repository->getSponsorForUser($userId);
|
||||
|
||||
|
||||
if ($sponsorUser) {
|
||||
$this->sponsor = new BusinessUserItemOptimized($this->date);
|
||||
$this->sponsor = new BusinessUserItemOptimized($this->date, $this);
|
||||
$this->sponsor->makeUser($sponsorUser->id);
|
||||
$this->logger->info("Loaded sponsor {$sponsorUser->id} for user {$userId}");
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
|
||||
foreach ($structure->structure as $obj) {
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this);
|
||||
$businessUserItem->makeUser($obj->user_id);
|
||||
$this->addUserIdToProcessed($obj->user_id);
|
||||
$this->businessUsers[] = $businessUserItem;
|
||||
|
|
@ -664,7 +664,7 @@ class TreeCalcBotOptimized
|
|||
|
||||
foreach ($structure->parentless as $obj) {
|
||||
if (!isset($this->processedUserIds[$obj->user_id])) {
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date);
|
||||
$businessUserItem = new BusinessUserItemOptimized($this->date, $this);
|
||||
$businessUserItem->makeUser($obj->user_id);
|
||||
$this->parentless[] = $businessUserItem;
|
||||
}
|
||||
|
|
@ -676,7 +676,7 @@ class TreeCalcBotOptimized
|
|||
*/
|
||||
private function loadStoredSponsorUser(int $userId): void
|
||||
{
|
||||
$this->sponsor = new BusinessUserItemOptimized($this->date);
|
||||
$this->sponsor = new BusinessUserItemOptimized($this->date, $this);
|
||||
$this->sponsor->makeUser($userId);
|
||||
}
|
||||
|
||||
|
|
@ -691,7 +691,7 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
$processingStack = [];
|
||||
$collectionStack = []; // Sammelt Items in korrekter Reihenfolge
|
||||
|
||||
|
||||
// Phase 1: Sammle alle Items in Depth-First Reihenfolge
|
||||
foreach ($businessUserItems as $item) {
|
||||
$collectionStack[] = ['item' => $item, 'line' => $startLine, 'depth' => 0];
|
||||
|
|
@ -704,11 +704,11 @@ class TreeCalcBotOptimized
|
|||
$item = $current['item'];
|
||||
$line = $current['line'];
|
||||
$depth = $current['depth'];
|
||||
|
||||
|
||||
// Markiere für Verarbeitung (mit Tiefe für spätere Sortierung)
|
||||
$processingStack[] = [
|
||||
'item' => $item,
|
||||
'line' => $line,
|
||||
'item' => $item,
|
||||
'line' => $line,
|
||||
'depth' => $depth,
|
||||
'id' => $item->user_id ?? uniqid()
|
||||
];
|
||||
|
|
@ -719,8 +719,8 @@ class TreeCalcBotOptimized
|
|||
$children = array_reverse($item->businessUserItems);
|
||||
foreach ($children as $childItem) {
|
||||
array_unshift($collectionStack, [
|
||||
'item' => $childItem,
|
||||
'line' => $line + 1,
|
||||
'item' => $childItem,
|
||||
'line' => $line + 1,
|
||||
'depth' => $depth + 1
|
||||
]);
|
||||
}
|
||||
|
|
@ -728,7 +728,7 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
|
||||
// Phase 2: Sortiere nach Tiefe (tiefste zuerst, wie bei Rekursion)
|
||||
usort($processingStack, function($a, $b) {
|
||||
usort($processingStack, function ($a, $b) {
|
||||
return $b['depth'] <=> $a['depth']; // Tiefste zuerst
|
||||
});
|
||||
|
||||
|
|
@ -753,7 +753,6 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
|
||||
$this->logger->debug("Processed user {$current['id']} at line {$line} with {$points} points");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Error processing user points for {$current['id']}: " . $e->getMessage());
|
||||
}
|
||||
|
|
@ -771,9 +770,9 @@ class TreeCalcBotOptimized
|
|||
}
|
||||
|
||||
/**
|
||||
* Prüft ob User bereits verarbeitet wurde
|
||||
* Prüft ob User bereits verarbeitet wurde (Public für BusinessUserItemOptimized)
|
||||
*/
|
||||
private function isUserProcessed(int $id): bool
|
||||
public function isUserProcessed(int $id): bool
|
||||
{
|
||||
return isset($this->processedUserIds[$id]);
|
||||
}
|
||||
|
|
@ -790,7 +789,7 @@ class TreeCalcBotOptimized
|
|||
if ($memoryPercent > 80) {
|
||||
$currentFormatted = $this->formatBytes($currentMemory);
|
||||
$limitFormatted = $this->formatBytes($memoryLimit);
|
||||
|
||||
|
||||
$this->logger->warning("High memory usage detected in {$operation}", [
|
||||
'identifier' => $identifier,
|
||||
'current_memory' => $currentFormatted,
|
||||
|
|
@ -809,13 +808,16 @@ class TreeCalcBotOptimized
|
|||
private function parseMemoryLimit(string $limit): int
|
||||
{
|
||||
$limit = trim($limit);
|
||||
$last = strtolower($limit[strlen($limit)-1]);
|
||||
$last = strtolower($limit[strlen($limit) - 1]);
|
||||
$number = (int) $limit;
|
||||
|
||||
switch($last) {
|
||||
case 'g': $number *= 1024;
|
||||
case 'm': $number *= 1024;
|
||||
case 'k': $number *= 1024;
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$number *= 1024;
|
||||
case 'm':
|
||||
$number *= 1024;
|
||||
case 'k':
|
||||
$number *= 1024;
|
||||
}
|
||||
|
||||
return $number;
|
||||
|
|
@ -859,21 +861,21 @@ class TreeCalcBotOptimized
|
|||
{
|
||||
$this->logger->info("Starting recursive calcQualPP for all users");
|
||||
$totalCalculated = 0;
|
||||
|
||||
|
||||
foreach ($this->businessUsers as $businessUser) {
|
||||
$totalCalculated += $this->calculateQualPPRecursive($businessUser);
|
||||
}
|
||||
|
||||
|
||||
$this->logger->info("Completed calcQualPP for {$totalCalculated} users");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rekursive Hilfsmethode für calcQualPP
|
||||
*/
|
||||
private function calculateQualPPRecursive($businessUser): int
|
||||
{
|
||||
$calculated = 0;
|
||||
|
||||
|
||||
if (isset($businessUser->businessUserItems) && is_array($businessUser->businessUserItems)) {
|
||||
foreach ($businessUser->businessUserItems as $subBusinessUser) {
|
||||
if ($subBusinessUser->b_user && $subBusinessUser->b_user->user_id) {
|
||||
|
|
@ -884,13 +886,13 @@ class TreeCalcBotOptimized
|
|||
} catch (\Exception $e) {
|
||||
$this->logger->warning("Error calculating calcQualPP for user " . $subBusinessUser->b_user->user_id . ": " . $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
// Rekursiver Aufruf
|
||||
$calculated += $this->calculateQualPPRecursive($subBusinessUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $calculated;
|
||||
}
|
||||
|
||||
|
|
@ -907,4 +909,4 @@ class TreeCalcBotOptimized
|
|||
throw new \InvalidArgumentException("Property {$name} cannot be set");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue