CameraApiController.php 49 KB

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