ApiController.php 64 KB

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