mivita/app/Models/UserCreditItem.php
2022-07-29 18:18:05 +02:00

99 lines
1.8 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use App\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class UserCreditItem
*
* @property int $id
* @property int $user_id
* @property int|null $user_credit_id
* @property float|null $credit
* @property string|null $message
* @property int $status
* @property bool $paid
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property UserCredit|null $user_credit
* @property User $user
*
* @package App\Models
*/
class UserCreditItem extends Model
{
public static $statusTypes = [
1 => 'Provision Shop',
2 => 'Provision Team',
3 => 'Guthaben hinzugefügt',
4 => 'commission ...',
];
public static $statusColors = [
0 => 'warning',
1 => 'success',
2 => 'secondary',
3 => 'warning',
4 => 'info',
10 => 'danger',
];
protected $table = 'user_credit_items';
protected $casts = [
'user_id' => 'int',
'user_credit_id' => 'int',
'credit' => 'float',
'status' => 'int',
'paid' => 'bool'
];
protected $fillable = [
'user_id',
'user_credit_id',
'credit',
'message',
'status',
'paid'
];
public function user_credit()
{
return $this->belongsTo(UserCredit::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function deleteTime(){
$time = '+100 min';
if(Carbon::parse($this->created_at)->modify($time)->gt(Carbon::now())){
return Carbon::now()->diffInMinutes(Carbon::parse($this->created_at)->modify($time));
}
return false;
}
public function getStatusType(){
return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : "";
}
public function getStatusColor(){
return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : "default";
}
}