School.php
3.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\api\model\School as SchoolModel;
/**
* 高中相关
*/
class School extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 添加一个高中
* @ApiTitle (添加一个高中)
* @ApiSummary (添加一个高中)
* @ApiMethod (POST)
* @ApiParams (name="name", type="string", required=true, description="高中名")
* @ApiParams (name="province_id", type="integer", required=true, description="省ID")
* @ApiParams (name="city_id", type="integer", required=true, description="城市ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "已经提交了哦,管理员正在审核",
"time": "1586507878",
"data": null
})
*/
public function addOneSchool()
{
$provinceId = $this->request->param('province_id', 0, 'int');
$cityId = $this->request->param('city_id', 0, 'int');
if(!$cityId || !$provinceId) {
$this->error('您的操作有误');
}
$name = $this->request->param('name', '', 'string');
if(!$name) {
$this->error('学校名字不能是空的哦');
}
if(mb_strlen($name) > 50) {
$this->error('学校名字不能超过50汉字长度哦');
}
$school = new SchoolModel();
$insertData = [
'name' => $name,
'province_id' => $provinceId,
'city_id' => $cityId,
'createtime' => time(),
'updatetime' => time(),
];
$res = $school->addOne($insertData);
if(!$res) {
$this->error('对不起,提交失败了');
}
$this->success('已经提交了哦,管理员正在审核');
}
/**
* 获取市的高中
* @ApiTitle (获取市的高中)
* @ApiSummary (获取市的高中)
* @ApiMethod (GET)
* @ApiParams (name="name", type="string", required=true, description="高中名")
* @ApiParams (name="city_id", type="integer", required=true, description="城市ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn ({
"code": 1,
"msg": "获取市的高中成功",
"time": "1586508827",
"data": [
{
"id": 1,
"province_id": 1,
"city_id": 1,
"createtime": 0,
"updatetime": 0,
"name": "北京高中",
"weigh": 0,
"show_switch": 1,
"deletetime": null
},
{
"id": 2,
"province_id": 1,
"city_id": 1,
"createtime": 0,
"updatetime": 0,
"name": "北京二高",
"weigh": 0,
"show_switch": 1,
"deletetime": null
}
]
})
*/
public function getSchoolList()
{
$cityId = $this->request->param('city_id', 0, 'int');
if(!$cityId) {
$this->error('您的操作有误');
}
$school = new SchoolModel();
$schoolList = $school->listAllByCityId($cityId);
$this->success('获取市的高中成功', $schoolList);
}
}