|
|
@@ -724,42 +724,59 @@ class WorkOrder extends Api
|
|
|
if (empty($param)){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
- $UniqId = [];
|
|
|
- $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
|
|
|
- if ($lastId['id']>10000000){
|
|
|
- $lastUniqId = $lastId['id'];
|
|
|
- }else{
|
|
|
- $lastUniqId = 10000000;
|
|
|
- }
|
|
|
- foreach ($param as $key=>$value){
|
|
|
- $UniqId[$key] = $value['UniqId'];
|
|
|
- }
|
|
|
- $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
|
|
|
- if (empty($processList)){
|
|
|
- $this->success('未找到工艺资料');
|
|
|
- }
|
|
|
- $data = [];
|
|
|
- foreach ($param as $key=>$value){
|
|
|
- foreach ($processList as $k=>$v){
|
|
|
- if ($value['UniqId'] = $v['UniqId']){
|
|
|
- $data[$key] = $v;
|
|
|
- $data[$key]['Gy0_gxh'] = $value['gxh'];
|
|
|
- $data[$key]['Gy0_gdbh'] = $value['workOrder'];
|
|
|
- $data[$key]['UniqId'] = $lastUniqId + $key + 1;
|
|
|
- }
|
|
|
+ $i = 0;
|
|
|
+ foreach ($param as $key => $value){
|
|
|
+ $sql = \db('工单_工艺资料')
|
|
|
+ ->where('UniqId',$value['UniqId'])
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->update(['Gy0_gxh'=>$value['gxh']]);
|
|
|
+ $res = \db()->query($sql);
|
|
|
+ if ($res === false){
|
|
|
+ $i++;
|
|
|
}
|
|
|
}
|
|
|
- $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
|
|
|
- if ($res !== false){
|
|
|
- $result = \db('工单_工艺资料')->insertAll($data);
|
|
|
- if ($result !== false){
|
|
|
- $this->success('成功');
|
|
|
- }else{
|
|
|
- $this->error('失败');
|
|
|
- }
|
|
|
+ if ($i === 0){
|
|
|
+ $this->success('成功');
|
|
|
}else{
|
|
|
$this->error('失败');
|
|
|
}
|
|
|
+// $UniqId = [];
|
|
|
+// $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
|
|
|
+// if ($lastId['id']>10000000){
|
|
|
+// $lastUniqId = $lastId['id'];
|
|
|
+// }else{
|
|
|
+// $lastUniqId = 10000000;
|
|
|
+// }
|
|
|
+// foreach ($param as $key=>$value){
|
|
|
+// $UniqId[$key] = $value['UniqId'];
|
|
|
+// }
|
|
|
+// $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
|
|
|
+// if (empty($processList)){
|
|
|
+// $this->success('未找到工艺资料');
|
|
|
+// }
|
|
|
+// halt($processList);
|
|
|
+// $data = [];
|
|
|
+// foreach ($param as $key=>$value){
|
|
|
+// foreach ($processList as $k=>$v){
|
|
|
+// if ($value['UniqId'] = $v['UniqId']){
|
|
|
+// $data[$key] = $v;
|
|
|
+// $data[$key]['Gy0_gxh'] = $value['gxh'];
|
|
|
+// $data[$key]['Gy0_gdbh'] = $value['workOrder'];
|
|
|
+// $data[$key]['UniqId'] = $lastUniqId + $key + 1;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
|
|
|
+// if ($res !== false){
|
|
|
+// $result = \db('工单_工艺资料')->insertAll($data);
|
|
|
+// if ($result !== false){
|
|
|
+// $this->success('成功');
|
|
|
+// }else{
|
|
|
+// $this->error('失败');
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// $this->error('失败');
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -952,7 +969,6 @@ class WorkOrder extends Api
|
|
|
$value['gxh'] = '0'.$value['gxh'];
|
|
|
}
|
|
|
$list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
|
|
|
- unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
|
|
|
}
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
@@ -1109,11 +1125,15 @@ class WorkOrder extends Api
|
|
|
$param['Mod_rq'] = date('Y-m-d H:i:s',time());
|
|
|
$UniqId = $param['UniqId'];
|
|
|
unset($param['UniqId']);
|
|
|
+ //获取工单第一道工艺编号
|
|
|
+ $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
|
|
|
//修改工艺资料
|
|
|
$sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
|
|
|
$res = Db::query($sql);
|
|
|
//获取工艺资料数据
|
|
|
$list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
|
|
|
+ //如果是第一道工序需从印件资料中获取计划产量
|
|
|
+ $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
|
|
|
//修改工单状态
|
|
|
$status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
|
|
|
if ($status['status'] !== '2-生产中'){
|
|
|
@@ -1122,7 +1142,7 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
//重新分配工序计划产量
|
|
|
if ((int)$list['计划接货数'] > 0){
|
|
|
- $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
|
|
|
+ $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
|
|
|
}
|
|
|
if ($res !== false){
|
|
|
$this->success('成功');
|
|
|
@@ -1149,6 +1169,7 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
$list = \db('设备_基本资料')
|
|
|
->where('使用部门',$param['address'])
|
|
|
+ ->where('sys_sbID','<>','')
|
|
|
->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
|
|
|
->order('设备编组,设备编号')
|
|
|
->select();
|
|
|
@@ -1373,7 +1394,6 @@ class WorkOrder extends Api
|
|
|
$value['gxh'] = '0'.$value['gxh'];
|
|
|
}
|
|
|
if ($value['add_gxmc'] !== null){
|
|
|
-
|
|
|
$list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
|
|
|
}else{
|
|
|
$list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
|
|
|
@@ -1421,7 +1441,7 @@ class WorkOrder extends Api
|
|
|
/**
|
|
|
* 新增工单->添加工单
|
|
|
* @ApiMethod (POST)
|
|
|
- * @param
|
|
|
+ * @param
|
|
|
* @return void
|
|
|
* @throws \think\Exception
|
|
|
* @throws \think\db\exception\BindParamException
|
|
|
@@ -1489,8 +1509,8 @@ class WorkOrder extends Api
|
|
|
'Gd_khmc' =>$param['khmc'],
|
|
|
'客户料号' =>rtrim($productDetail['客户料号']),
|
|
|
'客户ERP编码' =>$param['erp'],
|
|
|
- 'Gd_cpdh' =>$param['cpdh'],
|
|
|
- 'Gd_cpmc' =>$param['cpmc'],
|
|
|
+ 'Gd_cpdh' =>'',
|
|
|
+ 'Gd_cpmc' =>'',
|
|
|
'成品代号' =>$param['cpdh'],
|
|
|
'成品名称' =>$param['cpmc'],
|
|
|
'产品版本号' =>$param['bbh'],
|
|
|
@@ -1642,6 +1662,7 @@ class WorkOrder extends Api
|
|
|
$list = \db('产品_基本资料')
|
|
|
->where($where)
|
|
|
->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
|
|
|
+ ->limit(50)
|
|
|
->select();
|
|
|
if (empty($list)){
|
|
|
$this->success('未获取到产品数据');
|
|
|
@@ -1678,9 +1699,39 @@ class WorkOrder extends Api
|
|
|
$param['Uniqid'] = $lastId;
|
|
|
$param['Sys_rq'] = date('Y-m-d H:i:s',time());
|
|
|
$param['Mod_rq'] = date('Y-m-d H:i:s',time());
|
|
|
- $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
|
|
|
- $res = \db()->query($sql);
|
|
|
- if ($res !== false){
|
|
|
+ //判断印件号是否存在在工单基本资料表中,存在不增加行号,不存在增加行号
|
|
|
+ if (empty(\db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->where('行号',$param['yj_Yjno'])->find())){
|
|
|
+ $list = \db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->find();
|
|
|
+ $list['行号'] = $param['yj_Yjno'];
|
|
|
+ $list['Gd_cpdh'] = $param['yj_Yjdh'];
|
|
|
+ $list['Gd_cpmc'] = $param['yj_yjmc'];
|
|
|
+ $list['Sys_id'] = $param['Sys_id'];
|
|
|
+ $list['Sys_rq'] = $param['Sys_rq'];
|
|
|
+ $list['Mod_rq'] = $param['Mod_rq'];
|
|
|
+ unset($list['Uniqid']);
|
|
|
+ $workSql = \db('工单_基本资料')->fetchSql(true)->insert($list);
|
|
|
+ }else{
|
|
|
+ $data['Gd_cpdh'] = $param['yj_Yjdh'];
|
|
|
+ $data['Gd_cpmc'] = $param['yj_yjmc'];
|
|
|
+ $workSql = \db('工单_基本资料')
|
|
|
+ ->where('Gd_gdbh',$param['Yj_Gdbh'])
|
|
|
+ ->where('行号',$param['yj_Yjno'])
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->update($data);
|
|
|
+ }
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
|
|
|
+ $res = \db()->query($sql);
|
|
|
+ $workRes = \db()->query($workSql);
|
|
|
+ //提交事务
|
|
|
+ \db()->commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ \db()->rollback();
|
|
|
+ }
|
|
|
+ if ($res !== false && $workRes !== false){
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('失败');
|
|
|
@@ -1734,7 +1785,7 @@ class WorkOrder extends Api
|
|
|
->value('rtrim(yj_平张投料)');
|
|
|
//分配工艺计划产量
|
|
|
if ((int)$number >0){
|
|
|
- $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
|
|
|
+ $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],0,$number);
|
|
|
}
|
|
|
if ($res !== false){
|
|
|
$this->success('成功');
|
|
|
@@ -1873,6 +1924,9 @@ class WorkOrder extends Api
|
|
|
if (empty($param['process'])){
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
+ if (strlen($param['process'])>6){
|
|
|
+ $param['process'] = substr($param['process'],0,6);
|
|
|
+ }
|
|
|
$order = \db('dic_lzsh')
|
|
|
->where('sys_mc','like',$param['process'].'%')
|
|
|
->value('rtrim(sys_bh) as 编号');
|
|
|
@@ -1920,7 +1974,7 @@ class WorkOrder extends Api
|
|
|
'附件类型',
|
|
|
'适用工序',
|
|
|
'关联产品'
|
|
|
- ];
|
|
|
+ ];
|
|
|
$data = [];
|
|
|
foreach ($arr as $key => $value){
|
|
|
if (!isset($req[$value])){
|
|
|
@@ -1951,7 +2005,7 @@ class WorkOrder extends Api
|
|
|
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 产品附件修改
|
|
|
* @ApiMethod (GET)
|
|
|
@@ -2025,7 +2079,7 @@ class WorkOrder extends Api
|
|
|
'附件内容',
|
|
|
'附件类型',
|
|
|
'关联编号'
|
|
|
- ];
|
|
|
+ ];
|
|
|
$data = [];
|
|
|
foreach ($arr as $key => $value){
|
|
|
if (!isset($req[$value])){
|
|
|
@@ -2056,7 +2110,7 @@ class WorkOrder extends Api
|
|
|
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 产品附件修改
|
|
|
* @ApiMethod (GET)
|
|
|
@@ -2251,6 +2305,9 @@ class WorkOrder extends Api
|
|
|
//设置默认机台
|
|
|
$machineList = \db('设备_基本资料')
|
|
|
->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
|
|
|
+ ->where('使用部门','<>','研发中心')
|
|
|
+ ->where('设备编组','<>','')
|
|
|
+ ->where('sys_sbID','<>','')
|
|
|
->order('设备编号')
|
|
|
->value('设备编号');
|
|
|
$ProcessList[$key]['Gy0_sbbh'] = '';
|
|
|
@@ -2362,18 +2419,11 @@ class WorkOrder extends Api
|
|
|
*/
|
|
|
public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
|
|
|
{
|
|
|
- if ($gxh === 0){
|
|
|
- $where = [
|
|
|
- 'Gy0_gdbh'=>$workOrder,
|
|
|
- 'Gy0_yjno'=>$yjno,
|
|
|
- ];
|
|
|
- }else{
|
|
|
- $where = [
|
|
|
- 'Gy0_gdbh'=>$workOrder,
|
|
|
- 'Gy0_yjno'=>$yjno,
|
|
|
- 'Gy0_gxh'=>['>=',$gxh]
|
|
|
- ];
|
|
|
- }
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'Gy0_gdbh'=>$workOrder,
|
|
|
+ 'Gy0_yjno'=>$yjno,
|
|
|
+ ];
|
|
|
//获取工艺资料
|
|
|
$processList = \db('工单_工艺资料')
|
|
|
->where($where)
|
|
|
@@ -2387,26 +2437,39 @@ class WorkOrder extends Api
|
|
|
$production = [];
|
|
|
$i = 0;
|
|
|
foreach ($processList as $key=>$value){
|
|
|
+// if ($key === 0){
|
|
|
+// array_push($production,$feed);
|
|
|
+// }
|
|
|
+// $wastage = 0;
|
|
|
+// if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
|
|
|
+// $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
|
|
|
+// $wastage = round($wastage * $value['Gy0_ms']);
|
|
|
+// }
|
|
|
+// if ((int)$value['Gy0_ls'] === 1 && $key>=1){
|
|
|
+// $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
|
|
|
+// }else{
|
|
|
+// $number = $production[$key];
|
|
|
+// }
|
|
|
+// if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
|
|
|
+// $number = $number/(int)$value['Gy0_ls'];
|
|
|
+// }
|
|
|
+// array_push($production,ceil($number-$wastage));
|
|
|
if ($key === 0){
|
|
|
array_push($production,$feed);
|
|
|
+ }else{
|
|
|
+ $production[$key] = $production[$key]/$value['Gy0_ls'];
|
|
|
}
|
|
|
$wastage = 0;
|
|
|
if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
|
|
|
$wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
|
|
|
}
|
|
|
-
|
|
|
if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
|
|
|
$wastage = round($wastage * $value['Gy0_ms']);
|
|
|
}
|
|
|
- if ((int)$value['Gy0_ls'] === 1 && $key>=1){
|
|
|
- $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
|
|
|
- }else{
|
|
|
- $number = $production[$key];
|
|
|
- }
|
|
|
- if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
|
|
|
- $number = $number/(int)$value['Gy0_ls'];
|
|
|
- }
|
|
|
- array_push($production,ceil($number-$wastage));
|
|
|
+ array_push($production,ceil($production[$key]-$wastage)*$value['Gy0_ls']);
|
|
|
$processSql = \db('工单_工艺资料')
|
|
|
->where('UniqId',$value['UniqId'])
|
|
|
->fetchSql(true)
|
|
|
@@ -2522,4 +2585,4 @@ class WorkOrder extends Api
|
|
|
$list['工序号'] = $process + 1;
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
-}
|
|
|
+}
|