Facility.php 67 KB

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