refactor: use Carbon for dates
This commit is contained in:
12
module/oc_telegram_shop/upload/oc_telegram_shop/src/Models/TelegramCustomer.php
Normal file → Executable file
12
module/oc_telegram_shop/upload/oc_telegram_shop/src/Models/TelegramCustomer.php
Normal file → Executable file
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
||||||
use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;
|
use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
@@ -78,8 +79,8 @@ class TelegramCustomer
|
|||||||
*/
|
*/
|
||||||
public function create(array $data): int
|
public function create(array $data): int
|
||||||
{
|
{
|
||||||
$data['created_at'] = date('Y-m-d H:i:s');
|
$data['created_at'] = Carbon::now()->toDateTimeString();
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
$data['updated_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
|
||||||
$success = $this->database->insert(self::TABLE_NAME, $data);
|
$success = $this->database->insert(self::TABLE_NAME, $data);
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ class TelegramCustomer
|
|||||||
*/
|
*/
|
||||||
public function updateByTelegramUserId(int $telegramUserId, array $data): bool
|
public function updateByTelegramUserId(int $telegramUserId, array $data): bool
|
||||||
{
|
{
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
$data['updated_at'] = Carbon::now()->toDateTimeString();
|
||||||
|
|
||||||
return $this->builder->newQuery()
|
return $this->builder->newQuery()
|
||||||
->where('telegram_user_id', '=', $telegramUserId)
|
->where('telegram_user_id', '=', $telegramUserId)
|
||||||
@@ -117,14 +118,15 @@ class TelegramCustomer
|
|||||||
public function updateLastSeen(int $telegramUserId): bool
|
public function updateLastSeen(int $telegramUserId): bool
|
||||||
{
|
{
|
||||||
return $this->updateByTelegramUserId($telegramUserId, [
|
return $this->updateByTelegramUserId($telegramUserId, [
|
||||||
'last_seen_at' => date('Y-m-d H:i:s'),
|
'last_seen_at' => Carbon::now()->toDateTimeString(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function increase(int $id, string $field): bool
|
public function increase(int $id, string $field): bool
|
||||||
{
|
{
|
||||||
|
$now = Carbon::now()->toDateTimeString();
|
||||||
$table = self::TABLE_NAME;
|
$table = self::TABLE_NAME;
|
||||||
$sql = "UPDATE `$table` SET `$field` = `$field` + 1 WHERE id = ?";
|
$sql = "UPDATE `$table` SET `$field` = `$field` + 1, updated_at = '$now' WHERE id = ?";
|
||||||
|
|
||||||
return $this->database->statement($sql, [$id]);
|
return $this->database->statement($sql, [$id]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user