Browse Source

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

haozi 5 years ago
parent
commit
2901f8105f
1 changed files with 10 additions and 3 deletions
  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('CUSTOMER_TYPE', 'OW')
             ->get();
-        $ownerCount = Owner::count();
+        $ownerCount = Owner::query()->count();
         if (count($basCustomers) == $ownerCount) return null;
         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([
                     'code' => $basCustomer['customerid'],
                     'name' => $basCustomer['descr_c'],
                     '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();
         return $owners;