İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
use App\Models\Counter;
|
||||
use Carbon\Carbon;
|
||||
|
||||
function get_counter($prefix, $type="1") {
|
||||
//eğer type boşsa o gün üretilen başka bir counter varsa onu al
|
||||
$run = true;
|
||||
if($type == "") {
|
||||
$todayCounter = Counter::whereDate("updated_at", Carbon::today())->where("prefix", $prefix)->first();
|
||||
if($todayCounter) {
|
||||
$get = $todayCounter->value;
|
||||
$run = false;
|
||||
} else {
|
||||
$run = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($run) {
|
||||
$set = Counter::updateOrCreate(
|
||||
[
|
||||
'prefix' => $prefix
|
||||
])
|
||||
->increment('value');
|
||||
|
||||
$get = Counter::where("prefix", $prefix)->first()->value;
|
||||
}
|
||||
|
||||
$totalZero = 6;
|
||||
$totalGet = strlen($get);
|
||||
$resultZero = $totalZero - $totalGet;
|
||||
$result = "";
|
||||
for($k=1;$k<=$resultZero; $k++) {
|
||||
$result .= "0";
|
||||
}
|
||||
$result .= $get;
|
||||
|
||||
return $result;
|
||||
} ?>
|
||||
Reference in New Issue
Block a user