Facility.php 74 KB

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