ApiController.php 62 KB

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