فهرست منبع

点检记录新增优化

zck 1 ماه پیش
والد
کامیت
4f20638e7a
1فایلهای تغییر یافته به همراه22 افزوده شده و 25 حذف شده
  1. 22 25
      application/api/controller/Facility.php

+ 22 - 25
application/api/controller/Facility.php

@@ -993,48 +993,45 @@ class Facility extends Api
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public  function InspectionItemAdd()
+    public function InspectionItemAdd()
     {
-        if (Request::instance()->isPost()  === false){
+        if (!Request::instance()->isPost()) {
             $this->error('请求错误');
         }
+        
         $param = Request::instance()->post();
-        if (empty($param)){
+        if (empty($param)) {
             $this->error('参数错误');
         }
-        $lastNumber =  \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
-        if (empty($lastNumber)){
-            $lastId = 0;
-        }else{
-            $lastId = $lastNumber;
-        }
+        
         $row = [];
-        foreach ($param as $key=>$value){
-            $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
-            $row[$key] = [
-                '日期' => date('Y-m-d 00:00:00',time()),
+        foreach ($param as $value) {
+            $unitCode = \db('设备_点检项目')
+                ->where('部件名称', $value['unitName'])
+                ->field('rtrim(部件编号) as 部件编号')
+                ->find();
+                
+            $row[] = [
+                '日期' => date('Y-m-d 00:00:00'),
                 '班组编号' => $value['team'],
                 '点检设备' => $value['machine'],
-                '部件编号' => $unitCode['部件编号'],
+                '部件编号' => $unitCode['部件编号'] ?? '',
                 '部件名称' => $value['unitName'],
                 '检验项目' => $value['itemName'],
                 '判定标准' => $value['standard'],
                 '点检方法' => $value['method'],
                 '点检结果' => $value['status'],
                 '备注说明' => $value['remark'],
-                'Sys_id'  =>'',
-                'Sys_rq'  => date('Y-m-d H:i:s',time()),
-                'Mod_rq'  => date('Y-m-d H:i:s',time()),
-                'Uniqid'  => $lastId+$key+1
+                'Sys_rq' => date('Y-m-d H:i:s')
             ];
-
         }
-        $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
-        $res = Db::query($sql);
-        if ($res !== false){
-            $this->success('成功');
-        }else{
-            $this->error('失败');
+        
+        $res = \db('设备_点检记录')->insertAll($row);
+        
+        if ($res !== false) {
+            $this->success('添加成功,添加了' . count($row) . '条记录');
+        } else {
+            $this->error('添加失败');
         }
     }