Zhouzhendong 5 лет назад
Родитель
Сommit
5cfa934748

+ 10 - 5
app/Http/Controllers/TestController.php

@@ -141,6 +141,7 @@ use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
 use Doctrine\DBAL\Query\QueryBuilder;
 use Illuminate\Database\Connection;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\QueryException;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Http\Request;
@@ -175,12 +176,16 @@ class TestController extends Controller
     public function test()
     {
         try{
-            Unit::query()->create(["name"=>"tt1"]);
-            Unit::query()->create(["name"=>"tt1"]);
-        }catch (\SQLiteException $E){
-            dd($E);
+            Unit::query()->select("xx")->find(1);
+            //Unit::query()->create(["name"=>"tt1"]);
+        } catch(QueryException $qe){
+                if ($qe->getCode()!='23000'){
+                    dd(1);
+                }
+            }catch (\Exception $a){
+            dump(2);
         }
-        dd(1);
+        dd(3);
         Cache::flush();
         $service = new OrderService();
         $order = Order::query()->find(2748314);

+ 6 - 0
app/Jobs/OrderCreateInstantBill.php

@@ -7,6 +7,7 @@ use App\Services\OrderService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\QueryException;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 
@@ -41,6 +42,11 @@ class OrderCreateInstantBill implements ShouldQueue
                 try{
                     if (!$service->createInstantBill($order))
                         LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson());
+                }catch(QueryException $qe){
+                    if ($qe->getCode()!='23000'){
+                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$qe->getMessage());
+                        $errors = ["order_".$order->id.":".$qe->getMessage()];
+                    }
                 }catch (\Exception $e){
                     LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$e->getMessage());
                     $errors = ["order_".$order->id.":".$e->getMessage()];

+ 6 - 0
app/Jobs/StoreCreateInstantBill.php

@@ -7,6 +7,7 @@ use App\Services\StoreService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\QueryException;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 
@@ -41,6 +42,11 @@ class StoreCreateInstantBill implements ShouldQueue
         foreach ($this->stores as $store){
             try{
                 $service->createInstantBill($store);
+            }catch(QueryException $qe){
+                if ($qe->getCode()!='23000'){
+                    LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$qe->getMessage());
+                    $errors = ["store_".$store->id.":".$qe->getMessage()];
+                }
             }catch (\Exception $e){
                 LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$e->getMessage());
                 $errors = ["store_".$store->id.":".$e->getMessage()];