48 lines
934 B
PHP
48 lines
934 B
PHP
<?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();
|
|
}
|
|
}
|