Facility.php 91 KB

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