252 lines
8 KiB
PHP
252 lines
8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use App\Services\Util;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class UserAbo
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $payone_userid
|
|
* @property string $clearingtype
|
|
* @property string|null $wallettype
|
|
* @property int $amount
|
|
* @property bool $active
|
|
* @property int $status
|
|
* @property int $abo_interval
|
|
* @property Carbon|null $abo_date
|
|
* @property Carbon|null $next_abo_date
|
|
* @property Carbon|null $cancel_date
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property string|null $deleted_at
|
|
* @property Carbon|null $user_deleted_at
|
|
* @property User $user
|
|
* @property Collection|UserAboOrder[] $user_abo_orders
|
|
* @package App\Models
|
|
* @property int|null $member_id
|
|
* @property int $shopping_user_id
|
|
* @property string|null $email
|
|
* @property string|null $is_for
|
|
* @property array|null $carddata
|
|
* @property \Illuminate\Support\Carbon|null $start_date
|
|
* @property \Illuminate\Support\Carbon|null $last_date
|
|
* @property \Illuminate\Support\Carbon|null $next_date
|
|
* @property-read User|null $member
|
|
* @property-read \App\Models\ShoppingUser $shopping_user
|
|
* @property-read Collection<int, \App\Models\UserAboItem> $user_abo_items
|
|
* @property-read int|null $user_abo_items_count
|
|
* @property-read int|null $user_abo_orders_count
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo onlyTrashed()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereAboInterval($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereAmount($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereCancelDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereCarddata($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereClearingtype($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereEmail($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereIsFor($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereLastDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereMemberId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereNextDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo wherePayoneUserid($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereShoppingUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereStartDate($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereStatus($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereUserDeletedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereUserId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo whereWallettype($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo withTrashed()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserAbo withoutTrashed()
|
|
* @mixin \Eloquent
|
|
*/
|
|
class UserAbo extends Model
|
|
{
|
|
use SoftDeletes;
|
|
protected $table = 'user_abos';
|
|
|
|
protected $casts = [
|
|
'user_id' => 'int',
|
|
'member_id' => 'int',
|
|
'shopping_user_id' => 'int',
|
|
'payone_userid' => 'int',
|
|
'active' => 'bool',
|
|
'status' => 'int',
|
|
'abo_interval' => 'int',
|
|
'amount' => 'int',
|
|
'start_date' => 'datetime',
|
|
'last_date' => 'datetime',
|
|
'next_date' => 'datetime',
|
|
'cancel_date' => 'datetime',
|
|
'user_deleted_at' => 'datetime',
|
|
'carddata' => 'array'
|
|
|
|
];
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'member_id',
|
|
'shopping_user_id',
|
|
'is_for',
|
|
'email',
|
|
'payone_userid',
|
|
'clearingtype',
|
|
'wallettype',
|
|
'carddata',
|
|
'amount',
|
|
'active',
|
|
'status',
|
|
'abo_interval',
|
|
'start_date',
|
|
'last_date',
|
|
'next_date',
|
|
'cancel_date',
|
|
'user_deleted_at'
|
|
];
|
|
|
|
public static $aboDeliveryDays = [5, 10, 20, 25];
|
|
|
|
public static $statusTypes = [
|
|
0 => 'abo_new',
|
|
1 => 'abo_new',
|
|
2 => 'abo_okay',
|
|
3 => 'abo_hold',
|
|
4 => 'abo_cancel',
|
|
5 => 'abo_finish',
|
|
6 => 'abo_inactive',
|
|
7 => 'abo_grace'
|
|
];
|
|
|
|
public static $statusColors = [
|
|
0 => 'success',
|
|
1 => 'success',
|
|
2 => 'secondary',
|
|
3 => 'warning',
|
|
4 => 'danger',
|
|
5 => 'info',
|
|
6 => 'warning',
|
|
7 => 'danger'
|
|
];
|
|
|
|
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function member()
|
|
{
|
|
return $this->belongsTo(User::class, 'member_id');
|
|
}
|
|
|
|
public function shopping_user()
|
|
{
|
|
return $this->belongsTo('App\Models\ShoppingUser', 'shopping_user_id');
|
|
}
|
|
|
|
public function user_abo_orders()
|
|
{
|
|
return $this->hasMany(UserAboOrder::class);
|
|
}
|
|
|
|
public function user_abo_items()
|
|
{
|
|
return $this->hasMany(UserAboItem::class);
|
|
}
|
|
|
|
public function getCountOrders()
|
|
{
|
|
//sind bezahlte Bestellungen
|
|
return $this->user_abo_orders->where('status', '>=', 2)->count();
|
|
}
|
|
|
|
public function getCountPaidOrders()
|
|
{
|
|
//sind bezahlte Bestellungen
|
|
return $this->user_abo_orders->where('status', '>=', 2)->where('paid', true)->count();
|
|
}
|
|
|
|
public function setStartDateAttribute($value)
|
|
{
|
|
$this->attributes['start_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
|
}
|
|
public function getStartDateAttribute()
|
|
{
|
|
return $this->attributes['start_date'] ? Carbon::parse($this->attributes['start_date'])->format(\Util::formatDateDB()) : '';
|
|
}
|
|
|
|
public function setLastDateAttribute($value)
|
|
{
|
|
$this->attributes['last_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
|
}
|
|
public function getLastDateAttribute()
|
|
{
|
|
return $this->attributes['last_date'] ? Carbon::parse($this->attributes['last_date'])->format(\Util::formatDateDB()) : '';
|
|
}
|
|
|
|
public function setNextDateAttribute($value)
|
|
{
|
|
$this->attributes['next_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
|
}
|
|
public function getNextDateAttribute()
|
|
{
|
|
return $this->attributes['next_date'] ? Carbon::parse($this->attributes['next_date'])->format(\Util::formatDateDB()) : '';
|
|
}
|
|
|
|
public function setCancelDateAttribute($value)
|
|
{
|
|
$this->attributes['cancel_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
|
}
|
|
public function getCancelDateAttribute()
|
|
{
|
|
return $this->attributes['cancel_date'] ? Carbon::parse($this->attributes['cancel_date'])->format(\Util::formatDateDB()) : '';
|
|
}
|
|
|
|
public function getFormattedAmount()
|
|
{
|
|
return isset($this->attributes['amount']) ? Util::formatNumber($this->attributes['amount'] / 100) : "";
|
|
}
|
|
public function getIsForFormated()
|
|
{
|
|
return $this->attributes['is_for'] === 'me' ? '<span class="badge badge-outline-warning-dark">' . __('tables.adviser') . '</span>' : '<span class="badge badge-outline-info">' . __('tables.customer') . '</span>';
|
|
}
|
|
|
|
public function getStatusFormated()
|
|
{
|
|
return '<span class="badge badge-pill badge-' . $this->getStatusColor() . '">' . $this->getStatusType() . '</span>';
|
|
}
|
|
|
|
public function getStatusType()
|
|
{
|
|
return isset(self::$statusTypes[$this->status]) ? __('abo.' . self::$statusTypes[$this->status]) : "";
|
|
}
|
|
|
|
public function getStatusColor()
|
|
{
|
|
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
|
|
}
|
|
|
|
public function getPaymentType()
|
|
{
|
|
return $this->clearingtype === 'wlt' ? __('payment.paypal') : __('payment.credit_card');
|
|
}
|
|
}
|