| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Controllers;
- use App\Controllers\BaseController;
- use App\Models\UserModel;
- use App\Models\VendorInfluencerMappingModel;
- use CodeIgniter\HTTP\ResponseInterface;
- class InfluencerController extends BaseController
- {
- protected $userModel;
- protected $vendorInfluencerModel;
-
- public function __construct()
- {
- $this->userModel = new UserModel();
- $this->vendorInfluencerModel = new VendorInfluencerMappingModel();
- }
-
- /**
- * 인플루언서 프로필 조회
- */
- public function getProfile()
- {
- try {
- $request = $this->request->getJSON();
- $influencerSeq = $request->influencerSeq ?? null;
-
- if (!$influencerSeq) {
- return $this->response->setStatusCode(400)->setJSON([
- 'success' => false,
- 'message' => '인플루언서 SEQ가 필요합니다.'
- ]);
- }
-
- // 인플루언서 프로필 정보 조회
- $profile = $this->userModel
- ->select('SEQ, NICK_NAME, NAME, EMAIL, PROFILE_IMAGE, PRIMARY_CATEGORY,
- REGION, DESCRIPTION, SNS_CHANNELS, FOLLOWER_COUNT, ENGAGEMENT_RATE')
- ->where('SEQ', $influencerSeq)
- ->where('IS_ACT', 'Y')
- ->first();
-
- if (!$profile) {
- return $this->response->setStatusCode(404)->setJSON([
- 'success' => false,
- 'message' => '인플루언서를 찾을 수 없습니다.'
- ]);
- }
-
- // 협업 이력 조회
- $partnerships = $this->vendorInfluencerModel
- ->select('vim.*, v.COMPANY_NAME as vendorName')
- ->from('VENDOR_INFLUENCER_MAPPING vim')
- ->join('VENDOR_LIST v', 'vim.VENDOR_SEQ = v.SEQ', 'left')
- ->where('vim.INFLUENCER_SEQ', $influencerSeq)
- ->where('vim.IS_ACT', 'Y')
- ->orderBy('vim.REG_DATE', 'DESC')
- ->findAll();
-
- // 협업 건수 계산 (승인된 건수만)
- $partnershipCount = $this->vendorInfluencerModel
- ->where('INFLUENCER_SEQ', $influencerSeq)
- ->where('STATUS', 'APPROVED')
- ->where('IS_ACT', 'Y')
- ->countAllResults();
-
- return $this->response->setJSON([
- 'success' => true,
- 'data' => [
- 'profile' => $profile,
- 'partnerships' => $partnerships,
- 'partnershipCount' => $partnershipCount
- ]
- ]);
-
- } catch (\Exception $e) {
- return $this->response->setStatusCode(500)->setJSON([
- 'success' => false,
- 'message' => '프로필 조회 중 오류가 발생했습니다.',
- 'error' => ENVIRONMENT === 'development' ? $e->getMessage() : null
- ]);
- }
- }
- }
|