ZxcZxc123 2 年之前
父節點
當前提交
bfcc8ccc7c
共有 3 個文件被更改,包括 236 次插入1 次删除
  1. 195 0
      app/model/api/EducationModel.php
  2. 40 0
      app/system/controller/EducationController.php
  3. 1 1
      library/utils/Qiniu.php

+ 195 - 0
app/model/api/EducationModel.php

@@ -0,0 +1,195 @@
+<?php
+
+namespace app\model\api;
+
+use think\Model;
+
+    /**
+    * 教育模型
+    */
+class EducationModel extends Model
+    {
+    // 设置当前模型对应的数据表名称
+    protected $name = 'education';
+
+    // 设置当前模型的数据库连接
+    protected $connection = 'database';
+
+    /**
+     * 当前所在模块的CSS样式类
+     */
+    const CURS_TYLE = 'current';
+    const CATE_TREE_PREFIX = '├──';
+    const CATE_TABLE_NAME = 'table_education_cate';
+
+    public static function getCateInstance()
+    {
+    return new self(strtr(self::CATE_TABLE_NAME, ['wp_' => '']));
+    }
+
+    /**
+     * 获取导航栏
+     *
+     * @return array
+     */
+    public static function getNav(array $params, $isRoot = false)
+    {
+    $nav = [];
+    foreach (self::getModules() as $module => $desc) {
+        if (($desc[1] && $isRoot) || !$desc[1]) {
+            $nav[$module] = [
+                'title' => $desc[0],
+                'url' => url($module, $params),
+            ];
+        }
+    }
+    $nav[ACTION_NAME]['class'] = self::CURS_TYLE;
+    return $nav;
+    }
+
+    /**
+     * 获取所有模块
+     * 按理说这里应该从数据库的配置表来动态取,但是扩展的可能性不大,所以直接写死了
+     *
+     * @return array
+     */
+    public static function getModules()
+    {
+    return [
+        'catelist' => ['分类管理', 1],
+        'lists' => ['课程列表', 0],
+        'grlists' => ['分组列表', 0],
+        'aboutme' => ['讲师介绍', 0],
+    ];
+    }
+
+    /**
+     * 获取所有分类
+     *
+     * @return mixed
+     */
+    public function getCate()
+    {
+    $items = $this->table(self::CATE_TABLE_NAME)
+        ->where(['status' => 'Y'])
+        ->order('sort', 'asc')
+        ->getField('id,pid,name,sort');
+
+    $tree = array(); //格式化好的树
+    foreach ($items as $key => $item) {
+        $items[$key]['oriName'] = $item['name'];
+        if (isset ($items [$item ['pid']])) {
+            $items [$item ['pid']] ['son'] [$item ['id']] = &$items [$item ['id']];
+        } else {
+            $tree [$item ['id']] = &$items [$item ['id']];
+        }
+    }
+
+    return $this->formatCateTree($tree);
+    }
+
+    /**
+     * 获取顶级类
+     */
+    public function getTopCate()
+    {
+    $items = $this->table(self::CATE_TABLE_NAME)
+        ->where(['status' => 'Y', 'pid' => 0])
+        ->order('sort', 'asc')
+        ->getField('id,pid,name,sort');
+
+    return $items;
+    }
+
+    public function getSubcatesByTopCate($cates, &$subcates = array())
+    {
+    foreach ($cates as $cate) {
+        $subcates[] = $cate['id'];
+        if (isset($cate['son'])) {
+            $this->getSubcatesByTopCate($cate['son'], $subcates);
+        }
+    }
+    return $subcates;
+    }
+
+    public static function getPureCateName($dirtyName)
+    {
+    return strtr($dirtyName, [self::CATE_TREE_PREFIX => '']);
+    }
+
+    /**
+     * 格式化分类树
+     *
+     * @param $tree
+     * @return mixed
+     */
+    public function formatCateTree($tree, $parents = '')
+    {
+    static $tem = array();
+    static $prefix = 0;
+
+    foreach ($tree as $key => $val) {
+        if (!isset($tem [$val ['id']]))
+            $tem [$val ['id']] = $val;
+
+        if ($prefix) {
+            $tem [$val ['id']]['name'] = str_repeat(self::CATE_TREE_PREFIX, $prefix) . $tem [$val ['id']]['name'];
+            $tem [$val ['id']]['parents'] = ($parents ? $parents . '->' : '') . $val['name'];
+        }
+
+        if (isset($val ['son']) && is_array($val ['son'])) {
+            $prefix += 1;
+            $this->formatCateTree($val ['son'], ($parents ? $parents . '->' : '') . $val['name']);
+            $prefix -= 1;
+        }
+    }
+
+    return $tem;
+    }
+
+    /**
+     * 修改分类
+     *
+     * @param array $data 修改的信息
+     * @param $id 类目ID
+     * @return bool
+     */
+    public function editCate(array $data, $id)
+    {
+    if ($this->allowField(true)->save($data, ['id' => $id])) {
+        return true;
+    }
+    return false;
+    }
+
+    /**
+     * 增加一个分类
+     *
+     * @param array $data
+     * @return bool|mixed
+     */
+    public function addCate(array $data)
+    {
+    $data['status'] = 'Y';
+    if ($this->allowField(true)->save($data)) {
+        return $this->id;
+    }
+    return false;
+    }
+
+    /**
+     * 删除一个分类
+     *
+     * @param array $data
+     * @return bool|mixed
+     */
+    public function delCate($id)
+    {
+    return $this->editCate(['id' => $id, 'status' => 'N'], $id);
+    }
+
+
+}
+
+
+

+ 40 - 0
app/system/controller/EducationController.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\system\controller;
+
+use Qiniu\Auth;
+use Qiniu\Storage\UploadManager;
+use app\model\api\EducationModel;
+use think\facade\View;
+
+class EducationController extends ManageBaseController
+{
+
+
+//    public function initialize()
+//    {
+//        parent::initialize();
+//
+//        // 公共导航
+//        View::assign('nav', EducationModel::getNav($this->get_param, is_administrator()));
+//
+//        if (!$this->mid) {
+//            $this->error("未检测到用户信息,请重新登录");
+//        }
+//    }
+
+
+
+    //获取所有分类列表
+    public function getCateList()
+    {
+        $cateList = EducationModel::select();
+        return json($cateList);
+    }
+
+    //获取所有文章列表
+    public function gteArticleList()
+    {
+
+    }
+}

+ 1 - 1
library/utils/Qiniu.php

@@ -100,7 +100,7 @@ class Qiniu {
         
     }
     /**
-     * 获取qiuniu信息
+     * 获取qiniu信息
      * @global \OSS\OssClient $_A
      */
     public  function getqiniu() {