|
|
@@ -934,134 +934,173 @@ class Manufacture extends Api
|
|
|
/**
|
|
|
* 月度车间报工汇总-菜单显示
|
|
|
*/
|
|
|
- public function MachineList(){
|
|
|
- if ($this->request->isGet() === false) {
|
|
|
+ public function MachineList() {
|
|
|
+ // 检查请求是否为 GET
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
- $date = date('Y-m-d 00:00:00', time() - 1888000);
|
|
|
|
|
|
- $clwhere['mod_rq'] = null;
|
|
|
-// $clwhere['sczl_jtbh'] = 'CQ03';
|
|
|
- $arr = \db('设备_产量计酬')
|
|
|
+ // 定义要查询的生产工序及排序顺序
|
|
|
+ $processList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装'];
|
|
|
+
|
|
|
+ // 查询所有数据
|
|
|
+ $results = \db('设备_产量计酬')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
|
|
|
->field([
|
|
|
- 'DISTINCT(date_format(sczl_rq,"%Y-%m-%d"))' => '时间',
|
|
|
- 'rtrim(sczl_jtbh)' => '机台编号'
|
|
|
+ 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d")' => '时间', // 转化为 "YYYY-MM-DD" 格式
|
|
|
+ 'DATE_FORMAT(a.sczl_rq, "%Y-%m")' => '年月', // 转化为 "YYYY-MM" 格式
|
|
|
+ 'RTRIM(a.sczl_jtbh)' => '机台编号',
|
|
|
+ 'b.设备编号',
|
|
|
+ 'b.设备编组',
|
|
|
+ 'b.生产工序'
|
|
|
])
|
|
|
- ->where('sczl_rq', '>', $date)
|
|
|
- ->where($clwhere)
|
|
|
- ->order('sczl_rq desc')
|
|
|
+ ->whereNull('a.mod_rq') // 筛选无修改日期的数据
|
|
|
+ ->whereIn('b.生产工序', $processList) // 筛选指定的生产工序
|
|
|
+ ->order('a.sczl_rq ASC') // 按时间升序排序
|
|
|
->select();
|
|
|
|
|
|
- $list = ['裁剪','车缝', '手工', '大烫', '总检', '包装'];
|
|
|
+ // 初始化按年月分组的结果
|
|
|
+ $formattedData = [];
|
|
|
|
|
|
- $MachineList = \db('设备_基本资料')
|
|
|
- ->where('生产工序', 'in', $list)
|
|
|
- ->select();
|
|
|
+ // 遍历查询结果并分组
|
|
|
+ foreach ($results as $row) {
|
|
|
+ $yearMonth = $row['年月']; // 获取年月 "YYYY-MM"
|
|
|
+ $monthDay = substr($row['时间'], 5, 5); // 获取月份和日期 "MM-DD"
|
|
|
+ $process = $row['生产工序'];
|
|
|
+ $machineKey = $row['设备编号'] . '--' . $row['设备编组'];
|
|
|
|
|
|
- $data = [];
|
|
|
+ // 初始化年份和工序结构
|
|
|
+ if (!isset($formattedData[$yearMonth])) {
|
|
|
+ $formattedData[$yearMonth] = array_fill_keys($processList, []); // 初始化月份,所有工序为空数组
|
|
|
+ }
|
|
|
+ if (!isset($formattedData[$yearMonth][$process][$machineKey])) {
|
|
|
+ $formattedData[$yearMonth][$process][$machineKey] = [];
|
|
|
+ }
|
|
|
|
|
|
- foreach ($list as $m => $n) {
|
|
|
- $data[$n] = [];
|
|
|
- foreach ($MachineList as $key => $value) {
|
|
|
- if ($n === $value['生产工序']) {
|
|
|
- $data[$n][$value['设备编号'] . '--' . $value['设备编组']] = [];
|
|
|
- foreach ($arr as $k => $v) {
|
|
|
- if ($value['设备编号'] === $v['机台编号']) {
|
|
|
- array_push($data[$n][$value['设备编号'] . '--' . $value['设备编组']], $v['时间']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 添加日期,避免重复
|
|
|
+ if (!in_array($monthDay, $formattedData[$yearMonth][$process][$machineKey])) {
|
|
|
+ $formattedData[$yearMonth][$process][$machineKey][] = $monthDay;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 将数据转换为所需格式,保留月份和日期
|
|
|
- $formattedData = [];
|
|
|
- foreach ($data as $process => $machines) {
|
|
|
- foreach ($machines as $machine => $dates) {
|
|
|
- foreach ($dates as $date) {
|
|
|
- $yearMonth = substr($date, 0, 7); // 年份
|
|
|
- $monthDay = substr($date, 5, 5); // 月份和日期,如 "10-28"
|
|
|
-
|
|
|
- // 初始化年份、工序和机器信息
|
|
|
- if (!isset($formattedData[$yearMonth])) {
|
|
|
- $formattedData[$yearMonth] = [];
|
|
|
- }
|
|
|
- if (!isset($formattedData[$yearMonth][$process])) {
|
|
|
- $formattedData[$yearMonth][$process] = [];
|
|
|
- }
|
|
|
- if (!isset($formattedData[$yearMonth][$process][$machine])) {
|
|
|
- $formattedData[$yearMonth][$process][$machine] = [];
|
|
|
- }
|
|
|
+ // 对年份和月份进行排序(按年月降序排序)
|
|
|
+ krsort($formattedData);
|
|
|
|
|
|
- // 将月份和日期加入到对应机器的数组中
|
|
|
- if (!in_array($monthDay, $formattedData[$yearMonth][$process][$machine])) {
|
|
|
- $formattedData[$yearMonth][$process][$machine][] = $monthDay;
|
|
|
- }
|
|
|
+ // 按生产工序排序
|
|
|
+ foreach ($formattedData as $yearMonth => &$processData) {
|
|
|
+ // 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
|
|
|
+ $sortedProcessData = array_fill_keys($processList, []);
|
|
|
+
|
|
|
+ // 合并原有数据
|
|
|
+ foreach ($processData as $process => $machines) {
|
|
|
+ $sortedProcessData[$process] = $machines;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新排序后的数据
|
|
|
+ $processData = $sortedProcessData;
|
|
|
+
|
|
|
+ // 对每组内的设备日期倒序排列
|
|
|
+ foreach ($processData as $process => &$machines) {
|
|
|
+ foreach ($machines as $machineKey => &$dates) {
|
|
|
+ rsort($dates); // 每台设备的日期倒序排序
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 对年月份进行降序排序,使最新的月份在最上面
|
|
|
- krsort($formattedData);
|
|
|
-
|
|
|
+ // 返回成功结果
|
|
|
$this->success('成功', $formattedData);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 月度车间报工汇总-列表数据
|
|
|
*/
|
|
|
- public function MachineDetail(){
|
|
|
- if ($this->request->isGet() === false){
|
|
|
- $this->error('请求错误');
|
|
|
- }
|
|
|
+ public function MachineDetail()
|
|
|
+ {
|
|
|
+ if ($this->request->isGet() === false) {$this->error('请求错误');}
|
|
|
$param = $this->request->param();
|
|
|
- if (empty($param)){
|
|
|
- $this->error('参数错误');
|
|
|
- }
|
|
|
+ if (empty($param)) {$this->error('参数错误');}
|
|
|
+
|
|
|
$where = [];
|
|
|
- if (isset($param['date'])) {
|
|
|
- // 检查 `date` 的格式是否为 "YYYY-MM" 或 "MM-DD"
|
|
|
+
|
|
|
+// 获取当前年份
|
|
|
+ $currentYear = date('Y');
|
|
|
+
|
|
|
+// 处理日期参数(可选)
|
|
|
+ if (!empty($param['date'])) {
|
|
|
+ // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
|
|
|
if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
|
|
|
- // 如果格式为 "YYYY-MM",则查询当月数据
|
|
|
+ // 如果格式为 "YYYY-MM",查询当月数据
|
|
|
$where['a.sys_rq'] = ['like', "{$param['date']}%"];
|
|
|
} elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
|
|
|
- // 如果格式为 "MM-DD",则查询指定的月份和日期
|
|
|
+ // 如果格式为 "MM-DD",查询指定的月份和日期
|
|
|
$monthDay = $param['date'];
|
|
|
$where['a.sys_rq'] = ['like', "%-$monthDay%"];
|
|
|
+ } elseif (preg_match('/^\d{2}$/', $param['date'])) {
|
|
|
+ // 如果格式为 "MM"(仅月份),自动补全为 "YYYY-MM"
|
|
|
+ $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
|
|
|
}
|
|
|
}
|
|
|
- // 判断是否传入订单编号参数
|
|
|
- if(!empty($param['order'])){
|
|
|
- $where['b.订单编号|b.款号'] = ['like','%'.$param['order'].'%'];
|
|
|
+
|
|
|
+// 判断是否传入订单编号参数(可选)
|
|
|
+ if (!empty($param['order'])) {
|
|
|
+ $where['b.订单编号|b.款号'] = ['like', '%' . $param['order'] . '%'];
|
|
|
}
|
|
|
- $where['a.sczl_jtbh'] = $param['machine'];//机台号
|
|
|
|
|
|
+// 处理机台号参数(可选)
|
|
|
+ if (!empty($param['machine'])) {
|
|
|
+ $where['a.sczl_jtbh'] = $param['machine'];
|
|
|
+ }
|
|
|
|
|
|
+// 查询数据
|
|
|
$list = \db('设备_产量计酬')->alias('a')
|
|
|
->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
|
|
|
->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
|
|
|
->field('
|
|
|
- b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数,b.颜色备注,
|
|
|
- a.数量, MIN(a.sys_rq) as 上报时间,a.UniqId,
|
|
|
- j.客户编号,j.生产款号,j.款式
|
|
|
- ')
|
|
|
+ b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
|
|
|
+ a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
|
|
|
+ j.客户编号, j.生产款号, j.款式
|
|
|
+ ')
|
|
|
->where($where)
|
|
|
- ->where('a.mod_rq',null)
|
|
|
- ->order('a.sys_rq desc,a.UniqId desc')
|
|
|
+ ->where('a.mod_rq', null)
|
|
|
+ ->order('a.sys_rq desc, a.UniqId desc')
|
|
|
->group('a.UniqId')
|
|
|
->select();
|
|
|
|
|
|
+
|
|
|
// 提取所有的尺码,并去重
|
|
|
$sizeList = array_values(array_unique(array_column($list, '尺码')));
|
|
|
+
|
|
|
+ // **自定义排序规则**
|
|
|
+ $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
|
|
|
+
|
|
|
+ usort($sizeList, function ($a, $b) use ($sizeOrder) {
|
|
|
+ // 如果是数字,直接比较大小
|
|
|
+ if (is_numeric($a) && is_numeric($b)) {
|
|
|
+ return $a - $b;
|
|
|
+ }
|
|
|
+ // 如果是字母,按 $sizeOrder 的索引排序
|
|
|
+ if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
|
|
|
+ return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
|
|
|
+ }
|
|
|
+ // 如果一个是数字,一个是字母,数字排在前面
|
|
|
+ if (is_numeric($a)) return -1;
|
|
|
+ if (is_numeric($b)) return 1;
|
|
|
+
|
|
|
+ // 如果都不符合,按字典顺序(备用)
|
|
|
+ return strcmp($a, $b);
|
|
|
+ });
|
|
|
+
|
|
|
// 动态将尺码的数量添加到每个订单中,并替换已完成字段
|
|
|
foreach ($list as &$item) {
|
|
|
$size = $item['尺码'];
|
|
|
$item[$size] = $item['数量'];
|
|
|
-// unset($item['数量']);
|
|
|
+ // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
|
|
|
}
|
|
|
- sort($sizeList);
|
|
|
+
|
|
|
// 返回结果
|
|
|
$this->success('请求成功', [
|
|
|
'table' => $list,
|
|
|
@@ -1070,6 +1109,7 @@ class Manufacture extends Api
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 工单审核
|
|
|
* @return void
|
|
|
@@ -1167,14 +1207,16 @@ class Manufacture extends Api
|
|
|
public function OrderYieldList(){
|
|
|
// 获取前端传来的参数
|
|
|
$param = $this->request->param();
|
|
|
+ // 初始化查询条件
|
|
|
+ $where = [];
|
|
|
// 处理搜索条件
|
|
|
- if (isset($param['search'])){
|
|
|
- $where['j.订单编号|j.生产款号'] = ['like','%'.$param['search'].'%'];
|
|
|
+ if (isset($param['search']) && !empty($param['search'])) {
|
|
|
+ $where['j.订单编号|j.生产款号'] = ['like', '%' . $param['search'] . '%'];
|
|
|
}
|
|
|
- if (isset($param['client'])){
|
|
|
+ if (isset($param['client']) && !empty($param['client'])) {
|
|
|
$where['j.客户编号'] = $param['client'];
|
|
|
}
|
|
|
- if (isset($param['date'])) {
|
|
|
+ if (isset($param['date']) && !empty($param['date'])) {
|
|
|
$year = substr($param['date'], 0, 4);
|
|
|
$month = substr($param['date'], 4, 2);
|
|
|
$where['j.Sys_rq'] = ['like', "$year-$month%"];
|
|
|
@@ -1182,9 +1224,10 @@ class Manufacture extends Api
|
|
|
// 只查询生产中的工单
|
|
|
$where['j.gd_statu'] = '2-生产中';
|
|
|
$where['j.Mod_rq'] = null;
|
|
|
+ // 执行查询
|
|
|
$orderList = \db('工单_基本资料')->alias('j')
|
|
|
->join('工单_印件资料 y', 'j.订单编号 = y.订单编号')
|
|
|
- ->field('j.Sys_rq,y.订单编号, j.落货日期, j.生产款号, j.款式, SUM(y.sctotal) as 裁剪总数, SUM(y.zdtotal) as 制单总数')
|
|
|
+ ->field('j.Sys_rq, y.订单编号, j.落货日期, j.生产款号, j.款式, SUM(y.sctotal) as 裁剪总数, SUM(y.zdtotal) as 制单总数')
|
|
|
->group('y.订单编号')
|
|
|
->where($where)
|
|
|
->select();
|
|
|
@@ -1197,7 +1240,9 @@ class Manufacture extends Api
|
|
|
->field('a.订单编号, a.工序名称, SUM(a.数量) as 总数量')
|
|
|
->group('a.订单编号, a.工序名称') // 按订单编号和工序名称分组
|
|
|
->select();
|
|
|
-
|
|
|
+//echo "<pre>";
|
|
|
+//print_r($processList);
|
|
|
+//echo "<pre>";
|
|
|
// 合并两个结果
|
|
|
$data = [];
|
|
|
foreach ($orderList as $key => $order) {
|