Facility.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 设备运行跟踪
  7. */
  8. class Facility extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 左侧菜单栏
  14. * @ApiMethod (GET)
  15. * @return void
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public function getTab()
  21. {
  22. if ($this->request->isGet() === false){
  23. $this->error('请求错误');
  24. }
  25. $data = [];
  26. $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
  27. if (empty($department)){
  28. $this->error('未获取到机台数据');
  29. }
  30. foreach ($department as $value){
  31. if (rtrim($value) !== '研发中心'){
  32. $machine = Db::table('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  33. foreach ($machine as $kk=>$vv){
  34. if ($vv['设备编号'] !== 'ZH01#'){
  35. $date = Db::table('设备_产量计酬')->where('sczl_jtbh',$vv['设备编号'])->distinct(true)->cache(60)->order('UniqId desc')->limit(40)->column('sczl_rq');
  36. $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
  37. }
  38. }
  39. }
  40. }
  41. $this->success('成功',$data);
  42. }
  43. /**
  44. * 机台每日产量
  45. * @ApiMethod (GET)
  46. * @param string $machine 机台编号
  47. * @param string $date 日期
  48. * @return void
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public function chanLiang()
  54. {
  55. if ($this->request->isGet() === false){
  56. $this->error('请求错误');
  57. }
  58. $machine = input('machine').'#';
  59. $date = input('date');
  60. $where = [
  61. 'sczl_jtbh' => $machine,
  62. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  63. ];
  64. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  65. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  66. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  67. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  68. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  69. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  70. sczl_rate8,sczl_rate9,sczl_rate10';
  71. //机台信息
  72. $machineDetail = Db::table('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  73. //工单编号
  74. $Gd_gdbh = Db::table('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
  75. //产品名称
  76. $productName = Db::table('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->column('Gd_cpmc','Gd_gdbh');
  77. //组员信息
  78. $list = Db::table('设备_产量计酬')->where($where)->field($field)->select();
  79. $totalA = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
  80. $totalB = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
  81. if (empty($list)){
  82. $this->error('未找到机台数据');
  83. }
  84. foreach ($list as $key=>$value){
  85. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName[$value['工单编号']];
  86. if ($value['yjno']<10){
  87. $list[$key]['yjno'] = '0'.$value['yjno'];
  88. }
  89. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  90. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  91. $list[$key]['千件工价'] = $machineDetail['千件工价'];
  92. $list[$key]['日定额'] = $machineDetail['日定额'];
  93. for ($i=1;$i<11;$i++){
  94. if (isset($value['sczl_bh'.$i])){
  95. $name = Db::table('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  96. if (isset($name['name'])){
  97. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  98. }
  99. }
  100. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  101. }
  102. unset($list[$key]['工序编号'],$list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['num'],$list[$key]['sj1'],$list[$key]['sj2'],$list[$key]['bzdh']);
  103. }
  104. $list['totalA'] = $totalA[0]['产量'];
  105. $list['totalB'] = $totalB[0]['产量'];
  106. $this->success('成功',$list);
  107. }
  108. /**
  109. * 当日制程检验记录
  110. * @ApiMethod (GET)
  111. * @param string $machine 机台编号
  112. * @param string $date 日期
  113. * @return void
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. * @throws \think\exception\DbException
  117. */
  118. public function Inspect()
  119. {
  120. if ($this->request->isGet() === false){
  121. $this->error('请求错误');
  122. }
  123. $machine = input('machine');
  124. $date = input('date');
  125. if (empty($machine) || empty($date)){
  126. $this->error('参数错误');
  127. }
  128. $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
  129. $startId = $last_id['UniqId']-1000000;
  130. $where = [
  131. '设备编号' => $machine,
  132. '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
  133. '类别' => ['in',['IPQC检验','机台检验']],
  134. 'UniqId' => ['>',$startId],
  135. ];
  136. $begin = Db::table('制程检验_记录')->where($where)->field('UniqId')->find();
  137. $end = Db::table('制程检验_记录')->where($where)->order('UniqId desc')->field('UniqId')->find();
  138. $where['UniqId'] = ['between',[$begin['UniqId'],$end['UniqId']+1]];
  139. //检验项目筛选
  140. $itemA = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','A班')->column('rtrim(检验项目)');
  141. $itemB = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','B班')->column('rtrim(检验项目)');
  142. //检验时间
  143. $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  144. foreach ($InspectionTime as $k=>$v){
  145. $InspectionTime[$k] = date('H:i',strtotime($v));
  146. }
  147. //检测记录详情
  148. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  149. $nameDetailA = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','A班')->find();
  150. $nameDetailB = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','B班')->find();
  151. $list = $data1 = $data2 = [];
  152. //A班检测数据
  153. foreach ($itemA as $key=>$value){
  154. $SubmissionTime = Db::table('制程检验_记录')->where($where)
  155. ->where('班组编号','A班')
  156. ->where('检验项目',$value)
  157. ->where('检验结果','合格')
  158. ->field('rtrim(提交时间) as 提交时间')
  159. ->select();
  160. $time = [];
  161. foreach ($SubmissionTime as $k=>$v){
  162. $time[$k] = date('H:i',strtotime($v['提交时间']));
  163. }
  164. $data1[$key] = [
  165. '工单编号' => $nameDetailA['工单编号'],
  166. '印件号' => $nameDetailA['印件号'],
  167. '工序名称' => $nameDetailA['工序名称'],
  168. '检验项目' => $value,
  169. 'inspectresult' => implode(',',$time),
  170. ];
  171. }
  172. //B班数据详情
  173. foreach ($itemB as $key=>$value){
  174. $SubmissionTime = Db::table('制程检验_记录')->where($where)
  175. ->where('班组编号','B班')
  176. ->where('检验项目',$value)
  177. ->where('检验结果','合格')
  178. ->field('rtrim(提交时间) as 提交时间')
  179. ->select();
  180. $time = [];
  181. foreach ($SubmissionTime as $k=>$v){
  182. $time[$k] = date('H:i',strtotime($v['提交时间']));
  183. }
  184. $data2[$key] = [
  185. '工单编号' => $nameDetailB['工单编号'],
  186. '印件号' => $nameDetailB['印件号'],
  187. '工序名称' => $nameDetailB['工序名称'],
  188. '检验项目' => $value,
  189. 'inspectresult' => implode(',',$time),
  190. ];
  191. }
  192. $list = array_merge($data2,$data1);
  193. $list['inspectiontime'] = $InspectionTime;
  194. $this->success('成功',$list);
  195. }
  196. /**
  197. * 设备生产中工单信息
  198. * @ApiMethod (GET)
  199. * @param string $machine 机台编号
  200. * @return void
  201. * @throws \think\Exception
  202. * @throws \think\db\exception\DataNotFoundException
  203. * @throws \think\db\exception\ModelNotFoundException
  204. * @throws \think\exception\DbException
  205. */
  206. public function Production()
  207. {
  208. if ($this->request->isGet() === false){
  209. $this->error('请求错误');
  210. }
  211. $machine = input('machine');
  212. if (empty($machine)){
  213. $this->error('参数错误');
  214. }
  215. $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
  216. $startUniqid = $lastUniqid['UniqId']-10000;
  217. $workOrder = Db::table('设备_产量计酬')->where('sczl_jtbh',$machine)->where('UniqId','>',$startUniqid)->field('sczl_gdbh')->order('UniqId desc')->find();
  218. if (empty($workOrder)){
  219. $this->error('未找到正在生产工单');
  220. }
  221. $where = [
  222. 'Gy0_sbbh' => $machine,
  223. 'Gy0_gdbh' => $workOrder['sczl_gdbh']
  224. ];
  225. $list = Db::table('工单_工艺资料')->where($where)->find();
  226. if (empty($list)){
  227. $this->error('未找到正在生产工单');
  228. }
  229. $facilityWhere = [
  230. 'sczl_jtbh'=>$machine,
  231. 'sczl_gdbh'=>$list['Gy0_gdbh']
  232. ];
  233. $facilityField = 'sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10';
  234. $Ctaff = Db::table('设备_产量计酬')->where($facilityWhere)->where('UniqId','>',$startUniqid)->field($facilityField)->order('UniqId desc')->find();
  235. $data = [];
  236. foreach ($Ctaff as $key=>$value){
  237. if (!empty($value)){
  238. $staffName = Db::table('人事_基本资料')->where('员工编号',$value)->field('员工姓名,员工编号')->find();
  239. $data[$key] = [
  240. '员工编号' => rtrim($staffName['员工编号']),
  241. '员工姓名' => rtrim($staffName['员工姓名']),
  242. ];
  243. }
  244. }
  245. if ($list['Gy0_yjno']<10){
  246. $list['Gy0_yjno'] = '0'.$list['Gy0_yjno'];
  247. }
  248. if ($list['Gy0_gxh']<10){
  249. $list['Gy0_gxh'] = '0'.$list['Gy0_gxh'];
  250. }
  251. $data['工单编号'] = rtrim($list['Gy0_gdbh']);
  252. $data['印件编号'] = rtrim($list['Gy0_yjno']);
  253. $data['工序名称'] = rtrim($list['Gy0_gxh']).'-'.rtrim($list['Gy0_gxmc']).'【'.rtrim($list['Add_gxmc']).'】';
  254. $data['产品名称'] = Db::table('工单_基本资料')->where('Gd_gdbh',rtrim($list['Gy0_gdbh']))->field('rtrim(Gd_cpmc) as 产品名称')->find()['产品名称'];
  255. $this->success('成功',$data);
  256. }
  257. /**
  258. * 设备工作清单
  259. * @ApiMethod (GET)
  260. * @param string $machine 机台编号
  261. * @return void
  262. * @throws \think\db\exception\DataNotFoundException
  263. * @throws \think\db\exception\ModelNotFoundException
  264. * @throws \think\exception\DbException
  265. */
  266. public function EquipmentWorklist()
  267. {
  268. if ($this->request->isGet() === false){
  269. $this->error('请求错误');
  270. }
  271. $machine = input('machine');
  272. if (empty($machine)){
  273. $this->error('参数错误');
  274. }
  275. $lastTechonUniqId = Db::table('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  276. $startTechonUniqId = $lastTechonUniqId['UniqId']-10000;
  277. $lastYieldUniqId = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
  278. $startYieldUniqId = $lastYieldUniqId['UniqId']-100000;
  279. $workOrder = Db::table('设备_产量计酬')->where('sczl_jtbh',$machine)->field('sczl_gdbh')->where('UniqId','>',$startYieldUniqId)->order('UniqId desc')->find();
  280. $startTime = Db::table('工单_工艺资料')->where('Gy0_gdbh',$workOrder['sczl_gdbh'])->where('Gy0_sbbh',$machine)->where('UniqId','>',$startTechonUniqId)->field('Gy0_sj1')->order('UniqId desc')->find();
  281. $where = [
  282. 'UniqId' => ['>',$startTechonUniqId],
  283. 'Gy0_sbbh' => $machine,
  284. 'Gy0_sj1' => ['>= time',$startTime['Gy0_sj1']],
  285. ];
  286. $field = 'rtrim(Gy0_gdbh) as gdbh,rtrim(质量要求) as 质量信息,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,
  287. rtrim(Add_gxmc) as add_gxmc,rtrim(Gy0_辅助工时) as 装版时数,rtrim(Gy0_小时产能) as 工序产能,rtrim(Gy0_生产工时) as 计划工时,
  288. rtrim(Gy0_sj1) as sj1,rtrim(Gy0_sj2) as sj2,rtrim(工序备注) as 排产备注';
  289. $orderList = Db::table('工单_工艺资料')
  290. ->where($where)
  291. ->where('Gy0_sj1','<','2099-01-01 00:00:00')
  292. ->field($field)
  293. ->order('UniqId desc')
  294. ->select();
  295. foreach ($orderList as $key=>$value){
  296. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  297. $name = Db::table('工单_印件资料')->where(['Yj_Gdbh'=>$value['gdbh'],'yj_Yjno'=>$value['yjno']])->field('yj_yjmc')->find();
  298. if ($value['yjno']<10){
  299. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  300. }
  301. if ($value['gxh']<10){
  302. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  303. }
  304. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.rtrim($name['yj_yjmc']);
  305. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  306. $scheduled = Db::table('工单_基本资料')->where('Gd_gdbh',$value['gdbh'])->field('rtrim(计划投料) as 计划产量')->find();
  307. $finished = Db::table('设备_产量计酬')
  308. ->where('sczl_gdbh',$value['gdbh'])
  309. ->where('sczl_jtbh',$machine)
  310. ->where('UniqId','>',$startYieldUniqId)
  311. ->order('UniqId desc')
  312. ->field('SUM(sczl_cl) as cl')
  313. ->select();
  314. $orderList[$key]['计划产量/已完成'] = $scheduled['计划产量'].'/'.$finished[0]['cl']=null?'':(int)$finished[0]['cl'];
  315. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  316. $orderList[$key]['产品名称'] = rtrim($name['yj_yjmc']);
  317. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['sj1'],$orderList[$key]['sj2']);
  318. }
  319. $this->success('成功',$orderList);
  320. }
  321. /**
  322. * 工序、印件、完成数量
  323. * @ApiMethod (GET)
  324. * @param string $workOrder 工单编号
  325. * @return void
  326. * @throws \think\Exception
  327. * @throws \think\db\exception\DataNotFoundException
  328. * @throws \think\db\exception\ModelNotFoundException
  329. * @throws \think\exception\DbException
  330. */
  331. public function Procedure()
  332. {
  333. if ($this->request->isGet() === false){
  334. $this->error('请求错误');
  335. }
  336. $workOrder = input('Gd_gdbh');
  337. if (empty($workOrder)){
  338. $this->error('参数错误');
  339. }
  340. $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
  341. $startUniqid = $lastUniqid['UniqId']-100000;
  342. //右边工艺及完成数量
  343. $Process = Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)->where('UniqId','>',$startUniqid)->distinct(true)->order('sczl_gxh')->column('sczl_gxh');
  344. $data = [];
  345. foreach ($Process as $k=>$v){
  346. $res= Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  347. ->where('UniqId','>',$startUniqid)
  348. ->where('sczl_gxh',$v)
  349. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  350. ->find();
  351. if ($res['sczl_yjno']<10){
  352. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  353. }
  354. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  355. $processList['completed'] = Db::table('设备_产量计酬')->where('sczl_gdbh',$workOrder)->where('UniqId','>',$startUniqid)->where('sczl_gxh',$v)->count();
  356. array_push($data,$processList);
  357. }
  358. $this->success('成功',$data);
  359. }
  360. /**
  361. * 班组人员及分配比例
  362. * @ApiMethod (GET)
  363. * @param string $machine 机台编号
  364. * @return void
  365. * @throws \think\db\exception\DataNotFoundException
  366. * @throws \think\db\exception\ModelNotFoundException
  367. * @throws \think\exception\DbException
  368. */
  369. public function Team()
  370. {
  371. if ($this->request->isGet() === false){
  372. $this->error('请求错误');
  373. }
  374. $machine = input('machine');
  375. if (empty($machine)){
  376. $this->error('参数错误');
  377. }
  378. $where = [
  379. 'sczl_jtbh' => $machine,
  380. ];
  381. $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  382. rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  383. rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
  384. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  385. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  386. $team = Db::table('设备_产量计酬')
  387. ->where('sczl_jtbh',$machine)
  388. ->field($field)
  389. ->order('UniqId desc')
  390. ->find();
  391. $list = Db::table('设备_班组资料')->where($where)->field($field)->select();
  392. $data = [];
  393. foreach ($list as $k=>$v){
  394. if ($team == $v){
  395. $data[$k]['status'] = 1;
  396. }else{
  397. $data[$k]['status'] = 0;
  398. }
  399. $data[$k]['ID'] = $v['ID'];
  400. $data[$k]['班组号'] = $v['班组号'];
  401. for ($i=1;$i<11;$i++){
  402. if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
  403. $name = Db::table('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  404. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  405. }
  406. }
  407. }
  408. $this->success('成功',$data);
  409. }
  410. /**
  411. * 当班产量明细
  412. * @ApiMethod (GET)
  413. * @param string $machine 机台编号
  414. * @param string $workOrder 工单编号
  415. * @param string $team 班次
  416. * @return void
  417. * @throws \think\db\exception\DataNotFoundException
  418. * @throws \think\db\exception\ModelNotFoundException
  419. * @throws \think\exception\DbException
  420. */
  421. public function OutputDetail()
  422. {
  423. if ($this->request->isGet() === false){
  424. $this->error('请求错误');
  425. }
  426. $machine = input('machine');
  427. $workOrder = input('Gd_gdbh');
  428. $team = input('team');
  429. if (empty($machine) || empty($workOrder) || empty($team)){
  430. $this->error('参数错误');
  431. }
  432. $lastUniqid = Db::table('设备_产量计酬')->field('UniqId')->order('UniqId desc')->find();
  433. $startUniqid = $lastUniqid['UniqId']-100000;
  434. $name = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
  435. $where = [
  436. 'UniqId' => ['>',$startUniqid],
  437. 'sczl_gdbh' => $workOrder,
  438. 'sczl_jtbh' => $machine,
  439. 'sczl_cl' => ['<>',0.0],
  440. 'sczl_bzdh' => $team,
  441. ];
  442. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
  443. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  444. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  445. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  446. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
  447. $list = Db::table('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  448. if (empty($list)){
  449. $this->error('未找到生产记录');
  450. }
  451. foreach ($list as $k=>$v){
  452. if ($v['yjno']<10){
  453. $list[$k]['yjno'] = '0'.$v['yjno'];
  454. }
  455. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  456. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  457. $list[$k]['产品名称'] = $name['productName'];
  458. unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
  459. }
  460. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  461. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  462. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  463. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  464. $total = Db::table('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  465. $total[0]['版数'] = count($list);
  466. $list['total'] = $total[0];
  467. $this->success('成功',$list);
  468. }
  469. /**
  470. * 检验记录
  471. * @ApiMethod (GET)
  472. * @param string $machine 机台编号
  473. * @param string $workOrder 工单编号
  474. * @param string $team 班次
  475. * @return void
  476. * @throws \think\db\exception\DataNotFoundException
  477. * @throws \think\db\exception\ModelNotFoundException
  478. * @throws \think\exception\DbException
  479. */
  480. public function InspectionRecord()
  481. {
  482. if ($this->request->isGet() === false){
  483. $this->error('请求失败');
  484. }
  485. $machine = input('machine');
  486. $workOrder = input('Gd_gdbh');
  487. $team = input('team');
  488. if (empty($machine) || empty($workOrder) || empty($team)){
  489. $this->error('参数错误');
  490. }
  491. $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
  492. $startId = $last_id['UniqId']-100000;
  493. $where = [
  494. '设备编号' => $machine,
  495. '工单编号' => $workOrder,
  496. '班组编号' => $team,
  497. '类别' => ['in',['IPQC检验','机台检验']],
  498. 'UniqId' => ['>',$startId],
  499. ];
  500. //检验项目筛选
  501. $item = Db::table('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  502. //检验时间
  503. $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  504. foreach ($InspectionTime as $k=>$v){
  505. $InspectionTime[$k] = date('H:i',strtotime($v));
  506. }
  507. //检测记录详情
  508. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  509. $nameDetail = Db::table('制程检验_记录')->where($where)->field($field)->find();
  510. $data = [];
  511. //检测数据
  512. foreach ($item as $key=>$value){
  513. $SubmissionTime = Db::table('制程检验_记录')->where($where)
  514. ->where('检验项目',$value)
  515. ->where('检验结果','合格')
  516. ->field('rtrim(提交时间) as 提交时间')
  517. ->select();
  518. $time = [];
  519. foreach ($SubmissionTime as $k=>$v){
  520. $time[$k] = date('H:i',strtotime($v['提交时间']));
  521. }
  522. $data[$key] = [
  523. '工单编号' => $nameDetail['工单编号'],
  524. '印件号' => $nameDetail['印件号'],
  525. '工序名称' => $nameDetail['工序名称'],
  526. '检验项目' => $value,
  527. 'inspectresult' => implode(',',$time),
  528. ];
  529. }
  530. $data['inspectiontime'] = $InspectionTime;
  531. $this->success('成功',$data);
  532. }
  533. //班组维护
  534. public function TeamMaintenance()
  535. {
  536. if ($this->request->isPost() === false){
  537. $this->error('请求错误');
  538. }
  539. $data = $this->request->param();
  540. if (empty($data)){
  541. $this->error('参数错误');
  542. }
  543. $field = 'rtrim(sczl_bzdh) as sczl_bzdh,rtrim(sczl_bh1) as sczl_bh1,rtrim(sczl_bh2) as sczl_bh2,rtrim(sczl_bh3) as sczl_bh3,rtrim(sczl_bh4) as sczl_bh4,
  544. rtrim(sczl_bh5) as sczl_bh5,rtrim(sczl_bh6) as sczl_bh6,rtrim(sczl_bh7) as sczl_bh7,rtrim(sczl_bh8) as sczl_bh8,rtrim(sczl_bh9) as sczl_bh9,
  545. rtrim(sczl_bh10) as sczl_bh10,rtrim(sczl_rate1) as sczl_rate1,rtrim(sczl_rate2) as sczl_rate2,rtrim(sczl_rate3) as sczl_rate3,rtrim(sczl_rate4) as sczl_rate4,
  546. rtrim(sczl_rate5) as sczl_rate5,rtrim(sczl_rate6) as sczl_rate6,rtrim(sczl_rate7) as sczl_rate7,rtrim(sczl_rate8) as sczl_rate8,
  547. rtrim(sczl_rate9) as sczl_rate9,rtrim(sczl_rate10) as sczl_rate10';
  548. $TeamList = Db::table('设备_班组资料')->where('UniqId',$data['ID'])->field($field)->find();
  549. }
  550. /**
  551. * 机台编号列表
  552. * @ApiMethod (GET)
  553. * @return void
  554. */
  555. public function MachineList()
  556. {
  557. if ($this->request->isGet() === false){
  558. $this->error('请求错误');
  559. }
  560. $list = Db::table('设备_基本资料')->column('设备编号');
  561. if (empty($list)){
  562. $this->error('未找到机台编号');
  563. }
  564. $this->success('成功',$list);
  565. }
  566. /**
  567. * 删除班组信息
  568. * @ApiMethod (GET)
  569. * @param void
  570. * @return void
  571. * @throws \think\Exception
  572. * @throws \think\exception\PDOException
  573. */
  574. public function teamDel()
  575. {
  576. if ($this->request->isPost() === false){
  577. $this->error('请求错误');
  578. }
  579. $param = $this->request->param();
  580. if (empty($param)){
  581. $this->error('参数错误');
  582. }
  583. $res = Db::table('设备_班组资料')
  584. ->where('UniqId',$param['UniqId'])
  585. ->delete();
  586. if ($res !== false){
  587. $this->success('成功');
  588. }else{
  589. $this->error('失败');
  590. }
  591. }
  592. //制程检验记录->指标检验
  593. public function ProcessInspectionRecords()
  594. {
  595. if ($this->request->isGet() === false){
  596. $this->error('请求错误');
  597. }
  598. $param = $this->request->param();
  599. if (empty($param)){
  600. $this->error('参数错误');
  601. }
  602. // $filed = ''
  603. }
  604. /**
  605. * 管理人员现场巡检记录->展示
  606. * @ApiMethod (GET)
  607. * @param void
  608. * @return void
  609. * @throws \think\db\exception\DataNotFoundException
  610. * @throws \think\db\exception\ModelNotFoundException
  611. * @throws \think\exception\DbException
  612. */
  613. public function FieldInspectionRecord()
  614. {
  615. if ($this->request->isGet() === false){
  616. $this->error('请求错误');
  617. }
  618. $param = $this->request->param();
  619. if (empty($param)){
  620. $this->error('参数错误');
  621. }
  622. $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
  623. $startId = $last_id['UniqId']-100000;
  624. $date = date('Y-m-d H:i:s',time());
  625. $startTime = date('Y-m-d 08:30:00',time());
  626. if ($date<$startTime){
  627. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  628. }
  629. $where = [
  630. '工单编号' => $param['workOrder'],
  631. '开工时间' => $startTime,
  632. '类别' => '现场巡查记录',
  633. '班组编号' => $param['team']
  634. ];
  635. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  636. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  637. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  638. $list = Db::table('制程检验_记录')->where($where)->where('UniqId','>',$startId)->field($filed)->select();
  639. if (empty($list)){
  640. $this->error('未找到该工单当前班次巡检记录');
  641. }
  642. foreach ($list as $key=>$value){
  643. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  644. $list[$key]['归属时段'] = $value['开工时间'];
  645. $list[$key]['分钟差数'] = $number;
  646. if ($number != 0){
  647. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  648. }
  649. }
  650. $this->success('成功',$list);
  651. }
  652. /**
  653. * 管理人员现场巡检记录->添加
  654. * @ApiMethod (POST)
  655. * @param void
  656. * @return void
  657. */
  658. public function FieldInspectionRecordAdd()
  659. {
  660. if ($this->request->isPost() === false){
  661. $this->error('请求错误');
  662. }
  663. $param = $this->request->param();
  664. if (empty($param)){
  665. $this->error('参数错误');
  666. }
  667. if ($param['processCode']<10){
  668. $param['processCode'] = '0'.$param['processCode'];
  669. }
  670. $date = date('Y-m-d H:i:s',time());
  671. $startTime = date('Y-m-d 08:30:00',time());
  672. if ($date<$startTime){
  673. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  674. }
  675. $data = [
  676. '类别' => $param['category'],
  677. '工单编号' => $param['workOrder'],
  678. '印件号' => $param['printCode'],
  679. '工序名称' => $param['processCode'].'-'.$param['process'],
  680. '流程单号' => $param['flowCode'],
  681. '设备编号' => $param['machine'],
  682. '班组编号' => $param['team'],
  683. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  684. '相关标准' => '',
  685. '量测仪器' => '',
  686. '检验结果' => '',
  687. '检验备注' => $param['remark'],
  688. '提交时间' => date('Y-m-d H:i:s',time()),
  689. '开工时间' => $startTime,
  690. 'sys_id' => '',
  691. 'sys_rq' => date('Y-m-d H:i:s',time()),
  692. 'mod_rq' => '',
  693. 'UniqId' => Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  694. ];
  695. $sql = Db::table('制程检验_记录')->fetchSql(true)->insert($data);
  696. $res = Db::query($sql);
  697. if ($res !== false){
  698. $this->success('成功');
  699. }else{
  700. $this->error('失败');
  701. }
  702. }
  703. /**
  704. * 设备点检->左侧菜单栏
  705. * @ApiMethod (GET)
  706. * @param void
  707. * @return void
  708. */
  709. public function SpotCheckItem()
  710. {
  711. if ($this->request->isGet() === false){
  712. $this->error('请求错误');
  713. }
  714. $param = $this->request->param();
  715. if (empty($param)){
  716. $this->error('参数错误');
  717. }
  718. $list = Db::table('设备_点检项目')
  719. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  720. ->distinct(true)
  721. ->column('部件名称','部件编号');
  722. if (empty($list)){
  723. $this->error('未找到检验项目');
  724. }
  725. $this->success('成功',$list);
  726. }
  727. /**
  728. * 设备点检->检测项目
  729. * @ApiMethod (GET)
  730. * @param void
  731. * @return void
  732. * @throws \think\db\exception\DataNotFoundException
  733. * @throws \think\db\exception\ModelNotFoundException
  734. * @throws \think\exception\DbException
  735. */
  736. public function InspectionItem()
  737. {
  738. if ($this->request->isGet() === false){
  739. $this->error('请求错误');
  740. }
  741. $param = $this->request->param();
  742. if (empty($param)){
  743. $this->error('参数错误');
  744. }
  745. $list = Db::table('设备_点检项目')
  746. ->where('部件名称',$param['unitName'])
  747. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  748. ->select();
  749. if (empty($list)){
  750. $this->error('未找到检测项目');
  751. }
  752. $this->success('成功',$list);
  753. }
  754. //设备点检->检测记录添加
  755. public function InspectionItemAdd()
  756. {
  757. if ($this->request->isPost() === false){
  758. $this->error('请求错误');
  759. }
  760. $param = $this->request->param();
  761. if (empty($param)){
  762. $this->error('参数错误');
  763. }
  764. }
  765. }