Facility.php 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  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_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';
  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. unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
  487. }
  488. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  489. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  490. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  491. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  492. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  493. $total[0]['版数'] = count($list);
  494. $list['total'] = $total[0];
  495. $this->success('成功',$list);
  496. }
  497. /**
  498. * 检验记录
  499. * @ApiMethod (GET)
  500. * @param string $machine 机台编号
  501. * @param string $workOrder 工单编号
  502. * @param string $team 班次
  503. * @return void
  504. * @throws \think\db\exception\DataNotFoundException
  505. * @throws \think\db\exception\ModelNotFoundException
  506. * @throws \think\exception\DbException
  507. */
  508. public function InspectionRecord()
  509. {
  510. if ($this->request->isGet() === false){
  511. $this->error('请求失败');
  512. }
  513. $machine = input('machine');
  514. $workOrder = input('Gd_gdbh');
  515. $team = input('team');
  516. if (empty($machine) || empty($workOrder) || empty($team)){
  517. $this->success('');
  518. }
  519. $where = [
  520. '设备编号' => $machine,
  521. '工单编号' => $workOrder,
  522. '班组编号' => $team,
  523. '类别' => ['in',['IPQC检验','机台检验']],
  524. ];
  525. //检验项目筛选
  526. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  527. //检验时间
  528. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  529. foreach ($InspectionTime as $k=>$v){
  530. $InspectionTime[$k] = date('H:i',strtotime($v));
  531. }
  532. //检测记录详情
  533. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  534. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  535. $data = [];
  536. //检测数据
  537. foreach ($item as $key=>$value){
  538. $SubmissionTime = \db('制程检验_记录')->where($where)
  539. ->where('检验项目',$value)
  540. ->where('检验结果','合格')
  541. ->field('rtrim(提交时间) as 提交时间')
  542. ->select();
  543. $time = [];
  544. foreach ($SubmissionTime as $k=>$v){
  545. $time[$k] = date('H:i',strtotime($v['提交时间']));
  546. }
  547. $data[$key] = [
  548. '工单编号' => $nameDetail['工单编号'],
  549. '印件号' => $nameDetail['印件号'],
  550. '工序名称' => $nameDetail['工序名称'],
  551. '检验项目' => $value,
  552. 'inspectresult' => implode(',',$time),
  553. ];
  554. }
  555. $data['inspectiontime'] = $InspectionTime;
  556. $this->success('成功',$data);
  557. }
  558. /**
  559. * 班组维护->班组添加
  560. * @ApiMethod (GET)
  561. * @param void
  562. * @return void
  563. * @throws \think\db\exception\DataNotFoundException
  564. * @throws \think\db\exception\ModelNotFoundException
  565. * @throws \think\exception\DbException
  566. */
  567. public function MachineTeamAdd()
  568. {
  569. if (Request::instance()->isPost() === false ){
  570. $this->error('请求错误');
  571. }
  572. $param = Request::instance()->post();
  573. if (empty($param)){
  574. $this->error('参数错误');
  575. }
  576. $lastId = \db('设备_班组资料')
  577. ->order('UniqId desc')
  578. ->value('UniqId');
  579. if ($lastId<100000){
  580. $lastId = 1000000;
  581. }
  582. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  583. $param['UniqId'] = $lastId + 1;
  584. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  585. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  586. $res = \db()->query($sql);
  587. if ($res !== false){
  588. $this->success('成功');
  589. }else{
  590. $this->error('失败');
  591. }
  592. }
  593. /**
  594. * 机台编号列表
  595. * @ApiMethod (GET)
  596. * @return void
  597. */
  598. public function MachineList()
  599. {
  600. if ($this->request->isGet() === false){
  601. $this->error('请求错误');
  602. }
  603. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  604. if (empty($list)){
  605. $this->success('未找到机台编号');
  606. }
  607. $data = [];
  608. foreach ($list as $key=>$value){
  609. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  610. }
  611. $this->success('成功',$data);
  612. }
  613. /**
  614. * 删除班组信息
  615. * @ApiMethod (GET)
  616. * @param void
  617. * @return void
  618. * @throws \think\Exception
  619. * @throws \think\exception\PDOException
  620. */
  621. public function teamDel()
  622. {
  623. if (Request::instance()->isPost() === false){
  624. $this->error('请求错误');
  625. }
  626. $param = Request::instance()->post();
  627. if (empty($param)){
  628. $this->error('参数错误');
  629. }
  630. $res = \db('设备_班组资料')
  631. ->where('UniqId',$param['UniqId'])
  632. ->delete();
  633. if ($res !== false){
  634. $this->success('成功');
  635. }else{
  636. $this->error('失败');
  637. }
  638. }
  639. /**
  640. * 管理人员现场巡检记录->展示
  641. * @ApiMethod (GET)
  642. * @param void
  643. * @return void
  644. * @throws \think\db\exception\DataNotFoundException
  645. * @throws \think\db\exception\ModelNotFoundException
  646. * @throws \think\exception\DbException
  647. */
  648. public function FieldInspectionRecord()
  649. {
  650. if ($this->request->isGet() === false){
  651. $this->error('请求错误');
  652. }
  653. $param = $this->request->param();
  654. if (empty($param)){
  655. $this->error('参数错误');
  656. }
  657. $date = date('Y-m-d H:i:s',time());
  658. if (empty($param['start'])){
  659. $startTime = date('Y-m-d 08:30:00',time());
  660. }else{
  661. $startTime = $param['start'];
  662. }
  663. if ($date<$startTime){
  664. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  665. }
  666. $where = [
  667. '工单编号' => $param['workOrder'],
  668. '开工时间' => $startTime,
  669. '类别' => '现场巡查记录',
  670. '班组编号' => $param['team']
  671. ];
  672. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  673. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  674. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  675. $list = \db('制程检验_记录')->where($where)
  676. ->field($filed)
  677. ->select();
  678. if (empty($list)){
  679. $this->success('',[]);
  680. }
  681. foreach ($list as $key=>$value){
  682. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  683. $list[$key]['归属时段'] = $value['开工时间'];
  684. $list[$key]['分钟差数'] = $number;
  685. if ($number != 0){
  686. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  687. }
  688. }
  689. $this->success('成功',$list);
  690. }
  691. /**
  692. * 管理人员现场巡检记录->添加
  693. * @ApiMethod (POST)
  694. * @param void
  695. * @return void
  696. */
  697. public function FieldInspectionRecordAdd()
  698. {
  699. if (Request::instance()->isPost() === false){
  700. $this->error('请求错误');
  701. }
  702. $param = Request::instance()->post();
  703. if (empty($param)){
  704. $this->error('参数错误');
  705. }
  706. if ($param['processCode']<10){
  707. $param['processCode'] = '0'.$param['processCode'];
  708. }
  709. $date = date('Y-m-d H:i:s',time());
  710. $startTime = date('Y-m-d 08:30:00',time());
  711. if ($date<$startTime){
  712. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  713. }
  714. $data = [
  715. '类别' => $param['category'],
  716. '工单编号' => $param['workOrder'],
  717. '印件号' => $param['printCode'],
  718. '工序名称' => $param['processCode'].'-'.$param['process'],
  719. '流程单号' => $param['flowCode'],
  720. '设备编号' => $param['machine'],
  721. '班组编号' => $param['team'],
  722. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  723. '相关标准' => '',
  724. '量测仪器' => '',
  725. '检验结果' => '',
  726. '检验备注' => $param['remark'],
  727. '提交时间' => date('Y-m-d H:i:s',time()),
  728. '开工时间' => $startTime,
  729. 'sys_id' => '',
  730. 'sys_rq' => date('Y-m-d H:i:s',time()),
  731. 'mod_rq' => '0000-00-00 00:00:00',
  732. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  733. ];
  734. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  735. $res = Db::query($sql);
  736. if ($res !== false){
  737. $this->success('成功');
  738. }else{
  739. $this->error('失败');
  740. }
  741. }
  742. /**
  743. * 设备点检->左侧菜单栏
  744. * @ApiMethod (GET)
  745. * @param void
  746. * @return void
  747. */
  748. public function SpotCheckItem()
  749. {
  750. if ($this->request->isGet() === false){
  751. $this->error('请求错误');
  752. }
  753. $param = $this->request->param();
  754. if (empty($param)){
  755. $this->error('参数错误');
  756. }
  757. $list = \db('设备_点检项目')
  758. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  759. ->distinct(true)
  760. ->column('部件名称','部件编号');
  761. if (empty($list)){
  762. $this->success('');
  763. }
  764. $this->success('成功',$list);
  765. }
  766. /**
  767. * 设备点检->检测项目
  768. * @ApiMethod (GET)
  769. * @param void
  770. * @return void
  771. * @throws \think\db\exception\DataNotFoundException
  772. * @throws \think\db\exception\ModelNotFoundException
  773. * @throws \think\exception\DbException
  774. */
  775. public function InspectionItem()
  776. {
  777. if ($this->request->isGet() === false){
  778. $this->error('请求错误');
  779. }
  780. $param = $this->request->param();
  781. if (empty($param)){
  782. $this->error('参数错误');
  783. }
  784. $list = \db('设备_点检项目')
  785. ->where('部件名称',$param['unitName'])
  786. ->where('适用机型','like','%'.$param['machine'].'#%')
  787. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  788. ->select();
  789. if (empty($list)){
  790. $this->success('未找到检测项目');
  791. }
  792. $this->success('成功',$list);
  793. }
  794. /**
  795. * 设备点检->检测记录添加
  796. * @ApiMethod (POST)
  797. * @param void
  798. * @return void
  799. * @throws \think\db\exception\DataNotFoundException
  800. * @throws \think\db\exception\ModelNotFoundException
  801. * @throws \think\exception\DbException
  802. */
  803. public function InspectionItemAdd()
  804. {
  805. if (Request::instance()->isPost() === false){
  806. $this->error('请求错误');
  807. }
  808. $param = Request::instance()->post();
  809. if (empty($param)){
  810. $this->error('参数错误');
  811. }
  812. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  813. if ((int)$lastNumber>10000000){
  814. $lastId = $lastNumber;
  815. }else{
  816. $lastId = 10000000;
  817. }
  818. $row = [];
  819. foreach ($param as $key=>$value){
  820. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  821. $row[$key] = [
  822. '日期' => date('Y-m-d 00:00:00',time()),
  823. '班组编号' => $value['team'],
  824. '点检设备' => $value['machine'],
  825. '部件编号' => $unitCode['部件编号'],
  826. '部件名称' => $value['unitName'],
  827. '检验项目' => $value['itemName'],
  828. '判定标准' => $value['standard'],
  829. '点检方法' => $value['method'],
  830. '点检结果' => $value['status'],
  831. '备注说明' => $value['remark'],
  832. 'Sys_id' =>'',
  833. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  834. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  835. 'Uniqid' => $lastId+$key+1
  836. ];
  837. }
  838. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  839. $res = Db::query($sql);
  840. if ($res !== false){
  841. $this->success('成功');
  842. }else{
  843. $this->error('失败');
  844. }
  845. }
  846. /**
  847. * 机台印版领用->左侧菜单
  848. * @ApiMethod (GET)
  849. * @param void
  850. * @return void
  851. */
  852. public function PrintGetTab()
  853. {
  854. if ($this->request->isGet() === false){
  855. $this->error('请求错误');
  856. }
  857. $param = $this->request->param();
  858. if (empty($param)){
  859. $this->error('参数错误');
  860. }
  861. $productCode = $param['productCode'];
  862. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  863. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  864. WHERE a.YB_Cpdh = '{$productCode}'";
  865. $res = Db::query($sql);
  866. if (empty($res)){
  867. $this->success('');
  868. }
  869. $this->success('成功',$res);
  870. }
  871. /**
  872. * 机台印版领用记录->数据详情
  873. * @ApiMethod (GET)
  874. * @param void
  875. * @return void
  876. */
  877. public function PrintDetail()
  878. {
  879. if ($this->request->isGet() === false){
  880. $this->error('请求失败');
  881. }
  882. $param = $this->request->param();
  883. if (empty($param)){
  884. $this->error('参数错误');
  885. }
  886. $productCode = $param['productCode'];
  887. $code = $param['code'].'%';
  888. $workOrder = $param['workOrder'];
  889. $sql = "SELECT
  890. RTRIM(a.`存货编码`) as `存货编码`,
  891. RTRIM(c.`物料名称`) as `存货名称`,
  892. RTRIM(b.`印版名称`) as `印版名称`,
  893. RTRIM(b.`供方批号`) as `供方批号`,
  894. RTRIM(b.`制造日期`) as `制造日期`,
  895. SUM(d.`Yb_印数`) as `印数`,
  896. RTRIM(e.`名称`) as `印版类别`,
  897. SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
  898. RTRIM(f.`Gd_客户名称`) as `客户名称`,
  899. RTRIM(a.YB_Cpdh) as `产品编号`,
  900. RTRIM(f.Gd_cpmc) as `产品名称`,
  901. RTRIM(d.UniqID) as UniqId
  902. FROM `产品_印版资料` as a
  903. LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
  904. JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
  905. LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
  906. JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
  907. JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
  908. WHERE a.YB_Cpdh = '{$productCode}'
  909. AND a.`存货编码` LIKE '{$code}'
  910. AND f.Gd_gdbh = '{$workOrder}'
  911. AND b.`报废日期` = '1900-01-01 00:00:00'
  912. GROUP BY b.`供方批号`
  913. ORDER BY a.`存货编码`";
  914. $list = Db::query($sql);
  915. if (empty($list)){
  916. $this->success('');
  917. }
  918. $this->success('成功',$list);
  919. }
  920. /**
  921. * 换型清场->左侧菜单栏
  922. * @ApiMethod (GET)
  923. * @param void
  924. * @return void
  925. */
  926. public function remodelGetTab()
  927. {
  928. if ($this->request->isGet() === false){
  929. $this->error('请求错误');
  930. }
  931. $date = date('Y-m-d 00:00:00',time()-3456000);
  932. $nowTime = date('Y-m-d H:i:s',time());
  933. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  934. if (empty($list)){
  935. $this->error('失败');
  936. }
  937. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  938. FROM `设备_基本资料` as a
  939. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  940. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  941. $res = Db::query($sql);
  942. $data = $result = [];
  943. foreach ($list as $key=>$value){
  944. $data[$value] = $result[$value]= $time = [];
  945. foreach ($res as $k=>$v){
  946. if ($value === $v['设备编号']){
  947. $row = [
  948. '日期' => $v['日期'],
  949. 'id' => $v['UniqId']
  950. ];
  951. array_push($data[$value],$row);
  952. }
  953. }
  954. foreach ($data[$value] as $m=>$n){
  955. $time[$m] = $n['日期'];
  956. }
  957. $time = array_values(array_unique($time));
  958. foreach ($time as $kk=>$vv){
  959. $i=1;
  960. foreach ($data[$value] as $kkk=>$vvv){
  961. if ($kkk>=$kk && $vv === $vvv['日期']){
  962. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  963. $i++;
  964. }
  965. }
  966. }
  967. }
  968. $this->success('成功',$result);
  969. }
  970. /**
  971. * 换型清场->详情
  972. * @return void
  973. * @throws \think\db\exception\DataNotFoundException
  974. * @throws \think\db\exception\ModelNotFoundException
  975. * @throws \think\exception\DbException
  976. */
  977. public function RemodelDetail()
  978. {
  979. if ($this->request->isGet() === false){
  980. $this->error('请求错误');
  981. }
  982. $param = $this->request->param();
  983. if (empty($param)){
  984. $this->error('参数错误');
  985. }
  986. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  987. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  988. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  989. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  990. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  991. if (empty($list)){
  992. $this->success('未找到该条清场记录');
  993. }
  994. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  995. $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  996. // if ()
  997. $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  998. $this->success('成功',$list);
  999. }
  1000. /**
  1001. * 换型清场->当前设备清场记录
  1002. * @ApiMethod (GET)
  1003. * @param void
  1004. * @return void
  1005. * @throws \think\db\exception\DataNotFoundException
  1006. * @throws \think\db\exception\ModelNotFoundException
  1007. * @throws \think\exception\DbException
  1008. */
  1009. public function ModelChangeRecord()
  1010. {
  1011. if ($this->request->isGet() === false){
  1012. $this->error('请求错误');
  1013. }
  1014. $param = $this->request->param();
  1015. if (empty($param)){
  1016. $this->error('参数错误');
  1017. }
  1018. $date = date('Y-m-d 00:00:00',time()-3888000);
  1019. $nowTime = date('Y-m-d H:i:s',time());
  1020. $where = [
  1021. '日期' =>['between',[$date,$nowTime]],
  1022. '机台编号' => $param['machine'],
  1023. '工单编号A' => ['<>',''],
  1024. '工单编号B' => ['<>',''],
  1025. ];
  1026. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1027. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1028. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1029. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1030. $list = \db('制程_换型清场')
  1031. ->where($where)
  1032. ->field($field)
  1033. ->select();
  1034. if (empty($list)){
  1035. $this->success('未找到换型记录');
  1036. }
  1037. foreach ($list as $key=>$value){
  1038. $list[$key]['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  1039. $list[$key]['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  1040. }
  1041. $this->success('成功',$list);
  1042. }
  1043. /**
  1044. * 车间机台状态列表展示
  1045. * @ApiMethod (GET)
  1046. * @param void
  1047. * @return void
  1048. * @throws \think\db\exception\BindParamException
  1049. * @throws \think\exception\PDOException
  1050. */
  1051. public function MachineDetailList()
  1052. {
  1053. if ($this->request->isGet() === false){
  1054. $this->error('请求错误');
  1055. }
  1056. $param = $this->request->param();
  1057. if (empty($param)){
  1058. $this->error('参数错误');
  1059. }
  1060. $workshop = $param['workshop'];
  1061. $sql = "SELECT
  1062. RTRIM( a.`设备编号` ) AS 设备编号,
  1063. RTRIM( a.`设备名称` ) AS 设备名称,
  1064. RTRIM( d.`当前状态` ) AS 状态
  1065. FROM
  1066. `设备_基本资料` AS a
  1067. JOIN (
  1068. SELECT
  1069. b.`设备编号`,
  1070. b.`当前状态`,
  1071. b.`开工时间`
  1072. FROM
  1073. `设备_产量采集` AS b
  1074. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1075. AND b.`UniqId` = c.`UniqId`
  1076. ) AS d ON a.`设备编号` = d.`设备编号`
  1077. WHERE
  1078. a.`使用部门` = '{$workshop}'
  1079. GROUP BY
  1080. a.`设备编号`
  1081. ORDER BY
  1082. a.UniqId";
  1083. $list = \db()->query($sql);
  1084. foreach ($list as $key=>$value){
  1085. if ($value['状态'] == ''){
  1086. $list[$key]['状态'] = '待单';
  1087. }
  1088. }
  1089. $this->success('成功',$list);
  1090. }
  1091. /**
  1092. * 机台当前参数展示
  1093. * @ApiMethod (GET)
  1094. * @return void
  1095. * @throws \think\db\exception\DataNotFoundException
  1096. * @throws \think\db\exception\ModelNotFoundException
  1097. * @throws \think\exception\DbException
  1098. */
  1099. public function MachineDetail()
  1100. {
  1101. if ($this->request->isGet() === false){
  1102. $this->error('请求错误');
  1103. }
  1104. $param = $this->request->param();
  1105. if (empty($param)){
  1106. $this->error('参数错误');
  1107. }
  1108. $data = [];
  1109. if ($param['start'] === ''){
  1110. 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())){
  1111. $param['start'] = date('Y-m-d 08:30:00',time());
  1112. }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())){
  1113. $param['start'] = date('Y-m-d 20:30:00',time());
  1114. }else{
  1115. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1116. }
  1117. }
  1118. $machineDetail = \db('设备_产量采集')
  1119. ->alias('a')
  1120. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1121. ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
  1122. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1123. ->field([
  1124. 'rtrim(a.开工时间)' => '开工时间',
  1125. 'rtrim(a.设备编号)' => '设备编号',
  1126. 'rtrim(a.工单编号)' => '工单编号',
  1127. 'rtrim(b.设备名称)' => '设备名称',
  1128. 'rtrim(c.Gy0_gxh)' => '工序号',
  1129. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1130. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1131. ])
  1132. ->where('a.设备编号', $param['machine'])
  1133. ->order('a.UniqId desc')
  1134. ->find();
  1135. $data['machine'] = [
  1136. '日期' => $machineDetail['开工时间'],
  1137. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1138. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1139. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1140. ];
  1141. //机台状态时间
  1142. $startTime = \db('设备_产量采集')
  1143. ->where('设备编号',$param['machine'])
  1144. ->where('开工时间',$param['start'])
  1145. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1146. ->group('当前状态')
  1147. ->select();
  1148. if (!empty($startTime)){
  1149. foreach ($startTime as $key=>$value){
  1150. $data['timeDifference'][$key] = [
  1151. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1152. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1153. ];
  1154. if ($value['状态'] === '生产'){
  1155. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1156. }
  1157. }
  1158. }else{
  1159. $data['timeDifference'][0] = [
  1160. '时间' => 0,
  1161. '状态' => '待单'
  1162. ];
  1163. $data['当班产量'] = 0;
  1164. }
  1165. //机台产能/时间明细
  1166. $row = \db('设备_产量采集')
  1167. ->where('设备编号',$param['machine'])
  1168. ->where('开工时间',$param['start'])
  1169. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1170. ->select();
  1171. if (empty($row)){
  1172. $data['row'] = [];
  1173. }
  1174. foreach ($row as $key=>$value){
  1175. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1176. $data['row'][$key]['状态'] = $value['状态'];
  1177. if ($key<2){
  1178. $data['row'][$key]['产能'] = 0;
  1179. }else{
  1180. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1181. }
  1182. }
  1183. //机台状态
  1184. $status = end($row);
  1185. if (empty($status['状态'])){
  1186. $data['status'] = '待单';
  1187. }else{
  1188. $data['status'] = $status['状态'];
  1189. }
  1190. //检验数据
  1191. $list = \db('制程检验_记录')
  1192. ->where('开工时间',$param['start'])
  1193. ->where('设备编号',$param['machine'])
  1194. ->where('sys_rq','>',$param['start'])
  1195. ->field('rtrim(类别) as 类别,提交时间')
  1196. ->select();
  1197. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1198. if (!empty($list)){
  1199. foreach ($list as $key=>$value){
  1200. if ($value['类别'] == '首件与过程确认'){
  1201. array_push($data['首件'],$value['提交时间']);
  1202. }
  1203. if ($value['类别'] == '机台检验'){
  1204. array_push($data['自检'],$value['提交时间']);
  1205. }
  1206. if ($value['类别'] == 'IPQC检验'){
  1207. array_push($data['IPQC'],$value['提交时间']);
  1208. }
  1209. }
  1210. $data['首件'] = array_values(array_unique($data['首件']));
  1211. $data['自检'] = array_values(array_unique($data['自检']));
  1212. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1213. }else{
  1214. $data['首件'] = [];
  1215. $data['自检'] = [];
  1216. $data['IPQC'] = [];
  1217. }
  1218. $this->success('成功',$data);
  1219. }
  1220. /**
  1221. * 制程检验记录->检验项目
  1222. * @ApiMethod (GET)
  1223. * @param void
  1224. * @return void
  1225. * @throws \think\db\exception\DataNotFoundException
  1226. * @throws \think\db\exception\ModelNotFoundException
  1227. * @throws \think\exception\DbException
  1228. */
  1229. public function ProcessInspectionRecordsItem()
  1230. {
  1231. if ($this->request->isGet() === false){
  1232. $this->error('请求错误');
  1233. }
  1234. $param = $this->request->param();
  1235. if (empty($param)){
  1236. $this->error('参数错误');
  1237. }
  1238. $list = \db('制程检验_项目')
  1239. ->where('工序','like','%'.$param['process'].'%')
  1240. ->select();
  1241. if (empty($list)){
  1242. $this->success('未找到检测项目');
  1243. }
  1244. $data = [];
  1245. foreach ($list as $key=>$value){
  1246. $data['首件']['指标检验'][$key] = [
  1247. '检验项目' => rtrim($value['检测项目']),
  1248. '检测方法' => rtrim($value['检测方法']),
  1249. '检验频率' => rtrim($value['首件签样要求']),
  1250. '相关标准' => rtrim($value['技术要求'])
  1251. ];
  1252. $data['机台检验']['指标检验'][$key] = [
  1253. '检验项目' => rtrim($value['检测项目']),
  1254. '检测方法' => rtrim($value['检测方法']),
  1255. '检验频率' => rtrim($value['机台自检频率']),
  1256. '相关标准' => rtrim($value['技术要求'])
  1257. ];
  1258. $data['IPQC']['指标检验'][$key] = [
  1259. '检验项目' => rtrim($value['检测项目']),
  1260. '检测方法' => rtrim($value['检测方法']),
  1261. '检验频率' => rtrim($value['IPQC检验频率']),
  1262. '相关标准' => rtrim($value['技术要求'])
  1263. ];
  1264. }
  1265. $row = \db('制程检验_项目附加')
  1266. ->where('工序','like','%'.$param['process'].'%')
  1267. ->select();
  1268. foreach ($row as $key=>$value){
  1269. $data['首件']['附加'][$key] = [
  1270. '缺陷备注' => rtrim($value['缺陷备注']),
  1271. '编号' => rtrim($value['编号'])
  1272. ];
  1273. $data['机台检验']['附加'][$key] = [
  1274. '缺陷备注' => rtrim($value['缺陷备注']),
  1275. '编号' => rtrim($value['编号'])
  1276. ];
  1277. $data['IPQC']['附加'][$key] = [
  1278. '缺陷备注' => rtrim($value['缺陷备注']),
  1279. '编号' => rtrim($value['编号'])
  1280. ];
  1281. }
  1282. $this->success('成功',$data);
  1283. }
  1284. /**
  1285. * 制程检验记录->检测记录添加
  1286. * @ApiMethod (POST)
  1287. * @param void
  1288. * @return void
  1289. * @throws \think\db\exception\DataNotFoundException
  1290. * @throws \think\db\exception\ModelNotFoundException
  1291. * @throws \think\exception\DbException
  1292. */
  1293. public function ProcessInspectionRecordsItemAdd()
  1294. {
  1295. if (Request::instance()->isPost() === false){
  1296. $this->error('请求错误');
  1297. }
  1298. $param = Request::instance()->post();
  1299. if (empty($param)){
  1300. $this->error('参数错误');
  1301. }
  1302. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1303. if ($startID<100000000){
  1304. $startID = 100000000;
  1305. }
  1306. $process = \db('工单_工艺资料')
  1307. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1308. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1309. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1310. ->find();
  1311. $startTime = \db('设备_产量采集')
  1312. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1313. ->where('工单编号',$param[0]['workOrder'])
  1314. ->order('UniqId desc')
  1315. ->find();
  1316. if ((int)$process['gxh']<10){
  1317. $process['gxh'] = '0'.$process['gxh'];
  1318. }
  1319. if ($process['add_gxmc'] !== ''){
  1320. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1321. }else{
  1322. $printName = $process['gxh'].'-'.$process['gxmc'];
  1323. }
  1324. if (empty($process)){
  1325. $this->success('数据错误');
  1326. }
  1327. $data = [];
  1328. foreach ($param as $key=>$value){
  1329. $data[$key] = [
  1330. '类别' => $value['category'],
  1331. '工单编号' => $value['workOrder'],
  1332. '印件号' => $value['yjno'],
  1333. '工序名称' => $printName,
  1334. '流程单号' => $value['flow'],
  1335. '设备编号' => $value['machine'].'#',
  1336. '班组编号' => $startTime['班组编号'],
  1337. '检验项目' => $value['item'],
  1338. '相关标准' => $value['standard'],
  1339. '量测仪器' => $value['instrument'],
  1340. '检验结果' => $value['result'],
  1341. '检验备注' => $value['remark'],
  1342. '提交时间' => date('Y-m-d H:i:s',time()),
  1343. '开工时间' => rtrim($startTime['开工时间']),
  1344. 'sys_id' => '',
  1345. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1346. 'mod_rq' => '0000-00-00 00:00:00',
  1347. 'UniqId' => $startID + $key +1
  1348. ];
  1349. }
  1350. $res = \db('制程检验_记录')->insertAll($data);
  1351. if ($res !== false){
  1352. $this->success('成功');
  1353. }else{
  1354. $this->error('失败');
  1355. }
  1356. }
  1357. /**
  1358. * 制程检验记录->附加检验记录添加
  1359. * @ApiMethod (POST)
  1360. * @param void
  1361. * @return void
  1362. * @throws \think\db\exception\DataNotFoundException
  1363. * @throws \think\db\exception\ModelNotFoundException
  1364. * @throws \think\exception\DbException
  1365. */
  1366. public function AdditionalInspectionRecordAdd()
  1367. {
  1368. if (Request::instance()->isPost() === false){
  1369. $this->error('请求错误');
  1370. }
  1371. $param = Request::instance()->post();
  1372. if (empty($param)){
  1373. $this->error('参数错误');
  1374. }
  1375. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1376. if ($startID<100000000){
  1377. $startID = 100000000;
  1378. }
  1379. $process = \db('工单_工艺资料')
  1380. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1381. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1382. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1383. ->find();
  1384. $startTime = \db('设备_产量采集')
  1385. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1386. ->where('工单编号',$param[0]['workOrder'])
  1387. ->order('UniqId desc')
  1388. ->find();
  1389. if ((int)$process['gxh']<10){
  1390. $process['gxh'] = '0'.$process['gxh'];
  1391. }
  1392. if ($process['add_gxmc'] !== ''){
  1393. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1394. }else{
  1395. $printName = $process['gxh'].'-'.$process['gxmc'];
  1396. }
  1397. if (empty($process)){
  1398. $this->success('数据错误');
  1399. }
  1400. $data = [];
  1401. foreach ($param as $key=>$value){
  1402. $data[$key] = [
  1403. '工单编号' => $value['workOrder'],
  1404. '印件号' => $value['yjno'],
  1405. '工序名称' => $printName,
  1406. '流程单号' => $value['flow'],
  1407. '设备编号' => $value['machine'],
  1408. '班组编号' => $startTime['班组编号'],
  1409. '缺陷备注' => $value['remark'],
  1410. '提交时间' => date('Y-m-d H:i:s',time()),
  1411. '开工时间' => rtrim($startTime['开工时间']),
  1412. 'sys_id' => '',
  1413. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1414. 'mod_rq' => '0000-00-00 00:00:00',
  1415. 'UniqId' => $startID + $key +1
  1416. ];
  1417. }
  1418. $res = \db('制程检验_记录附加')->insertAll($data);
  1419. if ($res !== false){
  1420. $this->success('成功');
  1421. }else{
  1422. $this->error('失败');
  1423. }
  1424. }
  1425. /**
  1426. * 客诉记录
  1427. * @ApiMethod (GET)
  1428. * @param void
  1429. * @return void
  1430. * @throws \think\db\exception\DataNotFoundException
  1431. * @throws \think\db\exception\ModelNotFoundException
  1432. * @throws \think\exception\DbException
  1433. */
  1434. public function ComplaintRecord()
  1435. {
  1436. if ($this->request->isGet() === false){
  1437. $this->error('请求错误');
  1438. }
  1439. $param = $this->request->param();
  1440. if (isset($param['productCode'])){
  1441. $where['产品编号'] = $param['productCode'];
  1442. }
  1443. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1444. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1445. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1446. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1447. $list = \db('db_客诉记录')
  1448. ->where($where)
  1449. ->field($filed)
  1450. ->select();
  1451. if (empty($list)){
  1452. $this->success('未找到该产品客诉记录');
  1453. }
  1454. $this->success('成功',$list);
  1455. }
  1456. /**
  1457. * 设置机台班组信息
  1458. * @return void
  1459. * @throws \think\db\exception\DataNotFoundException
  1460. * @throws \think\db\exception\ModelNotFoundException
  1461. * @throws \think\exception\DbException
  1462. */
  1463. public function setMachineTeam()
  1464. {
  1465. if (Request::instance()->isPost() == false) {
  1466. $this->error('非法请求');
  1467. }
  1468. $params = Request::instance()->post();
  1469. if (!isset($params['machine']) || empty($params['machine'] )) {
  1470. $this->error('参数不能为空');
  1471. }
  1472. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1473. $this->error('请先选择班组成员');
  1474. }
  1475. $machine = $params['machine'] . '#';
  1476. $data = [];
  1477. $lastData = \db('设备_产量采集')
  1478. ->order('UniqId desc')
  1479. ->find();
  1480. if ($lastData['UniqId'] < 160000000) {
  1481. $id = 160000000;
  1482. } else {
  1483. $id = $lastData['UniqId'] + 1;
  1484. }
  1485. $data['当前状态'] = $params['status'];
  1486. $data['时间'] = date('Y-m-d H:i:s');
  1487. $data['设备编号'] = $machine;
  1488. $data['工单编号'] = $params['order'];
  1489. $data['印件号'] = $params['yjno'];
  1490. $data['工序号'] = (int)substr($params['gy_name'], 0, 2);
  1491. $data['工序名称'] = $params['gy_name'];
  1492. $data['当班产量'] = $params['production_now'];
  1493. $data['累计产量'] = $params['production_all'];
  1494. $data['班组编号'] = $params['sczl_bzdh'];
  1495. $data['班组ID'] = $params['team_id'];
  1496. // 获取当前时间
  1497. $current_time = time();
  1498. // 设置时间范围
  1499. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1500. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1501. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1502. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1503. // 判断当前时间属于哪个时间范围
  1504. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1505. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1506. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1507. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1508. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1509. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1510. }
  1511. $option['Gy0_gdbh'] = $params['order'];
  1512. $option['Gy0_yjno'] = $params['yjno'];
  1513. $option['Gy0_gxh'] = $data['工序号'];
  1514. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1515. $data['UniqId'] = $id;
  1516. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1517. $res = Db::query($sql);
  1518. if ($res === false) {
  1519. $this->error('设置失败');
  1520. } else {
  1521. $this->success('设置成功');
  1522. }
  1523. }
  1524. /**
  1525. * 首页数据
  1526. * @return void
  1527. * @throws \think\Exception
  1528. * @throws \think\db\exception\DataNotFoundException
  1529. * @throws \think\db\exception\ModelNotFoundException
  1530. * @throws \think\exception\DbException
  1531. */
  1532. public function index()
  1533. {
  1534. if ($this->request->isGet() === false){
  1535. $this->error('请求错误');
  1536. }
  1537. $nowTime = date('Y-m-d H:i:s',time());
  1538. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1539. $where =[
  1540. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1541. '行号' => '1'
  1542. ];
  1543. $data = [];
  1544. //按状态查询工单信息
  1545. $orderList = \db('工单_基本资料')
  1546. ->where($where)
  1547. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1548. ->group('gd_statu')
  1549. ->select();
  1550. foreach ($orderList as $value){
  1551. if ($value['状态'] === '1-已完工'){
  1552. $data['workOrderData']['已完工'] = $value['数量'];
  1553. }
  1554. if ($value['状态'] === '3-计划中'){
  1555. $data['workOrderData']['计划中'] = $value['数量'];
  1556. }
  1557. }
  1558. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1559. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1560. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1561. ->where([
  1562. 'a.gd_statu' => '2-生产中',
  1563. 'a.行号' => '1',
  1564. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1565. 'b.PD_WG' => '1900-01-01 00:00:00',
  1566. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1567. 'c.状态' => '',
  1568. ])
  1569. ->group('a.Gd_gdbh')
  1570. ->count();
  1571. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1572. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1573. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1574. ->where([
  1575. 'a.gd_statu' => '2-生产中',
  1576. 'a.行号' => '1',
  1577. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1578. 'b.PD_WG' => '1900-01-01 00:00:00',
  1579. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1580. 'c.状态' => '',
  1581. ])
  1582. ->group('a.Gd_gdbh')
  1583. ->count();
  1584. //按月份查询工单信息
  1585. $data['monthData'] = \db('工单_基本资料')
  1586. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1587. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1588. ->group('month')
  1589. ->order('month')
  1590. ->select();
  1591. //查询最近十条客诉信息
  1592. $data['customer'] = \db('db_客诉记录')
  1593. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1594. ->limit(10)
  1595. ->order('Sys_rq desc')
  1596. ->select();
  1597. $this->success('成功',$data);
  1598. }
  1599. /**
  1600. * 员工信息获取
  1601. * @return void
  1602. * @throws \think\db\exception\DataNotFoundException
  1603. * @throws \think\db\exception\ModelNotFoundException
  1604. * @throws \think\exception\DbException
  1605. */
  1606. public function EmployeeData()
  1607. {
  1608. if ($this->request->isGet() === false){
  1609. $this->error('请求错误');
  1610. }
  1611. $param = $this->request->param();
  1612. if (isset($param['code']) === false){
  1613. $this->error('参数错误');
  1614. }
  1615. $res = \db('人事_基本资料')
  1616. ->where('员工编号','like',$param['code'].'%')
  1617. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1618. ->select();
  1619. if (empty($res)){
  1620. $this->success('未找到该员工');
  1621. }
  1622. $this->success('成功',$res);
  1623. }
  1624. /**
  1625. * 换型清场添加
  1626. * @return void
  1627. * @throws \think\db\exception\BindParamException
  1628. * @throws \think\exception\PDOException
  1629. */
  1630. public function remodelDataAdd()
  1631. {
  1632. if (Request::instance()->isPost() === false){
  1633. $this->error('请求错误');
  1634. }
  1635. $param = Request::instance()->post();
  1636. if (empty($param)){
  1637. $this->error('参数错误');
  1638. }
  1639. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1640. $param['sys_id'] = '['.$param['机台编号'].']';
  1641. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1642. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1643. $param['UniqId'] = $lastId + 1;
  1644. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1645. $res = \db()->query($sql);
  1646. if ($res !== false){
  1647. $this->success('成功');
  1648. }else{
  1649. $this->error('失败');
  1650. }
  1651. }
  1652. /**
  1653. * 换型清场记录修改
  1654. * @return void
  1655. * @throws \think\Exception
  1656. * @throws \think\db\exception\BindParamException
  1657. * @throws \think\exception\PDOException
  1658. */
  1659. public function remodelDataEdit()
  1660. {
  1661. if (Request::instance()->isPost() === false){
  1662. $this->error('请求错误');
  1663. }
  1664. $param = Request::instance()->post();
  1665. if (empty($param)){
  1666. $this->error('参数错误');
  1667. }
  1668. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1669. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1670. $res = \db()->query($sql);
  1671. if ($res !== false){
  1672. $this->success('成功');
  1673. }else{
  1674. $this->error('失败');
  1675. }
  1676. }
  1677. /**
  1678. * 换型清场记录删除
  1679. * @return void
  1680. * @throws \think\Exception
  1681. * @throws \think\exception\PDOException
  1682. */
  1683. public function remodelDataDel()
  1684. {
  1685. if ($this->request->isGet() === false){
  1686. $this->error('请求错误');
  1687. }
  1688. $param = $this->request->param();
  1689. if (empty($param)){
  1690. $this->error('参数错误');
  1691. }
  1692. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1693. if ($res !== false){
  1694. $this->success('删除成功');
  1695. }else{
  1696. $this->error('删除失败');
  1697. }
  1698. }
  1699. /**
  1700. * 印版领用记录添加
  1701. * @return void
  1702. * @throws \think\db\exception\BindParamException
  1703. * @throws \think\exception\PDOException
  1704. */
  1705. public function PrintDetailAdd()
  1706. {
  1707. if (Request::instance()->isPost() === false){
  1708. $this->error('请求错误');
  1709. }
  1710. $param = Request::instance()->post();
  1711. if (empty($param)){
  1712. $this->error('参数错误');
  1713. }
  1714. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1715. foreach ($param as $key=>$value){
  1716. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1717. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1718. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1719. $param[$key]['UniqID'] = $lastId + $key +1;
  1720. }
  1721. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1722. $res = \db()->query($sql);
  1723. if ($res !== false){
  1724. $this->success('添加成功');
  1725. }else{
  1726. $this->error('添加失败');
  1727. }
  1728. }
  1729. /**
  1730. * 印版领用记录退还
  1731. * @return void
  1732. * @throws \think\Exception
  1733. * @throws \think\db\exception\BindParamException
  1734. * @throws \think\exception\PDOException
  1735. */
  1736. public function PrintDetailEdit()
  1737. {
  1738. if ($this->request->isGet() === false){
  1739. $this->error('请求错误');
  1740. }
  1741. $param = $this->request->param();
  1742. if (empty($param)){
  1743. $this->error('参数错误');
  1744. }
  1745. $idList = explode(',',$param['id']);
  1746. $i = 0;
  1747. foreach ($idList as $key=>$value){
  1748. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  1749. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  1750. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  1751. $res = \db()->query($sql);
  1752. if ($res === false){
  1753. $i++;
  1754. }
  1755. }
  1756. if ($i !== 0){
  1757. $this->error('退还失败');
  1758. }else{
  1759. $this->success('退还成功');
  1760. }
  1761. }
  1762. /**
  1763. * 当日上报产量修改
  1764. * @return void
  1765. * @throws \think\Exception
  1766. * @throws \think\db\exception\BindParamException
  1767. * @throws \think\exception\PDOException
  1768. */
  1769. public function chanliangEdit()
  1770. {
  1771. if (Request::instance()->isPost() === false){
  1772. $this->error('请求错误');
  1773. }
  1774. $param = Request::instance()->post();
  1775. if (empty($param['UniqId'])){
  1776. $this->error('参数错误');
  1777. }
  1778. $data = $param;
  1779. unset($data['UniqId']);
  1780. $sql = \db('设备_产量计酬')
  1781. ->where('UniqId',$param['UniqId'])
  1782. ->fetchSql(true)
  1783. ->update($data);
  1784. $res = \db()->query($sql);
  1785. if ($res !== false){
  1786. $this->success('修改成功');
  1787. }else {
  1788. $this->error('修改失败');
  1789. }
  1790. }
  1791. }