SchoolController.php
3.2 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class SchoolController extends AdminBaseController{
/*
* 学校管理列表
* */
public function school_list(){
if($this -> request -> isPost()){
if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
$start_time = strtotime($_POST['start_time']);
$end_time = strtotime($_POST['end_time']);
$where['create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($_POST['keyword'])){
$keyword = $_POST['keyword'];
$where['school'] = ['like',"%$keyword%"];
}
$data1 = Db::name('school') -> where($where) -> paginate(1000000) ;
$data = $data1 -> toArray();
}else{
$data1 = Db::name('school') -> paginate(12) ;
$data = $data1 -> toArray();
}
foreach ($data['data'] as $key => $val){
$user_data = Db::name('user') -> where('id',$val['uid']) -> find();
$data['data'][$key]['uname'] = $user_data['user_nickname'];
}
$this -> assign('data',$data['data']);
$this -> assign('res',$data1);
return $this -> fetch();
}
/*
* 学校管理编辑
* */
public function school_edit(){
$id = $this -> request -> param();
$data = Db::name('school') -> where('id',$id['ids']) -> find();
$data_grade = Db::name('grade_class') -> where('school_id',$id['ids']) -> select();
$grade_id = [];
$grade_class = [];
foreach ($data_grade as $key => $val){
$grade_id[] = $val['id'];
$grade_class[] = $val['grade'].','.$val['class'];
}
$grade_id_str = implode('-',$grade_id);
$grade_class_str = implode('|',$grade_class);
$this -> assign('data',$data);
$this -> assign('grade_class_str',$grade_class_str);
$this -> assign('grade_id_str',$grade_id_str);
$province = Db::name('area')->where(['pid'=>0])->select();
$this->assign('province',$province);
return $this -> fetch();
}
/*
* 学校管理编辑提交 修改数据
* */
public function school_edit_post(){
$data['id'] = $_POST['id'];
$data['region'] = $_POST['region'];
$data['school'] = $_POST['school'];
$data['type'] = $_POST['type'];
$res = Db::name('school') -> update($data);
$gread = explode('|',$_POST['grade_class_str']);
foreach($gread as $key => $val){
$greads[] = explode(',',$gread[$key]);
}
$id = explode('-',$_POST['grade_id_str']);
foreach($id as $key => $val){
Db::name('grade_class') -> where('id',$id[$key]) -> update(['grade'=>$greads[$key][0],'class'=>$greads[$key][1]]);
}
$this -> success('保存成功',url('School/school_edit',array('ids'=>$_POST['id'])));
}
/**
* 删除数据
*
*/
public function school_del(){
$id = $_POST['id'];
Db::name('school') -> delete($id);
return true;
}
}