mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 10:32:48 +08:00
完成资讯主题
This commit is contained in:
@@ -1,47 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use app\model\UploadFiles as AppUploadFiles;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Config;
|
||||
|
||||
class UploadFiles
|
||||
class UploadFiles
|
||||
{
|
||||
|
||||
public static function add()
|
||||
{
|
||||
return new AppUploadFiles();
|
||||
public static function add()
|
||||
{
|
||||
return new AppUploadFiles();
|
||||
}
|
||||
|
||||
public static function create($data, $allowFiled = [], $replace = false)
|
||||
{
|
||||
return AppUploadFiles::create($data, $allowFiled, $replace);
|
||||
}
|
||||
|
||||
public static function use($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name', $save_name)->update([
|
||||
'used_time' => time(),
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
public static function delete($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name', $save_name)->update([
|
||||
'delete_time' => time(),
|
||||
'status' => 2
|
||||
]);
|
||||
}
|
||||
|
||||
public static function clear($id)
|
||||
{
|
||||
$model_file = AppUploadFiles::withTrashed()->find($id);
|
||||
|
||||
$model_file->clear_time = time();
|
||||
$model_file->status = 3;
|
||||
|
||||
$model_file->save();
|
||||
|
||||
return Filesystem::delete($model_file->getData('save_name'));
|
||||
}
|
||||
|
||||
public static function save(Request $request)
|
||||
{
|
||||
|
||||
$type = $request->param('type');
|
||||
if (empty($type)) {
|
||||
return json_message('缺少类型参数');
|
||||
}
|
||||
|
||||
public static function create($data,$allowFiled = [],$replace = false)
|
||||
{
|
||||
return AppUploadFiles::create($data,$allowFiled,$replace);
|
||||
$file = request()->file('file');
|
||||
|
||||
$file_extension = $file->extension();
|
||||
|
||||
if ($file_extension == 'php') {
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
|
||||
public static function use($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name',$save_name)->update([
|
||||
'used_time'=>time(),
|
||||
'status'=>1
|
||||
]);
|
||||
$file_path = $file->getRealPath();
|
||||
|
||||
$file_content = file_get_contents($file_path);
|
||||
|
||||
if (strpos($file_content, '<?php') !== false) {
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
|
||||
public static function delete($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name',$save_name)->update([
|
||||
'delete_time'=>time(),
|
||||
'status'=>2
|
||||
]);
|
||||
if (empty($file)) {
|
||||
return json_message('上传失败');
|
||||
}
|
||||
|
||||
public static function clear($id)
|
||||
{
|
||||
$model_file = AppUploadFiles::withTrashed()->find($id);
|
||||
|
||||
$model_file->clear_time = time();
|
||||
$model_file->status = 3;
|
||||
|
||||
$model_file->save();
|
||||
|
||||
return Filesystem::delete($model_file->getData('save_name'));
|
||||
$dir_name = $request->param('dir', 'data');
|
||||
$model_file = UploadFiles::add();
|
||||
$model_file->file_name = $file->getOriginalName();
|
||||
$model_file->mime_type = $file->getOriginalMime();
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
try {
|
||||
$model_file->save_name = Filesystem::putFile('upload/' . $dir_name, $file, 'uniqid');
|
||||
$model_file->save();
|
||||
return json_message($model_file->append(['src'])->toArray());
|
||||
} catch (\Throwable $th) {
|
||||
return json_message($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,100 +9,102 @@ use think\Request;
|
||||
|
||||
class File extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$type = $this->request->param('type',1);
|
||||
$status = $this->request->param('status','');
|
||||
$type = $this->request->param('type', 1);
|
||||
$status = $this->request->param('status', '');
|
||||
|
||||
$model_list = UploadFiles::withTrashed()->where('type',$type)->order('id desc');
|
||||
$model_list = UploadFiles::withTrashed()->where('type', $type)->order('id desc');
|
||||
|
||||
if($status != ''){
|
||||
$model_list->where('status',$status);
|
||||
}
|
||||
|
||||
$list = $model_list->paginate();
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
if ($status != '') {
|
||||
$model_list->where('status', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
$list = $model_list->paginate();
|
||||
View::assign('list', $list);
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
return AppUploadFiles::save($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
AppUploadFiles::clear($id);
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
return json_message();
|
||||
}
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
AppUploadFiles::clear($id);
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,111 +10,69 @@ use app\UploadFiles as AppUploadFiles;
|
||||
|
||||
class Files extends BaseController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$type = $request->param('type');
|
||||
if(empty($type)){
|
||||
return json_message('缺少类型参数');
|
||||
}
|
||||
|
||||
$file = request()->file('file');
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
return AppUploadFiles::save($request);
|
||||
}
|
||||
|
||||
$file_extension = $file->extension();
|
||||
|
||||
if($file_extension == 'php'){
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
$file_path = $file->getRealPath();
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
$file_content = file_get_contents($file_path);
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
if(strpos($file_content,'<?php') !== false){
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
|
||||
if(empty($file)){
|
||||
return json_message('上传失败');
|
||||
}
|
||||
|
||||
$dir_name = $request->param('dir','data');
|
||||
$model_file = AppUploadFiles::add();
|
||||
$model_file->file_name = $file->getOriginalName();
|
||||
$model_file->mime_type = $file->getOriginalMime();
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
try {
|
||||
$model_file->save_name = Filesystem::putFile('upload/'.$dir_name,$file,'uniqid');
|
||||
$model_file->save();
|
||||
return json_message($model_file->append(['src'])->toArray());
|
||||
} catch (\Throwable $th) {
|
||||
return json_message($th->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\BaseController as AppBaseController;
|
||||
@@ -9,38 +10,58 @@ use think\helper\Str;
|
||||
class BaseController extends AppBaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 是否使用多模板
|
||||
* 仅当名称为空或者指定名称有效,
|
||||
* 使用跨应用,跨控制器,引用模板路径的写法时无效
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isUseTpls = true;
|
||||
/**
|
||||
* 是否使用多模板
|
||||
* 仅当名称为空或者指定名称有效,
|
||||
* 使用跨应用,跨控制器,引用模板路径的写法时无效
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isUseTpls = true;
|
||||
|
||||
public function assign($template,$value)
|
||||
{
|
||||
return View::assign($template,$value);
|
||||
}
|
||||
protected $indexTplName = '';
|
||||
protected $indexTplMethod = '';
|
||||
protected $indexTplMethodCurrentAction = '';
|
||||
|
||||
public function fetch($template = '',$vars = [])
|
||||
{
|
||||
if($this->isUseTpls && strpos($template,'@') === false && stripos($template,'/') === false){
|
||||
|
||||
if($template === ''){
|
||||
$config_auto_rule = Config::get('view.auto_rule');
|
||||
if (2 == $config_auto_rule) {
|
||||
$template = $this->request->action(true);
|
||||
} elseif (3 == $config_auto_rule) {
|
||||
$template = $this->request->action();
|
||||
} else {
|
||||
$template = Str::snake($this->request->action());
|
||||
}
|
||||
}
|
||||
return View::fetch(get_system_config('index_tpl_name').$template,$vars);
|
||||
}else{
|
||||
return View::fetch($template,$vars);
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->indexTplName = get_system_config('index_tpl_name');
|
||||
|
||||
$this->indexTplMethod = '__'.Str::camel($this->indexTplName);
|
||||
|
||||
$this->indexTplMethodCurrentAction = $this->indexTplMethod.Str::studly($this->request->action());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function assign($template, $value)
|
||||
{
|
||||
return View::assign($template, $value);
|
||||
}
|
||||
|
||||
public function fetch($template = '', $vars = [])
|
||||
{
|
||||
if ($this->isUseTpls && strpos($template, '@') === false && stripos($template, '/') === false) {
|
||||
|
||||
if ($template === '') {
|
||||
$config_auto_rule = Config::get('view.auto_rule');
|
||||
if (2 == $config_auto_rule) {
|
||||
$template = $this->request->action(true);
|
||||
} elseif (3 == $config_auto_rule) {
|
||||
$template = $this->request->action();
|
||||
} else {
|
||||
$template = Str::snake($this->request->action());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return View::fetch($this->indexTplName . $template, $vars);
|
||||
} else {
|
||||
return View::fetch($template, $vars);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\model\Category;
|
||||
use app\model\Nav;
|
||||
use think\facade\View;
|
||||
use think\helper\Str;
|
||||
|
||||
class Common extends BaseController
|
||||
class Common extends BaseController
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
|
||||
parent::initialize();
|
||||
|
||||
$list_header_nav = Nav::where('type',1)->order('sort asc')->where('status',1)->select();
|
||||
View::assign('list_header_nav',$list_header_nav);
|
||||
$list_nav_slide = Nav::where('type',3)->order('sort asc')->where('status',1)->select();
|
||||
View::assign('list_nav_slide',$list_nav_slide);
|
||||
$list_nav_index_block_1 = Nav::where('type',6)->order('sort asc')->where('status',1)->select();
|
||||
View::assign('list_nav_index_block_1',$list_nav_index_block_1);
|
||||
$list_nav_index_block_2 = Nav::where('type',7)->order('sort asc')->where('status',1)->select();
|
||||
View::assign('list_nav_index_block_2',$list_nav_index_block_2);
|
||||
$list_nav_friend_url = Nav::where('type',2)->order('sort asc')->where('status',1)->select();
|
||||
View::assign('list_nav_friend_url',$list_nav_friend_url);
|
||||
$list_header_nav = Nav::where('type', 1)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
$list_nav_slide = Nav::where('type', 3)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_slide', $list_nav_slide);
|
||||
$list_nav_friend_url = Nav::where('type', 2)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_friend_url', $list_nav_friend_url);
|
||||
|
||||
if (!empty($this->indexTplMethod)) {
|
||||
|
||||
if (method_exists($this, $this->indexTplMethod)) {
|
||||
$this->{$this->indexTplMethod}();
|
||||
}
|
||||
|
||||
}
|
||||
if (!empty($this->indexTplMethodCurrentAction)) {
|
||||
|
||||
if (method_exists($this, $this->indexTplMethodCurrentAction)) {
|
||||
$this->{$this->indexTplMethodCurrentAction}();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function __easyBlue()
|
||||
{
|
||||
$list_nav_index_block_1 = Nav::where('type', 6)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_index_block_1', $list_nav_index_block_1);
|
||||
$list_nav_index_block_2 = Nav::where('type', 7)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_index_block_2', $list_nav_index_block_2);
|
||||
}
|
||||
|
||||
public function __articles()
|
||||
{
|
||||
$list_category_first_level = Category::where('level', 1)->where('status', 1)->select();
|
||||
$this->assign('list_category_first_level', $list_category_first_level);
|
||||
$list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_more', $list_nav_more);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,86 +2,126 @@
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use think\facade\View;
|
||||
use app\model\Category;
|
||||
use app\model\Post;
|
||||
use app\model\PostCategory;
|
||||
use think\Request;
|
||||
|
||||
class Index extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
return $this->fetch();
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function __articlesIndex()
|
||||
{
|
||||
|
||||
$sub_category = [];
|
||||
|
||||
if(!empty($this->request->param('category_id'))){
|
||||
$sub_category = Category::where('pid',$this->request->param('category_id'))->select();
|
||||
|
||||
if(empty($this->request->param('sub_category_id'))){
|
||||
$categorys = [$this->request->param('category_id')];
|
||||
|
||||
$categorys = array_merge($categorys,array_column((array)Category::getListLevel($this->request->param('category_id')),'id'));
|
||||
|
||||
$categorys_where = PostCategory::whereIn('category_id',$categorys);
|
||||
|
||||
$model_post = Post::hasWhere('categorys',$categorys_where)->where('status',1)->order('id desc');
|
||||
}else{
|
||||
$model_post = Post::hasWhere('categorys',['category_id'=>$this->request->param('sub_category_id')])->where('status',1)->order('id desc');
|
||||
|
||||
}
|
||||
}else{
|
||||
|
||||
$model_post = Post::where('status',1)->order('id desc');
|
||||
}
|
||||
|
||||
$keywords = $this->request->param('keywords');
|
||||
|
||||
if(!empty($keywords)){
|
||||
$model_post->whereLike('title|desc',"%$keywords%");
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
$list_post = $model_post->paginate();
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
$this->assign('sub_category',$sub_category);
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
$this->assign('list_post',$list_post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,41 @@ class Category extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public static function getListLevel()
|
||||
{
|
||||
$model_list = Category::select();
|
||||
public static $allCategory = [];
|
||||
|
||||
// return $model_list;
|
||||
return array2level($model_list,0,0);
|
||||
|
||||
/**
|
||||
* 获取指定id下的所有分类
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public static function getListLevel($id = '')
|
||||
{
|
||||
|
||||
if(empty(self::$allCategory)){
|
||||
|
||||
$model_list = Category::select();
|
||||
self::$allCategory = array2level($model_list,0,0);
|
||||
}
|
||||
|
||||
if(!empty($id)){
|
||||
$list = [];
|
||||
$in_category = [$id];
|
||||
foreach (self::$allCategory as $category) {
|
||||
if(in_array($category->pid,$in_category)){
|
||||
$list[] = $category;
|
||||
$in_category[] = $category->id;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
return self::$allCategory;
|
||||
}
|
||||
|
||||
|
||||
public function getTitleImgAttr($value)
|
||||
{
|
||||
|
||||
|
||||
@@ -113,6 +113,10 @@ class Post extends Model
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
public function setContentHtmlAttr($value)
|
||||
{
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
public function getContentAttr($value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user