init
This commit is contained in:
45
web10/app/Models/Article.php
Normal file
45
web10/app/Models/Article.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'slug',
|
||||
'summary',
|
||||
'content_md',
|
||||
'cover',
|
||||
'author',
|
||||
'view_count',
|
||||
'status',
|
||||
'published_at',
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany(Tag::class)->withTimestamps();
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'target_id')
|
||||
->where('target_type', 'article');
|
||||
}
|
||||
|
||||
public function scopePublished($query)
|
||||
{
|
||||
return $query->where('status', 'published');
|
||||
}
|
||||
}
|
||||
37
web10/app/Models/Category.php
Normal file
37
web10/app/Models/Category.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'icon',
|
||||
'sort',
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
];
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
}
|
||||
41
web10/app/Models/Comment.php
Normal file
41
web10/app/Models/Comment.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'target_type',
|
||||
'target_id',
|
||||
'nickname',
|
||||
'email',
|
||||
'content',
|
||||
'status',
|
||||
'like_count',
|
||||
'reply_content',
|
||||
'replied_at',
|
||||
'ip',
|
||||
'user_agent',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'replied_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'target_id')
|
||||
->where('target_type', 'product');
|
||||
}
|
||||
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsTo(Article::class, 'target_id')
|
||||
->where('target_type', 'article');
|
||||
}
|
||||
}
|
||||
17
web10/app/Models/ContactMessage.php
Normal file
17
web10/app/Models/ContactMessage.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactMessage extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'content',
|
||||
];
|
||||
}
|
||||
23
web10/app/Models/ContentViewLog.php
Normal file
23
web10/app/Models/ContentViewLog.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContentViewLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'content_type',
|
||||
'content_id',
|
||||
'ip',
|
||||
'user_agent_hash',
|
||||
'viewed_on',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'viewed_on' => 'date',
|
||||
];
|
||||
}
|
||||
106
web10/app/Models/Product.php
Normal file
106
web10/app/Models/Product.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'category_id',
|
||||
'name',
|
||||
'slug',
|
||||
'summary',
|
||||
'description',
|
||||
'cover',
|
||||
'screenshots',
|
||||
'video_url',
|
||||
'website_url',
|
||||
'pricing_type',
|
||||
'platforms',
|
||||
'is_featured',
|
||||
'featured_until',
|
||||
'is_sponsored',
|
||||
'sponsor_until',
|
||||
'sort',
|
||||
'hot_score',
|
||||
'hot_override',
|
||||
'view_count',
|
||||
'click_count',
|
||||
'status',
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'screenshots' => 'array',
|
||||
'platforms' => 'array',
|
||||
'is_featured' => 'boolean',
|
||||
'featured_until' => 'datetime',
|
||||
'is_sponsored' => 'boolean',
|
||||
'sponsor_until' => 'datetime',
|
||||
];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany(Tag::class)->withPivot('sort')->withTimestamps();
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'target_id')
|
||||
->where('target_type', 'product');
|
||||
}
|
||||
|
||||
public function scopePublished($query)
|
||||
{
|
||||
return $query->where('status', 'published');
|
||||
}
|
||||
|
||||
public function scopeFeatured($query)
|
||||
{
|
||||
return $query->where('is_featured', true)
|
||||
->where(function ($inner) {
|
||||
$inner->whereNull('featured_until')
|
||||
->orWhere('featured_until', '>=', now());
|
||||
});
|
||||
}
|
||||
|
||||
public function getEffectiveHotScoreAttribute(): int
|
||||
{
|
||||
return $this->hot_override ?? $this->hot_score;
|
||||
}
|
||||
|
||||
public function refreshHotScore(): void
|
||||
{
|
||||
$this->hot_score = $this->calculateHotScore();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
private function calculateHotScore(): int
|
||||
{
|
||||
if ($this->hot_override !== null) {
|
||||
return (int) $this->hot_override;
|
||||
}
|
||||
|
||||
$weightView = (int) SiteSetting::value('hot_weight_view', 1);
|
||||
$weightClick = (int) SiteSetting::value('hot_weight_click', 3);
|
||||
|
||||
return (int) $this->view_count * $weightView + (int) $this->click_count * $weightClick;
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function (Product $product): void {
|
||||
$product->hot_score = $product->calculateHotScore();
|
||||
});
|
||||
}
|
||||
}
|
||||
15
web10/app/Models/SensitiveWord.php
Normal file
15
web10/app/Models/SensitiveWord.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SensitiveWord extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'word',
|
||||
];
|
||||
}
|
||||
32
web10/app/Models/SiteSetting.php
Normal file
32
web10/app/Models/SiteSetting.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SiteSetting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'key',
|
||||
'value',
|
||||
];
|
||||
|
||||
public static function value(string $key, $default = null)
|
||||
{
|
||||
return cache()->remember("site_setting_{$key}", 600, function () use ($key, $default) {
|
||||
$setting = static::where('key', $key)->first();
|
||||
|
||||
return $setting?->value ?? $default;
|
||||
});
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(function (SiteSetting $setting): void {
|
||||
cache()->forget("site_setting_{$setting->key}");
|
||||
});
|
||||
}
|
||||
}
|
||||
30
web10/app/Models/Tag.php
Normal file
30
web10/app/Models/Tag.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'hot_score',
|
||||
'sort',
|
||||
'seo_title',
|
||||
'seo_description',
|
||||
];
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class)->withPivot('sort')->withTimestamps();
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->belongsToMany(Article::class)->withTimestamps();
|
||||
}
|
||||
}
|
||||
45
web10/app/Models/User.php
Normal file
45
web10/app/Models/User.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user