Browse Source

删除报工数据

unknown 1 week ago
parent
commit
eb95c81965
1 changed files with 46 additions and 0 deletions
  1. 46 0
      application/api/controller/GluingReport.php

+ 46 - 0
application/api/controller/GluingReport.php

@@ -1091,4 +1091,50 @@ class GluingReport extends Api
         }
         }
         $this->success('获取成功',$result);
         $this->success('获取成功',$result);
     }
     }
+
+
+
+    /**
+     * 报工数据删除
+     * @return void
+     * @throws \Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function deleteGluingReportData()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $params = $this->request->param();
+        if (!isset($params['id']) || empty($params['id'])){
+            $this->error('参数错误');
+        }
+        $ids = explode(',', $params['id']);
+        $roleIds = \db('设备_糊盒报工资料')
+            ->where('Uid', 'in', $ids)
+            ->column('role');
+        $roleIds = array_filter(array_unique($roleIds));
+
+        db()->startTrans();
+        try {
+            $res = \db('设备_糊盒报工资料')->where('Uid', 'in', $ids)->delete();
+            if ($res === false) {
+                throw new \Exception('删除报工数据失败');
+            }
+            if (!empty($roleIds)) {
+                $classRes = \db('糊盒报工班组')->where('id', 'in', $roleIds)->delete();
+                if ($classRes === false) {
+                    throw new \Exception('删除班组数据失败');
+                }
+            }
+            db()->commit();
+        } catch (\Exception $e) {
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+        $this->success('删除成功');
+    }
 } 
 }