|
|
@@ -63,7 +63,7 @@ class WorkOrderProcess extends Api
|
|
|
->order('part_code')
|
|
|
->select();
|
|
|
if(empty($list)){
|
|
|
- $this->error('该工单没有部件,请先添加部件');
|
|
|
+ // $this->error('该工单没有部件,请先添加部件');
|
|
|
}
|
|
|
$this->success('成功', $list);
|
|
|
}
|
|
|
@@ -89,7 +89,7 @@ class WorkOrderProcess extends Api
|
|
|
if (empty($params['part_name'])) {
|
|
|
$this->error('部件名称不能为空');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否传入了part_code
|
|
|
if (!empty($params['part_code'])) {
|
|
|
$code = $params['part_code'];
|
|
|
@@ -98,7 +98,7 @@ class WorkOrderProcess extends Api
|
|
|
->where('work_order', $params['workorder'])
|
|
|
->where('part_code', '>=', $code)
|
|
|
->count();
|
|
|
-
|
|
|
+
|
|
|
if ($exists > 0) {
|
|
|
// 如果存在冲突,将后续编号自动加1
|
|
|
db('工单_部件资料')
|
|
|
@@ -113,7 +113,7 @@ class WorkOrderProcess extends Api
|
|
|
->max('part_code');
|
|
|
$code = $code ? $code + 1 : 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$data = [
|
|
|
'work_order' => $params['workorder'],
|
|
|
'part_code' => $code,
|
|
|
@@ -209,39 +209,39 @@ class WorkOrderProcess extends Api
|
|
|
if (!$this->request->isPost()) {
|
|
|
$this->error('请求方法错误');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$params = $this->request->post();
|
|
|
if (empty($params['id'])) {
|
|
|
$this->error('部件ID不能为空');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$ids = explode(',', $params['id']);
|
|
|
$ids = array_filter(array_map('intval', $ids));
|
|
|
-
|
|
|
+
|
|
|
if (empty($ids)) {
|
|
|
$this->error('无效的部件ID');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = db('工单_部件资料')
|
|
|
->whereIn('id', $ids)
|
|
|
->whereNull('del_rq')
|
|
|
->update(['del_rq' => date('Y-m-d H:i:s')]);
|
|
|
-
|
|
|
+
|
|
|
if ($result === false) {
|
|
|
$this->error('删除失败');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if ($result === 0) {
|
|
|
$this->error('未找到可删除的部件');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$this->success('删除成功');
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 工单工艺列表
|
|
|
- * @param workorder 工单编号
|
|
|
+ * @param workorder 工单编号
|
|
|
*/
|
|
|
public function GetProcessList()
|
|
|
{
|
|
|
@@ -252,22 +252,59 @@ class WorkOrderProcess extends Api
|
|
|
if (empty($params['workorder'])) {
|
|
|
$this->error('工单编号不能为空');
|
|
|
}
|
|
|
+
|
|
|
$list = db('工单_基础工艺资料')
|
|
|
->alias('a')
|
|
|
- ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order')
|
|
|
+ ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order', 'LEFT')
|
|
|
->where('a.del_rq', null)
|
|
|
->where('a.work_order', $params['workorder'])
|
|
|
->where('b.del_rq', null)
|
|
|
- ->field('a.id,a.part_code as 部件编号,b.part_name as 部件名称,a.process_code as 工艺编号,
|
|
|
- a.process_name as 工艺名称,a.big_process as 大工艺,a.standard_hour as 标准工时,
|
|
|
- a.standard_score as 标准公分,a.remark as 备注,a.coefficient as 系数,a.sys_id as 系统人,a.sys_rq as 系统时间,a.mod_id as 修改人,
|
|
|
- a.mod_rq as 修改时间')
|
|
|
- ->order('process_code')
|
|
|
+ ->field('a.id,a.part_code as 部件编号,
|
|
|
+ IFNULL(b.part_name, "") as 部件名称,
|
|
|
+ a.process_code as 工艺编号,
|
|
|
+ a.process_name as 工艺名称,
|
|
|
+ a.big_process as 大工艺,
|
|
|
+ a.standard_hour as 标准工时,
|
|
|
+ a.standard_score as 标准公分,
|
|
|
+ a.remark as 备注,
|
|
|
+ a.coefficient as 系数,
|
|
|
+ a.sys_id as 系统人,
|
|
|
+ a.sys_rq as 系统时间,
|
|
|
+ a.mod_id as 修改人,
|
|
|
+ a.mod_rq as 修改时间')
|
|
|
+ ->order('a.id')
|
|
|
->select();
|
|
|
+
|
|
|
$this->success('成功', $list);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 工单工艺列表
|
|
|
+ * @param workorder 工单编号
|
|
|
+ */
|
|
|
+ // public function GetProcessList()
|
|
|
+ // {
|
|
|
+ // if (!$this->request->isGet()) {
|
|
|
+ // $this->error('请求方法错误');
|
|
|
+ // }
|
|
|
+ // $params = $this->request->param();
|
|
|
+ // if (empty($params['workorder'])) {
|
|
|
+ // $this->error('工单编号不能为空');
|
|
|
+ // }
|
|
|
+ // $list = db('工单_基础工艺资料')
|
|
|
+ // ->alias('a')
|
|
|
+ // ->join('工单_部件资料 b', 'a.part_code = b.part_code and a.work_order = b.work_order')
|
|
|
+ // ->where('a.del_rq', null)
|
|
|
+ // ->where('a.work_order', $params['workorder'])
|
|
|
+ // ->where('b.del_rq', null)
|
|
|
+ // ->field('a.id,a.part_code as 部件编号,b.part_name as 部件名称,a.process_code as 序号,
|
|
|
+ // a.process_name as 工序名称,a.big_process as 大工艺,a.standard_hour as 秒,a.standard_minutes as 分钟,
|
|
|
+ // a.standard_score as 标准公分,a.money as 金额,a.remark as 备注,a.coefficient as 难度系数,a.sys_id as 操作人员,
|
|
|
+ // a.sys_rq as 系统时间,a.mod_id as 修改人,a.mod_rq as 修改时间')
|
|
|
+ // ->order('process_code')
|
|
|
+ // ->select();
|
|
|
+ // $this->success('成功', $list);
|
|
|
+ // }
|
|
|
/**
|
|
|
* 获取部件列表
|
|
|
* @param workorder 工单编号
|
|
|
@@ -281,7 +318,7 @@ class WorkOrderProcess extends Api
|
|
|
if (empty($params['workorder'])) {
|
|
|
$this->error('工单编号不能为空');
|
|
|
}
|
|
|
- $list = db('工单_部件资料')
|
|
|
+ $list = db('工单_部件资料')
|
|
|
->where('work_order', $params['workorder'])
|
|
|
->where('del_rq', null)
|
|
|
->field('part_code as 部件编号,part_name as 部件名称')
|
|
|
@@ -336,7 +373,7 @@ class WorkOrderProcess extends Api
|
|
|
if (empty($params['sys_id'])) {
|
|
|
$this->error('系统人不能为空');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查是否传入了process_code
|
|
|
if (!empty($params['process_code'])) {
|
|
|
$code = $params['process_code'];
|
|
|
@@ -346,7 +383,7 @@ class WorkOrderProcess extends Api
|
|
|
->where('part_code', $params['part_code'])
|
|
|
->where('process_code', '>=', $code)
|
|
|
->count();
|
|
|
-
|
|
|
+
|
|
|
if ($exists > 0) {
|
|
|
// 如果存在冲突,将后续编号自动加1
|
|
|
db('工单_基础工艺资料')
|
|
|
@@ -363,7 +400,7 @@ class WorkOrderProcess extends Api
|
|
|
->max('process_code');
|
|
|
$code = $code ? $code + 1 : 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$data = [
|
|
|
'work_order' => $params['workorder'],
|
|
|
'part_code' => $params['part_code'],
|
|
|
@@ -484,8 +521,8 @@ class WorkOrderProcess extends Api
|
|
|
/**
|
|
|
* 工单工艺复制
|
|
|
* @param workorder 工单编号
|
|
|
- * @param product_code 产品编号
|
|
|
- * @param sys_id 操作人
|
|
|
+ * @param product_code 产品编号
|
|
|
+ * @param sys_id 操作人
|
|
|
* @return array
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
@@ -664,12 +701,12 @@ class WorkOrderProcess extends Api
|
|
|
|
|
|
$this->success('排序成功');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 工单工艺excel导入
|
|
|
* @param workorder 工单编号
|
|
|
- *
|
|
|
+ *
|
|
|
*/
|
|
|
public function importProcess()
|
|
|
{
|
|
|
@@ -845,4 +882,154 @@ class WorkOrderProcess extends Api
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取工单信息和工单制造工分
|
|
|
+ * @param workorder 工单编号
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function getWorkOrderInfo()
|
|
|
+ {
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->param();
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
+ }
|
|
|
+ $where = [
|
|
|
+ '订单编号' => $params['workorder'],
|
|
|
+ 'Mod_rq' => null,
|
|
|
+ ];
|
|
|
+ $workOrderInfo = Db::table('工单_基本资料')
|
|
|
+ ->where($where)
|
|
|
+ ->field('订单编号,客户编号,生产款号,款式,落货日期,审核日期,接单日期,审核,订单数量,计划制造工分,Uniqid')
|
|
|
+ ->find();
|
|
|
+ if (empty($workOrderInfo)) {
|
|
|
+ $this->error('工单不存在');
|
|
|
+ }
|
|
|
+ $this->success('成功', $workOrderInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取工单工艺信息
|
|
|
+ * @param workorder 工单编号
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function getWorkOrderProcess()
|
|
|
+ {
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->param();
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
+ }
|
|
|
+ $where = [
|
|
|
+ 'work_order' => $params['workorder'],
|
|
|
+ 'del_rq' => null,
|
|
|
+ ];
|
|
|
+ $workOrderProcess = Db::table('工单_基础工艺资料')
|
|
|
+ ->where($where)
|
|
|
+ ->field('id,part_code as 部件编号,part_name as 部件名称,process_code as 工序编号,process_name as 工序名称,
|
|
|
+ big_process as 大工序,standard_hour as 秒,standard_minutes as 分,standard_score as 定额分,money as 金额,
|
|
|
+ coefficient as 难度系数,remark as 备注,status as 状态')
|
|
|
+ ->select();
|
|
|
+ if (empty($workOrderProcess)) {
|
|
|
+ $this->error('工单工艺不存在');
|
|
|
+ }
|
|
|
+ $this->success('成功', $workOrderProcess);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改工单计划制造工分
|
|
|
+ * @param id 工单Uniqid或订单编号
|
|
|
+ * @param number 计划制造工分
|
|
|
+ * @param sys_id 操作人
|
|
|
+ */
|
|
|
+ public function updateWorkOrderPlanManufacture()
|
|
|
+ {
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->post();
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('工单ID不能为空');
|
|
|
+ }
|
|
|
+ if (!isset($params['number']) || $params['number'] === '') {
|
|
|
+ $this->error('制造工分不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['sys_id'])) {
|
|
|
+ $this->error('操作人不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ $workOrder = Db::table('工单_基本资料')
|
|
|
+ ->where('Uniqid|订单编号', $params['id'])
|
|
|
+ ->where('Mod_rq', null)
|
|
|
+ ->field('Uniqid,订单编号,计划制造工分')
|
|
|
+ ->find();
|
|
|
+ if (empty($workOrder)) {
|
|
|
+ $this->error('工单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $oldValue = $workOrder['计划制造工分'];
|
|
|
+ $newValue = $params['number'];
|
|
|
+ if ((string)$oldValue === (string)$newValue) {
|
|
|
+ $this->error('计划制造工分未发生变化');
|
|
|
+ }
|
|
|
+
|
|
|
+ $totalStandardScore = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('work_order', $workOrder['订单编号'])
|
|
|
+ ->where('status', 0)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->sum('standard_score');
|
|
|
+ $totalStandardScore = $totalStandardScore ? floatval($totalStandardScore) : 0;
|
|
|
+ if ($totalStandardScore > floatval($newValue)) {
|
|
|
+ $this->error('工序定额分和大于制造工分,请修改确认之后再修改');
|
|
|
+ }
|
|
|
+
|
|
|
+ $operTime = date('Y-m-d H:i:s');
|
|
|
+ $logData = [
|
|
|
+ 'order_no' => $workOrder['订单编号'],
|
|
|
+ 'change_field' => '计划制造工分',
|
|
|
+ 'old_value' => $oldValue === null ? '' : (string)$oldValue,
|
|
|
+ 'new_value' => (string)$newValue,
|
|
|
+ 'oper_type' => '修改工单计划制造工分',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ];
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $updateResultSql = Db::table('工单_基本资料')
|
|
|
+ ->where('Uniqid', $workOrder['Uniqid'])
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->update(['计划制造工分' => $newValue]);
|
|
|
+ $updateResult = Db::query($updateResultSql);
|
|
|
+ if ($updateResult === false) {
|
|
|
+ throw new \Exception('更新工单失败');
|
|
|
+ }
|
|
|
+ $logResult = Db::name('work_order_operation_log')->insert($logData);
|
|
|
+ if ($logResult === false) {
|
|
|
+ throw new \Exception('写入操作日志失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('修改失败');
|
|
|
+ }
|
|
|
+ $this->success('修改成功');
|
|
|
+ }
|
|
|
+
|
|
|
}
|