ApiController.php 54 KB

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