Facility.php 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * 设备运行跟踪
  8. */
  9. class Facility extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 左侧菜单栏
  15. * @ApiMethod (GET)
  16. * @return void
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function getTab()
  22. {
  23. if ($this->request->isGet() === false){
  24. $this->error('请求错误');
  25. }
  26. $param = $this->request->param();
  27. if (isset($param['sort'])){
  28. $where['使用部门'] = '智能车间';
  29. }else{
  30. $where['使用部门'] = ['<>','智能车间'];
  31. }
  32. $data = [];
  33. $date = date('Y-m-d 00:00:00',time()-3888000);
  34. $department = \db('设备_基本资料')
  35. ->distinct(true)
  36. ->where('使用部门','<>','研发中心')
  37. ->where('设备编组','<>','')
  38. ->where($where)
  39. ->order('设备编组,设备编号')
  40. ->column('rtrim(使用部门) as 使用部门');
  41. if (empty($department)){
  42. $this->success('为获取到机台数据');
  43. }
  44. $list = \db('设备_产量计酬')
  45. ->field([
  46. 'DISTINCT(sczl_rq)' => '时间',
  47. 'rtrim(sczl_jtbh)' => '机台编号'
  48. ])
  49. ->where('sczl_rq','>',$date)
  50. ->order('sczl_rq desc')
  51. ->select();
  52. if (empty($list)){
  53. $this->success('未找到机台生产记录');
  54. }
  55. foreach ($department as $value){
  56. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  57. foreach ($machine as $k=>$v){
  58. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  59. foreach ($list as $kk=>$vv){
  60. if ($v['设备编号'] === $vv['机台编号']){
  61. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  62. }
  63. }
  64. }
  65. }
  66. $this->success('成功',$data);
  67. }
  68. /**
  69. * 机台每日产量
  70. * @ApiMethod (GET)
  71. * @param string $machine 机台编号
  72. * @param string $date 日期
  73. * @return void
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. */
  78. public function chanLiang()
  79. {
  80. if ($this->request->isGet() === false){
  81. $this->error('请求错误');
  82. }
  83. $machine = input('machine');
  84. $date = input('date');
  85. $where = [
  86. 'sczl_jtbh' => $machine,
  87. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  88. ];
  89. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  90. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,IF(sczl_zcfp = 0, "",sczl_zcfp) as 制程废品,IF(sczl_zccp = 0, "",sczl_zccp) as 制程次品,IF(sczl_前工序废 = 0, "",sczl_前工序废) as 前工序废,IF(sczl_来料少数 = 0, "",sczl_来料少数) as 来料异常,
  91. IF(sczl_装版工时 = 0, "",sczl_装版工时) as 装版工时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_打样工时 = 0, "",sczl_打样工时) as 打样工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  92. IF(码开始行 = 0, "",码开始行) as 码开始行,IF(码结束行 = 0, "",码结束行) as 码结束行,IF(码包 = 0, "",码包) as 码包,IF(主电表 = 0, "",主电表) as 主电表,IF(辅电表 = 0, "",辅电表) as 辅电表,IF(sczl_ms = 0, "",sczl_ms) as 色度数,
  93. rtrim(sys_id) as 用户,rtrim(sys_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  94. 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,
  95. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号';
  96. //机台信息
  97. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  98. //组员信息
  99. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  100. $totalA = \db('设备_产量计酬')
  101. ->where($where)
  102. ->where('sczl_bzdh','like','A%')
  103. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  104. ->select();
  105. $totalB = \db('设备_产量计酬')
  106. ->where($where)
  107. ->where('sczl_bzdh','like','B%')
  108. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  109. ->select();
  110. if (empty($list)){
  111. $this->success('',[]);
  112. }
  113. foreach ($list as $key=>$value){
  114. //产品名称
  115. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  116. if (!empty($productName)){
  117. if (!empty($productName['成品名称'])){
  118. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  119. $list[$key]['cpmc'] = $productName['成品名称'];
  120. }else{
  121. $list[$key]['产品名称'] = $value['工单编号'];
  122. $list[$key]['cpmc'] = '';
  123. }
  124. }else{
  125. $list[$key]['产品名称'] = $value['工单编号'];
  126. $list[$key]['cpmc'] = '';
  127. }
  128. $process = \db('工单_工艺资料')
  129. ->where('Gy0_gdbh',$value['工单编号'])
  130. ->where('Gy0_yjno',$value['yjno'])
  131. ->where('Gy0_gxh',$value['gxh'])
  132. ->field('rtrim(工价系数) as 工价系数,rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距')
  133. ->find();
  134. if (!empty($process)){
  135. if ($value['难度系数'] == 0){
  136. $list[$key]['难度系数'] = $process['工价系数'];
  137. }else{
  138. $list[$key]['难度系数'] = $process['工价系数'].'x'.$value['难度系数'];
  139. }
  140. $list[$key]['印刷方式'] = $process['印刷方式'].' '.$process['版距'];
  141. }else{
  142. $list[$key]['难度系数'] = '';
  143. $list[$key]['印刷方式'] = '';
  144. }
  145. if ($value['yjno']<10){
  146. $list[$key]['yjno'] = '0'.$value['yjno'];
  147. }
  148. if (empty($value['定额代号'])){
  149. $list[$key]['千件工价'] = '';
  150. $list[$key]['日定额'] = '';
  151. $list[$key]['补产标准'] = '';
  152. }else{
  153. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  154. $list[$key]['千件工价'] = $row['千件工价'];
  155. $list[$key]['日定额'] = $row['日定额'];
  156. $list[$key]['补产标准'] = $row['补产标准'];
  157. }
  158. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  159. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  160. for ($i=1;$i<11;$i++){
  161. if (isset($value['sczl_bh'.$i])){
  162. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  163. if (isset($name['name'])){
  164. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  165. }
  166. }
  167. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  168. }
  169. }
  170. $list['totalA'] = $totalA[0]['产量'];
  171. $list['totalB'] = $totalB[0]['产量'];
  172. $list['制程废品A'] = $totalA[0]['制程废品'];
  173. $list['制程废品B'] = $totalB[0]['制程废品'];
  174. $list['制程次品A'] = $totalA[0]['制程次品'];
  175. $list['制程次品B'] = $totalB[0]['制程次品'];
  176. $list['来料异常A'] = $totalA[0]['来料异常'];
  177. $list['来料异常B'] = $totalB[0]['来料异常'];
  178. $list['装版工时A'] = $totalA[0]['装版工时'];
  179. $list['装版工时B'] = $totalB[0]['装版工时'];
  180. $list['保养工时A'] = $totalA[0]['保养工时'];
  181. $list['保养工时B'] = $totalB[0]['保养工时'];
  182. $list['打样工时A'] = $totalA[0]['打样工时'];
  183. $list['打样工时B'] = $totalB[0]['打样工时'];
  184. $list['异常工时A'] = $totalA[0]['异常工时'];
  185. $list['异常工时B'] = $totalB[0]['异常工时'];
  186. $list['异常补时工时A'] = $totalA[0]['异常补时工时'];
  187. $list['异常补时工时B'] = $totalB[0]['异常补时工时'];
  188. $list['通电工时A'] = $totalA[0]['通电工时'];
  189. $list['通电工时B'] = $totalB[0]['通电工时'];
  190. $list['前工序废A'] = $totalA[0]['前工序废'];
  191. $list['前工序废B'] = $totalB[0]['前工序废'];
  192. $this->success('成功',$list);
  193. }
  194. /**
  195. * 当日制程检验记录
  196. * @ApiMethod (GET)
  197. * @param string $machine 机台编号
  198. * @param string $date 日期
  199. * @return void
  200. * @throws \think\db\exception\DataNotFoundException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. * @throws \think\exception\DbException
  203. */
  204. public function Inspect()
  205. {
  206. if ($this->request->isGet() === false){
  207. $this->error('请求错误');
  208. }
  209. $machine = input('machine');
  210. // $date = input('date');
  211. // 获取当前时间
  212. $current_time = time();
  213. // 设置时间范围
  214. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  215. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  216. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  217. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  218. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  219. // 判断当前时间属于哪个时间范围
  220. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  221. $startTime = date('Y-m-d') . ' 08:30:00';
  222. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  223. $startTime = date('Y-m-d') . ' 20:30:00';
  224. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  225. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  226. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  227. $startTime = date('Y-m-d') . ' 20:30:00';
  228. }
  229. if (empty($machine)){
  230. $this->error('参数错误');
  231. }
  232. $where = [
  233. '设备编号' => $machine,
  234. '开工时间' => $startTime,
  235. '类别' => ['in',['IPQC检验','机台检验']],
  236. ];
  237. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
  238. $list = \db('制程检验_记录')
  239. ->where($where)
  240. ->field($field)
  241. ->select();
  242. if (empty($list)){
  243. $this->success('未找到检验记录');
  244. }
  245. $data = [];
  246. foreach ($list as $key=>$value)
  247. {
  248. $data['item'][$key] = $value['检验项目'];
  249. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  250. $data['工单编号'][$key] = $value['工单编号'];
  251. }
  252. $data['item'] = array_unique($data['item']);
  253. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  254. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  255. foreach ($data['工单编号'] as $key => $value){
  256. foreach ($data['item'] as $k=>$v){
  257. $time = '';
  258. foreach ($list as $kk=>$vv){
  259. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  260. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  261. $data['row'][$key][$k] = [
  262. '工单编号' => $value,
  263. '印件号' => $vv['印件号'],
  264. '工序名称' => $vv['工序名称'],
  265. '检验项目' => $v,
  266. 'time' => substr($time,0,-1),
  267. ];
  268. }
  269. }
  270. }
  271. $data['row'][$key] = array_values($data['row'][$key]);
  272. }
  273. unset($data['item'],$data['工单编号']);
  274. $this->success('成功',$data);
  275. }
  276. /**
  277. * 设备生产中工单信息
  278. * @ApiMethod (GET)
  279. * @param string $machine 机台编号
  280. * @return void
  281. * @throws \think\Exception
  282. * @throws \think\db\exception\DataNotFoundException
  283. * @throws \think\db\exception\ModelNotFoundException
  284. * @throws \think\exception\DbException
  285. */
  286. public function Production()
  287. {
  288. if (Request::instance()->isGet() == false) {
  289. $this->error('非法请求');
  290. }
  291. $params = Request::instance()->param();
  292. if (!isset($params['machine']) || empty($params['machine'])) {
  293. $this->error('参数错误');
  294. }
  295. $machine = $params['machine'];
  296. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  297. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  298. $list = [];
  299. $row = [];
  300. if (!empty($data['工单编号'])){
  301. $endTime = \db('工单_工艺资料')
  302. ->where('Gy0_gdbh',$data['工单编号'])
  303. ->where('Gy0_yjno',$data['印件号'])
  304. ->where('Gy0_gxh',$data['工序号'])
  305. ->find();
  306. $list['工单编号'] = $data['工单编号'];
  307. if (!empty($endTime)){
  308. $list['印件号'] = $data['印件号'];
  309. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  310. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  311. $list['产品名称'] = rtrim($name);
  312. $list['产品代号'] = rtrim($code);
  313. $list['工序名称'] = $data['工序名称'];
  314. }
  315. $list['状态'] = rtrim($data['当前状态']);
  316. $list['开工时间'] = $data['开工时间'];
  317. }else{
  318. $list['工单编号'] = '';
  319. $list['印件号'] = 0;
  320. $list['产品名称'] = '';
  321. $list['工序名称'] = '';
  322. $list['产品代号'] = '';
  323. $list['状态'] = '';
  324. $list['开工时间'] = '';
  325. }
  326. $list['班组编号'] = rtrim($data['班组编号']);
  327. $list['班组Id'] = rtrim($data['班组ID']);
  328. $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  329. 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,
  330. rtrim(sczl_bh10) as bh10")->find();
  331. if (!empty($class)){
  332. for ($i=1;$i<11;$i++) {
  333. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  334. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  335. $row[$i] = [
  336. '编号' => $class['bh' . $i],
  337. '姓名' => $name['姓名']
  338. ];
  339. }
  340. }
  341. $row = array_values($row);
  342. }
  343. $list['班组成员'] = $row;
  344. $list['定额代号'] = $machineCode;
  345. $this->success('成功',$list);
  346. }
  347. /**
  348. * 设备工作清单
  349. * @ApiMethod (GET)
  350. * @param string $machine 机台编号
  351. * @return void
  352. * @throws \think\db\exception\DataNotFoundException
  353. * @throws \think\db\exception\ModelNotFoundException
  354. * @throws \think\exception\DbException
  355. */
  356. public function EquipmentWorklist()
  357. {
  358. if ($this->request->isGet() === false){
  359. $this->error('请求错误');
  360. }
  361. $machine = input('machine');
  362. if (empty($machine)){
  363. $this->error('参数错误');
  364. }
  365. $orderList = \db('工单_工艺资料')
  366. ->alias('a')
  367. // ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','LEFT')
  368. ->join('工单_基本资料 c','a.Gy0_gdbh = c.Gd_gdbh')
  369. ->join('工单_印件资料 d','a.Gy0_gdbh = d.Yj_Gdbh AND a.Gy0_yjno = d.yj_Yjno')
  370. ->field('a.Gy0_gdbh as gdbh,a.质量要求 as 质量信息,a.Gy0_yjno as yjno,a.Gy0_gxh as gxh,a.Gy0_sbbh as sbbh,
  371. a.Gy0_gxmc as gxmc,a.Add_gxmc as add_gxmc,a.Gy0_辅助工时 as 装版工时,a.Gy0_小时产能 as 工序产能,a.Gy0_生产工时 as 计划工时,
  372. a.Gy0_sj1 as sj1,a.Gy0_sj2 as sj2,a.工序备注 as 排产备注,d.yj_yjmc as 印件名称,c.成品名称 as 产品名称,c.成品代号 as 产品代号,
  373. a.Gy0_计划接货数 as 计划接货数,a.Gy0_ls as ls,a.Gy0_班次安排 as 班组,a.UniqId as UniqId,a.Gy0_最早开工时间 as 最早开工时间')
  374. ->where('a.Gy0_sbbh','like','%'.$machine.'%')
  375. ->where('a.PD_WG','1900-01-01 00:00:00')
  376. ->where('a.Gy0_sj1','<>','1900-01-01 00:00:00')
  377. ->where('c.gd_statu','2-生产中')
  378. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  379. ->order('a.Gy0_sj1')
  380. ->select();
  381. if (!empty($orderList)){
  382. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  383. foreach ($orderList as $key=>$value){
  384. $machineList = explode(' ',$value['sbbh']);
  385. $cl_data = \db('设备_产量计酬')
  386. ->field('SUM(sczl_cl) as 已完成,SUM(sczl_zcfp) as 制程废品')
  387. ->where('sczl_gdbh',$value['gdbh'])
  388. ->where('sczl_yjno',$value['yjno'])
  389. ->where('sczl_gxh',$value['gxh'])
  390. ->select();
  391. $orderList[$key]['status'] = 0;
  392. if (!empty($data)){
  393. if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
  394. $orderList[$key]['status'] = 1;
  395. }
  396. }
  397. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  398. $orderList[$key]['印件号'] = $value['yjno'];
  399. $orderList[$key]['工序号'] = $value['gxh'];
  400. if ($value['yjno']<10){
  401. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  402. }
  403. if ($value['gxh']<10){
  404. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  405. }
  406. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  407. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  408. if ((int)$cl_data[0]['制程废品'] === 0){
  409. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'];
  410. }else{
  411. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'].'('.$cl_data[0]['制程废品'].')';
  412. }
  413. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  414. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls'],$orderList[$key]['制程废品']);
  415. if (in_array($machine,$machineList) === false){
  416. unset($orderList[$key]);
  417. }
  418. }
  419. $data = array_values($orderList);
  420. }
  421. $this->success('成功',$data);
  422. }
  423. /**
  424. * 工序、印件、完成数量
  425. * @ApiMethod (GET)
  426. * @param string $workOrder 工单编号
  427. * @return void
  428. * @throws \think\Exception
  429. * @throws \think\db\exception\DataNotFoundException
  430. * @throws \think\db\exception\ModelNotFoundException
  431. * @throws \think\exception\DbException
  432. */
  433. public function Procedure()
  434. {
  435. if ($this->request->isGet() === false){
  436. $this->error('请求错误');
  437. }
  438. $workOrder = input('Gd_gdbh');
  439. $data = [];
  440. if (!empty($workOrder)){
  441. //右边工艺及完成数量
  442. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  443. ->distinct(true)->order('sczl_gxh')
  444. ->column('sczl_gxh');
  445. foreach ($Process as $k=>$v){
  446. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  447. ->where('sczl_gxh',$v)
  448. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  449. ->find();
  450. if ($res['sczl_yjno']<10){
  451. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  452. }
  453. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  454. $processList['completed'] = \db('设备_产量计酬')
  455. ->where('sczl_gdbh',$workOrder)
  456. ->where('sczl_gxh',$v)
  457. ->count();
  458. array_push($data,$processList);
  459. }
  460. }
  461. $this->success('成功',$data);
  462. }
  463. /**
  464. * 班组人员及分配比例
  465. * @ApiMethod (GET)
  466. * @param string $machine 机台编号
  467. * @return void
  468. * @throws \think\db\exception\DataNotFoundException
  469. * @throws \think\db\exception\ModelNotFoundException
  470. * @throws \think\exception\DbException
  471. */
  472. public function Team()
  473. {
  474. if ($this->request->isGet() === false){
  475. $this->error('请求错误');
  476. }
  477. $machine = input('machine');
  478. if (empty($machine)){
  479. $this->error('参数错误');
  480. }
  481. $where = [
  482. 'sczl_jtbh' => $machine,
  483. ];
  484. $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,
  485. 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,
  486. 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,
  487. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  488. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  489. $team = \db('设备_产量计酬')
  490. ->where('sczl_jtbh',$machine)
  491. ->field($field)
  492. ->order('UniqId desc')
  493. ->find();
  494. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  495. $data = [];
  496. foreach ($list as $k=>$v){
  497. if ($team == $v){
  498. $data[$k]['status'] = 1;
  499. }else{
  500. $data[$k]['status'] = 0;
  501. }
  502. $data[$k]['ID'] = $v['ID'];
  503. $data[$k]['班组号'] = $v['班组号'];
  504. for ($i=1;$i<11;$i++){
  505. if ($v['bh'.$i] != ''){
  506. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  507. if ($v['rate'.$i] > 0){
  508. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  509. }else{
  510. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
  511. }
  512. }
  513. }
  514. }
  515. $this->success('成功',$data);
  516. }
  517. /**
  518. * 当班产量明细
  519. * @ApiMethod (GET)
  520. * @param string $machine 机台编号
  521. * @param string $workOrder 工单编号
  522. * @param string $team 班次
  523. * @return void
  524. * @throws \think\db\exception\DataNotFoundException
  525. * @throws \think\db\exception\ModelNotFoundException
  526. * @throws \think\exception\DbException
  527. */
  528. public function OutputDetail()
  529. {
  530. if ($this->request->isGet() === false){
  531. $this->error('请求错误');
  532. }
  533. $machine = input('machine');
  534. $workOrder = input('Gd_gdbh');
  535. $team = substr(input('team'),0,1);
  536. if (empty($machine) || empty($team)){
  537. $this->success('');
  538. }
  539. $sczlTime = date('Y-m-d H:i:s',time());
  540. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  541. $time = date('Y-m-d 00:00:00',time()-86400);
  542. }else{
  543. $time = date('Y-m-d 00:00:00');
  544. }
  545. $where = [
  546. 'sczl_jtbh' => $machine,
  547. 'sczl_bzdh' => ['like',$team.'%'],
  548. 'sczl_rq' => $time,
  549. ];
  550. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_num) as 流程单号,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
  551. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  552. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  553. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  554. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
  555. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  556. if (!empty($list)){
  557. foreach ($list as $k=>$v){
  558. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  559. if ($v['yjno']<10){
  560. $list[$k]['yjno'] = '0'.$v['yjno'];
  561. }
  562. if (!empty($v['拉料'])){
  563. $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
  564. }
  565. if (isset($list[$k]['拉料姓名']) === false){
  566. $list[$k]['拉料姓名'] = '';
  567. }
  568. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  569. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  570. $list[$k]['产品名称'] = $name['cpmc'];
  571. }
  572. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  573. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  574. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  575. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  576. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  577. $total[0]['版数'] = count($list);
  578. $list['total'] = $total[0];
  579. }
  580. $this->success('成功',$list);
  581. }
  582. /**
  583. * 检验记录
  584. * @ApiMethod (GET)
  585. * @param string $machine 机台编号
  586. * @param string $workOrder 工单编号
  587. * @param string $team 班次
  588. * @return void
  589. * @throws \think\db\exception\DataNotFoundException
  590. * @throws \think\db\exception\ModelNotFoundException
  591. * @throws \think\exception\DbException
  592. */
  593. public function InspectionRecord()
  594. {
  595. if ($this->request->isGet() === false){
  596. $this->error('请求失败');
  597. }
  598. $machine = input('machine');
  599. $workOrder = input('Gd_gdbh');
  600. $team = input('team');
  601. if (empty($machine) || empty($workOrder) || empty($team)){
  602. $this->success('');
  603. }
  604. $where = [
  605. '设备编号' => $machine,
  606. '工单编号' => $workOrder,
  607. '班组编号' => $team,
  608. '类别' => ['in',['IPQC检验','机台检验']],
  609. ];
  610. //检验项目筛选
  611. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  612. //检验时间
  613. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  614. foreach ($InspectionTime as $k=>$v){
  615. $InspectionTime[$k] = date('H:i',strtotime($v));
  616. }
  617. //检测记录详情
  618. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  619. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  620. $data = [];
  621. //检测数据
  622. foreach ($item as $key=>$value){
  623. $SubmissionTime = \db('制程检验_记录')->where($where)
  624. ->where('检验项目',$value)
  625. ->where('检验结果','合格')
  626. ->field('rtrim(提交时间) as 提交时间')
  627. ->select();
  628. $time = [];
  629. foreach ($SubmissionTime as $k=>$v){
  630. $time[$k] = date('H:i',strtotime($v['提交时间']));
  631. }
  632. $data[$key] = [
  633. '工单编号' => $nameDetail['工单编号'],
  634. '印件号' => $nameDetail['印件号'],
  635. '工序名称' => $nameDetail['工序名称'],
  636. '检验项目' => $value,
  637. 'inspectresult' => implode(',',$time),
  638. ];
  639. }
  640. $data['inspectiontime'] = $InspectionTime;
  641. $this->success('成功',$data);
  642. }
  643. /**
  644. * 班组维护->班组添加
  645. * @ApiMethod (GET)
  646. * @param void
  647. * @return void
  648. * @throws \think\db\exception\DataNotFoundException
  649. * @throws \think\db\exception\ModelNotFoundException
  650. * @throws \think\exception\DbException
  651. */
  652. public function MachineTeamAdd()
  653. {
  654. if (Request::instance()->isPost() === false ){
  655. $this->error('请求错误');
  656. }
  657. $param = Request::instance()->post();
  658. if (empty($param)){
  659. $this->error('参数错误');
  660. }
  661. $lastId = \db('设备_班组资料')
  662. ->order('UniqId desc')
  663. ->value('UniqId');
  664. if (empty($lastId)){
  665. $lastId = 0;
  666. }
  667. for($i=1;$i<11;$i++){
  668. if (!empty($param['sczl_bh'.$i])){
  669. $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
  670. if (empty($name)){
  671. $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
  672. }
  673. }
  674. }
  675. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  676. $param['UniqId'] = $lastId + 1;
  677. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  678. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  679. $res = \db()->query($sql);
  680. if ($res !== false){
  681. $this->success('成功');
  682. }else{
  683. $this->error('失败');
  684. }
  685. }
  686. /**
  687. * 机台编号列表
  688. * @ApiMethod (GET)
  689. * @return void
  690. */
  691. public function MachineList()
  692. {
  693. if ($this->request->isGet() === false){
  694. $this->error('请求错误');
  695. }
  696. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  697. if (empty($list)){
  698. $this->success('未找到机台编号');
  699. }
  700. $data = [];
  701. foreach ($list as $key=>$value){
  702. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  703. }
  704. $this->success('成功',$data);
  705. }
  706. /**
  707. * 删除班组信息
  708. * @ApiMethod (GET)
  709. * @param void
  710. * @return void
  711. * @throws \think\Exception
  712. * @throws \think\exception\PDOException
  713. */
  714. public function teamDel()
  715. {
  716. if (Request::instance()->isPost() === false){
  717. $this->error('请求错误');
  718. }
  719. $param = Request::instance()->post();
  720. if (empty($param)){
  721. $this->error('参数错误');
  722. }
  723. $machine = \db('设备_班组资料')
  724. ->where('UniqId',$param['UniqId'])
  725. ->value('sczl_jtbh');
  726. $teamId = \db('设备_产量采集')
  727. ->where('设备编号',$machine)
  728. ->order('UniqId desc')
  729. ->value('班组ID');
  730. if ($teamId === (int)$param['UniqId']){
  731. $this->success('无法删除正在生产的班组资料,请先切换班组');
  732. }
  733. $res = \db('设备_班组资料')
  734. ->where('UniqId',$param['UniqId'])
  735. ->delete();
  736. if ($res !== false){
  737. $this->success('成功');
  738. }else{
  739. $this->error('失败');
  740. }
  741. }
  742. /**
  743. * 管理人员现场巡检记录->展示
  744. * @ApiMethod (GET)
  745. * @param void
  746. * @return void
  747. * @throws \think\db\exception\DataNotFoundException
  748. * @throws \think\db\exception\ModelNotFoundException
  749. * @throws \think\exception\DbException
  750. */
  751. public function FieldInspectionRecord()
  752. {
  753. if ($this->request->isGet() === false){
  754. $this->error('请求错误');
  755. }
  756. $param = $this->request->param();
  757. if (empty($param)){
  758. $this->error('参数错误');
  759. }
  760. // $date = date('Y-m-d H:i:s',time());
  761. // if (empty($param['start'])){
  762. // $startTime = date('Y-m-d 08:30:00',time());
  763. // }else{
  764. // $startTime = date('Y-m-d H:i:s',strtotime($param['start']));
  765. // }
  766. // if ($date<$startTime){
  767. // $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  768. // }
  769. // 获取当前时间
  770. $current_time = time();
  771. // 设置时间范围
  772. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  773. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  774. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  775. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  776. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  777. // 判断当前时间属于哪个时间范围
  778. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  779. $startTime = date('Y-m-d') . ' 08:30:00';
  780. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  781. $startTime = date('Y-m-d') . ' 20:30:00';
  782. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  783. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  784. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  785. $startTime = date('Y-m-d') . ' 20:30:00';
  786. }
  787. $where = [
  788. '工单编号' => $param['workOrder'],
  789. '开工时间' => $startTime,
  790. '类别' => '现场巡查记录',
  791. '班组编号' => ['like',substr($param['team'],0,1).'%']
  792. ];
  793. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  794. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  795. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  796. $list = \db('制程检验_记录')->where($where)
  797. ->field($filed)
  798. ->select();
  799. if (empty($list)){
  800. $this->success('',[]);
  801. }
  802. foreach ($list as $key=>$value){
  803. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  804. $list[$key]['归属时段'] = $value['开工时间'];
  805. $list[$key]['分钟差数'] = $number;
  806. if ($number != 0){
  807. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  808. }
  809. }
  810. $this->success('成功',$list);
  811. }
  812. /**
  813. * 管理人员现场巡检记录->添加
  814. * @ApiMethod (POST)
  815. * @param void
  816. * @return void
  817. */
  818. public function FieldInspectionRecordAdd()
  819. {
  820. if (Request::instance()->isPost() === false){
  821. $this->error('请求错误');
  822. }
  823. $param = Request::instance()->post();
  824. if (empty($param)){
  825. $this->error('参数错误');
  826. }
  827. if ($param['processCode']<10){
  828. $param['processCode'] = '0'.$param['processCode'];
  829. }
  830. $date = date('Y-m-d H:i:s',time());
  831. $startTime = date('Y-m-d 08:30:00',time());
  832. if ($date<$startTime){
  833. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  834. }
  835. $data = [
  836. '类别' => $param['category'],
  837. '工单编号' => $param['workOrder'],
  838. '印件号' => $param['printCode'],
  839. '工序名称' => $param['processCode'].'-'.$param['process'],
  840. '流程单号' => $param['flowCode'],
  841. '设备编号' => $param['machine'],
  842. '班组编号' => $param['team'],
  843. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  844. '相关标准' => '',
  845. '量测仪器' => '',
  846. '检验结果' => '',
  847. '检验备注' => $param['remark'],
  848. '提交时间' => date('Y-m-d H:i:s',time()),
  849. '开工时间' => $startTime,
  850. 'sys_id' => '',
  851. 'sys_rq' => date('Y-m-d H:i:s',time()),
  852. 'mod_rq' => '0000-00-00 00:00:00',
  853. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  854. ];
  855. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  856. $res = Db::query($sql);
  857. if ($res !== false){
  858. $this->success('成功');
  859. }else{
  860. $this->error('失败');
  861. }
  862. }
  863. /**
  864. * 设备点检->左侧菜单栏
  865. * @ApiMethod (GET)
  866. * @param void
  867. * @return void
  868. */
  869. public function SpotCheckItem()
  870. {
  871. if ($this->request->isGet() === false){
  872. $this->error('请求错误');
  873. }
  874. $param = $this->request->param();
  875. if (empty($param)){
  876. $this->error('参数错误');
  877. }
  878. $list = \db('设备_点检项目')
  879. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  880. ->distinct(true)
  881. ->column('部件名称','部件编号');
  882. if (empty($list)){
  883. $this->success('');
  884. }
  885. $this->success('成功',$list);
  886. }
  887. /**
  888. * 设备点检->检测项目
  889. * @ApiMethod (GET)
  890. * @param void
  891. * @return void
  892. * @throws \think\db\exception\DataNotFoundException
  893. * @throws \think\db\exception\ModelNotFoundException
  894. * @throws \think\exception\DbException
  895. */
  896. public function InspectionItem()
  897. {
  898. if ($this->request->isGet() === false){
  899. $this->error('请求错误');
  900. }
  901. $param = $this->request->param();
  902. if (empty($param)){
  903. $this->error('参数错误');
  904. }
  905. $list = \db('设备_点检项目')
  906. ->where('部件名称',$param['unitName'])
  907. ->where('适用机型','like','%'.$param['machine'].'#%')
  908. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  909. ->select();
  910. if (empty($list)){
  911. $this->success('未找到检测项目');
  912. }
  913. $this->success('成功',$list);
  914. }
  915. /**
  916. * 设备点检->检测记录添加
  917. * @ApiMethod (POST)
  918. * @param void
  919. * @return void
  920. * @throws \think\db\exception\DataNotFoundException
  921. * @throws \think\db\exception\ModelNotFoundException
  922. * @throws \think\exception\DbException
  923. */
  924. public function InspectionItemAdd()
  925. {
  926. if (Request::instance()->isPost() === false){
  927. $this->error('请求错误');
  928. }
  929. $param = Request::instance()->post();
  930. if (empty($param)){
  931. $this->error('参数错误');
  932. }
  933. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  934. if (empty($lastNumber)){
  935. $lastId = 0;
  936. }else{
  937. $lastId = $lastNumber;
  938. }
  939. $row = [];
  940. foreach ($param as $key=>$value){
  941. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  942. $row[$key] = [
  943. '日期' => date('Y-m-d 00:00:00',time()),
  944. '班组编号' => $value['team'],
  945. '点检设备' => $value['machine'],
  946. '部件编号' => $unitCode['部件编号'],
  947. '部件名称' => $value['unitName'],
  948. '检验项目' => $value['itemName'],
  949. '判定标准' => $value['standard'],
  950. '点检方法' => $value['method'],
  951. '点检结果' => $value['status'],
  952. '备注说明' => $value['remark'],
  953. 'Sys_id' =>'',
  954. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  955. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  956. 'Uniqid' => $lastId+$key+1
  957. ];
  958. }
  959. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  960. $res = Db::query($sql);
  961. if ($res !== false){
  962. $this->success('成功');
  963. }else{
  964. $this->error('失败');
  965. }
  966. }
  967. /**
  968. * 机台印版领用->左侧菜单
  969. * @ApiMethod (GET)
  970. * @param void
  971. * @return void
  972. */
  973. public function PrintGetTab()
  974. {
  975. if ($this->request->isGet() === false){
  976. $this->error('请求错误');
  977. }
  978. $param = $this->request->param();
  979. if (empty($param)){
  980. $this->error('参数错误');
  981. }
  982. $productCode = $param['productCode'];
  983. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  984. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  985. WHERE a.YB_Cpdh = '{$productCode}'";
  986. $res = Db::query($sql);
  987. if (empty($res)){
  988. $this->success('');
  989. }
  990. $this->success('成功',$res);
  991. }
  992. /**
  993. * 机台印版领用记录->数据详情
  994. * @ApiMethod (GET)
  995. * @param void
  996. * @return void
  997. */
  998. public function PrintDetail()
  999. {
  1000. if ($this->request->isGet() === false){
  1001. $this->error('请求失败');
  1002. }
  1003. $param = $this->request->param();
  1004. if (empty($param)){
  1005. $this->error('参数错误');
  1006. }
  1007. $productCode = $param['productCode'];
  1008. $code = $param['code'].'%';
  1009. $workOrder = $param['workOrder'];
  1010. $sql = "SELECT
  1011. RTRIM(a.`存货编码`) as `存货编码`,
  1012. RTRIM(c.`物料名称`) as `存货名称`,
  1013. RTRIM(b.`印版名称`) as `印版名称`,
  1014. RTRIM(b.`供方批号`) as `供方批号`,
  1015. RTRIM(b.`制造日期`) as `制造日期`,
  1016. SUM(d.`Yb_印数`) as `印数`,
  1017. RTRIM(e.`名称`) as `印版类别`,
  1018. SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
  1019. RTRIM(f.`Gd_客户名称`) as `客户名称`,
  1020. RTRIM(a.YB_Cpdh) as `产品编号`,
  1021. RTRIM(f.Gd_cpmc) as `产品名称`,
  1022. RTRIM(d.UniqID) as UniqId
  1023. FROM `产品_印版资料` as a
  1024. LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
  1025. JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
  1026. LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
  1027. JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
  1028. JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
  1029. WHERE a.YB_Cpdh = '{$productCode}'
  1030. AND a.`存货编码` LIKE '{$code}'
  1031. AND f.Gd_gdbh = '{$workOrder}'
  1032. AND b.`报废日期` = '1900-01-01 00:00:00'
  1033. GROUP BY b.`供方批号`
  1034. ORDER BY a.`存货编码`";
  1035. $list = Db::query($sql);
  1036. if (empty($list)){
  1037. $this->success('');
  1038. }
  1039. $this->success('成功',$list);
  1040. }
  1041. /**
  1042. * 换型清场->左侧菜单栏
  1043. * @ApiMethod (GET)
  1044. * @param void
  1045. * @return void
  1046. */
  1047. public function remodelGetTab()
  1048. {
  1049. if ($this->request->isGet() === false){
  1050. $this->error('请求错误');
  1051. }
  1052. $date = date('Y-m-d 00:00:00',time()-3456000);
  1053. $nowTime = date('Y-m-d H:i:s',time());
  1054. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  1055. if (empty($list)){
  1056. $this->error('失败');
  1057. }
  1058. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  1059. FROM `设备_基本资料` as a
  1060. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  1061. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  1062. $res = Db::query($sql);
  1063. $data = $result = [];
  1064. foreach ($list as $key=>$value){
  1065. $data[$value] = $result[$value]= $time = [];
  1066. foreach ($res as $k=>$v){
  1067. if ($value === $v['设备编号']){
  1068. $row = [
  1069. '日期' => $v['日期'],
  1070. 'id' => $v['UniqId']
  1071. ];
  1072. array_push($data[$value],$row);
  1073. }
  1074. }
  1075. foreach ($data[$value] as $m=>$n){
  1076. $time[$m] = $n['日期'];
  1077. }
  1078. $time = array_values(array_unique($time));
  1079. foreach ($time as $kk=>$vv){
  1080. $i=1;
  1081. foreach ($data[$value] as $kkk=>$vvv){
  1082. if ($kkk>=$kk && $vv === $vvv['日期']){
  1083. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  1084. $i++;
  1085. }
  1086. }
  1087. }
  1088. }
  1089. $this->success('成功',$result);
  1090. }
  1091. /**
  1092. * 换型清场->详情
  1093. * @return void
  1094. * @throws \think\db\exception\DataNotFoundException
  1095. * @throws \think\db\exception\ModelNotFoundException
  1096. * @throws \think\exception\DbException
  1097. */
  1098. public function RemodelDetail()
  1099. {
  1100. if ($this->request->isGet() === false){
  1101. $this->error('请求错误');
  1102. }
  1103. $param = $this->request->param();
  1104. if (empty($param)){
  1105. $this->error('参数错误');
  1106. }
  1107. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1108. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1109. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1110. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1111. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1112. if (empty($list)){
  1113. $this->success('未找到该条清场记录');
  1114. }
  1115. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1116. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1117. if (empty($printNameA)){
  1118. $list['印件名称A'] = '';
  1119. }else{
  1120. $list['印件名称A'] = $printNameA['yjmc'];
  1121. }
  1122. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1123. if (empty($printNameB)){
  1124. $list['印件名称B'] = '';
  1125. }else{
  1126. $list['印件名称B'] = $printNameB['yjmc'];
  1127. }
  1128. $this->success('成功',$list);
  1129. }
  1130. /**
  1131. * 换型清场->当前设备清场记录
  1132. * @ApiMethod (GET)
  1133. * @param void
  1134. * @return void
  1135. * @throws \think\db\exception\DataNotFoundException
  1136. * @throws \think\db\exception\ModelNotFoundException
  1137. * @throws \think\exception\DbException
  1138. */
  1139. public function ModelChangeRecord()
  1140. {
  1141. if ($this->request->isGet() === false){
  1142. $this->error('请求错误');
  1143. }
  1144. $param = $this->request->param();
  1145. if (empty($param)){
  1146. $this->error('参数错误');
  1147. }
  1148. $date = date('Y-m-d 00:00:00',time()-3888000);
  1149. $nowTime = date('Y-m-d H:i:s',time());
  1150. $where = [
  1151. '日期' =>['between',[$date,$nowTime]],
  1152. '机台编号' => $param['machine'],
  1153. '工单编号A' => ['<>',''],
  1154. '工单编号B' => ['<>',''],
  1155. ];
  1156. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1157. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1158. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1159. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1160. $list = \db('制程_换型清场')
  1161. ->where($where)
  1162. ->field($field)
  1163. ->select();
  1164. if (empty($list)){
  1165. $this->success('未找到换型记录');
  1166. }
  1167. foreach ($list as $key=>$value){
  1168. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1169. if (empty($printNameA)){
  1170. $list[$key]['印件名称A'] = '';
  1171. }else{
  1172. $list[$key]['印件名称A'] = $printNameA;
  1173. }
  1174. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1175. if (empty($printNameB)){
  1176. $list[$key]['印件名称B'] = '';
  1177. }else{
  1178. $list[$key]['印件名称B'] = $printNameB;
  1179. }
  1180. }
  1181. $this->success('成功',$list);
  1182. }
  1183. /**
  1184. * 车间机台状态列表展示
  1185. * @ApiMethod (GET)
  1186. * @param void
  1187. * @return void
  1188. * @throws \think\db\exception\BindParamException
  1189. * @throws \think\exception\PDOException
  1190. */
  1191. public function MachineDetailList()
  1192. {
  1193. if ($this->request->isGet() === false){
  1194. $this->error('请求错误');
  1195. }
  1196. $param = $this->request->param();
  1197. if (empty($param)){
  1198. $this->error('参数错误');
  1199. }
  1200. $workshop = $param['workshop'];
  1201. $sql = "SELECT
  1202. RTRIM( a.`设备编号` ) AS 设备编号,
  1203. RTRIM( a.`设备名称` ) AS 设备名称,
  1204. RTRIM( d.`当前状态` ) AS 状态
  1205. FROM
  1206. `设备_基本资料` AS a
  1207. JOIN (
  1208. SELECT
  1209. b.`设备编号`,
  1210. b.`当前状态`,
  1211. b.`开工时间`
  1212. FROM
  1213. `设备_产量采集` AS b
  1214. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1215. AND b.`UniqId` = c.`UniqId`
  1216. ) AS d ON a.`设备编号` = d.`设备编号`
  1217. WHERE
  1218. a.`使用部门` = '{$workshop}'
  1219. GROUP BY
  1220. a.`设备编号`
  1221. ORDER BY
  1222. a.UniqId";
  1223. $list = \db()->query($sql);
  1224. foreach ($list as $key=>$value){
  1225. if ($value['状态'] == ''){
  1226. $list[$key]['状态'] = '待单';
  1227. }
  1228. }
  1229. $this->success('成功',$list);
  1230. }
  1231. /**
  1232. * 机台当前参数展示
  1233. * @ApiMethod (GET)
  1234. * @return void
  1235. * @throws \think\db\exception\DataNotFoundException
  1236. * @throws \think\db\exception\ModelNotFoundException
  1237. * @throws \think\exception\DbException
  1238. */
  1239. public function MachineDetail()
  1240. {
  1241. if ($this->request->isGet() === false){
  1242. $this->error('请求错误');
  1243. }
  1244. $param = $this->request->param();
  1245. if (empty($param)){
  1246. $this->error('参数错误');
  1247. }
  1248. $data = [];
  1249. if ($param['start'] === ''){
  1250. if (date('Y-m-d H:i:s')>date('Y-m-d 08:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 20:30:00',time())){
  1251. $param['start'] = date('Y-m-d 08:30:00',time());
  1252. }elseif (date('Y-m-d H:i:s')>date('Y-m-d 20:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 23:59:59',time())){
  1253. $param['start'] = date('Y-m-d 20:30:00',time());
  1254. }else{
  1255. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1256. }
  1257. }
  1258. $machineDetail = \db('设备_产量采集')
  1259. ->alias('a')
  1260. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1261. ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
  1262. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1263. ->field([
  1264. 'rtrim(a.开工时间)' => '开工时间',
  1265. 'rtrim(a.设备编号)' => '设备编号',
  1266. 'rtrim(a.工单编号)' => '工单编号',
  1267. 'rtrim(b.设备名称)' => '设备名称',
  1268. 'rtrim(c.Gy0_gxh)' => '工序号',
  1269. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1270. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1271. ])
  1272. ->where('a.设备编号', $param['machine'])
  1273. ->order('a.UniqId desc')
  1274. ->find();
  1275. $data['machine'] = [
  1276. '日期' => $machineDetail['开工时间'],
  1277. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1278. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1279. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1280. ];
  1281. //机台状态时间
  1282. $startTime = \db('设备_产量采集')
  1283. ->where('设备编号',$param['machine'])
  1284. ->where('开工时间',$param['start'])
  1285. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1286. ->group('当前状态')
  1287. ->select();
  1288. if (!empty($startTime)){
  1289. foreach ($startTime as $key=>$value){
  1290. $data['timeDifference'][$key] = [
  1291. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1292. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1293. ];
  1294. if ($value['状态'] === '生产'){
  1295. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1296. }
  1297. }
  1298. }else{
  1299. $data['timeDifference'][0] = [
  1300. '时间' => 0,
  1301. '状态' => '待单'
  1302. ];
  1303. $data['当班产量'] = 0;
  1304. }
  1305. //机台产能/时间明细
  1306. $row = \db('设备_产量采集')
  1307. ->where('设备编号',$param['machine'])
  1308. ->where('开工时间',$param['start'])
  1309. ->where('当班产量','<>',-1)
  1310. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1311. ->select();
  1312. if (empty($row)){
  1313. $data['row'] = [];
  1314. }
  1315. foreach ($row as $key=>$value){
  1316. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1317. $data['row'][$key]['状态'] = $value['状态'];
  1318. if ($key<2){
  1319. $data['row'][$key]['产能'] = 0;
  1320. }else{
  1321. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1322. }
  1323. }
  1324. //机台状态
  1325. $status = end($row);
  1326. if (empty($status['状态'])){
  1327. $data['status'] = '待单';
  1328. }else{
  1329. $data['status'] = $status['状态'];
  1330. }
  1331. //检验数据
  1332. $list = \db('制程检验_记录')
  1333. ->where('开工时间',$param['start'])
  1334. ->where('设备编号',$param['machine'])
  1335. ->where('sys_rq','>',$param['start'])
  1336. ->where('工单编号',$machineDetail['工单编号'])
  1337. ->field('rtrim(类别) as 类别,提交时间')
  1338. ->select();
  1339. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1340. if (!empty($list)){
  1341. foreach ($list as $key=>$value){
  1342. if ($value['类别'] == '首件与过程确认'){
  1343. array_push($data['首件'],$value['提交时间']);
  1344. }
  1345. if ($value['类别'] == '机台检验'){
  1346. array_push($data['自检'],$value['提交时间']);
  1347. }
  1348. if ($value['类别'] == 'IPQC检验'){
  1349. array_push($data['IPQC'],$value['提交时间']);
  1350. }
  1351. }
  1352. $data['首件'] = array_values(array_unique($data['首件']));
  1353. $data['自检'] = array_values(array_unique($data['自检']));
  1354. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1355. }else{
  1356. $data['首件'] = [];
  1357. $data['自检'] = [];
  1358. $data['IPQC'] = [];
  1359. }
  1360. $this->success('成功',$data);
  1361. }
  1362. /**
  1363. * 制程检验记录->检验项目
  1364. * @ApiMethod (GET)
  1365. * @param void
  1366. * @return void
  1367. * @throws \think\db\exception\DataNotFoundException
  1368. * @throws \think\db\exception\ModelNotFoundException
  1369. * @throws \think\exception\DbException
  1370. */
  1371. public function ProcessInspectionRecordsItem()
  1372. {
  1373. if ($this->request->isGet() === false){
  1374. $this->error('请求错误');
  1375. }
  1376. $param = $this->request->param();
  1377. if (empty($param)){
  1378. $this->error('参数错误');
  1379. }
  1380. $list = \db('制程检验_项目')
  1381. ->where('工序','like','%'.$param['process'].'%')
  1382. ->select();
  1383. if (empty($list)){
  1384. $this->success('未找到检测项目');
  1385. }
  1386. $data = [];
  1387. foreach ($list as $key=>$value){
  1388. $data['首件']['指标检验'][$key] = [
  1389. '检验项目' => rtrim($value['检测项目']),
  1390. '检测方法' => rtrim($value['检测方法']),
  1391. '检验频率' => rtrim($value['首件签样要求']),
  1392. '相关标准' => rtrim($value['技术要求'])
  1393. ];
  1394. $data['机台检验']['指标检验'][$key] = [
  1395. '检验项目' => rtrim($value['检测项目']),
  1396. '检测方法' => rtrim($value['检测方法']),
  1397. '检验频率' => rtrim($value['机台自检频率']),
  1398. '相关标准' => rtrim($value['技术要求'])
  1399. ];
  1400. $data['IPQC']['指标检验'][$key] = [
  1401. '检验项目' => rtrim($value['检测项目']),
  1402. '检测方法' => rtrim($value['检测方法']),
  1403. '检验频率' => rtrim($value['IPQC检验频率']),
  1404. '相关标准' => rtrim($value['技术要求'])
  1405. ];
  1406. }
  1407. $row = \db('制程检验_项目附加')
  1408. ->where('工序','like','%'.$param['process'].'%')
  1409. ->select();
  1410. foreach ($row as $key=>$value){
  1411. $data['首件']['附加'][$key] = [
  1412. '缺陷备注' => rtrim($value['缺陷备注']),
  1413. '编号' => rtrim($value['编号'])
  1414. ];
  1415. $data['机台检验']['附加'][$key] = [
  1416. '缺陷备注' => rtrim($value['缺陷备注']),
  1417. '编号' => rtrim($value['编号'])
  1418. ];
  1419. $data['IPQC']['附加'][$key] = [
  1420. '缺陷备注' => rtrim($value['缺陷备注']),
  1421. '编号' => rtrim($value['编号'])
  1422. ];
  1423. }
  1424. $this->success('成功',$data);
  1425. }
  1426. /**
  1427. * 制程检验记录->检测记录添加
  1428. * @ApiMethod (POST)
  1429. * @param void
  1430. * @return void
  1431. * @throws \think\db\exception\DataNotFoundException
  1432. * @throws \think\db\exception\ModelNotFoundException
  1433. * @throws \think\exception\DbException
  1434. */
  1435. public function ProcessInspectionRecordsItemAdd()
  1436. {
  1437. if (Request::instance()->isPost() === false){
  1438. $this->error('请求错误');
  1439. }
  1440. $param = Request::instance()->post();
  1441. if (empty($param)){
  1442. $this->error('参数错误');
  1443. }
  1444. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1445. if (empty($startID)){
  1446. $startID = 0;
  1447. }
  1448. $process = \db('工单_工艺资料')
  1449. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1450. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1451. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1452. ->find();
  1453. $startTime = \db('设备_产量采集')
  1454. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1455. ->where('工单编号',$param[0]['workOrder'])
  1456. ->order('UniqId desc')
  1457. ->find();
  1458. if ((int)$process['gxh']<10){
  1459. $process['gxh'] = '0'.$process['gxh'];
  1460. }
  1461. if ($process['add_gxmc'] !== ''){
  1462. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1463. }else{
  1464. $printName = $process['gxh'].'-'.$process['gxmc'];
  1465. }
  1466. if (empty($process)){
  1467. $this->success('数据错误');
  1468. }
  1469. $data = [];
  1470. foreach ($param as $key=>$value){
  1471. $data[$key] = [
  1472. '类别' => $value['category'],
  1473. '工单编号' => $value['workOrder'],
  1474. '印件号' => $value['yjno'],
  1475. '工序名称' => $printName,
  1476. '流程单号' => $value['flow'],
  1477. '设备编号' => $value['machine'].'#',
  1478. '班组编号' => $startTime['班组编号'],
  1479. '检验项目' => $value['item'],
  1480. '相关标准' => $value['standard'],
  1481. '量测仪器' => $value['instrument'],
  1482. '检验结果' => $value['selected'],
  1483. '检验备注' => $value['remark'],
  1484. '提交时间' => date('Y-m-d H:i:s',time()),
  1485. '开工时间' => rtrim($startTime['开工时间']),
  1486. 'sys_id' => '',
  1487. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1488. 'mod_rq' => '0000-00-00 00:00:00',
  1489. 'UniqId' => $startID + $key +1
  1490. ];
  1491. }
  1492. $res = \db('制程检验_记录')->insertAll($data);
  1493. if ($res !== false){
  1494. $this->success('成功');
  1495. }else{
  1496. $this->error('失败');
  1497. }
  1498. }
  1499. /**
  1500. * 制程检验记录->附加检验记录添加
  1501. * @ApiMethod (POST)
  1502. * @param void
  1503. * @return void
  1504. * @throws \think\db\exception\DataNotFoundException
  1505. * @throws \think\db\exception\ModelNotFoundException
  1506. * @throws \think\exception\DbException
  1507. */
  1508. public function AdditionalInspectionRecordAdd()
  1509. {
  1510. if (Request::instance()->isPost() === false){
  1511. $this->error('请求错误');
  1512. }
  1513. $param = Request::instance()->post();
  1514. if (empty($param)){
  1515. $this->error('参数错误');
  1516. }
  1517. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1518. if (empty($startID)){
  1519. $startID = 0;
  1520. }
  1521. $process = \db('工单_工艺资料')
  1522. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1523. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1524. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1525. ->find();
  1526. $startTime = \db('设备_产量采集')
  1527. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1528. ->where('工单编号',$param[0]['workOrder'])
  1529. ->order('UniqId desc')
  1530. ->find();
  1531. if ((int)$process['gxh']<10){
  1532. $process['gxh'] = '0'.$process['gxh'];
  1533. }
  1534. if ($process['add_gxmc'] !== ''){
  1535. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1536. }else{
  1537. $printName = $process['gxh'].'-'.$process['gxmc'];
  1538. }
  1539. if (empty($process)){
  1540. $this->success('数据错误');
  1541. }
  1542. $data = [];
  1543. foreach ($param as $key=>$value){
  1544. $data[$key] = [
  1545. '工单编号' => $value['workOrder'],
  1546. '印件号' => $value['yjno'],
  1547. '工序名称' => $printName,
  1548. '流程单号' => $value['flow'],
  1549. '设备编号' => $value['machine'],
  1550. '班组编号' => $startTime['班组编号'],
  1551. '缺陷备注' => $value['remark'],
  1552. '提交时间' => date('Y-m-d H:i:s',time()),
  1553. '开工时间' => rtrim($startTime['开工时间']),
  1554. 'sys_id' => '',
  1555. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1556. 'mod_rq' => '0000-00-00 00:00:00',
  1557. 'UniqId' => $startID + $key +1
  1558. ];
  1559. }
  1560. $res = \db('制程检验_记录附加')->insertAll($data);
  1561. if ($res !== false){
  1562. $this->success('成功');
  1563. }else{
  1564. $this->error('失败');
  1565. }
  1566. }
  1567. /**
  1568. * 客诉记录
  1569. * @ApiMethod (GET)
  1570. * @param void
  1571. * @return void
  1572. * @throws \think\db\exception\DataNotFoundException
  1573. * @throws \think\db\exception\ModelNotFoundException
  1574. * @throws \think\exception\DbException
  1575. */
  1576. public function ComplaintRecord()
  1577. {
  1578. if ($this->request->isGet() === false){
  1579. $this->error('请求错误');
  1580. }
  1581. $param = $this->request->param();
  1582. if (isset($param['productCode'])){
  1583. $where['产品编号'] = $param['productCode'];
  1584. }
  1585. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1586. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1587. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1588. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1589. $list = \db('db_客诉记录')
  1590. ->where($where)
  1591. ->field($filed)
  1592. ->select();
  1593. if (empty($list)){
  1594. $this->success('未找到该产品客诉记录');
  1595. }
  1596. $this->success('成功',$list);
  1597. }
  1598. /**
  1599. * 设置机台班组信息
  1600. * @return void
  1601. * @throws \think\db\exception\DataNotFoundException
  1602. * @throws \think\db\exception\ModelNotFoundException
  1603. * @throws \think\exception\DbException
  1604. */
  1605. public function setMachineTeam()
  1606. {
  1607. if (Request::instance()->isPost() == false) {
  1608. $this->error('非法请求');
  1609. }
  1610. $params = Request::instance()->post();
  1611. if (!isset($params['machine']) || empty($params['machine'] )) {
  1612. $this->error('参数不能为空');
  1613. }
  1614. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1615. $this->error('请先选择班组成员');
  1616. }
  1617. $machine = $params['machine'] . '#';
  1618. $data = [];
  1619. $lastData = \db('设备_产量采集')
  1620. ->order('UniqId desc')
  1621. ->find();
  1622. $id = $lastData['UniqId']+1;
  1623. $data['当前状态'] = $params['status'];
  1624. $data['时间'] = date('Y-m-d H:i:s');
  1625. $data['设备编号'] = $machine;
  1626. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1627. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1628. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1629. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1630. $data['当班产量'] = $params['production_now'];
  1631. $data['累计产量'] = $params['production_all'];
  1632. $data['班组编号'] = $params['sczl_bzdh'];
  1633. $data['班组ID'] = $params['team_id'];
  1634. // 获取当前时间
  1635. $current_time = time();
  1636. // 设置时间范围
  1637. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1638. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1639. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1640. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1641. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  1642. // 判断当前时间属于哪个时间范围
  1643. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1644. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1645. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1646. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1647. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1648. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1649. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  1650. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1651. }
  1652. if (!empty($params['order']) && !empty($params['yjno'])){
  1653. $option['Gy0_gdbh'] = $params['order'];
  1654. $option['Gy0_yjno'] = $params['yjno'];
  1655. $option['Gy0_gxh'] = $data['工序号'];
  1656. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1657. }else{
  1658. $data['任务ID'] = '';
  1659. }
  1660. $data['UniqId'] = $id;
  1661. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1662. $res = Db::query($sql);
  1663. if ($res === false) {
  1664. $this->error('设置失败');
  1665. } else {
  1666. $this->success('设置成功');
  1667. }
  1668. }
  1669. /**
  1670. * 首页数据
  1671. * @return void
  1672. * @throws \think\Exception
  1673. * @throws \think\db\exception\DataNotFoundException
  1674. * @throws \think\db\exception\ModelNotFoundException
  1675. * @throws \think\exception\DbException
  1676. */
  1677. public function index()
  1678. {
  1679. if ($this->request->isGet() === false){
  1680. $this->error('请求错误');
  1681. }
  1682. $nowTime = date('Y-m-d H:i:s',time());
  1683. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1684. $where =[
  1685. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1686. '行号' => '1'
  1687. ];
  1688. $data = [];
  1689. //按状态查询工单信息
  1690. $orderList = \db('工单_基本资料')
  1691. ->where($where)
  1692. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1693. ->group('gd_statu')
  1694. ->select();
  1695. foreach ($orderList as $value){
  1696. if ($value['状态'] === '1-已完工'){
  1697. $data['workOrderData']['已完工'] = $value['数量'];
  1698. }
  1699. if ($value['状态'] === '3-计划中'){
  1700. $data['workOrderData']['计划中'] = $value['数量'];
  1701. }
  1702. }
  1703. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1704. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1705. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1706. ->where([
  1707. 'a.gd_statu' => '2-生产中',
  1708. 'a.行号' => '1',
  1709. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1710. 'b.PD_WG' => '1900-01-01 00:00:00',
  1711. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1712. 'c.状态' => '',
  1713. ])
  1714. ->group('a.Gd_gdbh')
  1715. ->count();
  1716. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1717. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1718. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1719. ->where([
  1720. 'a.gd_statu' => '2-生产中',
  1721. 'a.行号' => '1',
  1722. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1723. 'b.PD_WG' => '1900-01-01 00:00:00',
  1724. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1725. 'c.状态' => '',
  1726. ])
  1727. ->group('a.Gd_gdbh')
  1728. ->count();
  1729. //按月份查询工单信息
  1730. $data['monthData'] = \db('工单_基本资料')
  1731. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1732. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1733. ->group('month')
  1734. ->order('month')
  1735. ->select();
  1736. //查询最近十条客诉信息
  1737. $data['customer'] = \db('db_客诉记录')
  1738. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1739. ->limit(10)
  1740. ->order('Sys_rq desc')
  1741. ->select();
  1742. $this->success('成功',$data);
  1743. }
  1744. /**
  1745. * 员工信息获取
  1746. * @return void
  1747. * @throws \think\db\exception\DataNotFoundException
  1748. * @throws \think\db\exception\ModelNotFoundException
  1749. * @throws \think\exception\DbException
  1750. */
  1751. public function EmployeeData()
  1752. {
  1753. if ($this->request->isGet() === false){
  1754. $this->error('请求错误');
  1755. }
  1756. $param = $this->request->param();
  1757. if (isset($param['code']) === false){
  1758. $this->error('参数错误');
  1759. }
  1760. $res = \db('人事_基本资料')
  1761. ->where('员工编号','like',$param['code'].'%')
  1762. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1763. ->select();
  1764. if (empty($res)){
  1765. $this->success('未找到该员工');
  1766. }
  1767. $this->success('成功',$res);
  1768. }
  1769. /**
  1770. * 换型清场添加
  1771. * @return void
  1772. * @throws \think\db\exception\BindParamException
  1773. * @throws \think\exception\PDOException
  1774. */
  1775. public function remodelDataAdd()
  1776. {
  1777. if (Request::instance()->isPost() === false){
  1778. $this->error('请求错误');
  1779. }
  1780. $param = Request::instance()->post();
  1781. if (empty($param)){
  1782. $this->error('参数错误');
  1783. }
  1784. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1785. $param['sys_id'] = '['.$param['机台编号'].']';
  1786. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1787. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1788. $param['UniqId'] = $lastId + 1;
  1789. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1790. $res = \db()->query($sql);
  1791. if ($res !== false){
  1792. $this->success('成功');
  1793. }else{
  1794. $this->error('失败');
  1795. }
  1796. }
  1797. /**
  1798. * 换型清场记录修改
  1799. * @return void
  1800. * @throws \think\Exception
  1801. * @throws \think\db\exception\BindParamException
  1802. * @throws \think\exception\PDOException
  1803. */
  1804. public function remodelDataEdit()
  1805. {
  1806. if (Request::instance()->isPost() === false){
  1807. $this->error('请求错误');
  1808. }
  1809. $param = Request::instance()->post();
  1810. if (empty($param)){
  1811. $this->error('参数错误');
  1812. }
  1813. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1814. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1815. $res = \db()->query($sql);
  1816. if ($res !== false){
  1817. $this->success('成功');
  1818. }else{
  1819. $this->error('失败');
  1820. }
  1821. }
  1822. /**
  1823. * 换型清场记录删除
  1824. * @return void
  1825. * @throws \think\Exception
  1826. * @throws \think\exception\PDOException
  1827. */
  1828. public function remodelDataDel()
  1829. {
  1830. if ($this->request->isGet() === false){
  1831. $this->error('请求错误');
  1832. }
  1833. $param = $this->request->param();
  1834. if (empty($param)){
  1835. $this->error('参数错误');
  1836. }
  1837. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1838. if ($res !== false){
  1839. $this->success('删除成功');
  1840. }else{
  1841. $this->error('删除失败');
  1842. }
  1843. }
  1844. /**
  1845. * 印版领用记录添加
  1846. * @return void
  1847. * @throws \think\db\exception\BindParamException
  1848. * @throws \think\exception\PDOException
  1849. */
  1850. public function PrintDetailAdd()
  1851. {
  1852. if (Request::instance()->isPost() === false){
  1853. $this->error('请求错误');
  1854. }
  1855. $param = Request::instance()->post();
  1856. if (empty($param)){
  1857. $this->error('参数错误');
  1858. }
  1859. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1860. foreach ($param as $key=>$value){
  1861. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1862. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1863. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1864. $param[$key]['UniqID'] = $lastId + $key +1;
  1865. }
  1866. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1867. $res = \db()->query($sql);
  1868. if ($res !== false){
  1869. $this->success('添加成功');
  1870. }else{
  1871. $this->error('添加失败');
  1872. }
  1873. }
  1874. /**
  1875. * 印版领用记录退还
  1876. * @return void
  1877. * @throws \think\Exception
  1878. * @throws \think\db\exception\BindParamException
  1879. * @throws \think\exception\PDOException
  1880. */
  1881. public function PrintDetailEdit()
  1882. {
  1883. if ($this->request->isGet() === false){
  1884. $this->error('请求错误');
  1885. }
  1886. $param = $this->request->param();
  1887. if (empty($param)){
  1888. $this->error('参数错误');
  1889. }
  1890. $idList = explode(',',$param['id']);
  1891. $i = 0;
  1892. foreach ($idList as $key=>$value){
  1893. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  1894. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  1895. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  1896. $res = \db()->query($sql);
  1897. if ($res === false){
  1898. $i++;
  1899. }
  1900. }
  1901. if ($i !== 0){
  1902. $this->error('退还失败');
  1903. }else{
  1904. $this->success('退还成功');
  1905. }
  1906. }
  1907. /**
  1908. * 当班产量明细修改
  1909. * @return void
  1910. * @throws \think\Exception
  1911. * @throws \think\db\exception\BindParamException
  1912. * @throws \think\exception\PDOException
  1913. */
  1914. public function chanliangEdit()
  1915. {
  1916. if (Request::instance()->isPost() === false){
  1917. $this->error('请求错误');
  1918. }
  1919. $param = Request::instance()->post();
  1920. if (empty($param['UniqId'])){
  1921. $this->error('参数错误');
  1922. }
  1923. $param['sczl_打样工时'] = $param['sczl_打样总工时'];
  1924. $param['sczl_装版工时'] = $param['sczl_装版总工时'];
  1925. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1926. $data = $param;
  1927. unset($data['UniqId']);
  1928. unset($data['sczl_rq']);
  1929. $sql = \db('设备_产量计酬')
  1930. ->where('UniqId',$param['UniqId'])
  1931. ->fetchSql(true)
  1932. ->update($data);
  1933. $res = \db()->query($sql);
  1934. if ($res !== false){
  1935. $this->success('修改成功');
  1936. }else {
  1937. $this->error('修改失败');
  1938. }
  1939. }
  1940. /**
  1941. * 获取当日上报产量详细数据
  1942. * @return void
  1943. * @throws \think\db\exception\DataNotFoundException
  1944. * @throws \think\db\exception\ModelNotFoundException
  1945. * @throws \think\exception\DbException
  1946. */
  1947. public function MachineChanliangDetail()
  1948. {
  1949. if ($this->request->isGet() === false){
  1950. $this->error('请求错误');
  1951. }
  1952. $param = $this->request->param();
  1953. if (empty($param['UniqId'])){
  1954. $this->error('参数错误');
  1955. }
  1956. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,rtrim(sczl_ls) as 联数,
  1957. 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 来料异常,
  1958. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  1959. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  1960. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
  1961. 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,
  1962. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  1963. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  1964. if (empty($list)){
  1965. $this->success('未找到产量详情信息');
  1966. }
  1967. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  1968. $list['印件名称'] = $productName['cpmc'];
  1969. if (!empty($productName['成品名称'])){
  1970. $list['cpmc'] = $productName['成品名称'];
  1971. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  1972. $list['cpmc'] = $productName['cpmc'];
  1973. }else{
  1974. $list['cpmc'] = '';
  1975. }
  1976. for ($i=1;$i<11;$i++){
  1977. if (isset($list['sczl_bh'.$i])){
  1978. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  1979. if (isset($name['name'])){
  1980. $list['组员'.$i] = [
  1981. '编号' => $list['sczl_bh'.$i],
  1982. '姓名' => $name['name'],
  1983. '比例' => (float)$list['sczl_rate'.$i]
  1984. ];
  1985. }
  1986. }
  1987. if (empty($list['sczl_bh'.$i])){
  1988. $list['组员'.$i] = [
  1989. '编号' => '',
  1990. '姓名' => '',
  1991. '比例' => ''
  1992. ];
  1993. }
  1994. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  1995. }
  1996. $list['拉料'] = [
  1997. '编号' => $list['sczl_bh98'],
  1998. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  1999. ];
  2000. unset($list['sczl_bh98']);
  2001. $this->success('成功',$list);
  2002. }
  2003. /**
  2004. * 当日上报产量详细数据修改
  2005. * @return void
  2006. * @throws \think\Exception
  2007. * @throws \think\db\exception\BindParamException
  2008. * @throws \think\exception\PDOException
  2009. */
  2010. public function MachineChanliangDetailEdit()
  2011. {
  2012. if (Request::instance()->isPost() === false){
  2013. $this->error('请求错误');
  2014. }
  2015. $param = Request::instance()->post();
  2016. if (empty($param['UniqId'])){
  2017. $this->error('参数错误');
  2018. }
  2019. $param['sczl_type'] = $param['sczl_gxmc'];
  2020. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2021. $UnidId = $param['UniqId'];
  2022. unset($param['UniqId']);
  2023. unset($param['sczl_rq']);
  2024. $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
  2025. $res = \db()->query($sql);
  2026. if ($res !== false){
  2027. $this->success('修改成功');
  2028. }else{
  2029. $this->error('修改失败');
  2030. }
  2031. }
  2032. /**
  2033. * 产量上报数据删除
  2034. * @return void
  2035. * @throws \think\Exception
  2036. * @throws \think\exception\PDOException
  2037. */
  2038. public function ChanliangDel()
  2039. {
  2040. if ($this->request->isGet() === false){
  2041. $this->error('请求错误');
  2042. }
  2043. $param = $this->request->param();
  2044. if (empty($param['UniqId'])){
  2045. $this->error('参数错误');
  2046. }
  2047. $idList = explode(',',$param['UniqId']);
  2048. foreach ($idList as $key=>$value){
  2049. $res = \db('设备_产量计酬')
  2050. ->where('UniqId',$value)
  2051. ->delete();
  2052. }
  2053. if ($res !== false){
  2054. $this->success('删除成功');
  2055. }else{
  2056. $this->error('删除失败');
  2057. }
  2058. }
  2059. /**
  2060. * 日产量上报添加
  2061. * @return void
  2062. * @throws \think\db\exception\BindParamException
  2063. * @throws \think\exception\PDOException
  2064. */
  2065. public function ChanliangAdd()
  2066. {
  2067. if (Request::instance()->isPost() === false){
  2068. $this->error('请求错误');
  2069. }
  2070. $params = Request::instance()->post();
  2071. if (empty($params['sczl_gdbh'])){
  2072. $this->error('参数错误');
  2073. }
  2074. $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2075. $params['sczl_type'] = $params['sczl_gxmc'];
  2076. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2077. $params['sczl_废品率系数'] = 0;
  2078. $params['sys_rq'] = date('Y-m-d H:i:s',time());
  2079. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  2080. $params['UniqId'] = $lastId + 1;
  2081. $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
  2082. $res = \db()->query($sql);
  2083. if ($res !== false){
  2084. $this->success('成功');
  2085. }else{
  2086. $this->error('失败');
  2087. }
  2088. }
  2089. /**
  2090. * 日产量上报添加获取工单信息
  2091. * @return void
  2092. * @throws \think\db\exception\DataNotFoundException
  2093. * @throws \think\db\exception\ModelNotFoundException
  2094. * @throws \think\exception\DbException
  2095. */
  2096. public function ChanliangWorkorder()
  2097. {
  2098. if ($this->request->isGet() === false)
  2099. {
  2100. $this->error('请求错误');
  2101. }
  2102. $param = $this->request->param();
  2103. if (empty($param)){
  2104. $this->error('参数错误');
  2105. }
  2106. // $where = [
  2107. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2108. // ];
  2109. // if (!empty($param['machine'])){
  2110. // $where = [
  2111. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2112. // ];
  2113. // }
  2114. if (!empty($param['search'])){
  2115. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2116. }
  2117. $list = \db('工单_基本资料')
  2118. ->alias('a')
  2119. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2120. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2121. ->where($where)
  2122. ->select();
  2123. if (empty($list)){
  2124. $this->success('未找到相关工单');
  2125. }else{
  2126. $this->success('成功',$list);
  2127. }
  2128. }
  2129. /**
  2130. * 日产量上报工单印件资料
  2131. * @return void
  2132. * @throws \think\db\exception\DataNotFoundException
  2133. * @throws \think\db\exception\ModelNotFoundException
  2134. * @throws \think\exception\DbException
  2135. */
  2136. public function ChanliangPrintDetail()
  2137. {
  2138. if ($this->request->isGet() === false){
  2139. $this->error('请求错误');
  2140. }
  2141. $param = $this->request->param();
  2142. if (empty($param['gdbh'])){
  2143. $this->error('参数错误');
  2144. }
  2145. $where = [
  2146. 'Yj_Gdbh' => $param['gdbh']
  2147. ];
  2148. $list = \db('工单_印件资料')
  2149. ->where($where)
  2150. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2151. ->select();
  2152. if (empty($list)){
  2153. $this->success('未找到印件资料');
  2154. }else{
  2155. $this->success('成功',$list);
  2156. }
  2157. }
  2158. /**
  2159. * 日产量上报工艺资料获取
  2160. * @return void
  2161. * @throws \think\db\exception\DataNotFoundException
  2162. * @throws \think\db\exception\ModelNotFoundException
  2163. * @throws \think\exception\DbException
  2164. */
  2165. public function ChanliangProcessDetail()
  2166. {
  2167. if ($this->request->isGet() === false){
  2168. $this->error('请求错误');
  2169. }
  2170. $param = $this->request->param();
  2171. if (empty($param['gdbh'])){
  2172. $this->error('参数错误');
  2173. }
  2174. // $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
  2175. $list = \db('工单_工艺资料')
  2176. ->where('Gy0_gdbh',$param['gdbh'])
  2177. ->where('Gy0_yjno',$param['yjno'])
  2178. // ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
  2179. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2180. ->select();
  2181. if (empty($list)){
  2182. $this->success('未获取工序');
  2183. }
  2184. // $time = \db('设备_产量计酬')
  2185. // ->where('sczl_gdbh',$param['gdbh'])
  2186. // ->where('sczl_yjno',$param['yjno'])
  2187. // ->where('sczl_jtbh','like','%'.$param['machine'].'%')
  2188. // ->order('UniqId desc')
  2189. // ->value('sczl_sj2');
  2190. // $newTime = date('Y-m-d H:i:s');
  2191. // if ($newTime > date('Y-m-d 08:30:00') && $newTime < date('Y-m-d 20:30:00') && $time < date('Y-m-d 08:30:00')){
  2192. // $time = date('Y-m-d 08:30:00');
  2193. // }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
  2194. // $time = date('Y-m-d 20:30:00');
  2195. // }
  2196. foreach ($list as $key=>$value){
  2197. if ((int)$value['gxh'] < 10){
  2198. $value['gxh'] = '0'.$value['gxh'];
  2199. }
  2200. if (empty($value['add_gxmc'])){
  2201. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2202. }else{
  2203. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2204. }
  2205. unset( $list[$key]['add_gxmc']);
  2206. // $list[$key]['time'] = $time;
  2207. }
  2208. // $list['sys_bh'] = $sys_bh;
  2209. $this->success('成功',$list);
  2210. }
  2211. /**
  2212. * 工价系数修改
  2213. * @return void
  2214. * @throws \think\Exception
  2215. * @throws \think\db\exception\BindParamException
  2216. * @throws \think\exception\PDOException
  2217. */
  2218. public function CoefficientEdit()
  2219. {
  2220. if (Request::instance()->isPost() === false){
  2221. $this->error('请求错误');
  2222. }
  2223. $params = Request::instance()->post();
  2224. if (empty($params['id'])){
  2225. $this->error('参数错误');
  2226. }
  2227. $idList = explode(',',$params['id']);
  2228. $i=0;
  2229. foreach ($idList as $key=>$value){
  2230. $sql = \db('设备_产量计酬')
  2231. ->where('UniqId',$value)
  2232. ->fetchSql(true)
  2233. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2234. $res = \db()->query($sql);
  2235. if ($res === false){
  2236. $i++;
  2237. }
  2238. }
  2239. if ($i!==0){
  2240. $this->error('修改失败');
  2241. }else{
  2242. $this->success('修改成功');
  2243. }
  2244. }
  2245. /**
  2246. * 色度系数修改
  2247. * @return void
  2248. * @throws \think\Exception
  2249. * @throws \think\db\exception\BindParamException
  2250. * @throws \think\exception\PDOException
  2251. */
  2252. public function ChromaDataEdit()
  2253. {
  2254. if (Request::instance()->isPost() === false){
  2255. $this->error('请求错误');
  2256. }
  2257. $params = Request::instance()->post();
  2258. if (empty($params['id'])){
  2259. $this->error('参数错误');
  2260. }
  2261. $idList = explode(',',$params['id']);
  2262. $i=0;
  2263. foreach ($idList as $key=>$value){
  2264. $sql = \db('设备_产量计酬')
  2265. ->where('UniqId',$value)
  2266. ->fetchSql(true)
  2267. ->update(['sczl_ms'=>$params['ms']]);
  2268. $res = \db()->query($sql);
  2269. if ($res === false){
  2270. $i++;
  2271. }
  2272. }
  2273. if ($i!==0){
  2274. $this->error('修改失败');
  2275. }else{
  2276. $this->success('修改成功');
  2277. }
  2278. }
  2279. /**
  2280. * 凹印版距修改
  2281. * @return void
  2282. * @throws \think\Exception
  2283. * @throws \think\db\exception\BindParamException
  2284. * @throws \think\exception\PDOException
  2285. */
  2286. public function PrintingModeDataEdit()
  2287. {
  2288. if (Request::instance()->isPost() === false){
  2289. $this->error('请求错误');
  2290. }
  2291. $params = Request::instance()->post();
  2292. if (empty($params['id'])){
  2293. $this->error('参数错误');
  2294. }
  2295. $idList = explode(',',$params['id']);
  2296. //获取工单印件工序
  2297. $orderList = \db('设备_产量计酬')
  2298. ->where('UniqId',$idList[0])
  2299. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
  2300. ->find();
  2301. //修改工艺资料
  2302. $sql = \db('工单_工艺资料')
  2303. ->where([
  2304. 'Gy0_gdbh'=>$orderList['工单编号'],
  2305. 'Gy0_yjno'=>$orderList['印件号'],
  2306. 'Gy0_gxh'=>$orderList['工序号']
  2307. ])
  2308. ->fetchSql(true)
  2309. ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
  2310. $res = \db()->query($sql);
  2311. if ($res === false){
  2312. $this->error('修改失败');
  2313. }else{
  2314. $this->success('修改成功');
  2315. }
  2316. }
  2317. /**
  2318. * 废品率系数批量修改
  2319. * @return void
  2320. * @throws \think\Exception
  2321. * @throws \think\db\exception\BindParamException
  2322. * @throws \think\exception\PDOException
  2323. */
  2324. public function RejectionEdit()
  2325. {
  2326. if (Request::instance()->isPost() === false){
  2327. $this->error('请求错误');
  2328. }
  2329. $params = Request::instance()->post();
  2330. if (empty($params['id'])){
  2331. $this->error('参数错误');
  2332. }
  2333. $idList = explode(',',$params['id']);
  2334. $i=0;
  2335. foreach ($idList as $key=>$value){
  2336. $sql = \db('设备_产量计酬')
  2337. ->where('UniqId',$value)
  2338. ->fetchSql(true)
  2339. ->update(['sczl_废品率系数'=>$params['rejection']]);
  2340. $res = \db()->query($sql);
  2341. if ($res === false){
  2342. $i++;
  2343. }
  2344. }
  2345. if ($i!==0){
  2346. $this->error('修改失败');
  2347. }else{
  2348. $this->success('修改成功');
  2349. }
  2350. }
  2351. /**
  2352. * 日产量上报班组信息批量修改
  2353. * @return void
  2354. * @throws \think\Exception
  2355. * @throws \think\db\exception\BindParamException
  2356. * @throws \think\db\exception\DataNotFoundException
  2357. * @throws \think\db\exception\ModelNotFoundException
  2358. * @throws \think\exception\DbException
  2359. * @throws \think\exception\PDOException
  2360. */
  2361. public function YieldTeamEdit()
  2362. {
  2363. if ($this->request->isGet() === false){
  2364. $this->error('请求错误');
  2365. }
  2366. $param = $this->request->param();
  2367. if (empty($param['Uniqid']) || empty($param['teamID'])){
  2368. $this->error('参数错误');
  2369. }
  2370. $idList = explode(',',$param['Uniqid']);
  2371. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  2372. $data = [];
  2373. for ($i=1;$i<11;$i++){
  2374. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  2375. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  2376. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  2377. }
  2378. $j = 0;
  2379. foreach ($idList as $key => $value){
  2380. $sql = \db('设备_产量计酬')
  2381. ->where('UniqId',$value)
  2382. ->fetchSql(true)
  2383. ->update($data);
  2384. $res = \db()->query($sql);
  2385. if ($res === false){
  2386. $j++;
  2387. }
  2388. }
  2389. if ($j === 0){
  2390. $this->success('修改成功');
  2391. }else{
  2392. $this->error('修改失败');
  2393. }
  2394. }
  2395. /**
  2396. * 检品机日产量上报数据修改
  2397. * @return void
  2398. * @throws \think\Exception
  2399. * @throws \think\db\exception\BindParamException
  2400. * @throws \think\exception\PDOException
  2401. */
  2402. public function JpChanliangEdit()
  2403. {
  2404. if (Request::instance()->isPost() == false){
  2405. $this->error('非法请求');
  2406. }
  2407. $params = Request::instance()->post();
  2408. if (empty($params['UniqId'])){
  2409. $this->error('参数错误');
  2410. }
  2411. $params['mod_rq'] = date('Y-m-d H:i:s');
  2412. $data = $params;
  2413. unset($data['UniqId']);
  2414. unset($data['sczl_rq']);
  2415. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  2416. $res = \db()->query($sql);
  2417. if ($res === false){
  2418. $this->error('修改失败');
  2419. }else{
  2420. $this->success('成功');
  2421. }
  2422. }
  2423. /**
  2424. * 检品机日产量上报数据列表
  2425. * @return void
  2426. * @throws \think\db\exception\DataNotFoundException
  2427. * @throws \think\db\exception\ModelNotFoundException
  2428. * @throws \think\exception\DbException
  2429. */
  2430. public function JPmachineDetail()
  2431. {
  2432. if ($this->request->isGet() === false){
  2433. $this->error('请求错误');
  2434. }
  2435. $machine = input('machine');
  2436. $date = input('date');
  2437. $where = [
  2438. 'sczl_jtbh' => $machine,
  2439. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  2440. ];
  2441. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
  2442. rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  2443. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2444. 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,
  2445. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  2446. //机台信息
  2447. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  2448. //组员信息
  2449. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  2450. $totalA = \db('设备_产量计酬')
  2451. ->where($where)
  2452. ->where('sczl_bzdh','like','A%')
  2453. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
  2454. ->group('检验类型')
  2455. ->select();
  2456. $totalB = \db('设备_产量计酬')
  2457. ->where($where)
  2458. ->where('sczl_bzdh','like','B%')
  2459. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数')
  2460. ->group('检验类型')
  2461. ->select();
  2462. if (empty($list)){
  2463. $this->success('',[]);
  2464. }
  2465. foreach ($list as $key=>$value){
  2466. //产品名称
  2467. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2468. if (!empty($productName)){
  2469. if (!empty($productName['成品名称'])){
  2470. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  2471. $list[$key]['cpmc'] = $productName['成品名称'];
  2472. }else{
  2473. $list[$key]['产品名称'] = $value['工单编号'];
  2474. $list[$key]['cpmc'] = '';
  2475. }
  2476. }else{
  2477. $list[$key]['产品名称'] = $value['工单编号'];
  2478. $list[$key]['cpmc'] = '';
  2479. }
  2480. if (empty($value['定额代号'])){
  2481. $list[$key]['千件工价'] = '';
  2482. $list[$key]['日定额'] = '';
  2483. $list[$key]['补产标准'] = '';
  2484. }else{
  2485. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  2486. $list[$key]['千件工价'] = $row['千件工价'];
  2487. $list[$key]['日定额'] = $row['日定额'];
  2488. $list[$key]['补产标准'] = $row['补产标准'];
  2489. }
  2490. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  2491. for ($i=1;$i<11;$i++){
  2492. if (isset($value['sczl_bh'.$i])){
  2493. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2494. if (isset($name['name'])){
  2495. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  2496. $list[$key]['sczl_name'.$i] = $name['name'];
  2497. }else{
  2498. $list[$key]['sczl_name'.$i] = '';
  2499. }
  2500. }
  2501. }
  2502. }
  2503. $list['totalA'] = $totalA;
  2504. $list['totalB'] = $totalB;
  2505. $this->success('成功',$list);
  2506. }
  2507. //设备运行跟踪月度数据导出
  2508. // public function MouthDataOutput()
  2509. // {
  2510. // if ($this->request->isGet() === false){
  2511. // $this->error('参数错误');
  2512. // }
  2513. // $param = $this->request->param();
  2514. // if (empty($param)){
  2515. // $this->error('参数错误');
  2516. // }
  2517. // $filed = "工单编号,产品名称,流程单号,印件号,工序号,机台编号,日期,工序产量,工序名称,机长工号,机长名称,组员工号1,组员姓名1,";
  2518. // }
  2519. }