Facility.php 65 KB

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