EscortController.php
7.3 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
namespace app\escort\controller;
use cmf\controller\HomeBaseController;
use Think\Db;
/**
* @title 萨米户外
*/
class EscortController extends HomeBaseController
{
function _initialize()
{
header("Access-Control-Allow-Origin: *"); // 允许任意域名发起的跨域请求
header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
$this->userId = (empty($_POST['user_id'])) ? null : $_POST['user_id'];
if (empty($this->userId)) {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
}
/**
* @title 添加出行人
* @description 接口说明
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /escort/Escort/add
* @method POST
* @module 出行人模块
*
* @param name:name type:char require:1 default:lihan other: desc:出行人姓名
* @param name:sex type:tinyint require:1 default:0 other: 0 desc:出行人性别 0男 1女
* @param name:tel type:char require:1 default:15122554644 desc:出行人电话
* @param name:identity type:char require:1 default:12010319991111261X desc:出行人身份证
* @param name:wechat type:char require:1 default:9fk390_xmw1985 desc:出行人微信号
*
* @return id:新增出行人id
*/
public function add()
{
$request = request();
if ($request->isPost()) {
$userId = $this->userId;
if (!empty($userId)) {
$post = $request->param();
if (empty($post['name'])) {
echo json_encode(['msg' => '请填写出行人姓名', 'code' => 40000]);
exit();
}
if (empty($post['tel'])) {
echo json_encode(['msg' => '请填写出行人电话', 'code' => 40000]);
exit();
}
if (empty($post['identity'])) {
echo json_encode(['msg' => '请填写出行人身份证信息', 'code' => 40000]);
exit();
}
if (empty($post['wechat'])) {
echo json_encode(['msg' => '请填写出行人微信号', 'code' => 40000]);
exit();
}
$post['user_id'] = $userId;
if (Db::name('escort')->insert($post)) {
echo json_encode(['msg' => '添加成功', 'data' => ['id' => Db::name('escort')->getLastInsID()], 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '添加失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
/**
* @title 编辑出行人
* @description 接口说明
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /escort/Escort/edit
* @method POST
* @module 出行人模块
*
* @param name:id type:int require:1 default:2 desc:出行人id
* @param name:name type:char require:1 default:lihan other: desc:出行人姓名
* @param name:sex type:tinyint require:1 default:other: 0 desc:出行人性别 0男 1女
* @param name:tel type:char require:1 default:15122554644 desc:出行人电话
* @param name:identity type:char require:1 default:12010319991111261X desc:出行人身份证
* @param name:wechat type:char require:1 default:9fk390_xmw1985 desc:出行人微信号
*/
public function edit()
{
$request = request();
if ($request->isPost()) {
$userId = $this->userId;
if (!empty($userId)) {
$post = $request->param();
if (empty($post['name'])) {
echo json_encode(['msg' => '请填写出行人姓名', 'code' => 40000]);
exit();
}
if (empty($post['tel'])) {
echo json_encode(['msg' => '请填写出行人电话', 'code' => 40000]);
exit();
}
if (empty($post['identity'])) {
echo json_encode(['msg' => '请填写出行人身份证信息', 'code' => 40000]);
exit();
}
if (empty($post['wechat'])) {
echo json_encode(['msg' => '请填写出行人微信号', 'code' => 40000]);
exit();
}
$post['user_id'] = $userId;
if (Db::name('escort')->update($post)) {
echo json_encode(['msg' => '编辑成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '您未做出任何修改', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
/**
* @title 删除出行人
* @description 接口说明
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /escort/Escort/del
* @method POST
* @module 出行人模块
*
* @param name:id type:int require:1 default:2 desc:出行人id
*/
public function del()
{
$request = request();
if ($request->isPost()) {
$userId = $this->userId;
if (!empty($userId)) {
if (Db::name('escort')->delete($request->param('id'))) {
echo json_encode(['msg' => '删除成功', 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '删除失败', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '登陆失败', 'code' => 40001]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
/**
* @title 出行人列表
* @description 接口说明
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /escort/Escort/_list
* @method POST
* @module 出行人模块
*
* @param name:user_id type:int require:1 default:1 desc:用户id
*
* @return id:出行人id
* @return name:出行人姓名
* @return tel:出行人电话
* @return identity:出行人身份证
*/
public function _list()
{
$request = request();
$userId = $this->userId;
if ($request->isPost()) {
$data = Db::name('escort')->field('id,name,tel,identity')->where(['user_id' => $userId])->select()->toArray();
if (!empty($data)) {
echo json_encode(['data' => $data, 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '暂无数据', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
}