TrainController.php 2.2 KB
<?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('请求方式错误!');
        }
    }
}