Updates to 03-2025

This commit is contained in:
Kevin Adametz 2025-04-01 10:36:47 +02:00
parent bfa3bb1df4
commit 9ae662f63e
243 changed files with 12580 additions and 12018 deletions

View file

@ -1,48 +1,158 @@
<?php
namespace App\Services;
use App\Models\Product;
use Yard;
use App\User;
use Carbon\Carbon;
use App\Models\UserAbo;
use App\Models\UserAboItem;
use App\Models\UserAboOrder;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\Models\ShoppingUser;
class AboHelper
{
public static $txaction_filter_text = [
'paid' => 'paymend_paid',
'appointed' => 'paymend_open',
'failed' => 'paymend_failed',
'extern' => 'extern_open', //offen
'extern_paid' => 'extern_paid',
'invoice_open' => 'invoice_open',
'invoice_paid' => 'invoice_paid',
'invoice_non' => 'invoice_no_payment',
'NULL' => 'no_payment',
];
public static function userHasAbo(User $user){
$user = $user ? $user : \Auth::user();
return UserAbo::where('user_id', $user->id)->where('is_for', 'me')->where('status', '>', 1)->first() === null ? false : true;
}
public static function memberHasAbo(ShoppingUser $shopping_user){
if(!$shopping_user){
return false;
}
return UserAbo::where('email', $shopping_user->billing_email)->where('is_for', 'ot')->where('status', '>', 1)->first() === null ? false : true;
}
public static function hasAboByEmail($email){
return UserAbo::where('email', $email)->where('status', '>', 1)->first() === null ? false : true;
}
public static function setAboStatus(ShoppingOrder $shopping_order, $status){
$user_abo = $shopping_order->getUserAbo();
if($user_abo && $user_abo->status < 2){ //status < 2 is not active
$user_abo->update(['status' => $status]);
}
UserAboOrder::where('user_abo_id', $user_abo->id)->where('shopping_order_id', $shopping_order->id)->update(['status' => $status]);
}
public static function setAboActive(ShoppingOrder $shopping_order, $status){
self::setAboStatus($shopping_order, $status);
//delete UserAbo is not active status = 1
//is_for = me
UserAbo::where('user_id', $shopping_order->auth_user_id)->where('is_for', 'me')->where('status', 1)->delete();
//is_for = ot
UserAbo::where('member_id', $shopping_order->member_id)->where('email', $shopping_order->shopping_user->billing_email)->where('is_for', 'ot')->where('status', 1)->delete();
}
public static function aboHasBaseProduct($yard_products){
foreach($yard_products as $product){
if(is_array($product->options->show_on)){
if(in_array('12', $product->options->show_on)){
return true;
}
}
}
return false;
}
public static function getAboShowOn(Product $product){
$show_on = $product->show_on;
if(in_array('12', $show_on)){
return 'base';
}
if(in_array('13', $show_on)){
return 'upgrade';
}
return false;
}
public static function getAboTypeBadge($abo_type){
if($abo_type === 'base'){
return '<span class="badge badge-pill badge-warning"><i class="fas fa-star"></i> '.__('abo.'.$abo_type).'</span></a>';
}
if($abo_type === 'upgrade'){
return '<span class="badge badge-pill badge-info"><i class="far fa-star"></i> '.__('abo.'.$abo_type).'</span></a>';
}
return '';
}
public static function setNextDate($date, $abo_interval){
$nextDate = Carbon::parse($date)->firstOfMonth();
$nextDate->addDays($abo_interval-1);
return $nextDate->gt($date) ? $nextDate : $nextDate->addMonth(1);
}
public static function createNewAbo(ShoppingPayment $shopping_payment){
//is Abo - create init Abo from PP or else
if($shopping_payment->shopping_order->is_abo && $shopping_payment->shopping_order->abo_interval > 0){
$payment_transaction = $shopping_payment->payment_transactions->last();
$payment_transaction = $shopping_payment->payment_transactions->last();
$user_abo = UserAbo::create([
'user_id' => $shopping_payment->shopping_order->auth_user_id,
'shopping_user_id' => $shopping_payment->shopping_order->shopping_user_id,
'is_for' => $shopping_payment->shopping_order->shopping_user->is_for,
'payone_userid' => $payment_transaction->userid,
'clearingtype' => $shopping_payment->clearingtype,
'wallettype' => $shopping_payment->wallettype,
'amount' => $shopping_payment->amount,
'currency' => $shopping_payment->currency,
'status' => 1,
'abo_interval' => $shopping_payment->abo_interval,
'start_date' => now(),
'last_date' => now(),
'next_date' => now()->addWeeks($shopping_payment->abo_interval),
'next_abo_date' => $shopping_payment->created_at->addMonths($shopping_payment->abo_interval),
'count' => 1,
]);
if($user_abo){
UserAboOrder::create([
$user_abo = UserAbo::create([
'user_id' => $shopping_payment->shopping_order->auth_user_id,
'member_id' => $shopping_payment->shopping_order->member_id,
'shopping_user_id' => $shopping_payment->shopping_order->shopping_user_id,
'email' => $shopping_payment->shopping_order->shopping_user->billing_email,
'is_for' => $shopping_payment->shopping_order->shopping_user->is_for,
'payone_userid' => $payment_transaction->userid,
'clearingtype' => $shopping_payment->clearingtype,
'wallettype' => $shopping_payment->wallettype,
'carddata' => $shopping_payment->carddata,
'amount' => $shopping_payment->amount,
'status' => 1,
'abo_interval' => $shopping_payment->abo_interval,
'start_date' => now(),
'last_date' => now(),
'next_date' => self::setNextDate(now(), $shopping_payment->abo_interval),
]);
if($user_abo){
self::createAboItems($user_abo, $shopping_payment);
UserAboOrder::create([
'user_abo_id' => $user_abo->id,
'shopping_order_id' => $shopping_payment->shopping_order_id,
'status' => 1,
]);
}
}
}
public static function createAboItems($user_abo, ShoppingPayment $shopping_payment){
foreach($shopping_payment->shopping_order->shopping_order_items as $item){
UserAboItem::create([
'user_abo_id' => $user_abo->id,
'shopping_order_id' => $shopping_payment->shopping_order_id,
'product_id' => $item->product_id,
'comp' => $item->comp ?? 0,
'qty' => $item->qty,
'status' => 1,
]);
}
}
public static function getTransStatusFilterText(){
$ret = [];
foreach(self::$txaction_filter_text as $key=>$val){
$ret[$key] = trans('payment.'.$val);
}
return $ret;
}
}

View file

@ -0,0 +1,201 @@
<?php
namespace App\Services;
use Yard;
use App\User;
use Carbon\Carbon;
use App\Models\Product;
use App\Models\UserAbo;
use App\Models\UserAboItem;
use App\Models\ShoppingUser;
use App\Models\UserAboOrder;
use App\Models\ShoppingOrder;
use App\Models\ShippingCountry;
use App\Models\ShoppingPayment;
class AboOrderCart
{
private static $user_abo;
private static $is_for;
private static $customer_detail;
public static function initYard($user_abo){
self::$user_abo = $user_abo;
Yard::instance('shopping')->destroy();
self::$customer_detail = self::makeCustomerDetail($user_abo);
if($user_abo->is_for === 'me'){
self::$is_for = 'abo-me';
if($user_abo->user && $user_abo->user->account->same_as_billing){
$country_id = $user_abo->user->account->country_id;
}else{
$country_id = $user_abo->user->account->shipping_country_id;
}
if($country_id && $shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
if($shipping_country->shipping && $shipping_country->shipping->active){
UserService::initUserYard($user_abo->user, $shipping_country->id, 'abo-me');
return true;
}
}
abort(403, 'Fehler: Versandland nicht gefunden');
}
if($user_abo->is_for === 'ot'){
self::$is_for = 'abo-ot-customer';
UserService::initCustomerYard(self::$customer_detail, 'abo-ot-customer');
return true;
}
return false;
}
public static function makeOrderYard($user_abo)
{
self::$user_abo = $user_abo;
if($user_abo->is_for === 'ot'){
self::$is_for = 'abo-ot-customer';
}
if($user_abo->is_for === 'me'){
self::$is_for = 'abo-me';
}
foreach($user_abo->user_abo_items as $abo_item){
self::addProductToCart($abo_item);
}
Yard::instance('shopping')->reCalculateShippingPrice();
$user_abo->amount = Yard::instance('shopping')->totalWithShipping(2, '.', '')*100;
$user_abo->save();
}
private static function addProductToCart($item){
$product = Product::find($item->product_id);
$tax_free = Yard::instance('shopping')->getUserTaxFree();
$user_country = Yard::instance('shopping')->getUserCountry();
if($product){
if($item->comp){
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, false, false,
['image' => '', 'slug' => $product->slug, 'weight' => 0, 'points' => 0,
'comp' => $item->comp, 'product_id' => $product->id]);
Yard::setTax($cartItem->rowId, 0);
return true;
}
if(self::$is_for === 'ot-customer' || self::$is_for === 'abo-ot-customer'){
$cartItem = Yard::instance('shopping')
->add($product->id, $product->getLang('name'), $item->qty,
round($product->getPriceWith($tax_free, false, $user_country, false, self::$user_abo->user), 1), false, false,
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
}else{
$cartItem = Yard::instance('shopping')
->add($product->id, $product->getLang('name'), $item->qty,
$product->getPriceWith($tax_free, true, $user_country, false, self::$user_abo->user), false, false,
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
}
if($tax_free){
Yard::setTax($cartItem->rowId, 0);
}else{
Yard::setTax($cartItem->rowId, $product->getTaxWith($user_country));
}
}
}
public static function checkNumOfCompProducts($user_abo){
if($user_abo->is_for === 'me'){
$needNumComp = Yard::instance('shopping')->getNumComp();
if($needNumComp > 0){
$UserAboItems = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', '>', 0)->get();
if(count($UserAboItems) === $needNumComp){
return true;
}
//need to add
if(count($UserAboItems) < $needNumComp){
$product = Product::whereActive(true)->where('shipping_addon', true)->whereJsonContains('show_on', '12')->orderBy('pos', 'DESC')->first();
for($i = count($UserAboItems); $i <= $needNumComp; $i++){
$UserAboItem = UserAboItem::create([
'user_abo_id' => $user_abo->id,
'product_id' => $product->id,
'comp' => $i + 1,
'qty' => 1,
'status' => 1,
]);
self::addProductToCart($UserAboItem);
}
}
//need to remove
if(count($UserAboItems) > $needNumComp){
foreach($UserAboItems as $UserAboItem){
if($UserAboItem->comp > $needNumComp){
$UserAboItem->delete();
}
}
foreach (Yard::instance('shopping')->content() as $row) {
if($row->options->comp > $needNumComp) {
Yard::instance('shopping')->remove($row->rowId);
}
}
}
}
}
}
public static function getCustomerDetail(){
return self::$customer_detail;
}
/* Need this, can change the address */
public static function makeCustomerDetail($user_abo){
if($user_abo->is_for === 'me'){
//only on Abo!
$user = $user_abo->user;
$shopping_user = new ShoppingUser();
$shopping_user->billing_salutation = $user->account->salutation;
$shopping_user->billing_company = $user->account->company;
$shopping_user->billing_firstname = $user->account->first_name;
$shopping_user->billing_lastname = $user->account->last_name;
$shopping_user->billing_address = $user->account->address;
$shopping_user->billing_address_2 = $user->account->address_2;
$shopping_user->billing_zipcode = $user->account->zipcode;
$shopping_user->billing_city = $user->account->city;
$shopping_user->billing_country_id = $user->account->country_id;
$shopping_user->billing_phone = $user->account->phone;
if($user->account->same_as_billing){
$shopping_user->shipping_salutation = $user->account->salutation;
$shopping_user->shipping_company = $user->account->company;
$shopping_user->shipping_firstname = $user->account->first_name;
$shopping_user->shipping_lastname = $user->account->last_name;
$shopping_user->shipping_address = $user->account->address;
$shopping_user->shipping_address_2 = $user->account->address_2;
$shopping_user->shipping_zipcode = $user->account->zipcode;
$shopping_user->shipping_city = $user->account->city;
$shopping_user->shipping_country_id = $user->account->country_id;
$shopping_user->shipping_phone = $user->account->phone;
}else{
$shopping_user->shipping_salutation = $user->account->shipping_salutation;
$shopping_user->shipping_company = $user->account->shipping_company;
$shopping_user->shipping_firstname = $user->account->shipping_firstname;
$shopping_user->shipping_lastname = $user->account->shipping_lastname;
$shopping_user->shipping_address = $user->account->shipping_address;
$shopping_user->shipping_address_2 = $user->account->shipping_address_2;
$shopping_user->shipping_zipcode = $user->account->shipping_zipcode;
$shopping_user->shipping_city = $user->account->shipping_city;
$shopping_user->shipping_country_id = $user->account->shipping_country_id;
$shopping_user->shipping_phone = $user->account->shipping_phone;
}
}
if($user_abo->is_for === 'ot'){
//look for the primary user of this abo
$shopping_user = $user_abo->shopping_user->replicate();
}
return $shopping_user;
}
}

View file

@ -1,4 +1,5 @@
<?php
namespace App\Services\BusinessPlan;
use App\User;
@ -15,7 +16,7 @@ class ExportBot
public $user_list;
private $root_user;
public function __construct($init_from = 'member')
{
@ -23,26 +24,25 @@ class ExportBot
$this->init_from = $init_from;
}
public function initStructureUser(User $user, $order='list') //tree or list
public function initStructureUser(User $user, $order = 'list') //tree or list
{
$line = 0;
$this->order = $order;
$this->root_user = $user;
if($this->order === 'tree'){
$this->user_tree = $this->setUserValues($user, $line);
$this->user_tree->childs = $this->readChildUsers($this->user_tree, $line+1);
}
if($this->order === 'list'){
$this->user_list = $this->setUserValues($user, $line);
$this->readChildUsers($this->user_list, $line+1);
}
if ($this->order === 'tree') {
$this->user_tree = $this->setUserValues($user, $line);
$this->user_tree->childs = $this->readChildUsers($this->user_tree, $line + 1);
}
if ($this->order === 'list') {
$this->user_list = $this->setUserValues($user, $line);
$this->readChildUsers($this->user_list, $line + 1);
}
}
private function readChildUsers($parent_user, $line){
private function readChildUsers($parent_user, $line)
{
$childUsers = [];
$users = User::with('account')->select('users.*')
@ -55,24 +55,25 @@ class ExportBot
->where('users.active', "=", 1)
->get();
if($users){
foreach($users as $user){
if ($users) {
foreach ($users as $user) {
$user_values = $this->setUserValues($user, $line);
$childUsers[] = $user_values;
if($this->order === 'list'){
$childUsers[] = $user_values;
if ($this->order === 'list') {
$this->user_list->childs[] = $user_values;
$this->readChildUsers($user_values, $line+1);
}
$this->readChildUsers($user_values, $line + 1);
}
}
}
return $childUsers;
}
private function setUserValues(User $user, $line){
private function setUserValues(User $user, $line)
{
$sponsor_name = "";
if($user->m_sponsor && $user->user_sponsor->account){
$sponsor_name = $user->user_sponsor->account->m_first_name." ".$user->user_sponsor->account->m_last_name;
if ($user->m_sponsor && $user->user_sponsor->account) {
$sponsor_name = $user->user_sponsor->account->m_first_name . " " . $user->user_sponsor->account->m_last_name;
}
$obj = new stdClass();
$obj->line = $line;
@ -93,28 +94,28 @@ class ExportBot
$obj->zipcode = $user->account->zipcode;
$obj->city = $user->account->city;
$obj->country_id = $user->account->country_id ? $user->account->country->getLocated() : "";
$pre_phone = $user->account->pre_phone_id != "" ? $user->account->pre_phone->phone." " : "";
$pre_mobil = $user->account->pre_mobil_id != "" ? $user->account->pre_mobil->phone." " : "";
$obj->phone = $pre_phone.$user->account->phone;
$obj->mobil = $pre_mobil.$user->account->mobil;
$pre_phone = $user->account->pre_phone_id != "" ? $user->account->pre_phone->phone . " " : "";
$pre_mobil = $user->account->pre_mobil_id != "" ? $user->account->pre_mobil->phone . " " : "";
$obj->phone = $pre_phone . $user->account->phone;
$obj->mobil = $pre_mobil . $user->account->mobil;
$obj->birthday = $user->account->birthday;
$obj->partner_since = $user->active_date ? $user->getActiveDateFormat(false) : "";
if($this->order === 'tree'){
$obj->childs = $this->readChildUsers($obj, $line+1);
if ($this->order === 'tree') {
$obj->childs = $this->readChildUsers($obj, $line + 1);
}
if($this->order === 'list'){
if ($this->order === 'list') {
$obj->childs = [];
}
return $obj;
}
public function getUser(){
public function getUser()
{
return $this->root_user;
}
}

View file

@ -15,7 +15,8 @@ class SalesPointsVolumeHelper
line: nach reihenfolge sortiert,
*/
private static $business_users_line = [];
private static $totalcommission = [];
private static $totalpoints = [];
private static $cbot = null;
@ -36,7 +37,6 @@ class SalesPointsVolumeHelper
$deep = 0;
$ret = "";
foreach(self::$cbot->business_users as $business_user){
$ret .= self::addTableItemStructur($business_user, $deep);
}
return $ret;
@ -68,7 +68,7 @@ class SalesPointsVolumeHelper
<td><div class="no-line-break">'.$pp.'</div></td>
<td><span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>'.$item->first_name.' '.$item->last_name.'
</td>
<td><div class="no-line-break">'.formatNumber($points, 0).' &euro;</span></td>
<td><div class="no-line-break">'.formatNumber($points, 0).'</span></td>
<td>'.formatNumber($margin, 1).' %</td>
<td><div class="no-line-break">'.formatNumber($commission, 2).' &euro;</span></td>
<td><span class="small">'.$item->user_level_name.'</span></td>
@ -84,10 +84,16 @@ class SalesPointsVolumeHelper
self::addTableItemLine($business_user, $deep);
}
foreach(self::$business_users_line as $deep => $items){
self::$totalcommission[$deep] = 0;
self::$totalpoints[$deep] = 0;
foreach($items as $item){
$ret .= self::setTableHTMLItemLine($item, $deep);
}
if($deep > 0){
$ret .= self::addTableHTMLTotalItemLine($deep, 'line');
}
}
$ret .= self::addTableHTMLTotalItemLine($deep, 'end');
return $ret;
}
@ -100,6 +106,39 @@ class SalesPointsVolumeHelper
}
}
}
private static function addTableHTMLTotalItemLine($deep, $type){
$points = 0;
$commission = 0;
if($type == 'end'){
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.__('team.PP').'</div>';
$style = ' style="background-color:#d7d700;"';
$text = __('order.total');
foreach(self::$totalpoints as $key => $value){
$points += $value;
$commission += self::$totalcommission[$key];
}
}else{
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.$deep.'. '.__('team.PP').'</div>';
$style = 'style="background-color:#e5e4e4"';
$text = __('order.sum');
$points = self::$totalpoints[$deep];
$commission = self::$totalcommission[$deep];
}
$ret = '<tr '.$style.'>
<td><div class="no-line-break">'.$pp.'</div></td>
<td><b>'.$text.'</b></td>
<td><div class="no-line-break"><b>'.formatNumber($points, 0).'</b></span></td>
<td>&nbsp;</td>
<td><div class="no-line-break"><b>'.formatNumber($commission, 2).' &euro;</b></span></td>
<td>&nbsp;</td>
</tr>';
return $ret;
}
private static function setTableHTMLItemLine($item, $deep){
@ -111,6 +150,8 @@ class SalesPointsVolumeHelper
$pp = '<div class=" line-height-1 my-2 badge badge-outline-success text-dark font-weight-bolder">'.$deep.'. '.__('team.PP').'</div>';
$margin = self::$cbot->getKeybyLine($deep, 'margin');
$commission = $points / 100 * $margin;
self::$totalcommission[$deep] += $commission;
self::$totalpoints[$deep] += $points;
}
//
/*
@ -121,11 +162,12 @@ class SalesPointsVolumeHelper
<th>{{__('tables.commission')}} &euro;</th>
<th>{{ __('tables.level') }}</th>
*/
$ret = '<tr>
<td><div class="no-line-break">'.$pp.'</div></td>
<td><span class="mr-1 ion ion-ios-contact '.($item->active_account ? 'text-primary' : 'text-danger').'"></span>'.$item->first_name.' '.$item->last_name.'
</td>
<td><div class="no-line-break">'.formatNumber($points, 0).' &euro;</span></td>
<td><div class="no-line-break">'.formatNumber($points, 0).'</span></td>
<td>'.formatNumber($margin, 1).' %</td>
<td><div class="no-line-break">'.formatNumber($commission, 2).' &euro;</span></td>
<td><span class="small">'.$item->user_level_name.'</span></td>

View file

@ -135,8 +135,8 @@ class CustomerPriority
$matches = [];
$change = [];
$ret = 'update';
//email geändert
if(isset($data['billing_email']) && $shopping_user->billing_email != $data['billing_email']){
$found = ShoppingUser::where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
@ -205,8 +205,10 @@ class CustomerPriority
$shopping_user->member_id = $member_id;
$shopping_user->number = self::nextNumber();
$shopping_user->save();
$shopping_user->shopping_order->member_id = $member_id;
$shopping_user->shopping_order->save();
if($shopping_user->shopping_order){
$shopping_user->shopping_order->member_id = $member_id;
$shopping_user->shopping_order->save();
}
return true;
}
return false;

View file

@ -104,23 +104,22 @@ class HTMLHelper
return $ret;
}
public static function getAboIntervallWeeks($default = 1){
$values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
public static function getAboDeliveryOptions($default = 5){
$values = \App\Models\UserAbo::$aboDeliveryDays;
$ret = "";
foreach ($values as $value){
$attr = ($value == $default) ? 'selected="selected"' : '';
$str = self::getAboWeeksLang($value);
$str = self::getAboStrLang($value);
$ret .= '<option value="'.$value.'" '.$attr.'>'.$str.'</option>\n';
}
return $ret;
}
public static function getAboWeeksLang($num){
if($num == 1){
return __('order.every_week');
}
return __('order.every_weeks', ['num' => $num]);
public static function getAboStrLang($num){
return $num.'. '.__('abo.of_month');
}
public static function getAttributesWithoutParents($id = false, $sameId = false, $all = true){
$values = Attribute::where('parent_id', null)->get();
$ret = "";
@ -157,14 +156,14 @@ class HTMLHelper
if($ids == null){
$ids = array();
}
$values = Product::where('active', 1)->get();
$values = Product::all();
$ret = "";
if($all){
$ret .= '<option value="">'.__('none').'</option>\n';
}
foreach ($values as $value){
$attr = in_array($value->id, $ids) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.' ('.($value->active ? 'on' : 'off').')</option>\n';
}
return $ret;
}

View file

@ -0,0 +1,180 @@
<?php
namespace App\Services;
use App\Models\ShoppingUser;
use App\Models\ShoppingInstance;
use Yard;
class OrderPaymentService
{
public static function deleteInstance($identifier){
Yard::instance('shopping')->deleteStoredCart($identifier);
\App\Models\ShoppingInstance::where('identifier', $identifier)->delete();
//delete session
/* if(\Session::has('user_shop_payment') && \Session::get('user_shop_payment') === 6){
$user_shop_identifier = \Session::get('user_shop_identifier');
Yard::instance('shopping')->deleteStoredCart($identifier);
\App\Models\ShoppingInstance::where('identifier', $identifier)->delete();
}*/
}
public static function updateInstanceStatus($identifier, $status, $lower = true){
if(!ShoppingInstance::where('identifier', $identifier)->exists()){
return false;
}
if($lower){
ShoppingInstance::where('identifier', $identifier)->where('status', '<', $status)
->update(['status' => $status]);
}else{
ShoppingInstance::where('identifier', $identifier)
->update(['status' => $status]);
}
}
public static function getInstanceStatus($identifier){
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
if(!$shopping_instance){
return false;
}
return $shopping_instance->getStatus();
}
public static function getTypeBadge(ShoppingInstance $shoppingInstance){
$isFor = $shoppingInstance->shopping_data['is_for'] ?? '-';
if ($isFor === 'abo-ot-customer' ) {
return ' <span class="badge badge-pill badge-warning">'.__('abo.abo').'</span>';
}
if ($isFor === 'ot-customer' ) {
return ' <span class="badge badge-pill badge-secondary">'.__('order.order').'</span>';
}
return "";
}
public static function getStatusBadge(ShoppingInstance $shoppingInstance){
$status = $shoppingInstance->getStatus();
$badgeClasses = [
'link_sent' => 'success',
'link_openly' => 'warning',
'link_paid' => 'secondary',
'link_check' => 'warning',
'link_pending' => 'warning',
'link_appointed' => 'secondary',
'link_failed' => 'danger',
'link_canceled' => 'danger'
];
if (isset($badgeClasses[$status])) {
return sprintf(' <span class="badge badge-pill badge-%s">%s</span>',
$badgeClasses[$status],
__('payment.' . $status)
);
}
return '';
}
public static function getStatusAlert($status){
$badgeClasses = [
'link_sent' => 'success',
'link_openly' => 'success',
'link_check' => 'warning',
'link_pending' => 'warning',
'link_failed' => 'danger',
'link_canceled' => 'danger',
'link_appointed' => 'success',
'link_paid' => 'success',
];
if (isset($badgeClasses[$status])) {
return sprintf(' <div class="alert alert-%s">%s</div>',
$badgeClasses[$status],
__('payment.alert_' . $status)
);
}
return '';
}
public static function getCustomPayment($identifier){
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
if(!$shopping_instance){
abort(403, __('msg.shopping_instance_not_found'));
}
$shopping_data = $shopping_instance->shopping_data;
$shopping_user = $shopping_data['shopping_user_id'] ? ShoppingUser::find($shopping_data['shopping_user_id']) : null;
if(!$shopping_user){
abort(403, __('msg.shopping_user_not_found'));
}
$yard_shopping_items = self::getRestoredYardShoppingItems($shopping_instance);
$data = [
'shopping_instance' => $shopping_instance,
'shopping_user' => $shopping_user,
'yard_shopping_items' => $yard_shopping_items,
'identifier' => $identifier,
'is_abo' => $shopping_instance->shopping_data['is_abo'] ?? false,
'is_for' => $shopping_instance->shopping_data['is_for'] ?? false,
'backlink' => false,
];
return $data;
}
public static function getRestoredYardShoppingItems($shopping_instance){
Yard::instance('shopping')->destroy();
Yard::instance('shopping')->restore($shopping_instance->identifier, [], false);
Yard::instance('shopping')->putYardExtra('user_shop_payment', $shopping_instance->payment);
Yard::instance('shopping')->putYardExtra('shopping_data', $shopping_instance->shopping_data);
$is_for = isset($shopping_instance->shopping_data['is_for']) ? $shopping_instance->shopping_data['is_for'] : 'ot-member';
Yard::instance('shopping')->setUserPriceInfos($shopping_instance->shopping_data['user_price_infos']);
Yard::instance('shopping')->setShippingCountryWithPrice($shopping_instance->country_id, $is_for);
$rows = Yard::instance('shopping')->getContentByOrder();
$ret = [];
$ret['items'] = [];
$is_currency = Yard::instance('shopping')->isPriceCurrency();
$tax_free = Yard::instance('shopping')->getUserTaxFree();
foreach($rows as $row){
$product = \App\Models\Product::find($row->id);
$item = new \stdClass();
$item->image = $row->options->has('image') ? $row->options->image : null;
$item->price_net = (float) Yard::instance('shopping')->rowPriceNet($row, 3, '.', '');
$item->price_net_total = (float) Yard::instance('shopping')->rowSubtotalNet($row, 2, '.', '');
$item->price_currency = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('rowPriceNetCurrency', $row, 3)." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$item->price_currency_total = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('rowSubtotalCurrency', $row, 3)." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$item->price = $row->price;
$item->price_total = ($row->qty * $row->price);
$item->qty = $row->qty;
$item->name = $product->name;
$item->contents = $product->contents;
$item->numbers = $product->numbers;
$item->abo_type = AboHelper::getAboShowOn($product);
$item->number = $product->number;
$item->contents = $product->contents;
$ret['items'][] = $item;
}
$ret['tax_free'] = $tax_free;
$ret['total']['subtotal'] = Yard::instance('shopping')->subtotal();
$ret['total']['subtotal_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('subtotal')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['shippingCountryName'] = Yard::instance('shopping')->getShippingCountryName();
$ret['total']['shippingNet'] = Yard::instance('shopping')->shippingNet();
$ret['total']['shippingNet currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('shippingNet')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['subtotalWithShipping'] = Yard::instance('shopping')->subtotalWithShipping();
$ret['total']['subtotalWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('subtotalWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['taxWithShipping'] = Yard::instance('shopping')->taxWithShipping();
$ret['total']['taxWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('taxWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['totalWithShipping'] = Yard::instance('shopping')->totalWithShipping();
$ret['total']['totalWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('totalWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
return $ret;
}
}

View file

@ -6,6 +6,7 @@ use App\User;
use App\Models\UserLevel;
use App\Mail\MailCheckout;
use App\Services\UserUtil;
use App\Services\AboHelper;
use App\Models\ProductBuying;
use App\Models\ShoppingOrder;
use App\Models\UserCreditItem;
@ -91,6 +92,7 @@ class Payment
}
public static function getShoppingOrderBadge(ShoppingOrder $shopping_order){
if($shopping_order->mode === 'test'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
@ -100,6 +102,14 @@ class Payment
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_order->txaction).'">'.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
public static function getPaymentForBadge(ShoppingOrder $shopping_order){
$abo = '';
if($shopping_order->is_abo){
$abo = ' <span class="badge badge-pill badge-success">'.__('abo.abo').'</span>';
}
return '<span class="badge badge-pill badge-'.$shopping_order->getPaymentForColor().'">'.$shopping_order->getPaymentForType().'</span>'.$abo;
}
public static function getShoppingPaymentBadge(ShoppingPayment $shopping_payment){
if($shopping_payment->mode === 'test'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_payment->mode).' - '.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
@ -159,10 +169,10 @@ class Payment
$paid = Status der Zahlung, Payone = true, MIVITA Rechnung = false damit kann später die rechnung auf bezahlt gesetzt werden.
*/
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid, $shopping_payment = null){
$send_link = false;
$shopping_order->setUserHistoryValue(['status' => 8]);
Shop::userOrders();
ShoppingUserService::snycOrdersByShoppingOrder($shopping_order);
$shopping_order->paid = $paid;
$shopping_order->save();
@ -225,6 +235,7 @@ class Payment
}
}
if($shopping_order->homeparty){
$shopping_order->setUserHistoryValue(['status' => 9]);
$shopping_order->homeparty->completed = 1;
@ -235,12 +246,24 @@ class Payment
$shopping_order->setUserHistoryValue(['status' => 9]);
ShopApiOrderCart::finishOrder($shopping_order->shopping_collect_order);
}
//make Invoice and
$invoice_repo = new InvoiceRepository($shopping_order);
if(!$shopping_order->isInvoice()){
$invoice_repo->createAndSalesVolume();
//the Order is Pay, so we can set the Status in the Abo
if($shopping_order->is_abo){
if($shopping_payment){
Util::setInstanceStatusByPayment($shopping_payment, 10); //link_paid
$shopping_payment->identifier = null;
$shopping_payment->save();
}
AboHelper::setAboActive($shopping_order, 2);
}
//make Invoice is not exist and is live
if($shopping_order->mode === 'live'){
$invoice_repo = new InvoiceRepository($shopping_order);
if(!$shopping_order->isInvoice()){
$invoice_repo->createAndSalesVolume();
}
}
return $send_link;
}
@ -263,6 +286,7 @@ class Payment
if(!$shopping_order->shopping_user->is_like && $shopping_order->shopping_user->member){
$bcc[] = $shopping_order->shopping_user->member->email;
}
Mail::to($billing_email)->bcc($bcc)->locale($shopping_order->getLocale())->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $data['send_link'], $data['mode']));
$data['payment_error'] = isset($data['payment_error']) ? $data['payment_error'] : false;
Mail::to($billing_email)->bcc($bcc)->locale($shopping_order->getLocale())->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $data['send_link'], $data['mode'], $data['payment_error']));
}
}

View file

@ -17,7 +17,7 @@ class PaymentHelper
public function setProduct($product){
Yard::instance('shopping')->destroy();
Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, false, false, ['image' => "", 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission]);
Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, false, false, ['image' => "", 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
}
public function initELVPayment($user){

View file

@ -1,15 +1,17 @@
<?php
namespace App\Services;
use Yard;
use App\User;
use App\Models\Country;
use App\Models\Product;
use App\Models\Setting;
use App\Models\ShippingCountry;
use App\Models\ShoppingUser;
use App\Services\dbip\MyDBIP;
use App\Models\ShippingCountry;
use App\Services\IPinfo\IPinfo;
use App\User;
use Yard;
class Shop
{
@ -19,99 +21,73 @@ class Shop
public static $shipping_free;
public static $user_reverse_charge = false;
public static function userOrders() {
$shopping_users = ShoppingUser::whereHas('shopping_order', function($q) {
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed')->OrWhere('txaction', 'extern')->OrWhere('txaction', 'invoice_open')->OrWhere('txaction', 'invoice_paid');
})->where('orders', '=', NULL)->get();
foreach ($shopping_users as $shopping_user) {
if ($shopping_user->number) {
$orders = ShoppingUser::where('number', '=', $shopping_user->number)->max('orders');
$orders = $orders + 1;
} else {
$orders = ShoppingUser::where('billing_email', '=', $shopping_user->billing_email)->max('orders');
$orders = $orders + 1;
}
$shopping_user->orders = $orders;
$shopping_user->save();
}
public static function newUserOrder($number)
{
ShoppingUserService::snycOrdersByNumber($number);
}
public static function newUserOrder($number){
if($number > 0){
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
$orders = 1;
foreach ($shopping_users as $shopping_user) {
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' ||
$shopping_user->shopping_order->txaction === 'appointed' ||
$shopping_user->shopping_order->txaction === 'extern' ||
$shopping_user->shopping_order->txaction === 'extern_paid' )){
$shopping_user->orders = $orders++;
}else{
$shopping_user->orders = NULL;
}
$shopping_user->save();
}
}
}
public static function getShippingCountryCountryId($shipping_country_id){
public static function getShippingCountryCountryId($shipping_country_id)
{
$shippingCountry = ShippingCountry::find($shipping_country_id);
if($shippingCountry && $shippingCountry->country){
if ($shippingCountry && $shippingCountry->country) {
return $shippingCountry->country->id;
}
return 1; //default DE
}
public static function getCountryShippingCountryId($country_id){
public static function getCountryShippingCountryId($country_id)
{
$shippingCountry = ShippingCountry::whereCountryId($country_id)->first();
if($shippingCountry){
if ($shippingCountry) {
return $shippingCountry->id;
}
return ShippingCountry::all()->first()->id;
}
public static function getLangChange(){
public static function getLangChange()
{
$ret = [];
$countries = Country::whereActive(true)->whereSwitch(true)->get();
$first_country = null;
foreach($countries as $country){
$ShippingCountry = ShippingCountry::whereCountryId($country->id)->first();
if($ShippingCountry && $ShippingCountry->shipping && $ShippingCountry->shipping->active){
if(!$first_country){
foreach ($countries as $country) {
$ShippingCountry = ShippingCountry::whereCountryId($country->id)->first();
if ($ShippingCountry && $ShippingCountry->shipping && $ShippingCountry->shipping->active) {
if (!$first_country) {
$first_country = $country;
}
$ret[strtolower($country->code)] = $country;
}
}
$ret[strtolower($country->code)] = $country;
}
}
Shop::getUserShopLang($first_country);
return $ret;
}
public static function getUserShopLang($country = null){
if(\Session::has('user_shop_lang')){
if($user_shop_lang = \Session::get('user_shop_lang')){
return $user_shop_lang;
public static function getUserShopLang($country = null)
{
if (\Session::has('user_shop_lang')) {
if ($user_shop_lang = \Session::get('user_shop_lang')) {
return $user_shop_lang;
}
}
if($country){
if ($country) {
Shop::initUserShopLang($country);
return strtolower($country->code);
}
return false;
}
public static function initUserShopLang($country){
public static function initUserShopLang($country)
{
Yard::instance('shopping')->destroy();
\Session::put('user_shop_lang', strtolower($country->code));
//init Yard
self::initUserShopYard($country);
}
public static function initUserShopYard($country){
public static function initUserShopYard($country)
{
//Lieferadresse im Drittland?
self::$user_tax_free = $country->supply_country ? true : false;
$ShippingCountry = ShippingCountry::whereCountryId($country->id)->first();
@ -123,8 +99,9 @@ class Shop
Yard::instance('shopping')->setUserPriceInfos(Shop::getShopYardInfo());
}
public static function getShopYardInfo(){
public static function getShopYardInfo()
{
return [
'user_tax_free' => self::$user_tax_free,
'shipping_free' => self::$shipping_free,
@ -133,107 +110,68 @@ class Shop
'shipping_country_id' => self::$shipping_country->id,
];
}
public static function getYardShoppingItems(){
$rows = Yard::instance('shopping')->getContentByOrder();
$ret = [];
$ret['items'] = [];
$is_currency = Yard::instance('shopping')->isPriceCurrency();
$tax_free = Yard::instance('shopping')->getUserTaxFree();
foreach($rows as $row){
$product = \App\Models\Product::find($row->id);
$item = new \stdClass();
$item->image = $row->options->has('image') ? $row->options->image : null;
$item->price_net = (float) Yard::instance('shopping')->rowPriceNet($row, 3, '.', '');
$item->price_net_total = (float) Yard::instance('shopping')->rowSubtotalNet($row, 2, '.', '');
$item->price_currency = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('rowPriceNetCurrency', $row, 3)." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$item->price_currency_total = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('rowSubtotalCurrency', $row, 3)." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$item->price = $row->price;
$item->price_total = ($row->qty * $row->price);
$item->qty = $row->qty;
$item->name = $product->name;
$item->contents = $product->contents;
$item->numbers = $product->numbers;
$ret['items'][] = $item;
}
$ret['tax_free'] = $tax_free;
$ret['total']['subtotal'] = Yard::instance('shopping')->subtotal();
$ret['total']['subtotal_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('subtotal')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['shippingCountryName'] = Yard::instance('shopping')->getShippingCountryName();
$ret['total']['shippingNet'] = Yard::instance('shopping')->shippingNet();
$ret['total']['shippingNet currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('shippingNet')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['subtotalWithShipping'] = Yard::instance('shopping')->subtotalWithShipping();
$ret['total']['subtotalWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('subtotalWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['taxWithShipping'] = Yard::instance('shopping')->taxWithShipping();
$ret['total']['taxWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('taxWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
$ret['total']['totalWithShipping'] = Yard::instance('shopping')->totalWithShipping();
$ret['total']['totalWithShipping_currency'] = $is_currency ? "~".Yard::instance('shopping')->getCurrencyByKey('totalWithShipping')." ".Yard::instance('shopping')->getPriceCurrencyUnit() : null;
return $ret;
}
public static function checkShoppingUser($id, $user){
if($id === null){
public static function checkShoppingUser($id, $user)
{
if ($id === null) {
abort(403, 'Error: Keine User ID');
}
$shopping_user = ShoppingUser::findOrFail($id);
if($shopping_user->member_id !== $user->id){
if ($shopping_user->member_id !== $user->id) {
abort(403, 'Error: Falsche User ID');
}
$shopping_user = ShoppingUser::findOrFail($id);
if($shopping_user->is_like){
if ($shopping_user->is_like) {
abort(403, 'Error: Kunde in Prüfung');
}
return $shopping_user;
}
public static function checkShoppingCountry($for, $id=null){
public static function checkShoppingCountry($for, $id = null)
{
$country_id = null;
if($for === 'me' || $for === 'abo-me'){
if ($for === 'me' || $for === 'abo-me') {
$user = User::find(\Auth::user()->id);
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(strpos($for, 'ot') !== false && $id){
if (strpos($for, 'ot') !== false && $id) {
$shopping_user = ShoppingUser::findOrFail($id);
if($shopping_user->same_as_billing){
if ($shopping_user->same_as_billing) {
$country_id = $shopping_user->billing_country->id;
}else{
} else {
$country_id = $shopping_user->shipping_country->id;
}
}
if($country_id){
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
if($shipping_country->shipping && $shipping_country->shipping->active){
if ($country_id) {
if ($shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
if ($shipping_country->shipping && $shipping_country->shipping->active) {
return $shipping_country->id;
}
}
}
return false;
}
public static function getDeliveryCountry($for, $id=null){
public static function getDeliveryCountry($for, $id = null)
{
$country_id = null;
if($for === 'me' || $for === 'abo-me'){
if ($for === 'me' || $for === 'abo-me') {
$user = User::find(\Auth::user()->id);
if($user->account->same_as_billing){
return $user->account->country ? $user->account->country->getLocated() : '';
}else{
if ($user->account->same_as_billing) {
return $user->account->country ? $user->account->country->getLocated() : '';
} else {
return $user->account->shipping_country ? $user->account->shipping_country->getLocated() : '';
}
}
if(strpos($for, 'ot') !== false && $id){
if (strpos($for, 'ot') !== false && $id) {
$shopping_user = ShoppingUser::findOrFail($id);
if($shopping_user->same_as_billing){
if ($shopping_user->same_as_billing) {
return $shopping_user->billing_country ? $shopping_user->billing_country->getLocated() : '';
}else{
} else {
return $shopping_user->shipping_country ? $shopping_user->shipping_country->getLocated() : '';
}
}
@ -241,16 +179,17 @@ class Shop
}
public static function getShippingPriceByShippingCountryId($shipping_country_id, $shipping_weight){
public static function getShippingPriceByShippingCountryId($shipping_country_id, $shipping_weight)
{
$shippingCountry = ShippingCountry::find($shipping_country_id);
if(!$shippingCountry){
if (!$shippingCountry) {
abort(403, 'Fehler: Versandland nicht gefunden');
}
if(!isset($shippingCountry->shipping) && count($shippingCountry->shipping->shipping_prices) === 0){
if (!isset($shippingCountry->shipping) && count($shippingCountry->shipping->shipping_prices) === 0) {
abort(403, 'Fehler: Kein Preise für das Versandland angelegt');
}
$shipping_price = $shippingCountry->shipping->shipping_prices->first();
if(!$shipping_price){
if (!$shipping_price) {
abort(403, 'Fehler: Preis vom Versandland nicht gefunden');
}
@ -258,13 +197,13 @@ class Shop
abort(403, 'Fehler: Kein Versandgewicht');
}*/
if($shipping_weight == 0){
if ($shipping_weight == 0) {
$shipping_price->price = 0;
$shipping_price->price_comp = 0;
return $shipping_price;
}
if($shipping_weight > 0){
if ($shipping_weight > 0) {
/*
if($this->shipping_free && $this->total(2, '.', '') >= $this->shipping_free){
if($this->weightByFreeShipping() == 0){
@ -293,13 +232,13 @@ class Shop
//default
}*/
}
public static function shippingPriceByWeight($shipping_prices, $shipping_weight){
foreach ($shipping_prices as $price){
if($price->weight_from > 0 && $price->weight_to > 0){
if($shipping_weight >= $price->weight_from && $shipping_weight <= $price->weight_to){
public static function shippingPriceByWeight($shipping_prices, $shipping_weight)
{
foreach ($shipping_prices as $price) {
if ($price->weight_from > 0 && $price->weight_to > 0) {
if ($shipping_weight >= $price->weight_from && $shipping_weight <= $price->weight_to) {
return $price;
}
}
@ -307,25 +246,56 @@ class Shop
abort(403, 'Fehler: Preis nach Gewicht im Versandland nicht gefunden');
}
public static function isCompProducts($for){
/*
public static function isCompProducts($for)
{
/*
$for = me, ot-member, ot-customer, abo-ot-member, abo-ot-customer, abo-me
*/
if($for === 'me'){
if ($for === 'me') {
return (bool) Setting::getContentBySlug('is_comp_me_order');
}
if($for === 'abo-me'){
if ($for === 'abo-me') {
return (bool) Setting::getContentBySlug('is_comp_me_abo');
}
return false;
}
public static function getIPDatabaseInfo(){
public static function getCompProducts($for)
{
if (Shop::isCompProducts($for)) {
$show_on = '0';
switch ($for) {
case 'me':
$show_on = '2';
break;
case 'abo-me':
$show_on = '12';
break;
case 'ot-member':
$show_on = '3';
break;
case 'ot-customer':
$show_on = '3';
break;
case 'abo-ot-member':
$show_on = '13';
break;
case 'abo-ot-customer':
$show_on = '13';
break;
}
return Product::whereActive(true)->where('shipping_addon', true)->whereJsonContains('show_on', $show_on)->orderBy('pos', 'DESC')->get();
}
return [];
}
public static function getIPDatabaseInfo()
{
//first check the DBs for the IP
/* testing
/* testing
foreach(self::testIps() as $ip_address){
$country = MyDBIP::lookup($ip_address);
@ -355,12 +325,12 @@ class Shop
dd("done");
*/
/* live */
/* live */
$ip_address = \Request::ip();
// $ip_address = '86.189.47.78'; //testing
// $ip_address = '86.189.47.78'; //testing
$country = MyDBIP::lookup($ip_address);
if($country !== false){
if ($country !== false) {
return strtolower($country);
}
//not found search in IPinfo
@ -368,10 +338,10 @@ class Shop
$client = new IPinfo($access_token);
$details = $client->getDetails($ip_address);
if(isset($details->error) && $details->error !== null){
if (isset($details->error) && $details->error !== null) {
return 'error';
}
if(isset($details->country) && $details->country !== null){
if (isset($details->country) && $details->country !== null) {
MyDBIP::insert($ip_address, $details->country);
return strtolower($details->country);
}
@ -379,82 +349,83 @@ class Shop
}
private static function testIps(){
private static function testIps()
{
return [
'58.217.40.197'
,'207.117.144.54'
,'65.169.228.128'
,'6.84.3.236'
,'214.56.36.93'
,'9.43.145.245'
,'231.199.26.76'
,'86.189.47.78'
,'3.122.58.75'
,'251.133.143.149'
,'6.142.181.83'
,'2.55.191.86'
,'90.189.58.233'
,'57.3.139.111'
,'41.130.99.194'
,'1.59.123.14'
,'9.119.131.109'
,'54.240.231.9'
,'117.19.131.144'
,'221.217.39.211'
,'7.43.125.76'
,'224.86.233.79'
,'32.151.38.98'
,'4.134.40.92'
,'4.70.188.58'
,'24.7.152.228'
,'58.122.179.1'
,'5.123.9.44'
,'3.175.206.5'
,'8.142.119.47'
,'40.248.58.203'
,'7.84.254.187'
,'215.215.239.71'
,'124.40.66.196'
,'215.87.143.102'
,'143.39.97.13'
,'202.56.79.198'
,'143.60.125.142'
,'73.233.153.126'
,'121.144.28.245'
,'53.232.193.122'
,'104.222.102.209'
,'216.55.215.13'
,'84.106.145.239'
,'200.131.52.20'
,'132.252.158.0'
,'220.11.129.27'
,'8.153.0.186'
,'119.206.117.107'
,'222.93.42.133'
,'105.104.224.98'
,'252.156.181.78'
,'7.139.235.187'
,'111.140.127.91'
,'1.186.17.84'
,'85.59.39.221'
,'231.152.252.43'
,'125.214.216.123'
,'69.31.65.238'
,'126.12.105.55'
,'211.39.4.118'
,'73.102.88.79'
,'210.229.38.137'
,'5.3.230.214'
,'208.92.91.242'
,'4.105.177.199'
,'38.10.48.92'
,'133.33.44.13'
,'202.189.24.255'
,'5.101.244.234'
,'2.52.110.194'
,'1.130.73.146'
,'84.237.232.120'
,'25.163.83.194'
'58.217.40.197',
'207.117.144.54',
'65.169.228.128',
'6.84.3.236',
'214.56.36.93',
'9.43.145.245',
'231.199.26.76',
'86.189.47.78',
'3.122.58.75',
'251.133.143.149',
'6.142.181.83',
'2.55.191.86',
'90.189.58.233',
'57.3.139.111',
'41.130.99.194',
'1.59.123.14',
'9.119.131.109',
'54.240.231.9',
'117.19.131.144',
'221.217.39.211',
'7.43.125.76',
'224.86.233.79',
'32.151.38.98',
'4.134.40.92',
'4.70.188.58',
'24.7.152.228',
'58.122.179.1',
'5.123.9.44',
'3.175.206.5',
'8.142.119.47',
'40.248.58.203',
'7.84.254.187',
'215.215.239.71',
'124.40.66.196',
'215.87.143.102',
'143.39.97.13',
'202.56.79.198',
'143.60.125.142',
'73.233.153.126',
'121.144.28.245',
'53.232.193.122',
'104.222.102.209',
'216.55.215.13',
'84.106.145.239',
'200.131.52.20',
'132.252.158.0',
'220.11.129.27',
'8.153.0.186',
'119.206.117.107',
'222.93.42.133',
'105.104.224.98',
'252.156.181.78',
'7.139.235.187',
'111.140.127.91',
'1.186.17.84',
'85.59.39.221',
'231.152.252.43',
'125.214.216.123',
'69.31.65.238',
'126.12.105.55',
'211.39.4.118',
'73.102.88.79',
'210.229.38.137',
'5.3.230.214',
'208.92.91.242',
'4.105.177.199',
'38.10.48.92',
'133.33.44.13',
'202.189.24.255',
'5.101.244.234',
'2.52.110.194',
'1.130.73.146',
'84.237.232.120',
'25.163.83.194'
];
}
}
}

View file

@ -0,0 +1,198 @@
<?php
namespace App\Services;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;
use App\User;
use Yard;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\QueryException;
class ShoppingUserService
{
/**
* Gibt alle Bestellungen eines Mitglieds zurück
*
* @param ShoppingUser $shopping_user Das Mitglied, dessen Bestellungen zurückgegeben werden sollen
* @return Collection Die Bestellungen des Mitglieds
*/
public static function getAllOrdersByMember($shopping_user){
$users = ShoppingUser::where('billing_email', '=', $shopping_user->billing_email)->where('member_id', '=', $shopping_user->member_id)->get();
return $users->flatMap(function($user) {
return $user->shopping_orders;
})->sortByDesc('created_at');
}
public static function syncOrdersByEmail($user)
{
$maxAttempts = 3;
$attempt = 1;
while ($attempt <= $maxAttempts) {
try {
DB::beginTransaction();
$shopping_user = ShoppingUser::where('member_id', $user->id)
->first();
if (!$shopping_user) {
DB::commit();
return;
}
$shopping_users = ShoppingUser::where('billing_email', '=', $shopping_user->billing_email)
->whereHas('shopping_order', function($q) {
$q->where('txaction', 'paid')
->orWhere('txaction', 'appointed')
->orWhere('txaction', 'extern')
->orWhere('txaction', 'invoice_open')
->orWhere('txaction', 'invoice_paid');
})
->lockForUpdate()
->get();
$order_count = $shopping_users->count();
foreach($shopping_users as $user) {
$user->orders = $order_count;
$user->save();
}
DB::commit();
return; // Erfolgreicher Fall
} catch (QueryException $e) {
DB::rollBack();
// Wenn es ein Deadlock ist, versuchen wir es erneut
if ($e->getCode() == 40001 && $attempt < $maxAttempts) {
$sleepTime = pow(2, $attempt) * 100000; // Exponentielles Backoff in Mikrosekunden
usleep($sleepTime);
$attempt++;
continue;
}
throw $e; // Andere Fehler oder zu viele Versuche
}
}
}
/*public static function syncOrdersByEmail($user){
ShoppingUser::where('member_id', $user->id)
->whereNotNull('billing_email')
->where('billing_email', '!=', '')
->select('billing_email')
->groupBy('billing_email')
->get()
->each(function($shopping_user) {
self::snycOrdersByShoppingUser($shopping_user);
});
}*/
/**
* Synchronisiert die Bestellungen eines ShoppingOrders mit den Bestellungen des zugehörigen ShoppingUsers
*
* @param ShoppingOrder $shopping_order Der zu synchronisierende ShoppingOrder
*/
public static function snycOrdersByShoppingOrder(ShoppingOrder $shopping_order) {
$shopping_user = $shopping_order->shopping_user ? $shopping_order->shopping_user : null;
if($shopping_user){
self::snycOrdersByShoppingUser($shopping_user);
}
}
/**
* Synchronisiert die Bestellungen eines ShoppingUsers mit den Bestellungen des zugehörigen Benutzers
*
* @param ShoppingUser $shopping_user Der zu synchronisierende ShoppingUser
*/
public static function snycOrdersByShoppingUser(ShoppingUser $shopping_user) {
// Aktualisiere alle Benutzer mit einer einzigen Datenbankabfrage
ShoppingUser::where('billing_email', $shopping_user->billing_email)
->update([
'orders' => ShoppingUser::where('billing_email', $shopping_user->billing_email)
->whereHas('shopping_order', function($q) {
$q->whereIn('txaction', ['paid', 'appointed', 'extern', 'invoice_open', 'invoice_paid']);
})
->count()
]);
}
public static function snycOrdersByNumber($number){
if($number <= 0) {
return;
}
// Aktualisiere alle Benutzer mit einer einzigen Datenbankabfrage
ShoppingUser::where('number', '=', $number)
->update([
'orders' => ShoppingUser::where('number', '=', $number)
->whereHas('shopping_order', function($q) {
$q->whereIn('txaction', ['paid', 'appointed', 'extern', 'invoice_open', 'invoice_paid']);
})
->count()
]);
// Setze orders auf NULL für alle anderen
ShoppingUser::where('number', '=', $number)
->whereDoesntHave('shopping_order', function($q) {
$q->whereIn('txaction', ['paid', 'appointed', 'extern', 'extern_paid']);
})
->update(['orders' => null]);
}
/**
* Synchronisiert die Nummern aller ShoppingUser eines Benutzers anhand der E-Mails
*
* @param User $user Der Benutzer, dessen ShoppingUser synchronisiert werden sollen
*/
public static function syncNumbersByEmail($user) {
// Hole alle ShoppingUser mit E-Mail gruppiert
$emailGroups = ShoppingUser::where('member_id', $user->id)
->whereNotNull('billing_email')
->where('billing_email', '!=', '')
->get()
->groupBy('billing_email');
foreach($emailGroups as $email => $users) {
// Suche ob es bereits eine Nummer für diese E-Mail gibt
$existingNumber = ($users->whereNotNull('number')->first()) ? $users->whereNotNull('number')->first()->number : null;
if($existingNumber) {
// Wenn eine Nummer existiert, nutze diese für alle User mit der E-Mail
ShoppingUser::where('member_id', $user->id)
->where('billing_email', $email)
->whereNull('number')
->update(['number' => $existingNumber]);
} else {
// Wenn keine Nummer existiert, generiere eine neue
$maxNumber = ShoppingUser::max('number') ?: 1000;
$newNumber = $maxNumber + 1;
ShoppingUser::where('member_id', $user->id)
->where('billing_email', $email)
->update(['number' => $newNumber]);
}
}
}
/**
* Setzt alle Faker-E-Mails für einen Benutzer auf 1
*
* @param User $user Der Benutzer, dessen Faker-E-Mails gesetzt werden sollen
*/
public static function setFakerMail($user){
// Aktualisiere alle Faker-E-Mails für den Benutzer in einem einzigen Update
// Schneller da nur ein einzelner SQL Query ausgeführt wird
ShoppingUser::where('member_id', $user->id)
->where('faker_mail', '!=', 1)
->where('billing_email', 'LIKE', '%faker@mivita.care')
->update(['faker_mail' => 1]);
// Setze alle anderen auf NULL zurück
ShoppingUser::where('member_id', $user->id)
->where('billing_email', 'NOT LIKE', '%faker@mivita.care')
->update(['faker_mail' => null]);
}
}

View file

@ -43,9 +43,7 @@ class Slim {
if (empty($value)) {return null;}
// If magic quotes enabled
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Magic quotes were removed in PHP 5.4, no need to check in PHP 8.2
// The data is posted as a JSON String so to be used it needs to be deserialized first
$data = json_decode($value);

View file

@ -5,6 +5,7 @@ use Request;
use App\Services\Shop;
use App\Models\UserShop;
use App\Models\ShoppingUser;
use App\Services\ShoppingUserService;
use App\Http\Controllers\Api\KasController;
use App\Http\Controllers\Api\KasSLLController;
@ -55,7 +56,7 @@ class ShoppingOrders
}
if($data['action'] === 'next_run'){
Shop::userOrders();
ShoppingUserService::snycOrdersByShoppingUser($shopping_user);
\Session()->flash('alert-save', true);
}
return back();

View file

@ -85,7 +85,15 @@ class Util
return number_format($value, $dec, self::_decimal_separator(), self::_thousands_separator());
}
public static function cleanIntegerFromString($value) {
// Entferne alle nicht-numerischen Zeichen außer Minus
$cleanStr = preg_replace("/[^0-9-]/", "", $value);
// Konvertiere zu Integer und entferne führende Nullen
$number = (int)$cleanStr;
return $number;
}
public static function cleanNumberFormat($num = 0, $dec = 2, $fullzero = false){
if($fullzero && $num == 0){
@ -140,6 +148,35 @@ class Util
}
return false;
}
public static function getInstanceStatus(){
$identifier = self::getUserShopIdentifier();
if($identifier && \Session::has('user_shop_payment') && \Session::get('user_shop_payment') === 6){
return OrderPaymentService::getInstanceStatus($identifier);
}
return false;
}
public static function setInstanceStatus($status, $lower = true){
$identifier = self::getUserShopIdentifier();
if($identifier && \Session::has('user_shop_payment') && \Session::get('user_shop_payment') === 6){
OrderPaymentService::updateInstanceStatus($identifier, $status, $lower);
}
}
public static function setInstanceStatusByPayment($shopping_payment, $status, $lower = true){
if($shopping_payment->identifier){
OrderPaymentService::updateInstanceStatus($shopping_payment->identifier, $status, $lower);
}
}
public static function getShoppingInstance(){
if(\Session::has('shopping_instance')){
return \Session::get('shopping_instance');
}
return false;
}
public static function getUserHistory(){
$auth_user = self::getAuthUser();
$user_shop_identifier = self::getUserShopIdentifier();
@ -171,7 +208,7 @@ class Util
return 'test';
}
}
return 'live';
return config('app.mode');
}
public static function addRoute($p = []){
$b = [];