update cms
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\ArticlesEvent;
|
||||
use catchAdmin\cms\model\search\ArticlesSearch;
|
||||
|
||||
/**
|
||||
* Class Articles
|
||||
@@ -47,7 +48,7 @@ use catchAdmin\cms\model\events\ArticlesEvent;
|
||||
*/
|
||||
class Articles extends BaseModel
|
||||
{
|
||||
use ArticlesEvent;
|
||||
use ArticlesEvent, ArticlesSearch;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_articles';
|
||||
|
@@ -13,8 +13,11 @@
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\search\CommentsSearch;
|
||||
|
||||
class Comments extends BaseModel
|
||||
{
|
||||
use CommentsSearch;
|
||||
// 表名
|
||||
public $name = 'cms_comments';
|
||||
// 数据库字段映射
|
||||
@@ -43,4 +46,14 @@ class Comments extends BaseModel
|
||||
// 软删除
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
public function getList()
|
||||
{
|
||||
return $this->catchJoin(Articles::class, 'id', 'article_id', ['title'])
|
||||
->catchJoin(Users::class, 'id', 'user_id', ['username'])
|
||||
->field($this->aliasField('*'))
|
||||
->catchSearch()
|
||||
->catchOrder()
|
||||
->paginate();
|
||||
}
|
||||
}
|
@@ -13,8 +13,12 @@
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\search\UsersSearch;
|
||||
|
||||
class Users extends BaseModel
|
||||
{
|
||||
use UsersSearch;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_users';
|
||||
// 数据库字段映射
|
||||
|
15
catch/cms/model/search/ArticlesSearch.php
Normal file
15
catch/cms/model/search/ArticlesSearch.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait ArticlesSearch
|
||||
{
|
||||
public function searchCategoryAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('name', 'cms_category'), $value);
|
||||
}
|
||||
|
||||
public function searchTitleAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('title'), $value);
|
||||
}
|
||||
}
|
44
catch/cms/model/search/CommentsSearch.php
Normal file
44
catch/cms/model/search/CommentsSearch.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait CommentsSearch
|
||||
{
|
||||
/**
|
||||
* 文章 title 搜索
|
||||
*
|
||||
* @time 2021年05月26日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchTitleAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('title', 'cms_articles'), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论人昵称
|
||||
*
|
||||
* @time 2021年05月26日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchUsernameAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('username', 'cms_users'), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态搜索
|
||||
*
|
||||
* @time 2021年05月26日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchStatusAttr($query, $value)
|
||||
{
|
||||
return $query->where($this->aliasField('status'), $value);
|
||||
}
|
||||
}
|
25
catch/cms/model/search/UsersSearch.php
Normal file
25
catch/cms/model/search/UsersSearch.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\search;
|
||||
|
||||
trait UsersSearch
|
||||
{
|
||||
public function searchUsernameAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('name'), $value);
|
||||
}
|
||||
|
||||
public function searchEmailAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('email'), $value);
|
||||
}
|
||||
|
||||
public function searchMobileAttr($query, $value)
|
||||
{
|
||||
return $query->whereLike($this->aliasField('mobile'), $value);
|
||||
}
|
||||
|
||||
public function searchStatusAttr($query, $value)
|
||||
{
|
||||
return $query->where($this->aliasField('status'), $value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user