| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
- namespace App\Models;
-
- use CodeIgniter\Model;
-
- class VendorContactModel extends Model
- {
- protected $table = 'vendor_contacts';
- protected $primaryKey = 'id';
- protected $useAutoIncrement = true;
- protected $returnType = 'array';
- protected $useSoftDeletes = false;
-
- protected $allowedFields = [
- 'vendor_id', 'contact_type', 'name', 'position',
- 'phone', 'email', 'is_primary'
- ];
-
- protected $useTimestamps = true;
- protected $createdField = 'created_at';
- protected $updatedField = 'updated_at';
-
- protected $validationRules = [
- 'vendor_id' => 'required|integer|is_not_unique[vendors.id]',
- 'contact_type' => 'required|in_list[PRIMARY,SECONDARY,BILLING,TECHNICAL]',
- 'name' => 'required|max_length[100]',
- 'position' => 'permit_empty|max_length[100]',
- 'phone' => 'permit_empty|max_length[20]',
- 'email' => 'permit_empty|max_length[255]|valid_email',
- 'is_primary' => 'permit_empty|in_list[0,1]'
- ];
-
- protected $validationMessages = [
- 'vendor_id' => [
- 'required' => '벤더사 id는 필수입니다.',
- 'is_not_unique' => '존재하지 않는 벤더사입니다.'
- ],
- 'name' => [
- 'required' => '담당자명은 필수입니다.'
- ],
- 'email' => [
- 'valid_email' => '유효하지 않은 이메일 형식입니다.'
- ]
- ];
-
- // 기본 담당자로 설정
- public function setPrimaryContact($vendorId, $contactId)
- {
- $this->db->transStart();
-
- // 기존 기본 담당자 해제
- $this->where('vendor_id', $vendorId)
- ->set('is_primary', 0)
- ->update();
-
- // 새로운 기본 담당자 설정
- $this->update($contactId, ['is_primary' => 1]);
-
- $this->db->transComplete();
-
- return $this->db->transStatus();
- }
- }
|