瀏覽代碼

修改同步货主名称不一样情况

haozi 5 年之前
父節點
當前提交
2901f8105f
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10 3
      app/Services/OwnerService.php

+ 10 - 3
app/Services/OwnerService.php

@@ -32,16 +32,23 @@ Class OwnerService
             ->where('DESCR_C', 'not like', '%退仓%')
             ->where('DESCR_C', 'not like', '%退仓%')
             ->where('CUSTOMER_TYPE', 'OW')
             ->where('CUSTOMER_TYPE', 'OW')
             ->get();
             ->get();
-        $ownerCount = Owner::count();
+        $ownerCount = Owner::query()->count();
         if (count($basCustomers) == $ownerCount) return null;
         if (count($basCustomers) == $ownerCount) return null;
         foreach ($basCustomers as $basCustomer) {
         foreach ($basCustomers as $basCustomer) {
-            $owner = Owner::where('code', $basCustomer['customerid'])->first();
-            if (!isset($owner))
+            $owner = Owner::query()->where('code', $basCustomer['customerid'])->first();
+            if (!isset($owner)){
                 Owner::query()->create([
                 Owner::query()->create([
                     'code' => $basCustomer['customerid'],
                     'code' => $basCustomer['customerid'],
                     'name' => $basCustomer['descr_c'],
                     'name' => $basCustomer['descr_c'],
                     'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
                     'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
                 ]);
                 ]);
+            }
+            if ($owner['name']!=$basCustomer['descr_c']){
+                $owner->update([
+                    'code' => $basCustomer['customerid'],
+                    'name' => $basCustomer['descr_c'],
+                ]);
+            }
         }
         }
         $owners = Owner::query()->select('id', 'name')->get();
         $owners = Owner::query()->select('id', 'name')->get();
         return $owners;
         return $owners;