ApiController.php 62 KB

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