|
|
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|
|
|
|
use App\Customer;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class OrderItems extends SoftDeletesModel
|
|
|
|
|
{
|
|
|
|
|
@ -136,11 +137,11 @@ class OrderItems extends SoftDeletesModel
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function autoCheckout($before_today = false)
|
|
|
|
|
public function autoCheckout()
|
|
|
|
|
{
|
|
|
|
|
$threshold = 100;
|
|
|
|
|
$last_id = cache("last_auto_checkout_order_item_id", 0);
|
|
|
|
|
dump("last_auto_checkout_order_item_id:" . $last_id);
|
|
|
|
|
|
|
|
|
|
$unpaid_order_items = $this
|
|
|
|
|
->whereHas("order", function ($query) {
|
|
|
|
|
$query->where("status", Orders::STATUS_ONGOING);
|
|
|
|
|
@ -148,11 +149,6 @@ class OrderItems extends SoftDeletesModel
|
|
|
|
|
->whereNull("paid_at")
|
|
|
|
|
->where("id", ">", $last_id);
|
|
|
|
|
|
|
|
|
|
if ($before_today) {
|
|
|
|
|
$today = strtotime(date("Y-m-d"));
|
|
|
|
|
$unpaid_order_items->whereRaw("UNIX_TIMESTAMP(`service_date`) < {$today}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$unpaid_order_items = $unpaid_order_items
|
|
|
|
|
->orderBy("id")
|
|
|
|
|
->limit($threshold)
|
|
|
|
|
@ -162,6 +158,7 @@ class OrderItems extends SoftDeletesModel
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log::channel("daily_auto_checkout")->info("Last id:" . $last_id);
|
|
|
|
|
foreach ($unpaid_order_items as $item) {
|
|
|
|
|
cache(['last_auto_checkout_order_item_id' => $item->id], now()->addSeconds(90));
|
|
|
|
|
$customer = $item->order->customer;
|
|
|
|
|
@ -189,6 +186,7 @@ class OrderItems extends SoftDeletesModel
|
|
|
|
|
|
|
|
|
|
$item->order->refreshTotal();
|
|
|
|
|
}
|
|
|
|
|
Log::channel("daily_auto_checkout")->info("From " . $unpaid_order_items->first()->id . " to " . $unpaid_order_items->last()->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function balance()
|
|
|
|
|
|