ApiController.php 63 KB

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