IndexController.php 4.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;
/**
 * @title 首页
 */
class IndexController extends RestBaseController
{
    /**
     * @title 领导,员工首页
     * @description 接口说明
     * @author 开发者
     * @url /api/home/index/index
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     *
     * @return is_work:上班状态(0:下班,1:上班)
     * @return identity:身份(1:甲方员工,2:乙方员工,3:甲方领导,4:乙方领导,5:甲方总领导)
     * @return company_name:公司名称
     * @return service:企业拥有的服务@
     * @service id:服务id(1:日常巡检,2:消防月检,3:维修/改造,4:故障报修,5:培训/演习) name:服务名称 icon:图标路径
     * @return run_time:0 运行时间
     * @return project_name:项目名称
     * @return is_project:是否有项目(0:无,1:有)
     * @return is_finish:未完成数量(甲乙方员工有此字段)
     */
    public function index(){
        if($this->request->isGet()){
            $common = new CommonController();
            $res = $common->getIndexData();
            //获取未完成数量
            $user = $common->getUserIdentity();
            //如果是员工
            if($user['identity'] == config('site.a_staff') || $user['identity'] == config('site.b_staff')){
                $arr = $common->getInsList();
                $res['is_finish'] = $arr['is_finish'];
            }
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 总领导首页
     * @description 接口说明
     * @author 开发者
     * @url /api/home/index/chiefLeaderIndex
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     *
     * @return data: @
     * @data id:公司id company_name:甲方公司名称 company_name_head:甲方总公司名称 address:地区 run_time:运行时间 service:服务列表@
     * @service id:服务id(1:日常巡检,2:消防月检,3:维修/改造,4:故障报修,5:培训/演习) name:服务名称 icon:图标路径 english_name:英文名称
     * @return address: @
     * @address id:地区id(和公司id对应) address:地区
     */
    public function chiefLeaderIndex(){
        if($this->request->isGet()){
            $where = ['u_ls_id' => $this->userId];
            $field = 'id,company_name,company_name_head,address,logo';
            $common = new CommonController();
            $res = $common->getTotalCompany($where,$field);
            $city = [];
            $i = 0;
            foreach($res as &$value){
                $i+=0;
                $where = ['a_cid'=>$value['id']];
                $field = 'id,name,create_time';
                //查找企业拥有的服务
                $data['c_id'] = $value['id'];

                $rule = $common->getRule($data);
                $value['service'] = $rule;
                foreach($value['service'] as &$value1){
                    $value1['name'] = $value1['name'].'报表';
                }
                //查询企业拥有的项目
                $res1 = $common->getProject($where,$field);
                $value['run_time'] = 0;
                if($res1){
                    $value['run_time'] = $common->getRunTime($res1['create_time']);
                }
                $city[$i]['id'] = $value['id'];
                $city[$i]['address'] = $value['address'];
                $i++;
            }
            $arr['data'] = $res;
            $arr['address'] = $city;
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误!');
        }
    }

}