Facility.php 87 KB

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