ApiController.php 57 KB

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