Banner.php
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace app\school\controller\content;
use app\common\controller\ManystoreBase;
use think\Db;
class Banner extends ManystoreBase
{
protected $model = null;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->model = new \app\school\model\content\Banner;
}
public function index(){
if($this->request->isAjax()){
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$count = $this->model->where($where)->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $count, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
public function add(){
if($this->request->isAjax()){
$row = $this->request->param("row/a");
$row['school_id'] = SCHOOL_ID;
if($row['sort'] ==1){
$this->model::where("school_id",$row["school_id"])->setInc("sort");
}elseif($row['sort']>1){
$this->model::where(["school_id"=> ['=',$row["school_id"]],"sort"=>['>=',$row['sort']]])->setInc("sort");
}
$result = $this->model->save($row);
if($result){
$this->success("添加成功");
}else{
$this->error("添加失败");
}
}
return $this->view->fetch();
}
public function edit($ids = null)
{
$info =$this->model::get($ids);
if($this->request->isAjax()){
$row = $this->request->param("row/a");
if($row['sort'] ==1){
$this->model::where("school_id",SCHOOL_ID)->setInc("sort");
}elseif($row['sort']>1){
$this->model::where(["school_id"=> ['=',SCHOOL_ID],"sort"=>['>=',$row['sort']]])->setInc("sort");
}
$status = $info->save($row);
if($status){
$this->success("编辑成功");
}else{
$this->error("编辑失败");
}
}
$this->assign("row",$info);
return $this->view->fetch();
}
public function del($ids = "")
{
$data = $this->model::get($ids);
if(!$data){
$this->error("数据不存在");
}else{
$status = $data->delete();
if($status){
$this->success("删除成功");
}else{
$this->error("删除失败");
}
}
}
}