feat: add note module and route fixes
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\note\model;
|
||||
|
||||
use think\Model;
|
||||
use think\db\Query;
|
||||
|
||||
/**
|
||||
* note 模块笔记主表模型
|
||||
*/
|
||||
class NoteItem extends Model
|
||||
{
|
||||
protected $connection = 'dbnote';
|
||||
|
||||
protected $name = 'note_item';
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
/**
|
||||
* 创建当前用户的基础查询
|
||||
*
|
||||
* @param int $noteUserId
|
||||
* @return Query
|
||||
*/
|
||||
public static function buildUserQuery(int $noteUserId): Query
|
||||
{
|
||||
return self::where('note_user_id', $noteUserId)
|
||||
->where('deleted_at', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户拥有的笔记
|
||||
*
|
||||
* @param int $noteUserId
|
||||
* @param int $id
|
||||
* @return self|null
|
||||
*/
|
||||
public static function findOwnedNote(int $noteUserId, int $id): ?self
|
||||
{
|
||||
return self::buildUserQuery($noteUserId)
|
||||
->where('id', $id)
|
||||
->find();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user