Facility.php 106 KB

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