Facility.php 106 KB

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