123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- declare(strict_types=1);
- namespace app\model;
- /**
- * 栏目模型
- */
- class Category extends Base
- {
- protected $pk = 'id';
- protected $schema = [
- "id" => "int",
- "parent_id" => "int",
- "name" => "varchar",
- "url" => "varchar",
- "route" => "varchar",
- "type" => "int",
- "is_nav" => "int",
- "sort" => "int",
- "title" => "varchar",
- "keywords" => "varchar",
- "description" => "varchar",
- "is_blank" => "int",
- "create_time" => "int",
- "update_time" => "int"
- ];
- // 获取列表
- public static function getList(array $param = [])
- {
- $where = [];
- if (isset($param['is_nav']) ) {
- $where[] = ['is_nav', '=', (int) $param['is_nav']];
- }
- if (isset($param['type']) ) {
- $where[] = ['type', '=', (int) $param['type']];
- }
- $order = isset($param['order']) ? (string) $param['order'] : "sort ASC,id DESC";
- return self::where($where)->field("id,parent_id,name,url,route,type,is_nav,sort,is_blank,create_time")->order($order)->select();
- }
- // 导航状态修改 1,显示; 0,不显示
- public static function navStaus(int $id)
- {
- try {
- $info = self::find($id);
- $info->is_nav = -1 - $info['is_nav'];
- $info->save();
- return json(['code' => 0, 'msg' => '修改成功!', 'is_nav'=>$info->is_nav]);
- } catch (\Exception $e) {
- return json(['code' => 1, 'msg' => $e->getMessage()]);
- }
- }
- public static function selectOne()
- {
- $list = self::where('type', 1)->field("id, parent_id,name")->select();
- $top = new static([
- "id"=> 0,
- "parent_id" => -1,
- "name" => "顶级栏目"
- ]);
- $list->push($top);
- return list_tree($list, 'id', 'parent_id', 'child', -1);
- }
- }
|