chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\blog\model;
use ywxapp\model\BaseModel;
use ywxapp\model\MemberUser;
class BlogLike extends BaseModel
{
// 设置数据表名
protected $name = 'blog_like';
// 设置主键
protected $pk = 'id';
// 自动写入时间戳(int 型 Unix 时间戳,匹配 create_at int 列)
protected $autoWriteTimestamp = 'int';
protected $createTime = 'create_at';
protected $updateTime = false;
// 定义允许写入的字段
protected $allowField = [
'uid', 'aid'
];
// 设置字段类型
protected $type = [
'id' => 'int',
'uid' => 'int',
'aid' => 'int',
'create_at' => 'int'
];
// 定义关联 - 用户(博客用户即主系统会员,统一使用 wxapp_user,主键 uid
public function user()
{
return $this->belongsTo(MemberUser::class, 'uid', 'uid');
}
// 定义关联 - 文章
public function article()
{
return $this->belongsTo(BlogArticle::class, 'aid');
}
// 检查用户是否已点赞
public static function hasLiked($userId, $articleId)
{
return self::where('uid', $userId)
->where('aid', $articleId)
->count() > 0;
}
// 切换点赞状态
public static function toggle($userId, $articleId)
{
$like = self::where('uid', $userId)
->where('aid', $articleId)
->find();
if ($like) {
$like->delete();
return false; // 取消点赞
} else {
$like = new self();
$like->uid = $userId;
$like->aid = $articleId;
$like->save();
return true; // 添加点赞
}
}
}