ApiController.php 61 KB

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