dbmsv2/app/Models/Customer/ClientModel.php
2025-08-18 14:55:18 +09:00

70 lines
2.0 KiB
PHP

<?php
namespace App\Models\Customer;
use App\Entities\Customer\ClientEntity;
class ClientModel extends CustomerModel
{
const TABLE = "clientinfo";
const PK = "uid";
const TITLE = "name";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $allowedFields = [
"code",
"name",
"email",
"phone",
"role",
"account_balance",
"coupon_balance",
"point_balance",
"status",
"updated_at"
];
public function __construct()
{
parent::__construct();
$this->returnType = ClientEntity::class;
}
public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "name":
$rule = "required|trim|string";
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "role":
$rule = "required|trim|string";
break;
case "code":
$rule = "if_exist|trim|string";
break;
case "email":
$rule = "if_exist|trim|valid_email";
break;
case "account_balance":
case "coupon_balance":
case "point_balance":
$rule = "if_exist|numeric";
break;
default:
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;
}
protected function create_process(array $formDatas): ClientEntity
{
$entity = parent::create_process($formDatas);
// 생성 후, 추가 작업이 필요할 경우 여기에 작성
$formDatas = ['code' => SITE_PREFIX['Client'] . $entity->getPK()];
return $this->modify($entity, $formDatas);
}
}