|
|
@@ -1041,79 +1041,210 @@ class Manufacture extends Api
|
|
|
/**
|
|
|
* 月度车间报工汇总-列表数据
|
|
|
*/
|
|
|
+
|
|
|
+// public function MachineDetail()
|
|
|
+// {
|
|
|
+// if ($this->request->isGet() === false) {
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)) {
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $where = [];
|
|
|
+//
|
|
|
+// // 获取当前年份
|
|
|
+// $currentYear = date('Y');
|
|
|
+//
|
|
|
+// // 处理日期参数(可选)
|
|
|
+// if (!empty($param['date'])) {
|
|
|
+// if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
|
|
|
+// $where['a.sys_rq'] = ['like', "{$param['date']}%"];
|
|
|
+// } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
|
|
|
+// $monthDay = $param['date'];
|
|
|
+// $where['a.sys_rq'] = ['like', "%-$monthDay%"];
|
|
|
+// } elseif (preg_match('/^\d{2}$/', $param['date'])) {
|
|
|
+// $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 订单编号筛选
|
|
|
+// if (!empty($param['order'])) {
|
|
|
+// $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 机台号筛选
|
|
|
+// if (!empty($param['machine'])) {
|
|
|
+// $machineMapping = [
|
|
|
+// '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
|
|
|
+// '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
|
|
|
+// ];
|
|
|
+//
|
|
|
+// if (isset($machineMapping[$param['machine']])) {
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
|
|
|
+// } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
|
|
|
+// $where['a.sczl_jtbh'] = ''; // 若为日期格式,清空该字段
|
|
|
+// } else {
|
|
|
+// $where['a.sczl_jtbh'] = $param['machine'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 查询数据
|
|
|
+// $list = \db('设备_产量计酬')->alias('a')
|
|
|
+// ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
|
|
|
+// ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
|
|
|
+// ->field('
|
|
|
+// a.工序名称, 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')
|
|
|
+// ->group('a.UniqId')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// // 提取所有的尺码,并去重,去除空格
|
|
|
+// $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
|
|
|
+//
|
|
|
+// // 自定义排序规则(已存在的排序逻辑)
|
|
|
+// $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
|
|
|
+// usort($sizeList, function ($a, $b) use ($sizeOrder) {
|
|
|
+// // 数字优先比较
|
|
|
+// if (is_numeric($a) && is_numeric($b)) {
|
|
|
+// return $a - $b;
|
|
|
+// }
|
|
|
+// 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);
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 不合并相同的子订单编号,而是按 "子订单编号 + 工序名称" 作为唯一键
|
|
|
+// $mergedList = [];
|
|
|
+// foreach ($list as $item) {
|
|
|
+// $uniqueKey = $item['子订单编号'] . '-' . $item['工序名称']; // 关键点:加入工序名称
|
|
|
+//
|
|
|
+// if (!isset($mergedList[$uniqueKey])) {
|
|
|
+// $mergedList[$uniqueKey] = $item;
|
|
|
+// } else {
|
|
|
+// // 汇总数量
|
|
|
+// foreach ($sizeList as $size) {
|
|
|
+// // 如果当前行有这个尺码,累加数量
|
|
|
+// if (isset($item['尺码']) && $item['尺码'] == $size) {
|
|
|
+// $mergedList[$uniqueKey][$size] = isset($mergedList[$uniqueKey][$size])
|
|
|
+// ? $mergedList[$uniqueKey][$size] + $item['数量']
|
|
|
+// : $item['数量'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 转换合并后的数组为列表
|
|
|
+// $finalList = array_values($mergedList);
|
|
|
+//
|
|
|
+// // 将合并后的结果转换为列表形式
|
|
|
+// $finalList = array_values($mergedList);
|
|
|
+//
|
|
|
+// // 返回结果
|
|
|
+// $this->success('请求成功', [
|
|
|
+// 'table' => $finalList,
|
|
|
+// 'length' => count($finalList),
|
|
|
+// 'headers' => $sizeList // 返回所有的尺码作为表头
|
|
|
+// ]);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 月度车间报工汇总-列表详情数据
|
|
|
+ */
|
|
|
public function MachineDetail()
|
|
|
{
|
|
|
- if ($this->request->isGet() === false) {$this->error('请求错误');}
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+
|
|
|
$param = $this->request->param();
|
|
|
- if (empty($param)) {$this->error('参数错误');}
|
|
|
+ if (empty($param)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
|
|
|
$where = [];
|
|
|
|
|
|
-// 获取当前年份
|
|
|
+ // 获取当前年份
|
|
|
$currentYear = date('Y');
|
|
|
|
|
|
-// 处理日期参数(可选)
|
|
|
+ // 处理日期参数(可选)
|
|
|
if (!empty($param['date'])) {
|
|
|
- // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
|
|
|
+ // 日期参数的格式处理
|
|
|
if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
|
|
|
- // 如果格式为 "YYYY-MM",查询当月数据
|
|
|
$where['a.sys_rq'] = ['like', "{$param['date']}%"];
|
|
|
} elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
|
|
|
- // 如果格式为 "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'] . '%'];
|
|
|
+ $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
|
|
|
}
|
|
|
|
|
|
-// 处理机台号参数(可选)
|
|
|
+ // 机台号筛选
|
|
|
if (!empty($param['machine'])) {
|
|
|
- $where['a.sczl_jtbh'] = $param['machine'];
|
|
|
+ // 针对机台号的特定条件判断
|
|
|
+ $machineMapping = [
|
|
|
+ '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
|
|
|
+ '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (isset($machineMapping[$param['machine']])) {
|
|
|
+ $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
|
|
|
+ } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
|
|
|
+ $where['a.sczl_jtbh'] = ''; // 若为日期格式,清空该字段
|
|
|
+ } else {
|
|
|
+ $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.款式
|
|
|
- ')
|
|
|
+ a.工序名称, 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')
|
|
|
->group('a.UniqId')
|
|
|
->select();
|
|
|
|
|
|
+ // 提取所有的尺码,并去重,去除空格
|
|
|
+ $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
|
|
|
|
|
|
- // 提取所有的尺码,并去重
|
|
|
- $sizeList = array_values(array_unique(array_column($list, '尺码')));
|
|
|
-
|
|
|
- // **自定义排序规则**
|
|
|
- $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
|
|
|
-
|
|
|
+ // 自定义排序规则(已存在的排序逻辑)
|
|
|
+ $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
|
|
|
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);
|
|
|
});
|
|
|
|
|
|
@@ -1121,18 +1252,130 @@ class Manufacture extends Api
|
|
|
foreach ($list as &$item) {
|
|
|
$size = $item['尺码'];
|
|
|
$item[$size] = $item['数量'];
|
|
|
- // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
|
|
|
}
|
|
|
|
|
|
// 返回结果
|
|
|
$this->success('请求成功', [
|
|
|
'table' => $list,
|
|
|
'length' => count($list),
|
|
|
- 'headers' => $sizeList // 返回所有的尺码作为表头
|
|
|
+ 'headers' => $sizeList // 返回所有的尺码作为表头
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
|
|
|
+// public function MachineDetail()
|
|
|
+// {
|
|
|
+// if ($this->request->isGet() === false) {$this->error('请求错误');}
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)) {$this->error('参数错误');}
|
|
|
+//
|
|
|
+// $where = [];
|
|
|
+//
|
|
|
+// // 获取当前年份
|
|
|
+// $currentYear = date('Y');
|
|
|
+//
|
|
|
+// // 处理日期参数(可选)
|
|
|
+// if (!empty($param['date'])) {
|
|
|
+// // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
|
|
|
+// if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
|
|
|
+// // 如果格式为 "YYYY-MM",查询当月数据
|
|
|
+// $where['a.sys_rq'] = ['like', "{$param['date']}%"];
|
|
|
+// } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
|
|
|
+// // 如果格式为 "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.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 处理机台号参数(可选)
|
|
|
+// if (!empty($param['machine'])) {
|
|
|
+// // 判断是否为年-月格式(2025-02)
|
|
|
+// if (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
|
|
|
+// // 如果是日期格式,则设为空
|
|
|
+// $where['a.sczl_jtbh'] = '';
|
|
|
+// } else {
|
|
|
+// // 如果不是日期格式,则正常赋值
|
|
|
+// $where['a.sczl_jtbh'] = $param['machine'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if($param['machine'] === '裁剪'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'CQ' . '%'];
|
|
|
+// }else if($param['machine'] === '车缝'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'CF' . '%'];
|
|
|
+// }else if($param['machine'] === '手工'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'HD' . '%'];
|
|
|
+// }else if($param['machine'] === '大烫'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'DT' . '%'];
|
|
|
+// }else if($param['machine'] === '总检'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'ZJ' . '%'];
|
|
|
+// }else if($param['machine'] === '包装'){
|
|
|
+// $where['a.sczl_jtbh'] = ['like', '%' . 'BZ' . '%'];
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// // 查询数据
|
|
|
+// $list = \db('设备_产量计酬')->alias('a')
|
|
|
+// ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
|
|
|
+// ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
|
|
|
+// ->field('
|
|
|
+// a.工序名称,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')
|
|
|
+// ->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['数量']); // 如果不需要保留原字段,可以取消注释
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 返回结果
|
|
|
+// $this->success('请求成功', [
|
|
|
+// 'table' => $list,
|
|
|
+// 'length' => count($list),
|
|
|
+// 'headers' => $sizeList // 返回所有的尺码作为表头
|
|
|
+// ]);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 工单审核
|
|
|
* @return void
|