TrainController.php
2.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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
use app\portal\model\TrainModel;
/**
* @title 培训演习
*/
class TrainController extends RestBaseController
{
/**
* @title 甲方提交培训演习申请
* @description 接口说明
* @author 开发者
* @url /api/home/train/applyTrain
* @method POST
*
* @header name:token require:1 default: desc:header
*
* @param name:train_time type:string require:1 default: other desc:培训时间
* @param name:address type:string require:1 default: other desc:培训地点
* @param name:remark type:string require:1 default: other desc:培训备注
*/
public function applyTrain(){
if($this->request->isPost()){
$data = $this->request->post();
$common = new CommonController();
$user = $common->getUserIdentity();
//如果是乙方,则没有权限操作
if($user['party'] == 1){
$this->error('无权操作');
}
$rule = config('site.train_post');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$data['uid'] = $this->userId;
$data['project_id'] = $user['project_id'];
$data['create_time'] = time();
$trainModel = new TrainModel();
$res = $trainModel->create($data);
if($res){
$this->success('培训信息提交成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误!');
}
}
}