YxFaility.php 110 KB

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