Browse Source

生产数据同步数据库配置

qiuenguang 1 year ago
parent
commit
6166bddd73
1 changed files with 15 additions and 13 deletions
  1. 15 13
      application/api/controller/Synchronization.php

+ 15 - 13
application/api/controller/Synchronization.php

@@ -985,14 +985,15 @@ class Synchronization extends Api
         {
             mkdir(ROOT_PATH.'public/'.date('Y-m-d',time()),0777,true);
         }
-        $lastID = \db('设备_产量计酬')->order('UniqId desc')->value('UniqId');
-        if (empty($lastID)){
-            $lastID = 0;
-        }
+//        $lastID = \db('设备_产量计酬')->order('UniqId desc')->value('UniqId');
+//        if (empty($lastID)){
+//            $lastID = 0;
+//        }
         $db4 = \db()->connect(config('database.db4'));
         $where = [
-            'sczl_rq'=>date('Y-m-d',time()),
-            'UniqId' =>['>',$lastID]
+//            'sczl_rq'=>date('Y-m-d',time()),
+//            'UniqId' =>['>',$lastID]
+            'sczl_rq' => ['>=','2024-04-01']
         ];
         $productData = $db4->name('设备_产量计酬')
             ->where($where)
@@ -1050,13 +1051,14 @@ class Synchronization extends Api
             $data[$key]['sczl_gdbh'] = $workcode;
         }
         //插入设备产量计酬数据
-        $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
-        $res = \db()->query($sql);
-        if ($res !== false){
-            $this->success('同步成功');
-        }else{
-            $this->error('同步失败');
+        \db()->startTrans();
+        try {
+            \db('设备_产量计酬')->where('sczl_rq','>=','2024-04-01 00:00:00')->delete();
+            $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
+            $res = \db()->query($sql);
+        }catch (\Exception $e){
+            \db()->rollback();
         }
-
+        $this->success('同步成功');
     }
 }