Facility.php 88 KB

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