| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 6/22/24
- * Time: 12:32 PM
- */
- namespace Modules\Admin\Http\Controllers\Api;
- use App\Enum\ApiEnum;
- use App\Http\Controllers\Api\BaseController;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Input;
- use Modules\Admin\Entities\User;
- use Modules\Admin\Http\Requests\TokenRequest;
- use Modules\Admin\Services\ApiService;
- use Modules\Staff\Entities\Staff;
- use Symfony\Component\HttpFoundation\Response;
- class ApiController extends BaseController
- {
- //整改人列表
- public function zgrList(Request $request){
- $params = $request->all();
- if(!$params['xjdw']){
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $depart = $params['xjdw'];
- if($depart == '羊二洗煤厂' || $depart == '羊场湾二分区洗煤厂'){
- $where = ['羊二洗煤厂','羊场湾二分区洗煤厂'];
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->whereIn('dwmc',$where)->get();
- }elseif($depart == '羊一洗煤厂' || $depart == '羊场湾洗煤厂'){
- $where = ['羊一洗煤厂','羊场湾洗煤厂'];
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->whereIn('dwmc',$where)->get();
- }else{
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc',$depart)->get();
- }
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $result['data'][$i] = $list[$i]->zgrxm.'|'.$list[$i]->zgrgh;
- }
- }
- return $result;
- }
- //网格化录入
- public function addConition(Request $request)
- {
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::addConition($params);
- return self::successResponse($result);
- }
- //网格化整改
- public function editConition(Request $request){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::editConition($params);
- return self::successResponse($result);
- }
- //网格化人员轨迹查询条件
- public function getQueryConition(Request $request)
- {
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getQueryConitions($date);
- return self::successResponse($result);
- }
- //全流程巡检记录
- public function inspectionRecord(Request $request){
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- // $data = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'))->pluck('xjdw')->toArray();
- $data = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where('lrsj', '>=', DB::raw("DATE_SUB(NOW(), INTERVAL 6 MONTH)"))->pluck('xjdw')->toArray();
- $counts = array_count_values($data);// 1. 统计每个值的出现次数
- arsort($counts);// 2. 按出现次数降序排序
- $depart = array_keys($counts);// 3. 只保留键(去重),并按频率排序
- $result['data']['depart_list'] = $depart;
- $list = [];
- if(count($depart) > 0){
- for($i=0;$i<count($depart);$i++){
- //巡检人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')
- ->where('xjdw', $depart[$i])
- ->where('lrsj', 'like', '%' . $date . '%')
- ->groupBy('lrr')->select(
- [
- 'lrr'
- ]
- )->get();
- if(count($people_list) > 0){
- for($j=0;$j<count($people_list);$j++){
- $people_name = explode('|',$people_list[$j]->lrr);
- //查职务
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrxm',$people_name[0])->where('IS_DELETE',0)->first();
- //全部单位
- $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')->where('szxmc',$depart[$i])->where('IS_DELETE',0)->pluck('qymc');
- //巡检单位数
- $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();
- if(count($unit_list) == count($record_list)){
- $color = 'green';
- }else{
- $color = 'red';
- }
- if (!$people) {
- $zw = '';
- } else {
- $zw = $people->zw;
- }
- array_push($list,[
- 'depart' => $depart[$i],
- 'name' => $people_name[0],
- 'zw' => $zw,
- 'ys' => $color
- ]);
- }
- }
- }
- }
- $result['data']['list'] = $list;
- return self::successResponse($result);
- }
- //全流程巡检按月查个人巡检记录
- public function peopleRecordByMonth(Request $request){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $depart = Input::get('depart', '');
- $people = Input::get('people', '');
- $ym = Input::get('ym', '');
- if (!$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$people) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$ym) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $timestamp = strtotime($ym);
- $ny = date('Y年n月', $timestamp);
- $result['data']['title'] = $ny.$depart.$people.'的巡检记录';
- if($depart == '羊二洗煤厂' || $depart == '羊场湾二分区洗煤厂'){
- $where = ['羊二洗煤厂','羊场湾二分区洗煤厂'];
- $people_info = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrxm',$people)->whereIn('dwmc',$where)->where('IS_DELETE',0)->first();
- }elseif($depart == '羊一洗煤厂' || $depart == '羊场湾洗煤厂'){
- $where = ['羊一洗煤厂','羊场湾洗煤厂'];
- $people_info = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrxm',$people)->whereIn('dwmc',$where)->where('IS_DELETE',0)->first();
- }else{
- // $people_info = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrxm',$people)->where('dwmc',$depart)->where('IS_DELETE',0)->first();
- $people_info = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrxm',$people)->where('dwmc','like','%'.$depart.'%')->where('IS_DELETE',0)->first();
- }
- $person_id = $people_info->zgrxm.'|'.$people_info->zgrgh;
- //全部单位
- $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')->where('szxmc',$depart)->where('IS_DELETE',0)->pluck('qymc');
- $record_list = DB::connection('mysql_fwe10')
- ->table('uf_zhxx_qlcxjjl')
- ->where('xjdw', $depart)
- ->where('lrr', 'like', '%'.$people.'%')
- ->where('lrsj', 'like', '%'.$ym.'%')
- ->distinct() // 改用 distinct 去重
- ->select('lrsj')
- ->orderBy('lrsj') // 改为按分组字段排序
- ->get();
- $list = [];
- if(count($record_list) > 0){
- for($i=0;$i<count($record_list);$i++){
- $record = DB::connection('mysql_fwe10')
- ->table('uf_zhxx_qlcxjjl')
- ->where('xjdw', $depart)
- ->where('lrr', 'like', '%'.$people.'%')
- ->where('lrsj', $record_list[$i]->lrsj)
- ->distinct()
- ->select('xjqy')
- ->get();
- if(count($record) == count($unit_list)){
- $color = 'green';
- }else{
- $color = 'red';
- }
- $timestamp = strtotime($record_list[$i]->lrsj);
- $riqi = date('n月j日', $timestamp);
- $date = date('Y-m-d', $timestamp);
- $list[] = [
- 'riqi' => $riqi,
- 'depart' => $depart,
- 'name' => $people,
- 'zw' => $people_info->zw,
- 'ys' => $color,
- 'date' => $date,
- 'person_id' => $person_id
- ];
- }
- }
- $result['data']['list'] = $list;
- return self::successResponse($result);
- }
- //根据单位查人员列表
- public function getPeopleByUnit(Request $request){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $depart = Input::get('depart', '');
- if($depart == '羊二洗煤厂' || $depart == '羊场湾二分区洗煤厂'){
- $where = ['羊二洗煤厂','羊场湾二分区洗煤厂'];
- $result['data'] = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->whereIn('dwmc',$where)->where('is_delete',0)->pluck('zgrxm');
- }elseif($depart == '羊一洗煤厂' || $depart == '羊场湾洗煤厂'){
- $where = ['羊一洗煤厂','羊场湾洗煤厂'];
- $result['data'] = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->whereIn('dwmc',$where)->where('is_delete',0)->pluck('zgrxm');
- }else{
- $result['data'] = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc','like','%'.$depart.'%')->where('is_delete',0)->pluck('zgrxm');
- }
- return $result;
- }
- //网格化人员轨迹
- public function getPersonTravel(Request $request)
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', '');
- $date = Input::get('date', '');
- if (!$person_id || !$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getPersonTravel($person_id, $depart, $date);
- return self::successResponse($result);
- }
- //网格化巡检记录查询条件
- public function getResultConition()
- {
- $result = ApiService::getResultConition();
- return self::successResponse($result);
- }
- //网格化巡检记录查询
- public function getResultRecord()
- {
- $depart = Input::get('depart', 'all');
- $date_type = Input::get('date_type', 'week');
- $result = ApiService::getResultRecord($depart, $date_type);
- return self::successResponse($result);
- }
- //全流程巡检记录排名
- public function getRecordSort()
- {
- $depart = Input::get('depart', 'all');
- $start_date = Input::get('start_date', '');
- $end_date = Input::get('end_date', '');
- $result = ApiService::getRecordSort($depart, $start_date,$end_date);
- // return self::successResponse($result);
- return $result;
- }
- //网格化巡检记录列表
- public function getResultList()
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', 'all');
- $date_type = Input::get('date_type', 'week');
- if (!$person_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultList($person_id, $depart, $date_type);
- return self::successResponse($result);
- }
- //网格化巡检记录列表明细
- public function getResultDlist()
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', '');
- $date = Input::get('date', '');
- if (!$person_id || !$depart || !$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultDlist($person_id, $depart, $date);
- return self::successResponse($result);
- }
- //网格化巡检记录明细
- public function getResultDetail()
- {
- $id = Input::get('id', '');
- if (!$id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultDetails($id);
- return self::successResponse($result);
- }
- //网格化巡检记录
- public function getFinalList()
- {
- $start_date = Input::get('start_date', '');
- $end_date = Input::get('end_date', '');
- $depart = Input::get('depart', '');
- $person = Input::get('person', '');
- if (!$start_date || !$end_date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getFinalList($start_date, $end_date, $depart, $person);
- return self::successResponse($result);
- }
- //网格化巡检权限
- public function getRole(){
- $staff_num = Input::get('staff_num', '');
- $depart = Input::get('ssdw', '');
- if (!$staff_num) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = 2;//无权限
- if($depart == '羊二洗煤厂' || $depart == '羊场湾二分区洗煤厂'){
- $where = ['羊二洗煤厂','羊场湾二分区洗煤厂'];
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->whereIn('dwmc',$where)->where('is_delete',0)->get();
- }elseif($depart == '羊一洗煤厂' || $depart == '羊场湾洗煤厂'){
- $where = ['羊一洗煤厂','羊场湾洗煤厂'];
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->whereIn('dwmc',$where)->where('is_delete',0)->get();
- }else{
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->where('dwmc',$depart)->where('is_delete',0)->get();
- }
- if(count($people) > 0){
- $result['data'] = 1;//有权限
- }
- return self::successResponse($result);
- }
- //设备管理添加设备单位列表
- public function sbglUnitList(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_qygl')->where('is_delete',0)->get();
- foreach($unit_list as $k => $v){
- $result['data'][] = [
- 'id' => $v->ID,
- 'qymc' => $v->qymc
- ];
- }
- return self::successResponse($result);
- }
- //设备管理添加设备负责人列表
- public function sbglPeopleList(){
- $unit_id = Input::get('unit_id', '');
- $type = Input::get('type', '');
- if (!$unit_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if($type == ''){
- $type = 0;
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if($type == 0){//新设备负责人
- $name = 'xsbfzr';
- }elseif($type == 2){//待修负责人
- $name = 'dxfzr';
- }elseif($type == 3){//检修负责人
- $name = 'jxfzr';
- }elseif($type == 4){//检修验收负责人
- $name = 'jxysfzr';
- }elseif($type == 5){//鉴定识别(登记核实)负责人
- $name = 'dbffzr';
- }elseif($type == 6){//固定资产鉴定负责人
- $name = 'bffzr';
- }
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where($name,0)->where('is_delete',0)->get();
- foreach($people_list as $k => $v){
- $result['data'][] = [
- 'id' => $v->ID,
- 'xm' => $v->xm
- ];
- }
- return self::successResponse($result);
- }
- //设备管理添加新设备
- public function sbglAdd(Request $request){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'ssdw' => $params['qymc'],
- 'xsbdhfzr' => $params['xsbdhfzr'],
- 'sbmc' => $params['sbmc'],
- 'sbzp' => $params['sbzp'],
- 'rhzq' => $params['rhzq'],
- 'sbbh' => $params['sbbh'],
- 'ggxh' => $params['ggxh'],
- 'jscs' => $params['jscs'],
- 'sccj' => $params['sccj'],
- 'ccrq' => $params['ccrq'],
- 'dhrq' => $params['dhrq'],
- 'azrq' => $params['azrq'],
- 'syrq' => $params['syrq'],
- 'zyfssb' => $params['zyfssb'],
- 'ptjsj' => $params['ptjsj'],
- 'ylohq' => $params['ylohq'],
- 'ptqt' => $params['ptqt'],
- 'zypj' => $params['zypj'],
- 'bz' => $params['bz'],
- 'sbzt' => 0,
- 'sylx' => 4
- ];
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->insert($insert);
- return self::successResponse($result);
- }
- //设备管理设备详情
- public function sbglDetail(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $data = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
- ->select('sbgl.*','qygl.qymc','qygl.wxlx','qygl.ID as qyid')
- ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
- ->where('sbgl.ID',$params['id'])->get();
- // $sbzt = ['新设备到货验收中','完好','待修','检修中','检修验收中','鉴定识别(登记核实)中','已报废','代物资保管'];
- // $sylx = ['在用','备用','拆除','检修','闲置'];
- // $bflx = ['委外设备废品废件','废品','设备待报废'];
- foreach($data as $k=>$v){
- $v->xsbfzr_list = [];
- $v->dxfzr_list = [];
- $v->jxfzr_list = [];
- $v->dbffzr_list = [];
- $v->bffzr_list = [];
- if($v->sbzt == 0){//新设备负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('xsbfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->xsbfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 2){//待修负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dxfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->dxfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 3){//检修负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->jxfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 4){//检修验收负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxysfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->jxysfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 5){//鉴定识别(登记核实)负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dbffzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->dbffzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 6){//固定资产鉴定负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('bffzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->bffzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }
- if($v->rhzq != null){
- $v->rhzq = $v->rhzq.'个月';
- }
- }
- $result['data'] = $data;
- return self::successResponse($result);
- }
- //设备管理润滑管理
- public function sbglRhList(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $current = time();// 获取当前时间戳
- $list = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
- ->select('sbgl.ID','sbgl.create_time','sbgl.sbmc','sbgl.scrhsj','sbgl.rhzq','qygl.qymc')
- ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
- ->where('sbgl.rhzq','!=','')->where('sbgl.is_delete',0)->get()->toArray();
- foreach($list as $k => $v){
- if($v->scrhsj != null){
- $scrhsj = strtotime($v->scrhsj);
- $sjc = floor(($current - $scrhsj) / (60 * 60 * 24));
- $sjc = intval(round($sjc));
- $v->sjc = ($v->rhzq*30 - $sjc);
- }else{
- $create_time = strtotime($v->create_time);
- $sjc = floor(($current - $create_time) / (60 * 60 * 24));
- $sjc = intval(round($sjc));
- $v->sjc = ($v->rhzq*30 - $sjc);
- }
- }
- usort($list, function ($a, $b) {
- return $a->sjc <=> $b->sjc;
- });
- $result['data'] = $list;
- return self::successResponse($result);
- }
- //设备管理设备调拨
- public function sbglSbdb(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $update = [
- 'ssdw' => $params['unit_id'],
- 'sbzt' => $params['sbzt'],
- 'sylx' => $params['sylx'],
- ];
- if(isset($params['sbbh'])){
- $update['sbbh'] = $params['sbbh'];
- }
- if(isset($params['bz'])){
- $update['bz'] = $params['bz'];
- }
- if($params['sbzt'] == 0){
- $update['xsbdhfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 2){
- $update['dxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 3){
- $update['jxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 4){
- $update['jxysfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 5){
- $update['dbffzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 6){
- $update['bffzr'] = $params['fzr_id'];
- }
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
- return self::successResponse($result);
- }
- //设备管理设备审核
- public function sbglSbsh(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if($params['action'] == 1){//删除设备
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update(['is_delete'=>1]);
- return self::successResponse($result);
- }
- $update = [
- 'sbzt' => $params['sbzt'],
- 'sylx' => $params['sylx']
- ];
- if(isset($params['bz'])){
- $update['bz'] = $params['bz'];
- }
- if($params['sbzt'] == 3){
- $update['jxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 4){
- $update['jxysfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 5){
- $update['dbffzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 6){
- $update['bffzr'] = $params['fzr_id'];
- $update['bflx'] = $params['bflx'];
- }
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
- return self::successResponse($result);
- }
- //设备管理权限
- public function sbglRole(){
- $id = Input::get('id', '');
- $staff_num = Input::get('staff_num', '');
- $unit_id = Input::get('unit_id', '');
- $type = Input::get('type', '');
- if (!$unit_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$staff_num) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$type) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$id && $type != 'sbgly') {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = 2;//无权限
- if($type == 'sbgly'){
- $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();
- if(count($people_list) > 0){
- $result['data'] = 1;//有权限
- }
- }else{
- $sb = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('id',$id)->get();
- if($type == 'xsbdhfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->xsbdhfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'dxfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dxfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'jxfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'jxysfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxysfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'dbffzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dbffzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'bffzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->bffzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- }
- return self::successResponse($result);
- }
- //教育学习(洗选中的教育学习应用)
- // 学习效果检查统计表
- public function learningEffectCheck(Request $request)
- {
- $params = $request->all();
- if(isset($params['start_time']) && isset($params['end_time'])){
- $start_time = $params['start_time'];
- $end_time = $params['end_time'];
- }else{
- $start_time = date('Y-m-d 00:00:00');
- $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
- }
- // 自评表数据
- $evaluate_data = DB::connection('mysql_fwe10')->table('uf_xx_zpb as t')
- ->select('t.dwmc as unitId','t.sgyy','t.sghg','t.sgcljg','t.xqjxjffcs','t.df','t1.dwmc')
- ->leftJoin('uf_xx_gxmcdw as t1', 't.dwmc', '=', 't1.id')
- ->whereBetween('t.create_time', [$start_time, $end_time])
- ->where('t.is_delete',0)
- ->where('t.delete_type',0)
- ->get();
- // 数据库查出来的数据进行处理
- $process_data = [];
- // 1. 提取所有单位id值
- $tmp = [];
- $index = 0;
- if(count($evaluate_data) > 0){
- for ($i = 0; $i < count($evaluate_data); $i++) {
- $process_data[$index]['unitId'] = $evaluate_data[$i]->unitId;
- $process_data[$index]['sgyy'] = $evaluate_data[$i]->sgyy;
- $process_data[$index]['sghg'] = $evaluate_data[$i]->sghg;
- $process_data[$index]['sgcljg'] = $evaluate_data[$i]->sgcljg;
- $process_data[$index]['xqjxjffcs'] = $evaluate_data[$i]->xqjxjffcs;
- $process_data[$index]['df'] = $evaluate_data[$i]->df;
- $process_data[$index]['dwmc'] = $evaluate_data[$i]->dwmc;
- $index++;
- $tmp[] = $evaluate_data[$i]->unitId;
- }
- }
- // 2. 去重并重置索引
- $unitId_List = array_values(array_unique($tmp));
- // 根据去重后的单位id给$evaluate_data中的数据分组
- $grouped = [];
- foreach ($process_data as $item) {
- $unitId = $item['unitId'];
- $grouped[$unitId][] = $item; // 按unitId值分组
- }
- $result = [];
- foreach ($unitId_List as $unitIdVar) {
- if (isset($grouped[$unitIdVar])) {
- $var1 = $grouped[$unitIdVar]; // 按uniqueBms顺序提取分组
- $result[] = $this->dataProcessing($var1);
- }
- }
- // 最后结果需要有个排名
- usort($result, function ($a, $b) {
- return $b['pjf'] <=> $a['pjf'];
- });
- $rank = 1;
- for ($i = 0; $i < count($result); $i++) {
- // 对于同一个 control_num 赋予相同的排名
- if ($i > 0 && $result[$i]['pjf'] == $result[$i - 1]['pjf']) {
- $result[$i]['rank'] = $result[$i - 1]['rank']; // 保持相同排名
- } else {
- $result[$i]['rank'] = $rank++; // 否则递增排名
- }
- }
- return self::successResponse($result);
- }
- // 对每组数据进行统计处理
- public function dataProcessing ($data = []): array
- {
- // 单位名称
- $unitName = '';
- // 检查人次
- $checkPeopleNum = count($data);
- // 事故原因
- $accidentCause = 0;
- // 事故后果
- $accidentConsequence = 0;
- // 事故处理结果
- $resultOfAccidentTreatment = 0;
- // 吸取教训/防范措施
- $preventiveMeasures = 0;
- // 最高分
- $theHighestScore = 0;
- // 最低分
- $theLowestScore = 100;
- // 平均分
- $averageScore = 0;
- foreach ($data as $item) {
- $accidentCause += $item['sgyy'];
- $accidentConsequence += $item['sghg'];
- $resultOfAccidentTreatment += $item['sgcljg'];
- $preventiveMeasures += $item['xqjxjffcs'];
- if ($theHighestScore < $item['df']) {
- $theHighestScore = $item['df'];
- }
- if ($theLowestScore > $item['df']) {
- $theLowestScore = $item['df'];
- }
- $averageScore += $item['df'];
- }
- $unitName = reset($data)['dwmc'];
- $accidentCause = round($accidentCause / $checkPeopleNum,2);
- $accidentConsequence = round($accidentConsequence / $checkPeopleNum,2);
- $resultOfAccidentTreatment = round($resultOfAccidentTreatment / $checkPeopleNum,2);
- $preventiveMeasures = round($preventiveMeasures / $checkPeopleNum,2);
- $averageScore = round($averageScore / $checkPeopleNum,2);
- $res = [
- 'dwmc' => $unitName,
- 'jcrc' => $checkPeopleNum,
- 'sgyy' => $accidentCause,
- 'sghg' => $accidentConsequence,
- 'sgcljg' => $resultOfAccidentTreatment,
- 'xqjxjffcs' => $preventiveMeasures,
- 'zgf' => $theHighestScore,
- 'zdf' => $theLowestScore,
- 'pjf' => $averageScore
- ];
- return $res;
- }
- //巡检轨迹
- public function getGuiji(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $list1 = [];
- $date = Input::get('date', '');
- $depart = Input::get('depart', '');
- $lrr = Input::get('lrr', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$lrr) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where('lrsj','like','%'.$date.'%')->where('xjdw',$depart)->where('lrr',$lrr)->orderBy('create_time')->get();
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $list1[$i]['lat'] = $list[$i]->lat;
- $list1[$i]['lng'] = $list[$i]->lng;
- $list1[$i]['title'] = $list[$i]->xjqy;
- $list1[$i]['id'] = $list[$i]->ID;
- }
- }
- //去重
- $serialized = array_map('serialize', $list1);
- $unique = array_unique($serialized);
- $list2 = array_map('unserialize', $unique);
- //取中心点
- $total = array_reduce($list2, function($carry, $item) {
- $carry['lat'] += (float)$item['lat'];
- $carry['lng'] += (float)$item['lng'];
- return $carry;
- }, ['lat' => 0, 'lng' => 0]);
- $avgLat = $total['lat'] / count($list2);
- $avgLng = $total['lng'] / count($list2);
- $result['list1'] = $list1;
- $result['list2'] = $list2;
- $result['lat'] = $avgLat;
- $result['lng'] = $avgLng;
- return self::successResponse($result);
- }
- //获取视频信息
- public function getVideoInfo()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $spid = Input::get('spid', '');
- if (!$spid) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $res = DB::connection('mysql_fwe10')->table('uf_zhxx_aqsc_aqjsjy')->where('ID',$spid)->get();
- if(count($res) > 0){
- $result['data']['title'] = $res[0]->bt;
- $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';
- }
- return self::successResponse($result);
- }
- //问卷调查题目
- public function getTopicList()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $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();
- if(count($res) > 0){
- for($i=0;$i<count($res);$i++){
- if($res[$i]->tmlx == '3'){//简答题
- $res[$i]->tm = $res[$i]->jdtm;
- }elseif($res[$i]->tmlx == '2'){//填空题
- $res[$i]->tm = $res[$i]->tktm;
- }else{//选择题
- $res[$i]->tm = $res[$i]->xztm;
- }
- }
- }
- $result['data'] = $res;
- return self::successResponse($result);
- }
- //问卷调查统计
- public function getTopicStatic()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data']['title'] = '洗选中心'.date("Y").'年员工思想状况调查问卷';
- $jid = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_jgl')->where('is_delete',0)->orderBy('create_time','desc')->limit(1)->pluck('ID')[0];
- $tgl_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
- $statis_list = [];
- if(count($tgl_list) > 0){
- for($i=0;$i<count($tgl_list);$i++){
- $statis_list[$i]['id'] = $tgl_list[$i]->ID;
- $statis_list[$i]['tmlx'] = $tgl_list[$i]->tmlx;
- if($tgl_list[$i]->tmlx == 0){//单选题
- $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
- $statis_list[$i]['type'] = '单选题';
- $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
- $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
- $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
- $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
- $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
- $statis_list[$i]['a_num'] = 0;
- $statis_list[$i]['b_num'] = 0;
- $statis_list[$i]['c_num'] = 0;
- $statis_list[$i]['d_num'] = 0;
- $statis_list[$i]['e_num'] = 0;
- $statis_list[$i]['num'] = 0;
- }
- if($tgl_list[$i]->tmlx == 1){//多选题
- $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
- $statis_list[$i]['type'] = '多选题';
- $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
- $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
- $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
- $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
- $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
- $statis_list[$i]['a_num'] = 0;
- $statis_list[$i]['b_num'] = 0;
- $statis_list[$i]['c_num'] = 0;
- $statis_list[$i]['d_num'] = 0;
- $statis_list[$i]['e_num'] = 0;
- $statis_list[$i]['num'] = 0;
- }
- if($tgl_list[$i]->tmlx == 2){//填空题
- $statis_list[$i]['title'] = $tgl_list[$i]->tktm;
- }
- if($tgl_list[$i]->tmlx == 3){//简答题
- $statis_list[$i]['title'] = $tgl_list[$i]->jdtm;
- }
- }
- }
- $dtqk_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->select('da','tid')->where('jid',$jid)->where('is_delete',0)->get();
- $id_list = array_column($statis_list, 'id');
- if(count($dtqk_list) > 0){
- for($i=0;$i<count($dtqk_list);$i++){
- $key = array_search($dtqk_list[$i]->tid, $id_list);
- if($statis_list[$key]['tmlx'] == 0){//单选
- if($dtqk_list[$i]->da == 'A'){
- $statis_list[$key]['a_num']++;
- }
- if($dtqk_list[$i]->da == 'B'){
- $statis_list[$key]['b_num']++;
- }
- if($dtqk_list[$i]->da == 'C'){
- $statis_list[$key]['c_num']++;
- }
- if($dtqk_list[$i]->da == 'D'){
- $statis_list[$key]['d_num']++;
- }
- if($dtqk_list[$i]->da == 'E'){
- $statis_list[$key]['e_num']++;
- }
- }
- if($statis_list[$key]['tmlx'] == 1){//多选
- $da = explode(',',$dtqk_list[$i]->da);
- for($j=0;$j<count($da);$j++){
- if($da[$j] == 'A'){
- $statis_list[$key]['a_num']++;
- }
- if($da[$j] == 'B'){
- $statis_list[$key]['b_num']++;
- }
- if($da[$j] == 'C'){
- $statis_list[$key]['c_num']++;
- }
- if($da[$j] == 'D'){
- $statis_list[$key]['d_num']++;
- }
- if($da[$j] == 'E'){
- $statis_list[$key]['e_num']++;
- }
- }
- }
- }
- }
- if(count($statis_list) > 0){
- $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'];
- for($i=0;$i<count($statis_list);$i++){
- if($statis_list[$i]['tmlx'] == 0){
- $statis_list[$i]['num'] = $num;
- $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$num)*100, 2).'%';
- $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$num)*100, 2).'%';
- $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$num)*100, 2).'%';
- $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$num)*100, 2).'%';
- $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$num)*100, 2).'%';
- }
- if($statis_list[$i]['tmlx'] == 1){
- $statis_list[$i]['num'] = $num;
- $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'];
- $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$n)*100, 2).'%';
- $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$n)*100, 2).'%';
- $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$n)*100, 2).'%';
- $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$n)*100, 2).'%';
- $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$n)*100, 2).'%';
- }
- }
- }
- $result['data']['list'] = $statis_list;
- return self::successResponse($result);
- }
- //问卷调查单题列表
- public function getTopicTestList()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $id = Input::get('id', '');
- if (!$id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $t = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('ID',$id)->get();
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->where('tid',$id)->where('is_delete',0)->orderBy('create_time')->pluck('da');
- if($t[0]->tmlx == 2){//填空
- $result['data']['title'] = $t[0]->tktm;
- }
- if($t[0]->tmlx == 3){//简答
- $result['data']['title'] = $t[0]->jdtm;
- }
- $result['data']['list'] = [];
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- if($list[$i] != '无' && $list[$i] != '没有'){
- array_push($result['data']['list'],$list[$i]);
- }
- }
- }
- return self::successResponse($result);
- }
- //问卷调查提交
- public function submitTopic(Request $request)
- {
- $params = $request->all();
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $list = $params['answer'];
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- if (is_array($list[$i]['value'])) {
- $value = implode(',', $list[$i]['value']);
- } else {
- $value = $list[$i]['value'];
- }
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'jid' => $params['jid'],
- 'da' => $value,
- 'tid' => $list[$i]['id'],
- 'xm' => $params['xm'],
- 'gh' => $params['gh']
- ];
- DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->insert($insert);
- }
- }
- return self::successResponse($result);
- }
- public function getTestList(Request $request)
- {
- $params = $request->all();
- $result['status'] = true;
- $result['data'] = [];
- // 查询是否答过题
- $var1 = DB::connection('mysql_fwe10')->table('uf_dtqk')
- ->select('id','df')
- ->where('is_delete',0)
- ->where('sjzt',$params['sjid'])
- ->where('ryid',$params['gh'])
- ->get();
- if(count($var1) == 0){
- $res = DB::connection('mysql_fwe10')->table('uf_xx_dtk')
- ->select('id','tmlx','tm','xxa','xxb','xxc','xxd','da','score')
- ->where('is_delete',0)
- ->where('sjzt',$params['sjid'])
- ->orderBy('tmlx')
- ->orderBy('sort')->get();
- $result['data'] = $res;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- }else{
- $result['msg'] = "已经答过此试卷,得分:".$var1[0]->df."分。";
- }
- return self::successResponse($result);
- }
- public function submitTest(Request $request)
- {
- $params = $request->all();
- $result['status'] = true;
- $list = $params['answer'];
- // 查询是否答过题
- $var1 = DB::connection('mysql_fwe10')->table('uf_dtqk')
- ->select('id','df')
- ->where('is_delete',0)
- ->where('sjzt',$params['sjid'])
- ->where('ryid',$params['gh'])
- ->get();
- if(count($var1) == 0){
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- if (is_array($list[$i]['value'])) {
- $value = implode(',', $list[$i]['value']);
- } else {
- $value = $list[$i]['value'];
- }
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'sjzt' => $params['sjid'],
- 'da' => $value,
- 'tmid' => $list[$i]['id'],
- 'xm' => $params['xm'],
- 'gh' => $params['gh'],
- 'zqyf' => $list[$i]['right']
- ];
- DB::connection('mysql_fwe10')->table('uf_xx_dtjl')->insert($insert);
- }
- }
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'sjzt' => $params['sjid'],
- 'xm' => $params['xm'],
- 'ryid' => $params['gh'],
- 'df' => $params['score']
- ];
- DB::connection('mysql_fwe10')->table('uf_dtqk')->insert($insert);
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['code'] = "200";
- }else{
- $result['msg'] = "已经答过此试卷,得分:".$var1[0]->df."分。";
- $result['code'] = "401";
- }
- return self::successResponse($result);
- }
- //内部市场化结算项目审批
- public function nbschJsxmsp(){
- $now_month = Input::get('now_month', '');
- if (!$now_month) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $data = DB::connection('mysql_nbsch')->table('sys_flow_master_dept')->get();
- dd($data);
- }
- //腾讯地图逆地址解析
- public function positionGeocoder(){
- $lat = Input::get('lat', '');//纬度
- $lng = Input::get('lng', '');//经度
- if (!$lat) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$lng) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $gps = $lat.','.$lng;
- $sig = '/ws/geocoder/v1?key='.env('TX_KEY').'&location='.$gps.env('TX_SK');
- $sig = md5($sig);
- $params = [
- 'location' => $gps,
- 'key' => env('TX_KEY'),
- 'sig' => $sig
- ];
- $result = $this->sendRequest("https://apis.map.qq.com/ws/geocoder/v1",$params);
- $position = '';
- if(isset($result['result']['formatted_addresses']['recommend'])){
- $position = $result['result']['formatted_addresses']['recommend'];
- }
- return self::successResponse($position);
- }
- //微信公众号获取文章列表
- public function getWechatArticleList(){
- $res = $this->getaccessToken();
- // dd($res);
- if($res['access_token']){
- // 获取已发布但未群发的文章
- $access_token = $res['access_token'];
- $url = 'https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token='.$access_token;
- $params = [
- "offset" => 0,
- "no_content" => 1,
- "count" => 10
- ];
- $result = $this->httpRequest($url,'post',$params);
- return $result;
- // 获取永久图文素材(已群发)
- // $access_token = $res['access_token'];
- // $url = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token='.$access_token;
- // $params = [
- // "type" => 'news',
- // "offset" => 0,
- // "count" => 20
- // ];
- // $result = $this->httpRequest($url,'post',$params);
- // return $result;
- // 获取草稿列表
- // $access_token = $res['access_token'];
- // $url = 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$access_token;
- // $params = [
- // "offset" => 0,
- // "no_content" => 1,
- // "count" => 200
- // ];
- // $result = $this->httpRequest($url,'post',$params);
- // return $result;
- }
- }
- //微信公众号获取access_token
- public function getaccessToken(){
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.env('MZY_WECHAT_APPID').'&secret='.env('MZY_WECHAT_APPSECRET');
- $result = $this->httpRequest($url,'GET',[]);
- return $result;
- }
- //公管公司值班日历
- public function dutyCalendar(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $riqi = Input::get('riqi', '');
- if (!$riqi) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['title'] = date('Y年n月j日', strtotime($riqi)).'值班信息';
- $zbInfo = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$riqi)->where('is_delete',0)->orderBy('CREATE_TIME','desc')->first();
- if (!$zbInfo) {
- return self::successResponse($result);
- }
- if ($zbInfo) {
- $fields = [
- 'zzb', 'zzb2', 'fzb1', 'fzb2', 'zbsj',
- 'pmyzx1', 'pmyzx2', 'pmezx1', 'pmezx2',
- 'whzx1', 'whzx2', 'dyzx1', 'dyzx2',
- 'zczx1', 'zczx2', 'zabw1', 'zabw2',
- 'ylzx1', 'ylzx2', 'hqzx1', 'hqzx2'
- ];
- foreach ($fields as $field) {
- if (!empty($zbInfo->$field)) {
- $zbInfo->$field = str_replace(' ', '', $zbInfo->$field);
- }
- }
- }
- $data = [
- // 'title' => date('Y年n月j日', strtotime($riqi)).'值班信息',
- 'zzb' => [], // 主值班
- 'fzb' => [], // 副值班
- 'gbdd' => [], // 跟班地点
- 'zbsj' => [], // 值班司机
- 'pmyzx' => [], // 配煤一中心
- 'pmezx' => [], // 配煤二中心
- 'whzx' => [], // 维护中心
- 'dyzx' => [], // 电仪中心
- 'zczx' => [], // 渣场中心
- 'zabw' => [], // 治安保卫
- 'ylzx' => [], // 原料中心
- 'hqzx' => [] // 后勤中心
- ];
- $fieldMap = [
- 'zzb' => ['zzb','zzb2'],
- 'fzb' => ['fzb1', 'fzb2'],
- 'gbdd' => ['gbdd1','gbdd2'],
- 'zbsj' => ['zbsj'],
- 'pmyzx' => ['pmyzx1','pmyzx2'],
- 'pmezx' => ['pmezx1','pmezx2'],
- 'whzx' => ['whzx1','whzx2'],
- 'dyzx' => ['dyzx1','dyzx2'],
- 'zczx' => ['zczx1','zczx2'],
- 'zabw' => ['zabw1','zabw2'],
- 'ylzx' => ['ylzx1','ylzx2'],
- 'hqzx' => ['hqzx1','hqzx2'],
- ];
- $namesToQuery = array_filter([
- $zbInfo->zzb,
- $zbInfo->zzb2,
- $zbInfo->fzb1,
- $zbInfo->fzb2,
- $zbInfo->zbsj,
- $zbInfo->pmyzx1,
- $zbInfo->pmyzx2,
- $zbInfo->pmezx1,
- $zbInfo->pmezx2,
- $zbInfo->whzx1,
- $zbInfo->whzx2,
- $zbInfo->dyzx1,
- $zbInfo->dyzx2,
- $zbInfo->zczx1,
- $zbInfo->zczx2,
- $zbInfo->zabw1,
- $zbInfo->zabw2,
- $zbInfo->ylzx1,
- $zbInfo->ylzx2,
- $zbInfo->hqzx1,
- $zbInfo->hqzx2
- ]);
- $peopleInfo = [];
- if (!empty($namesToQuery)) {
- $peopleData = DB::connection('mysql_fwe10')
- ->table('uf_gggs_rygl as r1')
- ->whereIn('xm', $namesToQuery)
- ->whereRaw('CREATE_TIME = (
- SELECT MAX(CREATE_TIME)
- FROM uf_gggs_rygl as r2
- WHERE r2.xm = r1.xm)')
- ->where('is_delete',0)
- ->get()
- ->keyBy('xm');
- foreach ($peopleData as $person) {
- $peopleInfo[$person->xm] = $person->dh ?? '';
- }
- }
- foreach ($fieldMap as $dataKey => $dbFields) {
- foreach ($dbFields as $field) {
- if (!empty($zbInfo->$field)) {
- $name = $zbInfo->$field;
- $phone = $peopleInfo[$name] ?? '';
- $data[$dataKey][] = $phone ? $name . $phone : $name;
- }
- }
- }
- $result['data'] = $data;
- return self::successResponse($result);
- }
- //公管公司值班查询
- public function dutySearch(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $name = Input::get('name', '');
- $start_date = Input::get('start_date', '');
- $end_date = Input::get('end_date', '');
- if (!$name) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$start_date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$end_date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $people = DB::connection('mysql_fwe10')->table('uf_gggs_rygl')->where('xm',$name)->where('is_delete',0)->orderBy('create_time','desc')->first();
- $mobile = '';
- if(!empty($people) && $people->dh != null && $people->dh != ''){
- $mobile = '('.$people->dh.')';
- }
- $result['title'] = $name.$mobile.date('Y年n月j日', strtotime($start_date)).'至'.date('Y年n月j日', strtotime($end_date)).'值班记录';
- $list = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->whereBetween('riqi', [$start_date, $end_date])
- ->whereIn('id', function($subQuery) {
- $subQuery->selectRaw('MAX(id)') // 获取每个日期的最大create_time对应的记录
- ->from('uf_gggs_zbgl')
- ->groupBy('riqi'); // 按riqi分组
- })->where('is_delete',0)->orderBy('riqi')->get();
- $data = [];
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $riqi = date('Y/n/j', strtotime($list[$i]->riqi));
- if($list[$i]->zzb == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'主值班'
- ]);
- }
- if($list[$i]->zzb2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'主值班'
- ]);
- }
- if($list[$i]->fzb1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'副值班'
- ]);
- }
- if($list[$i]->fzb2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'副值班'
- ]);
- }
- if($list[$i]->zbsj == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'值班司机'
- ]);
- }
- if($list[$i]->pmyzx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'配煤一中心'
- ]);
- }
- if($list[$i]->pmyzx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'配煤一中心'
- ]);
- }
- if($list[$i]->pmezx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'配煤二中心'
- ]);
- }
- if($list[$i]->pmezx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'配煤二中心'
- ]);
- }
- if($list[$i]->whzx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'维护中心'
- ]);
- }
- if($list[$i]->whzx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'维护中心'
- ]);
- }
- if($list[$i]->dyzx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'电仪中心'
- ]);
- }
- if($list[$i]->dyzx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'电仪中心'
- ]);
- }
- if($list[$i]->zczx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'渣场中心'
- ]);
- }
- if($list[$i]->zczx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'渣场中心'
- ]);
- }
- if($list[$i]->zabw1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'治安保卫'
- ]);
- }
- if($list[$i]->zabw2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'治安保卫'
- ]);
- }
- if($list[$i]->ylzx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'原料中心'
- ]);
- }
- if($list[$i]->ylzx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'原料中心'
- ]);
- }
- if($list[$i]->hqzx1 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'后勤中心'
- ]);
- }
- if($list[$i]->hqzx2 == $name){
- array_push($data,[
- 'date'=>$riqi,
- 'title'=>'后勤中心'
- ]);
- }
- }
- }
- $result['data'] =$data;
- return self::successResponse($result);
- }
- //公管公司值班查询
- public function dutyChange(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $id = Input::get('id', '');
- if (!$id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $apply_record = DB::connection('mysql_fwe10')->table('uf_gggs_hbsq')->where('id',$id)->first();
- dd($apply_record);
- if($apply_record){
- $dw = $apply_record->ssdw;
- if($dw == '主值班'){
- DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$apply_record->hbrq)->where('zzb',$apply_record->sqr)->update(['zzb'=>$apply_record->bhbr]);
- DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$apply_record->rq)->where('zzb',$apply_record->bhbr)->update(['zzb'=>$apply_record->sqr]);
- }
- if($dw == '副值班'){
- DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$apply_record->hbrq)->where('fzb1',$apply_record->sqr)->update(['zzb'=>$apply_record->bhbr]);
- // DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$apply_record->rq)->where('zzb',$apply_record->bhbr)->update(['zzb'=>$apply_record->sqr]);
- }
- dd($dw);
- }
- return self::successResponse($result);
- }
- //公管公司总表值班
- public function sumTableDuty(){
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $date2 = date('Y-m-d', strtotime($date . ' +1 day'));
- $date3 = date('Y-m-d', strtotime($date . ' +2 day'));
- $data = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$date)->orderBy('create_time','desc')->first();
- $data2 = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$date2)->orderBy('create_time','desc')->first();
- $data3 = DB::connection('mysql_fwe10')->table('uf_gggs_zbgl')->where('riqi',$date3)->orderBy('create_time','desc')->first();
- $str = date('n月j日',strtotime($date));
- if($data != null){
- $str = $str.' 主值班:'.$data->zzb.' 副值班:'.$data->fzb1.' '.$data->fzb2.' 跟班地点:'.$data->gbdd1.' '.$data->gbdd2.' A1区';
- }else{
- $str = $str.' 暂无值班信息';
- }
- $str2 = date('n月j日',strtotime($date2));
- if($data2 != null){
- $str2 = $str2.' 主值班:'.$data2->zzb.' 副值班:'.$data2->fzb1.' '.$data2->fzb2.' 跟班地点:'.$data2->gbdd1.' '.$data2->gbdd2.' A1区';
- }else{
- $str2 = $str2.' 暂无值班信息';
- }
- $str3 = date('n月j日',strtotime($date3));
- if($data3 != null){
- $str3 = $str3.' 主值班:'.$data3->zzb.' 副值班:'.$data3->fzb1.' '.$data3->fzb2.' 跟班地点:'.$data3->gbdd1.' '.$data3->gbdd2.' A1区';
- }else{
- $str3 = $str3.' 暂无值班信息';
- }
- $result['data1'] = $str;
- $result['data2'] = $str2;
- $result['data3'] = $str3;
- return $result;
- }
- //公管公司仓储煤仓
- public function coalBunker(){
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $mcmc_zd = ['1号仓储煤仓','2号仓储煤仓','3号仓储煤仓','4号仓储煤仓','5号仓储煤仓','6号仓储煤仓'];
- $pm1 = DB::connection('mysql_fwe10')
- ->table('uf_gggs_ccmc as main')
- ->select('main.id','main.ssdw', 'main.mcmc', 'main.lrsj', 'main.is_delete', 'main.create_time')
- ->whereDate('main.lrsj', $date)
- ->where('main.ssdw', 0)
- ->where('main.is_delete', 0)
- ->whereIn('main.create_time', function ($query) use ($date) {
- $query->select(DB::raw('MAX(create_time)'))
- ->from('uf_gggs_ccmc')
- ->whereDate('lrsj', $date)
- ->where('ssdw', 0)
- ->where('is_delete', 0)
- ->groupBy('mcmc');
- })
- ->orderBy('main.mcmc')->get();
- $total1 = [];
- $temp1 = [];
- $result['total1_num'] = 0;
- $result['list1'] = [];
- if(count($pm1) > 0){
- for($i=0;$i<count($pm1);$i++){
- $result['list1'][$i]['title'] = $mcmc_zd[$pm1[$i]->mcmc];
- $result['list1'][$i]['data'] = DB::connection('mysql_fwe10')->table('uf_gggs_cc_mx')->select('mz','ml','jd','hf','lf','zdts')->where('form_data_id',$pm1[$i]->id)->where('is_delete',0)->get()->toArray();
- if(count($result['list1'][$i]['data']) > 0){
- $data = $result['list1'][$i]['data'];
- for($j=0;$j<count($data);$j++){
- $mz = $data[$j]->mz;
- $ml = $data[$j]->ml;
- $result['total1_num'] = $result['total1_num'] + $ml;
- if (isset($temp1[$mz])) {
- $temp1[$mz] += $ml;
- } else {
- $temp1[$mz] = $ml;
- }
- }
- }
- }
- }
- foreach ($temp1 as $key => $value) {
- $total1[] = [
- 'mz' => $key, // 煤种
- 'ml' => $value // 总煤量
- ];
- }
- $result['total1'] = $total1;
- $pm2 = DB::connection('mysql_fwe10')
- ->table('uf_gggs_ccmc as main')
- ->select('main.id','main.ssdw', 'main.mcmc', 'main.lrsj', 'main.is_delete', 'main.create_time')
- ->whereDate('main.lrsj', $date)
- ->where('main.ssdw', 1)
- ->where('main.is_delete', 0)
- ->whereIn('main.create_time', function ($query) use ($date) {
- $query->select(DB::raw('MAX(create_time)'))
- ->from('uf_gggs_ccmc')
- ->whereDate('lrsj', $date)
- ->where('ssdw', 1)
- ->where('is_delete', 0)
- ->groupBy('mcmc');
- })
- ->orderBy('main.mcmc')->get();
- $total2 = [];
- $temp2 = [];
- $result['total2_num'] = 0;
- $result['list2'] = [];
- if(count($pm2) > 0){
- for($i=0;$i<count($pm2);$i++){
- $result['list2'][$i]['title'] = $mcmc_zd[$pm2[$i]->mcmc];
- $result['list2'][$i]['data'] = DB::connection('mysql_fwe10')->table('uf_gggs_cc_mx')->select('mz','ml','jd','hf','lf','zdts')->where('form_data_id',$pm2[$i]->id)->where('is_delete',0)->get()->toArray();
- if(count($result['list2'][$i]['data']) > 0){
- $data = $result['list2'][$i]['data'];
- for($j=0;$j<count($data);$j++){
- $mz = $data[$j]->mz;
- $ml = $data[$j]->ml;
- $result['total2_num'] = $result['total2_num'] + $ml;
- if (isset($temp2[$mz])) {
- $temp2[$mz] += $ml;
- } else {
- $temp2[$mz] = $ml;
- }
- }
- }
- }
- }
- foreach ($temp2 as $key => $value) {
- $total2[] = [
- 'mz' => $key, // 煤种
- 'ml' => $value // 总煤量
- ];
- }
- $result['total2'] = $total2;
- return $result;
- }
- //公管公司总表火车进煤情况
- public function trainEnterCoal(){
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $start_time = date('Y-m-d 18:00:00', strtotime($date . ' -1 day')); // 2025-10-08 18:00:00
- $end_time = date('Y-m-d 18:00:00', strtotime($date)); // 2025-10-09 18:00:00
- $result['pm1_jh_mmls'] = '/';//配煤一计划末煤列数
- $result['pm1_jh_xhmls'] = '/';//配煤一计划洗混煤列数
- $result['pm1_jh_jmls'] = '/';//配煤一计划精煤列数
- $result['pm1_jh_mmjl'] = '/';//配煤一计划末煤进量
- $result['pm1_jh_xhmjl'] = '/';//配煤一计划洗混煤进量
- $result['pm1_jh_jmjl'] = '/';//配煤一计划精煤进量
- $result['pm1_jh_mmmx'] = '/';//配煤一计划末煤明细
- $result['pm1_jh_xhmmx'] = '/';//配煤一计划洗混煤明细
- $result['pm1_jh_jmmx'] = '/';//配煤一计划精煤明细
- $result['pm1_jh_ls'] = '/';//配煤一计划列数
- $result['pm2_jh_mmls'] = '/';//配煤二计划末煤列数
- $result['pm2_jh_xhmls'] = '/';//配煤二计划洗混煤列数
- $result['pm2_jh_jmls'] = '/';//配煤二计划精煤列数
- $result['pm2_jh_mmjl'] = '/';//配煤二计划末煤进量
- $result['pm2_jh_xhmjl'] = '/';//配煤二计划洗混煤进量
- $result['pm2_jh_jmjl'] = '/';//配煤二计划精煤进量
- $result['pm2_jh_mmmx'] = '/';//配煤二计划末煤明细
- $result['pm2_jh_xhmmx'] = '/';//配煤二计划洗混煤明细
- $result['pm2_jh_jmmx'] = '/';//配煤二计划精煤明细
- $result['pm2_jh_ls'] = '/';//配煤二计划列数
- $result['pm1_sj_mmls'] = '/';//配煤一实际末煤列数
- $result['pm1_sj_xhmls'] = '/';//配煤一实际洗混煤列数
- $result['pm1_sj_jmls'] = '/';//配煤一实际精煤列数
- $result['pm1_sj_mmjl'] = '/';//配煤一实际末煤进量
- $result['pm1_sj_xhmjl'] = '/';//配煤一实际洗混煤进量
- $result['pm1_sj_jmjl'] = '/';//配煤一实际精煤进量
- $result['pm1_sj_mmmx'] = '/';//配煤一实际末煤明细
- $result['pm1_sj_xhmmx'] = '/';//配煤一实际洗混煤明细
- $result['pm1_sj_jmmx'] = '/';//配煤一实际精煤明细
- $result['pm1_sj_ls'] = '/';//配煤一实际列数
- $result['pm1_xhc'] = '/';//配煤一卸火车情况
- $result['pm2_sj_mmls'] = '/';//配煤二实际末煤列数
- $result['pm2_sj_xhmls'] = '/';//配煤二实际洗混煤列数
- $result['pm2_sj_jmls'] = '/';//配煤二实际精煤列数
- $result['pm2_sj_mmjl'] = '/';//配煤二实际末煤进量
- $result['pm2_sj_xhmjl'] = '/';//配煤二实际洗混煤进量
- $result['pm2_sj_jmjl'] = '/';//配煤二实际精煤进量
- $result['pm2_sj_mmmx'] = '/';//配煤二实际末煤明细
- $result['pm2_sj_xhmmx'] = '/';//配煤二实际洗混煤明细
- $result['pm2_sj_jmmx'] = '/';//配煤二实际精煤明细
- $result['pm2_sj_ls'] = '/';//配煤二实际列数
- $result['pm2_xhc'] = '/';//配煤二卸火车情况
- //配煤一计划
- $jh1 = DB::connection('mysql_fwe10')->table('uf_gggs_hcjmjh')
- ->where('create_time', '>=', $start_time)
- ->where('create_time', '<', $end_time)
- ->where('ssdw',0)
- ->where('is_delete',0)
- ->orderBy('create_time', 'desc')
- ->first();
- //配煤二计划
- $jh2 = DB::connection('mysql_fwe10')->table('uf_gggs_hcjmjh')
- ->where('create_time', '>=', $start_time)
- ->where('create_time', '<', $end_time)
- ->where('ssdw',1)
- ->where('is_delete',0)
- ->orderBy('create_time', 'desc')
- ->first();
- //配煤一实际
- $sj1 = DB::connection('mysql_fwe10')->table('uf_gggs_hcsjjm')
- ->where('create_time', '>=', $start_time)
- ->where('create_time', '<', $end_time)
- ->where('ssdw',0)
- ->where('is_delete',0)
- ->orderBy('create_time', 'desc')
- ->first();
- //配煤二实际
- $sj2 = DB::connection('mysql_fwe10')->table('uf_gggs_hcsjjm')
- ->where('create_time', '>=', $start_time)
- ->where('create_time', '<', $end_time)
- ->where('ssdw',1)
- ->where('is_delete',0)
- ->orderBy('create_time', 'desc')
- ->first();
- //计划
- $result['pm1_jh_ls'] = 0;
- if($jh1 != null){
- $result['pm1_jh_mmls'] = $jh1->mmls;//配煤一计划末煤列数
- $result['pm1_jh_xhmls'] = $jh1->xhmls;//配煤一计划洗混煤列数
- $result['pm1_jh_jmls'] = $jh1->jmls;//配煤一计划精煤列数
- $result['pm1_jh_mmjl'] = $jh1->mmjl;//配煤一计划末煤进量
- $result['pm1_jh_xhmjl'] = $jh1->xhmjl;//配煤一计划洗混煤进量
- $result['pm1_jh_jmjl'] = $jh1->jmjl;//配煤一计划精煤进量
- $result['pm1_jh_mmmx'] = $jh1->mmmx;//配煤一计划末煤明细
- $result['pm1_jh_xhmmx'] = $jh1->xhmmx;//配煤一计划洗混煤明细
- $result['pm1_jh_jmmx'] = $jh1->jmmx;//配煤一计划精煤明细
- $result['pm1_jh_ls'] = $jh1->mmls + $jh1->xhmls + $jh1->jmls;//配煤一计划列数
- }
- $result['pm2_jh_ls'] = 0;
- if($jh2 != null){
- $result['pm2_jh_mmls'] = $jh2->mmls;//配煤二计划末煤列数
- $result['pm2_jh_xhmls'] = $jh2->xhmls;//配煤二计划洗混煤列数
- $result['pm2_jh_jmls'] = $jh2->jmls;//配煤二计划精煤列数
- $result['pm2_jh_mmjl'] = $jh2->mmjl;//配煤二计划末煤进量
- $result['pm2_jh_xhmjl'] = $jh2->xhmjl;//配煤二计划洗混煤进量
- $result['pm2_jh_jmjl'] = $jh2->jmjl;//配煤二计划精煤进量
- $result['pm2_jh_mmmx'] = $jh2->mmmx;//配煤二计划末煤明细
- $result['pm2_jh_xhmmx'] = $jh2->xhmmx;//配煤二计划洗混煤明细
- $result['pm2_jh_jmmx'] = $jh2->jmmx;//配煤二计划精煤明细
- $result['pm2_jh_ls'] = $jh2->mmls + $jh2->xhmls + $jh2->jmls;//配煤二计划列数
- }
- $result['jh_hj'] = $result['pm1_jh_ls'] + $result['pm2_jh_ls'];//计划合计
- //实际
- $result['pm1_sj_ls'] = 0;
- $bz1 = '';
- if($sj1 != null){
- $result['pm1_sj_mmls'] = $sj1->mmls;//配煤一实际末煤列数
- $result['pm1_sj_xhmls'] = $sj1->xhmls;//配煤一实际洗混煤列数
- $result['pm1_sj_jmls'] = $sj1->jmls;//配煤一实际精煤列数
- $result['pm1_sj_mmjl'] = $sj1->mmjl;//配煤一实际末煤进量
- $result['pm1_sj_xhmjl'] = $sj1->xhmjl;//配煤一实际洗混煤进量
- $result['pm1_sj_jmjl'] = $sj1->jmjl;//配煤一实际精煤进量
- $result['pm1_sj_mmmx'] = $sj1->mmmx;//配煤一实际末煤明细
- $result['pm1_sj_xhmmx'] = $sj1->xhmmx;//配煤一实际洗混煤明细
- $result['pm1_sj_jmmx'] = $sj1->jmmx;//配煤一实际精煤明细
- $result['pm1_sj_ls'] = $sj1->mmls + $sj1->xhmls + $sj1->jmls;//配煤一实际列数
- $result['pm1_xhc'] = $sj1->xhcqk;//配煤一卸火车情况
- $bz1 = trim($sj1->bz ?? '');
- }
- $result['pm2_sj_ls'] = 0;
- $bz2 = '';
- if($sj2 != null){
- $result['pm2_sj_mmls'] = $sj2->mmls;//配煤二实际末煤列数
- $result['pm2_sj_xhmls'] = $sj2->xhmls;//配煤二实际洗混煤列数
- $result['pm2_sj_jmls'] = $sj2->jmls;//配煤二实际精煤列数
- $result['pm2_sj_mmjl'] = $sj2->mmjl;//配煤二实际末煤进量
- $result['pm2_sj_xhmjl'] = $sj2->xhmjl;//配煤二实际洗混煤进量
- $result['pm2_sj_jmjl'] = $sj2->jmjl;//配煤二实际精煤进量
- $result['pm2_sj_mmmx'] = $sj2->mmmx;//配煤二实际末煤明细
- $result['pm2_sj_xhmmx'] = $sj2->xhmmx;//配煤二实际洗混煤明细
- $result['pm2_sj_jmmx'] = $sj2->jmmx;//配煤二实际精煤明细
- $result['pm2_sj_ls'] = $sj2->mmls + $sj2->xhmls + $sj2->jmls;//配煤二实际列数
- $result['pm2_xhc'] = $sj2->xhcqk;//配煤二卸火车情况
- $bz2 = trim($sj2->bz ?? '');
- }
- $result['sj_hj'] = $result['pm1_sj_ls'] + $result['pm2_sj_ls'];//实际合计
- if (empty($bz1) && empty($bz2)) {
- $result['bz'] = '无';
- } else {
- $result['bz'] = implode(';', array_filter([$bz1, $bz2]));
- }
- foreach ($result as $key => &$value) {
- if ($value === null) {
- $value = '/';
- }
- }
- unset($value);
- return $result;
- }
- //腾讯位置接口服务
- public function sendRequest($url, $params) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $response = curl_exec($ch);
- curl_close($ch);
- return json_decode($response, true);
- }
- public function httpRequest($url, $format = 'get', $data = null){
- //设置头信息
- $headerArray =array("Content-type:application/json;","Accept:application/json");
- $curl=curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
- if ($format == 'post') {
- //post传值设置post传参
- curl_setopt($curl, CURLOPT_POST, 1);
- if ($data) {
- $data = json_encode($data);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- }
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
- $data=json_decode(curl_exec($curl), true);
- curl_close($curl);
- //返回接口返回数据
- return $data;
- }
- }
|