Facility.php 101 KB

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