ApiController.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 6/22/24
  6. * Time: 12:32 PM
  7. */
  8. namespace Modules\Admin\Http\Controllers\Api;
  9. use App\Enum\ApiEnum;
  10. use App\Http\Controllers\Api\BaseController;
  11. use App\Http\Controllers\Controller;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Log;
  15. use Illuminate\Support\Facades\Input;
  16. use Modules\Admin\Entities\User;
  17. use Modules\Admin\Http\Requests\TokenRequest;
  18. use Modules\Admin\Services\ApiService;
  19. use Modules\Staff\Entities\Staff;
  20. use Symfony\Component\HttpFoundation\Response;
  21. class ApiController extends BaseController
  22. {
  23. //整改人列表
  24. public function zgrList(Request $request){
  25. $params = $request->all();
  26. if(!$params['xjdw']){
  27. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  28. }
  29. $result['status'] = true;
  30. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  31. $result['data'] = [];
  32. $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc',$params['xjdw'])->get();
  33. if(count($list) > 0){
  34. for($i=0;$i<count($list);$i++){
  35. $result['data'][$i] = $list[$i]->zgrxm.'|'.$list[$i]->zgrgh;
  36. }
  37. }
  38. return $result;
  39. }
  40. //网格化录入
  41. public function addConition(Request $request)
  42. {
  43. $params = Input::get();
  44. if (!$params) {
  45. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  46. }
  47. $result = ApiService::addConition($params);
  48. return self::successResponse($result);
  49. }
  50. //网格化整改
  51. public function editConition(Request $request){
  52. $params = Input::get();
  53. if (!$params) {
  54. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  55. }
  56. $result = ApiService::editConition($params);
  57. return self::successResponse($result);
  58. }
  59. //网格化人员轨迹查询条件
  60. public function getQueryConition(Request $request)
  61. {
  62. $date = Input::get('date', '');
  63. if (!$date) {
  64. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  65. }
  66. $result = ApiService::getQueryConitions($date);
  67. return self::successResponse($result);
  68. }
  69. //根据单位查人员列表
  70. public function getPeopleByUnit(Request $request){
  71. $result['status'] = true;
  72. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  73. $result['data'] = [];
  74. $depart = Input::get('depart', '');
  75. if($depart != '羊二洗煤厂' && $depart != '羊场湾二分区洗煤厂'){
  76. $result['data'] = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc','like','%'.$depart.'%')->where('is_delete',0)->pluck('zgrxm');
  77. }else{
  78. $result['data'] = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc','like','%羊二洗煤厂%')->orWhere('dwmc','like','%羊场湾二分区洗煤厂%')->where('is_delete',0)->pluck('zgrxm');
  79. }
  80. return $result;
  81. }
  82. //网格化人员轨迹
  83. public function getPersonTravel(Request $request)
  84. {
  85. $person_id = Input::get('person_id', '');
  86. $depart = Input::get('depart', '');
  87. $date = Input::get('date', '');
  88. if (!$person_id || !$depart) {
  89. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  90. }
  91. $result = ApiService::getPersonTravel($person_id, $depart, $date);
  92. return self::successResponse($result);
  93. }
  94. //网格化巡检记录查询条件
  95. public function getResultConition()
  96. {
  97. $result = ApiService::getResultConition();
  98. return self::successResponse($result);
  99. }
  100. //网格化巡检记录查询
  101. public function getResultRecord()
  102. {
  103. $depart = Input::get('depart', 'all');
  104. $date_type = Input::get('date_type', 'week');
  105. $result = ApiService::getResultRecord($depart, $date_type);
  106. return self::successResponse($result);
  107. }
  108. //网格化巡检记录列表
  109. public function getResultList()
  110. {
  111. $person_id = Input::get('person_id', '');
  112. $depart = Input::get('depart', 'all');
  113. $date_type = Input::get('date_type', 'week');
  114. if (!$person_id) {
  115. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  116. }
  117. $result = ApiService::getResultList($person_id, $depart, $date_type);
  118. return self::successResponse($result);
  119. }
  120. //网格化巡检记录列表明细
  121. public function getResultDlist()
  122. {
  123. $person_id = Input::get('person_id', '');
  124. $depart = Input::get('depart', '');
  125. $date = Input::get('date', '');
  126. if (!$person_id || !$depart || !$date) {
  127. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  128. }
  129. $result = ApiService::getResultDlist($person_id, $depart, $date);
  130. return self::successResponse($result);
  131. }
  132. //网格化巡检记录明细
  133. public function getResultDetail()
  134. {
  135. $id = Input::get('id', '');
  136. if (!$id) {
  137. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  138. }
  139. $result = ApiService::getResultDetails($id);
  140. return self::successResponse($result);
  141. }
  142. //网格化巡检记录
  143. public function getFinalList()
  144. {
  145. $start_date = Input::get('start_date', '');
  146. $end_date = Input::get('end_date', '');
  147. $depart = Input::get('depart', '');
  148. $person = Input::get('person', '');
  149. if (!$start_date || !$end_date) {
  150. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  151. }
  152. $result = ApiService::getFinalList($start_date, $end_date, $depart, $person);
  153. return self::successResponse($result);
  154. }
  155. //网格化巡检权限
  156. public function getRole(){
  157. $staff_num = Input::get('staff_num', '');
  158. if (!$staff_num) {
  159. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  160. }
  161. $result['status'] = true;
  162. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  163. $result['data'] = 2;//无权限
  164. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->where('is_delete',0)->get();
  165. if(count($people) > 0){
  166. $result['data'] = 1;//有权限
  167. }
  168. return self::successResponse($result);
  169. }
  170. //设备管理添加设备单位列表
  171. public function sbglUnitList(){
  172. $result['status'] = true;
  173. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  174. $result['data'] = [];
  175. $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_qygl')->where('is_delete',0)->get();
  176. foreach($unit_list as $k => $v){
  177. $result['data'][] = [
  178. 'id' => $v->ID,
  179. 'qymc' => $v->qymc
  180. ];
  181. }
  182. return self::successResponse($result);
  183. }
  184. //设备管理添加设备负责人列表
  185. public function sbglPeopleList(){
  186. $unit_id = Input::get('unit_id', '');
  187. $type = Input::get('type', '');
  188. if (!$unit_id) {
  189. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  190. }
  191. if($type == ''){
  192. $type = 0;
  193. }
  194. $result['status'] = true;
  195. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  196. $result['data'] = [];
  197. if($type == 0){//新设备负责人
  198. $name = 'xsbfzr';
  199. }elseif($type == 2){//待修负责人
  200. $name = 'dxfzr';
  201. }elseif($type == 3){//检修负责人
  202. $name = 'jxfzr';
  203. }elseif($type == 4){//检修验收负责人
  204. $name = 'jxysfzr';
  205. }elseif($type == 5){//鉴定识别(登记核实)负责人
  206. $name = 'dbffzr';
  207. }elseif($type == 6){//固定资产鉴定负责人
  208. $name = 'bffzr';
  209. }
  210. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where($name,0)->where('is_delete',0)->get();
  211. foreach($people_list as $k => $v){
  212. $result['data'][] = [
  213. 'id' => $v->ID,
  214. 'xm' => $v->xm
  215. ];
  216. }
  217. return self::successResponse($result);
  218. }
  219. //设备管理添加新设备
  220. public function sbglAdd(Request $request){
  221. $params = Input::get();
  222. if (!$params) {
  223. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  224. }
  225. $result['status'] = true;
  226. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  227. $result['data'] = [];
  228. $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  229. $insert = [
  230. 'ID' => $id,
  231. 'FORM_DATA_ID' => $id,
  232. 'DATA_INDEX' => 0.0,
  233. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  234. 'TENANT_KEY' => 't1zz9w8165',
  235. 'IS_DELETE' => 0,
  236. 'DELETE_TYPE' => 0,
  237. 'FT_STATUS' => 0,
  238. 'ssdw' => $params['qymc'],
  239. 'xsbdhfzr' => $params['xsbdhfzr'],
  240. 'sbmc' => $params['sbmc'],
  241. 'sbzp' => $params['sbzp'],
  242. 'rhzq' => $params['rhzq'],
  243. 'sbbh' => $params['sbbh'],
  244. 'ggxh' => $params['ggxh'],
  245. 'jscs' => $params['jscs'],
  246. 'sccj' => $params['sccj'],
  247. 'ccrq' => $params['ccrq'],
  248. 'dhrq' => $params['dhrq'],
  249. 'azrq' => $params['azrq'],
  250. 'syrq' => $params['syrq'],
  251. 'zyfssb' => $params['zyfssb'],
  252. 'ptjsj' => $params['ptjsj'],
  253. 'ylohq' => $params['ylohq'],
  254. 'ptqt' => $params['ptqt'],
  255. 'zypj' => $params['zypj'],
  256. 'bz' => $params['bz'],
  257. 'sbzt' => 0,
  258. 'sylx' => 4
  259. ];
  260. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->insert($insert);
  261. return self::successResponse($result);
  262. }
  263. //设备管理设备详情
  264. public function sbglDetail(){
  265. $params = Input::get();
  266. if (!$params) {
  267. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  268. }
  269. $result['status'] = true;
  270. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  271. $data = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
  272. ->select('sbgl.*','qygl.qymc','qygl.wxlx','qygl.ID as qyid')
  273. ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
  274. ->where('sbgl.ID',$params['id'])->get();
  275. // $sbzt = ['新设备到货验收中','完好','待修','检修中','检修验收中','鉴定识别(登记核实)中','已报废','代物资保管'];
  276. // $sylx = ['在用','备用','拆除','检修','闲置'];
  277. // $bflx = ['委外设备废品废件','废品','设备待报废'];
  278. foreach($data as $k=>$v){
  279. $v->xsbfzr_list = [];
  280. $v->dxfzr_list = [];
  281. $v->jxfzr_list = [];
  282. $v->dbffzr_list = [];
  283. $v->bffzr_list = [];
  284. if($v->sbzt == 0){//新设备负责人
  285. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('xsbfzr',0)->where('is_delete',0)->get();
  286. foreach($people_list as $key => $val){
  287. $v->xsbfzr_list[] = [
  288. 'id' => $val->ID,
  289. 'xm' => $val->xm
  290. ];
  291. }
  292. }elseif($v->sbzt == 2){//待修负责人
  293. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dxfzr',0)->where('is_delete',0)->get();
  294. foreach($people_list as $key => $val){
  295. $v->dxfzr_list[] = [
  296. 'id' => $val->ID,
  297. 'xm' => $val->xm
  298. ];
  299. }
  300. }elseif($v->sbzt == 3){//检修负责人
  301. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxfzr',0)->where('is_delete',0)->get();
  302. foreach($people_list as $key => $val){
  303. $v->jxfzr_list[] = [
  304. 'id' => $val->ID,
  305. 'xm' => $val->xm
  306. ];
  307. }
  308. }elseif($v->sbzt == 4){//检修验收负责人
  309. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxysfzr',0)->where('is_delete',0)->get();
  310. foreach($people_list as $key => $val){
  311. $v->jxysfzr_list[] = [
  312. 'id' => $val->ID,
  313. 'xm' => $val->xm
  314. ];
  315. }
  316. }elseif($v->sbzt == 5){//鉴定识别(登记核实)负责人
  317. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dbffzr',0)->where('is_delete',0)->get();
  318. foreach($people_list as $key => $val){
  319. $v->dbffzr_list[] = [
  320. 'id' => $val->ID,
  321. 'xm' => $val->xm
  322. ];
  323. }
  324. }elseif($v->sbzt == 6){//固定资产鉴定负责人
  325. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('bffzr',0)->where('is_delete',0)->get();
  326. foreach($people_list as $key => $val){
  327. $v->bffzr_list[] = [
  328. 'id' => $val->ID,
  329. 'xm' => $val->xm
  330. ];
  331. }
  332. }
  333. if($v->rhzq != null){
  334. $v->rhzq = $v->rhzq.'个月';
  335. }
  336. }
  337. $result['data'] = $data;
  338. return self::successResponse($result);
  339. }
  340. //设备管理润滑管理
  341. public function sbglRhList(){
  342. $result['status'] = true;
  343. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  344. $result['data'] = [];
  345. $current = time();// 获取当前时间戳
  346. $list = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
  347. ->select('sbgl.ID','sbgl.create_time','sbgl.sbmc','sbgl.scrhsj','sbgl.rhzq','qygl.qymc')
  348. ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
  349. ->where('sbgl.rhzq','!=','')->where('sbgl.is_delete',0)->get()->toArray();
  350. foreach($list as $k => $v){
  351. if($v->scrhsj != null){
  352. $scrhsj = strtotime($v->scrhsj);
  353. $sjc = floor(($current - $scrhsj) / (60 * 60 * 24));
  354. $sjc = intval(round($sjc));
  355. $v->sjc = ($v->rhzq*30 - $sjc);
  356. }else{
  357. $create_time = strtotime($v->create_time);
  358. $sjc = floor(($current - $create_time) / (60 * 60 * 24));
  359. $sjc = intval(round($sjc));
  360. $v->sjc = ($v->rhzq*30 - $sjc);
  361. }
  362. }
  363. usort($list, function ($a, $b) {
  364. return $a->sjc <=> $b->sjc;
  365. });
  366. $result['data'] = $list;
  367. return self::successResponse($result);
  368. }
  369. //设备管理设备调拨
  370. public function sbglSbdb(){
  371. $params = Input::get();
  372. if (!$params) {
  373. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  374. }
  375. $result['status'] = true;
  376. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  377. $result['data'] = [];
  378. $update = [
  379. 'ssdw' => $params['unit_id'],
  380. 'sbzt' => $params['sbzt'],
  381. 'sylx' => $params['sylx'],
  382. ];
  383. if(isset($params['sbbh'])){
  384. $update['sbbh'] = $params['sbbh'];
  385. }
  386. if(isset($params['bz'])){
  387. $update['bz'] = $params['bz'];
  388. }
  389. if($params['sbzt'] == 0){
  390. $update['xsbdhfzr'] = $params['fzr_id'];
  391. }
  392. if($params['sbzt'] == 2){
  393. $update['dxfzr'] = $params['fzr_id'];
  394. }
  395. if($params['sbzt'] == 3){
  396. $update['jxfzr'] = $params['fzr_id'];
  397. }
  398. if($params['sbzt'] == 4){
  399. $update['jxysfzr'] = $params['fzr_id'];
  400. }
  401. if($params['sbzt'] == 5){
  402. $update['dbffzr'] = $params['fzr_id'];
  403. }
  404. if($params['sbzt'] == 6){
  405. $update['bffzr'] = $params['fzr_id'];
  406. }
  407. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
  408. return self::successResponse($result);
  409. }
  410. //设备管理设备审核
  411. public function sbglSbsh(){
  412. $params = Input::get();
  413. if (!$params) {
  414. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  415. }
  416. $result['status'] = true;
  417. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  418. $result['data'] = [];
  419. if($params['action'] == 1){//删除设备
  420. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update(['is_delete'=>1]);
  421. return self::successResponse($result);
  422. }
  423. $update = [
  424. 'sbzt' => $params['sbzt'],
  425. 'sylx' => $params['sylx']
  426. ];
  427. if(isset($params['bz'])){
  428. $update['bz'] = $params['bz'];
  429. }
  430. if($params['sbzt'] == 3){
  431. $update['jxfzr'] = $params['fzr_id'];
  432. }
  433. if($params['sbzt'] == 4){
  434. $update['jxysfzr'] = $params['fzr_id'];
  435. }
  436. if($params['sbzt'] == 5){
  437. $update['dbffzr'] = $params['fzr_id'];
  438. }
  439. if($params['sbzt'] == 6){
  440. $update['bffzr'] = $params['fzr_id'];
  441. $update['bflx'] = $params['bflx'];
  442. }
  443. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
  444. return self::successResponse($result);
  445. }
  446. //设备管理权限
  447. public function sbglRole(){
  448. $id = Input::get('id', '');
  449. $staff_num = Input::get('staff_num', '');
  450. $unit_id = Input::get('unit_id', '');
  451. $type = Input::get('type', '');
  452. if (!$unit_id) {
  453. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  454. }
  455. if (!$staff_num) {
  456. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  457. }
  458. if (!$type) {
  459. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  460. }
  461. if (!$id && $type != 'sbgly') {
  462. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  463. }
  464. $result['status'] = true;
  465. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  466. $result['data'] = 2;//无权限
  467. if($type == 'sbgly'){
  468. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where('gh',$staff_num)->where('sbgly',0)->where('is_delete',0)->get();
  469. if(count($people_list) > 0){
  470. $result['data'] = 1;//有权限
  471. }
  472. }else{
  473. $sb = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('id',$id)->get();
  474. if($type == 'xsbdhfzr'){
  475. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->xsbdhfzr)->get();
  476. if($people[0]->gh == $staff_num){
  477. $result['data'] = 1;
  478. }
  479. }
  480. if($type == 'dxfzr'){
  481. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dxfzr)->get();
  482. if($people[0]->gh == $staff_num){
  483. $result['data'] = 1;
  484. }
  485. }
  486. if($type == 'jxfzr'){
  487. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxfzr)->get();
  488. if($people[0]->gh == $staff_num){
  489. $result['data'] = 1;
  490. }
  491. }
  492. if($type == 'jxysfzr'){
  493. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxysfzr)->get();
  494. if($people[0]->gh == $staff_num){
  495. $result['data'] = 1;
  496. }
  497. }
  498. if($type == 'dbffzr'){
  499. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dbffzr)->get();
  500. if($people[0]->gh == $staff_num){
  501. $result['data'] = 1;
  502. }
  503. }
  504. if($type == 'bffzr'){
  505. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->bffzr)->get();
  506. if($people[0]->gh == $staff_num){
  507. $result['data'] = 1;
  508. }
  509. }
  510. }
  511. return self::successResponse($result);
  512. }
  513. //教育学习(洗选中的教育学习应用)
  514. // 学习效果检查统计表
  515. public function learningEffectCheck(Request $request)
  516. {
  517. $params = $request->all();
  518. if(isset($params['start_time']) && isset($params['end_time'])){
  519. $start_time = $params['start_time'];
  520. $end_time = $params['end_time'];
  521. }else{
  522. $start_time = date('Y-m-d 00:00:00');
  523. $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
  524. }
  525. // 自评表数据
  526. $evaluate_data = DB::connection('mysql_fwe10')->table('uf_xx_zpb as t')
  527. ->select('t.dwmc as unitId','t.sgyy','t.sghg','t.sgcljg','t.xqjxjffcs','t.df','t1.dwmc')
  528. ->leftJoin('uf_xx_gxmcdw as t1', 't.dwmc', '=', 't1.id')
  529. ->whereBetween('t.create_time', [$start_time, $end_time])
  530. ->where('t.is_delete',0)
  531. ->where('t.delete_type',0)
  532. ->get();
  533. // 数据库查出来的数据进行处理
  534. $process_data = [];
  535. // 1. 提取所有单位id值
  536. $tmp = [];
  537. $index = 0;
  538. if(count($evaluate_data) > 0){
  539. for ($i = 0; $i < count($evaluate_data); $i++) {
  540. $process_data[$index]['unitId'] = $evaluate_data[$i]->unitId;
  541. $process_data[$index]['sgyy'] = $evaluate_data[$i]->sgyy;
  542. $process_data[$index]['sghg'] = $evaluate_data[$i]->sghg;
  543. $process_data[$index]['sgcljg'] = $evaluate_data[$i]->sgcljg;
  544. $process_data[$index]['xqjxjffcs'] = $evaluate_data[$i]->xqjxjffcs;
  545. $process_data[$index]['df'] = $evaluate_data[$i]->df;
  546. $process_data[$index]['dwmc'] = $evaluate_data[$i]->dwmc;
  547. $index++;
  548. $tmp[] = $evaluate_data[$i]->unitId;
  549. }
  550. }
  551. // 2. 去重并重置索引
  552. $unitId_List = array_values(array_unique($tmp));
  553. // 根据去重后的单位id给$evaluate_data中的数据分组
  554. $grouped = [];
  555. foreach ($process_data as $item) {
  556. $unitId = $item['unitId'];
  557. $grouped[$unitId][] = $item; // 按unitId值分组
  558. }
  559. $result = [];
  560. foreach ($unitId_List as $unitIdVar) {
  561. if (isset($grouped[$unitIdVar])) {
  562. $var1 = $grouped[$unitIdVar]; // 按uniqueBms顺序提取分组
  563. $result[] = $this->dataProcessing($var1);
  564. }
  565. }
  566. // 最后结果需要有个排名
  567. usort($result, function ($a, $b) {
  568. return $b['pjf'] <=> $a['pjf'];
  569. });
  570. $rank = 1;
  571. for ($i = 0; $i < count($result); $i++) {
  572. // 对于同一个 control_num 赋予相同的排名
  573. if ($i > 0 && $result[$i]['pjf'] == $result[$i - 1]['pjf']) {
  574. $result[$i]['rank'] = $result[$i - 1]['rank']; // 保持相同排名
  575. } else {
  576. $result[$i]['rank'] = $rank++; // 否则递增排名
  577. }
  578. }
  579. return self::successResponse($result);
  580. }
  581. // 对每组数据进行统计处理
  582. public function dataProcessing ($data = []): array
  583. {
  584. // 单位名称
  585. $unitName = '';
  586. // 检查人次
  587. $checkPeopleNum = count($data);
  588. // 事故原因
  589. $accidentCause = 0;
  590. // 事故后果
  591. $accidentConsequence = 0;
  592. // 事故处理结果
  593. $resultOfAccidentTreatment = 0;
  594. // 吸取教训/防范措施
  595. $preventiveMeasures = 0;
  596. // 最高分
  597. $theHighestScore = 0;
  598. // 最低分
  599. $theLowestScore = 100;
  600. // 平均分
  601. $averageScore = 0;
  602. foreach ($data as $item) {
  603. $accidentCause += $item['sgyy'];
  604. $accidentConsequence += $item['sghg'];
  605. $resultOfAccidentTreatment += $item['sgcljg'];
  606. $preventiveMeasures += $item['xqjxjffcs'];
  607. if ($theHighestScore < $item['df']) {
  608. $theHighestScore = $item['df'];
  609. }
  610. if ($theLowestScore > $item['df']) {
  611. $theLowestScore = $item['df'];
  612. }
  613. $averageScore += $item['df'];
  614. }
  615. $unitName = reset($data)['dwmc'];
  616. $accidentCause = round($accidentCause / $checkPeopleNum,2);
  617. $accidentConsequence = round($accidentConsequence / $checkPeopleNum,2);
  618. $resultOfAccidentTreatment = round($resultOfAccidentTreatment / $checkPeopleNum,2);
  619. $preventiveMeasures = round($preventiveMeasures / $checkPeopleNum,2);
  620. $averageScore = round($averageScore / $checkPeopleNum,2);
  621. $res = [
  622. 'dwmc' => $unitName,
  623. 'jcrc' => $checkPeopleNum,
  624. 'sgyy' => $accidentCause,
  625. 'sghg' => $accidentConsequence,
  626. 'sgcljg' => $resultOfAccidentTreatment,
  627. 'xqjxjffcs' => $preventiveMeasures,
  628. 'zgf' => $theHighestScore,
  629. 'zdf' => $theLowestScore,
  630. 'pjf' => $averageScore
  631. ];
  632. return $res;
  633. }
  634. //巡检轨迹
  635. public function getGuiji(){
  636. $result['status'] = true;
  637. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  638. $list1 = [];
  639. $date = Input::get('date', '');
  640. $depart = Input::get('depart', '');
  641. $lrr = Input::get('lrr', '');
  642. if (!$date) {
  643. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  644. }
  645. if (!$depart) {
  646. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  647. }
  648. if (!$lrr) {
  649. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  650. }
  651. $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where('lrsj','like','%'.$date.'%')->where('xjdw',$depart)->where('lrr',$lrr)->orderBy('create_time')->get();
  652. if(count($list) > 0){
  653. for($i=0;$i<count($list);$i++){
  654. $list1[$i]['lat'] = $list[$i]->lat;
  655. $list1[$i]['lng'] = $list[$i]->lng;
  656. $list1[$i]['title'] = $list[$i]->xjqy;
  657. $list1[$i]['id'] = $list[$i]->ID;
  658. }
  659. }
  660. //去重
  661. $serialized = array_map('serialize', $list1);
  662. $unique = array_unique($serialized);
  663. $list2 = array_map('unserialize', $unique);
  664. //取中心点
  665. $total = array_reduce($list2, function($carry, $item) {
  666. $carry['lat'] += (float)$item['lat'];
  667. $carry['lng'] += (float)$item['lng'];
  668. return $carry;
  669. }, ['lat' => 0, 'lng' => 0]);
  670. $avgLat = $total['lat'] / count($list2);
  671. $avgLng = $total['lng'] / count($list2);
  672. $result['list1'] = $list1;
  673. $result['list2'] = $list2;
  674. $result['lat'] = $avgLat;
  675. $result['lng'] = $avgLng;
  676. return self::successResponse($result);
  677. }
  678. //获取视频信息
  679. public function getVideoInfo()
  680. {
  681. $result['status'] = true;
  682. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  683. $result['data'] = [];
  684. $spid = Input::get('spid', '');
  685. if (!$spid) {
  686. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  687. }
  688. $res = DB::connection('mysql_fwe10')->table('uf_zhxx_aqsc_aqjsjy')->where('ID',$spid)->get();
  689. if(count($res) > 0){
  690. $result['data']['title'] = $res[0]->bt;
  691. $result['data']['url'] = 'http://10.186.134.157:20600/api/file/preview?fileId='.$res[0]->spsc.'&module=document&type=video&cusMenuId=8442742813977835931&urlPageTitle=5Liq5Lq65paH5qGj5bqT&docId=8445065037895701229&editLinkType=editPage&customParam=%7B%22fromPCDoc%22%3A1%7D';
  692. }
  693. return self::successResponse($result);
  694. }
  695. //问卷调查题目
  696. public function getTopicList()
  697. {
  698. $result['status'] = true;
  699. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  700. $result['data'] = [];
  701. $res = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->select('id','tmlx','xztm','tktm','jdtm','xxa','xxb','xxc','xxd','xxe')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
  702. if(count($res) > 0){
  703. for($i=0;$i<count($res);$i++){
  704. if($res[$i]->tmlx == '3'){//简答题
  705. $res[$i]->tm = $res[$i]->jdtm;
  706. }elseif($res[$i]->tmlx == '2'){//填空题
  707. $res[$i]->tm = $res[$i]->tktm;
  708. }else{//选择题
  709. $res[$i]->tm = $res[$i]->xztm;
  710. }
  711. }
  712. }
  713. $result['data'] = $res;
  714. return self::successResponse($result);
  715. }
  716. //问卷调查统计
  717. public function getTopicStatic()
  718. {
  719. $result['status'] = true;
  720. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  721. $result['data']['title'] = '洗选中心'.date("Y").'年员工思想状况调查问卷';
  722. $jid = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_jgl')->where('is_delete',0)->orderBy('create_time','desc')->limit(1)->pluck('ID')[0];
  723. $tgl_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
  724. $statis_list = [];
  725. if(count($tgl_list) > 0){
  726. for($i=0;$i<count($tgl_list);$i++){
  727. $statis_list[$i]['id'] = $tgl_list[$i]->ID;
  728. $statis_list[$i]['tmlx'] = $tgl_list[$i]->tmlx;
  729. if($tgl_list[$i]->tmlx == 0){//单选题
  730. $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
  731. $statis_list[$i]['type'] = '单选题';
  732. $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
  733. $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
  734. $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
  735. $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
  736. $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
  737. $statis_list[$i]['a_num'] = 0;
  738. $statis_list[$i]['b_num'] = 0;
  739. $statis_list[$i]['c_num'] = 0;
  740. $statis_list[$i]['d_num'] = 0;
  741. $statis_list[$i]['e_num'] = 0;
  742. $statis_list[$i]['num'] = 0;
  743. }
  744. if($tgl_list[$i]->tmlx == 1){//多选题
  745. $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
  746. $statis_list[$i]['type'] = '多选题';
  747. $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
  748. $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
  749. $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
  750. $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
  751. $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
  752. $statis_list[$i]['a_num'] = 0;
  753. $statis_list[$i]['b_num'] = 0;
  754. $statis_list[$i]['c_num'] = 0;
  755. $statis_list[$i]['d_num'] = 0;
  756. $statis_list[$i]['e_num'] = 0;
  757. $statis_list[$i]['num'] = 0;
  758. }
  759. if($tgl_list[$i]->tmlx == 2){//填空题
  760. $statis_list[$i]['title'] = $tgl_list[$i]->tktm;
  761. }
  762. if($tgl_list[$i]->tmlx == 3){//简答题
  763. $statis_list[$i]['title'] = $tgl_list[$i]->jdtm;
  764. }
  765. }
  766. }
  767. $dtqk_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->select('da','tid')->where('jid',$jid)->where('is_delete',0)->get();
  768. $id_list = array_column($statis_list, 'id');
  769. if(count($dtqk_list) > 0){
  770. for($i=0;$i<count($dtqk_list);$i++){
  771. $key = array_search($dtqk_list[$i]->tid, $id_list);
  772. if($statis_list[$key]['tmlx'] == 0){//单选
  773. if($dtqk_list[$i]->da == 'A'){
  774. $statis_list[$key]['a_num']++;
  775. }
  776. if($dtqk_list[$i]->da == 'B'){
  777. $statis_list[$key]['b_num']++;
  778. }
  779. if($dtqk_list[$i]->da == 'C'){
  780. $statis_list[$key]['c_num']++;
  781. }
  782. if($dtqk_list[$i]->da == 'D'){
  783. $statis_list[$key]['d_num']++;
  784. }
  785. if($dtqk_list[$i]->da == 'E'){
  786. $statis_list[$key]['e_num']++;
  787. }
  788. }
  789. if($statis_list[$key]['tmlx'] == 1){//多选
  790. $da = explode(',',$dtqk_list[$i]->da);
  791. for($j=0;$j<count($da);$j++){
  792. if($da[$j] == 'A'){
  793. $statis_list[$key]['a_num']++;
  794. }
  795. if($da[$j] == 'B'){
  796. $statis_list[$key]['b_num']++;
  797. }
  798. if($da[$j] == 'C'){
  799. $statis_list[$key]['c_num']++;
  800. }
  801. if($da[$j] == 'D'){
  802. $statis_list[$key]['d_num']++;
  803. }
  804. if($da[$j] == 'E'){
  805. $statis_list[$key]['e_num']++;
  806. }
  807. }
  808. }
  809. }
  810. }
  811. if(count($statis_list) > 0){
  812. $num = $statis_list[0]['a_num'] + $statis_list[0]['b_num'] + $statis_list[0]['c_num'] + $statis_list[0]['d_num'] + $statis_list[0]['e_num'];
  813. for($i=0;$i<count($statis_list);$i++){
  814. if($statis_list[$i]['tmlx'] == 0){
  815. $statis_list[$i]['num'] = $num;
  816. $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$num)*100, 2).'%';
  817. $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$num)*100, 2).'%';
  818. $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$num)*100, 2).'%';
  819. $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$num)*100, 2).'%';
  820. $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$num)*100, 2).'%';
  821. }
  822. if($statis_list[$i]['tmlx'] == 1){
  823. $statis_list[$i]['num'] = $num;
  824. $n = $statis_list[$i]['a_num']+$statis_list[$i]['b_num']+$statis_list[$i]['c_num']+$statis_list[$i]['d_num']+$statis_list[$i]['e_num'];
  825. $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$n)*100, 2).'%';
  826. $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$n)*100, 2).'%';
  827. $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$n)*100, 2).'%';
  828. $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$n)*100, 2).'%';
  829. $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$n)*100, 2).'%';
  830. }
  831. }
  832. }
  833. $result['data']['list'] = $statis_list;
  834. return self::successResponse($result);
  835. }
  836. //问卷调查单题列表
  837. public function getTopicTestList()
  838. {
  839. $result['status'] = true;
  840. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  841. $result['data'] = [];
  842. $id = Input::get('id', '');
  843. if (!$id) {
  844. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  845. }
  846. $t = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('ID',$id)->get();
  847. $list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->where('tid',$id)->where('is_delete',0)->orderBy('create_time')->pluck('da');
  848. if($t[0]->tmlx == 2){//填空
  849. $result['data']['title'] = $t[0]->tktm;
  850. }
  851. if($t[0]->tmlx == 3){//简答
  852. $result['data']['title'] = $t[0]->jdtm;
  853. }
  854. $result['data']['list'] = [];
  855. if(count($list) > 0){
  856. for($i=0;$i<count($list);$i++){
  857. if($list[$i] != '无' && $list[$i] != '没有'){
  858. array_push($result['data']['list'],$list[$i]);
  859. }
  860. }
  861. }
  862. return self::successResponse($result);
  863. }
  864. //问卷调查提交
  865. public function submitTopic(Request $request)
  866. {
  867. $params = $request->all();
  868. $result['status'] = true;
  869. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  870. $list = $params['answer'];
  871. if(count($list) > 0){
  872. for($i=0;$i<count($list);$i++){
  873. $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  874. if (is_array($list[$i]['value'])) {
  875. $value = implode(',', $list[$i]['value']);
  876. } else {
  877. $value = $list[$i]['value'];
  878. }
  879. $insert = [
  880. 'ID' => $id,
  881. 'FORM_DATA_ID' => $id,
  882. 'DATA_INDEX' => 0.0,
  883. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  884. 'TENANT_KEY' => 't1zz9w8165',
  885. 'IS_DELETE' => 0,
  886. 'DELETE_TYPE' => 0,
  887. 'FT_STATUS' => 0,
  888. 'jid' => $params['jid'],
  889. 'da' => $value,
  890. 'tid' => $list[$i]['id'],
  891. 'xm' => $params['xm'],
  892. 'gh' => $params['gh']
  893. ];
  894. DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->insert($insert);
  895. }
  896. }
  897. return self::successResponse($result);
  898. }
  899. //腾讯地图逆地址解析
  900. public function positionGeocoder(){
  901. $lat = Input::get('lat', '');//纬度
  902. $lng = Input::get('lng', '');//经度
  903. if (!$lat) {
  904. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  905. }
  906. if (!$lng) {
  907. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  908. }
  909. $gps = $lat.','.$lng;
  910. $sig = '/ws/geocoder/v1?key='.env('TX_KEY').'&location='.$gps.env('TX_SK');
  911. $sig = md5($sig);
  912. $params = [
  913. 'location' => $gps,
  914. 'key' => env('TX_KEY'),
  915. 'sig' => $sig
  916. ];
  917. $result = $this->sendRequest("https://apis.map.qq.com/ws/geocoder/v1",$params);
  918. $position = '';
  919. if(isset($result['result']['formatted_addresses']['recommend'])){
  920. $position = $result['result']['formatted_addresses']['recommend'];
  921. }
  922. return self::successResponse($position);
  923. }
  924. //微信公众号获取文章列表
  925. public function getWechatArticleList(){
  926. $res = $this->getaccessToken();
  927. // dd($res);
  928. if($res['access_token']){
  929. // 获取已发布但未群发的文章
  930. $access_token = $res['access_token'];
  931. $url = 'https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token='.$access_token;
  932. $params = [
  933. "offset" => 0,
  934. "no_content" => 1,
  935. "count" => 10
  936. ];
  937. $result = $this->httpRequest($url,'post',$params);
  938. return $result;
  939. // 获取永久图文素材(已群发)
  940. // $access_token = $res['access_token'];
  941. // $url = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$access_token;
  942. // $params = [
  943. // "type" => 'news',
  944. // "offset" => 0,
  945. // "count" => 20
  946. // ];
  947. // $result = $this->httpRequest($url,'post',$params);
  948. // return $result;
  949. // 获取草稿列表
  950. // $access_token = $res['access_token'];
  951. // $url = 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$access_token;
  952. // $params = [
  953. // "offset" => 0,
  954. // "no_content" => 1,
  955. // "count" => 200
  956. // ];
  957. // $result = $this->httpRequest($url,'post',$params);
  958. // return $result;
  959. }
  960. }
  961. //微信公众号获取access_token
  962. public function getaccessToken(){
  963. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.env('MZY_WECHAT_APPID').'&secret='.env('MZY_WECHAT_APPSECRET');
  964. $result = $this->httpRequest($url,'GET',[]);
  965. return $result;
  966. }
  967. //公管公司值班日历
  968. public function dutyCalendar(){
  969. $result['status'] = true;
  970. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  971. $result['data'] = [];
  972. $riqi = Input::get('riqi', '');
  973. if (!$riqi) {
  974. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  975. }
  976. $result['title'] = date('Y年n月j日', strtotime($riqi)).'值班信息';
  977. $zbInfo = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$riqi)->orderBy('CREATE_TIME','desc')->first();
  978. if (!$zbInfo) {
  979. return self::successResponse($result);
  980. }
  981. $data = [
  982. // 'title' => date('Y年n月j日', strtotime($riqi)).'值班信息',
  983. 'zzb' => [], // 主值班
  984. 'fzb' => [], // 副值班
  985. 'gbdd' => [], // 跟班地点
  986. 'zbsj' => [], // 值班司机
  987. 'pmyzx' => [], // 配煤一中心
  988. 'pmezx' => [], // 配煤二中心
  989. 'whzx' => [], // 维护中心
  990. 'dyzx' => [], // 电仪中心
  991. 'zczx' => [], // 渣场中心
  992. 'zabw' => [], // 治安保卫
  993. 'ylzx' => [], // 原料中心
  994. 'hqzx' => [] // 后勤中心
  995. ];
  996. $fieldMap = [
  997. 'zzb' => ['zzb'],
  998. 'fzb' => ['fzb1', 'fzb2'],
  999. 'gbdd' => ['gbdd1','gbdd2'],
  1000. 'zbsj' => ['zbsj'],
  1001. 'pmyzx' => ['pmyzx1','pmyzx2'],
  1002. 'pmezx' => ['pmezx1','pmezx2'],
  1003. 'whzx' => ['whzx1','whzx2'],
  1004. 'dyzx' => ['dyzx1','dyzx2'],
  1005. 'zczx' => ['zczx1','zczx2'],
  1006. 'zabw' => ['zabw1','zabw2'],
  1007. 'ylzx' => ['ylzx1','ylzx2'],
  1008. 'hqzx' => ['hqzx1','hqzx2'],
  1009. ];
  1010. $namesToQuery = array_filter([
  1011. $zbInfo->zzb,
  1012. $zbInfo->fzb1,
  1013. $zbInfo->fzb2,
  1014. $zbInfo->zbsj,
  1015. $zbInfo->pmyzx1,
  1016. $zbInfo->pmyzx2,
  1017. $zbInfo->pmezx1,
  1018. $zbInfo->pmezx2,
  1019. $zbInfo->whzx1,
  1020. $zbInfo->whzx2,
  1021. $zbInfo->dyzx1,
  1022. $zbInfo->dyzx2,
  1023. $zbInfo->zczx1,
  1024. $zbInfo->zczx2,
  1025. $zbInfo->zabw1,
  1026. $zbInfo->zabw2,
  1027. $zbInfo->ylzx1,
  1028. $zbInfo->ylzx2,
  1029. $zbInfo->hqzx1,
  1030. $zbInfo->hqzx2
  1031. ]);
  1032. $peopleInfo = [];
  1033. if (!empty($namesToQuery)) {
  1034. $peopleData = DB::connection('mysql_fwe10')
  1035. ->table('uf_gggs_rygl as r1')
  1036. ->whereIn('xm', $namesToQuery)
  1037. ->whereRaw('CREATE_TIME = (
  1038. SELECT MAX(CREATE_TIME)
  1039. FROM uf_gggs_rygl as r2
  1040. WHERE r2.xm = r1.xm)')
  1041. ->get()
  1042. ->keyBy('xm');
  1043. foreach ($peopleData as $person) {
  1044. $peopleInfo[$person->xm] = $person->dh ?? '';
  1045. }
  1046. }
  1047. foreach ($fieldMap as $dataKey => $dbFields) {
  1048. foreach ($dbFields as $field) {
  1049. if (!empty($zbInfo->$field)) {
  1050. $name = $zbInfo->$field;
  1051. $phone = $peopleInfo[$name] ?? '';
  1052. $data[$dataKey][] = $phone ? $name . $phone : $name;
  1053. }
  1054. }
  1055. }
  1056. $result['data'] = $data;
  1057. return self::successResponse($result);
  1058. }
  1059. //公管公司值班查询
  1060. public function dutySearch(){
  1061. $result['status'] = true;
  1062. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  1063. $result['data'] = [];
  1064. $name = Input::get('name', '');
  1065. $start_date = Input::get('start_date', '');
  1066. $end_date = Input::get('end_date', '');
  1067. if (!$name) {
  1068. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1069. }
  1070. if (!$start_date) {
  1071. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1072. }
  1073. if (!$end_date) {
  1074. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1075. }
  1076. $people = DB::connection('mysql_fwe10')->table('uf_gggs_rygl')->where('xm',$name)->orderBy('create_time','desc')->first();
  1077. $mobile = '';
  1078. if(!empty($people) && $people->dh != null && $people->dh != ''){
  1079. $mobile = '('.$people->dh.')';
  1080. }
  1081. $result['title'] = $name.$mobile.date('Y年n月j日', strtotime($start_date)).'至'.date('Y年n月j日', strtotime($end_date)).'值班记录';
  1082. $list = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->whereBetween('riqi', [$start_date, $end_date])
  1083. ->whereIn('id', function($subQuery) {
  1084. $subQuery->selectRaw('MAX(id)') // 获取每个日期的最大create_time对应的记录
  1085. ->from('uf_gggs_zbgl')
  1086. ->groupBy('riqi'); // 按riqi分组
  1087. })->orderBy('riqi')->get();
  1088. $data = [];
  1089. if(count($list) > 0){
  1090. for($i=0;$i<count($list);$i++){
  1091. $riqi = date('Y/n/j', strtotime($list[$i]->riqi));
  1092. if($list[$i]->zzb == $name){
  1093. array_push($data,[
  1094. 'date'=>$riqi,
  1095. 'title'=>'主值班'
  1096. ]);
  1097. }
  1098. if($list[$i]->fzb1 == $name){
  1099. array_push($data,[
  1100. 'date'=>$riqi,
  1101. 'title'=>'副值班'
  1102. ]);
  1103. }
  1104. if($list[$i]->fzb2 == $name){
  1105. array_push($data,[
  1106. 'date'=>$riqi,
  1107. 'title'=>'副值班'
  1108. ]);
  1109. }
  1110. if($list[$i]->zbsj == $name){
  1111. array_push($data,[
  1112. 'date'=>$riqi,
  1113. 'title'=>'值班司机'
  1114. ]);
  1115. }
  1116. if($list[$i]->pmyzx1 == $name){
  1117. array_push($data,[
  1118. 'date'=>$riqi,
  1119. 'title'=>'配煤一中心'
  1120. ]);
  1121. }
  1122. if($list[$i]->pmyzx2 == $name){
  1123. array_push($data,[
  1124. 'date'=>$riqi,
  1125. 'title'=>'配煤一中心'
  1126. ]);
  1127. }
  1128. if($list[$i]->pmezx1 == $name){
  1129. array_push($data,[
  1130. 'date'=>$riqi,
  1131. 'title'=>'配煤二中心'
  1132. ]);
  1133. }
  1134. if($list[$i]->pmezx2 == $name){
  1135. array_push($data,[
  1136. 'date'=>$riqi,
  1137. 'title'=>'配煤二中心'
  1138. ]);
  1139. }
  1140. if($list[$i]->whzx1 == $name){
  1141. array_push($data,[
  1142. 'date'=>$riqi,
  1143. 'title'=>'维护中心'
  1144. ]);
  1145. }
  1146. if($list[$i]->whzx2 == $name){
  1147. array_push($data,[
  1148. 'date'=>$riqi,
  1149. 'title'=>'维护中心'
  1150. ]);
  1151. }
  1152. if($list[$i]->dyzx1 == $name){
  1153. array_push($data,[
  1154. 'date'=>$riqi,
  1155. 'title'=>'电仪中心'
  1156. ]);
  1157. }
  1158. if($list[$i]->dyzx2 == $name){
  1159. array_push($data,[
  1160. 'date'=>$riqi,
  1161. 'title'=>'电仪中心'
  1162. ]);
  1163. }
  1164. if($list[$i]->zczx1 == $name){
  1165. array_push($data,[
  1166. 'date'=>$riqi,
  1167. 'title'=>'渣场中心'
  1168. ]);
  1169. }
  1170. if($list[$i]->zczx2 == $name){
  1171. array_push($data,[
  1172. 'date'=>$riqi,
  1173. 'title'=>'渣场中心'
  1174. ]);
  1175. }
  1176. if($list[$i]->zabw1 == $name){
  1177. array_push($data,[
  1178. 'date'=>$riqi,
  1179. 'title'=>'治安保卫'
  1180. ]);
  1181. }
  1182. if($list[$i]->zabw2 == $name){
  1183. array_push($data,[
  1184. 'date'=>$riqi,
  1185. 'title'=>'治安保卫'
  1186. ]);
  1187. }
  1188. if($list[$i]->ylzx1 == $name){
  1189. array_push($data,[
  1190. 'date'=>$riqi,
  1191. 'title'=>'原料中心'
  1192. ]);
  1193. }
  1194. if($list[$i]->ylzx2 == $name){
  1195. array_push($data,[
  1196. 'date'=>$riqi,
  1197. 'title'=>'原料中心'
  1198. ]);
  1199. }
  1200. if($list[$i]->hqzx1 == $name){
  1201. array_push($data,[
  1202. 'date'=>$riqi,
  1203. 'title'=>'后勤中心'
  1204. ]);
  1205. }
  1206. if($list[$i]->hqzx2 == $name){
  1207. array_push($data,[
  1208. 'date'=>$riqi,
  1209. 'title'=>'后勤中心'
  1210. ]);
  1211. }
  1212. }
  1213. }
  1214. $result['data'] =$data;
  1215. return self::successResponse($result);
  1216. }
  1217. //腾讯位置接口服务
  1218. public function sendRequest($url, $params) {
  1219. $ch = curl_init();
  1220. curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
  1221. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1222. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1223. $response = curl_exec($ch);
  1224. curl_close($ch);
  1225. return json_decode($response, true);
  1226. }
  1227. public function httpRequest($url, $format = 'get', $data = null){
  1228. //设置头信息
  1229. $headerArray =array("Content-type:application/json;","Accept:application/json");
  1230. $curl=curl_init();
  1231. curl_setopt($curl, CURLOPT_URL, $url);
  1232. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  1233. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  1234. if ($format == 'post') {
  1235. //post传值设置post传参
  1236. curl_setopt($curl, CURLOPT_POST, 1);
  1237. if ($data) {
  1238. $data = json_encode($data);
  1239. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  1240. }
  1241. }
  1242. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1243. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  1244. $data=json_decode(curl_exec($curl), true);
  1245. curl_close($curl);
  1246. //返回接口返回数据
  1247. return $data;
  1248. }
  1249. }