Facility.php 89 KB

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