Facility.php 124 KB

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