ApiController.php 57 KB

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