Minong.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * minong数据接口
  8. */
  9. class Minong extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /*
  22. *1、 获取各省份订单量接口
  23. * */
  24. public function getProvinceData(){
  25. $date = date('Y');
  26. $startTime = $date.'-01-01 00:00:00';
  27. $res = Db::connect('db2')
  28. ->query("select distinct Gd_khdh,Gd_khmc,round(sum(订单数量),2) as number from 工单_基本资料 where 接单日期 > '{$startTime}' and 订单数量 > 0 group by Gd_khdh order by number desc ");
  29. $res = array_slice($res,0,10);//取前十名
  30. foreach ($res as $key=>$value){
  31. $res[$key]['Gd_khdh'] = trim($value['Gd_khdh']);
  32. $res[$key]['Gd_khmc'] = mb_substr(trim($value['Gd_khmc']),0,4,'utf-8');//取4位中文
  33. }
  34. $this->success('请求成功',$res);
  35. }
  36. /*
  37. * 2、获取设备当前状态
  38. * */
  39. public function getEmStatus(){
  40. if (Request::instance()->isGet()){
  41. $this->error('非法请求');
  42. }
  43. $params = input('emid');
  44. if (empty($params)){
  45. $this->error('参数错误');
  46. }
  47. $emid = $params.'#';
  48. $res = Db::connect('db2')
  49. ->query("select 设备编号 as emid,工单编号 as Gd_gdbh,班组编号 as Yj_member,当前状态 as status,Uniqid from 设备_产量采集 where 设备编号 = '{$emid}' order by Uniqid desc limit 1");
  50. $list = array();
  51. $Gdbh = $res[0]['Gd_gdbh'];
  52. $Yj_res = Db::connect('db2')
  53. ->query("select yj_yjmc from 工单_印件资料 where Yj_Gdbh = '{$Gdbh}' limit 1");
  54. $Yj_yjmc = rtrim($Yj_res[0]['yj_yjmc']);
  55. $list['emid'] = $params;
  56. $list['status'] = $res[0]['status'];
  57. $list['Yj_yjmc'] = $Yj_yjmc;
  58. if ($res[0]['status'] == '生产'){
  59. $time = date('Y-m-d H:i:s');
  60. $firstStartTime = date('Y-m-d').' 08:30:00';//白班开工时间
  61. $firstEndTime = date('Y-m-d').' 20:30:00';//白班结束时间、晚班开工时间
  62. $lastEndTime = strtotime("+1 day",strtotime(date('Y-m-d').' 08:30:00'));//晚班结束时间
  63. $strTime = strtotime($time);
  64. if ($strTime>strtotime($firstStartTime) && $strTime < strtotime($firstEndTime)){//表示在上白班,8点到20点
  65. $out_res = Db::connect('db2')
  66. ->query("select sum(sczl_cl) as number,sum(sczl_装版工时) as zb_time, sum(sczl_保养工时) as by_time,
  67. sum(sczl_打样工时) as dy_time,sum(sczl_异常停机工时) as yctj_time,sum(sczl_异常工时1) as yc_time , sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4
  68. from 设备_产量计酬 where sczl_jtbh = '{$emid}' and 开工时间 = '{$firstStartTime}' ");
  69. $hour = $strTime - strtotime($firstStartTime);
  70. // $hour_res = intval($hour/3600);
  71. }
  72. if ($strTime > strtotime($firstEndTime) && $strTime < $lastEndTime){//表示在上夜班,20点到第二天8点
  73. $out_res = Db::connect('db2')
  74. ->query("select sum(sczl_cl) as number,sum(sczl_装版工时) as zb_time, sum(sczl_保养工时) as by_time,
  75. sum(sczl_打样工时) as dy_time,sum(sczl_异常停机工时) as yctj_time,sum(sczl_异常工时1) as yc_time , sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4
  76. from 设备_产量计酬 where sczl_jtbh = '{$emid}' and 开工时间 = '{$firstEndTime}' ");
  77. $hour = $strTime - strtotime($firstEndTime);
  78. }
  79. $hour_res = round($hour/3600);
  80. $hours = $out_res[0]['zb_time']+$out_res[0]['by_time']+$out_res[0]['dy_time']+$out_res[0]['yctj_time']+$out_res[0]['yc_time'];
  81. $validTime = $hour_res - $hours; //实际工作时间
  82. //扣除11.30和4.30的吃饭时间,各一个小时,11.30夜宵
  83. if ($strTime > strtotime(date('Y-m-d').' 12:30:00') && $strTime <strtotime(date('Y-m-d'.' 17:30:00')) ){
  84. $validTime = $validTime -1;
  85. }
  86. if ($strTime > strtotime(date('Y-m-d'.' 17:30:00')) && $strTime < strtotime($firstEndTime)){
  87. $validTime = $validTime -2;
  88. }
  89. if ($strTime > strtotime(date('Y-m-d').' 23:30:00')){
  90. $validTime = $validTime -2;
  91. }
  92. // print_r($validTime);die;
  93. $list['Yj_yield'] = $out_res[0]['number'];
  94. $list['production_efficiency'] = round($out_res[0]['number'] / $validTime);
  95. $list['production_rate'] = $list['production_efficiency']/10000*100 .'%';
  96. $member = $out_res[0];
  97. unset($member['number']);
  98. unset($member['zb_time']);
  99. unset($member['by_time']);
  100. unset($member['dy_time']);
  101. unset($member['yctj_time']);
  102. unset($member['yc_time']);
  103. $member = array_values($member);
  104. // print_r($member);die;
  105. if (empty($member[3])){
  106. unset($member[3]);
  107. $member_res = Db::connect('db2')
  108. ->query("select 员工姓名 as Yj_member from 人事_基本资料 where 员工编号 in ('{$member[0]}','{$member[1]}','{$member[2]}')");
  109. }else{
  110. $member_res = Db::connect('db2')
  111. ->query("select 员工姓名 as Yj_member from 人事_基本资料 where 员工编号 in ('{$member[0]}','{$member[1]}','{$member[2]}','{$member[3]}')");
  112. }
  113. // print_r($member_res);die;
  114. $str='';
  115. foreach ($member_res as $key=>$value){
  116. $str = $str.trim($value['Yj_member']).',';
  117. }
  118. $list['Yj_member'] = substr($str,0,strrpos($str,','));
  119. }else{
  120. $list['Yj_yield'] = '';
  121. $list['production_efficiency'] = '';
  122. $list['production_rate'] = '';
  123. $list['Yj_member'] = '';
  124. }
  125. $this->success('请求成功',$list);
  126. }
  127. /*
  128. * 3、获取年度销售量统计
  129. * */
  130. public function getMouthNumber(){
  131. $year = date('Y');
  132. $res = Db::connect('db2')
  133. ->query("select
  134. sum(case month(`接单日期`) when '1' then `订单数量` else 0 end) as Jan,
  135. sum(case month(`接单日期`) when '2' then `订单数量` else 0 end) as Feb,
  136. sum(case month(`接单日期`) when '3' then `订单数量` else 0 end) as Mar,
  137. sum(case month(`接单日期`) when '4' then `订单数量` else 0 end) as Apr,
  138. sum(case month(`接单日期`) when '5' then `订单数量` else 0 end) as May,
  139. sum(case month(`接单日期`) when '6' then `订单数量` else 0 end) as June,
  140. sum(case month(`接单日期`) when '7' then `订单数量` else 0 end) as July,
  141. sum(case month(`接单日期`) when '8' then `订单数量` else 0 end) as Aug,
  142. sum(case month(`接单日期`) when '9' then `订单数量` else 0 end) as Sept,
  143. sum(case month(`接单日期`) when '10' then `订单数量` else 0 end) as Oct,
  144. sum(case month(`接单日期`) when '11' then `订单数量` else 0 end) as Nov,
  145. sum(case month(`接单日期`) when '12' then `订单数量` else 0 end) as Dece
  146. from `工单_基本资料` where year(`接单日期`) = '{$year}' ");
  147. // print_r($res[0]);die;
  148. $this->success('请求成功',$res[0]);
  149. }
  150. /*
  151. * 4、获取设备排产状态
  152. * */
  153. public function getEmWorkStatus(){
  154. if (Request::instance()->isGet()){
  155. $this->error('非法请求');
  156. }
  157. $params = input('emid');
  158. if (empty($params)){
  159. $this->error('参数错误');
  160. }
  161. $emid = $params.'#';
  162. $res = Db::connect('db2')
  163. ->query("select Uniqid,工单编号 as sczl_gdbh,当前状态 as status from 设备_产量采集 where 设备编号 = '{$emid}' order by Uniqid desc limit 1");
  164. $result = array();
  165. if(empty($res[0]['sczl_gdbh'])){
  166. $result['em_status'] = $res[0]['status'];
  167. $result['Gd_gdbh'] = '';
  168. $result['Yj_yjmc'] = '';
  169. $result['plan_output'] = '';
  170. $result['finished_output'] = '';
  171. $result['scrap_rate'] = '';
  172. $result['Gd_status'] = '';
  173. $this->success('请求成功',$result);
  174. }
  175. $Gd_gdbh = $res[0]['sczl_gdbh'];//工单编号
  176. $yjmc_res = Db::connect('db2')
  177. ->query("select yj_yjmc,yj_zzdh from 工单_印件资料 where Yj_Gdbh = '{$Gd_gdbh}'");
  178. $Yj_yjmc = rtrim($yjmc_res[0]['yj_yjmc']);//工艺名称
  179. $Yj_zzdh = rtrim($yjmc_res[0]['yj_zzdh']);//纸张代号
  180. $gy_bom = Db::connect('db2')
  181. ->query("select Bom_计划用量 as plan_output from 工单_bom资料 where BOM_工单编号 = '{$Gd_gdbh}' and BOM_物料编码 = '{$Yj_zzdh}'");
  182. $plan_output = empty($gy_bom) ? ' ' : round($gy_bom[0]['plan_output'],2);//计划产量,目前不知道怎么计算
  183. $out_res = Db::connect('db2')
  184. ->query("select sum(sczl_cl) as number,sum(sczl_zcfp) as scrap from 设备_产量计酬
  185. where sczl_gdbh = '{$Gd_gdbh}' and sczl_jtbh = '{$emid}' ");
  186. $finished_output = $out_res[0]['number'];
  187. if ($finished_output == 0 && $out_res[0]['scrap']== 0){
  188. $scrap = 0 .'%';
  189. $finished_output = '';
  190. }else{
  191. $scrap =round($out_res[0]['scrap'] / ($finished_output+$out_res[0]['scrap']),4) *100 .'%';
  192. }
  193. $result['em_status'] = $res[0]['status'];
  194. $result['Gd_gdbh'] = $Gd_gdbh;
  195. $result['Yj_yjmc'] = $Yj_yjmc;
  196. $result['plan_output'] = $plan_output;
  197. $result['finished_output'] = $finished_output;
  198. $result['scrap_rate'] = $scrap;
  199. $result['Gd_status'] = '2-生产中';
  200. // print_r($result);die;
  201. $this->success('请求成功',$result);
  202. }
  203. /*
  204. * 5、获取设备月产量
  205. * */
  206. public function getEmMouthNumber(){
  207. if (Request::instance()->isGet()){
  208. $this->error('非法请求');
  209. }
  210. $params = input('emid');
  211. if (empty($params)){
  212. $this->error('参数错误');
  213. }
  214. $emid = $params.'#';
  215. $year = date('Y');
  216. $res = Db::connect('db2')
  217. ->query("select
  218. sum(case month(`开工时间`) when '1' then `sczl_cl` else 0 end) as Jan,
  219. sum(case month(`开工时间`) when '2' then `sczl_cl` else 0 end) as Feb,
  220. sum(case month(`开工时间`) when '3' then `sczl_cl` else 0 end) as Mar,
  221. sum(case month(`开工时间`) when '4' then `sczl_cl` else 0 end) as Apr,
  222. sum(case month(`开工时间`) when '5' then `sczl_cl` else 0 end) as May,
  223. sum(case month(`开工时间`) when '6' then `sczl_cl` else 0 end) as June,
  224. sum(case month(`开工时间`) when '7' then `sczl_cl` else 0 end) as July,
  225. sum(case month(`开工时间`) when '8' then `sczl_cl` else 0 end) as Aug,
  226. sum(case month(`开工时间`) when '9' then `sczl_cl` else 0 end) as Sept,
  227. sum(case month(`开工时间`) when '10' then `sczl_cl` else 0 end) as Oct,
  228. sum(case month(`开工时间`) when '11' then `sczl_cl` else 0 end) as Nov,
  229. sum(case month(`开工时间`) when '12' then `sczl_cl` else 0 end) as Dece
  230. from `设备_产量计酬` where year(`开工时间`) = '{$year}' and sczl_jtbh='{$emid}'");
  231. $this->success('请求成功',$res[0]);
  232. }
  233. /*
  234. * 6、获取设备月度运行时长
  235. * */
  236. public function getEmRunTime(){
  237. if (Request::instance()->isGet()){
  238. $this->error('非法请求');
  239. }
  240. $params = input('emid');
  241. if (empty($params)){
  242. $this->error('参数错误');
  243. }
  244. $emid = $params.'#';
  245. $year = date('Y');
  246. $out_res = Db::connect('db2')
  247. ->query("select
  248. month(开工时间) as worktime,sum(sczl_装版工时) as em_time_zb,sum(sczl_保养工时) as em_time_by,sum(sczl_打样工时) as em_time_dy,sum(sczl_异常停机工时) as em_time_tj,
  249. sum(sczl_设备运行工时) as em_time_run,sum(sczl_异常工时1) as em_time_yc
  250. from 设备_产量计酬 where year(开工时间) = '{$year}' and sczl_jtbh = '{$emid}'
  251. and (sczl_装版工时>0 or sczl_保养工时>0 or sczl_打样工时>0 or sczl_异常停机工时>0 or sczl_设备运行工时>0 or sczl_异常工时1>0) group by worktime ");
  252. $number = count($out_res);
  253. $displarityNumber = 12 - $number;
  254. if ($displarityNumber > 0){
  255. for ($i=$number;$i<12;$i++){
  256. $arr = array();
  257. $arr['worktime'] = $i+1;
  258. $arr['em_time_zb'] = '0';
  259. $arr['em_time_by'] = '0';
  260. $arr['em_time_dy'] = '0';
  261. $arr['em_time_tj'] = '0';
  262. $arr['em_time_run'] = '0';
  263. $arr['em_time_yc'] = '0';
  264. array_push($out_res,$arr);
  265. }
  266. }
  267. $this->success('请求成功',$out_res);
  268. }
  269. /*
  270. * 7、获取机台合格率、达成率
  271. * */
  272. public function getEmRate(){
  273. if (Request::instance()->isGet()){
  274. $this->error('非法请求');
  275. }
  276. $params = input('emid');
  277. if (empty($params)){
  278. $this->error('参数错误');
  279. }
  280. $emid = $params.'#';
  281. $output_res = Db::connect('db2')
  282. ->query("select 工单编号 as Gd_gdbh,当前状态 as status,UniqId from 设备_产量采集 where 设备编号='{$emid}' order by UniqId desc limit 1 ");
  283. if ($output_res[0]['status'] == '生产'){
  284. $Gd_gdbh = $output_res[0]['Gd_gdbh'];
  285. $hour_output = Db::connect('db2')
  286. ->query("select case ISNULL(B类产能) when 1 then A类产能 else B类产能 end as A_output,Gy0_小时产能 as hour_output
  287. from 工单_工艺资料 where Gy0_gdbh = '{$Gd_gdbh}' and Gy0_sbbh = '{$emid}'");
  288. $output = empty($hour_output[0]['A_output'])?$hour_output[0]['hour_output'] : $hour_output[0]['A_output'];
  289. $time = strtotime(date('Y-m-d H:i:s'));
  290. $firstStartTime = date('Y-m-d').' 08:30:00';//白班开工时间
  291. $firstEndTime = date('Y-m-d').' 20:30:00';//白班结束时间、晚班开工时间
  292. if (strtotime($firstStartTime) < $time && strtotime($firstEndTime) > $time){
  293. $whereTime = $firstStartTime;
  294. $hour = $time - strtotime($firstStartTime);
  295. }else{
  296. $whereTime = $firstEndTime;
  297. $hour = $time - strtotime($firstStartTime);
  298. }
  299. $now_output = Db::connect('db2')
  300. ->query("select sum(sczl_cl) as output,sum(sczl_zcfp) as scrap,sum(sczl_装版工时+sczl_打样工时+sczl_异常停机工时+sczl_异常工时1) as time
  301. from 设备_产量计酬 where sczl_jtbh='{$emid}' and 开工时间='{$whereTime}'");
  302. $hour_res = round($hour/3600);
  303. $validTime = $hour_res - $now_output[0]['time']; //实际工作时间
  304. //扣除11.30和4.30的吃饭时间,各一个小时,11.30夜宵
  305. if ($time > strtotime(date('Y-m-d').' 12:30:00') && $time <strtotime(date('Y-m-d'.' 17:30:00')) ){
  306. $validTime = $validTime -1;
  307. }
  308. if ($time > strtotime(date('Y-m-d'.' 17:30:00')) && $time < strtotime($firstEndTime)){
  309. $validTime = $validTime -2;
  310. }
  311. if ($time > strtotime(date('Y-m-d').' 23:30:00')){
  312. $validTime = $validTime -2;
  313. }
  314. // print_r($validTime);die;
  315. $list = array();
  316. $list['status'] = $output_res[0]['status'];
  317. $list['emid_qualified_rate'] =round($now_output[0]['output'] /($now_output[0]['output'] + $now_output[0]['scrap']),5) *100 .'%';
  318. $list['emid_reach_rate'] = round($now_output[0]['output'] / $validTime,4)/ $output * 100 . '%';
  319. $this->success('请求成功',$list);
  320. }
  321. $result = array();
  322. $result['status'] = $output_res[0]['status'];
  323. $result['emid_qualified_rate'] = 0;
  324. $result['emid_reach_rate'] = 0;
  325. $this->success('请求成功',$result);
  326. }
  327. /*
  328. * 8、获取上个月机台废品明细比例
  329. * */
  330. public function getEmScrap(){
  331. if (Request::instance()->isGet()){
  332. $this->error('非法请求');
  333. }
  334. $params = input('emid');
  335. if (empty($params)){
  336. $this->error('参数错误');
  337. }
  338. $emid = $params.'#';
  339. $date = date('Y-m',strtotime("-1 month"));
  340. $year = substr($date,0,4);//年
  341. $month = substr($date,5,2);//上月
  342. $em_res = Db::connect('db2')
  343. ->query("select distinct(sczl_gdbh) as Gd_gdbh from `设备_产量计酬` where `sczl_jtbh`='{$emid}' and year(开工时间)='{$year}' and month(开工时间)='{$month}' ");
  344. $arr = array_column($em_res,'Gd_gdbh');
  345. foreach ($arr as $key=>$value){
  346. $arr[$key] = "'".$value."'";
  347. }
  348. $str = implode(',',$arr);
  349. $scrap_res = Db::connect('db2')
  350. ->query("select 废品类别 as scrap_type,sum(废品数量) as scrap_number
  351. from `rec_月度废品汇总` where Gd_gdbh in ($str) and `废品类别` like '%E%' GROUP BY `废品类别` ORDER BY scrap_number desc ");
  352. $allNumber = Db::connect('db2')
  353. ->query("select distinct(Gd_gdbh),实际投料 as number from `rec_月度废品汇总` where Gd_gdbh in ($str) ");
  354. $number = array_sum(array_column($allNumber,'number'));
  355. $number = $number * 10000;
  356. foreach ($scrap_res as $k=>$v){
  357. $scrap_res[$k]['scrap_type'] = rtrim($v['scrap_type']);
  358. $scrap_res[$k]['scrap_rate'] = round($v['scrap_number']/$number,5) * 100 .'%';
  359. }
  360. $this->success('请求成功',$scrap_res);
  361. }
  362. /*
  363. * 9、获取机台该产品上批次问题
  364. * */
  365. public function getLastScrapType(){
  366. if (Request::instance()->isGet()){
  367. $this->error('非法请求');
  368. }
  369. $params = input('emid');
  370. if (empty($params)){
  371. $this->error('参数错误');
  372. }
  373. $emid = $params.'#';
  374. $em_res = Db::connect('db2')
  375. ->query("select distinct(`工单编号`) as Gd_gdbh,UniqId from `设备_产量采集` where `设备编号`='{$emid}' ORDER BY UniqId desc limit 1 ");
  376. $Gd_gdbh = $em_res[0]['Gd_gdbh'];
  377. $gd_res = Db::connect('db2')
  378. ->query("select Gd_cpdh from `工单_基本资料` where Gd_gdbh = '{$Gd_gdbh}' ");
  379. $Gd_cpdh = $gd_res[0]['Gd_cpdh'];
  380. $cp_res = Db::connect('db2')
  381. ->query("select distinct(a.Gy0_gdbh) as Gd_gdbh ,b.Gd_cpdh,b.Gd_cpmc,a.UniqId
  382. from `工单_工艺资料` a LEFT JOIN `工单_基本资料` b on a.Gy0_gdbh = b.Gd_gdbh where a.Gy0_sbbh='{$emid}'
  383. and b.Gd_cpdh = '{$Gd_cpdh}' and a.Gy0_gdbh != '{$Gd_gdbh}' ORDER BY a.UniqId desc limit 1 ");
  384. $scrap_gdbh = $cp_res[0]['Gd_gdbh'];
  385. $scrap_res = Db::connect('db2')
  386. ->query("select Gd_gdbh,废品类别 as scrap_type,废品数量 as scrap_number,实际投料 as feeding
  387. from `rec_月度废品汇总` where Gd_gdbh = '{$scrap_gdbh}' and 废品类别 like '%E%' ORDER BY `废品数量` desc limit 3");
  388. if (empty($scrap_res)){
  389. $result = array();
  390. $result['product_name'] = rtrim($cp_res[0]['Gd_cpmc']);
  391. $result['Gd_gdbh'] = $scrap_gdbh;
  392. $result['scrap_type'] = '';
  393. $result['scrap_number'] = '';
  394. $result['scrap_radio'] = '';
  395. $this->success('请求成功',$result);
  396. }else{
  397. foreach ($scrap_res as $key=>$value){
  398. $scrap_res[$key]['product_name'] = rtrim($cp_res[0]['Gd_cpmc']);
  399. $scrap_res[$key]['scrap_radio'] = round($value['scrap_number'] / ($value['feeding'] * 10000),5) * 100 .'%';
  400. unset($scrap_res[$key]['feeding']);
  401. }
  402. $this->success('请求成功',$scrap_res);
  403. }
  404. }
  405. /*
  406. * 10、获取机台最近一周报废原因前三名
  407. * */
  408. public function getLastWeekScrap(){
  409. if (Request::instance()->isGet()){
  410. $this->error('非法请求');
  411. }
  412. $lastMonth = date("Ym", strtotime("-1 month"));
  413. $scrap_res = Db::connect('db2')
  414. ->query("select 废品类别 as scrap_type,sum(废品数量) as scrap_number
  415. from `rec_月度废品汇总` where 年月='{$lastMonth}' and 废品类别 like '%E%' group by 废品类别 order by scrap_number desc limit 3");
  416. $feed_res = Db::connect('db2')
  417. ->query("select distinct(Gd_gdbh),实际投料 as number from `rec_月度废品汇总` where 年月='{$lastMonth}' and 废品类别 like '%E%'");
  418. $number = array_sum(array_column($feed_res,'number'));
  419. foreach ($scrap_res as $key => $value){
  420. $scrap_res[$key]['scrap_radio'] = round($value['scrap_number'] / ($number * 10000),5) *100 . '%';
  421. }
  422. $this->success('请求成功',$scrap_res);
  423. }
  424. /*
  425. * 11、获取工序大废品奖惩记录
  426. * */
  427. public function getRewardAndPunish(){
  428. $date = date('Y-m-d',strtotime('-1 day'));
  429. $department = '胶印';
  430. $scrap_res = Db::connect('db2')
  431. ->query("select a.sczl_gdbh as Gd_gdbh,rtrim(a.sczl_fplxA) as scrap_type,a.sys_rq as date,
  432. rtrim(a.`责任部门` ) as department,a.sczl_ls as ls,a.sczl_cl as big_scrap, a.sczl_bh1,a.sczl_bh2,rtrim(c.员工姓名) as nameOne,rtrim(b.yj_yjmc) as Yj_yjmc
  433. from `db_大废品` a
  434. left join `工单_印件资料` b on a.sczl_gdbh = b.Yj_Gdbh
  435. left join `人事_基本资料` c on a.sczl_bh1= c.员工编号
  436. where date_format(a.sys_rq,'%Y-%m-%d') = '{$date}' and a.`责任部门` = '{$department}' and b.yj_Yjno = a.sczl_yjno");
  437. if (empty($scrap_res)){
  438. $this->success('请求成功','');
  439. }
  440. $name_res = array_column($scrap_res,'sczl_bh2');
  441. foreach ($name_res as $key=>$value){
  442. $name_res[$key] = "'".$value."'";
  443. }
  444. $str = implode(',',$name_res);
  445. $name_bh = Db::connect('db2')
  446. ->query("select `员工编号` as bh2,`员工姓名` as name2 from `人事_基本资料` where `员工编号` in ($str)");
  447. foreach ($scrap_res as $k=>$v){
  448. foreach ($name_bh as $i=>$j){
  449. if ($v['sczl_bh2'] == $j['bh2']){
  450. $scrap_res[$k]['nameTwo'] = rtrim($j['name2']);
  451. }
  452. }
  453. unset($scrap_res[$k]['sczl_bh1']);
  454. unset($scrap_res[$k]['sczl_bh2']);
  455. }
  456. $this->success('请求成功',$scrap_res);
  457. }
  458. /*
  459. * 12、获取机台距上次带班检查时间
  460. * */
  461. public function getLastTest(){
  462. if (Request::instance()->isGet()){
  463. $this->error('非法请求');
  464. }
  465. $params = input('emid');
  466. if (empty($params)){
  467. $this->error('参数错误');
  468. }
  469. $emid = $params.'#';
  470. $time = strtotime(date('Y-m-d H:i:s'));
  471. $firstStartTime = date('Y-m-d').' 08:30:00';//白班开工时间
  472. $firstEndTime = date('Y-m-d').' 20:30:00';//白班结束时间、晚班开工时间
  473. if (strtotime($firstStartTime) < $time && strtotime($firstEndTime) > $time){
  474. $whereTime = $firstStartTime;
  475. }else{
  476. $whereTime = $firstEndTime;
  477. }
  478. //首检
  479. $test_one = Db::connect('db2')
  480. ->query("select distinct 提交时间 as submitTime from 制程检验_记录 where 设备编号 = '{$emid}' and 开工时间 = '{$whereTime}' and 类别 = '首件与过程确认' order by 提交时间 desc");
  481. $res_one = empty($test_one) ? round(($time-strtotime($whereTime))/3600) :round(($time-strtotime($test_one[0]['submitTime']))/3600);
  482. $list = array();
  483. $list['test_one'] = $res_one;
  484. //机台自检
  485. $test_machine = Db::connect('db2')
  486. ->query("select distinct 提交时间 as submitTime from 制程检验_记录 where 设备编号 = '{$emid}' and 开工时间 = '{$whereTime}' and 类别 = '机台检验' order by 提交时间 desc");
  487. $machine_res = empty($test_machine) ? round(($time-strtotime($whereTime))/3600) :round(($time-strtotime($test_machine[0]['submitTime']))/3600);
  488. $list['test_machine'] = $machine_res;
  489. //IPQC检验
  490. $test_IPQC = Db::connect('db2')
  491. ->query("select distinct 提交时间 as submitTime from 制程检验_记录 where 设备编号 = '{$emid}' and 开工时间 = '{$whereTime}' and 类别 = 'IPQC检验' order by 提交时间 desc");
  492. $res = empty($test_IPQC) ? round(($time-strtotime($whereTime))/3600) :round(($time-strtotime($test_IPQC[0]['submitTime']))/3600);
  493. $list['test_IPQC'] = $res;
  494. $this->success('请求成功',$list);
  495. }
  496. /**
  497. * 13、获取设备月综合利用率
  498. */
  499. public function getEmUse(){
  500. if (Request::instance()->isGet()){
  501. $this->error('非法请求');
  502. }
  503. $params = input('emid');
  504. if (empty($params)){
  505. $this->error('参数错误');
  506. }
  507. $emid = $params.'#';
  508. $year = date('Y');
  509. $res = Db::connect('db2')
  510. ->query("select 平均车速 as speed from 设备_基本资料 where 设备编号 = '{$emid}'");
  511. $number = $res[0]['speed'];
  512. $cl_res = Db::connect('db2')
  513. ->query("select
  514. month(开工时间) as worktime,sum(sczl_cl) as output,sum(sczl_设备运行工时-sczl_保养工时-sczl_打样总工时)*'{$number}' as time
  515. from 设备_产量计酬 where year(开工时间)='{$year}' and sczl_jtbh='{$emid}' group by worktime");
  516. foreach ($cl_res as $key=>$value){
  517. $cl_res[$key]['rate'] = round($value['output']/$value['time'],4) *100 .'%';
  518. unset($cl_res[$key]['output']);
  519. unset($cl_res[$key]['time']);
  520. }
  521. $number = count($cl_res);
  522. $displarityNumber = 12 - $number;
  523. if ($displarityNumber > 0){
  524. for ($i=$number;$i<12;$i++){
  525. $arr = array();
  526. $arr['worktime'] = $i+1;
  527. $arr['rate'] = '0%';
  528. array_push($cl_res,$arr);
  529. }
  530. }
  531. $this->success('请求成功',$cl_res);
  532. }
  533. //时间计算(距离现在多长时间)
  534. public function format_date($time){
  535. $t=time()-$time;
  536. $f=array(
  537. '31536000'=>'年',
  538. '2592000'=>'个月',
  539. '604800'=>'星期',
  540. '86400'=>'天',
  541. '3600'=>'小时',
  542. '60'=>'分钟',
  543. '1'=>'秒'
  544. );
  545. foreach ($f as $k=>$v) {
  546. if (0 !=$c=floor($t/(int)$k)) {
  547. return $c.$v.'前';
  548. }
  549. }
  550. }
  551. }