Facility.php 94 KB

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