38 lines
938 B
PHP
38 lines
938 B
PHP
<?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;
|
|
} ?>
|