ApiController.php 51 KB

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