Facility.php 89 KB

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