huangsanjia 1 year ago
parent
commit
ba0246069f
1 changed files with 14 additions and 12 deletions
  1. 14 12
      application/api/controller/ReportingWork.php

+ 14 - 12
application/api/controller/ReportingWork.php

@@ -389,18 +389,20 @@ class ReportingWork extends Api
             $newData[$key]['sys_rq'] = $data['sys_rq'];
             $newData[$key]['UniqID'] = $batchUniqId;
         }
-        $sql = \db('设备_产量计酬')->fetchSql(true)->insert($data);
-        $res = Db::query($sql);
-        $batch_sql = \db('物料_批次跟踪')->fetchSql(true)->insertAll($newData);
-        $batch_res = Db::query($batch_sql);
-//        $res = true;
-//        $batch_res = true;
-//        Db::startTrans();
-//        try {
-//            Db::commit();
-//        }catch (\Exception $e){
-//            Db::rollback();
-//        }
+
+
+        $res = false;
+        $batch_res = false;
+        Db::startTrans();
+        try {
+            $sql = \db('设备_产量计酬')->fetchSql(true)->insert($data);
+            $res = Db::query($sql);
+            $batch_sql = \db('物料_批次跟踪')->fetchSql(true)->insertAll($newData);
+            $batch_res = Db::query($batch_sql);
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+        }
         if ($res === false || $batch_res === false){
             $this->error('报工失败');
         }else{