浏览代码

上传至'application/admin/controller'

增加友情链接管理
Me 5 年之前
父节点
当前提交
88cdddb437
共有 1 个文件被更改,包括 140 次插入0 次删除
  1. 140 0
      application/admin/controller/Links.php

+ 140 - 0
application/admin/controller/Links.php

@@ -0,0 +1,140 @@
+<?php
+namespace app\admin\controller;
+
+use think\Request;
+use app\admin\model\LinksModel;
+
+class Links extends Base
+{
+    
+
+    public function lst()//友情链接列表
+    {   
+
+        return view(); 
+       
+         
+    }
+
+
+
+    public function lst_data(Request $request){//友情链接列表json数据动态表格显示(分页)
+        $user = new LinksModel();
+        $title = request()->param('title');//接收请求数据id
+        if(!empty($title)){//不为空执行搜索条件,为空则跳过判断条件直接显示列表页,
+            $where = ['title'=>$title];
+            //数据表获取总记录数           
+            $count = $user->where($where)->count();
+            //获取每页显示的条数
+            $limit= $request->param('limit');
+            //获取当前页码
+            $page= $request->param('page');
+            //limit的起始位置
+            $start=($page-1)*$limit; 
+            $list = $user
+                    ->limit("$start,$limit")
+                    ->where($where)
+                    ->select();
+            //返回数据
+            return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
+        }
+        //数据表获取总记录数           
+        $count = $user->count();
+        //获取每页显示的条数
+        $limit= $request->param('limit');
+        //获取当前页码
+        $page= $request->param('page');
+        //limit的起始位置
+        $start=($page-1)*$limit;
+        $list = $user
+                ->limit("$start,$limit")
+                ->select();
+        //返回数据
+        return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
+
+    }
+
+
+    public function add(){      
+        if(request()->isPost()){
+            $user = new LinksModel();
+            $data = input('post.');
+            $where=[
+                'title'=>$data['title'],
+            ];
+            $links = $user->where($where)->find();
+            if(empty($links)){
+                $user->save($data);
+                return 1;
+            }else{
+                return 2;//标题不能重复
+            }
+        }
+        return view();
+
+    }
+
+    public function edit(){
+        $user = new LinksModel();
+        $id = input('id');
+        $list = $user->where('id',$id)->find();
+        if(request()->isPost()){
+            $data = input('post.');
+            if($user->update($data)){             
+                return 1;//修改成功
+            }else{
+                return 2;//修改失败
+            }
+        }
+        $this->assign([
+            'list'=>$list,
+        ]);
+        return view();
+    }
+
+
+    public function del(){//删除
+        $user = new LinksModel();
+        if(request()->isPost()){
+            $id = input('id');
+            $del=$user->where('id',$id)->delete();
+            if($del){
+                return 1;//删除成功             
+            }else{
+                return 2;//删除失败        
+            }
+        }
+        return view();
+
+
+    } 
+
+    public function pdel(){//批量删除
+        $user = new LinksModel();
+        if(request()->isPost()){
+
+            $id = input('post.');//接收前台id
+            $ids = implode(',',$id);//将id用逗号进行隔开
+            $where = [
+                'id'=>['in',$ids],
+            ];
+            $list = $user->where($where)->delete();
+            if($list){
+               return 1;//删除成功
+              
+            }else{
+                return 2;//删除失败
+                
+            }
+        }
+        return view();
+
+    }
+
+    
+        
+ 
+
+
+        
+}