Facility.php 89 KB

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