InfluencerController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Controllers;
  3. use App\Controllers\BaseController;
  4. use App\Models\UserModel;
  5. use App\Models\VendorInfluencerMappingModel;
  6. use CodeIgniter\HTTP\ResponseInterface;
  7. class InfluencerController extends BaseController
  8. {
  9. protected $userModel;
  10. protected $vendorInfluencerModel;
  11. public function __construct()
  12. {
  13. $this->userModel = new UserModel();
  14. $this->vendorInfluencerModel = new VendorInfluencerMappingModel();
  15. }
  16. /**
  17. * 인플루언서 프로필 조회
  18. */
  19. public function getProfile()
  20. {
  21. try {
  22. $request = $this->request->getJSON();
  23. $influencerSeq = $request->influencerSeq ?? null;
  24. if (!$influencerSeq) {
  25. return $this->response->setStatusCode(400)->setJSON([
  26. 'success' => false,
  27. 'message' => '인플루언서 SEQ가 필요합니다.'
  28. ]);
  29. }
  30. // 인플루언서 프로필 정보 조회
  31. $profile = $this->userModel
  32. ->select('SEQ, NICK_NAME, NAME, EMAIL, PROFILE_IMAGE, PRIMARY_CATEGORY,
  33. REGION, DESCRIPTION, SNS_CHANNELS, FOLLOWER_COUNT, ENGAGEMENT_RATE')
  34. ->where('SEQ', $influencerSeq)
  35. ->where('IS_ACT', 'Y')
  36. ->first();
  37. if (!$profile) {
  38. return $this->response->setStatusCode(404)->setJSON([
  39. 'success' => false,
  40. 'message' => '인플루언서를 찾을 수 없습니다.'
  41. ]);
  42. }
  43. // 협업 이력 조회
  44. $partnerships = $this->vendorInfluencerModel
  45. ->select('vim.*, v.COMPANY_NAME as vendorName')
  46. ->from('VENDOR_INFLUENCER_MAPPING vim')
  47. ->join('VENDOR_LIST v', 'vim.VENDOR_SEQ = v.SEQ', 'left')
  48. ->where('vim.INFLUENCER_SEQ', $influencerSeq)
  49. ->where('vim.IS_ACT', 'Y')
  50. ->orderBy('vim.REG_DATE', 'DESC')
  51. ->findAll();
  52. // 협업 건수 계산 (승인된 건수만)
  53. $partnershipCount = $this->vendorInfluencerModel
  54. ->where('INFLUENCER_SEQ', $influencerSeq)
  55. ->where('STATUS', 'APPROVED')
  56. ->where('IS_ACT', 'Y')
  57. ->countAllResults();
  58. return $this->response->setJSON([
  59. 'success' => true,
  60. 'data' => [
  61. 'profile' => $profile,
  62. 'partnerships' => $partnerships,
  63. 'partnershipCount' => $partnershipCount
  64. ]
  65. ]);
  66. } catch (\Exception $e) {
  67. return $this->response->setStatusCode(500)->setJSON([
  68. 'success' => false,
  69. 'message' => '프로필 조회 중 오류가 발생했습니다.',
  70. 'error' => ENVIRONMENT === 'development' ? $e->getMessage() : null
  71. ]);
  72. }
  73. }
  74. }