CameraApiController.php 49 KB

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