unknown 10 miesięcy temu
rodzic
commit
1688b9dcf9

+ 3 - 4
application/api/controller/Machine.php

@@ -62,10 +62,9 @@ class Machine extends Api
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
-        $list = [
-            0 => '印刷车间',
-            1 => '印后车间'
-        ];
+        $list = \db('设备_基本资料')
+            ->group('使用部门')
+            ->column('rtrim(使用部门)');
         $this->success('请求成功',$list);
 
     }

+ 300 - 18
application/api/controller/MachineList.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use think\Request;
 use app\common\controller\Api;
 use think\response\Json;
+use function fast\e;
 
 /**
  * 设备维修保养记录
@@ -254,6 +255,10 @@ class MachineList extends Api
         if (empty($param) || !isset($param['machine']) || !isset($param['year']) || !isset($param['sist'])) {
             $this->error('参数错误');
         }
+        $where = [];
+        if (isset($param['type']) && $param['type'] == '修理') {
+            $where['st_jylb'] =['like','修理领用%'];
+        }
         $list = db('物料_收发记录')
             ->alias('a')
             ->join('物料_仓库信息 b', 'a.仓库编号 = b.编号','left')
@@ -265,7 +270,7 @@ class MachineList extends Api
                 $query->where('a.仓库编号', '107')
                     ->whereOr('a.仓库编号', 'Y107');
             })
-            ->where('st_jylb','like','修理领用%')
+            ->where($where)
             ->field(['DATE_FORMAT(a.st_rq, "%y-%m-%d") AS 日期','rtrim(a.st_jylb) as 交易类别','a.st_jtbh AS 机台编号','rtrim(a.仓库编号) as 仓库编号',
                 'rtrim(b.名称) as 仓库名称','rtrim(c.使用部门) as 领用部门','a.st_wlbh as 物料编号','rtrim(d.物料名称) as 物料名称','a.st_sl as 领用数量',
                 'rtrim(a.st_dw) as 领用单位','a.领用单价','a.st_sl*a.领用单价 as 金额','a.st_desc as 备注'])
@@ -375,21 +380,298 @@ class MachineList extends Api
     }
 
 
-    //月度设备维修记录上方机台列表
-//    public function MonthAccessoriesList()
-//    {
-//        if ($this->request->isGet() === false) {
-//            $this->error('请求错误');
-//        }
-//        $param = $this->request->param();
-//        if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
-//            $this->error('参数错误');
-//        }
-//        $list = db('设备_维修记录')
-//            ->alias('a')
-//            ->join('<UNK>_<UNK> b', 'a.<UNK> = b.<UNK>','left')
-//            ->where('使用部门', $param['sist'])
-//            ->where('保障时间', 'like', $param['mouth'] . '%')
-//            ->field('设备编号,设备名称,报障时间,维修受理时间,修复时间,实际维修工时 as 故障维修工时,验收情况,');
-//    }
+    /**
+     * 月度设备维修记录上方机台列表
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MonthAccessoriesList()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
+            $this->error('参数错误');
+        }
+        $query = db('设备_维修记录')
+            ->alias('a')
+            ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
+            ->where('a.使用部门', $param['sist'])
+            ->where('a.报障时间', 'like', $param['mouth'] . '%')
+            ->field('rtrim(a.设备编号) as 设备编号,rtrim(a.设备编号) as 设备名称,a.报障时间,a.维修受理时间,a.修复时间,a.实际维修工时 as 故障维修工时,rtrim(a.验收情况) as 验收情况,
+            rtrim(b.员工姓名) as 机长,rtrim(c1.员工姓名) as 维修姓名1,rtrim(c2.员工姓名) as 维修姓名2,rtrim(c3.员工姓名) as 维修姓名3,rtrim(c4.员工姓名) as 维修姓名4,
+            rtrim(a.故障现象) as 故障现象,rtrim(a.处理方法) as 处理方法,rtrim(a.使用部门) as 使用部门,a.sys_id as 创建用户,a.sys_rq as 创建时间,a.mod_rq as 修改时间,a.UniqId');
+        for($i=1;$i<=4;$i++){
+            $tableNumber = 'c'.$i;
+            $field = 'a.维修人员'.$i;
+            $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
+        }
+        $list = $query->order('设备编号')->select();
+        if (empty($list)) {
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功', $list);
+        }
+    }
+
+
+    /**
+     * 月度设备保养记录上方机台列表
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MouthMaintainList()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['sist']) || !isset($param['mouth'])) {
+            $this->error('参数错误');
+        }
+        $fields = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
+        a.保养工时,rtrim(b.员工姓名) as 执行机修,rtrim(c.员工姓名) as 执行机长,rtrim(a.保养备注) as 保养备注,d.员工姓名 as 验收人员,rtrim(a.验收情况) as 验收情况,
+        rtrim(a.sys_id) as 创建用户,a.sys_rq as 创建时间,a.UniqId';
+        $query = db('设备_保养记录')
+            ->alias('a')
+            ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
+            ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
+            ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
+            ->field($fields)
+            ->where('a.使用部门', $param['sist'])
+            ->where('a.保养开始时间', 'like', $param['mouth'] . '%')
+            ->order('a.设备编号');
+        $list = $query->select();
+        if (empty($list)) {
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功', $list);
+        }
+    }
+
+
+    /**
+     * 设备维修记录修改-》维修信息获取
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MachineMaintenanceDetail()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['UniqId'])) {
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,a.报障时间,a.等配件时间,a.修复时间,rtrim(a.故障现象) as 故障现象,
+        rtrim(a.报障人) as 机长,b.员工编号 as 机长姓名,rtrim(a.维修性质) as 维修性质,a.维修受理时间,a.修复时间,a.等配件时间,
+        a.修复时间,a.维修人员1,a.维修人员2,a.维修人员3,a.维修人员4,c1.员工姓名 as 维修人员姓名1,c2.员工姓名 as 维修人员姓名2,c3.员工姓名 as 维修人员姓名3,c4.员工姓名 as 维修人员姓名4,
+        rtrim(a.处理方法) as 原因分析及措施,a.实际维修工时,a.故障工时,rtrim(a.验收人) as 验收人,rtrim(a.验收情况) as 验收情况,a.UniqId';
+        $query = db('设备_维修记录')
+            ->alias('a')
+            ->join('人事_基本资料 b','a.报障人 = b.员工编号','left')
+            ->field($field)
+            ->where('a.UniqId', $param['UniqId']);
+        for($i=1;$i<=4;$i++){
+            $tableNumber = 'c'.$i;
+            $field = 'a.维修人员'.$i;
+            $query->join("人事_基本资料 $tableNumber", "$field = {$tableNumber}.员工编号 AND {$field} IS NOT NULL", 'LEFT');
+        }
+        $list = $query->find();
+        if (empty($list)) {
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功', $list);
+        }
+    }
+
+
+    /**
+     * 设备维修修改
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineMaintenanceUpdate()
+    {
+        if ($this->request->isPost() === false) {
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || !isset($param['UniqId'])) {
+            $this->error('参数错误');
+        }
+        $data = $param;
+        unset($data['UniqId']);
+        $data['mod_rq'] = date('Y-m-d H:i:s');
+        $sql = db('设备_维修记录')
+            ->where('UniqId', $param['UniqId'])
+            ->fetchSql(true)
+            ->update($data);
+        $res = db()->query($sql);
+        if ($res !== false) {
+            $this->success('修改成功');
+        }else{
+            $this->error('修改失败');
+        }
+    }
+
+    /**
+     * 设备维修记录添加
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineMaintenanceAdd()
+    {
+        if ($this->request->isPost() === false) {
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)) {
+            $this->error('参数错误');
+        }
+        $param['sys_rq'] = date('Y-m-d H:i:s');
+        $param['mod_rq'] = '1900-01-01 00:00:00';
+        $sql = db('设备_维修记录')
+            ->fetchSql(true)
+            ->insert($param);
+        $res = db()->query($sql);
+        if ($res !== false) {
+            $this->success('添加成功');
+        }else{
+            $this->error('添加失败');
+        }
+    }
+
+
+    /**
+     * 设备保养记录修改信息获取
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MachineMaintainDetail()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['UniqId'])) {
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(a.设备编号) as 设备编号,rtrim(a.设备名称) as 设备名称,rtrim(a.使用部门) as 使用部门,rtrim(a.保养类型) as 保养类型,a.保养开始时间,a.保养结束时间,
+        a.保养工时,rtrim(a.执行机修) as 执行机修,b.员工编号 as 执行机修姓名,a.执行机长,c.员工姓名 as 执行机长姓名,rtrim(a.保养备注) as 保养备注,rtrim(a.验收人员) as 验收人员,
+        d.员工姓名 as 验收人员姓名,rtrim(a.验收备注) as 验收备注,rtrim(a.验收情况) as 验收情况,a.UniqId';
+        $query = db('设备_保养记录')
+            ->alias('a')
+            ->join('人事_基本资料 b','a.执行机修 = b.员工编号','left')
+            ->join('人事_基本资料 c','a.执行机长 = c.员工姓名','left')
+            ->join('人事_基本资料 d','a.验收人员 = d.员工姓名','left')
+            ->field($field)
+            ->where('a.UniqId', $param['UniqId']);
+        $list = $query->find();
+        if (empty($list)) {
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功', $list);
+        }
+    }
+
+    /**
+     * 设备保养记录修改
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineMaintainUpdate()
+    {
+        if ($this->request->isPost() === false) {
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || !isset($param['UniqId'])) {
+            $this->error('参数错误');
+        }
+        $data = $param;
+        unset($data['UniqId']);
+        $data['mod_rq'] = date('Y-m-d H:i:s');
+        $sql = db('设备_保养记录')
+            ->where('UniqId', $param['UniqId'])
+            ->fetchSql(true)
+            ->update($data);
+        $res = db()->query($sql);
+        if ($res !== false) {
+            $this->success('修改成功');
+        }else{
+            $this->error('修改失败');
+        }
+    }
+
+    /**
+     * 设备保养记录新增
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineMaintainAdd()
+    {
+        if ($this->request->isPost() === false) {
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)) {
+            $this->error('参数错误');
+        }
+        $param['sys_rq'] = date('Y-m-d H:i:s');
+        $param['mod_rq'] = '1900-01-01 00:00:00';
+        $sql = db('设备_保养记录')
+            ->fetchSql(true)
+            ->insert($param);
+        $res = db()->query($sql);
+        if ($res !== false) {
+            $this->success('添加成功');
+        }else{
+            $this->error('添加失败');
+        }
+    }
+
+    /**
+     * 设备保养维修记录删除
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function MachineMaintainDelete()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['UniqId']) || !isset($param['type'])) {
+            $this->error('参数错误');
+        }
+        if ($param['type'] == 0) {
+            $table = '设备_维修记录';
+        }else{
+            $table = '设备_保养记录';
+        }
+        $res = db($table)->where('UniqId', $param['UniqId'])->delete();
+        if ($res !== false) {
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
 }