Facility.php 88 KB

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