Procházet zdrojové kódy

补充送货状态修改原单

Zhouzhendong před 5 roky
rodič
revize
2edc3d9a2b

+ 1 - 0
app/Http/Controllers/DeliveryAppointmentController.php

@@ -377,6 +377,7 @@ html;
         $car->update(["delivery_time"=>date("Y-m-d H:i:s")]);
         /** @var DeliveryAppointmentCar $car */
         event(new DeliveryAppointmentEvent($car));
+        app("DeliveryAppointmentService")->checkFull($car->delivery_appointment_id);
         return ["status"=>200,"k"=>$car->delivery_appointment_id];
     }
 

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

@@ -157,6 +157,11 @@ class TestController extends Controller
     }
     public function tt1()
     {
+        $delivery = DeliveryAppointment::query()->withCount(["cars"=>function($query){
+            /** @var Builder $query */
+            $query->whereNull("delivery_time");
+        }])->find(1);
+        dd($delivery);
         return view("store.deliveryAppointment.delivery",["k"=>"15661461456"]);
     }
     public function zzd(){

+ 16 - 0
app/Services/DeliveryAppointmentService.php

@@ -9,6 +9,7 @@ use App\Traits\ServiceAppAop;
 use App\DeliveryAppointment;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
+use phpDocumentor\Reflection\Types\Integer;
 
 class DeliveryAppointmentService
 {
@@ -143,4 +144,19 @@ class DeliveryAppointmentService
         }
         return false;
     }
+
+    /**
+     * 验证预约单完整性修改状态
+     *
+     * @param integer $id
+     */
+    public function checkFull($id)
+    {
+        /** @var DeliveryAppointment|\stdClass $delivery */
+        $delivery = DeliveryAppointment::query()->withCount(["cars"=>function($query){
+            /** @var Builder $query */
+            $query->whereNull("delivery_time");
+        }])->find($id);
+        if ($delivery->cars_count == 0)$delivery->update(["status"=>2]);
+    }
 }