95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\BillingEntity;
|
|
use App\Entities\ProductEntity;
|
|
|
|
class BillingModel extends BaseModel
|
|
{
|
|
private $_order_options = null;
|
|
protected $table = "tw_billing";
|
|
protected $returnType = BillingEntity::class;
|
|
protected $useSoftDeletes = true;
|
|
public function __construct()
|
|
{
|
|
parent::__construct('Billing');
|
|
$this->allowedFields = [
|
|
...$this->allowedFields, 'order_uid', "user_uid", "email", "phone",
|
|
"title", "upload_file", "response", "status"
|
|
];
|
|
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
|
|
}
|
|
final public function getTitleField(): string
|
|
{
|
|
return 'title';
|
|
}
|
|
public function getFieldRule(string $field, array $rules, string $action = ""): array
|
|
{
|
|
switch ($field) {
|
|
case 'order_uid':
|
|
$rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
|
break;
|
|
case "email":
|
|
$rules[$field] = "required|trim|valid_email";
|
|
break;
|
|
case "phone":
|
|
$rules[$field] = "if_exist|string";
|
|
break;
|
|
case $this->getTitleField():
|
|
$rules[$field] = "required|trim|string";
|
|
break;
|
|
case "upload_file": //uploaded[{$field}] == requried와 같은의미
|
|
$rules[$field] = "if_exist|string";
|
|
break;
|
|
case "response":
|
|
$rules[$field] = "if_exist|string";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules, $action);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
//Field별 Form Option용
|
|
public function getFieldFormOption(string $field): array
|
|
{
|
|
switch ($field) {
|
|
case 'order_uid':
|
|
if (is_null($this->_order_options)) {
|
|
$orderModel = new OrderModel();
|
|
$this->_order_options = $orderModel->getOptions();
|
|
}
|
|
$options = $this->_order_options;
|
|
break;
|
|
default:
|
|
return parent::getFieldFormOption($field);
|
|
break;
|
|
}
|
|
if (!is_array($options)) {
|
|
throw new \Exception(__FUNCTION__ . "에서 {$this->getClassName()}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
|
|
}
|
|
return $options;
|
|
}
|
|
public function getEntity($conditions): BillingEntity
|
|
{
|
|
return parent::getEntity($conditions);
|
|
}
|
|
public function create(array $formDatas): BillingEntity
|
|
{
|
|
return $this->create_process(new BillingEntity(), $formDatas);
|
|
}
|
|
public function modify(BillingEntity $entity, array $formDatas): BillingEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
//Index관련
|
|
public function setIndexWordFilter(string $word)
|
|
{
|
|
if ($word !== DEFAULTS['EMPTY']) {
|
|
parent::setIndexWordFilter($word);
|
|
$this->orLike($this->getTitleField(), $word, "both");
|
|
}
|
|
}
|
|
}
|