Facility.php 94 KB

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