ApiController.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  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. $result['status'] = true;
  1031. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  1032. $result['data'] = [];
  1033. $zt = $request->query('zt');
  1034. $res = DB::connection('mysql_fwe10')->table('uf_xx_dtk')
  1035. ->select('id','tmlx','tm','xxa','xxb','xxc','xxd','xxe')
  1036. ->where('is_delete',0)
  1037. ->where('sjzt',$zt)
  1038. ->orderBy('tmlx')
  1039. ->orderBy('create_time')->get();
  1040. $result['data'] = $res;
  1041. return self::successResponse($result);
  1042. }
  1043. //腾讯地图逆地址解析
  1044. public function positionGeocoder(){
  1045. $lat = Input::get('lat', '');//纬度
  1046. $lng = Input::get('lng', '');//经度
  1047. if (!$lat) {
  1048. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1049. }
  1050. if (!$lng) {
  1051. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1052. }
  1053. $gps = $lat.','.$lng;
  1054. $sig = '/ws/geocoder/v1?key='.env('TX_KEY').'&location='.$gps.env('TX_SK');
  1055. $sig = md5($sig);
  1056. $params = [
  1057. 'location' => $gps,
  1058. 'key' => env('TX_KEY'),
  1059. 'sig' => $sig
  1060. ];
  1061. $result = $this->sendRequest("https://apis.map.qq.com/ws/geocoder/v1",$params);
  1062. $position = '';
  1063. if(isset($result['result']['formatted_addresses']['recommend'])){
  1064. $position = $result['result']['formatted_addresses']['recommend'];
  1065. }
  1066. return self::successResponse($position);
  1067. }
  1068. //微信公众号获取文章列表
  1069. public function getWechatArticleList(){
  1070. $res = $this->getaccessToken();
  1071. // dd($res);
  1072. if($res['access_token']){
  1073. // 获取已发布但未群发的文章
  1074. $access_token = $res['access_token'];
  1075. $url = 'https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token='.$access_token;
  1076. $params = [
  1077. "offset" => 0,
  1078. "no_content" => 1,
  1079. "count" => 10
  1080. ];
  1081. $result = $this->httpRequest($url,'post',$params);
  1082. return $result;
  1083. // 获取永久图文素材(已群发)
  1084. // $access_token = $res['access_token'];
  1085. // $url = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$access_token;
  1086. // $params = [
  1087. // "type" => 'news',
  1088. // "offset" => 0,
  1089. // "count" => 20
  1090. // ];
  1091. // $result = $this->httpRequest($url,'post',$params);
  1092. // return $result;
  1093. // 获取草稿列表
  1094. // $access_token = $res['access_token'];
  1095. // $url = 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$access_token;
  1096. // $params = [
  1097. // "offset" => 0,
  1098. // "no_content" => 1,
  1099. // "count" => 200
  1100. // ];
  1101. // $result = $this->httpRequest($url,'post',$params);
  1102. // return $result;
  1103. }
  1104. }
  1105. //微信公众号获取access_token
  1106. public function getaccessToken(){
  1107. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.env('MZY_WECHAT_APPID').'&secret='.env('MZY_WECHAT_APPSECRET');
  1108. $result = $this->httpRequest($url,'GET',[]);
  1109. return $result;
  1110. }
  1111. //公管公司值班日历
  1112. public function dutyCalendar(){
  1113. $result['status'] = true;
  1114. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  1115. $result['data'] = [];
  1116. $riqi = Input::get('riqi', '');
  1117. if (!$riqi) {
  1118. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1119. }
  1120. $result['title'] = date('Y年n月j日', strtotime($riqi)).'值班信息';
  1121. $zbInfo = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$riqi)->where('is_delete',0)->orderBy('CREATE_TIME','desc')->first();
  1122. if (!$zbInfo) {
  1123. return self::successResponse($result);
  1124. }
  1125. $data = [
  1126. // 'title' => date('Y年n月j日', strtotime($riqi)).'值班信息',
  1127. 'zzb' => [], // 主值班
  1128. 'fzb' => [], // 副值班
  1129. 'gbdd' => [], // 跟班地点
  1130. 'zbsj' => [], // 值班司机
  1131. 'pmyzx' => [], // 配煤一中心
  1132. 'pmezx' => [], // 配煤二中心
  1133. 'whzx' => [], // 维护中心
  1134. 'dyzx' => [], // 电仪中心
  1135. 'zczx' => [], // 渣场中心
  1136. 'zabw' => [], // 治安保卫
  1137. 'ylzx' => [], // 原料中心
  1138. 'hqzx' => [] // 后勤中心
  1139. ];
  1140. $fieldMap = [
  1141. 'zzb' => ['zzb'],
  1142. 'fzb' => ['fzb1', 'fzb2'],
  1143. 'gbdd' => ['gbdd1','gbdd2'],
  1144. 'zbsj' => ['zbsj'],
  1145. 'pmyzx' => ['pmyzx1','pmyzx2'],
  1146. 'pmezx' => ['pmezx1','pmezx2'],
  1147. 'whzx' => ['whzx1','whzx2'],
  1148. 'dyzx' => ['dyzx1','dyzx2'],
  1149. 'zczx' => ['zczx1','zczx2'],
  1150. 'zabw' => ['zabw1','zabw2'],
  1151. 'ylzx' => ['ylzx1','ylzx2'],
  1152. 'hqzx' => ['hqzx1','hqzx2'],
  1153. ];
  1154. $namesToQuery = array_filter([
  1155. $zbInfo->zzb,
  1156. $zbInfo->fzb1,
  1157. $zbInfo->fzb2,
  1158. $zbInfo->zbsj,
  1159. $zbInfo->pmyzx1,
  1160. $zbInfo->pmyzx2,
  1161. $zbInfo->pmezx1,
  1162. $zbInfo->pmezx2,
  1163. $zbInfo->whzx1,
  1164. $zbInfo->whzx2,
  1165. $zbInfo->dyzx1,
  1166. $zbInfo->dyzx2,
  1167. $zbInfo->zczx1,
  1168. $zbInfo->zczx2,
  1169. $zbInfo->zabw1,
  1170. $zbInfo->zabw2,
  1171. $zbInfo->ylzx1,
  1172. $zbInfo->ylzx2,
  1173. $zbInfo->hqzx1,
  1174. $zbInfo->hqzx2
  1175. ]);
  1176. $peopleInfo = [];
  1177. if (!empty($namesToQuery)) {
  1178. $peopleData = DB::connection('mysql_fwe10')
  1179. ->table('uf_gggs_rygl as r1')
  1180. ->whereIn('xm', $namesToQuery)
  1181. ->whereRaw('CREATE_TIME = (
  1182. SELECT MAX(CREATE_TIME)
  1183. FROM uf_gggs_rygl as r2
  1184. WHERE r2.xm = r1.xm)')
  1185. ->where('is_delete',0)
  1186. ->get()
  1187. ->keyBy('xm');
  1188. foreach ($peopleData as $person) {
  1189. $peopleInfo[$person->xm] = $person->dh ?? '';
  1190. }
  1191. }
  1192. foreach ($fieldMap as $dataKey => $dbFields) {
  1193. foreach ($dbFields as $field) {
  1194. if (!empty($zbInfo->$field)) {
  1195. $name = $zbInfo->$field;
  1196. $phone = $peopleInfo[$name] ?? '';
  1197. $data[$dataKey][] = $phone ? $name . $phone : $name;
  1198. }
  1199. }
  1200. }
  1201. $result['data'] = $data;
  1202. return self::successResponse($result);
  1203. }
  1204. //公管公司值班查询
  1205. public function dutySearch(){
  1206. $result['status'] = true;
  1207. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  1208. $result['data'] = [];
  1209. $name = Input::get('name', '');
  1210. $start_date = Input::get('start_date', '');
  1211. $end_date = Input::get('end_date', '');
  1212. if (!$name) {
  1213. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1214. }
  1215. if (!$start_date) {
  1216. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1217. }
  1218. if (!$end_date) {
  1219. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1220. }
  1221. $people = DB::connection('mysql_fwe10')->table('uf_gggs_rygl')->where('xm',$name)->where('is_delete',0)->orderBy('create_time','desc')->first();
  1222. $mobile = '';
  1223. if(!empty($people) && $people->dh != null && $people->dh != ''){
  1224. $mobile = '('.$people->dh.')';
  1225. }
  1226. $result['title'] = $name.$mobile.date('Y年n月j日', strtotime($start_date)).'至'.date('Y年n月j日', strtotime($end_date)).'值班记录';
  1227. $list = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->whereBetween('riqi', [$start_date, $end_date])
  1228. ->whereIn('id', function($subQuery) {
  1229. $subQuery->selectRaw('MAX(id)') // 获取每个日期的最大create_time对应的记录
  1230. ->from('uf_gggs_zbgl')
  1231. ->groupBy('riqi'); // 按riqi分组
  1232. })->where('is_delete',0)->orderBy('riqi')->get();
  1233. $data = [];
  1234. if(count($list) > 0){
  1235. for($i=0;$i<count($list);$i++){
  1236. $riqi = date('Y/n/j', strtotime($list[$i]->riqi));
  1237. if($list[$i]->zzb == $name){
  1238. array_push($data,[
  1239. 'date'=>$riqi,
  1240. 'title'=>'主值班'
  1241. ]);
  1242. }
  1243. if($list[$i]->fzb1 == $name){
  1244. array_push($data,[
  1245. 'date'=>$riqi,
  1246. 'title'=>'副值班'
  1247. ]);
  1248. }
  1249. if($list[$i]->fzb2 == $name){
  1250. array_push($data,[
  1251. 'date'=>$riqi,
  1252. 'title'=>'副值班'
  1253. ]);
  1254. }
  1255. if($list[$i]->zbsj == $name){
  1256. array_push($data,[
  1257. 'date'=>$riqi,
  1258. 'title'=>'值班司机'
  1259. ]);
  1260. }
  1261. if($list[$i]->pmyzx1 == $name){
  1262. array_push($data,[
  1263. 'date'=>$riqi,
  1264. 'title'=>'配煤一中心'
  1265. ]);
  1266. }
  1267. if($list[$i]->pmyzx2 == $name){
  1268. array_push($data,[
  1269. 'date'=>$riqi,
  1270. 'title'=>'配煤一中心'
  1271. ]);
  1272. }
  1273. if($list[$i]->pmezx1 == $name){
  1274. array_push($data,[
  1275. 'date'=>$riqi,
  1276. 'title'=>'配煤二中心'
  1277. ]);
  1278. }
  1279. if($list[$i]->pmezx2 == $name){
  1280. array_push($data,[
  1281. 'date'=>$riqi,
  1282. 'title'=>'配煤二中心'
  1283. ]);
  1284. }
  1285. if($list[$i]->whzx1 == $name){
  1286. array_push($data,[
  1287. 'date'=>$riqi,
  1288. 'title'=>'维护中心'
  1289. ]);
  1290. }
  1291. if($list[$i]->whzx2 == $name){
  1292. array_push($data,[
  1293. 'date'=>$riqi,
  1294. 'title'=>'维护中心'
  1295. ]);
  1296. }
  1297. if($list[$i]->dyzx1 == $name){
  1298. array_push($data,[
  1299. 'date'=>$riqi,
  1300. 'title'=>'电仪中心'
  1301. ]);
  1302. }
  1303. if($list[$i]->dyzx2 == $name){
  1304. array_push($data,[
  1305. 'date'=>$riqi,
  1306. 'title'=>'电仪中心'
  1307. ]);
  1308. }
  1309. if($list[$i]->zczx1 == $name){
  1310. array_push($data,[
  1311. 'date'=>$riqi,
  1312. 'title'=>'渣场中心'
  1313. ]);
  1314. }
  1315. if($list[$i]->zczx2 == $name){
  1316. array_push($data,[
  1317. 'date'=>$riqi,
  1318. 'title'=>'渣场中心'
  1319. ]);
  1320. }
  1321. if($list[$i]->zabw1 == $name){
  1322. array_push($data,[
  1323. 'date'=>$riqi,
  1324. 'title'=>'治安保卫'
  1325. ]);
  1326. }
  1327. if($list[$i]->zabw2 == $name){
  1328. array_push($data,[
  1329. 'date'=>$riqi,
  1330. 'title'=>'治安保卫'
  1331. ]);
  1332. }
  1333. if($list[$i]->ylzx1 == $name){
  1334. array_push($data,[
  1335. 'date'=>$riqi,
  1336. 'title'=>'原料中心'
  1337. ]);
  1338. }
  1339. if($list[$i]->ylzx2 == $name){
  1340. array_push($data,[
  1341. 'date'=>$riqi,
  1342. 'title'=>'原料中心'
  1343. ]);
  1344. }
  1345. if($list[$i]->hqzx1 == $name){
  1346. array_push($data,[
  1347. 'date'=>$riqi,
  1348. 'title'=>'后勤中心'
  1349. ]);
  1350. }
  1351. if($list[$i]->hqzx2 == $name){
  1352. array_push($data,[
  1353. 'date'=>$riqi,
  1354. 'title'=>'后勤中心'
  1355. ]);
  1356. }
  1357. }
  1358. }
  1359. $result['data'] =$data;
  1360. return self::successResponse($result);
  1361. }
  1362. //腾讯位置接口服务
  1363. public function sendRequest($url, $params) {
  1364. $ch = curl_init();
  1365. curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
  1366. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1367. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1368. $response = curl_exec($ch);
  1369. curl_close($ch);
  1370. return json_decode($response, true);
  1371. }
  1372. public function httpRequest($url, $format = 'get', $data = null){
  1373. //设置头信息
  1374. $headerArray =array("Content-type:application/json;","Accept:application/json");
  1375. $curl=curl_init();
  1376. curl_setopt($curl, CURLOPT_URL, $url);
  1377. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  1378. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  1379. if ($format == 'post') {
  1380. //post传值设置post传参
  1381. curl_setopt($curl, CURLOPT_POST, 1);
  1382. if ($data) {
  1383. $data = json_encode($data);
  1384. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  1385. }
  1386. }
  1387. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1388. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  1389. $data=json_decode(curl_exec($curl), true);
  1390. curl_close($curl);
  1391. //返回接口返回数据
  1392. return $data;
  1393. }
  1394. }