IndexController.php 8.8 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
     *
     * @param name:project_id type:int require:0 default: other desc:项目id(员工传字段)
     *
     * @return is_work:上班状态(1:上班,2:下班)
     * @return identity:身份(1:甲方员工,2:乙方员工,3:甲方领导,4:乙方领导,5:甲方总领导)
     * @return company_name:公司名称
     * @return logo:公司logo
     * @return service:企业拥有的服务@
     * @service id:服务id(1:巡检,2:月检,3:改造,4:报修跟进,5:培训,6:演习,7:年检,100:报修,101:消息审批) name:服务名称 icon:图标路径
     * @return run_time:0 运行时间
     * @return is_finish:未检修数量(甲乙方员工有此字段)
     * @return tips:提示语
     */
    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')){
                $project_id = $this->request->get('project_id');

                $rule = config('site.project_id');
                $validate = new Validate($rule['rule'],$rule['msg']);
                if (!$validate->check(['project_id'=>$project_id])) {
                    $this->error($validate->getError());
                }

                $arr = $common->getInsList($project_id);
                $res['is_finish'] = $arr['is_finish'];
            }
            $res['tips'] = config('site.tips');
            $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:甲方公司名称 logo:公司logo company_name_head:甲方总公司名称 address:地区 run_time:运行时间 service:服务列表@
     * @service id:服务id(1:日常巡检,2:月检,3:改造,4:报修,5:培训,6:演习,7:年检,101:消息审批) name:服务名称 icon:图标路径 english_name:英文名称
     * @return address: @
     * @address id:地区id(和公司id对应) address:地区
     * @return tips:提示语
     */
    public function chiefLeaderIndex(){
        if($this->request->isGet()){
            $where = ['u_ls_id' => $this->userId];
            $field = 'id,company_name,company_name_head,address,logo,create_time';
            $common = new CommonController();
            $res = $common->getTotalCompany($where,$field);

            $host = config('site.host');
            $city = [];
            $i = 0;
            foreach($res as &$value){
                $i+=0;
                //查找企业拥有的服务
                $data['c_id'] = $value['id'];
                $rule = $common->getRule($data);
                $value['service'] = $rule;
                foreach($value['service'] as &$value1){
                    if($value1['id'] != 101 && $value1['id'] != 102){
                        $value1['name'] = $value1['name'].'报表';
                        if($value1['id'] == 1){
                            $value1['name'] = '日检/巡检报表';
                        }
                        if($value['id'] == 4){
                            $value['name'] = '维修报表';
                        }
                    }
                }
                $value['logo'] = $host.'/upload/'.$value['logo'];
                //公司运行时间
                $value['run_time'] = $common->getRunTime($value['create_time']);

                $city[$i]['id'] = $value['id'];
                $city[$i]['address'] = $value['address'];
                $i++;
            }
            $arr['data'] = $res;
            $arr['address'] = $city;
            $arr['tips'] = config('site.tips');
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 获取视频第一帧
     * @description 接口说明
     * @author 开发者
     * @url /api/home/index/getVideoCover
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     *
     * @param name:mp4_src type:string require:1 default: other desc:MP4文件路径
     *
     * @return src:视频第一帧图片路径
     */
    public function getVideoCover() {
        if($this->request->isGet()){
            $mp4_src = $this->request->get('mp4_src');

            $rule = config('site.mp4_src');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['mp4_src'=>$mp4_src])) {
                $this->error($validate->getError());
            }

            //自己服务器
//            $ffm_peg = FFMpeg::create([
//                'ffmpeg.binaries'  => '/usr/bin/ffmpeg',
//                'ffprobe.binaries' => '/usr/bin/ffprobe'
//            ]);
//            $host = config('site.host');
//            $time = time();
//            $src = str_replace($host,'',$mp4_src);
//            //打开文件路径
//            $video = $ffm_peg->open(ROOT_PATH.'public/'.$src);
//            //截取大小
//            $video->filters()->resize(new \FFMpeg\Coordinate\Dimension(320, 240))->synchronize();
//            //第一帧图片
//            $video->frame(TimeCode::fromSeconds(1))->save(ROOT_PATH.'public/pegImg/'.$time.'.jpg');
//            $src_jpg = $host.'/pegImg/'.$time.'.jpg';

            //七牛云服务器

            $this->success('成功',['src'=>$mp4_src.'?vframe/jpg/offset/1']);
        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 极光推送
     * @description 接口说明
     * @author 开发者
     * @url /api/home/index/jpush
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     * @param name:registration_id type:string require:1 default: other desc:registration_id
     *
     */
    public function jpush(){
        if($this->request->isGet()){
            $registration_id = $this->request->get('registration_id');
            $common = new CommonController();
            $alias = [$registration_id];
            $content = '您有一条消息,请注意查收';
            $title = '推送消息';
            $extras = [];
            $res = $common->pushMessage($alias,$content,$title,$extras);
            $this->success('成功',$registration_id);

        }else{
            $this->error('请求方式错误!');
        }
    }

    /**
     * @title 员工项目列表
     * @description 接口说明
     * @author 开发者
     * @url /api/home/index/projectList
     * @method GET
     *
     * @header name:token require:1 default: desc:header
     *
     * @return project_id:项目id
     * @return project_name:项目名称
     */
    public function projectList(){
        if($this->request->isGet()){
            $common = new CommonController();
            //获取未完成数量
            $user = $common->getUserIdentity();
            //如果是员工
            $res = [];
            $uid = ','.$this->userId.',';
            if(isset($user['identity'])){
                if($user['identity'] == config('site.a_staff')){
                    //甲方
                    $res = $common->getProjectByUid(['a_sid'=>['like','%'.$uid.'%']]);

                }else if($user['identity'] == config('site.b_staff')){
                    //乙方
                    $res = $common->getProjectByUid(['b_sid'=>['like','%'.$uid.'%']]);
                }
                $this->success('成功',$res);
            }
            $this->error('请联系管理员分配公司!');
        }else{
            $this->error('请求方式错误!');
        }
    }
}