0){ $where[] = ['pid', '=', $get['pid']]; } $model = new JobCate(); $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 getCate($pid=0) { try { $model = new JobCate(); 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 JobCate(); return $model->field(true)->findOrEmpty($id)->toArray(); } /** * 添加分类 * @param $post * @return bool */ public static function add($post) { try { JobCate::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 { JobCate::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 { JobCate::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 JobCate(); $category = $model->findOrEmpty($id)->toArray(); JobCate::update([ 'is_show' => !$category['is_show'], 'update_time' => time() ], ['id'=>$id]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } }