作者 lihan

同行人功能

<?php
namespace api\home\controller;
use cmf\controller\RestBaseController;
/**
... ...
<?php
namespace app\activity\controller;
use cmf\controller\HomeBaseController;
use think\Db;
/**
* @title 活动模块
*/
class ActivityController extends HomeBaseController {
/**
* @title 接口返回参数说明
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /activity/Activity/detail
* @method POST
*
* @param name:id type:char require:1 default:lihan other: desc:活动id
*/
public function detail() {
$request=request();
$id=$request->param('id');
$info=Db::name('activity')->where(['id'=>$id])->find();
$
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/9/1
* Time: 9:26
*/
namespace app\admin\controller;
use Think\Db;
use cmf\controller\AdminBaseController;
class OrderController extends AdminBaseController
{
public function index()
{
}
}
\ No newline at end of file
... ...
<?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
... ...
... ... @@ -17,10 +17,10 @@ use EasyWeChat\Foundation\Application;
*/
class IndexController extends HomeBaseController {
/**
* @title 首页
* @title 接口返回参数说明
* @description 默认访问接口
* @author Soul of Cinder
* @url /home/index/index
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /portal/index/index
* @method GET
*
* @return version:版本号
... ... @@ -39,7 +39,8 @@ class IndexController extends HomeBaseController {
'40004' => '登录失败',
]
];
$this->success("恭喜您,API访问成功!", $data);
echo json_encode(['msg'=>$data]);
exit();
}
}
... ...
... ... @@ -8,8 +8,9 @@ class Doc
'version'=>'1.0.0',
'copyright'=>'银河百荣科技',
'controller' => [
'api\\home\\controller\\IndexController',
'app\\portal\\controller\\IndexController'
'app\portal\controller\IndexController',
'app\escort\controller\EscortController',
'app\activity\controller\ActivityController'
],
'password'=>'bronet',
'static_path'=>'',
... ...