78 lines
2.4 KiB
PHP
78 lines
2.4 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 $useAutoIncrement = false;
|
|
protected $primaryKey = self::PK;
|
|
protected $returnType = ClientEntity::class;
|
|
protected $allowedFields = [
|
|
"user_uid",
|
|
"site",
|
|
"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 "user_uid":
|
|
$rule = "required|numeric";
|
|
break;
|
|
case "code":
|
|
$rule = "required|trim|alpha_numeric|min_length[4]|max_length[20]";
|
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
|
|
break;
|
|
case "name":
|
|
$rule = "required|trim|string";
|
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
|
|
break;
|
|
case "site":
|
|
case "role":
|
|
$rule = "required|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[$formDatas['site']] . $entity->getPK()];
|
|
return $this->modify($entity, $formDatas);
|
|
}
|
|
}
|