ApiController.php 54 KB

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