InformationController.php 6.4 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\CheckModel;

/**
 * @title 消息审批
 */
class InformationController extends RestBaseController
{

    /**
     * @title 甲方领导消息审批列表
     * @description 接口说明
     * @author 开发者
     * @url /api/home/information/informationList
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     * @param name:page type:inter require:1 default: other desc:分页页码
     * @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
     *
     * @return data:列表@
     * @data id:列表id project_id:项目id project_name:项目名称 ins_m_time:月检时间 user_group:项目组
     * @return type:工作类型 (1:月检,2:维修改造,3:培训演习)
     */
    public function informationList(){
        if($this->request->isGet()){
            $page = $this->request->get('page');
            $type = $this->request->get('type');
            $rule = config('site.type');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['type'=>$type,'page'=>$page])) {
                $this->error($validate->getError());
            }
            $common = new CommonController();
            $user = $common->getUserIdentity();
            //如果不是甲方领导,则没有权限操作
            if($user['identity'] != config('site.a_leader')){
                $this->error('无权操作');
            }
            //查看甲方领导的对应的乙方
            if($type == 1){
                //月检
                $b_company_id = $common->getCompany(['pid'=>$user['company_id']],'id');
                $res['data'] = $common->getCheckByCompanyBId($b_company_id['id'],$page);
            }else if($type == 2){
                //维修改造
            }else{
                //培训演习
                $b_company_id = $common->getCompany(['pid'=>$user['company_id']],'id');
                $res['data'] = $common->getTrainByCompanyBId($b_company_id['id'],$page);
            }
            //查找乙方项目组下的乙方员工
            foreach($res['data'] as &$value){
                $value['user_group'] = $common->getUserByProjectId($value['project_id'],'id,b_sid');
            }
            //工作类型
            $res['type'] = $type;
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 甲方领导确认申请
     * @description 接口说明
     * @author 开发者
     * @url /api/home/information/confirm
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     * @param name:id type:inter require:1 default: other desc:列表id
     * @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
     */
    public function confirm(){
        if($this->request->isGet()){
            $id = $this->request->get('id');
            $type = $this->request->get('type');
            $rule = config('site.confirm');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['type'=>$type,'id'=>$id])) {
                $this->error($validate->getError());
            }
            $common = new CommonController();
            $user = $common->getUserIdentity();
            //如果不是甲方领导,则没有权限操作
            if($user['identity'] != config('site.a_leader')){
                $this->error('无权操作');
            }
            if($type == 1){
                //月检
                $checkModel = new CheckModel();
                $res = $checkModel->where(['id'=>$id,'status'=>0])->update(['a_leader'=>$this->userId,'status'=>2,'l_confirm_time'=>time()]);
            }else if($type == 2){
                //维修改造
            }else{
                //培新演习

            }
            if($res){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 甲方领导驳回申请
     * @description 接口说明
     * @author 开发者
     * @url /api/home/information/reject
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     * @param name:id type:inter require:1 default: other desc:列表id
     * @param name:type type:inter require:1 default: other desc:工作类型(1:月检,2:维修改造,3:培训演习)
     */
    public function reject(){
        if($this->request->isGet()){
            $id = $this->request->get('id');
            $type = $this->request->get('type');
            $rule = config('site.confirm');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['type'=>$type,'id'=>$id])) {
                $this->error($validate->getError());
            }
            $common = new CommonController();
            $user = $common->getUserIdentity();
            //如果不是甲方领导,则没有权限操作
            if($user['identity'] != config('site.a_leader')){
                $this->error('无权操作');
            }
            if($type == 1){
                //月检
                $checkModel = new CheckModel();
                $data = ['a_leader'=>$this->userId,'status'=>1,'reject_time'=>time()];
                $res = $checkModel->where(['id'=>$id,'status'=>0])->update($data);
            }else if($type == 2){
                //维修改造
            }else{
                //培新演习
            }
            if($res){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('请求方式错误!');
        }
    }

}