#10 Promotion Modul, Kommentar 2

This commit is contained in:
Kevin Adametz 2021-11-09 18:40:18 +01:00
parent f0da981737
commit c9e1545693
128 changed files with 8194 additions and 637 deletions

View file

@ -45,6 +45,21 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUsedBudgetTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserDeletedAt($value)
* @mixin \Eloquent
* @property int $user_id
* @property string|null $user_address
* @property-read Collection|\App\Models\PromotionUserProduct[] $promotion_user_products
* @property-read int|null $promotion_user_products_count
* @property-read Collection|\App\Models\PromotionUserProduct[] $promotion_user_products_active
* @property-read int|null $promotion_user_products_active_count
* @property-read \App\User $user
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserId($value)
* @property string|null $about_you
* @property string|null $internal_name
* @property string|null $internal_description
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereAboutYou($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereInternalDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereInternalName($value)
*/
class PromotionUser extends Model
{
@ -68,8 +83,12 @@ class PromotionUser extends Model
'user_id',
'name',
'description',
'about_you',
'internal_name',
'internal_description',
'url',
'pick_up',
'user_address',
'used_budget_total',
'sell_items_total',
'active',
@ -97,7 +116,6 @@ class PromotionUser extends Model
{
return $this->hasMany(PromotionUserProduct::class);
}
public function promotion_user_products_active()
{
return $this->hasMany(PromotionUserProduct::class)->where('active', 1);
@ -106,7 +124,7 @@ class PromotionUser extends Model
public function getUrlPreview()
{
return $this->url ? config('app.promo_url').$this->url : "";
return $this->url ? config('app.promo_url')."/".$this->url : "";
}
public function canDelete(){
@ -164,7 +182,7 @@ class PromotionUser extends Model
public function checkPaymentCredit()
{
if($this->promotion_user_products_active->count() > 0 && $this->getCountOpenItems() > 0){
$payment_credit = \Auth::user()->payment_credit;
$payment_credit = $this->user->payment_credit;
if($payment_credit <= 0){
return "empty";
}
@ -179,9 +197,23 @@ class PromotionUser extends Model
}
return false;
}
public static function preCheckPaymentCredit($values){
public function checkOutOfStock(){
if(!$this->active){
return true;
}
if($this->getCountOpenItems() < 1){
return true;
}
if($this->checkPaymentCredit() !== 'okay'){
return true;
}
return false;
}
public static function preCheckPaymentCredit($values, $user){
if($values['count_items'] > 0 && $values['sum_items'] > 0){
$payment_credit = \Auth::user()->payment_credit;
$payment_credit = $user->payment_credit;
if($payment_credit <= 0){
return "empty";
}