| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: Tuolaji <479923197@qq.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\facade\Db;
- use think\db\Query;
- class NewsController extends AdminBaseController{
-
-
- // 后台新闻分类列表
- public function index(){
- $list=Db::name('news_cate')
- // ->where('status=1')
- ->order("sort DESC,id DESC")
- ->paginate(10);
- $list->each(function($v,$k){
- if($v['status']==1){
- $v['status_name'] = '启用';
- }else{
- $v['status_name'] = '隐藏';
- }
- $v['create_time'] = $v['create_time']? date('Y-m-d H:i:s',$v['create_time']):'';
- return $v;
- });
- $page = $list->render();
- $this->assign('list', $list);
- $this->assign('page', $page);
- // 渲染模板输出
- return $this->fetch();
- }
-
- //新闻分类添加
- public function add(){
- return $this->fetch();
- }
-
- public function add_post(){
- $data = input('post.');
- if($data['name']==''){
- $this->error('分类名称不能为空!');
- }
- $data['create_time'] = time();
- $add=Db::name('news_cate')->insertGetId($data);
- if($add){
- $this->success('添加成功!');
- }else{
- $this->error('添加失败!');
- }
- }
-
-
- //文章分类编辑
- public function edit(){
- $id = input('param.id');
- if($id){
- $info=Db::name('news_cate')->where('id',$id)->find();
- $this->assign('info',$info);
- }else{
- $this->error('数据传入失败!');
- }
-
- return $this->fetch();
- }
-
- public function edit_post(){
- $data = input('post.');
- if($data['name']==''){
- $this->error('分类名称不能为空!');
- }
- $save=Db::name('news_cate')->where('id',$data['id'])->update($data);
- if($save!==false){
- $url = 'news/index';
- $this->success('保存成功!',$url);
- }else{
- $this->error('保存失败!');
- }
- }
-
-
- // 新闻分类删除
- public function del(){
- $id = input('param.id');
- if($id){
- $result=Db::name('news_cate')->delete($id);
- if($result){
- //删除分类下的文章
- //Db::name('posts')->where('id',$id)->delete();
-
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }else{
- $this->error('数据传入失败!');
- }
- }
-
-
-
- // 文章分类排序
- public function listorder(){
- $listorders = input('listorders');
-
-
- foreach ($listorders as $key => $r) {
- $data=array();
- $data['listorder'] = $r;
- Db::name('terms')->where(['id'=>$key])->update($data);
- }
- $status = true;
- if ($status) {
- $this->success("排序更新成功!");
- } else {
- $this->error("排序更新失败!");
- }
- }
-
-
- }
|