Facility.php 90 KB

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