| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 2021-04-25
- * Time: 09:53
- */
- namespace Modules\Camera\Http\Controllers\Api;
- use App\Enum\ApiEnum;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Config;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Log;
- use Modules\Camera\Entities\CameraList;
- use Modules\Camera\Enum\CameraEnum;
- use Modules\Camera\Services\CameraServices;
- use Modules\Mine\Entities\MineList;
- use Modules\Mine\Entities\MineListExt;
- use DB;
- use OSS\OssClient;
- class CameraApiController extends BaseController
- {
- //通过摄像头类型获取摄像头
- public function getCameraByType(){
- $mine_code = Input::get('mine_code', '');
- $camera_type = Input::get('camera_type', '');
- if (!$mine_code || !$camera_type) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
- if (!$mine) {
- $result['status'] = false;
- $result['msg'] = '矿区名称不存在';
- return $result;
- }
- $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('deleted_at',null)->get();
- $mine_array = [];
- foreach($mine_list as $k=>$v){
- $mine_array[] = $v->id;
- }
- $query = CameraList::where('is_show', CameraEnum::IS_SHOW_YES)->where('deleted_at',null)->whereIn('mine_id',$mine_array)->where('camera_type',$camera_type)->orderBy('sort', 'desc')->get();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = '矿区下没有摄像头';
- return $result;
- }
- $result = [];
- foreach($query as $k=>$v){
- $result[$k]['id'] = $v->id;
- $result[$k]['mine_id'] = $v->mine_id;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- $result[$k]['playback'] = $v->playback;
- }
- return self::successResponse($result);
- }
- //宁煤摄像头统计
- public function getTotalNingmei(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- $mine_ningmei = [];//宁煤集团所有区域
- foreach($mine_all as $k=>$v){
- if(explode('|',$v->degree)[0] == $ningmei[0]->id){
- $mine_ningmei[] = $v->id;
- }
- }
- //宁煤在离线数量
- $data[0]['title'] = '宁煤公司';
- $data[0]['mine_code'] = $ningmei[0]->slug;
- $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
- $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
- $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
- $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
- foreach($mine_list as $k => $v){
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
- $mine_use[] = $value->id;
- }
- }
- }
- $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
- $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
- if($total == 0){
- $rate = "0%";
- }else{
- $rate = round($total_online / $total * 100,2)."%";
- }
- if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
- $res['title'] = $v->title;
- $res['mine_code'] = $v->slug."_jituan";
- $res['total'] = $total;
- $res['total_online'] = $total_online;
- $res['total_offline'] = $total - $total_online;
- $res['rate'] = $rate;
- }else{
- array_push($data,[
- 'title'=>$v->title,
- 'mine_code'=>$v->slug."_jituan",
- 'total'=>$total,
- 'total_online'=>$total_online,
- 'total_offline'=>$total - $total_online,
- 'rate'=>$rate
- ]);
- }
- }
- if(isset($res)){
- array_push($data,[
- 'title'=>$res['title'],
- 'mine_code'=>$res['mine_code'],
- 'total'=>$res['total'],
- 'total_online'=>$res['total_online'],
- 'total_offline'=>$res['total_offline'],
- 'rate'=>$res['rate']
- ]);
- }
- return self::successResponse($data);
- }
- //宁煤不在线摄像头列表
- public function offlineList(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- $mine_ningmei = [];//宁煤集团所有区域
- foreach($mine_all as $k=>$v){
- if(explode('|',$v->degree)[0] == $ningmei[0]->id){
- $mine_ningmei[] = $v->id;
- }
- }
- if(count(explode('_',$mine_code)) > 1){
- $mine_code = explode('_',$mine_code)[0];
- }
- $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
- //如果传参是宁煤显示全部
- if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
- //宁煤在离线数量
- $offline_list = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_ningmei)->where('camera_status','!=',1)->where('deleted_at',null)->get();
- return self::successResponse($offline_list);
- }
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
- $total_offline = [];
- foreach($mine_list as $k => $v){
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
- $mine_use[] = $value->id;
- }
- }
- }
- $total_offline = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status','!=',1)->where('deleted_at',null)->get();
- }
- return self::successResponse($total_offline);
- }
- //宁煤高风险摄像头
- public function getRiskNingmei(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- //宁煤集团下级单位
- $mine = DB::table('mine_list')
- ->where('parent_id',$ningmei[0]->id)
- ->where('slug','like','%'.$mine_code.'%')
- ->where('deleted_at',null)
- ->get();
- //子区域树形列表
- $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
- $risk_id = null;
- if(count($child_list)>0){
- $risk_id = $this->mineTree($child_list);
- }
- $mine_list = [];
- if($risk_id != null){
- $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
- if(count($risk) > 0){
- //有子区域
- $mine_list = $this->riskTree($risk,[]);
- }else{
- //没有子区域
- $mine_list[] = $risk_id;
- }
- }
- $camera_list = DB::table('camera_list')
- ->select('camera_list.*','mine_list.title')
- ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
- ->where('camera_list.deleted_at',null)
- ->whereIn('camera_list.mine_id',$mine_list)
- ->orderBy('sort', 'desc')->get();
- $result = [];
- foreach($camera_list as $k=>$v){
- $result[$k]['parent_id'] = $ningmei[0]->id;
- $result[$k]['camera_id'] = $v->id;
- $result[$k]['mine_name'] = $v->title;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- $result[$k]['base64'] = $v->base64;
- }
- return self::successResponse($result);
- }
- public function mineTree($regions)
- {
- $arr = null;
- foreach ($regions as $key => $value) {
- $risk = explode('高风险作业',$value->title);
- if (count($risk)>1){
- return $value->id;
- }
- $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
- if (count($mine_child) > 0) {
- $arr = self::mineTree($mine_child, $value->id);
- if($arr != null){
- return $arr;
- }
- }
- }
- return $arr;
- }
- public function riskTree($regions,$risk_list)
- {
- foreach ($regions as $key => $value) {
- $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
- if (count($risk_child) > 0) {
- $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
- }else{
- $risk_list[] = $value->id;
- }
- }
- return $risk_list;
- }
- //高风险区域摄像头
- public function getCameraByMinecode(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
- if (!$mine) {
- $result['status'] = false;
- $result['msg'] = '矿区名称不存在';
- return $result;
- }
- $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('title','like','%高风险%')->where('deleted_at',null)->get();
- $mine_array = [];
- foreach($mine_list as $k=>$v){
- $mine_child = DB::table('mine_list')->where('degree', 'like','%' . $v->id . '%')->where('deleted_at',null)->get();
- if(count($mine_child)>0){
- for($i=0;$i<count($mine_child);$i++){
- $mine_array[] = $mine_child[$i]->id;
- }
- }
- }
- $query = DB::table('camera_list')
- ->select('camera_list.*','mine_list.title')
- ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
- ->where('camera_list.deleted_at',null)
- ->whereIn('camera_list.mine_id',$mine_array)
- ->orderBy('sort', 'desc')->get();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = '矿区下没有摄像头';
- return $result;
- }
- $result = [];
- foreach($query as $k=>$v){
- $result[$k]['parent_id'] = $mine->id;
- $result[$k]['camera_id'] = $v->id;
- $result[$k]['mine_name'] = $v->title;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取摄像头列表
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getCamerasList()
- {
- $parent_id = Input::get('parent_id', '');
- $mine_id = Input::get('mine_id', '');
- $camera_type = Input::get('camera_type', CameraEnum::CAMERA_TYPE_ALL);
- $surface_id = Input::get('surface_id', '');
- if (!$parent_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!in_array($camera_type, [CameraEnum::CAMERA_TYPE_NORMAL, CameraEnum::CAMERA_TYPE_ALL]) && !$surface_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- // $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- // if ($is_hak) {
- // $result = CameraServices::getHaiKangCamera($parent_id, $mine_id, $camera_type);
- // } else {
- $result = CameraServices::getCameraListByMineId($mine_id, $camera_type, $parent_id, $surface_id);
- // }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取摄像头播放地址
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getCamerasUrl()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- //天地伟业
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- //宁煤集团
- }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
- $result = CameraServices::getHkHls($camera_id,$parent_id);
- }
- //信息技术中心测试ws协议
- // elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
- // $result = CameraServices::getHkWs($camera_id,$parent_id);
- //
- // }
- //海康切片逻辑
- else{
- $result = CameraServices::downloadCameraFiles($parent_id, $camera_id);
- }
- } else {
- //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
- $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
- // if(!$cover_picture){
- //ffmpeg拉流获取首帧图片
- // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
- // }else{
- // $result = CameraServices::getCameraUrlByCameraId($camera_id);
- $result = CameraServices::getRtspYingPan($camera_id);
- // }
- }
- return self::successResponse($result);
- }
- public function getCamerasLanUrl()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- //天地伟业
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- //宁煤集团
- }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
- $result = CameraServices::getHkHls($camera_id,$parent_id);
- }else{
- $result = CameraServices::getLanCameraUrl($parent_id, $camera_id);
- }
- } else {
- //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
- $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
- // if(!$cover_picture){
- //ffmpeg拉流获取首帧图片
- // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
- // }else{
- $result = CameraServices::getCameraUrlByCameraId($camera_id);
- // }
- }
- return self::successResponse($result);
- }
- //获取海康rtsp流
- public function getHikRtsp(){
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak == 1 && !$camera_url) {
- $result = CameraServices::getHkRtsp($camera_id,$parent_id);
- return self::successResponse($result);
- }else{
- return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
- }
- }
- //获取海康rtmp流
- public function getHikRtmp(){
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak == 1 && !$camera_url) {
- $result = CameraServices::getHkRtmp($camera_id,$parent_id);
- return self::successResponse($result);
- }else{
- return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
- }
- }
- //海康摄像头easy_drawin方式获取url
- public function getCamerasRtsp()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- //天地伟业使用easy_drawin获取rtsp
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- }else{
- //海康使用easy_drawin获取rtsp
- $result = CameraServices::getRtspHaiKang($camera_id, $parent_id);
- }
- } else {
- //硬盘录像机使用easy_drawin获取rtsp
- $result = CameraServices::getRtspYingPan($camera_id);
- }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 停止摄像头推流
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function stopCamerasStream()
- {
- $camera_id = Input::get('camera_id', '');
- $result = CameraServices::stopCameraStream();
- return self::successResponse($result);
- }
- //回放列表
- public function getPlaybackList(){
- $camera_id = Input::get('camera_id', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $playback = DB::table('playback')->where('camera_id',$query->id)->where('deleted_at',null)->get();
- if(count($playback)>0){
- for($i=0;$i<count($playback);$i++){
- $result['data'][$i]['title'] = $playback[$i]->title;
- $result['data'][$i]['start_time'] = $playback[$i]->start_time;
- $result['data'][$i]['end_time'] = $playback[$i]->end_time;
- $result['data'][$i]['camera_id'] = $playback[$i]->camera_id;
- }
- }else{
- $result['data'] = null;
- }
- return $result;
- }
- //回放URL
- public function getPlaybackUrl(){
- $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
- $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
- $camera_id = Input::get('camera_id', '');
- $start_time = Input::get('start_time', '');
- $end_time = Input::get('end_time', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id || !$start_time || !$end_time) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $degree = MineList::where('id', $query->mine_id)->value('degree');
- $degree = explode('|', $degree)[0];
- $mine_res = DB::table('mine_list')->where('id',$degree)->get();
- //判断摄像头是否是洗选中心的时间+34分钟
- if($mine_res[0]->slug == 'XiXuanZhongXin'){
- $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
- $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
- }
- $str = '.000+';
- $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
- $start_time = explode('+',$start_time);
- $start_time = $start_time[0].$str.$start_time[1];
- $end_time = date('c', strtotime($end_time));
- $end_time = explode('+',$end_time);
- $end_time = $end_time[0].$str.$end_time[1];
- //判断是否在配置文件里,在的不用走ffmpeg
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
- $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
- return self::successResponse($result);
- }else{
- $result = CameraServices::getPlaybackRtmp($camera_id,$start_time,$end_time,$time);
- return self::successResponse($result);
- }
- }
- //easydrawin回放URL
- public function getPlaybackUrlByEasy(){
- $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
- $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
- $camera_id = Input::get('camera_id', '');
- $start_time = Input::get('start_time', '');
- $end_time = Input::get('end_time', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id || !$start_time || !$end_time) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $degree = MineList::where('id', $query->mine_id)->value('degree');
- $degree = explode('|', $degree)[0];
- $mine_res = DB::table('mine_list')->where('id',$degree)->get();
- //判断摄像头是否是洗选中心的时间+34分钟
- if($mine_res[0]->slug == 'XiXuanZhongXin'){
- $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
- $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
- }
- $str = '.000+';
- $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
- $start_time = explode('+',$start_time);
- $start_time = $start_time[0].$str.$start_time[1];
- $end_time = date('c', strtotime($end_time));
- $end_time = explode('+',$end_time);
- $end_time = $end_time[0].$str.$end_time[1];
- //判断是否在配置文件里,在的不用走ffmpeg
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
- $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
- return self::successResponse($result);
- }else{
- $result = CameraServices::getPlaybackByEasy($camera_id,$start_time,$end_time,$time);
- return self::successResponse($result);
- }
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取编码设备信息
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getTranscodeInfo()
- {
- $parent_id = Input::get('parent_id', '');
- if (!$parent_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = CameraServices::getHaiKangTransCode($parent_id);
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取大南湖摄像头列表
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getSouthLakeCamera()
- {
- $result = CameraServices::getLeChangeCamera();
- return self::successResponse($result);
- }
- public function pictureBase64(){
- $base64 = Input::get('base64', '');
- $camera_id = Input::get('camera_id', '');
- if (!$base64 || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $data['base64'] = $base64;
- DB::table('camera_list')->where('id',$camera_id)->update($data);
- return self::successResponse();
- }
- public function test(){
- // header("Access-Control-Allow-Origin: *");
- $data = DB::table('goods')->get();
- return $data;
- }
- public function testadd(){
- // header("Access-Control-Allow-Origin: *");
- $res['good_name'] = Input::get('good_name', '');
- $res['good_url'] = 'images/1.jpg';
- $res['good_count'] = Input::get('good_count', '');
- $res['good_price'] = Input::get('good_price', '');
- $res['good_state'] = Input::get('good_state', '');
- DB::table('goods')->insert($res);
- return true;
- }
- public function testdel(){
- // header("Access-Control-Allow-Origin: *");
- DB::table('goods')->where('id',Input::get('id',''))->delete();
- return true;
- }
- public function testupdate(){
- // header("Access-Control-Allow-Origin: *");
- $res['good_name'] = Input::get('good_name', '');
- $res['good_url'] = 'images/1.jpg';
- $res['good_count'] = Input::get('good_count', '');
- $res['good_price'] = Input::get('good_price', '');
- $res['good_state'] = Input::get('good_state', '');
- DB::table('goods')->where('id',Input::get('id',''))->update($res);
- return true;
- }
- //值班信息
- public function dutyInformation(){
- $today = date('Y-m-d');
- $tomorrow = date("Y-m-d",strtotime("+1 day"));
- $result['today_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'zzb'");
- $result['today_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'fz'");
- $result['tomorrow_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'zzb'");
- $result['tomorrow_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'fz'");
- return self::successResponse($result);
- }
- //分类列表
- public function typeList(){
- $result = $result = DB::connection('etl_zaoquan')->select("select type from news_column_list group by type");
- if(count($result) > 0){
- for($i=0;$i<count($result);$i++){
- if($result[$i]->type == 'aqsc'){
- $result[$i]->name = '安全生产';
- }
- if($result[$i]->type == 'mkxw'){
- $result[$i]->name = '煤矿新闻';
- }
- if($result[$i]->type == 'zwbg'){
- $result[$i]->name = '政务办公';
- }
- if($result[$i]->type == 'djgz'){
- $result[$i]->name = '党建工作';
- }
- if($result[$i]->type == 'qygl'){
- $result[$i]->name = '企业管理';
- }
- if($result[$i]->type == 'jdgl'){
- $result[$i]->name = '机电管理';
- }
- if($result[$i]->type == 'scjsgl'){
- $result[$i]->name = '生产技术管理';
- }
- if($result[$i]->type == 'jjjc'){
- $result[$i]->name = '纪检监察';
- }
- if($result[$i]->type == 'zhzl'){
- $result[$i]->name = '综合治理';
- }
- if($result[$i]->type == 'jypx'){
- $result[$i]->name = '教育培训';
- }
- if($result[$i]->type == 'kwgk'){
- $result[$i]->name = '矿务公开';
- }
- }
- }
- return self::successResponse($result);
- }
- //文章列表
- public function articleList(Request $request){
- $params = $request->all();
- if (!isset($params['page_size'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['page_num'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['type'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $offset = $params['page_size'] * ($params['page_num'] - 1);
- $result = DB::connection('etl_zaoquan')->select("select * from news_column_list where type = '".$params['type']."' order by create_time desc limit ".$params['page_size']." offset ".$offset);
- $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';
- if(count($result) > 0){
- for($i=0;$i<count($result);$i++){
- //替换title_image
- $old_title_image = $result[$i]->title_image;
- $old_title_image_array = explode('/',$old_title_image);
- $old_img_path = $old_title_image_array[count($old_title_image_array)-1];
- $new_img_path_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".$old_img_path."'");
- if(count($new_img_path_list) > 0){
- $result[$i]->main_img = $new_img_path_list[0]->new_name;
- }
- unset($result[$i]->title_image);
- $result[$i]->created_at = $result[$i]->create_time;
- unset($result[$i]->create_time);
- //替换text
- preg_match_all($pattern, $result[$i]->text, $matches);
- foreach ($matches[2] as $index => $oldSrc) {
- $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
- if(count($news_img_list) > 0){
- $newSrc = $news_img_list[0]->new_name;
- $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
- }
- }
- }
- }
- return self::successResponse($result);
- }
- //文章图片上传至阿里云
- public function ossUrl(Request $request){
- $params = $request->all();
- if (!isset($params['url'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = $this->downloadFile($params['url']);
- return self::successResponse($result);
- }
- //下载文件
- public function downloadFile($file_path)
- {
- $rename = mt_rand(1111111,9999999);
- if (!$file_path) {
- return false;
- }
- set_time_limit(0);
- $ch = curl_init($file_path);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
- $rawdata = curl_exec ($ch);
- curl_close ($ch);
- // 使用中文文件名需要转码
- $fp = fopen(public_path() . '/filedownload/' . $rename.'.jpg', 'w');
- fwrite($fp, $rawdata);
- fclose($fp);
- $file_name = $rename;
- //上传文件
- $file_oss_path = $this->uploadFile($file_name);
- return $file_oss_path;
- }
- //上传文件
- public function uploadFile($file_name)
- {
- try{
- $oss = new OssClient(
- Config::get('filesystems.disks.oss_view.access_key'),
- Config::get('filesystems.disks.oss_view.secret_key'),
- Config::get('filesystems.disks.oss_view.endpoint')
- );
- $file_path = public_path() . '/filedownload/' . $file_name.'.jpg';
- $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.'.jpeg', $file_path);
- } catch(\OssException $e) {
- printf(__FUNCTION__ . ": FAILED\n");
- printf($e->getMessage() . "\n");
- return;
- }
- if (isset($res['info']['url']) && $res['info']['url']) {
- unlink($file_path);
- return urldecode($res['info']['url']);
- } else {
- return false;
- }
- }
- }
|