其余文件
This commit is contained in:
162
app/admin/logic/content/ArticleCategoryLogic.php
Normal file
162
app/admin/logic/content/ArticleCategoryLogic.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\logic\content;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\content\ArticleCategory;
|
||||
use Exception;
|
||||
|
||||
class ArticleCategoryLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* 获取文章分类
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
$model = new ArticleCategory();
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->order('id', 'desc')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
$item['is_show'] = $item['is_show'] ? '启用' : '停用';
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 获取文章分类
|
||||
* @Author: 张无忌
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategory()
|
||||
{
|
||||
try {
|
||||
$model = new ArticleCategory();
|
||||
return $model->field(true)
|
||||
->where(['del'=>0, 'is_show'=>1])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章分类详细
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new ArticleCategory();
|
||||
return $model->field(true)->findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文章分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
|
||||
ArticleCategory::create([
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
|
||||
ArticleCategory::update([
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show']
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章分类
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
|
||||
ArticleCategory::update([
|
||||
'del' => 1
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 隐藏
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function hide($id)
|
||||
{
|
||||
try {
|
||||
$model = new ArticleCategory();
|
||||
$category = $model->findOrEmpty($id)->toArray();
|
||||
|
||||
ArticleCategory::update([
|
||||
'is_show' => !$category['is_show'],
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
172
app/admin/logic/content/ArticleLogic.php
Normal file
172
app/admin/logic/content/ArticleLogic.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\logic\content;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\content\Article;
|
||||
use Exception;
|
||||
|
||||
class ArticleLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* 获取文章分类
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
if (!empty($get['title']) and $get['title'])
|
||||
$where[] = ['title', 'like', '%'.$get['title'].'%'];
|
||||
|
||||
if (!empty($get['cid']) and is_numeric($get['cid']))
|
||||
$where[] = ['cid', '=', $get['cid']];
|
||||
|
||||
if (isset($get['is_notice']) and is_numeric($get['is_notice']))
|
||||
$where[] = ['is_notice', '=', $get['is_notice']];
|
||||
|
||||
$model = new Article();
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->with(['category'])
|
||||
->order('sort', 'asc')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
$item['category'] = $item['category']['name'] ?? '未知';
|
||||
$item['is_notice'] = $item['is_notice'] ? '是' : '否';
|
||||
$item['is_show'] = $item['is_show'] ? '显示' : '隐藏';
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 文章详细
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new Article();
|
||||
return $model->field(true)->findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 添加文章
|
||||
* @Author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
Article::create([
|
||||
'cid' => $post['cid'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'content' => $post['content'] ?? '',
|
||||
'visit' => 0,
|
||||
'likes' => 0,
|
||||
'sort' => $post['sort'] ?? 0,
|
||||
'is_notice' => $post['is_notice'],
|
||||
'is_show' => $post['is_show']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 编辑文章
|
||||
* @Author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
Article::update([
|
||||
'cid' => $post['cid'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'content' => $post['content'] ?? '',
|
||||
'visit' => 0,
|
||||
'likes' => 0,
|
||||
'sort' => $post['sort'] ?? 0,
|
||||
'is_notice' => $post['is_notice'],
|
||||
'is_show' => $post['is_show']
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 删除
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
Article::update([
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 隐藏
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function hide($id)
|
||||
{
|
||||
try {
|
||||
$model = new Article();
|
||||
$article = $model->findOrEmpty($id)->toArray();
|
||||
|
||||
Article::update([
|
||||
'is_show' => !$article['is_show'],
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
163
app/admin/logic/content/HelpCategoryLogic.php
Normal file
163
app/admin/logic/content/HelpCategoryLogic.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\logic\content;
|
||||
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\content\HelpCategory;
|
||||
use Exception;
|
||||
|
||||
class HelpCategoryLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* 获取帮助分类
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
$model = new HelpCategory();
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->order('id', 'desc')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
$item['is_show'] = $item['is_show'] ? '启用' : '停用';
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 获取文章分类
|
||||
* @Author: 张无忌
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategory()
|
||||
{
|
||||
try {
|
||||
$model = new HelpCategory();
|
||||
return $model->field(true)
|
||||
->where(['del'=>0, 'is_show'=>1])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取帮助分类详细
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new HelpCategory();
|
||||
return $model->field(true)->findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文章分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
|
||||
HelpCategory::create([
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑帮助分类
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
|
||||
HelpCategory::update([
|
||||
'name' => $post['name'],
|
||||
'is_show' => $post['is_show']
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除帮助分类
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
|
||||
HelpCategory::update([
|
||||
'del' => 1
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 隐藏
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function hide($id)
|
||||
{
|
||||
try {
|
||||
$model = new HelpCategory();
|
||||
$category = $model->findOrEmpty($id)->toArray();
|
||||
|
||||
HelpCategory::update([
|
||||
'is_show' => !$category['is_show'],
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
167
app/admin/logic/content/HelpLogic.php
Normal file
167
app/admin/logic/content/HelpLogic.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\logic\content;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\content\Help;
|
||||
use Exception;
|
||||
|
||||
class HelpLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* 获取帮助分类
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['del', '=', 0]
|
||||
];
|
||||
|
||||
if (!empty($get['title']) and $get['title'])
|
||||
$where[] = ['title', 'like', '%'.$get['title'].'%'];
|
||||
|
||||
if (!empty($get['cid']) and is_numeric($get['cid']))
|
||||
$where[] = ['cid', '=', $get['cid']];
|
||||
|
||||
|
||||
$model = new Help();
|
||||
$lists = $model->field(true)
|
||||
->where($where)
|
||||
->with(['category'])
|
||||
->order('sort', 'asc')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
$item['category'] = $item['category']['name'] ?? '未知';
|
||||
$item['is_show'] = $item['is_show'] ? '显示' : '隐藏';
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 帮助详细
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new Help();
|
||||
return $model->field(true)->findOrEmpty($id)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 添加帮助
|
||||
* @Author: 张无忌Help
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
try {
|
||||
Help::create([
|
||||
'cid' => $post['cid'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'content' => $post['content'] ?? '',
|
||||
'visit' => 0,
|
||||
'likes' => 0,
|
||||
'sort' => $post['sort'] ?? 0,
|
||||
'is_show' => $post['is_show']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 编辑帮助
|
||||
* @Author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
try {
|
||||
Help::update([
|
||||
'cid' => $post['cid'],
|
||||
'title' => $post['title'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'intro' => $post['intro'] ?? '',
|
||||
'content' => $post['content'] ?? '',
|
||||
'visit' => 0,
|
||||
'likes' => 0,
|
||||
'sort' => $post['sort'] ?? 0,
|
||||
'is_show' => $post['is_show']
|
||||
], ['id'=>$post['id']]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 删除
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
try {
|
||||
Help::update([
|
||||
'del' => 1,
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 隐藏
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function hide($id)
|
||||
{
|
||||
try {
|
||||
$model = new Help();
|
||||
$article = $model->findOrEmpty($id)->toArray();
|
||||
|
||||
Help::update([
|
||||
'is_show' => !$article['is_show'],
|
||||
'update_time' => time()
|
||||
], ['id'=>$id]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user