CameraApiController.php 46 KB

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