You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
799 B

<?php
namespace App\Actions;
use App\Models\Orders;
use Illuminate\Support\Facades\DB;
class ChangeOrderStatus
{
public function __invoke(Orders $order)
{
if ($order->status != request()->from_status) {
throw new \Exception("订单状态不匹配");
}
$availableToStatus = [];
switch ($order->status) {
case Orders::STATUS_FINISHED:
$availableToStatus = [Orders::STATUS_ONGOING];
break;
default:
//do nothing
}
if (!in_array(request()->to_status, $availableToStatus)) {
throw new \Exception("订单状态不匹配");
}
$order->update([
"status" => request()->to_status
]);
return $order;
}
}