Pārlūkot izejas kodu

LogisticService
方法修改

ajun 5 gadi atpakaļ
vecāks
revīzija
2e1ede48da
1 mainītis faili ar 18 papildinājumiem un 10 dzēšanām
  1. 18 10
      app/Services/LogisticService.php

+ 18 - 10
app/Services/LogisticService.php

@@ -95,18 +95,26 @@ Class LogisticService
         $collect = collect();
         if(count($codes) == 0) return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("getLogisticByCodes_{$code}", config('database.cache.expirations.rand'), function()use($code){
-                $logistic = Logistic::query()->where('code',$code)->first();
-                if($logistic)return $logistic;
-                $baseCustomers = OracleBasCustomer::query()
-                    ->selectRaw('Customer_Type,CustomerID,Descr_C')
-                    ->where('Customer_Type','CA')
-                    ->where('CustomerID',$code)->first();
-                if(!$baseCustomers)return null;
-                return Logistic::query()->create(['name' => $baseCustomers['descr_c'], 'code' => $baseCustomers['customerid']]);
-            }));
+            $collect->push($this->getLogisticByCode($code));
         }
         return $collect;
     }
 
+    public function getLogisticByCode($code){
+        return Cache::remember("getLogisticByCode_{$code}", config('database.cache.expirations.rand'), function()use($code){
+            $logistic = Logistic::query()->where('code',$code)->first();
+            if($logistic)return $logistic;
+            $baseCustomers = app('OracleBasCustomerService')->first(['Customer_Type'=>'CA','CustomerID'=>'$code']);
+            if(!$baseCustomers)return null;
+            try {
+                $logistic = Logistic::query()->create(['name' => $baseCustomers['descr_c'], 'code' => $baseCustomers['customerid']]);
+                app('LogService')->log(__METHOD__, __FUNCTION__,'创建Logistic SUCCESS'." || ". json_encode($logistic));
+                return $logistic;
+            } catch (\Exception $e) {
+                app('LogService')->log(__METHOD__, __FUNCTION__,'创建Logistic ERROR'." || ". json_encode($logistic)." || ".json_encode($e->getMessage())." || ".json_encode($e->getTraceAsString()));
+                return null;
+            }
+        });
+    }
+
 }