CameraApiController.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 2021-04-25
  6. * Time: 09:53
  7. */
  8. namespace Modules\Camera\Http\Controllers\Api;
  9. use App\Enum\ApiEnum;
  10. use App\Http\Controllers\Api\BaseController;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\Config;
  13. use Illuminate\Support\Facades\Input;
  14. use Illuminate\Support\Facades\Log;
  15. use Modules\Camera\Entities\CameraList;
  16. use Modules\Camera\Enum\CameraEnum;
  17. use Modules\Camera\Services\CameraServices;
  18. use Modules\Mine\Entities\MineList;
  19. use Modules\Mine\Entities\MineListExt;
  20. use DB;
  21. use OSS\OssClient;
  22. class CameraApiController extends BaseController
  23. {
  24. //通过摄像头类型获取摄像头
  25. public function getCameraByType(){
  26. $mine_code = Input::get('mine_code', '');
  27. $camera_type = Input::get('camera_type', '');
  28. if (!$mine_code || !$camera_type) {
  29. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  30. }
  31. $result['status'] = true;
  32. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  33. $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
  34. if (!$mine) {
  35. $result['status'] = false;
  36. $result['msg'] = '矿区名称不存在';
  37. return $result;
  38. }
  39. $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('deleted_at',null)->get();
  40. $mine_array = [];
  41. foreach($mine_list as $k=>$v){
  42. $mine_array[] = $v->id;
  43. }
  44. $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();
  45. if (!$query) {
  46. $result['status'] = false;
  47. $result['msg'] = '矿区下没有摄像头';
  48. return $result;
  49. }
  50. $result = [];
  51. foreach($query as $k=>$v){
  52. $result[$k]['id'] = $v->id;
  53. $result[$k]['mine_id'] = $v->mine_id;
  54. $result[$k]['camera_name'] = $v->camera_name;
  55. $result[$k]['cover_picture'] = $v->cover_picture;
  56. $result[$k]['camera_status'] = $v->camera_status;
  57. $result[$k]['playback'] = $v->playback;
  58. }
  59. return self::successResponse($result);
  60. }
  61. //宁煤摄像头统计
  62. public function getTotalNingmei(){
  63. $result['status'] = true;
  64. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  65. //宁煤集团
  66. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  67. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  68. $mine_ningmei = [];//宁煤集团所有区域
  69. foreach($mine_all as $k=>$v){
  70. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  71. $mine_ningmei[] = $v->id;
  72. }
  73. }
  74. //宁煤在离线数量
  75. $data[0]['title'] = '宁煤公司';
  76. $data[0]['mine_code'] = $ningmei[0]->slug;
  77. $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  78. $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  79. $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
  80. $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
  81. //宁煤下各矿在离线数量
  82. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  83. foreach($mine_list as $k => $v){
  84. $mine_use = [];//宁煤下每个矿所有区域
  85. foreach($mine_all as $key=>$value){
  86. if(count(explode('|',$value->degree)) > 1){
  87. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  88. $mine_use[] = $value->id;
  89. }
  90. }
  91. }
  92. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  93. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  94. if($total == 0){
  95. $rate = "0%";
  96. }else{
  97. $rate = round($total_online / $total * 100,2)."%";
  98. }
  99. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  100. $res['title'] = $v->title;
  101. $res['mine_code'] = $v->slug."_jituan";
  102. $res['total'] = $total;
  103. $res['total_online'] = $total_online;
  104. $res['total_offline'] = $total - $total_online;
  105. $res['rate'] = $rate;
  106. }else{
  107. array_push($data,[
  108. 'title'=>$v->title,
  109. 'mine_code'=>$v->slug."_jituan",
  110. 'total'=>$total,
  111. 'total_online'=>$total_online,
  112. 'total_offline'=>$total - $total_online,
  113. 'rate'=>$rate
  114. ]);
  115. }
  116. }
  117. if(isset($res)){
  118. array_push($data,[
  119. 'title'=>$res['title'],
  120. 'mine_code'=>$res['mine_code'],
  121. 'total'=>$res['total'],
  122. 'total_online'=>$res['total_online'],
  123. 'total_offline'=>$res['total_offline'],
  124. 'rate'=>$res['rate']
  125. ]);
  126. }
  127. return self::successResponse($data);
  128. }
  129. //宁煤不在线摄像头列表
  130. public function offlineList(){
  131. $mine_code = Input::get('mine_code', '');
  132. if (!$mine_code) {
  133. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  134. }
  135. $result['status'] = true;
  136. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  137. //宁煤集团
  138. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  139. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  140. $mine_ningmei = [];//宁煤集团所有区域
  141. foreach($mine_all as $k=>$v){
  142. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  143. $mine_ningmei[] = $v->id;
  144. }
  145. }
  146. if(count(explode('_',$mine_code)) > 1){
  147. $mine_code = explode('_',$mine_code)[0];
  148. }
  149. $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  150. //如果传参是宁煤显示全部
  151. if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
  152. //宁煤在离线数量
  153. $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();
  154. return self::successResponse($offline_list);
  155. }
  156. //宁煤下各矿在离线数量
  157. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  158. $total_offline = [];
  159. foreach($mine_list as $k => $v){
  160. $mine_use = [];//宁煤下每个矿所有区域
  161. foreach($mine_all as $key=>$value){
  162. if(count(explode('|',$value->degree)) > 1){
  163. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  164. $mine_use[] = $value->id;
  165. }
  166. }
  167. }
  168. $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();
  169. }
  170. return self::successResponse($total_offline);
  171. }
  172. //宁煤高风险摄像头
  173. public function getRiskNingmei(){
  174. $mine_code = Input::get('mine_code', '');
  175. if (!$mine_code) {
  176. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  177. }
  178. $result['status'] = true;
  179. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  180. //宁煤集团
  181. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  182. //宁煤集团下级单位
  183. $mine = DB::table('mine_list')
  184. ->where('parent_id',$ningmei[0]->id)
  185. ->where('slug','like','%'.$mine_code.'%')
  186. ->where('deleted_at',null)
  187. ->get();
  188. //子区域树形列表
  189. $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
  190. $risk_id = null;
  191. if(count($child_list)>0){
  192. $risk_id = $this->mineTree($child_list);
  193. }
  194. $mine_list = [];
  195. if($risk_id != null){
  196. $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
  197. if(count($risk) > 0){
  198. //有子区域
  199. $mine_list = $this->riskTree($risk,[]);
  200. }else{
  201. //没有子区域
  202. $mine_list[] = $risk_id;
  203. }
  204. }
  205. $camera_list = DB::table('camera_list')
  206. ->select('camera_list.*','mine_list.title')
  207. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  208. ->where('camera_list.deleted_at',null)
  209. ->whereIn('camera_list.mine_id',$mine_list)
  210. ->orderBy('sort', 'desc')->get();
  211. $result = [];
  212. foreach($camera_list as $k=>$v){
  213. $result[$k]['parent_id'] = $ningmei[0]->id;
  214. $result[$k]['camera_id'] = $v->id;
  215. $result[$k]['mine_name'] = $v->title;
  216. $result[$k]['camera_name'] = $v->camera_name;
  217. $result[$k]['cover_picture'] = $v->cover_picture;
  218. $result[$k]['camera_status'] = $v->camera_status;
  219. $result[$k]['base64'] = $v->base64;
  220. }
  221. return self::successResponse($result);
  222. }
  223. public function mineTree($regions)
  224. {
  225. $arr = null;
  226. foreach ($regions as $key => $value) {
  227. $risk = explode('高风险作业',$value->title);
  228. if (count($risk)>1){
  229. return $value->id;
  230. }
  231. $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  232. if (count($mine_child) > 0) {
  233. $arr = self::mineTree($mine_child, $value->id);
  234. if($arr != null){
  235. return $arr;
  236. }
  237. }
  238. }
  239. return $arr;
  240. }
  241. public function riskTree($regions,$risk_list)
  242. {
  243. foreach ($regions as $key => $value) {
  244. $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  245. if (count($risk_child) > 0) {
  246. $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
  247. }else{
  248. $risk_list[] = $value->id;
  249. }
  250. }
  251. return $risk_list;
  252. }
  253. //高风险区域摄像头
  254. public function getCameraByMinecode(){
  255. $mine_code = Input::get('mine_code', '');
  256. if (!$mine_code) {
  257. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  258. }
  259. $result['status'] = true;
  260. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  261. $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
  262. if (!$mine) {
  263. $result['status'] = false;
  264. $result['msg'] = '矿区名称不存在';
  265. return $result;
  266. }
  267. $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('title','like','%高风险%')->where('deleted_at',null)->get();
  268. $mine_array = [];
  269. foreach($mine_list as $k=>$v){
  270. $mine_child = DB::table('mine_list')->where('degree', 'like','%' . $v->id . '%')->where('deleted_at',null)->get();
  271. if(count($mine_child)>0){
  272. for($i=0;$i<count($mine_child);$i++){
  273. $mine_array[] = $mine_child[$i]->id;
  274. }
  275. }
  276. }
  277. $query = DB::table('camera_list')
  278. ->select('camera_list.*','mine_list.title')
  279. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  280. ->where('camera_list.deleted_at',null)
  281. ->whereIn('camera_list.mine_id',$mine_array)
  282. ->orderBy('sort', 'desc')->get();
  283. if (!$query) {
  284. $result['status'] = false;
  285. $result['msg'] = '矿区下没有摄像头';
  286. return $result;
  287. }
  288. $result = [];
  289. foreach($query as $k=>$v){
  290. $result[$k]['parent_id'] = $mine->id;
  291. $result[$k]['camera_id'] = $v->id;
  292. $result[$k]['mine_name'] = $v->title;
  293. $result[$k]['camera_name'] = $v->camera_name;
  294. $result[$k]['cover_picture'] = $v->cover_picture;
  295. $result[$k]['camera_status'] = $v->camera_status;
  296. }
  297. return self::successResponse($result);
  298. }
  299. /**
  300. * 作者: qiuzijian
  301. * 注释: 获取摄像头列表
  302. * @return \App\Http\Controllers\Api\JsonResponse
  303. */
  304. public function getCamerasList()
  305. {
  306. $parent_id = Input::get('parent_id', '');
  307. $mine_id = Input::get('mine_id', '');
  308. $camera_type = Input::get('camera_type', CameraEnum::CAMERA_TYPE_ALL);
  309. $surface_id = Input::get('surface_id', '');
  310. if (!$parent_id) {
  311. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  312. }
  313. if (!in_array($camera_type, [CameraEnum::CAMERA_TYPE_NORMAL, CameraEnum::CAMERA_TYPE_ALL]) && !$surface_id) {
  314. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  315. }
  316. //判断是否使用海康视频服务器
  317. // $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  318. // if ($is_hak) {
  319. // $result = CameraServices::getHaiKangCamera($parent_id, $mine_id, $camera_type);
  320. // } else {
  321. $result = CameraServices::getCameraListByMineId($mine_id, $camera_type, $parent_id, $surface_id);
  322. // }
  323. return self::successResponse($result);
  324. }
  325. /**
  326. * 作者: qiuzijian
  327. * 注释: 获取摄像头播放地址
  328. * @return \App\Http\Controllers\Api\JsonResponse
  329. */
  330. public function getCamerasUrl()
  331. {
  332. $parent_id = Input::get('parent_id', '');
  333. $camera_id = Input::get('camera_id', '');
  334. if (!$parent_id || !$camera_id) {
  335. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  336. }
  337. //判断摄像头来源是否为内网服务器
  338. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  339. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  340. $result = CameraServices::getIntranetCameraUrl($camera_id);
  341. return self::successResponse($result);
  342. }
  343. //判断是否使用海康视频服务器
  344. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  345. //判断是否生成摄像头请求链接
  346. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  347. if ($is_hak && !$camera_url) {
  348. //判断是否是mine配置文件的矿区
  349. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  350. //天地伟业
  351. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  352. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  353. //宁煤集团
  354. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  355. $result = CameraServices::getHkHls($camera_id,$parent_id);
  356. }
  357. //信息技术中心测试ws协议
  358. // elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
  359. // $result = CameraServices::getHkWs($camera_id,$parent_id);
  360. //
  361. // }
  362. //海康切片逻辑
  363. else{
  364. $result = CameraServices::downloadCameraFiles($parent_id, $camera_id);
  365. }
  366. } else {
  367. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  368. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  369. // if(!$cover_picture){
  370. //ffmpeg拉流获取首帧图片
  371. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  372. // }else{
  373. // $result = CameraServices::getCameraUrlByCameraId($camera_id);
  374. $result = CameraServices::getRtspYingPan($camera_id);
  375. // }
  376. }
  377. return self::successResponse($result);
  378. }
  379. public function getCamerasLanUrl()
  380. {
  381. $parent_id = Input::get('parent_id', '');
  382. $camera_id = Input::get('camera_id', '');
  383. if (!$parent_id || !$camera_id) {
  384. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  385. }
  386. //判断摄像头来源是否为内网服务器
  387. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  388. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  389. $result = CameraServices::getIntranetCameraUrl($camera_id);
  390. return self::successResponse($result);
  391. }
  392. //判断是否使用海康视频服务器
  393. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  394. //判断是否生成摄像头请求链接
  395. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  396. if ($is_hak && !$camera_url) {
  397. //判断是否是mine配置文件的矿区
  398. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  399. //天地伟业
  400. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  401. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  402. //宁煤集团
  403. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  404. $result = CameraServices::getHkHls($camera_id,$parent_id);
  405. }else{
  406. $result = CameraServices::getLanCameraUrl($parent_id, $camera_id);
  407. }
  408. } else {
  409. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  410. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  411. // if(!$cover_picture){
  412. //ffmpeg拉流获取首帧图片
  413. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  414. // }else{
  415. $result = CameraServices::getCameraUrlByCameraId($camera_id);
  416. // }
  417. }
  418. return self::successResponse($result);
  419. }
  420. //获取海康rtsp流
  421. public function getHikRtsp(){
  422. $parent_id = Input::get('parent_id', '');
  423. $camera_id = Input::get('camera_id', '');
  424. if (!$parent_id || !$camera_id) {
  425. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  426. }
  427. //判断是否使用海康视频服务器
  428. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  429. //判断是否生成摄像头请求链接
  430. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  431. if ($is_hak == 1 && !$camera_url) {
  432. $result = CameraServices::getHkRtsp($camera_id,$parent_id);
  433. return self::successResponse($result);
  434. }else{
  435. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  436. }
  437. }
  438. //获取海康rtmp流
  439. public function getHikRtmp(){
  440. $parent_id = Input::get('parent_id', '');
  441. $camera_id = Input::get('camera_id', '');
  442. if (!$parent_id || !$camera_id) {
  443. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  444. }
  445. //判断是否使用海康视频服务器
  446. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  447. //判断是否生成摄像头请求链接
  448. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  449. if ($is_hak == 1 && !$camera_url) {
  450. $result = CameraServices::getHkRtmp($camera_id,$parent_id);
  451. return self::successResponse($result);
  452. }else{
  453. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  454. }
  455. }
  456. //海康摄像头easy_drawin方式获取url
  457. public function getCamerasRtsp()
  458. {
  459. $parent_id = Input::get('parent_id', '');
  460. $camera_id = Input::get('camera_id', '');
  461. if (!$parent_id || !$camera_id) {
  462. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  463. }
  464. //判断摄像头来源是否为内网服务器
  465. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  466. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  467. $result = CameraServices::getIntranetCameraUrl($camera_id);
  468. return self::successResponse($result);
  469. }
  470. //判断是否使用海康视频服务器
  471. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  472. //判断是否生成摄像头请求链接
  473. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  474. if ($is_hak && !$camera_url) {
  475. //判断是否是mine配置文件的矿区
  476. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  477. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  478. //天地伟业使用easy_drawin获取rtsp
  479. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  480. }else{
  481. //海康使用easy_drawin获取rtsp
  482. $result = CameraServices::getRtspHaiKang($camera_id, $parent_id);
  483. }
  484. } else {
  485. //硬盘录像机使用easy_drawin获取rtsp
  486. $result = CameraServices::getRtspYingPan($camera_id);
  487. }
  488. return self::successResponse($result);
  489. }
  490. /**
  491. * 作者: qiuzijian
  492. * 注释: 停止摄像头推流
  493. * @return \App\Http\Controllers\Api\JsonResponse
  494. */
  495. public function stopCamerasStream()
  496. {
  497. $camera_id = Input::get('camera_id', '');
  498. $result = CameraServices::stopCameraStream();
  499. return self::successResponse($result);
  500. }
  501. //回放列表
  502. public function getPlaybackList(){
  503. $camera_id = Input::get('camera_id', '');
  504. $result['status'] = true;
  505. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  506. if (!$camera_id) {
  507. $result['status'] = false;
  508. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  509. return $result;
  510. }
  511. $query = CameraList::where('id', $camera_id)->first();
  512. if (!$query) {
  513. $result['status'] = false;
  514. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  515. return $result;
  516. }
  517. if($query->playback == 0){
  518. $result['status'] = false;
  519. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  520. return $result;
  521. }
  522. $playback = DB::table('playback')->where('camera_id',$query->id)->where('deleted_at',null)->get();
  523. if(count($playback)>0){
  524. for($i=0;$i<count($playback);$i++){
  525. $result['data'][$i]['title'] = $playback[$i]->title;
  526. $result['data'][$i]['start_time'] = $playback[$i]->start_time;
  527. $result['data'][$i]['end_time'] = $playback[$i]->end_time;
  528. $result['data'][$i]['camera_id'] = $playback[$i]->camera_id;
  529. }
  530. }else{
  531. $result['data'] = null;
  532. }
  533. return $result;
  534. }
  535. //回放URL
  536. public function getPlaybackUrl(){
  537. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  538. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  539. $camera_id = Input::get('camera_id', '');
  540. $start_time = Input::get('start_time', '');
  541. $end_time = Input::get('end_time', '');
  542. $result['status'] = true;
  543. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  544. if (!$camera_id || !$start_time || !$end_time) {
  545. $result['status'] = false;
  546. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  547. return $result;
  548. }
  549. $query = CameraList::where('id', $camera_id)->first();
  550. if (!$query) {
  551. $result['status'] = false;
  552. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  553. return $result;
  554. }
  555. if($query->playback == 0){
  556. $result['status'] = false;
  557. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  558. return $result;
  559. }
  560. $degree = MineList::where('id', $query->mine_id)->value('degree');
  561. $degree = explode('|', $degree)[0];
  562. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  563. //判断摄像头是否是洗选中心的时间+34分钟
  564. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  565. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  566. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  567. }
  568. $str = '.000+';
  569. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  570. $start_time = explode('+',$start_time);
  571. $start_time = $start_time[0].$str.$start_time[1];
  572. $end_time = date('c', strtotime($end_time));
  573. $end_time = explode('+',$end_time);
  574. $end_time = $end_time[0].$str.$end_time[1];
  575. //判断是否在配置文件里,在的不用走ffmpeg
  576. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  577. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  578. return self::successResponse($result);
  579. }else{
  580. $result = CameraServices::getPlaybackRtmp($camera_id,$start_time,$end_time,$time);
  581. return self::successResponse($result);
  582. }
  583. }
  584. //easydrawin回放URL
  585. public function getPlaybackUrlByEasy(){
  586. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  587. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  588. $camera_id = Input::get('camera_id', '');
  589. $start_time = Input::get('start_time', '');
  590. $end_time = Input::get('end_time', '');
  591. $result['status'] = true;
  592. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  593. if (!$camera_id || !$start_time || !$end_time) {
  594. $result['status'] = false;
  595. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  596. return $result;
  597. }
  598. $query = CameraList::where('id', $camera_id)->first();
  599. if (!$query) {
  600. $result['status'] = false;
  601. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  602. return $result;
  603. }
  604. if($query->playback == 0){
  605. $result['status'] = false;
  606. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  607. return $result;
  608. }
  609. $degree = MineList::where('id', $query->mine_id)->value('degree');
  610. $degree = explode('|', $degree)[0];
  611. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  612. //判断摄像头是否是洗选中心的时间+34分钟
  613. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  614. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  615. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  616. }
  617. $str = '.000+';
  618. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  619. $start_time = explode('+',$start_time);
  620. $start_time = $start_time[0].$str.$start_time[1];
  621. $end_time = date('c', strtotime($end_time));
  622. $end_time = explode('+',$end_time);
  623. $end_time = $end_time[0].$str.$end_time[1];
  624. //判断是否在配置文件里,在的不用走ffmpeg
  625. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  626. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  627. return self::successResponse($result);
  628. }else{
  629. $result = CameraServices::getPlaybackByEasy($camera_id,$start_time,$end_time,$time);
  630. return self::successResponse($result);
  631. }
  632. }
  633. /**
  634. * 作者: qiuzijian
  635. * 注释: 获取编码设备信息
  636. * @return \App\Http\Controllers\Api\JsonResponse
  637. */
  638. public function getTranscodeInfo()
  639. {
  640. $parent_id = Input::get('parent_id', '');
  641. if (!$parent_id) {
  642. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  643. }
  644. $result = CameraServices::getHaiKangTransCode($parent_id);
  645. return self::successResponse($result);
  646. }
  647. /**
  648. * 作者: qiuzijian
  649. * 注释: 获取大南湖摄像头列表
  650. * @return \App\Http\Controllers\Api\JsonResponse
  651. */
  652. public function getSouthLakeCamera()
  653. {
  654. $result = CameraServices::getLeChangeCamera();
  655. return self::successResponse($result);
  656. }
  657. public function pictureBase64(){
  658. $base64 = Input::get('base64', '');
  659. $camera_id = Input::get('camera_id', '');
  660. if (!$base64 || !$camera_id) {
  661. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  662. }
  663. $data['base64'] = $base64;
  664. DB::table('camera_list')->where('id',$camera_id)->update($data);
  665. return self::successResponse();
  666. }
  667. public function test(){
  668. // header("Access-Control-Allow-Origin: *");
  669. $data = DB::table('goods')->get();
  670. return $data;
  671. }
  672. public function testadd(){
  673. // header("Access-Control-Allow-Origin: *");
  674. $res['good_name'] = Input::get('good_name', '');
  675. $res['good_url'] = 'images/1.jpg';
  676. $res['good_count'] = Input::get('good_count', '');
  677. $res['good_price'] = Input::get('good_price', '');
  678. $res['good_state'] = Input::get('good_state', '');
  679. DB::table('goods')->insert($res);
  680. return true;
  681. }
  682. public function testdel(){
  683. // header("Access-Control-Allow-Origin: *");
  684. DB::table('goods')->where('id',Input::get('id',''))->delete();
  685. return true;
  686. }
  687. public function testupdate(){
  688. // header("Access-Control-Allow-Origin: *");
  689. $res['good_name'] = Input::get('good_name', '');
  690. $res['good_url'] = 'images/1.jpg';
  691. $res['good_count'] = Input::get('good_count', '');
  692. $res['good_price'] = Input::get('good_price', '');
  693. $res['good_state'] = Input::get('good_state', '');
  694. DB::table('goods')->where('id',Input::get('id',''))->update($res);
  695. return true;
  696. }
  697. //值班信息
  698. public function dutyInformation(){
  699. $today = date('Y-m-d');
  700. $tomorrow = date("Y-m-d",strtotime("+1 day"));
  701. $result['today_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'zzb'");
  702. $result['today_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'fz'");
  703. $result['tomorrow_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'zzb'");
  704. $result['tomorrow_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'fz'");
  705. return self::successResponse($result);
  706. }
  707. //分类列表
  708. public function typeList(){
  709. $result = $result = DB::connection('etl_zaoquan')->select("select type from news_column_list group by type");
  710. if(count($result) > 0){
  711. for($i=0;$i<count($result);$i++){
  712. if($result[$i]->type == 'aqsc'){
  713. $result[$i]->name = '安全生产';
  714. }
  715. if($result[$i]->type == 'mkxw'){
  716. $result[$i]->name = '煤矿新闻';
  717. }
  718. if($result[$i]->type == 'zwbg'){
  719. $result[$i]->name = '政务办公';
  720. }
  721. if($result[$i]->type == 'djgz'){
  722. $result[$i]->name = '党建工作';
  723. }
  724. if($result[$i]->type == 'qygl'){
  725. $result[$i]->name = '企业管理';
  726. }
  727. if($result[$i]->type == 'jdgl'){
  728. $result[$i]->name = '机电管理';
  729. }
  730. if($result[$i]->type == 'scjsgl'){
  731. $result[$i]->name = '生产技术管理';
  732. }
  733. if($result[$i]->type == 'jjjc'){
  734. $result[$i]->name = '纪检监察';
  735. }
  736. if($result[$i]->type == 'zhzl'){
  737. $result[$i]->name = '综合治理';
  738. }
  739. if($result[$i]->type == 'jypx'){
  740. $result[$i]->name = '教育培训';
  741. }
  742. if($result[$i]->type == 'kwgk'){
  743. $result[$i]->name = '矿务公开';
  744. }
  745. }
  746. }
  747. return self::successResponse($result);
  748. }
  749. //文章列表
  750. public function articleList(Request $request){
  751. $params = $request->all();
  752. if (!isset($params['page_size'])) {
  753. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  754. }
  755. if (!isset($params['page_num'])) {
  756. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  757. }
  758. if (!isset($params['type'])) {
  759. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  760. }
  761. $offset = $params['page_size'] * ($params['page_num'] - 1);
  762. $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);
  763. $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';
  764. if(count($result) > 0){
  765. for($i=0;$i<count($result);$i++){
  766. //替换title_image
  767. $old_title_image = $result[$i]->title_image;
  768. $old_title_image_array = explode('/',$old_title_image);
  769. $old_img_path = $old_title_image_array[count($old_title_image_array)-1];
  770. $new_img_path_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".$old_img_path."'");
  771. if(count($new_img_path_list) > 0){
  772. $result[$i]->title_image = $new_img_path_list[0]->new_name;
  773. }
  774. //替换text
  775. preg_match_all($pattern, $result[$i]->text, $matches);
  776. foreach ($matches[2] as $index => $oldSrc) {
  777. $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
  778. if(count($news_img_list) > 0){
  779. $newSrc = $news_img_list[0]->new_name;
  780. $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
  781. }
  782. }
  783. }
  784. }
  785. return self::successResponse($result);
  786. }
  787. //文章图片上传至阿里云
  788. public function ossUrl(Request $request){
  789. $params = $request->all();
  790. if (!isset($params['url'])) {
  791. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  792. }
  793. $result = $this->downloadFile($params['url']);
  794. return self::successResponse($result);
  795. }
  796. //下载文件
  797. public function downloadFile($file_path)
  798. {
  799. $rename = mt_rand(1111111,9999999);
  800. if (!$file_path) {
  801. return false;
  802. }
  803. set_time_limit(0);
  804. $ch = curl_init($file_path);
  805. curl_setopt($ch, CURLOPT_HEADER, 0);
  806. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  807. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  808. $rawdata = curl_exec ($ch);
  809. curl_close ($ch);
  810. // 使用中文文件名需要转码
  811. $fp = fopen(public_path() . '/filedownload/' . $rename.'.jpg', 'w');
  812. fwrite($fp, $rawdata);
  813. fclose($fp);
  814. $file_name = $rename;
  815. //上传文件
  816. $file_oss_path = $this->uploadFile($file_name);
  817. return $file_oss_path;
  818. }
  819. //上传文件
  820. public function uploadFile($file_name)
  821. {
  822. try{
  823. $oss = new OssClient(
  824. Config::get('filesystems.disks.oss_view.access_key'),
  825. Config::get('filesystems.disks.oss_view.secret_key'),
  826. Config::get('filesystems.disks.oss_view.endpoint')
  827. );
  828. $file_path = public_path() . '/filedownload/' . $file_name.'.jpg';
  829. $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.'.jpeg', $file_path);
  830. } catch(\OssException $e) {
  831. printf(__FUNCTION__ . ": FAILED\n");
  832. printf($e->getMessage() . "\n");
  833. return;
  834. }
  835. if (isset($res['info']['url']) && $res['info']['url']) {
  836. unlink($file_path);
  837. return urldecode($res['info']['url']);
  838. } else {
  839. return false;
  840. }
  841. }
  842. }