10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
|
|
@ -1,70 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ShippingCountry;
|
||||
use App\User;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
use Yard;
|
||||
|
||||
class UserService
|
||||
{
|
||||
public static $user_country;
|
||||
|
||||
public static $shipping_country;
|
||||
|
||||
public static $shipping_free = false;
|
||||
|
||||
public static $user_tax_free = false;
|
||||
|
||||
public static $user_reverse_charge = false;
|
||||
|
||||
public static $instance = 'shopping';
|
||||
|
||||
public static function getTransChange(){
|
||||
public static function getTransChange()
|
||||
{
|
||||
|
||||
$langs = config('localization.supportedLocales');
|
||||
$ret = [];
|
||||
foreach($langs as $code => $lang){
|
||||
$ret[strtolower($code)] = strtolower($lang['native']);
|
||||
foreach ($langs as $code => $lang) {
|
||||
$ret[strtolower($code)] = strtolower($lang['native']);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function setInstance($instance){
|
||||
public static function setInstance($instance)
|
||||
{
|
||||
self::$instance = $instance;
|
||||
}
|
||||
|
||||
//init Yard for user order Customer
|
||||
public static function initCustomerYard($shopping_user, $for){
|
||||
// init Yard for user order Customer
|
||||
public static function initCustomerYard($shopping_user, $for)
|
||||
{
|
||||
self::$user_tax_free = false;
|
||||
if($shopping_user->same_as_billing){
|
||||
if ($shopping_user->same_as_billing) {
|
||||
self::$user_country = $shopping_user->billing_country;
|
||||
self::$shipping_country = $shopping_user->billing_country;
|
||||
}else{
|
||||
} else {
|
||||
self::$user_country = $shopping_user->billing_country;
|
||||
self::$shipping_country = $shopping_user->shipping_country;
|
||||
}
|
||||
if(self::$user_country->supply_country && self::$shipping_country->supply_country){
|
||||
if (self::$user_country->supply_country && self::$shipping_country->supply_country) {
|
||||
self::$user_tax_free = true;
|
||||
}
|
||||
$ShippingCountry = ShippingCountry::whereCountryId(self::$shipping_country->id)->first();
|
||||
self::$shipping_free = $ShippingCountry->shipping ? $ShippingCountry->shipping->free : false;
|
||||
|
||||
$shippingCountry = ShippingCountry::whereCountryId(self::$shipping_country->id)->first();
|
||||
if (! $shippingCountry) {
|
||||
$shippingCountry = ShippingCountry::query()
|
||||
->whereHas('shipping', fn ($q) => $q->where('active', true))
|
||||
->orderBy('id')
|
||||
->first();
|
||||
}
|
||||
if (! $shippingCountry) {
|
||||
$shippingCountry = ShippingCountry::query()->orderBy('id')->first();
|
||||
}
|
||||
if (! $shippingCountry) {
|
||||
throw new RuntimeException('Kein Eintrag in shipping_countries (Tabelle leer oder nicht migriert).');
|
||||
}
|
||||
|
||||
self::$shipping_free = $shippingCountry->shipping?->free ?? false;
|
||||
self::$shipping_free = self::$shipping_free !== null ? self::$shipping_free : false;
|
||||
Yard::instance(self::$instance)->setShippingCountryWithPrice($ShippingCountry->id, $for);
|
||||
Yard::instance(self::$instance)->setShippingCountryWithPrice($shippingCountry->id, $for);
|
||||
Yard::instance(self::$instance)->setUserPriceInfos(self::getYardInfo());
|
||||
}
|
||||
|
||||
//init Yard for user order Berater
|
||||
public static function initUserYard(User $user, $shipping_country_id, $for){
|
||||
// init Yard for user order Berater
|
||||
public static function initUserYard(User $user, $shipping_country_id, $for)
|
||||
{
|
||||
self::$shipping_free = false;
|
||||
self::checkUserTaxShippingCountry($user, $shipping_country_id,);
|
||||
self::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
Yard::instance(self::$instance)->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
Yard::instance(self::$instance)->setUserPriceInfos(self::getYardInfo());
|
||||
}
|
||||
|
||||
|
||||
public static function checkUserTaxShippingCountry(User $user, $shipping_country_id) {
|
||||
|
||||
if(!$user->account || !$user->account->country_id){
|
||||
public static function checkUserTaxShippingCountry(User $user, $shipping_country_id)
|
||||
{
|
||||
|
||||
if (! $user->account || ! $user->account->country_id) {
|
||||
abort(403, 'Error: User hat kein Land!');
|
||||
}
|
||||
$ShippingCountry = ShippingCountry::findOrFail($shipping_country_id);
|
||||
self::$user_tax_free = self::performUserTaxShippingCountry($user, $ShippingCountry);
|
||||
|
||||
return $ShippingCountry;
|
||||
/*
|
||||
dump( self::$user_price_code );
|
||||
|
|
@ -73,50 +100,56 @@ class UserService
|
|||
*/
|
||||
}
|
||||
|
||||
public static function performUserTaxShippingCountry($user, $ShippingCountry){
|
||||
//preise für das Land
|
||||
public static function performUserTaxShippingCountry($user, $ShippingCountry)
|
||||
{
|
||||
// preise für das Land
|
||||
self::$user_country = $user->account->country;
|
||||
self::$shipping_country = $ShippingCountry->country;
|
||||
//ausgehend vom Land des Rechnungsempfänger $user->account->country
|
||||
//ist der Rechnungsempfänger im Drittland?
|
||||
if($user->account->country->supply_country){
|
||||
if($ShippingCountry->country->supply_country){
|
||||
//Lieferadresse im Drittland?
|
||||
// ausgehend vom Land des Rechnungsempfänger $user->account->country
|
||||
// ist der Rechnungsempfänger im Drittland?
|
||||
if ($user->account->country->supply_country) {
|
||||
if ($ShippingCountry->country->supply_country) {
|
||||
// Lieferadresse im Drittland?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Rechnungsempfänger in der EU
|
||||
|
||||
//Lieferland mit RSV
|
||||
if($ShippingCountry->country->eu_country){
|
||||
//Rechnungsempfänger mit valid aktiv RSV
|
||||
if($user->account->reverse_charge && $user->account->reverse_charge_valid){
|
||||
//Rechnungsland ist auch Lieferland, dann RSV
|
||||
if(strtolower($user->account->reverse_charge_code) == strtolower($ShippingCountry->country->code)){
|
||||
// Rechnungsempfänger in der EU
|
||||
|
||||
// Lieferland mit RSV
|
||||
if ($ShippingCountry->country->eu_country) {
|
||||
// Rechnungsempfänger mit valid aktiv RSV
|
||||
if ($user->account->reverse_charge && $user->account->reverse_charge_valid) {
|
||||
// Rechnungsland ist auch Lieferland, dann RSV
|
||||
if (strtolower($user->account->reverse_charge_code) == strtolower($ShippingCountry->country->code)) {
|
||||
self::$user_reverse_charge = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Lieferland ohne RSV
|
||||
}
|
||||
|
||||
// Lieferland ohne RSV
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getYardInfo(){
|
||||
public static function getYardInfo()
|
||||
{
|
||||
return [
|
||||
'shipping_free' => self::$shipping_free,
|
||||
'shipping_free' => self::$shipping_free,
|
||||
'user_tax_free' => self::$user_tax_free,
|
||||
'user_reverse_charge' => self::$user_reverse_charge,
|
||||
'user_country_id' => self::$user_country->id,
|
||||
'shipping_country_id' => self::$shipping_country->id,
|
||||
'shipping_country_id' => self::$shipping_country->id,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getTaxFree(){
|
||||
public static function getTaxFree()
|
||||
{
|
||||
return self::$user_tax_free ? true : false;
|
||||
}
|
||||
|
||||
public static function getUserPriceInfos(){
|
||||
public static function getUserPriceInfos()
|
||||
{
|
||||
return [
|
||||
'user_tax_free' => self::$user_tax_free,
|
||||
'user_reverse_charge' => self::$user_reverse_charge,
|
||||
|
|
@ -124,8 +157,9 @@ class UserService
|
|||
];
|
||||
}
|
||||
|
||||
public static function getOrderInfo($key = false){
|
||||
if(!self::$user_country){
|
||||
public static function getOrderInfo($key = false)
|
||||
{
|
||||
if (! self::$user_country) {
|
||||
return '';
|
||||
}
|
||||
switch ($key) {
|
||||
|
|
@ -139,22 +173,21 @@ class UserService
|
|||
return self::$user_tax_free ? __('no') : __('yes');
|
||||
break;
|
||||
case 'user_reverse_charge':
|
||||
return self::$user_reverse_charge ? __('yes') : __('no');
|
||||
return self::$user_reverse_charge ? __('yes') : __('no');
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function createConfirmationCode() {
|
||||
public static function createConfirmationCode()
|
||||
{
|
||||
$unique = false;
|
||||
do{
|
||||
do {
|
||||
$confirmation_code = Str::random(30);
|
||||
if(User::where('confirmation_code', '=', $confirmation_code)->count() == 0){
|
||||
if (User::where('confirmation_code', '=', $confirmation_code)->count() == 0) {
|
||||
$unique = true;
|
||||
}
|
||||
}
|
||||
while(!$unique);
|
||||
} while (! $unique);
|
||||
|
||||
return $confirmation_code;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue