CameraController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. namespace Modules\Camera\Http\Controllers;
  3. use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
  4. use Illuminate\Contracts\Support\Renderable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Routing\Controller;
  7. use Illuminate\Support\Facades\Input;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Storage;
  10. use Modules\Admin\Auxiliary\View\FromAuxiliary;
  11. use Modules\Admin\Auxiliary\View\TableAuxiliary;
  12. use Modules\Admin\Auxiliary\View\TreeAuxiliary;
  13. use Modules\Admin\Http\Controllers\BaseController;
  14. use Modules\Camera\Entities\CameraFieldList;
  15. use Modules\Camera\Entities\CameraList;
  16. use Modules\Camera\Enum\CameraEnum;
  17. use Modules\Camera\Jobs\CameraListExcel;
  18. use Modules\Camera\Services\CameraServices;
  19. use Modules\Mine\Entities\MineList;
  20. use Modules\Mine\Entities\WorkingSurface;
  21. use Modules\Mine\Entities\WorkingSurfaceCamera;
  22. use Modules\Mine\Services\MineServices;
  23. use Modules\Mine\Services\SurfaceServices;
  24. use DB;
  25. class CameraController extends BaseController
  26. {
  27. /**
  28. * Display a listing of the resource.
  29. * @return Renderable
  30. */
  31. public function index()
  32. {
  33. return view('camera::index');
  34. }
  35. //摄像头列表
  36. public function cameraList(Request $request)
  37. {
  38. $this->menusActive[0] = 'adminCamera';
  39. $this->menusActive[1] = 'adminCameraList';
  40. //查询当前登录用户权限内的区域
  41. $user = DB::table('users')->where('staff_num',$request->user()->staff_num)->first();
  42. $mine_array = explode(';',$user->mine_role);//权限内的矿区
  43. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  44. $mine_use = [];//权限内矿区下所有区域
  45. foreach($mine_all as $k=>$v){
  46. if(in_array(explode('|',$v->degree)[0],$mine_array)){
  47. $mine_use[] = $v->id;
  48. }
  49. }
  50. $camera_list = CameraList::join(
  51. 'mine_list', 'camera_list.mine_id', '=', 'mine_list.id'
  52. )->whereIn('mine_list.id',$mine_use)->orderBy('camera_list.sort', 'desc');
  53. if ($request->has('mine_name') && $request->input('mine_name')) {
  54. $mine_id = MineList::where('title', 'like', '%' . $request->input('mine_name') . '%')->where('parent_id', 0)->get();
  55. if(sizeof($mine_id) == 0){
  56. $camera_list = $camera_list->where('mine_list.title', 'like', '%' . $request->input('mine_name') . '%')->where('parent_id', 0);
  57. }
  58. $camera_list = $camera_list->where(function ($query) use ($mine_id) {
  59. foreach($mine_id as $k=>$v){
  60. $query->orWhere('mine_list.degree', $v->id );
  61. $query->orWhere('mine_list.degree', 'like', $v->id . '|' . '%');
  62. }
  63. });
  64. // foreach($mine_id as $k=>$v){
  65. // $camera_list = $camera_list->orWhere('mine_list.degree', $v->id );
  66. // $camera_list = $camera_list->orWhere('mine_list.degree', 'like', $v->id . '|' . '%');
  67. // }
  68. // $camera_list = $camera_list->orWhere('mine_list.degree', 'like', 1 . '|' . '%');
  69. // $camera_list = $camera_list->orWhere('mine_list.degree', 'like', 2 . '|' . '%');
  70. // $camera_list = $camera_list->where('mine_list.title', 'like', '%' . $request->input('mine_name') . '%')->where('parent_id', 0);
  71. }
  72. if ($request->has('area_name') && $request->input('area_name')) {
  73. $area_id = MineList::where('title', 'like', '%' . $request->input('area_name') . '%')->get();
  74. if(sizeof($area_id) == 0){
  75. $camera_list = $camera_list->where('mine_list.title', 'like', '%' . $request->input('area_name') . '%')->where('parent_id','!=', 0);
  76. }
  77. $camera_list = $camera_list->where(function ($query) use ($area_id) {
  78. foreach($area_id as $k=>$v){
  79. $query->orWhere('mine_list.degree', $v->id)->where('mine_list.parent_id',0);
  80. $query->orWhere('mine_list.degree', 'like', '%' . '|' .$v->id);
  81. }
  82. });
  83. // foreach($area_id as $k=>$v){
  84. //// $camera_list = $camera_list->orWhere('mine_list.degree', $v->id );
  85. // $camera_list = $camera_list->orWhere('mine_list.degree', $v->id)->where('mine_list.parent_id',0);
  86. // $camera_list = $camera_list->orWhere('mine_list.degree', 'like', '%' . '|' .$v->id);
  87. // }
  88. // $camera_list = $camera_list->where('title', 'like', '%' . $request->input('area_name') . '%');
  89. // dd($camera_list);exit;
  90. // $camera_list = $camera_list->where('mine_list.degree', 'like', '%' . '|' . $area_id);
  91. // $camera_list = $camera_list->where('mine_list.title', 'like', '%' . $request->input('mine_name') . '%')->where('parent_id','!=', 0);
  92. }
  93. $data['mine_default'] = "";
  94. if ($request->has('mine_id') && $request->input('mine_id')) {
  95. $camera_list = $camera_list->where('mine_list.id',$request->input('mine_id'));
  96. $data['mine_default'] = $request->input('mine_id');
  97. }
  98. if ($request->has('camera_name') && $request->input('camera_name')) {
  99. $camera_list = $camera_list->where('camera_list.camera_name', 'like', '%' . $request->input('camera_name') . '%');
  100. }
  101. if ($request->has('camera_type') && $request->input('camera_type')) {
  102. $camera_list = $camera_list->where('camera_list.camera_type', $request->input('camera_type'));
  103. }
  104. if ($request->has('camera_source') && $request->input('camera_source')) {
  105. $camera_list = $camera_list->where('camera_list.camera_source', $request->input('camera_source'));
  106. }
  107. $camera_list = $camera_list->select(
  108. 'camera_list.id',
  109. 'camera_list.camera_url',
  110. 'camera_list.camera_name',
  111. 'camera_list.revert_id',
  112. 'camera_list.sort',
  113. 'camera_list.camera_type',
  114. 'camera_list.camera_source',
  115. 'camera_list.is_show',
  116. 'mine_list.title',
  117. 'mine_list.degree'
  118. )->paginate(CameraEnum::PAGE_SIZE);
  119. foreach ($camera_list as $key => $val) {
  120. $camera_list[$key]->parent_title = MineList::where('id', explode('|', $val->degree)[0])->value('title');
  121. }
  122. $tableObj = new TableAuxiliary('camera/list', $camera_list);
  123. // $tableObj->search('input', 'mine_name', '矿区名称');
  124. // $tableObj->search('input', 'area_name', '区域名称');
  125. $tableObj->search('input', 'camera_name', '摄像头名称');
  126. $tableObj->search('select', 'camera_type', '摄像头类型', CameraEnum::CAMERA_TYPE_EXCHANGE);
  127. $tableObj->search('select', 'camera_source', '摄像头来源', CameraEnum::CAMERA_SOURCE_EXCHANGE);
  128. $tableObj->topActions = ['add', 'import', 'importTemplate'];
  129. $tableObj->column('parent_title', '矿区名称');
  130. $tableObj->column('title', '区域名称');
  131. $tableObj->column('camera_name', '摄像头名称');
  132. // $tableObj->column('camera_type', '摄像头类型', function ($camera_type) {
  133. // return CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_type];
  134. // });
  135. $tableObj->column('camera_url', '链接');
  136. $tableObj->column('camera_source', '摄像头来源', function ($camera_source) {
  137. return CameraEnum::CAMERA_SOURCE_EXCHANGE[$camera_source];
  138. });
  139. // $tableObj->column('revert_id', '流媒体id');
  140. $tableObj->column('is_show', '是否显示', function ($is_show, $item) {
  141. return '<span class="layui-form"><input type="checkbox" name="is_show" data-href="camera/list/edit?type=show&id=' . $item['id'] . '" lay-skin="switch" lay-text="是|否" ' . ($is_show == CameraEnum::IS_SHOW_YES ? 'checked' : '') . '></span>';
  142. });
  143. $tableObj->column('sort', '排序');
  144. $data['pagesize'] = ceil($camera_list->total()/CameraEnum::PAGE_SIZE);
  145. $data['path'] = $tableObj->path;
  146. $data['items'] = $tableObj->items;
  147. $data['columns'] = $tableObj->columns;
  148. $data['searchs'] = $tableObj->searchColumns;
  149. $data['primaryKey'] = $tableObj->primaryKey;
  150. $data['displayActions'] = $tableObj->displayActions;
  151. if (is_string($data['displayActions']['value'])) {
  152. $data['displayActions']['value'] = [$data['displayActions']['value']];
  153. }
  154. $data['actionBtns'] = $tableObj->actionBtns;
  155. $data['actionBtnsAttribute'] = $tableObj->actionBtnsAttribute;
  156. $data['topActions'] = $tableObj->topActions;
  157. $data['displayActionOthers'] = $tableObj->displayActionOthers;
  158. $data['topActionOthers'] = $tableObj->topActionOthers;
  159. $data += \Illuminate\Support\Facades\Request::except('_token');
  160. //区域列表
  161. $mine_list = DB::table('mine_list')->whereIn('id',$mine_array)->where('parent_id',0)->where('deleted_at',null)->get();
  162. $tree_data = [];
  163. foreach($mine_list as $k=>$v){
  164. $tree_data[$v->id]['id'] = $v->id;
  165. $tree_data[$v->id]['name'] = $v->title;
  166. $child_list = DB::table('mine_list')->where('parent_id',$v->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
  167. if(count($child_list)>0){
  168. $tree_data[$v->id]['type'] = 'folder';
  169. $tree_data[$v->id]['additionalParameters']['children'] = $this->mineTree($child_list,$v->id);
  170. }else{
  171. $tree_data[$v->id]['type'] = 'item';
  172. }
  173. }
  174. $data['tree_data'] = $tree_data;
  175. return $this->view('camera::camera_list', $data);
  176. }
  177. //摄像头管理区域列表ajax
  178. public function mineList(Request $request){
  179. //查询当前登录用户权限内的区域
  180. $user = DB::table('users')->where('staff_num',$request->user()->staff_num)->first();
  181. $mine_array = explode(';',$user->mine_role);//权限内的矿区
  182. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  183. $mine_use = [];//权限内矿区下所有区域
  184. foreach($mine_all as $k=>$v){
  185. if(in_array(explode('|',$v->degree)[0],$mine_array)){
  186. $mine_use[] = $v->id;
  187. }
  188. }
  189. //区域列表
  190. $mine_list = DB::table('mine_list')->whereIn('id',$mine_use)->where('parent_id',0)->where('deleted_at',null)->get();
  191. $tree_data = [];
  192. foreach($mine_list as $k=>$v){
  193. $tree_data[$v->id]['id'] = $v->id;
  194. $tree_data[$v->id]['name'] = $v->title;
  195. $child_list = DB::table('mine_list')->where('parent_id',$v->id)->get();
  196. if(count($child_list)>0){
  197. $tree_data[$v->id]['type'] = 'folder';
  198. $tree_data[$v->id]['additionalParameters']['children'] = $this->mineTree($child_list,$v->id);
  199. }else{
  200. $tree_data[$v->id]['type'] = 'item';
  201. }
  202. }
  203. return $tree_data;
  204. }
  205. //摄像头管理区域列表ajax
  206. public function cameraUpdate(Request $request){
  207. //查询当前登录用户权限内的区域
  208. $user = DB::table('users')->where('staff_num',$request->user()->staff_num)->first();
  209. $mine_array = explode(';',$user->mine_role);//权限内的矿区
  210. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  211. $mine_use = [];//权限内矿区下所有区域
  212. foreach($mine_all as $k=>$v){
  213. if(in_array(explode('|',$v->degree)[0],$mine_array)){
  214. $mine_use[] = $v->id;
  215. }
  216. }
  217. $camera_list = CameraList::join(
  218. 'mine_list', 'camera_list.mine_id', '=', 'mine_list.id'
  219. )->whereIn('mine_list.id',$mine_use)->orderBy('camera_list.sort', 'desc');
  220. if ($_GET['mine_id'] != '' && $_GET['mine_id'] != null) {
  221. $camera_list = $camera_list->where('camera_list.mine_id', $_GET['mine_id']);
  222. }
  223. if ($_GET['camera_name'] != '' && $_GET['camera_name'] != null) {
  224. $camera_list = $camera_list->where('camera_list.camera_name', 'like', '%' . $_GET['camera_name'] . '%');
  225. }
  226. if ($_GET['camera_type'] != 0) {
  227. $camera_list = $camera_list->where('camera_list.camera_type', $_GET['camera_type']);
  228. }
  229. if ($_GET['camera_source'] != 0) {
  230. $camera_list = $camera_list->where('camera_list.camera_source', $_GET['camera_source']);
  231. }
  232. $camera_list = $camera_list->select(
  233. 'camera_list.id',
  234. 'camera_list.camera_url',
  235. 'camera_list.camera_name',
  236. 'camera_list.revert_id',
  237. 'camera_list.sort',
  238. 'camera_list.camera_type',
  239. 'camera_list.camera_source',
  240. 'camera_list.is_show',
  241. 'mine_list.title',
  242. 'mine_list.degree'
  243. )->paginate(CameraEnum::PAGE_SIZE);
  244. foreach ($camera_list as $key => $val) {
  245. $camera_list[$key]->parent_title = MineList::where('id', explode('|', $val->degree)[0])->value('title');
  246. $val->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$val->camera_type];
  247. $val->camera_source = CameraEnum::CAMERA_SOURCE_EXCHANGE[$val->camera_source];
  248. }
  249. return $camera_list;
  250. }
  251. //摄像头管理区域列表ajax
  252. public function camerapage(Request $request){
  253. //查询当前登录用户权限内的区域
  254. $user = DB::table('users')->where('staff_num',$request->user()->staff_num)->first();
  255. $mine_array = explode(';',$user->mine_role);//权限内的矿区
  256. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  257. $mine_use = [];//权限内矿区下所有区域
  258. foreach($mine_all as $k=>$v){
  259. if(in_array(explode('|',$v->degree)[0],$mine_array)){
  260. $mine_use[] = $v->id;
  261. }
  262. }
  263. $camera_list = CameraList::join(
  264. 'mine_list', 'camera_list.mine_id', '=', 'mine_list.id'
  265. )->whereIn('mine_list.id',$mine_use)->orderBy('camera_list.sort', 'desc');
  266. if ($_GET['mine_id'] != '' && $_GET['mine_id'] != null) {
  267. $camera_list = $camera_list->where('camera_list.mine_id', $_GET['mine_id']);
  268. }
  269. if ($_GET['camera_name'] != '' && $_GET['camera_name'] != null) {
  270. $camera_list = $camera_list->where('camera_list.camera_name', 'like', '%' . $_GET['camera_name'] . '%');
  271. }
  272. if ($_GET['camera_type'] != 0) {
  273. $camera_list = $camera_list->where('camera_list.camera_type', $_GET['camera_type']);
  274. }
  275. if ($_GET['camera_source'] != 0) {
  276. $camera_list = $camera_list->where('camera_list.camera_source', $_GET['camera_source']);
  277. }
  278. $camera_list = $camera_list->select(
  279. 'camera_list.id',
  280. 'camera_list.camera_url',
  281. 'camera_list.camera_name',
  282. 'camera_list.revert_id',
  283. 'camera_list.sort',
  284. 'camera_list.camera_type',
  285. 'camera_list.camera_source',
  286. 'camera_list.is_show',
  287. 'mine_list.title',
  288. 'mine_list.degree'
  289. )->paginate(CameraEnum::PAGE_SIZE);
  290. foreach ($camera_list as $key => $val) {
  291. $camera_list[$key]->parent_title = MineList::where('id', explode('|', $val->degree)[0])->value('title');
  292. $val->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$val->camera_type];
  293. $val->camera_source = CameraEnum::CAMERA_SOURCE_EXCHANGE[$val->camera_source];
  294. }
  295. return $camera_list;
  296. }
  297. public function mineTree($regions, $parent_id)
  298. {
  299. $arr = [];
  300. foreach ($regions as $key => $value) {
  301. $arr[$key]['id'] = $value->id;
  302. $arr[$key]['name'] = $value->title;
  303. $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->get();
  304. if (count($mine_child) > 0) {
  305. $arr[$key]['type'] = 'folder';
  306. $arr[$key]['additionalParameters']['children'] = self::mineTree($mine_child, $value->id);
  307. } else {
  308. $arr[$key]['type'] = 'item';
  309. }
  310. }
  311. return array_values($arr);
  312. }
  313. //查看摄像头列表详情
  314. public function cameraListView(Request $request)
  315. {
  316. if (!$request->has('id')) {
  317. return $this->redirect('admin/camera/list');
  318. }
  319. $camera_list = CameraList::join(
  320. 'mine_list', 'camera_list.mine_id', '=', 'mine_list.id'
  321. )->where('camera_list.id', $request->input('id'))->select(
  322. 'camera_list.id',
  323. 'camera_list.ip',
  324. 'camera_list.port',
  325. 'camera_list.user_name',
  326. 'camera_list.password',
  327. 'camera_list.com_number',
  328. 'camera_list.camera_url',
  329. 'camera_list.camera_name',
  330. 'camera_list.revert_id',
  331. 'camera_list.sort',
  332. 'camera_list.camera_type',
  333. 'camera_list.camera_source',
  334. 'camera_list.cover_picture',
  335. 'camera_list.video_recorder',
  336. 'mine_list.title',
  337. 'mine_list.degree'
  338. )->first();
  339. //工作面列表
  340. $working_surface = WorkingSurfaceCamera::join(
  341. 'working_surface', 'working_surface_camera.surface_id', '=', 'working_surface.id'
  342. )->where('working_surface_camera.camera_id', $request->input('id'))->value('surface_name');
  343. $camera_list->parent_title = MineList::where('id', explode('|', $camera_list->degree)[0])->value('title');
  344. $camera_list->working_surface = $working_surface;
  345. $tableObj = new TableAuxiliary('', $camera_list);
  346. $tableObj->column('parent_title', '矿区名称');
  347. $tableObj->column('title', '区域名称');
  348. $tableObj->column('camera_name', '摄像头名称');
  349. $tableObj->column('camera_type', '摄像头类型', function ($camera_type) {
  350. return CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_type];
  351. });
  352. $tableObj->column('camera_source', '摄像头来源', function ($camera_source) {
  353. return CameraEnum::CAMERA_SOURCE_EXCHANGE[$camera_source];
  354. });
  355. $tableObj->column('video_recorder', '视频服务器来源', function ($video_recorder) {
  356. return CameraEnum::VIDEO_RECORDER_EXCHANGE[$video_recorder];
  357. });
  358. if($camera_list->revert_id != '' && $camera_list->revert_id != null){
  359. $tableObj->column('revert_id', '流媒体id');
  360. }
  361. if($camera_list->user_name != '' && $camera_list->user_name != null){
  362. $tableObj->column('user_name', '用户名');
  363. }
  364. if($camera_list->password != '' && $camera_list->password != null){
  365. $tableObj->column('password', '密码');
  366. }
  367. if($camera_list->ip != '' && $camera_list->ip != null){
  368. $tableObj->column('ip', 'ip地址');
  369. }
  370. if($camera_list->port != '' && $camera_list->port != null){
  371. $tableObj->column('port', '端口');
  372. }
  373. if($camera_list->com_number != '' && $camera_list->com_number != null){
  374. $tableObj->column('com_number', '通道号');
  375. }
  376. if($camera_list->camera_url != '' && $camera_list->camera_url != null){
  377. $tableObj->column('camera_url', '链接');
  378. }
  379. if($camera_list->sort != '' && $camera_list->sort != null){
  380. $tableObj->column('sort', '排序');
  381. }
  382. if($camera_list->working_surface != '' && $camera_list->working_surface != null){
  383. $tableObj->column('working_surface', '所属矿区区域');
  384. }
  385. if($camera_list->cover_picture != '' && $camera_list->cover_picture != null){
  386. $tableObj->column('cover_picture', '封面图片', function($cover_picture) {
  387. return '<img src="'.$cover_picture.'">';
  388. });
  389. }
  390. $tableObj->title = '摄像头详情';
  391. return $this->tableView($tableObj);
  392. }
  393. //添加摄像头列表
  394. public function cameraListAdd(Request $request)
  395. {
  396. $mineService = new MineServices();
  397. $mineService->initMineList();
  398. $titleList = $mineService->getTierList();
  399. $formObj = new FromAuxiliary('camera/list/add');
  400. if(isset($_GET['mine_id']) && $_GET['mine_id'] != ''){
  401. $formObj->tree_select('mine_id', '所属区域', $titleList,$_GET['mine_id']);
  402. }else{
  403. $formObj->tree_select('mine_id', '所属区域', $titleList);
  404. }
  405. $formObj->input('camera_name', '摄像头名称');
  406. $formObj->select('camera_type', '摄像头类型', CameraEnum::CAMERA_TYPE_EXCHANGE, CameraEnum::CAMERA_TYPE_NORMAL);
  407. $formObj->select('camera_source', '摄像头来源', CameraEnum::CAMERA_SOURCE_EXCHANGE, CameraEnum::CAMERA_SOURCE_1);
  408. $formObj->radio('video_recorder', '硬盘录像机品牌',CameraEnum::VIDEO_RECORDER_EXCHANGE, CameraEnum::VIDEO_RECORDER_HK);
  409. $formObj->input('camera_url', '摄像头链接');
  410. $formObj->input('user_name', '用户名');
  411. $formObj->input('password', '密码');
  412. $formObj->input('ip', 'ip地址');
  413. $formObj->input('port', '端口');
  414. $formObj->input('com_number', '通道号');
  415. $formObj->select('code_stream', '视频码流', CameraEnum::CODE_STREAM_EXCHANGE, CameraEnum::CODE_STREAM_SUB);
  416. $formObj->input('sort', '排序', CameraEnum::DEFAULT_SORT);
  417. $formObj->uploadImg('cover_picture', '封面图片', '/admin/camera/upload/cover_picture', '');
  418. $formObj->title = '添加摄像头';
  419. return $this->from($formObj);
  420. }
  421. //添加摄像头列表操作
  422. public function cameraListAddPost(Request $request)
  423. {
  424. if (!$request->input('mine_id')) {
  425. return $this->error(1, '请选择矿区单位');
  426. }
  427. if (!$request->input('camera_type')) {
  428. return $this->error(1, '请选择摄像头类型');
  429. }
  430. if (!$request->input('camera_name')) {
  431. return $this->error(1, '请输入摄像头名称');
  432. }
  433. if ($request->input('camera_source') == CameraEnum::CAMERA_SOURCE_1 && (!$request->input('ip') || !$request->input('port') || !$request->input('user_name')
  434. || !$request->input('password') ||!$request->input('com_number'))) {
  435. return $this->error(1, '请输入必填字段');
  436. }
  437. if ($request->input('camera_source') == CameraEnum::CAMERA_SOURCE_2 && $request->input('code_stream') == 0) {
  438. return $this->error(1, '请选择视频码流');
  439. }
  440. if ($request->input('camera_source') == CameraEnum::CAMERA_SOURCE_3 && !$request->input('camera_url')) {
  441. return $this->error(1, '请输入摄像头链接');
  442. }
  443. if (!$request->input('code_stream')) {
  444. return $this->error(1, '请选择视频码流类型');
  445. }
  446. $result = CameraServices::addCameraList($request->all());
  447. if (!$result['status']) {
  448. return $this->error(1, $result['msg']);
  449. }
  450. return $this->redirect('admin/camera/list');
  451. }
  452. //编辑摄像头列表
  453. public function cameraListEdit(Request $request)
  454. {
  455. $id = $request->input('id');
  456. if (empty($id)) {
  457. return $this->redirect('admin/camera/list');
  458. }
  459. $mineService = new MineServices();
  460. $mineService->initMineList();
  461. $titleList = $mineService->getTierList();
  462. $camera_list = CameraList::find($id);
  463. if ($request->has('type') && $request->input('type') == 'show') {
  464. if ($camera_list->is_show == 1) {
  465. $camera_list->is_show = 2;
  466. } else {
  467. $camera_list->is_show = 1;
  468. }
  469. $camera_list->save();
  470. return $this->success();
  471. }
  472. //工作面列表
  473. $degree = MineList::where('id', $camera_list->mine_id)->value('degree');
  474. $parent_id = explode('|', $degree)[0];
  475. $surface_list = WorkingSurface::where('mine_id', $parent_id)->get()->toArray();
  476. $surface_arr = [];
  477. foreach ($surface_list as $key => $val) {
  478. $surface_arr[$val['id']] = $val['surface_name'];
  479. }
  480. $default_surface = WorkingSurfaceCamera::where('camera_id', $id)->value('surface_id');
  481. $formObj = new FromAuxiliary('camera/list/edit', $camera_list);
  482. $formObj->tree_select('mine_id', '所属区域', $titleList);
  483. $formObj->input('camera_name', '摄像头名称');
  484. $formObj->select('camera_type', '摄像头类型', CameraEnum::CAMERA_TYPE_EXCHANGE);
  485. $formObj->select('camera_source', '摄像头来源', CameraEnum::CAMERA_SOURCE_EXCHANGE);
  486. $formObj->radio('video_recorder', '视频服务器来源',CameraEnum::VIDEO_RECORDER_EXCHANGE);
  487. $formObj->input('camera_url', '摄像头链接');
  488. $formObj->input('user_name', '用户名');
  489. $formObj->input('password', '密码');
  490. $formObj->input('ip', 'ip地址');
  491. $formObj->input('port', '端口');
  492. $formObj->input('com_number', '通道号');
  493. $formObj->select('code_stream', '视频码流', CameraEnum::CODE_STREAM_EXCHANGE);
  494. $formObj->input('sort', '排序');
  495. $formObj->select('surface_id', '所属矿区区域', $surface_arr, $default_surface);
  496. $formObj->uploadImg('cover_picture', '封面图片', '/admin/camera/upload/cover_picture', $camera_list->cover_picture);
  497. $formObj->title = '编辑摄像头';
  498. return $this->from($formObj);
  499. }
  500. //编辑摄像头操作
  501. public function cameraListEditPost(Request $request)
  502. {
  503. if (!$request->input('mine_id')) {
  504. return $this->error(1, '请选择所属区域');
  505. }
  506. if (!$request->input('camera_type')) {
  507. return $this->error(1, '请选择摄像头类型');
  508. }
  509. if (!$request->input('camera_name')) {
  510. return $this->error(1, '请输入摄像头名称');
  511. }
  512. if ($request->input('camera_source') == CameraEnum::CAMERA_SOURCE_3 && !$request->input('camera_url')) {
  513. return $this->error(1, '请输入摄像头链接');
  514. }
  515. if (!$request->input('code_stream')) {
  516. return $this->error(1, '请选择视频码流类型');
  517. }
  518. // if (
  519. // !$request->input('ip') || !$request->input('port') || !$request->input('user_name')
  520. // || !$request->input('password') ||!$request->input('com_number')
  521. // ) {
  522. // return $this->error(1, '请输入必填字段');
  523. // }
  524. $result = CameraServices::editCameraList($request->all());
  525. if (!$result['status']) {
  526. return $this->error(1, $result['msg']);
  527. }
  528. //更新摄像头与工作面关联表
  529. SurfaceServices::updateSrufaceCamera($request->all());
  530. return $this->redirect('admin/camera/list');
  531. }
  532. //删除摄像头列表记录
  533. public function cameraListDelPost(Request $request)
  534. {
  535. if (!$request->has('id')) {
  536. return $this->error(1, '缺少必要参数');
  537. }
  538. $result = CameraServices::delCameraList($request->all());
  539. if (!$result['status']) {
  540. return $this->error(1, $result['msg']);
  541. }
  542. return $this->success();
  543. }
  544. //导入摄像头列表
  545. public function cameraListImport(Request $request)
  546. {
  547. if (!$request->hasFile('excel')) {
  548. return $this->error(9001, '缺少上传文件');
  549. }
  550. ini_set('memory_limit', '500M');
  551. set_time_limit(300);
  552. $reader = ReaderEntityFactory::createReaderFromFile($request->file('excel')->getClientOriginalName());
  553. $reader->open($request->file('excel')->getRealPath());
  554. $sheet = $reader->getSheetIterator(); // 获取sheet对象
  555. $sheet->rewind(); // 指定当前sheet序数
  556. $sheet = $sheet->current(); // 获取指定sheet
  557. $arr = [];
  558. foreach ($sheet->getRowIterator() as $index => $row) { // 读取每行记录
  559. $arr[] = $row->toArray();
  560. }
  561. $reader->close();
  562. $result = CameraListExcel::dispatch($arr);
  563. if (!$result) {
  564. return $this->error(1, '所传矿区信息不存在');
  565. }
  566. return $this->success();
  567. }
  568. //下载摄像头列表导入模板
  569. public function cameraListTemplate()
  570. {
  571. return $this->redirect('/template/摄像头列表导入模板_v3.0.xlsx');
  572. }
  573. //字段列表
  574. public function fieldList(Request $request)
  575. {
  576. $this->menusActive[0] = 'adminCamera';
  577. $this->menusActive[1] = 'adminCameraFieldlist';
  578. $field_list = CameraFieldList::get();
  579. $tableObj = new TableAuxiliary('camera/field_list', $field_list);
  580. $tableObj->actionBtns = ['edit', 'del'];
  581. $tableObj->column('field_name', '字段名称');
  582. return $this->tableList($tableObj);
  583. }
  584. //添加字段
  585. public function fieldListAdd(Request $request)
  586. {
  587. $formObj = new FromAuxiliary('camera/field_list/add');
  588. $formObj->input('field_name', '字段名称');
  589. $formObj->title = '添加字段';
  590. return $this->from($formObj);
  591. }
  592. //添加字段操作
  593. public function fieldListAddPost(Request $request)
  594. {
  595. if (!$request->input('field_name')) {
  596. return $this->error(1, '请输入字段名称');
  597. }
  598. $result = CameraServices::addCameraFieldList($request->all());
  599. if (!$result['status']) {
  600. return $this->error(1, $result['msg']);
  601. }
  602. return $this->redirect('admin/camera/field_list');
  603. }
  604. //编辑字段
  605. public function fieldListEdit(Request $request)
  606. {
  607. $field_list_id = $request->input('id');
  608. if (empty($field_list_id)) {
  609. return $this->redirect('admin/camera/field_list');
  610. }
  611. $field_list = CameraFieldList::find($field_list_id);
  612. $fromObj = new FromAuxiliary('camera/field_list/edit', $field_list);
  613. $fromObj->input("field_name", "字段名称", $field_list->field_name);
  614. $fromObj->title = '修改字段';
  615. return $this->from($fromObj);
  616. }
  617. //编辑字段操作
  618. public function fieldListEditPost(Request $request)
  619. {
  620. if (!$request->input('field_name')) {
  621. return $this->error(1, '请输入字段名称');
  622. }
  623. $result = CameraServices::editCameraFieldList($request->all());
  624. if (!$result['status']) {
  625. return $this->error(1, $result['msg']);
  626. }
  627. return $this->redirect('admin/camera/field_list');
  628. }
  629. //删除字段
  630. public function fieldListDelPost(Request $request)
  631. {
  632. if (!$request->has('id')) {
  633. return $this->error(1, '缺少必要参数');
  634. }
  635. $result = CameraServices::delCameraFieldList($request->all());
  636. if (!$result['status']) {
  637. return $this->error(1, $result['msg']);
  638. }
  639. return $this->success();
  640. }
  641. //上传摄像头封面图片
  642. public function cameraUploadCpicture(Request $request)
  643. {
  644. $file = $request->file('file');
  645. $file_name = CameraServices::uploadFile($file);
  646. $file_path = public_path() . '/filedownload/';
  647. $res = CameraServices::uploadOssFile($file_name, $file_path);
  648. CameraServices::delUploadFile();
  649. $result['image_path'] = $res;
  650. return $this->success($result);
  651. }
  652. }