diff --git a/.env b/.env index 51e8457..762a345 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -APP_DEBUG = true +APP_DEBUG = false SYSTEM_SALT= YAdmin [APP] diff --git a/README.md b/README.md index de60939..377b906 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ location / { } ``` +3、程序使用不收费,但不负责搭建,搭建过程遇到问题,可以私聊或群里咨询 +完全小白可付费搭建,可联系作者或群友 + ## 后台管理截图 @@ -75,3 +78,4 @@ location / { 请加微信l1417716300,请备注来源 + diff --git a/app/admin/controller/Source.php b/app/admin/controller/Source.php index b24398b..d220fe2 100644 --- a/app/admin/controller/Source.php +++ b/app/admin/controller/Source.php @@ -26,11 +26,11 @@ class Source extends QfShop ]; $this->insertFields = [ //允许添加的字段列表 - "title","url","status","is_delete" + "source_category_id","title","url","status","is_delete","sort","is_top" ]; $this->updateFields = [ //允许更新的字段列表 - "title","url","status","is_delete" + "source_category_id","title","url","status","is_delete","sort","is_top" ]; $this->insertRequire = [ //添加时必须填写的字段 @@ -65,8 +65,11 @@ class Source extends QfShop //从请求中获取筛选数据的数组 $map = $this->getDataFilterFromRequest(); $map[] = ['is_delete','=',0]; + if(!empty(input('source_category_id'))){ + $map[] = ['source_category_id','=',input('source_category_id')]; + } //从请求中获取排序方式 - $order = $this->getorderfromRequest(); + $order = ['is_top' => 'desc','sort' => 'desc','source_id' => 'desc']; //设置Model中的 per_page $this->setGetListPerPage(); //查询数据 @@ -217,6 +220,7 @@ class Source extends QfShop //删除这个文件 unlink("./uploads/".$saveName); + // 生成二维码 foreach ($excel_array as $k => $v) { $patterns = '/^\d+\.|\d+\-/'; @@ -238,6 +242,7 @@ class Source extends QfShop if (empty($res) && $url) { $data[$k]['title'] = $title; $data[$k]['url'] = $url; + $data[$k]['source_category_id'] = input('source_category_id')??0; $data[$k]['update_time'] = time(); $data[$k]['create_time'] = time(); $i++; diff --git a/app/admin/controller/SourceCategory.php b/app/admin/controller/SourceCategory.php new file mode 100644 index 0000000..1d546c6 --- /dev/null +++ b/app/admin/controller/SourceCategory.php @@ -0,0 +1,258 @@ +selectList = "*"; + //查询详情时允许的字段 + $this->selectDetail = "*"; + //筛选字段 + $this->searchFilter = [ + "source_category_id" => "=", + "name"=>"like" + ]; + $this->insertFields = [ + //允许添加的字段列表 + "name","sort","status" + ]; + $this->updateFields = [ + //允许更新的字段列表 + "name","sort","status" + ]; + $this->insertRequire = [ + //添加时必须填写的字段 + // "字段名称"=>"该字段不能为空" + "name"=>"分类名称必须填写", + ]; + $this->updateRequire = [ + //修改时必须填写的字段 + // "字段名称"=>"该字段不能为空" + "name"=>"分类名称必须填写", + ]; + $this->model = new SourceCategoryModel(); + } + + + /** + * 获取列表接口 + * + * @return void + */ + public function getList() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + //查询数据 + $dataList = $this->model->order('sort', 'desc')->select(); + return jok('数据获取成功', $dataList); + } + + /** + * 获取详情基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function detail() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + $source_category_id = input("source_category_id"); + if (!$source_category_id) { + return jerr("ID参数必须填写", 400); + } + //根据主键获取一行数据 + $item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find(); + if (empty($item)) { + return jerr("没有查询到数据", 404); + } + return jok('数据加载成功', $item); + } + + /** + * 添加接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function add() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + //校验Insert字段是否填写 + $error = $this->validateInsertFields(); + if ($error) { + return $error; + } + //从请求中获取Insert数据 + $data = $this->getInsertDataFromRequest(); + //添加这行数据 + $data['create_time'] = time(); + $data['update_time'] = time(); + $this->model->insertGetId($data); + return jok('添加成功'); + } + + /** + * 修改接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function update() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + $source_category_id = input("source_category_id"); + if (!$source_category_id) { + return jerr("ID参数必须填写", 400); + } + //根据主键获取一行数据 + $item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find(); + if (empty($item)) { + return jerr("数据查询失败", 404); + } + //校验Update字段是否填写 + $error = $this->validateUpdateFields(); + if ($error) { + return $error; + } + //从请求中获取Update数据 + $data = $this->getUpdateDataFromRequest(); + //根据主键更新这条数据 + $data['update_time'] = time(); + $this->model->where("source_category_id", $source_category_id)->update($data); + return jok('修改成功'); + } + + /** + * 删除接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function delete() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + $source_category_id = input("source_category_id"); + if (!$source_category_id) { + return jerr("ID参数必须填写", 400); + } + if (isInteger($source_category_id)) { + //根据主键获取一行数据 + $item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find(); + if (empty($item)) { + return jerr("数据查询失败", 404); + } + //单个操作 + $map = ["source_category_id" => $source_category_id]; + $this->model->where($map)->delete(); + } else { + //批量操作 + $list = explode(',', $source_category_id); + $this->model->where("source_category_id", 'in', $list)->delete(); + } + return jok('删除成功'); + } + + /** + * 禁用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function disable() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + $source_category_id = input("source_category_id"); + if (!$source_category_id) { + return jerr("ID参数必须填写", 400); + } + if (isInteger($source_category_id)) { + //根据主键获取一行数据 + $item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find(); + if (empty($item)) { + return jerr("数据查询失败", 404); + } + //单个操作 + $map = ["source_category_id" => $source_category_id]; + $this->model->where($map)->update([ + "status" => 1, + "update_time" => time(), + ]); + } else { + //批量操作 + $list = explode(',', $source_category_id); + $this->model->where("source_category_id", 'in', $list)->update([ + "status" => 1, + "update_time" => time(), + ]); + } + return jok("禁用成功"); + } + + + /** + * 启用接口基类 子类自动继承 如有特殊需求 可重写到子类 请勿修改父类方法 + * + * @return void + */ + public function enable() + { + //校验Access与RBAC + $error = $this->access(); + if ($error) { + return $error; + } + $source_category_id = input("source_category_id"); + if (!$source_category_id) { + return jerr("ID参数必须填写", 400); + } + if (isInteger($source_category_id)) { + //根据主键获取一行数据 + $item = $this->model->where("source_category_id", $source_category_id)->field($this->selectDetail)->find(); + if (empty($item)) { + return jerr("数据查询失败", 404); + } + //单个操作 + $map = ["source_category_id" => $source_category_id]; + $this->model->where($map)->update([ + "status" => 0, + "update_time" => time(), + ]); + } else { + //批量操作 + $list = explode(',', $source_category_id); + $this->model->where("source_category_id", 'in', $list)->update([ + "status" => 0, + "update_time" => time(), + ]); + } + return jok("启用成功"); + } + +} diff --git a/app/api/controller/Search.php b/app/api/controller/Search.php index 3647a42..10e0297 100644 --- a/app/api/controller/Search.php +++ b/app/api/controller/Search.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\api\QfShop; use app\model\Source as SourceModel; +use app\model\SourceCategory as SourceCategoryModel; class Search extends QfShop { @@ -34,4 +35,11 @@ class Search extends QfShop $data = $SourceModel->getHot(input('')); return jok('获取成功',$data); } + + public function getCategory() + { + $SourceCategoryModel = new SourceCategoryModel(); + $data = $SourceCategoryModel->getList(input('')); + return jok('获取成功',$data); + } } diff --git a/app/model/Source.php b/app/model/Source.php index 995b755..5617050 100644 --- a/app/model/Source.php +++ b/app/model/Source.php @@ -37,6 +37,19 @@ class Source extends QfShop 'time' => 'timestamp', ]; + /** + * hasOne qf_source_category + * @access public + * @return mixed + */ + public function category() + { + return $this + ->hasOne(SourceCategory::class, 'source_category_id', 'source_category_id') + ->joinType('left') + ->field('source_category_id,name'); + } + /** * @description: 获取一个信息 @@ -48,8 +61,8 @@ class Source extends QfShop $map[] = ['status', '=', 1]; $map[] = ['is_delete', '=', 0]; $map[] = ['source_id', '=', $data['id']]; - $field = 'source_id as id,title,url,update_time as time'; - $result = $this->where($map)->field($field)->find(); + $field = 'source_id as id,source_category_id,title,url,update_time as time'; + $result = $this->with('category')->where($map)->field($field)->find(); if(!is_null($result)){ $result->inc('page_views')->update(); } @@ -90,6 +103,10 @@ class Source extends QfShop unset($map[array_search(['is_time', '=', 0], $map)]); } + if(!empty($data['category_id'])){ + $map[] = ['source_category_id', '=', $data['category_id']]; + } + $result['total_result'] = $this->where($map)->count(); if ($result['total_result'] <= 0) { return $result; @@ -101,7 +118,8 @@ class Source extends QfShop } $result['items'] = $this->setDefaultOrder($order) - ->field('source_id as id,title,url,update_time as time,is_time') + ->field('source_id as id,source_category_id,title,url,update_time as time,is_time') + ->with('category') ->where($map) ->withSearch(['page', 'order'], $data) ->select()->each(function($item,$key){ diff --git a/app/model/SourceCategory.php b/app/model/SourceCategory.php new file mode 100644 index 0000000..073f9d0 --- /dev/null +++ b/app/model/SourceCategory.php @@ -0,0 +1,25 @@ +where($map)->order('sort', 'desc')->select(); + return $result; + } +} diff --git a/app/qfadmin/view/source/category.html b/app/qfadmin/view/source/category.html new file mode 100644 index 0000000..e8b3f73 --- /dev/null +++ b/app/qfadmin/view/source/category.html @@ -0,0 +1,279 @@ + + + + + 资源分类 + {include file="common/header"/} + + + 添加 + + + 批量删除 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {include file="common/footer"/} + + + + \ No newline at end of file diff --git a/app/qfadmin/view/source/index.html b/app/qfadmin/view/source/index.html index 2275533..35252b1 100644 --- a/app/qfadmin/view/source/index.html +++ b/app/qfadmin/view/source/index.html @@ -12,6 +12,12 @@ 导出资源
+ + + + + + @@ -27,11 +33,22 @@ + + - + + - + + + + +