|
|
@@ -8,7 +8,7 @@ use think\Db;
|
|
|
use think\Request;
|
|
|
|
|
|
/**
|
|
|
- * 设备运行跟踪
|
|
|
+ * 质量继绩效管理
|
|
|
*/
|
|
|
|
|
|
class Facility extends Api
|
|
|
@@ -18,385 +18,387 @@ class Facility extends Api
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 左侧菜单栏
|
|
|
- * @ApiMethod (GET)
|
|
|
- * @return void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * 查询月份数据
|
|
|
*/
|
|
|
- public function getTab()
|
|
|
- {
|
|
|
- if ($this->request->isGet() === false){
|
|
|
+ public function ApiMouthlist() {
|
|
|
+ // 检查请求类型是否为GET
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
$param = $this->request->param();
|
|
|
- if (isset($param['sort'])){
|
|
|
- $where['使用部门'] = '智能车间';
|
|
|
- }else{
|
|
|
- $where['使用部门'] = ['in',['印刷车间','印后车间']];
|
|
|
+ // 查询符合条件的数据
|
|
|
+ $list = \db('设备_质量汇总')
|
|
|
+ ->where('状态', $param['code'])
|
|
|
+ ->where('mod_rq', null)
|
|
|
+ ->group('Sys_rq')
|
|
|
+ ->select();
|
|
|
+ if (empty($list)) {
|
|
|
+ $this->error('没有找到数据');
|
|
|
}
|
|
|
+ // 用于存储按年和月分类的数据
|
|
|
$data = [];
|
|
|
- $date = date('Y-m-d 00:00:00',time()-3888000);
|
|
|
- $department = \db('设备_基本资料')
|
|
|
- ->distinct(true)
|
|
|
- ->where('使用部门','<>','研发中心')
|
|
|
- ->where('设备编组','<>','')
|
|
|
- ->where($where)
|
|
|
- ->order('设备编组')
|
|
|
- ->column('rtrim(使用部门) as 使用部门');
|
|
|
- if (empty($department)){
|
|
|
- $this->success('为获取到机台数据');
|
|
|
+ // 遍历查询结果,将日期按年、月分组
|
|
|
+ foreach ($list as $item) {
|
|
|
+ // 获取 Sys_rq 字段的值(日期)
|
|
|
+ $sys_rq = $item['Sys_rq'];
|
|
|
+
|
|
|
+ // 提取年、月、日
|
|
|
+ $year = date('Y', strtotime($sys_rq));
|
|
|
+ $month = date('Y-m', strtotime($sys_rq));
|
|
|
+ $day = date('Y-m-d', strtotime($sys_rq));
|
|
|
+
|
|
|
+ // 将数据按年、月、日分类
|
|
|
+ if (!isset($data[$year])) {
|
|
|
+ $data[$year] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isset($data[$year][$month])) {
|
|
|
+ $data[$year][$month] = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将日期加入到对应的年、月下
|
|
|
+ $data[$year][$month][] = $day;
|
|
|
}
|
|
|
- $list = \db('设备_产量计酬')
|
|
|
- ->field([
|
|
|
- 'DISTINCT(sczl_rq)' => '时间',
|
|
|
- 'rtrim(sczl_jtbh)' => '机台编号'
|
|
|
- ])
|
|
|
- ->where('sczl_rq','>',$date)
|
|
|
- ->order('sczl_rq desc')
|
|
|
- ->select();
|
|
|
- if (empty($list)){
|
|
|
- $this->success('未找到机台生产记录');
|
|
|
- }
|
|
|
- foreach ($department as $value){
|
|
|
- $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
|
|
|
- foreach ($machine as $k=>$v){
|
|
|
- $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
|
|
|
- foreach ($list as $kk=>$vv){
|
|
|
- if ($v['设备编号'] === $vv['机台编号']){
|
|
|
- array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
|
|
|
- }
|
|
|
- }
|
|
|
+ $this->success('成功', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增次品和新增返工
|
|
|
+ */
|
|
|
+ public function ApiAddDefective(){
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = $this->request->param();
|
|
|
+ if (empty($params)){
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $res = \db('设备_质量汇总')->where('mod_rq', null)->order('status_num desc')->find();
|
|
|
+ //记录每次新增次数排序
|
|
|
+ $status_num = $res['status_num'];
|
|
|
+
|
|
|
+ // 构建单条记录的函数,传递 $list_gd 作为参数
|
|
|
+ function buildRecords($item,$status_num) {
|
|
|
+ // 拆分物料名称(假设格式为 面料分类-面料名称)
|
|
|
+ $materialParts = explode('-', $item['物料名称']);
|
|
|
+ $materialCategory = isset($materialParts[0]) ? $materialParts[0] : ''; // 面料分类
|
|
|
+ $materialName = isset($materialParts[1]) ? $materialParts[1] : ''; // 面料名称
|
|
|
+
|
|
|
+
|
|
|
+ return [
|
|
|
+ '订单编号' => $item['订单编号'],
|
|
|
+ '生产款号' => $item['生产款号'],
|
|
|
+ '款式' => $item['款式'],
|
|
|
+ '颜色' => $item['颜色'],
|
|
|
+ '尺码' => $item['尺码'],
|
|
|
+ '数量' => $item['数量'],
|
|
|
+ '组别' => $item['组别'],
|
|
|
+ '实际用料' => $item['实际用料'],
|
|
|
+ '计划用料' => $item['计划用料'],
|
|
|
+ '备注' => $item['备注'],
|
|
|
+ '问题分类' => $item['问题分类'],
|
|
|
+ 'sczl_rq' => date('Y-m-d H:i:s'),
|
|
|
+ 'Sys_rq' => $item['Sys_rq'],
|
|
|
+ 'Sys_id' => $item['Sys_id'],
|
|
|
+ '状态' => $item['状态'],
|
|
|
+ 'status_num' => $status_num + 1,
|
|
|
+ '面料分类' => $materialCategory,
|
|
|
+ '面料名称' => $materialName,
|
|
|
+
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否是索引数组(多条记录)
|
|
|
+ if (isset($params[0]) && is_array($params[0])) {
|
|
|
+ foreach ($params as $item) {
|
|
|
+ $list[] = buildRecords($item,$status_num);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ // 处理单条记录
|
|
|
+ $list[] = buildRecords($params,$status_num);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 插入数据到设备_产量计酬表
|
|
|
+ $result = \db('设备_质量汇总')->insertAll($list);
|
|
|
+ if ($result) {
|
|
|
+ $this->success('数据插入成功 : ' . date('H:i:s'));
|
|
|
+ } else {
|
|
|
+ $this->error('数据插入失败');
|
|
|
}
|
|
|
- $this->success('成功',$data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 机台每日产量
|
|
|
- * @ApiMethod (GET)
|
|
|
- * @param string $machine 机台编号
|
|
|
- * @param string $date 日期
|
|
|
- * @return void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * 查询订单对应尺码
|
|
|
*/
|
|
|
- public function chanLiang()
|
|
|
- {
|
|
|
- if ($this->request->isGet() === false){
|
|
|
+ public function queryOrderSize() {
|
|
|
+ // 检查请求类型是否为GET
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
- $machine = input('machine');
|
|
|
- $date = input('date');
|
|
|
- $where = [
|
|
|
- 'sczl_jtbh' => $machine,
|
|
|
- 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
|
|
|
- ];
|
|
|
- $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
|
|
|
- rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,IF(sczl_zcfp = 0, "",sczl_zcfp) as 制程废品,IF(sczl_zccp = 0, "",sczl_zccp) as 制程次品,IF(sczl_前工序废 = 0, "",sczl_前工序废) as 前工序废,IF(sczl_来料少数 = 0, "",sczl_来料少数) as 来料异常,
|
|
|
- IF(sczl_装版工时 = 0, "",sczl_装版工时) as 装版工时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_打样工时 = 0, "",sczl_打样工时) as 打样工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
|
|
|
- IF(码开始行 = 0, "",码开始行) as 码开始行,IF(码结束行 = 0, "",码结束行) as 码结束行,IF(码包 = 0, "",码包) as 码包,IF(主电表 = 0, "",主电表) as 主电表,IF(辅电表 = 0, "",辅电表) as 辅电表,IF(sczl_ms = 0, "",sczl_ms) as 色度数,
|
|
|
- rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
|
|
|
- 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,
|
|
|
- sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号';
|
|
|
- //机台信息
|
|
|
- $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
|
|
|
- //组员信息
|
|
|
- $list = \db('设备_产量计酬')->where($where)->field($field)->select();
|
|
|
- $totalA = \db('设备_产量计酬')
|
|
|
- ->where($where)
|
|
|
- ->where('sczl_bzdh','like','A%')
|
|
|
- ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时')
|
|
|
- ->select();
|
|
|
- $totalB = \db('设备_产量计酬')
|
|
|
- ->where($where)
|
|
|
- ->where('sczl_bzdh','like','B%')
|
|
|
- ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时')
|
|
|
- ->select();
|
|
|
- if (empty($list)){
|
|
|
- $this->success('',[]);
|
|
|
+ $param = $this->request->param();
|
|
|
+
|
|
|
+ // 获取问题分类
|
|
|
+ $fetchCategory = \db('db_问题分类')->field('问题类型')->select();
|
|
|
+ $category = array_column($fetchCategory, '问题类型'); // 获取问题类型列表
|
|
|
+
|
|
|
+ // 查询订单基本信息
|
|
|
+ $gdlist = \db('工单_基本资料')
|
|
|
+ ->field('订单编号,生产款号,款式,订单数量')
|
|
|
+// ->where('订单编号|生产款号','like','%'.$param['订单编号'].'%')
|
|
|
+ ->where(['订单编号|生产款号' => $param['订单编号']])
|
|
|
+ ->where('Mod_rq', null)
|
|
|
+ ->find();
|
|
|
+ if (empty($gdlist)) {
|
|
|
+ $this->error('未找到相关数据');
|
|
|
}
|
|
|
- foreach ($list as $key=>$value){
|
|
|
- //产品名称
|
|
|
- $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
|
|
|
- if (!empty($productName)){
|
|
|
- if (!empty($productName['成品名称'])){
|
|
|
- $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
|
|
|
- $list[$key]['cpmc'] = $productName['成品名称'];
|
|
|
- }else{
|
|
|
- $list[$key]['产品名称'] = $value['工单编号'];
|
|
|
- $list[$key]['cpmc'] = '';
|
|
|
+
|
|
|
+
|
|
|
+ // 查询订单尺码信息
|
|
|
+ $sizeData = \db('工单_印件资料')->where(['订单编号' => $gdlist['订单编号']])->where('Mod_rq', null)->select();
|
|
|
+ if (empty($sizeData)) {
|
|
|
+ $this->error('未找到相关数据');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算所有尺码数据
|
|
|
+ $sizes = [];
|
|
|
+ foreach ($sizeData as $order) {
|
|
|
+ foreach ($order as $key => $value) {
|
|
|
+ if (strpos($key, 'cm') === 0 && strpos($key, 'cmsl') === false && $value !== null && $value !== '') {
|
|
|
+ $sizes[] = $value;
|
|
|
}
|
|
|
- }else{
|
|
|
- $list[$key]['产品名称'] = $value['工单编号'];
|
|
|
- $list[$key]['cpmc'] = '';
|
|
|
}
|
|
|
- $process = \db('工单_工艺资料')
|
|
|
- ->where('Gy0_gdbh',$value['工单编号'])
|
|
|
- ->where('Gy0_yjno',$value['yjno'])
|
|
|
- ->where('Gy0_gxh',$value['gxh'])
|
|
|
- ->field('rtrim(工价系数) as 工价系数,rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距')
|
|
|
- ->find();
|
|
|
- if (!empty($process)){
|
|
|
- if ($value['难度系数'] == 0){
|
|
|
- $list[$key]['难度系数'] = $process['工价系数'];
|
|
|
- }else{
|
|
|
- $list[$key]['难度系数'] = $process['工价系数'].'x'.$value['难度系数'];
|
|
|
+ }
|
|
|
+ $sizes = array_values(array_unique($sizes)); // 去重后的尺码数据
|
|
|
+
|
|
|
+ // 获取颜色备注并统计每个颜色的sctotal和zdtotal
|
|
|
+ $colorData = []; // 用于存储每个颜色备注对应的sctotal和zdtotal
|
|
|
+ foreach ($sizeData as $item) {
|
|
|
+ if (!empty($item['颜色备注'])) {
|
|
|
+ $color = $item['颜色备注'];
|
|
|
+
|
|
|
+ $sctotal = (int)$item['sctotal'];
|
|
|
+ $zdtotal = (int)$item['zdtotal'];
|
|
|
+ if (isset($colorData[$color])) {
|
|
|
+ $colorData[$color]['sctotal'] += $sctotal;
|
|
|
+ $colorData[$color]['zdtotal'] += $zdtotal;
|
|
|
+ } else {
|
|
|
+ $colorData[$color] = [
|
|
|
+ 'sctotal' => $sctotal,
|
|
|
+ 'zdtotal' => $zdtotal
|
|
|
+ ];
|
|
|
}
|
|
|
- $list[$key]['印刷方式'] = $process['印刷方式'].' '.$process['版距'];
|
|
|
- }else{
|
|
|
- $list[$key]['难度系数'] = '';
|
|
|
- $list[$key]['印刷方式'] = '';
|
|
|
}
|
|
|
- if ($value['yjno']<10){
|
|
|
- $list[$key]['yjno'] = '0'.$value['yjno'];
|
|
|
+ }
|
|
|
+ // 获取颜色备注(去重)
|
|
|
+ $colorremark = array_values(array_unique(array_keys($colorData)));
|
|
|
+
|
|
|
+ // 获取面料数据
|
|
|
+ $getAllFabricData = \db('工单_面料资料')
|
|
|
+ ->field('BOM_desc,BOM_物料名称,BOM_定额门幅,BOM_计划门幅,BOM_颜色')
|
|
|
+ ->where('BOM_工单编号', $param['订单编号'])
|
|
|
+ ->where('Mod_rq', null)
|
|
|
+ ->select();
|
|
|
+ $fabricData = [];
|
|
|
+ $materialSeen = [];
|
|
|
+ $descNullData = [];
|
|
|
+
|
|
|
+ // 处理面料数据
|
|
|
+ foreach ($getAllFabricData as $value) {
|
|
|
+ $materialName = $value['BOM_物料名称'];
|
|
|
+ $bomDesc = $value['BOM_desc'];
|
|
|
+ $combinedData = ($bomDesc ? $bomDesc : '') . ' - ' . $materialName;
|
|
|
+
|
|
|
+ // 如果 BOM_desc 为空,记录该物料名称
|
|
|
+ if (empty($bomDesc)) {
|
|
|
+ $descNullData[] = $combinedData;
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (empty($value['定额代号'])){
|
|
|
- $list[$key]['千件工价'] = '';
|
|
|
- $list[$key]['日定额'] = '';
|
|
|
- $list[$key]['补产标准'] = '';
|
|
|
- }else{
|
|
|
- $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
|
|
|
- $list[$key]['千件工价'] = $row['千件工价'];
|
|
|
- $list[$key]['日定额'] = $row['日定额'];
|
|
|
- $list[$key]['补产标准'] = $row['补产标准'];
|
|
|
+
|
|
|
+ // 如果 BOM_desc 不为空,检查该物料名称是否已经出现过
|
|
|
+ if (!in_array($materialName, $materialSeen)) {
|
|
|
+ $fabricData[] = $combinedData;
|
|
|
+ $materialSeen[] = $materialName;
|
|
|
}
|
|
|
- $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
|
|
|
- $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
|
|
|
- for ($i=1;$i<11;$i++){
|
|
|
- if (isset($value['sczl_bh'.$i])){
|
|
|
- $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
|
|
|
- if (isset($name['name'])){
|
|
|
- $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理 BOM_desc 为空的物料名称,确保不重复添加
|
|
|
+ foreach ($descNullData as $combinedData) {
|
|
|
+ if (!in_array($combinedData, $fabricData)) {
|
|
|
+ $fabricData[] = $combinedData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 去重处理面料数据
|
|
|
+ $finalFabricData = [];
|
|
|
+ $seenDescriptions = [];
|
|
|
+
|
|
|
+ foreach ($fabricData as $item) {
|
|
|
+ $parts = explode(' - ', $item);
|
|
|
+ if (count($parts) == 2) {
|
|
|
+ $desc = $parts[0];
|
|
|
+ $material = $parts[1];
|
|
|
+
|
|
|
+ // 如果物料没有被记录过,或者描述不为空,保留数据
|
|
|
+ if (!in_array($material, $seenDescriptions)) {
|
|
|
+ $finalFabricData[] = $item;
|
|
|
+ $seenDescriptions[] = $material;
|
|
|
}
|
|
|
- unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
|
|
|
+ } else {
|
|
|
+ // 描述为空的直接保留
|
|
|
+ $finalFabricData[] = $item;
|
|
|
}
|
|
|
}
|
|
|
- $list['totalA'] = $totalA[0]['产量'];
|
|
|
- $list['totalB'] = $totalB[0]['产量'];
|
|
|
- $list['制程废品A'] = $totalA[0]['制程废品'];
|
|
|
- $list['制程废品B'] = $totalB[0]['制程废品'];
|
|
|
- $list['制程次品A'] = $totalA[0]['制程次品'];
|
|
|
- $list['制程次品B'] = $totalB[0]['制程次品'];
|
|
|
- $list['来料异常A'] = $totalA[0]['来料异常'];
|
|
|
- $list['来料异常B'] = $totalB[0]['来料异常'];
|
|
|
- $list['装版工时A'] = $totalA[0]['装版工时'];
|
|
|
- $list['装版工时B'] = $totalB[0]['装版工时'];
|
|
|
- $this->success('成功',$list);
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 当日制程检验记录
|
|
|
- * @ApiMethod (GET)
|
|
|
- * @param string $machine 机台编号
|
|
|
- * @param string $date 日期
|
|
|
- * @return void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function Inspect()
|
|
|
- {
|
|
|
- if ($this->request->isGet() === false){
|
|
|
- $this->error('请求错误');
|
|
|
+ // 用于统计每个物料的用料情况
|
|
|
+ $uniqueFabricData = []; // 去重后的面料数据
|
|
|
+ foreach ($getAllFabricData as $fabric) {
|
|
|
+ $key = $fabric['BOM_颜色'] . '-' . $fabric['BOM_物料名称']; // 以颜色和物料名称为唯一标识
|
|
|
+ $uniqueFabricData[$key] = $fabric; // 使用唯一标识作为数组的键,自动去重
|
|
|
+ }
|
|
|
+ // 重建数组索引,移除键名
|
|
|
+ $uniqueFabricData = array_values($uniqueFabricData);
|
|
|
+ $materialUsage = [];
|
|
|
+ // 遍历每种颜色的统计数据
|
|
|
+ foreach ($colorData as $color => $data) {
|
|
|
+ // 遍历去重后的面料数据
|
|
|
+ foreach ($uniqueFabricData as $fabric) {
|
|
|
+ // 判断颜色是否匹配
|
|
|
+ if ($fabric['BOM_颜色'] === $color) {
|
|
|
+ // 直接统计每个物料的数量,而不进行用料的计算
|
|
|
+ $materialUsage[$color][$fabric['BOM_物料名称']][] = $fabric; // 使用物料名称作为键,存储所有相关的面料数据
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $machine = input('machine');
|
|
|
- $date = input('date');
|
|
|
- if (empty($machine) || empty($date)){
|
|
|
- $this->error('参数错误');
|
|
|
+
|
|
|
+ // 生成实际用料数据
|
|
|
+ $actualUsage = [];
|
|
|
+ foreach ($materialUsage as $color => $materials) {
|
|
|
+ foreach ($materials as $materialName => $fabricData) {
|
|
|
+ // 获取该颜色下的 sctotal 和 zdtotal
|
|
|
+ $sctotal = isset($colorData[$color]['sctotal']) ? $colorData[$color]['sctotal'] : 0;
|
|
|
+ $zdtotal = isset($colorData[$color]['zdtotal']) ? $colorData[$color]['zdtotal'] : 0;
|
|
|
+ // 获取定额门幅和计划门幅
|
|
|
+ $standardWidth = isset($fabricData[0]['BOM_定额门幅']) ? $fabricData[0]['BOM_定额门幅'] : 0;
|
|
|
+ $plannedWidth = isset($fabricData[0]['BOM_计划门幅']) ? $fabricData[0]['BOM_计划门幅'] : 0;
|
|
|
+ // 直接根据去重后的面料数据进行统计
|
|
|
+ $actualUsage[] = [
|
|
|
+ '颜色' => $color,
|
|
|
+ '物料名称' => $materialName,
|
|
|
+ '定额门幅' => $standardWidth,
|
|
|
+ '计划门幅' => $plannedWidth,
|
|
|
+ 'sctotal' => $sctotal,
|
|
|
+ 'zdtotal' => $zdtotal
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
- $where = [
|
|
|
- '设备编号' => $machine,
|
|
|
- '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
|
|
|
- '类别' => ['in',['IPQC检验','机台检验']],
|
|
|
- ];
|
|
|
- $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
|
|
|
- $list = \db('制程检验_记录')
|
|
|
- ->where($where)
|
|
|
- ->field($field)
|
|
|
- ->select();
|
|
|
- if (empty($list)){
|
|
|
- $this->success('未找到检验记录');
|
|
|
+
|
|
|
+ foreach ($actualUsage as &$item) {
|
|
|
+ $item['实际用料'] = $item['sctotal'] * $item['定额门幅'];
|
|
|
+ $item['计划用料'] = $item['zdtotal'] * $item['计划门幅'];
|
|
|
}
|
|
|
- $data = [];
|
|
|
- foreach ($list as $key=>$value)
|
|
|
- {
|
|
|
- $data['item'][$key] = $value['检验项目'];
|
|
|
- $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
|
|
|
- $data['工单编号'][$key] = $value['工单编号'];
|
|
|
- }
|
|
|
- $data['item'] = array_unique($data['item']);
|
|
|
- $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
|
|
|
- $data['工单编号'] = array_values(array_unique($data['工单编号']));
|
|
|
- foreach ($data['工单编号'] as $key => $value){
|
|
|
- foreach ($data['item'] as $k=>$v){
|
|
|
- $time = '';
|
|
|
- foreach ($list as $kk=>$vv){
|
|
|
- if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
|
|
|
- $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
|
|
|
- $data['row'][$key][$k] = [
|
|
|
- '工单编号' => $value,
|
|
|
- '印件号' => $vv['印件号'],
|
|
|
- '工序名称' => $vv['工序名称'],
|
|
|
- '检验项目' => $v,
|
|
|
- 'time' => substr($time,0,-1),
|
|
|
- ];
|
|
|
- }
|
|
|
+
|
|
|
+ // 选择显示的字段
|
|
|
+ $fieldsToShow = ['颜色', '物料名称', '实际用料', '计划用料'];
|
|
|
+ $finalResult = array();
|
|
|
+ foreach ($actualUsage as $item) {
|
|
|
+ $filteredItem = array();
|
|
|
+ foreach ($fieldsToShow as $field) {
|
|
|
+ if (isset($item[$field])) {
|
|
|
+ $filteredItem[$field] = $item[$field];
|
|
|
}
|
|
|
}
|
|
|
- $data['row'][$key] = array_values($data['row'][$key]);
|
|
|
+ $finalResult[] = $filteredItem;
|
|
|
}
|
|
|
- unset($data['item'],$data['工单编号']);
|
|
|
- $this->success('成功',$data);
|
|
|
+
|
|
|
+
|
|
|
+ $this->success('成功', [
|
|
|
+ 'list' => $gdlist,
|
|
|
+ 'colorremark' => $colorremark,
|
|
|
+ 'fetchCategory' => $category,
|
|
|
+ 'FabricData' => $finalFabricData,
|
|
|
+ 'size' => $sizes,
|
|
|
+ '面料统计' => $finalResult
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 设备生产中工单信息
|
|
|
- * @ApiMethod (GET)
|
|
|
- * @param string $machine 机台编号
|
|
|
- * @return void
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * 查询次片、返工列表数据
|
|
|
*/
|
|
|
- public function Production()
|
|
|
- {
|
|
|
- if (Request::instance()->isGet() == false) {
|
|
|
- $this->error('非法请求');
|
|
|
+ /**
|
|
|
+ * 查询次片、返工列表数据
|
|
|
+ */
|
|
|
+ public function ApiSubPieceAndReworkList() {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
}
|
|
|
- $params = Request::instance()->param();
|
|
|
- if (!isset($params['machine']) || empty($params['machine'])) {
|
|
|
- $this->error('参数错误');
|
|
|
+ $params = $this->request->param();
|
|
|
+ $where = ['mod_rq' => null];
|
|
|
+ if (!empty($params['code'])) {
|
|
|
+ $where['状态'] = $params['code'];
|
|
|
}
|
|
|
- $machine = $params['machine'];
|
|
|
- $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
|
|
|
- $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
|
|
|
- $list = [];
|
|
|
- if (!empty($data['工单编号'])){
|
|
|
- $endTime = \db('工单_工艺资料')
|
|
|
- ->where('Gy0_gdbh',$data['工单编号'])
|
|
|
- ->where('Gy0_yjno',$data['印件号'])
|
|
|
- ->where('Gy0_gxh',$data['工序号'])
|
|
|
- ->find();
|
|
|
- $list['工单编号'] = $data['工单编号'];
|
|
|
- if (!empty($endTime)){
|
|
|
- $list['印件号'] = $data['印件号'];
|
|
|
- $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
|
|
|
- $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
|
|
|
- $list['产品名称'] = rtrim($name);
|
|
|
- $list['产品代号'] = rtrim($code);
|
|
|
- $list['工序名称'] = $data['工序名称'];
|
|
|
- }
|
|
|
- }else{
|
|
|
- $list['工单编号'] = '';
|
|
|
- $list['印件号'] = 0;
|
|
|
- $list['产品名称'] = '';
|
|
|
- $list['工序名称'] = '';
|
|
|
- $list['产品代号'] = '';
|
|
|
- }
|
|
|
- $list['状态'] = rtrim($data['当前状态']);
|
|
|
- $list['班组编号'] = rtrim($data['班组编号']);
|
|
|
- $list['班组Id'] = rtrim($data['班组ID']);
|
|
|
- $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,
|
|
|
- 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,
|
|
|
- rtrim(sczl_bh10) as bh10")->find();
|
|
|
- $row = [];
|
|
|
- if (!empty($class)){
|
|
|
- for ($i=1;$i<11;$i++) {
|
|
|
- if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
|
|
|
- $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
|
|
|
- $row[$i] = [
|
|
|
- '编号' => $class['bh' . $i],
|
|
|
- '姓名' => $name['姓名']
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- $row = array_values($row);
|
|
|
+ if (!empty($params['search'])) {
|
|
|
+ $where['订单编号|生产款号|面料名称'] = ['like', '%' . $params['search'] . '%'];
|
|
|
}
|
|
|
- $list['班组成员'] = $row;
|
|
|
- $list['定额代号'] = $machineCode;
|
|
|
- $this->success('成功',$list);
|
|
|
+ if (!empty($params['Sys_rq'])) {
|
|
|
+ $where['Sys_rq'] = $params['Sys_rq'];
|
|
|
+ }
|
|
|
+ $query = \db('设备_质量汇总')
|
|
|
+ ->where($where)
|
|
|
+ ->limit(($params['page'] - 1) * $params['limit'], $params['limit']);
|
|
|
+ $res = $query->select();
|
|
|
+ $total = $query->count();
|
|
|
+ $this->success('成功', ['data' => $res, 'total' => $total]);
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 更新问题分类接口
|
|
|
+// */
|
|
|
+// public function Production()
|
|
|
+// {
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
- * 设备工作清单
|
|
|
- * @ApiMethod (GET)
|
|
|
- * @param string $machine 机台编号
|
|
|
- * @return void
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
+ * 统计面料次品汇总
|
|
|
+ * 统计面料返工汇总
|
|
|
*/
|
|
|
+// if ($this->request->isGet() === false){
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+// $params = $this->request->param();
|
|
|
|
|
|
- public function EquipmentWorklist()
|
|
|
+ public function ApiDefectsAndRework()
|
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
- $this->error('请求错误');
|
|
|
- }
|
|
|
- $machine = input('machine');
|
|
|
- if (empty($machine)){
|
|
|
- $this->error('参数错误');
|
|
|
- }
|
|
|
- $orderList = \db('工单_工艺资料')
|
|
|
- ->alias('a')
|
|
|
-// ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','LEFT')
|
|
|
- ->join('工单_基本资料 c','a.Gy0_gdbh = c.Gd_gdbh')
|
|
|
- ->join('工单_印件资料 d','a.Gy0_gdbh = d.Yj_Gdbh AND a.Gy0_yjno = d.yj_Yjno')
|
|
|
- ->field('a.Gy0_gdbh as gdbh,a.质量要求 as 质量信息,a.Gy0_yjno as yjno,a.Gy0_gxh as gxh,
|
|
|
- a.Gy0_gxmc as gxmc,a.Add_gxmc as add_gxmc,a.Gy0_辅助工时 as 装版工时,a.Gy0_小时产能 as 工序产能,a.Gy0_生产工时 as 计划工时,
|
|
|
- a.Gy0_sj1 as sj1,a.Gy0_sj2 as sj2,a.工序备注 as 排产备注,d.yj_yjmc as 印件名称,c.成品名称 as 产品名称,c.成品代号 as 产品代号,
|
|
|
- a.Gy0_计划接货数 as 计划接货数,a.Gy0_ls as ls,a.Gy0_班次安排 as 班组,a.UniqId as UniqId,a.Gy0_最早开工时间 as 最早开工时间')
|
|
|
- ->where('a.Gy0_sbbh','like','%'.$machine.'%')
|
|
|
- ->where('a.PD_WG','1900-01-01 00:00:00')
|
|
|
- ->where('a.Gy0_sj1','<>','1900-01-01 00:00:00')
|
|
|
- ->where('c.gd_statu','2-生产中')
|
|
|
- ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
|
|
|
- ->order('a.Gy0_sj1')
|
|
|
+ // 查询设备质量汇总数据,mod_rq为空
|
|
|
+ $list = \db('设备_质量汇总')
|
|
|
+ ->where('mod_rq', null)
|
|
|
+ ->where('状态', '次片')
|
|
|
->select();
|
|
|
-// halt($orderList);
|
|
|
- if (!empty($orderList)){
|
|
|
- $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
|
|
|
- foreach ($orderList as $key=>$value){
|
|
|
- $cl_data = \db('设备_产量计酬')
|
|
|
- ->field('SUM(sczl_cl) as 已完成,SUM(sczl_zcfp) as 制程废品')
|
|
|
- ->where('sczl_gdbh',$value['gdbh'])
|
|
|
- ->where('sczl_yjno',$value['yjno'])
|
|
|
- ->where('sczl_gxh',$value['gxh'])
|
|
|
- ->select();
|
|
|
- $orderList[$key]['status'] = 0;
|
|
|
- if (!empty($data)){
|
|
|
- if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
|
|
|
- $orderList[$key]['status'] = 1;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
|
|
|
- $orderList[$key]['印件号'] = $value['yjno'];
|
|
|
- $orderList[$key]['工序号'] = $value['gxh'];
|
|
|
- if ($value['yjno']<10){
|
|
|
- $orderList[$key]['yjno'] = '0'.$value['yjno'];
|
|
|
- }
|
|
|
- if ($value['gxh']<10){
|
|
|
- $orderList[$key]['gxh'] = '0'.$value['gxh'];
|
|
|
- }
|
|
|
- $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
|
|
|
- $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
|
|
|
- if ((int)$cl_data[0]['制程废品'] === 0){
|
|
|
- $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'];
|
|
|
- }else{
|
|
|
- $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'].'('.$cl_data[0]['制程废品'].')';
|
|
|
- }
|
|
|
-
|
|
|
- $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
|
|
|
- unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls'],$orderList[$key]['制程废品']);
|
|
|
+ // 创建一个空数组来存储面料名称及其对应的总数量
|
|
|
+ $fabricSummary = [];
|
|
|
+
|
|
|
+ // 遍历查询结果,累加相同面料名称的数量
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $fabricName = $item['面料名称'];
|
|
|
+ $quantity = $item['数量'];
|
|
|
+ // 如果该面料名称已存在于数组中,则累加数量
|
|
|
+ if (isset($fabricSummary[$fabricName])) {
|
|
|
+ $fabricSummary[$fabricName] += $quantity;
|
|
|
+ } else {
|
|
|
+ // 如果该面料名称不存在,则初始化数量
|
|
|
+ $fabricSummary[$fabricName] = $quantity;
|
|
|
}
|
|
|
}
|
|
|
- $this->success('成功',$orderList);
|
|
|
+
|
|
|
+ // 打印结果
|
|
|
+ echo "<pre>";
|
|
|
+ print_r($fabricSummary);
|
|
|
+ echo "</pre>";
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2530,4 +2532,4 @@ class Facility extends Api
|
|
|
$list['totalB'] = $totalB;
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
-}
|
|
|
+}
|