dbms_primeidc/extdbms/lib/Services/ClientService.php
2025-04-23 19:28:58 +09:00

55 lines
1.5 KiB
PHP

<?php
namespace lib\Services;
use lib\Entities\ClientEntity as Entity;
use lib\Models\ClientModel as Model;
class ClientService extends CommonService
{
public function __construct()
{
parent::__construct();
}
final public function getClassName(): string
{
return "Client";
}
final public function getClassPath(): string
{
return $this->getClassName();
}
public function getModelClass(): string
{
return Model::class;
}
public function getEntityClass(): string
{
return Entity::class;
}
//사용자 포인트 입금
public function depositPoint(Entity $client, int $point): bool
{
if ($point < 0) {
throw new \Exception("포인트금액이 잘못되었습니다. 포인트 : $point");
}
$this->getModel()->where("Client_Code", $client->getClientCode());
$this->getModel()->update(["Client_Point=(Client_Point+{$point})" => null]);
return true;
}
//사용자 포인트 출금
public function withdrawalPoint(Entity $client, int $point): bool
{
if ($point < 0) {
throw new \Exception("포인트금액이 잘못되었습니다. 포인트 : $point");
}
if ($client->getPoint() < $point) {
throw new \Exception("포인트금액이 잘못되었습니다. 남은 포인트: " . $client->getPoint() . ", 포인트 : $point");
}
$this->getModel()->where("Client_Code", $client->getClientCode());
$this->getModel()->update(["Client_Point=(Client_Point-{$point})" => null]);
return true;
}
}