소스 검색

修改数据同步接口

unknown 2 달 전
부모
커밋
a0bd710a53
1개의 변경된 파일78개의 추가작업 그리고 76개의 파일을 삭제
  1. 78 76
      application/api/controller/Synchronization.php

+ 78 - 76
application/api/controller/Synchronization.php

@@ -772,12 +772,17 @@ class Synchronization extends Api
         $OrganizationalDataList = $db3->name('U8_07物料领用')
             ->where('MES接收时间', null)
             ->where('MES接收状态', '0')
+            ->order('U8传递时间')
             ->select();
+
         if (empty($OrganizationalDataList)) {
             $this->success('未找到新的物料领用记录');
         }
         $i = 0;
         foreach ($OrganizationalDataList as $key => $value) {
+            foreach ($value as $k => $v) {
+                $value[$k] = rtrim($v);
+            }
             if (preg_match("/[A-Za-z]/", $value['工单编号'])) {
                 $workcode = $value['工单编号'];
             } else {
@@ -804,34 +809,33 @@ class Synchronization extends Api
                 'U8UID' => $value['U8_UID'],
                 'cpdh' => $value['产品编码'],
             ];
+
             // 联表
-        $materialInfo = \db('物料_存货编码')
-        ->where('物料代码', $data['st_wlbh'])
-        ->field('yj_tlgg, yj_zzmc')
-        ->find();
-    
-    // 单位换算
-    if ($data['st_dw'] === '吨' && !empty($materialInfo)) {
-        $spec = $materialInfo['yj_tlgg'];  
-        $materialName = $materialInfo['yj_zzmc'];
-        
-        
-        if (!empty($spec) && strpos($spec, '×') !== false) {
-            $dimensions = explode('×', $spec);
-            $number1 = (int)trim($dimensions[0]);
-            $number2 = (int)trim($dimensions[1]);
-            
-            
-            if (!empty($materialName) && preg_match('/(\d+(\.\d+)?)g/', $materialName, $matches)) {
+            $materialInfo = \db('物料_存货编码')
+                ->where('物料代码', $data['st_wlbh'])
+                ->field('规格 as yj_tlgg, 物料名称 as yj_zzmc')
+                ->find();
+
+            // 单位换算
+            if ($data['st_dw'] === '吨' && !empty($materialInfo)) {
+                $spec = $materialInfo['yj_tlgg'];
+                $materialName = $materialInfo['yj_zzmc'];
+
+                if (!empty($spec) && strpos($spec, '×') !== false) {
+                    $dimensions = explode('×', $spec);
+                    $number1 = (int)trim($dimensions[0]);
+                    $number2 = (int)trim($dimensions[1]);
 
-                if ($number1 > 0 && $number2 > 0 && $matches[1] > 0) {
-                    $data['st_sl'] = round(($data['st_sl']*1000*1000)/$matches[1]/($number1*$number2)*1000000);
-                    $data['st_dw'] = '张';
+
+                    if (!empty($materialName) && preg_match('/(\d+(\.\d+)?)g/', $materialName, $matches)) {
+
+                        if ($number1 > 0 && $number2 > 0 && $matches[1] > 0) {
+                            $data['st_sl'] = round(($data['st_sl'] * 1000 * 1000) / $matches[1] / ($number1 * $number2) * 1000000);
+                            $data['st_dw'] = '张';
+                        }
                     }
                 }
             }
-        }
-    }
 
             $number = \db('物料_收发记录')
                 ->where('U8UID', $value['U8_UID'])
@@ -843,12 +847,12 @@ class Synchronization extends Api
                     $i++;
                 } else {
                     $logData = [
-                        'Gd_gdbh'      => $data['st_gdbh'], // 使用原始工单编号
-                        'ModifyUser'   => '系统同步',
-                        'ModifyTime'   => date('Y-m-d H:i:s'),
-                        'FieldName'    => $data['U8UID'],
-                        'OldValue'     => $data['st_sl'],
-                        'NewValue'     => $data['仓库编号'],
+                        'Gd_gdbh' => $data['st_gdbh'], // 使用原始工单编号
+                        'ModifyUser' => '系统同步',
+                        'ModifyTime' => date('Y-m-d H:i:s'),
+                        'FieldName' => $data['U8UID'],
+                        'OldValue' => $data['st_sl'],
+                        'NewValue' => $data['仓库编号'],
                         'ModifySource' => '物料收发记录同步'
                     ];
                     $logSql = \db('系统操作日志表')->fetchSql(true)->insert($logData);
@@ -872,8 +876,8 @@ class Synchronization extends Api
                     if ($oldValue != $newValue) {
                         $changes[] = [
                             'field' => $field,
-                            'old'   => $oldValue,
-                            'new'   => $newValue
+                            'old' => $oldValue,
+                            'new' => $newValue
                         ];
                     }
                 }
@@ -889,12 +893,12 @@ class Synchronization extends Api
                         $logData = [];
                         foreach ($changes as $change) {
                             $logData[] = [
-                                'Gd_gdbh'      => $data['st_gdbh'], // 使用原始工单编号
-                                'ModifyUser'   => '系统同步',
-                                'ModifyTime'   => date('Y-m-d H:i:s'),
-                                'FieldName'    => $change['field'],
-                                'OldValue'     => $change['old'],
-                                'NewValue'     => $change['new'],
+                                'Gd_gdbh' => $data['st_gdbh'], // 使用原始工单编号
+                                'ModifyUser' => '系统同步',
+                                'ModifyTime' => date('Y-m-d H:i:s'),
+                                'FieldName' => $change['field'],
+                                'OldValue' => $change['old'],
+                                'NewValue' => $change['new'],
                                 'ModifySource' => '物料收发记录修改数据同步'
                             ];
                         }
@@ -1975,35 +1979,33 @@ class Synchronization extends Api
                 'cpdh' => $value['产品编码']
             ];
 
-        // 联表
-        $materialInfo = \db('物料_存货编码')
-        ->where('物料代码', $data['st_wlbh'])
-        ->field('yj_tlgg, yj_zzmc')
-        ->find();
-    
-    // 单位换算
-    if ($data['st_dw'] === '吨' && !empty($materialInfo)) {
-        $spec = $materialInfo['yj_tlgg'];  
-        $materialName = $materialInfo['yj_zzmc'];
-        
-        
-        if (!empty($spec) && strpos($spec, '×') !== false) {
-            $dimensions = explode('×', $spec);
-            $number1 = (int)trim($dimensions[0]);
-            $number2 = (int)trim($dimensions[1]);
-            
-            
-            if (!empty($materialName) && preg_match('/(\d+(\.\d+)?)g/', $materialName, $matches)) {
+            // 联表
+            $materialInfo = \db('物料_存货编码')
+                ->where('物料代码', $data['st_wlbh'])
+                ->field('规格 as yj_tlgg, 物料名称 as yj_zzmc')
+                ->find();
+
+            // 单位换算
+            if ($data['st_dw'] === '吨' && !empty($materialInfo)) {
+                $spec = $materialInfo['yj_tlgg'];
+                $materialName = $materialInfo['yj_zzmc'];
+
+
+                if (!empty($spec) && strpos($spec, '×') !== false) {
+                    $dimensions = explode('×', $spec);
+                    $number1 = (int)trim($dimensions[0]);
+                    $number2 = (int)trim($dimensions[1]);
+
 
-                if ($number1 > 0 && $number2 > 0 && $matches[1] > 0) {
-                    $data['st_sl'] = round(($data['st_sl']*1000*1000)/$matches[1]/($number1*$number2)*1000000);
-                    $data['st_dw'] = '张';
+                    if (!empty($materialName) && preg_match('/(\d+(\.\d+)?)g/', $materialName, $matches)) {
+
+                        if ($number1 > 0 && $number2 > 0 && $matches[1] > 0) {
+                            $data['st_sl'] = round(($data['st_sl'] * 1000 * 1000) / $matches[1] / ($number1 * $number2) * 1000000);
+                            $data['st_dw'] = '张';
+                        }
                     }
                 }
             }
-        }
-    }
-
             $number = \db('物料_收发记录')
                 ->where('U8UID', $value['U8_UID'])
                 ->count();
@@ -2014,12 +2016,12 @@ class Synchronization extends Api
                     $i++;
                 } else {
                     $logData = [
-                        'Gd_gdbh'      => $data['st_gdbh'], // 使用原始工单编号
-                        'ModifyUser'   => '系统同步',
-                        'ModifyTime'   => date('Y-m-d H:i:s'),
-                        'FieldName'    => $data['U8UID'],
-                        'OldValue'     => $data['st_sl'],
-                        'NewValue'     => $data['仓库编号'],
+                        'Gd_gdbh' => $data['st_gdbh'], // 使用原始工单编号
+                        'ModifyUser' => '系统同步',
+                        'ModifyTime' => date('Y-m-d H:i:s'),
+                        'FieldName' => $data['U8UID'],
+                        'OldValue' => $data['st_sl'],
+                        'NewValue' => $data['仓库编号'],
                         'ModifySource' => '物料收发记录同步'
                     ];
                     $logSql = \db('系统操作日志表')->fetchSql(true)->insert($logData);
@@ -2043,8 +2045,8 @@ class Synchronization extends Api
                     if ($oldValue != $newValue) {
                         $changes[] = [
                             'field' => $field,
-                            'old'   => $oldValue,
-                            'new'   => $newValue
+                            'old' => $oldValue,
+                            'new' => $newValue
                         ];
                     }
                 }
@@ -2060,12 +2062,12 @@ class Synchronization extends Api
                         $logData = [];
                         foreach ($changes as $change) {
                             $logData[] = [
-                                'Gd_gdbh'      => $data['st_gdbh'], // 使用原始工单编号
-                                'ModifyUser'   => '系统同步',
-                                'ModifyTime'   => date('Y-m-d H:i:s'),
-                                'FieldName'    => $change['field'],
-                                'OldValue'     => $change['old'],
-                                'NewValue'     => $change['new'],
+                                'Gd_gdbh' => $data['st_gdbh'], // 使用原始工单编号
+                                'ModifyUser' => '系统同步',
+                                'ModifyTime' => date('Y-m-d H:i:s'),
+                                'FieldName' => $change['field'],
+                                'OldValue' => $change['old'],
+                                'NewValue' => $change['new'],
                                 'ModifySource' => '物料收发记录修改数据同步'
                             ];
                         }