Facility.php 101 KB

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