|
@@ -26,51 +26,61 @@ class Course extends Api
|
|
|
*/
|
|
*/
|
|
|
public function getTab()
|
|
public function getTab()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
|
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
$this->error('请求错误');
|
|
|
}
|
|
}
|
|
|
- //获取总计划中数量和总生产中数量
|
|
|
|
|
- $productingAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
|
|
|
|
|
- $progressAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
|
|
|
|
|
|
|
+ $customers = \db('产品_基本资料')
|
|
|
|
|
+ ->where('客户编号', '<>', '')
|
|
|
|
|
+ ->field('rtrim(客户编号) as 客户编号, MAX(rtrim(客户名称)) as 客户名称')
|
|
|
|
|
+ ->group('客户编号')
|
|
|
|
|
+ ->order('客户编号 asc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (empty($customers)) {
|
|
|
|
|
+ $this->success('', []);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $productCodes = \db('工单_基本资料')
|
|
|
|
|
+ ->where('行号', '1')
|
|
|
|
|
+ ->where('成品代号', '<>', '')
|
|
|
|
|
+ ->where('gd_statu', 'in', ['2-生产中', '3-计划中'])
|
|
|
|
|
+ ->distinct(true)
|
|
|
|
|
+ ->column('成品代号');
|
|
|
|
|
+ $codesByInitial = [];
|
|
|
|
|
+ foreach ($productCodes as $productCode) {
|
|
|
|
|
+ $productCode = rtrim((string)$productCode);
|
|
|
|
|
+ if ($productCode === '') {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $codesByInitial[$productCode[0]][] = $productCode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$data = [
|
|
$data = [
|
|
|
'印刷工单' => [],
|
|
'印刷工单' => [],
|
|
|
- '糊盒工单' => []
|
|
|
|
|
|
|
+ '糊盒工单' => [],
|
|
|
];
|
|
];
|
|
|
- $sql = "SELECT DISTINCT
|
|
|
|
|
- (客户编号),rtrim(客户名称 ) as 客户名称
|
|
|
|
|
- FROM
|
|
|
|
|
- `产品_基本资料`
|
|
|
|
|
- WHERE
|
|
|
|
|
- 客户编号 <> ''
|
|
|
|
|
- GROUP BY
|
|
|
|
|
- 客户编号
|
|
|
|
|
- order by
|
|
|
|
|
- 客户编号";
|
|
|
|
|
- $list = \db()->query($sql);
|
|
|
|
|
- if (empty($list)){
|
|
|
|
|
- $this->success('',[]);
|
|
|
|
|
- }
|
|
|
|
|
- foreach ($list as $key=>$value){
|
|
|
|
|
- $value['客户编号'] = rtrim($value['客户编号']);
|
|
|
|
|
- $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
|
|
|
|
|
- $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
|
|
|
|
|
- $string = '';
|
|
|
|
|
- if ($productIng != 0){
|
|
|
|
|
- $string = $string."生产中:".$productIng;
|
|
|
|
|
- }
|
|
|
|
|
- if ($proGress != 0){
|
|
|
|
|
- $string = $string."计划中:".$proGress;
|
|
|
|
|
|
|
+ foreach ($customers as $value) {
|
|
|
|
|
+ $customerCode = rtrim((string)$value['客户编号']);
|
|
|
|
|
+ if ($customerCode === '') {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if ($string !== ''){
|
|
|
|
|
- $name = $value['客户编号'].$value['客户名称'];
|
|
|
|
|
- if (strpos($value['客户编号'],'J') !== false){
|
|
|
|
|
- array_push($data['糊盒工单'],$name);
|
|
|
|
|
- }else{
|
|
|
|
|
- array_push($data['印刷工单'],$name);
|
|
|
|
|
|
|
+ $matched = false;
|
|
|
|
|
+ foreach ($codesByInitial[$customerCode[0]] ?? [] as $productCode) {
|
|
|
|
|
+ if (stripos($productCode, $customerCode) === 0) {
|
|
|
|
|
+ $matched = true;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!$matched) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $name = $customerCode . $value['客户名称'];
|
|
|
|
|
+ if (strpos($customerCode, 'J') !== false) {
|
|
|
|
|
+ $data['糊盒工单'][] = $name;
|
|
|
|
|
+ } elseif (strpos($customerCode, 'Y') !== false) {
|
|
|
|
|
+ $data['印刷工单'][] = $name;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- $this->success('成功',$data);
|
|
|
|
|
|
|
+ $this->success('成功', $data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -83,47 +93,84 @@ class Course extends Api
|
|
|
*/
|
|
*/
|
|
|
public function workOrderDetail()
|
|
public function workOrderDetail()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
|
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
$this->error('请求错误');
|
|
|
}
|
|
}
|
|
|
$param = $this->request->param();
|
|
$param = $this->request->param();
|
|
|
$where = [];
|
|
$where = [];
|
|
|
- if (!empty($param['order'])){
|
|
|
|
|
- $where['a.Gd_cpdh|a.成品代号'] = ['like',$param['order'].'%'];
|
|
|
|
|
|
|
+ if (!empty($param['order'])) {
|
|
|
|
|
+ $where['a.Gd_cpdh|a.成品代号'] = ['like', $param['order'] . '%'];
|
|
|
}
|
|
}
|
|
|
- if (!empty($param['search'])){
|
|
|
|
|
- $where['a.Gd_gdbh'] = ['like','%'.$param['search'].'%'];
|
|
|
|
|
|
|
+ if (!empty($param['search'])) {
|
|
|
|
|
+ $where['a.Gd_gdbh'] = ['like', '%' . $param['search'] . '%'];
|
|
|
}
|
|
}
|
|
|
$list = \db('工单_基本资料')
|
|
$list = \db('工单_基本资料')
|
|
|
->alias('a')
|
|
->alias('a')
|
|
|
- ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh')
|
|
|
|
|
|
|
+ ->join('工单_印件资料 b', 'a.Gd_gdbh = b.Yj_Gdbh')
|
|
|
->field('b.Yj_Gdbh as 工单编号,b.yj_Yjno,b.yj_Yjdh as 印件代号,b.yj_yjmc as 印件名称,b.yj_ls as 联数,a.投料大箱 as 投料大箱,b.yj_平张投料 as 计划投料')
|
|
->field('b.Yj_Gdbh as 工单编号,b.yj_Yjno,b.yj_Yjdh as 印件代号,b.yj_yjmc as 印件名称,b.yj_ls as 联数,a.投料大箱 as 投料大箱,b.yj_平张投料 as 计划投料')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
- ->where('gd_statu','2-生产中')
|
|
|
|
|
|
|
+ ->where('a.gd_statu', '2-生产中')
|
|
|
->group('b.Yj_Gdbh,b.yj_Yjno')
|
|
->group('b.Yj_Gdbh,b.yj_Yjno')
|
|
|
->select();
|
|
->select();
|
|
|
- if (empty($list)){
|
|
|
|
|
|
|
+ if (empty($list)) {
|
|
|
$this->success('');
|
|
$this->success('');
|
|
|
}
|
|
}
|
|
|
- foreach ($list as $key=>$value){
|
|
|
|
|
- $process = \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')
|
|
|
|
|
- ->where('a.Gy0_gdbh',$value['工单编号'])
|
|
|
|
|
- ->where('a.Gy0_yjno',$value['yj_Yjno'])
|
|
|
|
|
- ->field('a.Gy0_gxh,a.Gy0_gxmc,a.PD_WG,SUM(b.sczl_cl) as 产量')
|
|
|
|
|
- ->group('a.Gy0_gxh')
|
|
|
|
|
- ->select();
|
|
|
|
|
- foreach ($process as $k=>$v){
|
|
|
|
|
- $status = '';
|
|
|
|
|
- if ($v['PD_WG'] !== '1900-01-01 00:00:00'){
|
|
|
|
|
- $status = '完工';
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $orderNos = [];
|
|
|
|
|
+ foreach ($list as $row) {
|
|
|
|
|
+ $orderNos[$row['工单编号']] = $row['工单编号'];
|
|
|
|
|
+ }
|
|
|
|
|
+ $processRows = \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')
|
|
|
|
|
+ ->where('a.Gy0_gdbh', 'in', array_values($orderNos))
|
|
|
|
|
+ ->field('a.Gy0_gdbh, a.Gy0_yjno, a.Gy0_gxh, a.Gy0_gxmc, a.PD_WG, SUM(b.sczl_cl) as 产量')
|
|
|
|
|
+ ->group('a.Gy0_gdbh, a.Gy0_yjno, a.Gy0_gxh')
|
|
|
|
|
+ ->order('a.Gy0_gxh asc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ $latestNumSql = \db('设备_产量计酬')
|
|
|
|
|
+ ->where('sczl_gdbh', 'in', array_values($orderNos))
|
|
|
|
|
+ ->field('sczl_gdbh, sczl_yjno, sczl_gxh, MAX(sczl_num) as max_num')
|
|
|
|
|
+ ->group('sczl_gdbh, sczl_yjno, sczl_gxh')
|
|
|
|
|
+ ->buildSql();
|
|
|
|
|
+ $latestRows = \db('设备_产量计酬')
|
|
|
|
|
+ ->alias('t')
|
|
|
|
|
+ ->join([$latestNumSql => 'm'], 't.sczl_gdbh = m.sczl_gdbh AND t.sczl_yjno = m.sczl_yjno AND t.sczl_gxh = m.sczl_gxh AND t.sczl_num = m.max_num')
|
|
|
|
|
+ ->field('t.sczl_gdbh, t.sczl_yjno, t.sczl_gxh, rtrim(t.sczl_num) as sczl_num, MAX(t.sczl_rq) as sczl_rq')
|
|
|
|
|
+ ->group('t.sczl_gdbh, t.sczl_yjno, t.sczl_gxh, t.sczl_num')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ $latestMap = [];
|
|
|
|
|
+ foreach ($latestRows as $latest) {
|
|
|
|
|
+ $latestKey = rtrim((string)$latest['sczl_gdbh']) . '|' . rtrim((string)$latest['sczl_yjno']) . '|' . (int)$latest['sczl_gxh'];
|
|
|
|
|
+ $latestMap[$latestKey] = $latest;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $processMap = [];
|
|
|
|
|
+ foreach ($processRows as $process) {
|
|
|
|
|
+ $mapKey = rtrim((string)$process['Gy0_gdbh']) . '|' . rtrim((string)$process['Gy0_yjno']);
|
|
|
|
|
+ $processMap[$mapKey][] = $process;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
|
|
+ $mapKey = rtrim((string)$value['工单编号']) . '|' . rtrim((string)$value['yj_Yjno']);
|
|
|
|
|
+ $index = 1;
|
|
|
|
|
+ foreach ($processMap[$mapKey] ?? [] as $process) {
|
|
|
|
|
+ $status = ($process['PD_WG'] !== '1900-01-01 00:00:00') ? '完工' : '';
|
|
|
|
|
+ $latestKey = rtrim((string)$process['Gy0_gdbh']) . '|' . rtrim((string)$process['Gy0_yjno']) . '|' . (int)$process['Gy0_gxh'];
|
|
|
|
|
+ $latest = $latestMap[$latestKey] ?? [];
|
|
|
|
|
+ $flowNo = rtrim((string)($latest['sczl_num'] ?? ''));
|
|
|
|
|
+ if ($flowNo === '0') {
|
|
|
|
|
+ $flowNo = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $reportDate = (string)($latest['sczl_rq'] ?? '');
|
|
|
|
|
+ if ($reportDate !== '') {
|
|
|
|
|
+ $reportDate = substr($reportDate, 0, 10);
|
|
|
}
|
|
}
|
|
|
- $k++;
|
|
|
|
|
- $list[$key]['工序'.$k] = $value['yj_Yjno'].'-'.$v['Gy0_gxh'].'-'.rtrim($v['Gy0_gxmc']).'['.$v['产量'].'/'.']'.$status;
|
|
|
|
|
|
|
+ $list[$key]['工序' . $index] = $value['yj_Yjno'] . '-' . $process['Gy0_gxh'] . '-' . rtrim((string)$process['Gy0_gxmc']) . '[' . $process['产量'] . '/' . ']' . $status . '[' . $flowNo . '/' . $reportDate . ']';
|
|
|
|
|
+ $index++;
|
|
|
}
|
|
}
|
|
|
unset($list[$key]['yj_Yjno']);
|
|
unset($list[$key]['yj_Yjno']);
|
|
|
}
|
|
}
|
|
|
- $this->success('成功',$list);
|
|
|
|
|
|
|
+ $this->success('成功', $list);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|