You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use App\Models\Game\Furniture\CatalogItem;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $item_name
|
||||
* @property int $category_id
|
||||
* @property int $item_id
|
||||
* @property int $currency_type
|
||||
* @property int $cost
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read WebsiteRareValueCategory|null $category
|
||||
* @property-read CatalogItem|null $item
|
||||
*/
|
||||
class WebsiteRareValue extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
#[\Override]
|
||||
protected function casts()
|
||||
{
|
||||
return [
|
||||
'currency_type' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteRareValueCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CatalogItem::class, 'item_id', 'item_ids');
|
||||
}
|
||||
|
||||
public function isLimitedEdition(): bool
|
||||
{
|
||||
if (is_null($this->item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->item->limited_stack > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $badge
|
||||
* @property int $priority
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Collection<int, WebsiteRareValue> $furniture
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory has($relation, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory whereId($id)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory withCount($relations)
|
||||
*/
|
||||
class WebsiteRareValueCategory extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
#[\Override]
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'priority' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function furniture(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteRareValue::class, 'category_id');
|
||||
}
|
||||
|
||||
public function getTotalValue(): int
|
||||
{
|
||||
return $this->furniture->sum(fn ($rare) => $rare->credit_value ?? 0);
|
||||
}
|
||||
|
||||
public function getAverageValue(): float
|
||||
{
|
||||
if ($this->furniture->isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return $this->furniture->avg(fn ($rare) => $rare->credit_value ?? 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user