| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace App\Controllers;
- use App\Controllers\BaseController;
- use App\Models\VendorInfluencerMappingModel;
- use App\Models\UserModel;
- use CodeIgniter\HTTP\ResponseInterface;
- /**
- * 벤더-인플루언서 파트너십 해지 API 예제
- * 경로: POST /api/vendor-influencer/terminate
- */
- class VendorInfluencerTerminate extends BaseController
- {
- protected $vendorInfluencerModel;
- protected $userModel;
-
- public function __construct()
- {
- $this->vendorInfluencerModel = new VendorInfluencerMappingModel();
- $this->userModel = new UserModel();
- }
-
- /**
- * 승인된 파트너십 해지 처리
- */
- public function terminate()
- {
- try {
- $request = $this->request->getJSON();
-
- $mappingSeq = $request->mappingSeq ?? null;
- $terminateReason = $request->terminateReason ?? null;
- $terminatedBy = $request->terminatedBy ?? null;
-
- // 필수 파라미터 검증
- if (!$mappingSeq || !$terminateReason || !$terminatedBy) {
- return $this->response->setStatusCode(400)->setJSON([
- 'success' => false,
- 'message' => '필수 파라미터가 누락되었습니다. (mappingSeq, terminateReason, terminatedBy 필요)'
- ]);
- }
-
- // 해지 사유 길이 검증
- if (strlen($terminateReason) > 500) {
- return $this->response->setStatusCode(400)->setJSON([
- 'success' => false,
- 'message' => '해지 사유는 500자를 초과할 수 없습니다.'
- ]);
- }
-
- // 기존 매핑 확인 (승인된 상태여야 함)
- $existingMapping = $this->vendorInfluencerModel
- ->where('SEQ', $mappingSeq)
- ->where('STATUS', 'APPROVED')
- ->where('IS_ACT', 'Y')
- ->first();
-
- if (!$existingMapping) {
- return $this->response->setStatusCode(404)->setJSON([
- 'success' => false,
- 'message' => '해지할 수 있는 승인된 파트너십을 찾을 수 없습니다.'
- ]);
- }
-
- // 해지 권한 확인 (벤더사 또는 관련 사용자만 해지 가능)
- $terminatingUser = $this->userModel
- ->where('SEQ', $terminatedBy)
- ->where('IS_ACT', 'Y')
- ->first();
-
- if (!$terminatingUser) {
- return $this->response->setStatusCode(400)->setJSON([
- 'success' => false,
- 'message' => '해지 처리자 정보를 찾을 수 없습니다.'
- ]);
- }
-
- // 해지 처리 데이터 준비
- $terminateData = [
- 'STATUS' => 'TERMINATED',
- 'RESPONSE_MESSAGE' => '파트너십 해지: ' . $terminateReason,
- 'RESPONSE_DATE' => date('Y-m-d H:i:s'),
- 'APPROVED_BY' => $terminatedBy, // 해지 처리자
- 'PARTNERSHIP_END_DATE' => date('Y-m-d H:i:s'), // 파트너십 종료일
- 'MOD_DATE' => date('Y-m-d H:i:s')
- ];
-
- log_message('info', "파트너십 해지 처리 시작 - 매핑 SEQ: {$mappingSeq}, 해지자: {$terminatedBy}");
-
- // 해지 처리 실행
- $result = $this->vendorInfluencerModel->update($mappingSeq, $terminateData);
-
- if (!$result) {
- log_message('error', "파트너십 해지 업데이트 실패 - 매핑 SEQ: {$mappingSeq}");
- return $this->response->setStatusCode(500)->setJSON([
- 'success' => false,
- 'message' => '파트너십 해지 처리 중 데이터베이스 오류가 발생했습니다.'
- ]);
- }
-
- // 해지된 매핑 정보 조회
- $terminatedMapping = $this->vendorInfluencerModel
- ->select('vim.SEQ, vim.VENDOR_SEQ, vim.INFLUENCER_SEQ, vim.STATUS,
- vim.RESPONSE_MESSAGE, vim.RESPONSE_DATE, vim.PARTNERSHIP_END_DATE,
- v.COMPANY_NAME as vendorName,
- inf.NICK_NAME as influencerNickname, inf.NAME as influencerName')
- ->from('VENDOR_INFLUENCER_MAPPING vim')
- ->join('VENDOR_LIST v', 'vim.VENDOR_SEQ = v.SEQ', 'left')
- ->join('USER_LIST inf', 'vim.INFLUENCER_SEQ = inf.SEQ', 'left')
- ->where('vim.SEQ', $mappingSeq)
- ->get()
- ->getRowArray();
-
- log_message('info', "파트너십 해지 완료 - 매핑 SEQ: {$mappingSeq}");
-
- return $this->response->setJSON([
- 'success' => true,
- 'message' => '파트너십이 성공적으로 해지되었습니다.',
- 'data' => [
- 'terminatedMapping' => $terminatedMapping,
- 'terminateDate' => date('Y-m-d H:i:s'),
- 'terminatedBy' => $terminatingUser['NICK_NAME'] ?? $terminatingUser['NAME']
- ]
- ]);
-
- } catch (\Exception $e) {
- log_message('error', "파트너십 해지 처리 중 예외 발생: " . $e->getMessage());
-
- return $this->response->setStatusCode(500)->setJSON([
- 'success' => false,
- 'message' => '파트너십 해지 처리 중 오류가 발생했습니다.',
- 'error' => ENVIRONMENT === 'development' ? $e->getMessage() : null
- ]);
- }
- }
- }
- /**
- * 라우터 설정 예제 (routes.php에 추가)
- *
- * $routes->group('api/vendor-influencer', ['namespace' => 'App\Controllers'], function($routes) {
- * $routes->post('terminate', 'VendorInfluencerController::terminate');
- * });
- */
- /**
- * 프론트엔드에서 호출 예제
- *
- * const params = {
- * mappingSeq: 123,
- * terminateReason: "계약 조건 위반으로 인한 해지",
- * terminatedBy: 8 // 해지 처리자 USER SEQ
- * };
- *
- * useAxios()
- * .post('/api/vendor-influencer/terminate', params)
- * .then((res) => {
- * if (res.data.success) {
- * console.log('해지 완료:', res.data.data);
- * // 성공 처리
- * } else {
- * console.error('해지 실패:', res.data.message);
- * // 실패 처리
- * }
- * })
- * .catch((err) => {
- * console.error('해지 오류:', err);
- * });
- */
- /**
- * 응답 예제
- *
- * 성공시:
- * {
- * "success": true,
- * "message": "파트너십이 성공적으로 해지되었습니다.",
- * "data": {
- * "terminatedMapping": {
- * "SEQ": 123,
- * "VENDOR_SEQ": 8,
- * "INFLUENCER_SEQ": 23,
- * "STATUS": "TERMINATED",
- * "RESPONSE_MESSAGE": "파트너십 해지: 계약 조건 위반으로 인한 해지",
- * "RESPONSE_DATE": "2025-07-23 10:30:00",
- * "PARTNERSHIP_END_DATE": "2025-07-23 10:30:00",
- * "vendorName": "테스트 벤더사",
- * "influencerNickname": "인플루언서닉네임",
- * "influencerName": "인플루언서이름"
- * },
- * "terminateDate": "2025-07-23 10:30:00",
- * "terminatedBy": "벤더관리자"
- * }
- * }
- *
- * 실패시:
- * {
- * "success": false,
- * "message": "해지할 수 있는 승인된 파트너십을 찾을 수 없습니다."
- * }
- */
|