|
|
<?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();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|