|
@@ -53,83 +53,174 @@ class Decision extends Api
|
|
|
* @throws \think\exception\DbException
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
+// public function MachineProduction()
|
|
|
|
|
+// {
|
|
|
|
|
+// if ($this->request->isGet() === false){
|
|
|
|
|
+// $this->error('请求错误');
|
|
|
|
|
+// }
|
|
|
|
|
+// $param = $this->request->param();
|
|
|
|
|
+// if (empty($param['mouth'])){
|
|
|
|
|
+// $this->error('参数错误');
|
|
|
|
|
+// }
|
|
|
|
|
+// $where = [];
|
|
|
|
|
+// if(!empty($param['sist'])){
|
|
|
|
|
+// $where['设备编组'] = $param['sist'];
|
|
|
|
|
+// }
|
|
|
|
|
+// //将参数装换成标准日期格式
|
|
|
|
|
+// $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
|
|
|
|
|
+// $machine = \db('设备_基本资料')
|
|
|
|
|
+// ->where($where)
|
|
|
|
|
+// ->where('sys_sbID','<>','')
|
|
|
|
|
+// ->field('设备编号')
|
|
|
|
|
+// ->order('设备编号')
|
|
|
|
|
+// ->select();
|
|
|
|
|
+// $day = \db('设备_产量计酬')
|
|
|
|
|
+// ->distinct(true)
|
|
|
|
|
+// ->field('DATE_FORMAT(sczl_rq,"%Y-%m-%d") as day')
|
|
|
|
|
+// ->whereRaw("DATE_FORMAT(sczl_rq, '%Y-%m') = '$mouth'")
|
|
|
|
|
+// ->order('day')
|
|
|
|
|
+// ->select();
|
|
|
|
|
+// $day = array_reduce($day, function($carry, $item) {
|
|
|
|
|
+// return array_merge($carry, array_values($item));
|
|
|
|
|
+// }, []);
|
|
|
|
|
+// $data = [];
|
|
|
|
|
+// $data['head'] = $day;
|
|
|
|
|
+// foreach ($machine as $key=>$value){
|
|
|
|
|
+// $data['total'][$key] = \db('设备_产量计酬')
|
|
|
|
|
+// ->field('sczl_jtbh,sczl_bzdh,SUM(sczl_cl) as total_cl,sczl_rq')
|
|
|
|
|
+// ->where('sczl_rq','like',$mouth.'%')
|
|
|
|
|
+// ->where('sczl_jtbh',$value['设备编号'])
|
|
|
|
|
+// ->group('sczl_bzdh')
|
|
|
|
|
+// ->select();
|
|
|
|
|
+// foreach ($data['total'][$key] as $k=>$v){
|
|
|
|
|
+// $day_cl = \db('设备_产量计酬')
|
|
|
|
|
+// ->alias('a')
|
|
|
|
|
+// ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
|
|
|
|
|
+// ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
|
|
|
|
|
+// ->field([
|
|
|
|
|
+// 'a.sczl_gdbh' => '工单编号',
|
|
|
|
|
+// 'a.sczl_yjno' => '印件号',
|
|
|
|
|
+// 'a.sczl_gxh' => '工序号',
|
|
|
|
|
+// 'c.yj_yjmc' => '印件名称',
|
|
|
|
|
+// 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
|
|
|
|
|
+// 'DATE(a.sczl_rq)' => 'day',
|
|
|
|
|
+// 'a.sczl_jtbh' => '机台编号',
|
|
|
|
|
+// 'a.sczl_bzdh' => '班组编号',
|
|
|
|
|
+// 'SUM(a.sczl_cl)' => 'total_cl',
|
|
|
|
|
+// 'a.sczl_ms' => '墨色数',
|
|
|
|
|
+// 'rtrim(d.印刷方式)' => '印刷方式',
|
|
|
|
|
+// 'rtrim(d.版距)' => '版距'
|
|
|
|
|
+// ])
|
|
|
|
|
+// ->where('a.sczl_rq','like',$mouth.'%')
|
|
|
|
|
+// ->where('a.sczl_jtbh', $value['设备编号'])
|
|
|
|
|
+// ->where('a.sczl_bzdh', $v['sczl_bzdh'])
|
|
|
|
|
+// ->group('sczl_bzdh,day')
|
|
|
|
|
+// ->select();
|
|
|
|
|
+// $day_total = [];
|
|
|
|
|
+// foreach ($day_cl as $index=>$item){
|
|
|
|
|
+// if ($item['印刷方式'] === '卷对卷'){
|
|
|
|
|
+// $day_cl[$index]['total_cl'] = round($item['total_cl']/$item['版距']*1000);
|
|
|
|
|
+// }
|
|
|
|
|
+// $day_total[$item['day']] =$day_cl[$index]['total_cl'];
|
|
|
|
|
+// }
|
|
|
|
|
+// $data['total'][$key][$k]['day_total'] = $day_total;
|
|
|
|
|
+// $data['total'][$key][$k]['total_cl'] = array_sum($day_total);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// $this->success('成功',$data);
|
|
|
|
|
+// }
|
|
|
public function MachineProduction()
|
|
public function MachineProduction()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
|
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
$this->error('请求错误');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
$param = $this->request->param();
|
|
$param = $this->request->param();
|
|
|
- if (empty($param['mouth'])){
|
|
|
|
|
|
|
+ if (empty($param['mouth'])) {
|
|
|
$this->error('参数错误');
|
|
$this->error('参数错误');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
$where = [];
|
|
$where = [];
|
|
|
- if(!empty($param['sist'])){
|
|
|
|
|
|
|
+ if (!empty($param['sist'])) {
|
|
|
$where['设备编组'] = $param['sist'];
|
|
$where['设备编组'] = $param['sist'];
|
|
|
}
|
|
}
|
|
|
- //将参数装换成标准日期格式
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 将参数转换成标准日期格式
|
|
|
$mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
|
|
$mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
|
|
|
- $machine = \db('设备_基本资料')
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 使用单个查询获取所有需要的数据
|
|
|
|
|
+ $results = \db('设备_产量计酬')
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
|
|
|
|
|
+ ->join('工单_印件资料 c', 'a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno', 'LEFT')
|
|
|
|
|
+ ->join('工单_工艺资料 d', 'a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh', 'LEFT')
|
|
|
|
|
+ ->field([
|
|
|
|
|
+ 'a.sczl_jtbh',
|
|
|
|
|
+ 'a.sczl_bzdh',
|
|
|
|
|
+ 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d") as day',
|
|
|
|
|
+ 'SUM(a.sczl_cl) as total_cl',
|
|
|
|
|
+ 'c.yj_yjmc as 印件名称',
|
|
|
|
|
+ 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")") as 工序名称',
|
|
|
|
|
+ 'RTRIM(d.印刷方式) as 印刷方式',
|
|
|
|
|
+ 'RTRIM(d.版距) as 版距'
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->where('a.sczl_rq', 'like', $mouth . '%')
|
|
|
|
|
+ ->where('b.sys_sbID', '<>', '')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
- ->where('sys_sbID','<>','')
|
|
|
|
|
- ->field('设备编号')
|
|
|
|
|
- ->order('设备编号')
|
|
|
|
|
|
|
+ ->group('a.sczl_bzdh, day, a.sczl_jtbh, c.yj_yjmc, d.Gy0_gxmc')
|
|
|
|
|
+ ->order('a.sczl_jtbh, a.sczl_bzdh, day')
|
|
|
->select();
|
|
->select();
|
|
|
- $day = \db('设备_产量计酬')
|
|
|
|
|
- ->distinct(true)
|
|
|
|
|
- ->field('DATE_FORMAT(sczl_rq,"%Y-%m-%d") as day')
|
|
|
|
|
- ->whereRaw("DATE_FORMAT(sczl_rq, '%Y-%m') = '$mouth'")
|
|
|
|
|
- ->order('day')
|
|
|
|
|
- ->select();
|
|
|
|
|
- $day = array_reduce($day, function($carry, $item) {
|
|
|
|
|
- return array_merge($carry, array_values($item));
|
|
|
|
|
- }, []);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 处理数据
|
|
|
$data = [];
|
|
$data = [];
|
|
|
- $data['head'] = $day;
|
|
|
|
|
- foreach ($machine as $key=>$value){
|
|
|
|
|
- $data['total'][$key] = \db('设备_产量计酬')
|
|
|
|
|
- ->field('sczl_jtbh,sczl_bzdh,SUM(sczl_cl) as total_cl,sczl_rq')
|
|
|
|
|
- ->where('sczl_rq','like',$mouth.'%')
|
|
|
|
|
- ->where('sczl_jtbh',$value['设备编号'])
|
|
|
|
|
- ->group('sczl_bzdh')
|
|
|
|
|
- ->select();
|
|
|
|
|
- foreach ($data['total'][$key] as $k=>$v){
|
|
|
|
|
- $day_cl = \db('设备_产量计酬')
|
|
|
|
|
- ->alias('a')
|
|
|
|
|
- ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
|
|
|
|
|
- ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
|
|
|
|
|
- ->field([
|
|
|
|
|
- 'a.sczl_gdbh' => '工单编号',
|
|
|
|
|
- 'a.sczl_yjno' => '印件号',
|
|
|
|
|
- 'a.sczl_gxh' => '工序号',
|
|
|
|
|
- 'c.yj_yjmc' => '印件名称',
|
|
|
|
|
- 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
|
|
|
|
|
- 'DATE(a.sczl_rq)' => 'day',
|
|
|
|
|
- 'a.sczl_jtbh' => '机台编号',
|
|
|
|
|
- 'a.sczl_bzdh' => '班组编号',
|
|
|
|
|
- 'SUM(a.sczl_cl)' => 'total_cl',
|
|
|
|
|
- 'a.sczl_ms' => '墨色数',
|
|
|
|
|
- 'rtrim(d.印刷方式)' => '印刷方式',
|
|
|
|
|
- 'rtrim(d.版距)' => '版距'
|
|
|
|
|
- ])
|
|
|
|
|
- ->where('a.sczl_rq','like',$mouth.'%')
|
|
|
|
|
- ->where('a.sczl_jtbh', $value['设备编号'])
|
|
|
|
|
- ->where('a.sczl_bzdh', $v['sczl_bzdh'])
|
|
|
|
|
- ->group('sczl_bzdh,day')
|
|
|
|
|
- ->select();
|
|
|
|
|
- $day_total = [];
|
|
|
|
|
- foreach ($day_cl as $index=>$item){
|
|
|
|
|
- if ($item['印刷方式'] === '卷对卷'){
|
|
|
|
|
- $day_cl[$index]['total_cl'] = round($item['total_cl']/$item['版距']*1000);
|
|
|
|
|
- }
|
|
|
|
|
- $day_total[$item['day']] =$day_cl[$index]['total_cl'];
|
|
|
|
|
- }
|
|
|
|
|
- $data['total'][$key][$k]['day_total'] = $day_total;
|
|
|
|
|
- $data['total'][$key][$k]['total_cl'] = array_sum($day_total);
|
|
|
|
|
|
|
+ $data['head'] = array_unique(array_column($results, 'day'));
|
|
|
|
|
+ $total_by_machine = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($results as $item) {
|
|
|
|
|
+ $machine_id = $item['sczl_jtbh'];
|
|
|
|
|
+ $group_id = $item['sczl_bzdh'];
|
|
|
|
|
+ $day = $item['day'];
|
|
|
|
|
+ $printed_type = $item['印刷方式'];
|
|
|
|
|
+
|
|
|
|
|
+ if (!isset($total_by_machine[$machine_id])) {
|
|
|
|
|
+ $total_by_machine[$machine_id] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isset($total_by_machine[$machine_id][$group_id])) {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id] = [
|
|
|
|
|
+ '印件名称' => $item['印件名称'],
|
|
|
|
|
+ '工序名称' => $item['工序名称'],
|
|
|
|
|
+ 'total_cl' => 0,
|
|
|
|
|
+ 'day_total' => []
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新总数量
|
|
|
|
|
+ if ($printed_type === '卷对卷') {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id]['total_cl'] += round($item['total_cl'] / $item['版距'] * 1000);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id]['total_cl'] += $item['total_cl'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 按天汇总
|
|
|
|
|
+ if (!isset($total_by_machine[$machine_id][$group_id]['day_total'][$day])) {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id]['day_total'][$day] = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 日总数
|
|
|
|
|
+ if ($printed_type === '卷对卷') {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id]['day_total'][$day] += round($item['total_cl'] / $item['版距'] * 1000);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $total_by_machine[$machine_id][$group_id]['day_total'][$day] += $item['total_cl'];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $this->success('成功',$data);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ // 格式化输出数据
|
|
|
|
|
+ $data['total'] = array_values(array_map(function ($machine) {
|
|
|
|
|
+ return array_values($machine);
|
|
|
|
|
+ }, $total_by_machine));
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('成功', $data);
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 机台班次生产工单明细
|
|
* 机台班次生产工单明细
|
|
|
* @return void
|
|
* @return void
|