dbms/app/Models/Customer/ClientModel.php
2025-05-06 19:08:29 +09:00

74 lines
2.1 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 $returnType = ClientEntity::class;
protected $allowedFields = [
"name",
"email",
"phone",
"role",
"account_balance",
"coupon_balance",
"point_balance",
"status"
];
public function __construct()
{
parent::__construct();
}
public function getFilterFields(): array
{
return ['role', 'status'];
}
public function getBatchJobFields(): array
{
return ['status'];
}
public function getFieldRule(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";
break;
case "email":
$rule = "if_exist|trim|valid_email";
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "role":
$rule = "required|trim|string";
break;
case "account_balance":
case "coupon_balance":
case "point_balance":
$rule = "if_exist|trim|numeric";
break;
case "status":
$rule = "if_exist|in_list[use,pause]";
break;
default:
$rule = parent::getFieldRule($action, $field);
break;
}
return $rule;
}
//List 검색용
public function setList_WordFilter(string $word): void
{
$this->orLike(self::TABLE . "." . self::TITLE, $word, 'both');
$this->orLike(self::TABLE . '.email', $word, 'both');
}
}