User Order all Margins / Checkout

This commit is contained in:
Kevin Adametz 2021-01-22 15:54:51 +01:00
parent a96d7d5c77
commit 224bf9e951
92 changed files with 3551 additions and 561 deletions

View file

@ -6,6 +6,7 @@
namespace App\Models;
use App\Services\Util;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@ -35,6 +36,8 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentMethod whereShowAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\PaymentMethod whereUpdatedAt($value)
* @mixin \Eloquent
* @property string|null $max_price
* @method static \Illuminate\Database\Eloquent\Builder|PaymentMethod whereMaxPrice($value)
*/
class PaymentMethod extends Model
{
@ -52,6 +55,7 @@ class PaymentMethod extends Model
'name',
'short',
'show_at',
'max_price',
'pos',
'default',
'active'
@ -59,11 +63,11 @@ class PaymentMethod extends Model
public static $showATs = [
0 => 'Nur Kunden Shop',
1 => 'Nur Berater Shop',
2 => 'Kunden + Berater Shop',
3 => 'Nur Reg/Mitgliedschaft Berater',
4 => 'Kunden + Berater Shop + Reg/Mitgliedschaft',
5 => 'Berater Shop + Reg/Mitgliedschaft',
1 => 'Nur Vertriebspartner Shop',
2 => 'Kunden + Vertriebspartner Shop',
3 => 'Nur Reg/Mitgliedschaft Vertriebspartner',
4 => 'Kunden + Vertriebspartner Shop + Reg/Mitgliedschaft',
5 => 'Vertriebspartner Shop + Reg/Mitgliedschaft',
9 => 'überall',
];
@ -74,4 +78,37 @@ class PaymentMethod extends Model
public static function getDefaultAsArray($short=false){
return PaymentMethod::where('active', true)->where('default', true)->pluck('id');
}
public function setMaxPriceAttribute($value)
{
$this->attributes['max_price'] = $value ? Util::reFormatNumber($value) : null;
}
public function getFormattedMaxPrice()
{
return isset($this->attributes['max_price']) ? Util::formatNumber($this->attributes['max_price']) : "";
}
/**
* @param $short //PP FNC VOR CC SB ...
* @param $user_payment_methods //PaymentMethod [] IDs
* @param $total //Full price
*/
public static function isShowPaymentMethod($short, $user_payment_methods, $total = 0){
$payment_method = PaymentMethod::whereShort($short)->first();
if($payment_method && $payment_method->active){
if(in_array($payment_method->id, $user_payment_methods)){
if($payment_method->max_price > 0){
if($payment_method->max_price >= $total){
return true;
}
}else{
return true;
}
}
}
return false;
}
}