CameraApiController.php 42 KB

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