| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 工单工艺管理
- *
- */
- class WorkOrderProcess extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 工单大工序列表
- * @param workorder 工单编号
- */
- public function MajorprocessList()
- {
- if (!$this->request->isGet()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->param();
- if (empty($params['workorder'])) {
- $this->error('工单编号不能为空');
- }
- $list = db('工单_工艺资料')
- ->where('订单编号', $params['workorder'])
- ->field('工序编号,工序名称,工序备注')
- ->distinct('工序名称')
- ->select();
- if(empty($list)){
- $this->error('该工单没有大工序');
- }
- $this->success('成功', $list);
- }
- /**
- * 工单部件列表
- * @param workorder 工单编号
- */
- public function PartList()
- {
- if (!$this->request->isGet()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->param();
- if (empty($params['workorder'])) {
- $this->error('工单编号不能为空');
- }
- $list = db('工单_部件资料')
- ->where('work_order', $params['workorder'])
- ->where('del_rq', null)
- ->field('part_code as 部件编号,part_name as 部件名称,remark as 部件备注,part_type as 部件类型,status as 状态,
- sys_id as 操作人,sys_rq as 操作时间,mod_rq as 修改时间,mod_id as 修改人,id as 部件ID')
- ->order('part_code')
- ->select();
- if(empty($list)){
- $this->error('该工单没有部件,请先添加部件');
- }
- $this->success('成功', $list);
- }
- /**
- * 新增工单部件
- * @param workorder 工单编号
- * @param part_code 部件编号
- * @param part_name 部件名称
- * @param remark 部件备注
- * @param part_type 部件类型
- * @param sys_id 操作人
- */
- public function AddPart()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->post();
- if (empty($params['workorder'])) {
- $this->error('工单编号不能为空');
- }
- if (empty($params['part_name'])) {
- $this->error('部件名称不能为空');
- }
-
- // 检查是否传入了part_code
- if (!empty($params['part_code'])) {
- $code = $params['part_code'];
- // 检查是否存在冲突
- $exists = db('工单_部件资料')
- ->where('work_order', $params['workorder'])
- ->where('part_code', '>=', $code)
- ->count();
-
- if ($exists > 0) {
- // 如果存在冲突,将后续编号自动加1
- db('工单_部件资料')
- ->where('work_order', $params['workorder'])
- ->where('part_code', '>=', $code)
- ->setInc('part_code');
- }
- } else {
- // 如果没有传入part_code,按照原来的逻辑生成
- $code = db('工单_部件资料')
- ->where('work_order', $params['workorder'])
- ->max('part_code');
- $code = $code ? $code + 1 : 1;
- }
-
- $data = [
- 'work_order' => $params['workorder'],
- 'part_code' => $code,
- 'part_name' => $params['part_name'],
- 'remark' => $params['remark'],
- 'part_type' => $params['part_type'],
- 'status' => 1,
- 'sys_id' => $params['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- $result = db('工单_部件资料')->insert($data);
- if (!$result) {
- $this->error('新增失败');
- }
- $this->success('新增成功');
- }
- /**
- * 修改部件状态
- * @param id 部件ID
- * @param status 状态
- */
- public function UpdatePartStatus()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->post();
- if (empty($params['id'])) {
- $this->error('部件ID不能为空');
- }
- if (!isset($params['status'])) {
- $this->error('状态不能为空');
- }
- $result = db('工单_部件资料')
- ->where('id', $params['id'])
- ->update(['status' => $params['status']]);
- if (!$result) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
- /**
- * 修改部件信息
- * @param workorder 工单编号
- * @param part_code 部件编号
- * @param part_name 部件名称
- * @param remark 部件备注
- * @param part_type 部件类型
- */
- public function UpdatePartInfo()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->post();
- if (empty($params['part_name'])) {
- $this->error('部件名称不能为空');
- }
- if (empty($params['remark'])) {
- $this->error('部件备注不能为空');
- }
- if (empty($params['part_type'])) {
- $this->error('部件类型不能为空');
- }
- if(empty($params['mod_id'])){
- $this->error('修改人不能为空');
- }
- if(empty($params['id'])){
- $this->error('部件ID不能为空');
- }
- $result = db('工单_部件资料')
- ->where('id', $params['id'])
- ->update([
- 'part_name' => $params['part_name'],
- 'remark' => $params['remark'],
- 'part_type' => $params['part_type'],
- 'mod_id' => $params['mod_id'],
- 'mod_rq' => date('Y-m-d H:i:s'),
- ]);
- if (!$result) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
- /** 软删除部件信息
- * @param id 部件ID
- */
- public function DeletePart()
- {
- 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 工单编号
- */
- 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_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')
- ->select();
- $this->success('成功', $list);
- }
- /**
- * 获取部件列表
- * @param workorder 工单编号
- */
- public function getpartlist()
- {
- if(!$this->request->isGet()){
- $this->error('请求方法错误');
- }
- $params = $this->request->get();
- if (empty($params['workorder'])) {
- $this->error('工单编号不能为空');
- }
- $list = db('工单_部件资料')
- ->where('work_order', $params['workorder'])
- ->where('del_rq', null)
- ->field('part_code as 部件编号,part_name as 部件名称')
- ->order('part_code')
- ->select();
- if(empty($list)){
- $this->error('该工单没有部件,请先添加部件');
- }
- $this->success('成功', $list);
- }
- /**
- * 新增工单工艺资料
- * @param workorder 工单编号
- * @param part_code 部件编号
- * @param process_code 工艺编号
- * @param process_name 工艺名称
- * @param big_process 大工艺
- * @param standard_hour 标准工时
- * @param standard_score 标准公分
- * @param sys_id 系统人
- * @param coefficient 系数
- * @param remark 备注
- */
- public function AddProcess()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->post();
- if (empty($params['workorder'])) {
- $this->error('工单编号不能为空');
- }
- if (empty($params['part_code'])) {
- $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 (empty($params['coefficient'])) {
- $params['coefficient'] = 1;
- }
- if (empty($params['sys_id'])) {
- $this->error('系统人不能为空');
- }
-
- // 检查是否传入了process_code
- if (!empty($params['process_code'])) {
- $code = $params['process_code'];
- // 检查是否存在冲突
- $exists = db('工单_基础工艺资料')
- ->where('work_order', $params['workorder'])
- ->where('part_code', $params['part_code'])
- ->where('process_code', '>=', $code)
- ->count();
-
- if ($exists > 0) {
- // 如果存在冲突,将后续编号自动加1
- db('工单_基础工艺资料')
- ->where('work_order', $params['workorder'])
- ->where('part_code', $params['part_code'])
- ->where('process_code', '>=', $code)
- ->setInc('process_code');
- }
- } else {
- // 如果没有传入process_code,按照原来的逻辑生成
- $code = db('工单_基础工艺资料')
- ->where('work_order', $params['workorder'])
- ->where('part_code', $params['part_code'])
- ->max('process_code');
- $code = $code ? $code + 1 : 1;
- }
-
- $data = [
- 'work_order' => $params['workorder'],
- 'part_code' => $params['part_code'],
- 'process_code' => $code,
- 'process_name' => $params['process_name'],
- 'big_process' => $params['big_process'],
- 'standard_hour' => $params['standard_hour'],
- 'standard_score' => $params['standard_score'],
- 'coefficient' => $params['coefficient'],
- 'remark' => $params['remark'],
- 'sys_id' => $params['sys_id'],
- 'sys_rq' => date('Y-m-d H:i:s'),
- ];
- $result = db('工单_基础工艺资料')->insert($data);
- if ($result === false) {
- $this->error('新增失败');
- }
- $this->success('新增成功');
- }
- /**
- * 更新工单工艺资料
- * @param id 工艺ID
- * @param mod_id 修改人
- * @param process_name 工艺名称
- * @param big_process 大工艺
- * @param standard_hour 标准工时
- * @param standard_score 标准公分
- * @param coefficient 系数
- * @param remark 备注
- */
- public function UpdateProcess()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->post();
- if(empty($params['id'])){
- $this->error('工艺ID不能为空');
- }
- if (empty($params['mod_id'])) {
- $this->error('修改人不能为空');
- }
- $data = [
- 'process_name' => $params['process_name'],
- 'big_process' => $params['big_process'],
- 'standard_hour' => $params['standard_hour'],
- 'standard_score' => $params['standard_score'],
- 'coefficient' => $params['coefficient'],
- 'remark' => $params['remark'],
- 'mod_id' => $params['mod_id'],
- 'mod_rq' => date('Y-m-d H:i:s'),
- ];
- $result = db('工单_基础工艺资料')->where('id', $params['id'])->update($data);
- if ($result === false) {
- $this->error('更新失败');
- }
- $this->success('更新成功');
- }
- /**
- * 工单工艺资料软删除
- * @param id 工艺ID
- */
- public function DeleteProcess()
- {
- if (!$this->request->isGet()) {
- $this->error('请求方法错误');
- }
- $params = $this->request->param();
- 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')]);
- if ($result === false) {
- $this->error('删除失败');
- }
- $this->success('删除成功');
- }
-
- }
|