|
|
@@ -402,12 +402,28 @@ class WorkOrderProcess extends Api
|
|
|
$this->error('请求方法错误');
|
|
|
}
|
|
|
$params = $this->request->post();
|
|
|
- if(empty($params['id'])){
|
|
|
- $this->error('工艺ID不能为空');
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('工艺ID不能为空');
|
|
|
}
|
|
|
if (empty($params['mod_id'])) {
|
|
|
$this->error('修改人不能为空');
|
|
|
}
|
|
|
+ if (empty($params['process_name'])) {
|
|
|
+ $this->error('工艺名称不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['big_process'])) {
|
|
|
+ $this->error('大工艺不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['standard_hour'])) {
|
|
|
+ $this->error('标准工时不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['standard_score'])) {
|
|
|
+ $this->error('标准公分不能为空');
|
|
|
+ }
|
|
|
+ if (!isset($params['coefficient']) || $params['coefficient'] === '') {
|
|
|
+ $params['coefficient'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
$data = [
|
|
|
'process_name' => $params['process_name'],
|
|
|
'big_process' => $params['big_process'],
|
|
|
@@ -418,10 +434,16 @@ class WorkOrderProcess extends Api
|
|
|
'mod_id' => $params['mod_id'],
|
|
|
'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
- $result = db('工单_基础工艺资料')->where('id', $params['id'])->update($data);
|
|
|
+ $result = db('工单_基础工艺资料')
|
|
|
+ ->where('id', intval($params['id']))
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->update($data);
|
|
|
if ($result === false) {
|
|
|
$this->error('更新失败');
|
|
|
}
|
|
|
+ if ($result === 0) {
|
|
|
+ $this->error('未找到可更新的工艺或数据无变化');
|
|
|
+ }
|
|
|
$this->success('更新成功');
|
|
|
}
|
|
|
|
|
|
@@ -432,20 +454,161 @@ class WorkOrderProcess extends Api
|
|
|
*/
|
|
|
public function DeleteProcess()
|
|
|
{
|
|
|
- if (!$this->request->isGet()) {
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
$this->error('请求方法错误');
|
|
|
}
|
|
|
- $params = $this->request->param();
|
|
|
- if(empty($params['id'])){
|
|
|
- $this->error('工艺ID不能为空');
|
|
|
+ $params = $this->request->post();
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('工艺ID不能为空');
|
|
|
}
|
|
|
$ids = explode(',', $params['id']);
|
|
|
- $result = db('工单_基础工艺资料')->where('id', 'in', $ids)->update(['del_rq' => date('Y-m-d H:i:s')]);
|
|
|
+ $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 product_code 产品编号
|
|
|
+ * @param sys_id 操作人
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function workorderprocessCopy()
|
|
|
+ {
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->param();
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['product_code'])) {
|
|
|
+ $this->error('产品编号不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['sys_id'])) {
|
|
|
+ $this->error('操作人不能为空');
|
|
|
+ }
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
+ $productParts = db('产品_部件资料')
|
|
|
+ ->where('product_code', $params['product_code'])
|
|
|
+ ->where('mod_rq', null)
|
|
|
+ ->field('part_sort as part_code,part_name')
|
|
|
+ ->select();
|
|
|
+ if (empty($productParts)) {
|
|
|
+ $this->error('该产品没有有效的部件');
|
|
|
+ }
|
|
|
+ $productProcesses = db('产品_工艺资料')
|
|
|
+ ->where('product_code', $params['product_code'])
|
|
|
+ ->field('part_sort as part_code,part_name,gy_sort as process_code,gy_name as process_name,
|
|
|
+ big_process,standard_hour,standard_score,difficulty_coef as coefficient')
|
|
|
+ ->select();
|
|
|
+ if (empty($productProcesses)) {
|
|
|
+ $this->error('该产品没有工艺');
|
|
|
+ }
|
|
|
+
|
|
|
+ $workOrderParts = [];
|
|
|
+ //配置工单部件数据
|
|
|
+ foreach ($productParts as $value) {
|
|
|
+ $workOrderParts[] = [
|
|
|
+ 'work_order' => $params['workorder'],
|
|
|
+ 'part_code' => $value['part_code'],
|
|
|
+ 'part_name' => $value['part_name'],
|
|
|
+ 'part_type' => '',
|
|
|
+ 'remark' => '',
|
|
|
+ 'status' => 1,
|
|
|
+ 'sys_id' => $params['sys_id'],
|
|
|
+ 'sys_rq' => $now,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $workOrderProcesses = [];
|
|
|
+ //配置工单工艺数据
|
|
|
+ foreach ($productProcesses as $value) {
|
|
|
+ $workOrderProcesses[] = [
|
|
|
+ 'work_order' => $params['workorder'],
|
|
|
+ 'part_code' => $value['part_code'],
|
|
|
+ 'part_name' => $value['part_name'],
|
|
|
+ 'process_code' => $value['process_code'],
|
|
|
+ 'process_name' => $value['process_name'],
|
|
|
+ 'big_process' => $value['big_process'],
|
|
|
+ 'standard_hour' => $value['standard_hour'],
|
|
|
+ 'standard_score' => $value['standard_score'],
|
|
|
+ 'coefficient' => $value['coefficient'],
|
|
|
+ 'remark' => '',
|
|
|
+ 'sys_id' => $params['sys_id'],
|
|
|
+ 'sys_rq' => $now,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //删除数据库现有的工单部件数据
|
|
|
+ Db::name('工单_部件资料')->where('work_order', $params['workorder'])->delete();
|
|
|
+ //删除数据库现有的工单工艺数据
|
|
|
+ Db::name('工单_基础工艺资料')->where('work_order', $params['workorder'])->delete();
|
|
|
+ //插入工单部件数据
|
|
|
+ $partInsertCount = Db::name('工单_部件资料')->insertAll($workOrderParts);
|
|
|
+ if ($partInsertCount === false) {
|
|
|
+ throw new \Exception('工单部件复制失败');
|
|
|
+ }
|
|
|
+ //插入工单工艺数据
|
|
|
+ $processInsertCount = Db::name('工单_基础工艺资料')->insertAll($workOrderProcesses);
|
|
|
+ if ($processInsertCount === false) {
|
|
|
+ throw new \Exception('工单工艺复制失败');
|
|
|
+ }
|
|
|
+ //提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('复制失败');
|
|
|
+ }
|
|
|
+ $this->success('复制成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询产品类型
|
|
|
+ * @ApiMethod (GET)
|
|
|
+ * @param string $workorder 工单编号
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function getproducttype()
|
|
|
+ {
|
|
|
+ if(!$this->request->isGet()){
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->get();
|
|
|
+ if (empty($params['product'])) {
|
|
|
+ $this->error('产品类型不能为空');
|
|
|
+ }
|
|
|
+ $list = db('产品_基本资料')
|
|
|
+ ->where('product_type', $params['product'])
|
|
|
+ ->where('status', 1)
|
|
|
+ ->field('product_code as 产品编号,product_type as 产品类型,product_name as 产品名称')
|
|
|
+ ->select();
|
|
|
+ if(empty($list)){
|
|
|
+ $this->error('该产品类型没有产品');
|
|
|
+ }
|
|
|
+ $this->success('成功', $list);
|
|
|
+ }
|
|
|
}
|