Facility.php 88 KB

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