ApiController.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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 getPersonTravel(Request $request)
  71. {
  72. $person_id = Input::get('person_id', '');
  73. $depart = Input::get('depart', '');
  74. $date = Input::get('date', '');
  75. if (!$person_id || !$depart) {
  76. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  77. }
  78. $result = ApiService::getPersonTravel($person_id, $depart, $date);
  79. return self::successResponse($result);
  80. }
  81. //网格化巡检记录查询条件
  82. public function getResultConition()
  83. {
  84. $result = ApiService::getResultConition();
  85. return self::successResponse($result);
  86. }
  87. //网格化巡检记录查询
  88. public function getResultRecord()
  89. {
  90. $depart = Input::get('depart', 'all');
  91. $date_type = Input::get('date_type', 'week');
  92. $result = ApiService::getResultRecord($depart, $date_type);
  93. return self::successResponse($result);
  94. }
  95. //网格化巡检记录列表
  96. public function getResultList()
  97. {
  98. $person_id = Input::get('person_id', '');
  99. $depart = Input::get('depart', 'all');
  100. $date_type = Input::get('date_type', 'week');
  101. if (!$person_id) {
  102. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  103. }
  104. $result = ApiService::getResultList($person_id, $depart, $date_type);
  105. return self::successResponse($result);
  106. }
  107. //网格化巡检记录列表明细
  108. public function getResultDlist()
  109. {
  110. $person_id = Input::get('person_id', '');
  111. $depart = Input::get('depart', '');
  112. $date = Input::get('date', '');
  113. if (!$person_id || !$depart || !$date) {
  114. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  115. }
  116. $result = ApiService::getResultDlist($person_id, $depart, $date);
  117. return self::successResponse($result);
  118. }
  119. //网格化巡检记录明细
  120. public function getResultDetail()
  121. {
  122. $id = Input::get('id', '');
  123. if (!$id) {
  124. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  125. }
  126. $result = ApiService::getResultDetails($id);
  127. return self::successResponse($result);
  128. }
  129. //网格化巡检记录
  130. public function getFinalList()
  131. {
  132. $start_date = Input::get('start_date', '');
  133. $end_date = Input::get('end_date', '');
  134. $depart = Input::get('depart', '');
  135. $person = Input::get('person', '');
  136. if (!$start_date || !$end_date) {
  137. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  138. }
  139. $result = ApiService::getFinalList($start_date, $end_date, $depart, $person);
  140. return self::successResponse($result);
  141. }
  142. //网格化巡检权限
  143. public function getRole(){
  144. $staff_num = Input::get('staff_num', '');
  145. if (!$staff_num) {
  146. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  147. }
  148. $result['status'] = true;
  149. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  150. $result['data'] = 2;//无权限
  151. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->where('is_delete',0)->get();
  152. if(count($people) > 0){
  153. $result['data'] = 1;//有权限
  154. }
  155. return self::successResponse($result);
  156. }
  157. //设备管理添加设备单位列表
  158. public function sbglUnitList(){
  159. $result['status'] = true;
  160. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  161. $result['data'] = [];
  162. $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_qygl')->where('is_delete',0)->get();
  163. foreach($unit_list as $k => $v){
  164. $result['data'][] = [
  165. 'id' => $v->ID,
  166. 'qymc' => $v->qymc
  167. ];
  168. }
  169. return self::successResponse($result);
  170. }
  171. //设备管理添加设备负责人列表
  172. public function sbglPeopleList(){
  173. $unit_id = Input::get('unit_id', '');
  174. $type = Input::get('type', '');
  175. if (!$unit_id) {
  176. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  177. }
  178. if($type == ''){
  179. $type = 0;
  180. }
  181. $result['status'] = true;
  182. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  183. $result['data'] = [];
  184. if($type == 0){//新设备负责人
  185. $name = 'xsbfzr';
  186. }elseif($type == 2){//待修负责人
  187. $name = 'dxfzr';
  188. }elseif($type == 3){//检修负责人
  189. $name = 'jxfzr';
  190. }elseif($type == 4){//检修验收负责人
  191. $name = 'jxysfzr';
  192. }elseif($type == 5){//鉴定识别(登记核实)负责人
  193. $name = 'dbffzr';
  194. }elseif($type == 6){//固定资产鉴定负责人
  195. $name = 'bffzr';
  196. }
  197. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where($name,0)->where('is_delete',0)->get();
  198. foreach($people_list as $k => $v){
  199. $result['data'][] = [
  200. 'id' => $v->ID,
  201. 'xm' => $v->xm
  202. ];
  203. }
  204. return self::successResponse($result);
  205. }
  206. //设备管理添加新设备
  207. public function sbglAdd(Request $request){
  208. $params = Input::get();
  209. if (!$params) {
  210. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  211. }
  212. $result['status'] = true;
  213. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  214. $result['data'] = [];
  215. $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  216. $insert = [
  217. 'ID' => $id,
  218. 'FORM_DATA_ID' => $id,
  219. 'DATA_INDEX' => 0.0,
  220. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  221. 'TENANT_KEY' => 't1zz9w8165',
  222. 'IS_DELETE' => 0,
  223. 'DELETE_TYPE' => 0,
  224. 'FT_STATUS' => 0,
  225. 'ssdw' => $params['qymc'],
  226. 'xsbdhfzr' => $params['xsbdhfzr'],
  227. 'sbmc' => $params['sbmc'],
  228. 'sbzp' => $params['sbzp'],
  229. 'rhzq' => $params['rhzq'],
  230. 'sbbh' => $params['sbbh'],
  231. 'ggxh' => $params['ggxh'],
  232. 'jscs' => $params['jscs'],
  233. 'sccj' => $params['sccj'],
  234. 'ccrq' => $params['ccrq'],
  235. 'dhrq' => $params['dhrq'],
  236. 'azrq' => $params['azrq'],
  237. 'syrq' => $params['syrq'],
  238. 'zyfssb' => $params['zyfssb'],
  239. 'ptjsj' => $params['ptjsj'],
  240. 'ylohq' => $params['ylohq'],
  241. 'ptqt' => $params['ptqt'],
  242. 'zypj' => $params['zypj'],
  243. 'bz' => $params['bz'],
  244. 'sbzt' => 0,
  245. 'sylx' => 4
  246. ];
  247. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->insert($insert);
  248. return self::successResponse($result);
  249. }
  250. //设备管理设备详情
  251. public function sbglDetail(){
  252. $params = Input::get();
  253. if (!$params) {
  254. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  255. }
  256. $result['status'] = true;
  257. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  258. $data = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
  259. ->select('sbgl.*','qygl.qymc','qygl.wxlx','qygl.ID as qyid')
  260. ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
  261. ->where('sbgl.ID',$params['id'])->get();
  262. // $sbzt = ['新设备到货验收中','完好','待修','检修中','检修验收中','鉴定识别(登记核实)中','已报废','代物资保管'];
  263. // $sylx = ['在用','备用','拆除','检修','闲置'];
  264. // $bflx = ['委外设备废品废件','废品','设备待报废'];
  265. foreach($data as $k=>$v){
  266. $v->xsbfzr_list = [];
  267. $v->dxfzr_list = [];
  268. $v->jxfzr_list = [];
  269. $v->dbffzr_list = [];
  270. $v->bffzr_list = [];
  271. if($v->sbzt == 0){//新设备负责人
  272. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('xsbfzr',0)->where('is_delete',0)->get();
  273. foreach($people_list as $key => $val){
  274. $v->xsbfzr_list[] = [
  275. 'id' => $val->ID,
  276. 'xm' => $val->xm
  277. ];
  278. }
  279. }elseif($v->sbzt == 2){//待修负责人
  280. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dxfzr',0)->where('is_delete',0)->get();
  281. foreach($people_list as $key => $val){
  282. $v->dxfzr_list[] = [
  283. 'id' => $val->ID,
  284. 'xm' => $val->xm
  285. ];
  286. }
  287. }elseif($v->sbzt == 3){//检修负责人
  288. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxfzr',0)->where('is_delete',0)->get();
  289. foreach($people_list as $key => $val){
  290. $v->jxfzr_list[] = [
  291. 'id' => $val->ID,
  292. 'xm' => $val->xm
  293. ];
  294. }
  295. }elseif($v->sbzt == 4){//检修验收负责人
  296. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxysfzr',0)->where('is_delete',0)->get();
  297. foreach($people_list as $key => $val){
  298. $v->jxysfzr_list[] = [
  299. 'id' => $val->ID,
  300. 'xm' => $val->xm
  301. ];
  302. }
  303. }elseif($v->sbzt == 5){//鉴定识别(登记核实)负责人
  304. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dbffzr',0)->where('is_delete',0)->get();
  305. foreach($people_list as $key => $val){
  306. $v->dbffzr_list[] = [
  307. 'id' => $val->ID,
  308. 'xm' => $val->xm
  309. ];
  310. }
  311. }elseif($v->sbzt == 6){//固定资产鉴定负责人
  312. $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('bffzr',0)->where('is_delete',0)->get();
  313. foreach($people_list as $key => $val){
  314. $v->bffzr_list[] = [
  315. 'id' => $val->ID,
  316. 'xm' => $val->xm
  317. ];
  318. }
  319. }
  320. if($v->rhzq != null){
  321. $v->rhzq = $v->rhzq.'个月';
  322. }
  323. }
  324. $result['data'] = $data;
  325. return self::successResponse($result);
  326. }
  327. //设备管理润滑管理
  328. public function sbglRhList(){
  329. $result['status'] = true;
  330. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  331. $result['data'] = [];
  332. $current = time();// 获取当前时间戳
  333. $list = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
  334. ->select('sbgl.ID','sbgl.create_time','sbgl.sbmc','sbgl.scrhsj','sbgl.rhzq','qygl.qymc')
  335. ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
  336. ->where('sbgl.rhzq','!=','')->where('sbgl.is_delete',0)->get()->toArray();
  337. foreach($list as $k => $v){
  338. if($v->scrhsj != null){
  339. $scrhsj = strtotime($v->scrhsj);
  340. $sjc = floor(($current - $scrhsj) / (60 * 60 * 24));
  341. $sjc = intval(round($sjc));
  342. $v->sjc = ($v->rhzq*30 - $sjc);
  343. }else{
  344. $create_time = strtotime($v->create_time);
  345. $sjc = floor(($current - $create_time) / (60 * 60 * 24));
  346. $sjc = intval(round($sjc));
  347. $v->sjc = ($v->rhzq*30 - $sjc);
  348. }
  349. }
  350. usort($list, function ($a, $b) {
  351. return $a->sjc <=> $b->sjc;
  352. });
  353. $result['data'] = $list;
  354. return self::successResponse($result);
  355. }
  356. //设备管理设备调拨
  357. public function sbglSbdb(){
  358. $params = Input::get();
  359. if (!$params) {
  360. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  361. }
  362. $result['status'] = true;
  363. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  364. $result['data'] = [];
  365. $update = [
  366. 'ssdw' => $params['unit_id'],
  367. 'sbzt' => $params['sbzt'],
  368. 'sylx' => $params['sylx'],
  369. ];
  370. if(isset($params['sbbh'])){
  371. $update['sbbh'] = $params['sbbh'];
  372. }
  373. if(isset($params['bz'])){
  374. $update['bz'] = $params['bz'];
  375. }
  376. if($params['sbzt'] == 0){
  377. $update['xsbdhfzr'] = $params['fzr_id'];
  378. }
  379. if($params['sbzt'] == 2){
  380. $update['dxfzr'] = $params['fzr_id'];
  381. }
  382. if($params['sbzt'] == 3){
  383. $update['jxfzr'] = $params['fzr_id'];
  384. }
  385. if($params['sbzt'] == 4){
  386. $update['jxysfzr'] = $params['fzr_id'];
  387. }
  388. if($params['sbzt'] == 5){
  389. $update['dbffzr'] = $params['fzr_id'];
  390. }
  391. if($params['sbzt'] == 6){
  392. $update['bffzr'] = $params['fzr_id'];
  393. }
  394. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
  395. return self::successResponse($result);
  396. }
  397. //设备管理设备审核
  398. public function sbglSbsh(){
  399. $params = Input::get();
  400. if (!$params) {
  401. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  402. }
  403. $result['status'] = true;
  404. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  405. $result['data'] = [];
  406. if($params['action'] == 1){//删除设备
  407. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update(['is_delete'=>1]);
  408. return self::successResponse($result);
  409. }
  410. $update = [
  411. 'sbzt' => $params['sbzt'],
  412. 'sylx' => $params['sylx']
  413. ];
  414. if(isset($params['bz'])){
  415. $update['bz'] = $params['bz'];
  416. }
  417. if($params['sbzt'] == 3){
  418. $update['jxfzr'] = $params['fzr_id'];
  419. }
  420. if($params['sbzt'] == 4){
  421. $update['jxysfzr'] = $params['fzr_id'];
  422. }
  423. if($params['sbzt'] == 5){
  424. $update['dbffzr'] = $params['fzr_id'];
  425. }
  426. if($params['sbzt'] == 6){
  427. $update['bffzr'] = $params['fzr_id'];
  428. $update['bflx'] = $params['bflx'];
  429. }
  430. DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
  431. return self::successResponse($result);
  432. }
  433. //设备管理权限
  434. public function sbglRole(){
  435. $id = Input::get('id', '');
  436. $staff_num = Input::get('staff_num', '');
  437. $unit_id = Input::get('unit_id', '');
  438. $type = Input::get('type', '');
  439. if (!$unit_id) {
  440. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  441. }
  442. if (!$staff_num) {
  443. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  444. }
  445. if (!$type) {
  446. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  447. }
  448. if (!$id && $type != 'sbgly') {
  449. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  450. }
  451. $result['status'] = true;
  452. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  453. $result['data'] = 2;//无权限
  454. if($type == 'sbgly'){
  455. $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();
  456. if(count($people_list) > 0){
  457. $result['data'] = 1;//有权限
  458. }
  459. }else{
  460. $sb = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('id',$id)->get();
  461. if($type == 'xsbdhfzr'){
  462. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->xsbdhfzr)->get();
  463. if($people[0]->gh == $staff_num){
  464. $result['data'] = 1;
  465. }
  466. }
  467. if($type == 'dxfzr'){
  468. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dxfzr)->get();
  469. if($people[0]->gh == $staff_num){
  470. $result['data'] = 1;
  471. }
  472. }
  473. if($type == 'jxfzr'){
  474. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxfzr)->get();
  475. if($people[0]->gh == $staff_num){
  476. $result['data'] = 1;
  477. }
  478. }
  479. if($type == 'jxysfzr'){
  480. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxysfzr)->get();
  481. if($people[0]->gh == $staff_num){
  482. $result['data'] = 1;
  483. }
  484. }
  485. if($type == 'dbffzr'){
  486. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dbffzr)->get();
  487. if($people[0]->gh == $staff_num){
  488. $result['data'] = 1;
  489. }
  490. }
  491. if($type == 'bffzr'){
  492. $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->bffzr)->get();
  493. if($people[0]->gh == $staff_num){
  494. $result['data'] = 1;
  495. }
  496. }
  497. }
  498. return self::successResponse($result);
  499. }
  500. //教育学习(洗选中的教育学习应用)
  501. // 学习效果检查统计表
  502. public function learningEffectCheck(Request $request)
  503. {
  504. $params = $request->all();
  505. if(isset($params['start_time']) && isset($params['end_time'])){
  506. $start_time = $params['start_time'];
  507. $end_time = $params['end_time'];
  508. }else{
  509. $start_time = date('Y-m-d 00:00:00');
  510. $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
  511. }
  512. // 自评表数据
  513. $evaluate_data = DB::connection('mysql_fwe10')->table('uf_xx_zpb as t')
  514. ->select('t.dwmc as unitId','t.sgyy','t.sghg','t.sgcljg','t.xqjxjffcs','t.df','t1.dwmc')
  515. ->leftJoin('uf_xx_gxmcdw as t1', 't.dwmc', '=', 't1.id')
  516. ->whereBetween('t.create_time', [$start_time, $end_time])
  517. ->where('t.is_delete',0)
  518. ->where('t.delete_type',0)
  519. ->get();
  520. // 数据库查出来的数据进行处理
  521. $process_data = [];
  522. // 1. 提取所有单位id值
  523. $tmp = [];
  524. $index = 0;
  525. if(count($evaluate_data) > 0){
  526. for ($i = 0; $i < count($evaluate_data); $i++) {
  527. $process_data[$index]['unitId'] = $evaluate_data[$i]->unitId;
  528. $process_data[$index]['sgyy'] = $evaluate_data[$i]->sgyy;
  529. $process_data[$index]['sghg'] = $evaluate_data[$i]->sghg;
  530. $process_data[$index]['sgcljg'] = $evaluate_data[$i]->sgcljg;
  531. $process_data[$index]['xqjxjffcs'] = $evaluate_data[$i]->xqjxjffcs;
  532. $process_data[$index]['df'] = $evaluate_data[$i]->df;
  533. $process_data[$index]['dwmc'] = $evaluate_data[$i]->dwmc;
  534. $index++;
  535. $tmp[] = $evaluate_data[$i]->unitId;
  536. }
  537. }
  538. // 2. 去重并重置索引
  539. $unitId_List = array_values(array_unique($tmp));
  540. // 根据去重后的单位id给$evaluate_data中的数据分组
  541. $grouped = [];
  542. foreach ($process_data as $item) {
  543. $unitId = $item['unitId'];
  544. $grouped[$unitId][] = $item; // 按unitId值分组
  545. }
  546. $result = [];
  547. foreach ($unitId_List as $unitIdVar) {
  548. if (isset($grouped[$unitIdVar])) {
  549. $var1 = $grouped[$unitIdVar]; // 按uniqueBms顺序提取分组
  550. $result[] = $this->dataProcessing($var1);
  551. }
  552. }
  553. // 最后结果需要有个排名
  554. usort($result, function ($a, $b) {
  555. return $b['pjf'] <=> $a['pjf'];
  556. });
  557. $rank = 1;
  558. for ($i = 0; $i < count($result); $i++) {
  559. // 对于同一个 control_num 赋予相同的排名
  560. if ($i > 0 && $result[$i]['pjf'] == $result[$i - 1]['pjf']) {
  561. $result[$i]['rank'] = $result[$i - 1]['rank']; // 保持相同排名
  562. } else {
  563. $result[$i]['rank'] = $rank++; // 否则递增排名
  564. }
  565. }
  566. return self::successResponse($result);
  567. }
  568. // 对每组数据进行统计处理
  569. public function dataProcessing ($data = []): array
  570. {
  571. // 单位名称
  572. $unitName = '';
  573. // 检查人次
  574. $checkPeopleNum = count($data);
  575. // 事故原因
  576. $accidentCause = 0;
  577. // 事故后果
  578. $accidentConsequence = 0;
  579. // 事故处理结果
  580. $resultOfAccidentTreatment = 0;
  581. // 吸取教训/防范措施
  582. $preventiveMeasures = 0;
  583. // 最高分
  584. $theHighestScore = 0;
  585. // 最低分
  586. $theLowestScore = 100;
  587. // 平均分
  588. $averageScore = 0;
  589. foreach ($data as $item) {
  590. $accidentCause += $item['sgyy'];
  591. $accidentConsequence += $item['sghg'];
  592. $resultOfAccidentTreatment += $item['sgcljg'];
  593. $preventiveMeasures += $item['xqjxjffcs'];
  594. if ($theHighestScore < $item['df']) {
  595. $theHighestScore = $item['df'];
  596. }
  597. if ($theLowestScore > $item['df']) {
  598. $theLowestScore = $item['df'];
  599. }
  600. $averageScore += $item['df'];
  601. }
  602. $unitName = reset($data)['dwmc'];
  603. $accidentCause = round($accidentCause / $checkPeopleNum,2);
  604. $accidentConsequence = round($accidentConsequence / $checkPeopleNum,2);
  605. $resultOfAccidentTreatment = round($resultOfAccidentTreatment / $checkPeopleNum,2);
  606. $preventiveMeasures = round($preventiveMeasures / $checkPeopleNum,2);
  607. $averageScore = round($averageScore / $checkPeopleNum,2);
  608. $res = [
  609. 'dwmc' => $unitName,
  610. 'jcrc' => $checkPeopleNum,
  611. 'sgyy' => $accidentCause,
  612. 'sghg' => $accidentConsequence,
  613. 'sgcljg' => $resultOfAccidentTreatment,
  614. 'xqjxjffcs' => $preventiveMeasures,
  615. 'zgf' => $theHighestScore,
  616. 'zdf' => $theLowestScore,
  617. 'pjf' => $averageScore
  618. ];
  619. return $res;
  620. }
  621. //巡检轨迹
  622. public function getGuiji(){
  623. $result['status'] = true;
  624. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  625. $list1 = [];
  626. $date = Input::get('date', '');
  627. $depart = Input::get('depart', '');
  628. $lrr = Input::get('lrr', '');
  629. if (!$date) {
  630. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  631. }
  632. if (!$depart) {
  633. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  634. }
  635. if (!$lrr) {
  636. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  637. }
  638. $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where('lrsj','like','%'.$date.'%')->where('xjdw',$depart)->where('lrr',$lrr)->orderBy('create_time')->get();
  639. if(count($list) > 0){
  640. for($i=0;$i<count($list);$i++){
  641. $list1[$i]['lat'] = $list[$i]->lat;
  642. $list1[$i]['lng'] = $list[$i]->lng;
  643. $list1[$i]['title'] = $list[$i]->xjqy;
  644. $list1[$i]['id'] = $list[$i]->ID;
  645. }
  646. }
  647. //去重
  648. $serialized = array_map('serialize', $list1);
  649. $unique = array_unique($serialized);
  650. $list2 = array_map('unserialize', $unique);
  651. //取中心点
  652. $total = array_reduce($list2, function($carry, $item) {
  653. $carry['lat'] += (float)$item['lat'];
  654. $carry['lng'] += (float)$item['lng'];
  655. return $carry;
  656. }, ['lat' => 0, 'lng' => 0]);
  657. $avgLat = $total['lat'] / count($list2);
  658. $avgLng = $total['lng'] / count($list2);
  659. $result['list1'] = $list1;
  660. $result['list2'] = $list2;
  661. $result['lat'] = $avgLat;
  662. $result['lng'] = $avgLng;
  663. return self::successResponse($result);
  664. }
  665. //获取视频信息
  666. public function getVideoInfo()
  667. {
  668. $result['status'] = true;
  669. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  670. $result['data'] = [];
  671. $spid = Input::get('spid', '');
  672. if (!$spid) {
  673. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  674. }
  675. $res = DB::connection('mysql_fwe10')->table('uf_zhxx_aqsc_aqjsjy')->where('ID',$spid)->get();
  676. if(count($res) > 0){
  677. $result['data']['title'] = $res[0]->bt;
  678. $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';
  679. }
  680. return self::successResponse($result);
  681. }
  682. //问卷调查题目
  683. public function getTopicList()
  684. {
  685. $result['status'] = true;
  686. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  687. $result['data'] = [];
  688. $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();
  689. if(count($res) > 0){
  690. for($i=0;$i<count($res);$i++){
  691. if($res[$i]->tmlx == '3'){//简答题
  692. $res[$i]->tm = $res[$i]->jdtm;
  693. }elseif($res[$i]->tmlx == '2'){//填空题
  694. $res[$i]->tm = $res[$i]->tktm;
  695. }else{//选择题
  696. $res[$i]->tm = $res[$i]->xztm;
  697. }
  698. }
  699. }
  700. $result['data'] = $res;
  701. return self::successResponse($result);
  702. }
  703. //问卷调查统计
  704. public function getTopicStatic()
  705. {
  706. $result['status'] = true;
  707. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  708. $result['data']['title'] = '洗选中心'.date("Y").'年员工思想状况调查问卷';
  709. $jid = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_jgl')->where('is_delete',0)->orderBy('create_time','desc')->limit(1)->pluck('ID')[0];
  710. $tgl_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
  711. $statis_list = [];
  712. if(count($tgl_list) > 0){
  713. for($i=0;$i<count($tgl_list);$i++){
  714. $statis_list[$i]['id'] = $tgl_list[$i]->ID;
  715. $statis_list[$i]['tmlx'] = $tgl_list[$i]->tmlx;
  716. if($tgl_list[$i]->tmlx == 0){//单选题
  717. $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
  718. $statis_list[$i]['type'] = '单选题';
  719. $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
  720. $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
  721. $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
  722. $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
  723. $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
  724. $statis_list[$i]['a_num'] = 0;
  725. $statis_list[$i]['b_num'] = 0;
  726. $statis_list[$i]['c_num'] = 0;
  727. $statis_list[$i]['d_num'] = 0;
  728. $statis_list[$i]['e_num'] = 0;
  729. $statis_list[$i]['num'] = 0;
  730. }
  731. if($tgl_list[$i]->tmlx == 1){//多选题
  732. $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
  733. $statis_list[$i]['type'] = '多选题';
  734. $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
  735. $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
  736. $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
  737. $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
  738. $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
  739. $statis_list[$i]['a_num'] = 0;
  740. $statis_list[$i]['b_num'] = 0;
  741. $statis_list[$i]['c_num'] = 0;
  742. $statis_list[$i]['d_num'] = 0;
  743. $statis_list[$i]['e_num'] = 0;
  744. $statis_list[$i]['num'] = 0;
  745. }
  746. if($tgl_list[$i]->tmlx == 2){//填空题
  747. $statis_list[$i]['title'] = $tgl_list[$i]->tktm;
  748. }
  749. if($tgl_list[$i]->tmlx == 3){//简答题
  750. $statis_list[$i]['title'] = $tgl_list[$i]->jdtm;
  751. }
  752. }
  753. }
  754. $dtqk_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->select('da','tid')->where('jid',$jid)->where('is_delete',0)->get();
  755. $id_list = array_column($statis_list, 'id');
  756. if(count($dtqk_list) > 0){
  757. for($i=0;$i<count($dtqk_list);$i++){
  758. $key = array_search($dtqk_list[$i]->tid, $id_list);
  759. if($statis_list[$key]['tmlx'] == 0){//单选
  760. if($dtqk_list[$i]->da == 'A'){
  761. $statis_list[$key]['a_num']++;
  762. }
  763. if($dtqk_list[$i]->da == 'B'){
  764. $statis_list[$key]['b_num']++;
  765. }
  766. if($dtqk_list[$i]->da == 'C'){
  767. $statis_list[$key]['c_num']++;
  768. }
  769. if($dtqk_list[$i]->da == 'D'){
  770. $statis_list[$key]['d_num']++;
  771. }
  772. if($dtqk_list[$i]->da == 'E'){
  773. $statis_list[$key]['e_num']++;
  774. }
  775. }
  776. if($statis_list[$key]['tmlx'] == 1){//多选
  777. $da = explode(',',$dtqk_list[$i]->da);
  778. for($j=0;$j<count($da);$j++){
  779. if($da[$j] == 'A'){
  780. $statis_list[$key]['a_num']++;
  781. }
  782. if($da[$j] == 'B'){
  783. $statis_list[$key]['b_num']++;
  784. }
  785. if($da[$j] == 'C'){
  786. $statis_list[$key]['c_num']++;
  787. }
  788. if($da[$j] == 'D'){
  789. $statis_list[$key]['d_num']++;
  790. }
  791. if($da[$j] == 'E'){
  792. $statis_list[$key]['e_num']++;
  793. }
  794. }
  795. }
  796. }
  797. }
  798. if(count($statis_list) > 0){
  799. $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'];
  800. for($i=0;$i<count($statis_list);$i++){
  801. if($statis_list[$i]['tmlx'] == 0){
  802. $statis_list[$i]['num'] = $num;
  803. $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$num)*100, 2).'%';
  804. $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$num)*100, 2).'%';
  805. $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$num)*100, 2).'%';
  806. $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$num)*100, 2).'%';
  807. $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$num)*100, 2).'%';
  808. }
  809. if($statis_list[$i]['tmlx'] == 1){
  810. $statis_list[$i]['num'] = $num;
  811. $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'];
  812. $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$n)*100, 2).'%';
  813. $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$n)*100, 2).'%';
  814. $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$n)*100, 2).'%';
  815. $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$n)*100, 2).'%';
  816. $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$n)*100, 2).'%';
  817. }
  818. }
  819. }
  820. $result['data']['list'] = $statis_list;
  821. return self::successResponse($result);
  822. }
  823. //问卷调查单题列表
  824. public function getTopicTestList()
  825. {
  826. $result['status'] = true;
  827. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  828. $result['data'] = [];
  829. $id = Input::get('id', '');
  830. if (!$id) {
  831. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  832. }
  833. $t = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('ID',$id)->get();
  834. $list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->where('tid',$id)->where('is_delete',0)->orderBy('create_time')->pluck('da');
  835. if($t[0]->tmlx == 2){//填空
  836. $result['data']['title'] = $t[0]->tktm;
  837. }
  838. if($t[0]->tmlx == 3){//简答
  839. $result['data']['title'] = $t[0]->jdtm;
  840. }
  841. $result['data']['list'] = [];
  842. if(count($list) > 0){
  843. for($i=0;$i<count($list);$i++){
  844. if($list[$i] != '无' && $list[$i] != '没有'){
  845. array_push($result['data']['list'],$list[$i]);
  846. }
  847. }
  848. }
  849. return self::successResponse($result);
  850. }
  851. //问卷调查提交
  852. public function submitTopic(Request $request)
  853. {
  854. $params = $request->all();
  855. $result['status'] = true;
  856. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  857. $list = $params['answer'];
  858. if(count($list) > 0){
  859. for($i=0;$i<count($list);$i++){
  860. $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
  861. if (is_array($list[$i]['value'])) {
  862. $value = implode(',', $list[$i]['value']);
  863. } else {
  864. $value = $list[$i]['value'];
  865. }
  866. $insert = [
  867. 'ID' => $id,
  868. 'FORM_DATA_ID' => $id,
  869. 'DATA_INDEX' => 0.0,
  870. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  871. 'TENANT_KEY' => 't1zz9w8165',
  872. 'IS_DELETE' => 0,
  873. 'DELETE_TYPE' => 0,
  874. 'FT_STATUS' => 0,
  875. 'jid' => $params['jid'],
  876. 'da' => $value,
  877. 'tid' => $list[$i]['id'],
  878. 'xm' => $params['xm'],
  879. 'gh' => $params['gh']
  880. ];
  881. DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->insert($insert);
  882. }
  883. }
  884. return self::successResponse($result);
  885. }
  886. //腾讯地图逆地址解析
  887. public function positionGeocoder(){
  888. $lat = Input::get('lat', '');//纬度
  889. $lng = Input::get('lng', '');//经度
  890. if (!$lat) {
  891. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  892. }
  893. if (!$lng) {
  894. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  895. }
  896. $gps = $lat.','.$lng;
  897. $sig = '/ws/geocoder/v1?key='.env('TX_KEY').'&location='.$gps.env('TX_SK');
  898. $sig = md5($sig);
  899. $params = [
  900. 'location' => $gps,
  901. 'key' => env('TX_KEY'),
  902. 'sig' => $sig
  903. ];
  904. $result = $this->sendRequest("https://apis.map.qq.com/ws/geocoder/v1",$params);
  905. $position = '';
  906. if(isset($result['result']['formatted_addresses']['recommend'])){
  907. $position = $result['result']['formatted_addresses']['recommend'];
  908. }
  909. return self::successResponse($position);
  910. }
  911. //微信公众号获取文章列表
  912. public function getWechatArticleList(){
  913. $access_token = $this->getaccessToken();
  914. $url = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$access_token;
  915. $params = [
  916. "type" => "news",
  917. "offset" => 0,
  918. "count" => 10
  919. ];
  920. $result = $this->httpRequest($url,'POST',$params);
  921. return $result;
  922. }
  923. //微信公众号获取access_token
  924. public function getaccessToken(){
  925. $url = 'https://api.weixin.qq.com/cgi-bin/token';
  926. $params = [
  927. 'grant_type' => 'client_credential',
  928. 'appid' => env('WECHAT_KEY'),
  929. 'secret' => env('WECHAT_SECRET')
  930. ];
  931. $result = $this->httpRequest($url,'GET',$params);
  932. return $result;
  933. }
  934. //腾讯位置接口服务
  935. public function sendRequest($url, $params) {
  936. $ch = curl_init();
  937. curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
  938. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  939. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  940. $response = curl_exec($ch);
  941. curl_close($ch);
  942. return json_decode($response, true);
  943. }
  944. public function httpRequest($url, $format = 'get', $data = null){
  945. //设置头信息
  946. $headerArray =array("Content-type:application/json;","Accept:application/json");
  947. $curl=curl_init();
  948. curl_setopt($curl, CURLOPT_URL, $url);
  949. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  950. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  951. if ($format == 'post') {
  952. //post传值设置post传参
  953. curl_setopt($curl, CURLOPT_POST, 1);
  954. if ($data) {
  955. $data = json_encode($data);
  956. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  957. }
  958. }
  959. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  960. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  961. $data=json_decode(curl_exec($curl), true);
  962. curl_close($curl);
  963. //返回接口返回数据
  964. return $data;
  965. }
  966. }