dbms/app/Models/Customer/ClientModel.php
2025-07-11 13:23:26 +09:00

84 lines
2.7 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 = [
"code",
"name",
"email",
"phone",
"role",
"account_balance",
"coupon_balance",
"point_balance",
"status",
"updated_at"
];
public function __construct()
{
parent::__construct();
}
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;
}
//Create용
//FormFilter 조건절 처리
public function setList_FormFilter(string $field, mixed $filter_value): void
{
switch ($field) {
case 'role':
$where = "FIND_IN_SET(" . $this->escape($filter_value) . ", {$this->getTable()}.{$field}) > 0";
//FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동
$this->where($where, null, false);
break;
default:
parent::setList_FormFilter($field, $filter_value);
break;
}
}
//검색어조건절처리
//List 검색용
public function setList_WordFilter(string $word): void
{
$this->orLike(self::TABLE . '.email', $word, 'both');
parent::setList_WordFilter($word);
}
}