ApiController.php 51 KB

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