Skip to content

Commit

Permalink
Admin Can Delete Order
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsumon4u committed Oct 21, 2024
1 parent cb71dbb commit 6c9d0aa
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/Http/Controllers/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Pathao\Facade\Pathao;
use App\Product;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;

class OrderController extends Controller
Expand Down Expand Up @@ -390,7 +391,25 @@ public function destroy(Order $order)
}
return null;
}, $products);
$order->delete();

DB::transaction(function () use ($order) {
$phone = $order->phone;
$order->delete();

// update data.is_fraud, data.is_repeat for other orders
$orders = Order::where('phone', $phone)->get();
// is_fraud
$orders->each(function ($order) use ($orders) {
// where order_id is less than $order->id and status is CANCELLED or RETURNED
$order->update([
'data' => [
'is_fraud' => $orders->where('id', '<', $order->id)->whereIn('status', ['CANCELLED', 'RETURNED'])->count() > 0,
'is_repeat' => $orders->where('id', '<', $order->id)->count() > 0,
],
]);
});
});

return request()->expectsJson() ? true : redirect(action([self::class, 'index']))
->with('success', 'Order Has Been Deleted.');
}
Expand Down

0 comments on commit 6c9d0aa

Please sign in to comment.