安徽博创起重服务端程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

182 lines
4.3 KiB

<?php
namespace app\admin\logic\content;
use app\common\basics\Logic;
use app\common\model\content\ArticleCategory;
use app\common\model\content\ResourceCategory;
use Exception;
class ResourceCategoryLogic extends Logic
{
/**
* 获取资源分类
* @param $get
* @return array
*/
public static function lists($get)
{
try {
$where = [
['del', '=', 0],
];
if(isset($get['pid']) && $get['pid']>0){
$where[] = ['pid', '=', $get['pid']];
}
$model = new ResourceCategory();
$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'] ? '启用' : '停用';
if($item['pid']){
$where2 = [
['del', '=', 0],
['id', '=', $item['pid']],
];
$cates = $model->where($where2)->find();
if($cates){
$item['p_name'] = $cates['name'];
}else{
$item['p_name'] = '无';
}
}else{
$item['p_name'] = '无';
}
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 获取分类
* @Author: 张无忌
* @return array
*/
public static function getCategory($pid=0)
{
try {
$model = new ResourceCategory();
return $model->field(true)
->where(['del'=>0, 'is_show'=>1,'pid'=>$pid])
->order('id', 'desc')
->select()
->toArray();
} catch (\Exception $e) {
return [];
}
}
/**
* 获取文章分类详细
* @param $id
* @return array
*/
public static function detail($id)
{
$model = new ResourceCategory();
return $model->field(true)->findOrEmpty($id)->toArray();
}
/**
* 添加分类
* @param $post
* @return bool
*/
public static function add($post)
{
try {
ResourceCategory::create([
'name' => $post['name'],
'is_show' => $post['is_show'],
'pid' => $post['pid']
]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* 编辑分类
* @param $post
* @return bool
*/
public static function edit($post)
{
try {
ResourceCategory::update([
'name' => $post['name'],
'pid' => $post['pid'],
'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 {
ResourceCategory::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 ResourceCategory();
$category = $model->findOrEmpty($id)->toArray();
ResourceCategory::update([
'is_show' => !$category['is_show'],
'update_time' => time()
], ['id'=>$id]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
}