feat: 新增导航相关接口
This commit is contained in:
46
app/admin/model/v1/SysNavigationItemModel.php
Normal file
46
app/admin/model/v1/SysNavigationItemModel.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 导航数据模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysNavigationItemModel extends Model
|
||||
{
|
||||
// 关联导航
|
||||
public function navigation()
|
||||
{
|
||||
return $this->belongsTo(SysNavigationModel::class, 'nav_id', 'id');
|
||||
}
|
||||
|
||||
// 名称搜索
|
||||
public function searchNameAttr($query, $value, $data)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
$query->where('name', 'like', "%{$value}%");
|
||||
}
|
||||
|
||||
// 新增时间搜索
|
||||
public function searchCreatedAtAttr($query, $value, $data)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
if (is_array($value)) {
|
||||
if (count($value) > 1) {
|
||||
$query->whereBetweenTime('created_at', $value[0], $value[1]);
|
||||
} else {
|
||||
$query->whereTime('created_at', '>=', $value[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导航查询
|
||||
public function scopeNavId($query, $value)
|
||||
{
|
||||
if (empty($value)) return;
|
||||
$query->where('nav_id', '=', $value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user