Facility.php 102 KB

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