ApiController.php 51 KB

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