Komp / Max Produkt,

This commit is contained in:
Kevin Adametz 2021-06-18 15:01:01 +02:00
parent a4c76d06fa
commit 78f43169c8
19 changed files with 347 additions and 51 deletions

View file

@ -141,7 +141,10 @@ class Product extends Model
'wp_number' => 'int',
'single_commission' => 'bool',
'amount_commission' => 'bool',
'active' => 'bool'
'active' => 'bool',
'shipping_addon' => 'bool',
'max_buy' => 'bool',
'max_buy_num' => 'int'
];
use Sluggable;
@ -178,7 +181,10 @@ class Product extends Model
'partner_commission',
'identifier',
'action',
'upgrade_to_id'
'upgrade_to_id',
'shipping_addon',
'max_buy',
'max_buy_num'
];
public $identifiers_types = [
@ -249,6 +255,10 @@ class Product extends Model
return $this->hasMany(CountryPrice::class, 'product_id');
}
public function product_buys()
{
return $this->hasMany(ProductBuy::class, 'product_id');
}
public function p_ingredients()
{

72
app/Models/ProductBuy.php Normal file
View file

@ -0,0 +1,72 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class ProductBuy
*
* @property int $id
* @property int $auth_user_id
* @property int $product_id
* @property int $num
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Product $product
*
* @package App\Models
*/
class ProductBuy extends Model
{
protected $table = 'product_buys';
protected $casts = [
'auth_user_id' => 'int',
'product_id' => 'int',
'num' => 'int'
];
protected $fillable = [
'auth_user_id',
'product_id',
'num'
];
public function product()
{
return $this->belongsTo(Product::class);
}
public function user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public function auth_user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public static function getNotShowProductIDs($user_id){
$ret = [];
$ProductBuys = ProductBuy::where('auth_user_id', $user_id)->get();
if($ProductBuys){
foreach($ProductBuys as $ProductBuy){
if($ProductBuy->product){
if($ProductBuy->product->max_buy && $ProductBuy->num >= $ProductBuy->product->max_buy_num){
$ret[] = $ProductBuy->product->id;
}
}
}
}
return $ret;
}
}

View file

@ -77,6 +77,10 @@ class Setting extends Model
'object' => 'Object',
'full_text' => 'Full Text',
'text' => 'Text',
'int' => 'Zahl',
'bool' => 'Bool',
];
public function sluggable()
@ -103,6 +107,9 @@ class Setting extends Model
case 'int':
return $content->int;
break;
case 'bool':
return $content->int === 1 ? true : false;
break;
}
}
return false;
@ -120,17 +127,20 @@ class Setting extends Model
$content->type = $type;
switch ($content->type){
case 'object':
$content->object = $value;
$content->object = $value ? $value : null;;
break;
case 'full_text':
$content->full_text = $value;
$content->full_text = $value ? $value : null;;
break;
case 'text':
$content->text = $value;
$content->text = $value ? $value : null;;
break;
case 'int':
$content->int = (int) $value;
break;
case 'bool':
$content->int = $value ? 1 : 0;
break;
}
$content->save();