init
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Accounting;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class TaxController extends BaseController
|
||||
{
|
||||
public function tax()
|
||||
{
|
||||
return view('accounting/tax/tax');
|
||||
}
|
||||
|
||||
public function taxList()
|
||||
{
|
||||
return view('accounting/tax/tax_list');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Accounting;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class UnpaidController extends BaseController
|
||||
{
|
||||
public function unpaid()
|
||||
{
|
||||
return view('accounting/unpaid/unpaid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Accounting;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Accounting\WithdrawModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class WithdrawController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $wd;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->wd = model(WithdrawModel::class);
|
||||
}
|
||||
public function withdraw()
|
||||
{
|
||||
return view('accounting/withdraw/withdraw');
|
||||
}
|
||||
|
||||
public function withdrawList()
|
||||
{
|
||||
return view('accounting/withdraw/withdraw_list');
|
||||
}
|
||||
|
||||
public function withdrawWrite(){
|
||||
return view('accounting/withdraw/withdraw_write');
|
||||
}
|
||||
|
||||
public function accountList(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$data = $this->request->getRawInput();
|
||||
$result = $this->wd->accountList($data);
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function typeList(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$result = $this->wd->typeList();
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function userList(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$result = $this->wd->userList();
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$data = $this->request->getRawInput();
|
||||
$result = $this->wd->getList($data);
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function excelDownload(){
|
||||
$data = $this->request->getRawInput();
|
||||
$transformedData = json_decode($this->wd->getList($data),true);
|
||||
$columns = $this->getColumns();
|
||||
|
||||
$fileData = $this->createExcelFile($transformedData, $columns);
|
||||
$contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||
$fileExtension = 'xlsx';
|
||||
|
||||
return $this->response
|
||||
->setHeader('Content-Type', $contentType)
|
||||
->setHeader('Content-Disposition', 'attachment; filename="event_lead_' . date('YmdHis') . '.' . $fileExtension . '"')
|
||||
->setBody($fileData);
|
||||
}
|
||||
|
||||
private function createExcelFile($data, $columns)
|
||||
{
|
||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// 헤더 설정
|
||||
$columnIndex = 'A';
|
||||
$sheet->setCellValue($columnIndex . '1', '#');
|
||||
$columnIndex++;
|
||||
foreach ($columns as $key => $header) {
|
||||
$sheet->setCellValue($columnIndex . '1', $header);
|
||||
// if (in_array($key, ['addr', 'email', 'add1', 'add2', 'add3', 'add4', 'add5', 'add6'])) {
|
||||
// $sheet->getColumnDimension($columnIndex)->setAutoSize(true);
|
||||
// $sheet->getColumnDimension($columnIndex)->setWidth(200 / 7); // 최대 200픽셀로 제한
|
||||
// } else if ($key === 'name') {
|
||||
// $sheet->getColumnDimension($columnIndex)->setWidth(100 / 7); // 100픽셀로 설정 (엑셀의 너비 단위는 약 1/7인치)
|
||||
// } else {
|
||||
$sheet->getColumnDimension($columnIndex)->setAutoSize(true); // 자동 너비 조정
|
||||
// }
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
// 필터 설정
|
||||
$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
|
||||
|
||||
// 데이터 삽입
|
||||
$rowIndex = 2; // 데이터는 2번째 행부터 시작
|
||||
$totalRows = count($data);
|
||||
|
||||
foreach ($data as $row) {
|
||||
|
||||
$columnIndex = 'A';
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $totalRows); // 역순 카운트
|
||||
$columnIndex++;
|
||||
|
||||
foreach ($columns as $key => $header) {
|
||||
$value = $row[$key];
|
||||
|
||||
if(!isset($row["gwstatus"])){
|
||||
$row["gwstatus"]="";
|
||||
}else if(strpos($row["gwstatus"],"http") > -1){
|
||||
$row["gwstatus"]="완료";
|
||||
}
|
||||
|
||||
// if ($key === 'phone') {
|
||||
// $value = preg_replace("/([0-9]{3})([0-9]{4})([0-9]{4})/", "$1-$2-$3", $value);
|
||||
// $sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
// } elseif($key === 'age') {
|
||||
// $value = $value == 0 ? "" : $value;
|
||||
// $sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
// } elseif ($key === 'site') {
|
||||
// $sheet->getCell($columnIndex . $rowIndex)->setValueExplicit($value, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
|
||||
// } else {
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
// }
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$rowIndex++;
|
||||
$totalRows--;
|
||||
}
|
||||
|
||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||
ob_start();
|
||||
$writer->save('php://output');
|
||||
$excelData = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $excelData;
|
||||
}
|
||||
|
||||
private function getColumns()
|
||||
{
|
||||
$columns = [
|
||||
'reg_date' => '등록일시',
|
||||
'nickname' => '이름',
|
||||
'type' => '구분',
|
||||
'company_name' => '거래처명(입금주명)',
|
||||
'bank' => '은행',
|
||||
'account' => '계좌번호',
|
||||
'detail' => '내역(자세히)',
|
||||
'total_price' => '총금액(VAT 포함)',
|
||||
'memo' => '비고',
|
||||
'status' => '결과',
|
||||
'gwstatus'=>'결제현황',
|
||||
'date' => '출금완료일',
|
||||
];
|
||||
|
||||
// if(auth()->user()->hasPermission('integrate.description')
|
||||
// || auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
// $columns = array_merge(
|
||||
// array_slice($columns, 0, 2, true),
|
||||
// ['description' => '구분'],
|
||||
// array_slice($columns, 2, null, true)
|
||||
// );
|
||||
// }
|
||||
// if(auth()->user()->hasPermission('integrate.media')
|
||||
// || auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
// $columns = array_merge(
|
||||
// array_slice($columns, 0, 2, true),
|
||||
// ['media' => '매체'],
|
||||
// array_slice($columns, 2, null, true)
|
||||
// );
|
||||
// }
|
||||
// if(auth()->user()->hasPermission('integrate.advertiser')
|
||||
// || auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
// $columns = array_merge(
|
||||
// array_slice($columns, 0, 2, true),
|
||||
// ['advertiser' => '광고주'],
|
||||
// array_slice($columns, 2, null, true)
|
||||
// );
|
||||
// }
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Advertisement;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Api\AdLeadModel;
|
||||
use App\ThirdParty\facebook_api\ZenithFB;
|
||||
use App\ThirdParty\googleads_api\ZenithGG;
|
||||
use App\ThirdParty\moment_api\ZenithKM;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
class AdLeadController extends BaseController
|
||||
{
|
||||
protected $adlead, $facebook, $google, $kakao;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->adlead = model(AdLeadModel::class);
|
||||
$this->facebook = new ZenithFB();
|
||||
$this->google = new ZenithGG();
|
||||
$this->kakao = new ZenithKM();
|
||||
}
|
||||
|
||||
public function sendToEventLead()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("잠재고객 업데이트를 시작합니다.", "yellow");
|
||||
$this->sendToEventLeadFromKakao();
|
||||
$this->sendToEventLeadFromFacebook();
|
||||
//$this->sendToEventLeadFromGoogle();
|
||||
CLI::write("잠재고객 업데이트가 완료되었습니다.", "yellow");
|
||||
}
|
||||
|
||||
private function sendToEventLeadFromKakao()
|
||||
{
|
||||
$moment_ads = $this->adlead->getBizFormUserResponse();
|
||||
$step = 1;
|
||||
$total = $moment_ads->getNumRows();
|
||||
if(!$total){
|
||||
return null;
|
||||
}
|
||||
CLI::write("카카오 모먼트 잠재고객 업데이트를 시작합니다.", "yellow");
|
||||
foreach($moment_ads->getResultArray() as $row){
|
||||
CLI::showProgress($step++, $total);
|
||||
if (!empty($row['code'])) {
|
||||
$title = trim($row['code']);
|
||||
}else{
|
||||
$title = $row['name'];
|
||||
}
|
||||
$landing = $this->kakao->landingGroup($title, $row['landingUrl'] ?? '');
|
||||
if(is_null($landing)) {
|
||||
CLI::print('비즈폼 매칭 오류 발생 : ' . $row . '');
|
||||
continue;
|
||||
}
|
||||
|
||||
//전화번호
|
||||
$phone = str_replace("+82010", "010", $row['phoneNumber']);
|
||||
$phone = str_replace("+8210", "010", $phone);
|
||||
$phone = preg_replace("/^8210(.+)$/", "010$1", $phone);
|
||||
$phone = str_replace("+82 10", "010", $phone);
|
||||
$phone = str_replace("-", "", $phone);
|
||||
if ($row['email'] == '없음') $row['email'] = '';
|
||||
|
||||
//추가질문
|
||||
$questions = [];
|
||||
$add = [];
|
||||
$responses = json_decode($row['responses'], 1);
|
||||
$acnt = 1;
|
||||
|
||||
$addr = $add1 = $add2 = $add3 = $add4 = $add5 = null;
|
||||
foreach ($responses as $response) {
|
||||
$qs = $this->adlead->getBizformQuestion($row['bizFormId'], $response['bizformItemId']);
|
||||
if(is_null($qs)) continue;
|
||||
if (!key_exists($qs['id'], $questions))
|
||||
$questions[$qs['id']] = $qs['title'];
|
||||
$add[] = ${'add' . $acnt} = $questions[$response['bizformItemId']] . '::' . $response['response'];
|
||||
$acnt++;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
if ($landing['event_seq']) {
|
||||
$result['event_seq'] = $landing['event_seq'];
|
||||
$result['site'] = $landing['site']??null;
|
||||
$result['name'] = $row['nickname'];
|
||||
$result['email'] = $row['email']??'';
|
||||
$result['gender'] = $row['gender']??null;
|
||||
$result['age'] = $row['age'] ?? 0;
|
||||
$result['phone'] = $phone;
|
||||
$result['add1'] = $add1;
|
||||
$result['add2'] = $add2;
|
||||
$result['add3'] = $add3;
|
||||
$result['add4'] = $add4;
|
||||
$result['add5'] = $add5;
|
||||
$result['addr'] = $addr;
|
||||
$result['reg_timestamp'] = strtotime($row['submitAt']);
|
||||
$result['lead_id'] = $row['id']??null;
|
||||
$result['encUserId'] = $row['encUserId'];
|
||||
$result['bizFormId'] = $row['bizFormId'];
|
||||
}
|
||||
|
||||
if (is_array($result) && count($result)) {
|
||||
$this->adlead->insertEventLeadKakao($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function sendToEventLeadFromFacebook()
|
||||
{
|
||||
$facebook_ads = $this->adlead->getFBAdLead();
|
||||
$step = 1;
|
||||
$total = count($facebook_ads);
|
||||
if(!$total){
|
||||
return null;
|
||||
}
|
||||
CLI::write("페이스북 잠재고객 업데이트를 시작합니다.", "yellow");
|
||||
foreach($facebook_ads as $row){
|
||||
CLI::showProgress($step++, $total);
|
||||
if (!empty($row['code'])) {
|
||||
$title = trim($row['code']);
|
||||
}else{
|
||||
$title = $row['ad_name'];
|
||||
}
|
||||
$landing = $this->facebook->landingGroup($title);
|
||||
//이름
|
||||
$full_name = $row['full_name'];
|
||||
if (!$full_name || $full_name == null) {
|
||||
$full_name = trim($row['first_name'] . ' ' . $row['last_name']);
|
||||
}
|
||||
|
||||
//성별
|
||||
if ($row['gender'] == "female") {
|
||||
$gender = "여자";
|
||||
} elseif ($row['gender'] == "male") {
|
||||
$gender = "남자";
|
||||
} else {
|
||||
$gender = $row['gender'];
|
||||
}
|
||||
|
||||
//나이
|
||||
if ($row['date_of_birth']) {
|
||||
$birthyear = date("Y", strtotime($row['date_of_birth']));
|
||||
$nowyear = date("Y");
|
||||
$age = $nowyear - $birthyear + 1;
|
||||
} else {
|
||||
$age = "";
|
||||
}
|
||||
|
||||
//전화번호
|
||||
$phone = str_replace("+82010", "010", $row['phone_number']);
|
||||
$phone = str_replace("+8210", "010", $phone);
|
||||
$phone = str_replace("-", "", $phone);
|
||||
|
||||
|
||||
//주소
|
||||
if ($row['street_address']) {
|
||||
$addr = $row['street_address'];
|
||||
} else {
|
||||
$addr = "";
|
||||
}
|
||||
|
||||
//추가질문
|
||||
preg_match_all("/0 => \'(.*)\',/iU", $row['field_data'], $match);
|
||||
if (isset($match[1][0])) {
|
||||
$add1 = $match[1][0];
|
||||
} else {
|
||||
$add1 = "";
|
||||
}
|
||||
if (isset($match[1][1])) {
|
||||
$add2 = $match[1][1];
|
||||
} else {
|
||||
$add2 = "";
|
||||
}
|
||||
if (isset($match[1][2])) {
|
||||
$add3 = $match[1][2];
|
||||
} else {
|
||||
$add3 = "";
|
||||
}
|
||||
if (isset($match[1][3])) {
|
||||
$add4 = $match[1][3];
|
||||
} else {
|
||||
$add4 = "";
|
||||
}
|
||||
if (isset($match[1][4])) {
|
||||
$add5 = $match[1][4];
|
||||
} else {
|
||||
$add5 = "";
|
||||
}
|
||||
|
||||
if ($landing['event_seq']) {
|
||||
$result['event_seq'] = $landing['event_seq'];
|
||||
$result['site'] = $landing['site'];
|
||||
$result['name'] = addslashes($full_name);
|
||||
$result['gender'] = $gender;
|
||||
$result['age'] = $age ?? 0;
|
||||
$result['phone'] = $phone;
|
||||
$result['add1'] = addslashes($add1);
|
||||
$result['add2'] = addslashes($add2);
|
||||
$result['add3'] = addslashes($add3);
|
||||
$result['add4'] = addslashes($add4);
|
||||
$result['add5'] = addslashes($add5);
|
||||
$result['addr'] = $addr;
|
||||
$result['reg_date'] = $row['created_time'];
|
||||
$result['id'] = $row['id'];
|
||||
|
||||
if (is_array($result)) {
|
||||
$this->adlead->insertEventLeadFacebook($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function sendToEventLeadFromGoogle()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace App\Controllers\Advertisement;
|
||||
use App\Controllers\BaseController;
|
||||
use App\ThirdParty\facebook_api\ZenithFB;
|
||||
use App\ThirdParty\moment_api\ZenithKM;
|
||||
use App\ThirdParty\googleads_api\ZenithGG;
|
||||
|
||||
class ApiController extends BaseController
|
||||
{
|
||||
protected $chainsaw;
|
||||
/*
|
||||
public function __construct(...$params) {
|
||||
print_r($params); exit;
|
||||
include APPPATH."/ThirdParty/facebook_api/facebook-api.php";
|
||||
$this->chainsaw = new \ChainsawFB();
|
||||
}
|
||||
*/
|
||||
public function _remap($method, ...$params) {
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->{$method}(...$params);
|
||||
}
|
||||
|
||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
protected function facebook(...$params) {
|
||||
$this->chainsaw = new ZenithFB();
|
||||
$this->fb_func(...$params);
|
||||
}
|
||||
protected function moment(...$params) {
|
||||
$this->chainsaw = new ZenithKM();
|
||||
$this->fb_func(...$params);
|
||||
}
|
||||
protected function google(...$params) {
|
||||
$this->chainsaw = new ZenithGG();
|
||||
$this->fb_func(...$params);
|
||||
}
|
||||
|
||||
protected function fb_func(...$params) {
|
||||
if (method_exists($this->chainsaw, $params[0])) {
|
||||
$result = $this->chainsaw->{$params[0]}();
|
||||
if(in_array('grid', $params)) $this->chainsaw->grid($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
//안쓰는거
|
||||
/*
|
||||
protected function kakaoMoment(...$params) {
|
||||
include APPPATH."/ThirdParty/moment_api/kmapi.php";
|
||||
$this->chainsaw = new \ChainsawKM();
|
||||
$this->km_func(...$params);
|
||||
}
|
||||
|
||||
protected function km_func(...$params) {
|
||||
if (method_exists($this->chainsaw, $params[0])) {
|
||||
$result = $this->chainsaw->{$params[0]}();
|
||||
if(in_array('grid', $params)) $this->chainsaw->grid($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
namespace App\Controllers\Advertisement;
|
||||
|
||||
use App\ThirdParty\facebook_api\ZenithFB;
|
||||
use App\Libraries\slack_api\SlackChat;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
|
||||
class Facebook extends Controller
|
||||
{
|
||||
private $zenith;
|
||||
private $slack;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->zenith = new ZenithFB();
|
||||
$this->slack = new SlackChat();
|
||||
}
|
||||
|
||||
public function initController(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$date = "";
|
||||
$today = date('Y-m-d');
|
||||
$argv = @$request->getServer()['argv'];
|
||||
if(!is_null($argv)) {
|
||||
$method = $argv[2];
|
||||
$params = @array_slice($argv, 3);
|
||||
if(!@count($params)) return;
|
||||
foreach($params as $v) {
|
||||
$value = preg_replace('/[^0-9\-]+/', '', $v);
|
||||
if(preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $value)) { //request argument에 날짜형식이 있는지 체크
|
||||
$date = $v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
$hour = date("G"); //24-hour format of an hour without leading zeros
|
||||
if($date == $today && ($hour >= 0 && $hour <= 7)) {
|
||||
CLI::write("당일 0시~8시는 자동업데이트를 사용할 수 없습니다.", "light_purple");
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccounts() {
|
||||
$this->zenith->updateAdAccounts();
|
||||
}
|
||||
|
||||
public function getLongLivedAccessToken() {
|
||||
$this->zenith->getLongLivedAccessToken();
|
||||
}
|
||||
|
||||
public function getInsight($all=null, $date=null, $edate=null) {
|
||||
CLI::clearScreen();
|
||||
if($all == null)
|
||||
$all = CLI::prompt("인사이트가 수신된 캠페인,광고그룹,광고 데이터를 함께 수신하시겠습니까?\n(시간이 오래 걸릴 수 있습니다.)", ["true","false"]);
|
||||
if($date == null)
|
||||
$date = CLI::prompt("인사이트를 수신할 기간 중 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($edate == null)
|
||||
$edate = CLI::prompt("인사이트를 수신할 기간 중 종료날짜를 입력해주세요.", $date);
|
||||
// $run = CLI::prompt("광고데이터를 ".($all=="true"?"포함":"미포함")."하여 {$date} ~ {$edate} 기간의 인사이트를 수신합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
$this->zenith->getAsyncInsights($all, $date, $edate);
|
||||
CLI::write("데이터 수신이 완료되었습니다.", "yellow");
|
||||
}
|
||||
|
||||
public function adLeadByAd($ad_id = null, $from = null, $to = null) {
|
||||
CLI::clearScreen();
|
||||
if($ad_id == null)
|
||||
$ad_id = CLI::prompt("잠재고객 업데이트 할 광고ID를 입력해주세요.");
|
||||
if($from == null)
|
||||
$from = CLI::prompt("잠재고객 업데이트 할 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($to == null)
|
||||
$to = CLI::prompt("잠재고객 업데이트 할 종료날짜를 입력해주세요.", $from);
|
||||
$result = $this->zenith->adLeadByAd($ad_id, $from, $to);
|
||||
CLI::write("잠재고객 업데이트 완료되었습니다.", "yellow");
|
||||
}
|
||||
|
||||
public function getAdLead($from = null, $to = null) {
|
||||
CLI::clearScreen();
|
||||
if($from == null)
|
||||
$from = CLI::prompt("잠재고객 업데이트 할 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($to == null)
|
||||
$to = CLI::prompt("잠재고객 업데이트 할 종료날짜를 입력해주세요.", date('Y-m-d'));
|
||||
// $run = CLI::prompt("{$from}~{$to}일자의 잠재고객을 업데이트 합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
$this->zenith->getAdLead($from, $to);
|
||||
}
|
||||
|
||||
public function updateAll() {
|
||||
CLI::clearScreen();
|
||||
// $run = CLI::prompt("캠페인/광고그룹/광고를 업데이트 합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
CLI::write("캠페인/광고그룹/광고를 업데이트 합니다.", "light_red");
|
||||
$this->zenith->updateAllByAccounts();
|
||||
/*
|
||||
$getAds = $this->zenith->getAds();
|
||||
$updateAdsets = $this->zenith->updateAdsets($getAds);
|
||||
$updateCampaigns = $this->zenith->updateCampaigns($updateAdsets);
|
||||
*/
|
||||
}
|
||||
|
||||
public function updateDB($sdate = null, $edate = null) {
|
||||
CLI::clearScreen();
|
||||
if($sdate == null)
|
||||
$sdate = CLI::prompt("유효DB 업데이트 할 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($edate == null)
|
||||
$edate = CLI::prompt("유효DB 업데이트 할 종료날짜를 입력해주세요.", $sdate);
|
||||
$sdate = date_create($sdate);
|
||||
$edate = date_create(date('Y-m-d', strtotime($edate.'+1 days')));
|
||||
$interval = DateInterval::createFromDateString('1 day');
|
||||
$date_range = new DatePeriod($sdate, $interval, $edate);
|
||||
foreach($date_range as $date) {
|
||||
$date = $date->format('Y-m-d');
|
||||
CLI::write("{$date} 유효DB를 업데이트 합니다.", "light_red");
|
||||
$this->zenith->getAdsUseLanding($date);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateCampaign() {
|
||||
$campaign_id = CLI::prompt("업데이트 할 캠페인 ID를 입력해주세요.", null);
|
||||
if(is_null($campaign_id)) return;
|
||||
$data = [
|
||||
['campaign_id'=>$campaign_id]
|
||||
];
|
||||
$campaign = $this->zenith->updateCampaigns($data);
|
||||
print_r($campaign);
|
||||
}
|
||||
|
||||
public function updateAds() {
|
||||
CLI::clearScreen();
|
||||
// $run = CLI::prompt("광고를 업데이트 합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
CLI::write("광고를 업데이트 합니다.", "light_red");
|
||||
|
||||
$this->zenith->updateAds();
|
||||
}
|
||||
public function updateAdCreatives() {
|
||||
CLI::clearScreen();
|
||||
$ad_id = CLI::prompt("업데이트 할 광고 ID를 입력해주세요.", null);
|
||||
if(is_null($ad_id)) return;
|
||||
$data = [
|
||||
['id'=>$ad_id]
|
||||
];
|
||||
// $run = CLI::prompt("광고를 업데이트 합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
CLI::write("광고소재를 업데이트 합니다.", "light_red");
|
||||
|
||||
$adcreative = $this->zenith->updateAdCreatives($data);
|
||||
print_r($adcreative);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace App\Controllers\Advertisement;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\ThirdParty\googleads_api\ZenithGG;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Paths;
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
|
||||
class GoogleAds extends BaseController
|
||||
{
|
||||
private $chainsaw;
|
||||
|
||||
public function __construct(...$param)
|
||||
{
|
||||
$this->chainsaw = new ZenithGG();
|
||||
}
|
||||
|
||||
public function getAccounts()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("광고계정 수신을 진행합니다.", "light_red");
|
||||
$this->chainsaw->getAccounts();
|
||||
CLI::write("광고계정 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
public function getReports($date=null, $edate=null) {
|
||||
CLI::clearScreen();
|
||||
if($date == null)
|
||||
$date = CLI::prompt("리포트를 수신할 기간 중 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($edate == null)
|
||||
$edate = CLI::prompt("리포트를 수신할 기간 중 종료날짜를 입력해주세요.", $date);
|
||||
// $run = CLI::prompt("광고데이터를 ".($all=="true"?"포함":"미포함")."하여 {$date} ~ {$edate} 기간의 인사이트를 수신합니다.",["y","n"]);
|
||||
// if($run != 'y') return false;
|
||||
$this->chainsaw->getReports($date, $edate);
|
||||
CLI::write("데이터 수신이 완료되었습니다.", "yellow");
|
||||
$this->chainsaw->getAdsUseLanding($date);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("계정/계정예산/에셋/캠페인/그룹/소재/보고서 업데이트를 진행합니다.", "light_red");
|
||||
$result = $this->chainsaw->getAll();
|
||||
CLI::write("계정/계정예산/에셋/캠페인/그룹/소재/보고서 업데이트 완료", "yellow");
|
||||
// $paths = new Paths();
|
||||
// $log_file = fopen($paths->writableDirectory . '/logs/GoogleAdsGetAll.txt', 'a');
|
||||
// fwrite($log_file, $result . "\r\n\r\n");
|
||||
// fclose($log_file);
|
||||
}
|
||||
public function getAdSchedules() {
|
||||
$result = $this->chainsaw->getAdSchedules();
|
||||
}
|
||||
|
||||
public function updateDB($sdate = null, $edate = null) {
|
||||
CLI::clearScreen();
|
||||
$cliArgs = CLI::getOptions();
|
||||
$is_result = false;
|
||||
$ids = [];
|
||||
if (isset($cliArgs['result'])) {
|
||||
$is_result = $cliArgs['result'];
|
||||
}
|
||||
if (isset($cliArgs['ids'])) {
|
||||
$ids = $cliArgs['ids'];
|
||||
}
|
||||
if($sdate == null) {
|
||||
$sdate = CLI::prompt("유효DB 업데이트 할 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
}
|
||||
if($edate == null) {
|
||||
$edate = CLI::prompt("유효DB 업데이트 할 종료날짜를 입력해주세요.", $sdate);
|
||||
}
|
||||
if(!empty($ids)) {
|
||||
$ids = explode(',', $ids);
|
||||
}
|
||||
$sdate = date_create($sdate);
|
||||
$edate = date_create(date('Y-m-d', strtotime($edate.'+1 days')));
|
||||
$interval = DateInterval::createFromDateString('1 day');
|
||||
$date_range = new DatePeriod($sdate, $interval, $edate);
|
||||
foreach($date_range as $date) {
|
||||
$date = $date->format('Y-m-d');
|
||||
CLI::write("{$date} 유효DB를 업데이트 합니다.", "light_red");
|
||||
$result = $this->chainsaw->getAdsUseLanding($date, $ids);
|
||||
if($is_result) print_r($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function getReport() {
|
||||
$accounts = [
|
||||
['manageCustomer'=> 7792262348,'customerId'=>4658512480]
|
||||
];
|
||||
$this->chainsaw->getReports('2024-05-31', '2024-05-31', $accounts);
|
||||
}
|
||||
|
||||
public function getCampaign() {
|
||||
$campaigns = $this->chainsaw->getCampaigns('7792262348', '1705230747', '20870581914');
|
||||
dd($campaigns);
|
||||
}
|
||||
|
||||
public function getCriterion() {
|
||||
// $campaigns = $this->chainsaw->getCriterions('7792262348', '1705230747', '20870581914');
|
||||
// $campaigns = $this->chainsaw->getCriterions('7792262348', '8023466215', '20999659346');
|
||||
$campaigns = $this->chainsaw->getCriterions('7792262348', '9049844350', '20979863645');
|
||||
dd($campaigns);
|
||||
}
|
||||
|
||||
public function getAdGroups() {
|
||||
$adgroups = $this->chainsaw->getAdGroups('5980790227', '3931611101', '20581900068');
|
||||
dd($adgroups);
|
||||
}
|
||||
|
||||
public function getAds() {
|
||||
$ads = $this->chainsaw->getAds('5980790227', '3288458378', '130392657290', '2023-12-22');
|
||||
dd($ads);
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
$getAll = $this->chainsaw->getAll(null, [['manageCustomer'=>7177486093, 'customerId'=>9604111811]]);
|
||||
dd($getAll);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Advertisement;
|
||||
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use App\ThirdParty\moment_api\ZenithKM;
|
||||
use CodeIgniter\Controller;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
|
||||
class KakaoMoment extends Controller
|
||||
{
|
||||
private $chainsaw;
|
||||
private $run_proc = [];
|
||||
|
||||
public function __construct(...$param)
|
||||
{
|
||||
$this->chainsaw = new ZenithKM();
|
||||
}
|
||||
|
||||
public function initController(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$uname = php_uname();
|
||||
if(stripos($uname, 'windows') === false) {
|
||||
@exec("ps ax | grep -i kmapi | grep -v grep", $exec);
|
||||
if($exec) {
|
||||
foreach($exec as $v) $proc[] = preg_replace('/^.+php\skmapi\s(.+)$/', '$1', $v);
|
||||
foreach($proc as $v) {
|
||||
$method = preg_replace('/^([a-z]+)\s.+$/i', '$1', $v);
|
||||
$_params = preg_replace('/^([a-z]+)\s(.+)$/i', '$2', str_replace('\\', '', $v));
|
||||
$params = explode(' ', $_params);
|
||||
$this->run_proc = [
|
||||
'method' => $method,
|
||||
'params' => $params
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function oauth() {
|
||||
return $this->chainsaw->oauth();
|
||||
}
|
||||
//토큰 업데이트
|
||||
public function refresh_token()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("토큰 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->refresh_token();
|
||||
CLI::write("토큰 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//전체 광고계정 업데이트
|
||||
public function updateAdAccounts()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("전체 광고계정 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->updateAdAccounts();
|
||||
CLI::write("전체 광고계정 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//캠페인 데이터 업데이트
|
||||
public function updateCampaigns()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("캠페인 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->updateCampaigns();
|
||||
CLI::write("캠페인 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//광고그룹 데이터 업데이트
|
||||
public function updateAdGroups()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("광고그룹 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->updateAdGroups();
|
||||
CLI::write("광고그룹 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//소재 데이터 업데이트
|
||||
public function updateCreatives()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("소재 데이터 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->updateCreatives();
|
||||
CLI::write("소재 데이터 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//전체 소재 보고서 BASIC 업데이트
|
||||
/*
|
||||
public function updateReportByAdgroup($date = null)
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("소재 보고서 업데이트를 진행합니다.", "light_red");
|
||||
if(is_null($date))
|
||||
$date = CLI::prompt("전체 소재 보고서 BASIC 수신할 날짜를 입력해주세요.(ex. ".date('Y-m-d', strtotime('-1 day')).")", 'TODAY');
|
||||
$this->chainsaw->updateCreativesReportBasic($date);
|
||||
CLI::write("소재 보고서 업데이트 완료", "yellow");
|
||||
}
|
||||
*/
|
||||
public function updateReportByHour($date = null)
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("소재 보고서 업데이트를 진행합니다.", "light_red");
|
||||
if(is_null($date))
|
||||
$date = CLI::prompt("전체 소재 보고서 BASIC 수신할 날짜를 입력해주세요.(ex. ".date('Y-m-d', strtotime('-1 day')).")", 'TODAY');
|
||||
$this->chainsaw->updateHourReportBasic($date);
|
||||
CLI::write("소재 보고서 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
public function getAll() {
|
||||
$this->chainsaw->updateAdAccounts();
|
||||
$this->chainsaw->updateCampaigns();
|
||||
$this->chainsaw->updateAdGroups();
|
||||
$this->chainsaw->updateCreatives();
|
||||
$this->chainsaw->updateBizform();
|
||||
}
|
||||
|
||||
|
||||
//비즈폼 데이터 업데이트
|
||||
public function updateBizform()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("비즈폼 데이터 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->updateBizform();
|
||||
CLI::write("비즈폼 데이터 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//app_subscribe 데이터 업데이트
|
||||
/* public function moveToAppsubscribe()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("app_subscribe 데이터 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->moveToLeads();
|
||||
CLI::write("app_subscribe 데이터 업데이트 완료", "yellow");
|
||||
} */
|
||||
|
||||
//유효DB 개수 업데이트
|
||||
public function updateDB($sdate = null, $edate = null) {
|
||||
CLI::clearScreen();
|
||||
if($sdate == null)
|
||||
$sdate = CLI::prompt("유효DB 업데이트 할 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($edate == null)
|
||||
$edate = CLI::prompt("유효DB 업데이트 할 종료날짜를 입력해주세요.", $sdate);
|
||||
$sdate = date_create($sdate);
|
||||
$edate = date_create(date('Y-m-d', strtotime($edate.'+1 days')));
|
||||
$interval = DateInterval::createFromDateString('1 day');
|
||||
$date_range = new DatePeriod($sdate, $interval, $edate);
|
||||
foreach($date_range as $date) {
|
||||
$date = $date->format('Y-m-d');
|
||||
CLI::write("{$date} 유효DB를 업데이트 합니다.", "light_red");
|
||||
$result = $this->chainsaw->getCreativesUseLanding($date);
|
||||
}
|
||||
}
|
||||
|
||||
//리포트데이터를 업데이트
|
||||
public function updateReportByDate($sdate=null, $edate=null)
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("리포트데이터를 업데이트를 진행합니다.", "light_red");
|
||||
if($sdate == null)
|
||||
$sdate = CLI::prompt("리포트데이터를 수신할 기간 중 시작날짜를 입력해주세요.", date('Y-m-d'));
|
||||
if($edate == null)
|
||||
$edate = CLI::prompt("리포트데이터를 수신할 기간 중 종료날짜를 입력해주세요.", $sdate);
|
||||
$this->chainsaw->updateReportByDate($sdate, $edate);
|
||||
CLI::write("리포트데이터 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//소재 자동 변경
|
||||
public function autoCreativeOnOff()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("소재 자동 변경을 진행합니다.", "light_red");
|
||||
$check = CLI::prompt("전체 소재 보고서 BASIC 수신할 날짜를 입력해주세요.", ['on', 'off']);
|
||||
$this->chainsaw->autoCreativeOnOff();
|
||||
CLI::write("소재 자동 변경 완료", "yellow");
|
||||
}
|
||||
|
||||
//자동 입찰가한도 리셋
|
||||
public function autoLimitBidAmountReset()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("자동 입찰가한도 리셋을 진행합니다.", "light_red");
|
||||
$date = CLI::prompt("자동 입찰가한도 리셋할 날짜를 입력해주세요.", date('Y-m-d'));
|
||||
$this->chainsaw->autoLimitBidAmountReset($date);
|
||||
CLI::write("자동 입찰가한도 리셋 완료", "yellow");
|
||||
}
|
||||
|
||||
//자동 입찰가 설정
|
||||
public function autoLimitBidAmount()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("자동 입찰가한도 설정을 진행합니다.", "light_red");
|
||||
$date = CLI::prompt("자동 입찰가한도 설정할 날짜를 입력해주세요.", date('Y-m-d'));
|
||||
$this->chainsaw->autoLimitBidAmount($date);
|
||||
CLI::write("자동 입찰가한도 설정 완료", "yellow");
|
||||
}
|
||||
|
||||
//자동 예산한도 리셋
|
||||
public function autoLimitBudgetReset()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("자동 예산한도 리셋을 진행합니다.", "light_red");
|
||||
$date = CLI::prompt("자동 예산한도 리셋할 날짜를 입력해주세요.", date('Y-m-d'));
|
||||
$this->chainsaw->autoLimitBudgetReset($date);
|
||||
CLI::write("자동 예산한도 리셋 완료", "yellow");
|
||||
}
|
||||
|
||||
//자동 예산한도 설정
|
||||
public function autoLimitBudget()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("자동 예산한도 설정을 진행합니다.", "light_red");
|
||||
$date = CLI::prompt("자동 예산한도 설정할 날짜를 입력해주세요.", date('Y-m-d'));
|
||||
$this->chainsaw->autoLimitBudget();
|
||||
CLI::write("자동 예산한도 설정 완료", "yellow");
|
||||
}
|
||||
|
||||
//광고그룹 AI 업데이트
|
||||
public function setAdGroupsAiRun()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("광고그룹 AI 업데이트를 진행합니다.", "light_red");
|
||||
$this->chainsaw->setAdGroupsAiRun();
|
||||
CLI::write("광고그룹 AI 업데이트 완료", "yellow");
|
||||
}
|
||||
|
||||
//AI 자동켜기
|
||||
public function autoAiOn()
|
||||
{
|
||||
CLI::clearScreen();
|
||||
CLI::write("AI를 시작합니다.", "light_red");
|
||||
$this->chainsaw->autoAiOn();
|
||||
CLI::write("AI 시작", "yellow");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\AdvertisementManager;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Advertiser\AdvEtcManagerModel;
|
||||
|
||||
class AdvEtcManagerController extends BaseController
|
||||
{
|
||||
protected $advEtcManagerModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->advEtcManagerModel = model(AdvEtcManagerModel::class);
|
||||
}
|
||||
|
||||
// 기본 페이지 로드
|
||||
public function index()
|
||||
{
|
||||
return view('advertisements/etc/etc');
|
||||
}
|
||||
|
||||
public function getList() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$date = $this->request->getPost('date') ?? ['sdate' => date('Y-m-d'), 'edate' => date('Y-m-d')];
|
||||
$sdate = (new \DateTime($date['sdate']))->format('Y-m-d') . ' 00:00:00';
|
||||
$edate = (new \DateTime($date['edate']))->format('Y-m-d') . ' 23:59:59';
|
||||
|
||||
$data = $this->advEtcManagerModel->getList(['sdate' => $sdate, 'edate' => $edate]);
|
||||
|
||||
return $this->response->setJSON([
|
||||
'data' => $data // dataTables에 맞게 'data' 키 사용
|
||||
]);
|
||||
} else {
|
||||
return $this->response->setStatusCode(403)->setBody('Access denied');
|
||||
}
|
||||
}
|
||||
|
||||
public function updateData()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$result = $this->advEtcManagerModel->updateOrInsertEventData($data);
|
||||
|
||||
if ($result) {
|
||||
return $this->response->setJSON(['status' => 'success', 'message' => 'Data updated successfully']);
|
||||
} else {
|
||||
return $this->response->setJSON(['status' => 'error', 'message' => 'Failed to update data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\AdvertisementManager;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Advertiser\AdvFacebookManagerModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class AdvFacebookManagerController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $facebook;
|
||||
public function __construct()
|
||||
{
|
||||
$this->facebook = model(AdvFacebookManagerModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('advertisements/facebook/facebook');
|
||||
}
|
||||
|
||||
public function getAccounts()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'businesses' => $this->request->getGet('businesses'),
|
||||
];
|
||||
|
||||
$accounts = $this->facebook->getAccounts($arg);
|
||||
$getDisapprovalByAccount = $this->getDisapprovalByAccount();
|
||||
foreach ($accounts as &$account) {
|
||||
|
||||
$account['class'] = [];
|
||||
$account['db_ratio'] = 0;
|
||||
|
||||
if ($account['status'] != 1)
|
||||
array_push($account['class'], 'tag-inactive');
|
||||
if (in_array($account['id'], $getDisapprovalByAccount))
|
||||
array_push($account['class'], 'disapproval');
|
||||
|
||||
$account['db_count'] = $account['db_count'] * $account['date_count'];
|
||||
|
||||
if($account['db_sum'] && $account['db_count'])
|
||||
$account['db_ratio'] = round($account['db_sum'] / $account['db_count'] * 100,1);
|
||||
|
||||
if($account['db_ratio'] >= 100) {
|
||||
$account['db_ratio'] = 100;
|
||||
array_push($account['class'], 'over');
|
||||
}
|
||||
|
||||
if(!$account['db_sum']) $account['db_sum'] = 0;
|
||||
}
|
||||
|
||||
return $this->respond($accounts);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'type' => $this->request->getGet('type'),
|
||||
'businesses' => $this->request->getGet('businesses'),
|
||||
'accounts' => $this->request->getGet('accounts'),
|
||||
'stx' => $this->request->getGet('stx'),
|
||||
];
|
||||
|
||||
if($arg['type'] == 'ads'){
|
||||
$result = $this->getAds($arg);
|
||||
}else if($arg['type'] == 'adsets'){
|
||||
$result = $this->getAdSets($arg);
|
||||
}else{
|
||||
$result = $this->getCampaigns($arg);
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getReport()
|
||||
{
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
$arg = [
|
||||
'sdate' => $this->request->getGet('sdate'),
|
||||
'edate' => $this->request->getGet('edate'),
|
||||
];
|
||||
}else{
|
||||
$arg = [
|
||||
'sdate' => date("Y-m-d"),
|
||||
'edate' => date("Y-m-d"),
|
||||
];
|
||||
}
|
||||
|
||||
$res = $this->facebook->getReport($arg)->get()->getResultArray();
|
||||
$columnIndex = 0;
|
||||
$data = [];
|
||||
foreach($res as $row) {
|
||||
$data[] = $row;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($val == NULL) $val = "0";
|
||||
$total[$col][$columnIndex] = $val;
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = $report['clicks_sum'] = $report['click_ratio_sum'] = $report['spend_sum'] = $report['unique_total_sum'] = $report['unique_one_price_sum'] = $report['conversion_ratio_sum'] = $report['profit_sum'] = $report['per_sum'] = $report['price_sum'] = 0;
|
||||
|
||||
if(!empty($res)){
|
||||
$report['impressions_sum'] = array_sum($total['impressions']); //총 노출수
|
||||
$report['clicks_sum'] = array_sum($total['click']); //총 클릭수
|
||||
if ($report['clicks_sum'] != 0 && $report['impressions_sum'] != 0) {
|
||||
$report['click_ratio_sum'] = round(($report['clicks_sum'] / $report['impressions_sum']) * 100, 2); //총 클릭률
|
||||
}
|
||||
$report['spend_sum'] = array_sum($total['spend']); //총 지출액
|
||||
$report['unique_total_sum'] = array_sum($total['unique_total']); //총 유효db수
|
||||
if ($report['spend_sum'] != 0 && $report['unique_total_sum'] != 0) {
|
||||
$report['unique_one_price_sum'] = round($report['spend_sum'] / $report['unique_total_sum'], 0); //총 db당 단가
|
||||
}
|
||||
if ($report['unique_total_sum'] != 0 && $report['clicks_sum'] != 0) {
|
||||
$report['conversion_ratio_sum'] = round(($report['unique_total_sum'] / $report['clicks_sum']) * 100, 2); //총 전환율
|
||||
}
|
||||
$report['price_sum'] = array_sum($total['price']); //총 매출액
|
||||
$report['profit_sum'] = array_sum($total['profit']); //총 수익
|
||||
if ($report['profit_sum'] != 0 && $report['price_sum'] != 0) {
|
||||
$report['per_sum'] = round(($report['profit_sum'] / $report['price_sum']) * 100, 2); //총 수익률
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = number_format($report['impressions_sum']);
|
||||
$report['clicks_sum'] = number_format($report['clicks_sum']);
|
||||
$report['spend_sum'] = number_format($report['spend_sum']);
|
||||
$report['unique_one_price_sum'] = number_format($report['unique_one_price_sum']);
|
||||
$report['price_sum'] = number_format($report['price_sum']);
|
||||
$report['profit_sum'] = number_format($report['profit_sum']);
|
||||
}
|
||||
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
return $this->respond($report);
|
||||
}else{
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
||||
private function getCampaigns($arg)
|
||||
{
|
||||
$campaigns = $this->facebook->getCampaigns($arg);
|
||||
$campaigns = $this->facebook->getStatuses("campaigns", $campaigns, $arg['dates']);
|
||||
$total = $this->getTotal($campaigns);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $campaigns,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAdSets($arg)
|
||||
{
|
||||
$adsets = $this->facebook->getAdSets($arg);
|
||||
$adsets = $this->facebook->getStatuses("adsets", $adsets, $arg['dates']);
|
||||
$total = $this->getTotal($adsets);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $adsets
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAds($arg)
|
||||
{
|
||||
$ads = $this->facebook->getAds($arg);
|
||||
$ads = $this->facebook->getStatuses("ads", $ads, $arg['dates']);
|
||||
$total = $this->getTotal($ads);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $ads
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDisapprovalByAccount()
|
||||
{
|
||||
$disapprovals = $this->facebook->getDisapproval();
|
||||
$data = [];
|
||||
foreach ($disapprovals as $row) {
|
||||
$data[] = $row['ad_account_id'];
|
||||
}
|
||||
$data = array_unique($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getTotal($datas)
|
||||
{
|
||||
$total = [];
|
||||
$total['impressions'] = 0;
|
||||
$total['click'] = 0;
|
||||
$total['spend'] = 0;
|
||||
$total['margin'] = 0;
|
||||
$total['unique_total'] = 0;
|
||||
$total['sales'] = 0;
|
||||
$total['budget'] = 0;
|
||||
$total['cpc'] = 0;
|
||||
$total['ctr'] = 0;
|
||||
$total['cpa'] = 0;
|
||||
$total['cvr'] = 0;
|
||||
$total['margin_ratio'] = 0;
|
||||
$total['expect_db'] = 0;
|
||||
foreach($datas as $data){
|
||||
$total['impressions'] +=$data['impressions'];
|
||||
$total['click'] +=$data['click'];
|
||||
$total['spend'] +=$data['spend'];
|
||||
$total['margin'] +=$data['margin'];
|
||||
$total['unique_total'] +=$data['unique_total'];
|
||||
$total['sales'] +=$data['sales'];
|
||||
$total['budget'] +=$data['budget'];
|
||||
$total['cpc'] +=$data['cpc'];
|
||||
$total['ctr'] +=$data['ctr'];
|
||||
$total['cpa'] +=$data['cpa'];
|
||||
$total['cvr'] +=$data['cvr'];
|
||||
$total['margin_ratio'] +=$data['margin_ratio'];
|
||||
|
||||
//CPC(Cost Per Click: 클릭당단가 (1회 클릭당 비용)) = 지출액/링크클릭
|
||||
if($total['click'] > 0){
|
||||
$total['avg_cpc'] = $total['spend'] / $total['click'];
|
||||
}else{
|
||||
$total['avg_cpc'] = 0;
|
||||
}
|
||||
|
||||
//CTR(Click Through Rate: 클릭율 (노출 대비 클릭한 비율)) = (링크클릭/노출수)*100
|
||||
$total['avg_ctr'] = ($total['click'] / $total['impressions']) * 100;
|
||||
|
||||
//CPA(Cost Per Action: 현재 DB단가(전환당 비용)) = 지출액/유효db
|
||||
if($total['unique_total'] > 0){
|
||||
$total['avg_cpa'] = $total['spend'] / $total['unique_total'];
|
||||
}else{
|
||||
$total['avg_cpa'] = 0;
|
||||
}
|
||||
|
||||
//CVR(Conversion Rate:전환율 = (유효db / 링크클릭)*100
|
||||
if ($total['click'] > 0) {
|
||||
$total['avg_cvr'] = ($total['unique_total'] / $total['click']) * 100;
|
||||
} else {
|
||||
$total['avg_cvr'] = 0;
|
||||
}
|
||||
|
||||
//수익률 = (수익/매출액)*100
|
||||
if ($total['sales'] > 0) {
|
||||
$total['avg_margin_ratio'] = ($total['margin'] / $total['sales']) * 100;
|
||||
} else {
|
||||
$total['avg_margin_ratio'] = 0;
|
||||
}
|
||||
|
||||
if ($data['status'] == 'ACTIVE' && $data['unique_total']){
|
||||
$total['expect_db'] += round($data['budget'] / $data['cpa']);
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\AdvertisementManager;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Advertiser\AdvGoogleManagerModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class AdvGoogleManagerController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $google;
|
||||
public function __construct()
|
||||
{
|
||||
$this->google = model(AdvGoogleManagerModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('advertisements/google/google');
|
||||
}
|
||||
|
||||
public function getManageAccounts()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$accounts = $this->google->getManageAccounts();
|
||||
return $this->respond($accounts);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccounts()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'businesses' => $this->request->getGet('businesses'),
|
||||
];
|
||||
|
||||
$accounts = $this->google->getAccounts($arg);
|
||||
$getDisapprovalByAccount = $this->getDisapprovalByAccount();
|
||||
foreach ($accounts as &$account) {
|
||||
|
||||
$account['class'] = [];
|
||||
$account['db_ratio'] = '';
|
||||
|
||||
if($account['is_exposed'] === 0)
|
||||
array_push($account['class'], 'tag-inactive');
|
||||
if(in_array($account['id'], $getDisapprovalByAccount))
|
||||
array_push($account['class'], 'disapproval');
|
||||
|
||||
$account['db_count'] = $account['db_count'] * $account['date_count'];
|
||||
|
||||
if($account['db_sum'] && $account['db_count'])
|
||||
$account['db_ratio'] = round($account['db_sum'] / $account['db_count'] * 100,1);
|
||||
|
||||
if($account['db_ratio'] >= 100) {
|
||||
$account['db_ratio'] = 100;
|
||||
array_push($account['class'], 'over');
|
||||
}
|
||||
|
||||
if(!$account['db_sum']) $account['db_sum'] = 0;
|
||||
}
|
||||
|
||||
return $this->respond($accounts);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'type' => $this->request->getGet('type'),
|
||||
'businesses' => $this->request->getGet('businesses'),
|
||||
'accounts' => $this->request->getGet('accounts'),
|
||||
'stx' => $this->request->getGet('stx'),
|
||||
];
|
||||
|
||||
if($arg['type'] == 'ads'){
|
||||
$result = $this->getAds($arg);
|
||||
}else if($arg['type'] == 'adsets'){
|
||||
$result = $this->getAdSets($arg);
|
||||
}else{
|
||||
$result = $this->getCampaigns($arg);
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getReport()
|
||||
{
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
$arg = [
|
||||
'sdate' => $this->request->getGet('sdate'),
|
||||
'edate' => $this->request->getGet('edate'),
|
||||
];
|
||||
}else{
|
||||
$arg = [
|
||||
'sdate' => date("Y-m-d"),
|
||||
'edate' => date("Y-m-d"),
|
||||
];
|
||||
}
|
||||
|
||||
$res = $this->google->getReport($arg)->get()->getResultArray();
|
||||
$columnIndex = 0;
|
||||
$data = [];
|
||||
foreach($res as $row) {
|
||||
$data[] = $row;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($val == NULL) $val = "0";
|
||||
$total[$col][$columnIndex] = $val;
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = $report['clicks_sum'] = $report['click_ratio_sum'] = $report['spend_sum'] = $report['unique_total_sum'] = $report['unique_one_price_sum'] = $report['conversion_ratio_sum'] = $report['profit_sum'] = $report['per_sum'] = $report['price_sum'] = 0;
|
||||
|
||||
if(!empty($res)){
|
||||
$report['impressions_sum'] = array_sum($total['impressions']); //총 노출수
|
||||
$report['clicks_sum'] = array_sum($total['click']); //총 클릭수
|
||||
if ($report['clicks_sum'] != 0 && $report['impressions_sum'] != 0) {
|
||||
$report['click_ratio_sum'] = round(($report['clicks_sum'] / $report['impressions_sum']) * 100, 2); //총 클릭률
|
||||
}
|
||||
$report['spend_sum'] = array_sum($total['spend']); //총 지출액
|
||||
$report['unique_total_sum'] = array_sum($total['unique_total']); //총 유효db수
|
||||
if ($report['spend_sum'] != 0 && $report['unique_total_sum'] != 0) {
|
||||
$report['unique_one_price_sum'] = round($report['spend_sum'] / $report['unique_total_sum'], 0); //총 db당 단가
|
||||
}
|
||||
if ($report['unique_total_sum'] != 0 && $report['clicks_sum'] != 0) {
|
||||
$report['conversion_ratio_sum'] = round(($report['unique_total_sum'] / $report['clicks_sum']) * 100, 2); //총 전환율
|
||||
}
|
||||
$report['price_sum'] = array_sum($total['price']); //총 매출액
|
||||
$report['profit_sum'] = array_sum($total['profit']); //총 수익
|
||||
if ($report['profit_sum'] != 0 && $report['price_sum'] != 0) {
|
||||
$report['per_sum'] = round(($report['profit_sum'] / $report['price_sum']) * 100, 2); //총 수익률
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = number_format($report['impressions_sum']);
|
||||
$report['clicks_sum'] = number_format($report['clicks_sum']);
|
||||
$report['spend_sum'] = number_format($report['spend_sum']);
|
||||
$report['unique_one_price_sum'] = number_format($report['unique_one_price_sum']);
|
||||
$report['price_sum'] = number_format($report['price_sum']);
|
||||
$report['profit_sum'] = number_format($report['profit_sum']);
|
||||
}
|
||||
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
return $this->respond($report);
|
||||
}else{
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
||||
private function getCampaigns($arg)
|
||||
{
|
||||
$campaigns = $this->google->getCampaigns($arg);
|
||||
$campaigns = $this->google->getStatuses("campaigns", $campaigns, $arg['dates']);
|
||||
$total = $this->getTotal($campaigns);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $campaigns,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAdSets($arg)
|
||||
{
|
||||
$adsets = $this->google->getAdSets($arg);
|
||||
$adsets = $this->google->getStatuses("adsets", $adsets, $arg['dates']);
|
||||
$total = $this->getTotal($adsets);
|
||||
|
||||
foreach ($adsets as &$adset) {
|
||||
$adset['bidAmount'] = max([$adset['cpcBidAmount'],$adset['cpmBidAmount']]);
|
||||
if($adset['biddingStrategyType'] == '타겟 CPA')
|
||||
$adset['bidAmount'] = $adset['cpaBidAmount'];
|
||||
}
|
||||
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $adsets
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAds($arg)
|
||||
{
|
||||
$ads = $this->google->getAds($arg);
|
||||
$ads = $this->google->getStatuses("ads", $ads, $arg['dates']);
|
||||
$total = $this->getTotal($ads);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $ads
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDisapprovalByAccount()
|
||||
{
|
||||
$disapprovals = $this->google->getDisapproval();
|
||||
$data = [];
|
||||
foreach ($disapprovals as $row) {
|
||||
$data[] = $row['customerId'];
|
||||
}
|
||||
$data = array_unique($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getTotal($datas)
|
||||
{
|
||||
$total = [];
|
||||
$total['impressions'] = 0;
|
||||
$total['click'] = 0;
|
||||
$total['spend'] = 0;
|
||||
$total['margin'] = 0;
|
||||
$total['unique_total'] = 0;
|
||||
$total['sales'] = 0;
|
||||
$total['budget'] = 0;
|
||||
$total['cpc'] = 0;
|
||||
$total['ctr'] = 0;
|
||||
$total['cpa'] = 0;
|
||||
$total['cvr'] = 0;
|
||||
$total['margin_ratio'] = 0;
|
||||
$total['expect_db'] = 0;
|
||||
foreach($datas as $data){
|
||||
$total['impressions'] +=$data['impressions'];
|
||||
$total['click'] +=$data['click'];
|
||||
$total['spend'] +=$data['spend'];
|
||||
$total['margin'] +=$data['margin'];
|
||||
$total['unique_total'] +=$data['unique_total'];
|
||||
$total['sales'] +=$data['sales'];
|
||||
$total['budget'] +=$data['budget'];
|
||||
$total['cpc'] +=$data['cpc'];
|
||||
$total['ctr'] +=$data['ctr'];
|
||||
$total['cpa'] +=$data['cpa'];
|
||||
$total['cvr'] +=$data['cvr'];
|
||||
$total['margin_ratio'] +=$data['margin_ratio'];
|
||||
|
||||
//CPC(Cost Per Click: 클릭당단가 (1회 클릭당 비용)) = 지출액/링크클릭
|
||||
if($total['click'] > 0){
|
||||
$total['avg_cpc'] = $total['spend'] / $total['click'];
|
||||
}else{
|
||||
$total['avg_cpc'] = 0;
|
||||
}
|
||||
|
||||
//CTR(Click Through Rate: 클릭율 (노출 대비 클릭한 비율)) = (링크클릭/노출수)*100
|
||||
$total['avg_ctr'] = ($total['click'] / $total['impressions']) * 100;
|
||||
|
||||
//CPA(Cost Per Action: 현재 DB단가(전환당 비용)) = 지출액/유효db
|
||||
if($total['unique_total'] > 0){
|
||||
$total['avg_cpa'] = $total['spend'] / $total['unique_total'];
|
||||
}else{
|
||||
$total['avg_cpa'] = 0;
|
||||
}
|
||||
|
||||
//CVR(Conversion Rate:전환율 = (유효db / 링크클릭)*100
|
||||
if ($total['click'] > 0) {
|
||||
$total['avg_cvr'] = ($total['unique_total'] / $total['click']) * 100;
|
||||
} else {
|
||||
$total['avg_cvr'] = 0;
|
||||
}
|
||||
|
||||
//수익률 = (수익/매출액)*100
|
||||
if ($total['sales'] > 0) {
|
||||
$total['avg_margin_ratio'] = ($total['margin'] / $total['sales']) * 100;
|
||||
} else {
|
||||
$total['avg_margin_ratio'] = 0;
|
||||
}
|
||||
|
||||
if ($data['status'] == 'ACTIVE' && $data['unique_total']){
|
||||
$total['expect_db'] += round($data['budget'] / $data['cpa']);
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\AdvertisementManager;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Advertiser\AdvKakaoManagerModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class AdvKakaoManagerController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $kakao;
|
||||
public function __construct()
|
||||
{
|
||||
$this->kakao = model(AdvKakaoManagerModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('advertisements/kakao/kakao');
|
||||
}
|
||||
|
||||
public function getAccounts()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'businesses' => $this->request->getGet('businesses'),
|
||||
];
|
||||
|
||||
$accounts = $this->kakao->getAccounts($arg);
|
||||
$getDisapprovalByAccount = $this->getDisapprovalByAccount();
|
||||
foreach ($accounts as &$account) {
|
||||
$account['class'] = [];
|
||||
if($account['config'] == 'OFF' || $account['isAdminStop'] == 1)
|
||||
array_push($account['class'], 'tag-inactive');
|
||||
if(is_array($getDisapprovalByAccount) && in_array($account['id'], $getDisapprovalByAccount))
|
||||
array_push($account['class'], 'disapproval');
|
||||
}
|
||||
|
||||
return $this->respond($accounts);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'type' => $this->request->getGet('type'),
|
||||
'accounts' => $this->request->getGet('accounts'),
|
||||
'stx' => $this->request->getGet('stx'),
|
||||
];
|
||||
|
||||
if($arg['type'] == 'ads'){
|
||||
$result = $this->getAds($arg);
|
||||
}else if($arg['type'] == 'adsets'){
|
||||
$result = $this->getAdSets($arg);
|
||||
}else{
|
||||
$result = $this->getCampaigns($arg);
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getReport()
|
||||
{
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
$arg = [
|
||||
'sdate' => $this->request->getGet('sdate'),
|
||||
'edate' => $this->request->getGet('edate'),
|
||||
];
|
||||
}else{
|
||||
$arg = [
|
||||
'sdate' => date("Y-m-d"),
|
||||
'edate' => date("Y-m-d"),
|
||||
];
|
||||
}
|
||||
|
||||
$res = $this->kakao->getReport($arg)->get()->getResultArray();
|
||||
$columnIndex = 0;
|
||||
$data = [];
|
||||
foreach($res as $row) {
|
||||
$data[] = $row;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($val == NULL) $val = "0";
|
||||
$total[$col][$columnIndex] = $val;
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = $report['clicks_sum'] = $report['click_ratio_sum'] = $report['spend_sum'] = $report['unique_total_sum'] = $report['unique_one_price_sum'] = $report['conversion_ratio_sum'] = $report['profit_sum'] = $report['per_sum'] = 0;
|
||||
|
||||
if(!empty($res)){
|
||||
$report['impressions_sum'] = array_sum($total['impressions']); //총 노출수
|
||||
$report['clicks_sum'] = array_sum($total['click']); //총 클릭수
|
||||
if($report['clicks_sum'] != 0 && $report['impressions_sum'] != 0) {
|
||||
$report['click_ratio_sum'] = round(($report['clicks_sum'] / $report['impressions_sum']) * 100,2); //총 클릭률
|
||||
}
|
||||
$report['spend_sum'] = array_sum($total['spend']); //총 지출액
|
||||
$report['unique_total_sum'] = array_sum($total['unique_total']); //총 유효db수
|
||||
if($report['spend_sum'] != 0 && $report['unique_total_sum'] != 0) {
|
||||
$report['unique_one_price_sum'] = round($report['spend_sum'] / $report['unique_total_sum'],0); //총 db당 단가
|
||||
}
|
||||
if($report['unique_total_sum'] != 0 && $report['clicks_sum'] != 0) {
|
||||
$report['conversion_ratio_sum'] = round(($report['unique_total_sum'] / $report['clicks_sum']) * 100,2); //총 전환율
|
||||
}
|
||||
$report['price_sum'] = array_sum($total['price']); //총 매출액
|
||||
$report['profit_sum'] = array_sum($total['profit']); //총 수익
|
||||
if($report['profit_sum'] != 0 && $report['price_sum'] != 0) {
|
||||
$report['per_sum'] = round(($report['profit_sum'] / $report['price_sum']) * 100,2); //총 수익률
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = number_format($report['impressions_sum']);
|
||||
$report['clicks_sum'] = number_format($report['clicks_sum']);
|
||||
$report['spend_sum'] = number_format($report['spend_sum']);
|
||||
$report['unique_one_price_sum'] = number_format($report['unique_one_price_sum']);
|
||||
$report['price_sum'] = number_format($report['price_sum']);
|
||||
$report['profit_sum'] = number_format($report['profit_sum']);
|
||||
}
|
||||
|
||||
if(isset($this->request) && $this->request->isAJAX()){
|
||||
return $this->respond($report);
|
||||
}else{
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
||||
private function getCampaigns($arg)
|
||||
{
|
||||
$campaigns = $this->kakao->getCampaigns($arg);
|
||||
$campaigns = $this->kakao->getStatuses("campaigns", $campaigns, $arg['dates']);
|
||||
$total = $this->getTotal($campaigns);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $campaigns,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAdSets($arg)
|
||||
{
|
||||
$adsets = $this->kakao->getAdSets($arg);
|
||||
$adsets = $this->kakao->getStatuses("adsets", $adsets, $arg['dates']);
|
||||
$total = $this->getTotal($adsets);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $adsets
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAds($arg)
|
||||
{
|
||||
$ads = $this->kakao->getAds($arg);
|
||||
$ads = $this->kakao->getStatuses("ads", $ads, $arg['dates']);
|
||||
$total = $this->getTotal($ads);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $ads
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDisapprovalByAccount()
|
||||
{
|
||||
$disapprovals = $this->kakao->getDisapproval();
|
||||
$data = [];
|
||||
foreach ($disapprovals as $row) {
|
||||
$data[] = $row['account_id'];
|
||||
}
|
||||
$data = array_unique($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getTotal($datas)
|
||||
{
|
||||
$total = [];
|
||||
$total['impressions'] = 0;
|
||||
$total['click'] = 0;
|
||||
$total['spend'] = 0;
|
||||
$total['margin'] = 0;
|
||||
$total['unique_total'] = 0;
|
||||
$total['sales'] = 0;
|
||||
$total['budget'] = 0;
|
||||
$total['cpc'] = 0;
|
||||
$total['ctr'] = 0;
|
||||
$total['cpa'] = 0;
|
||||
$total['cvr'] = 0;
|
||||
$total['margin_ratio'] = 0;
|
||||
$total['expect_db'] = 0;
|
||||
foreach($datas as $data){
|
||||
$total['impressions'] +=$data['impressions'];
|
||||
$total['click'] +=$data['click'];
|
||||
$total['spend'] +=$data['spend'];
|
||||
$total['margin'] +=$data['margin'];
|
||||
$total['unique_total'] +=$data['unique_total'];
|
||||
$total['sales'] +=$data['sales'];
|
||||
$total['budget'] +=$data['budget'];
|
||||
$total['cpc'] +=$data['cpc'];
|
||||
$total['ctr'] +=$data['ctr'];
|
||||
$total['cpa'] +=$data['cpa'];
|
||||
$total['cvr'] +=$data['cvr'];
|
||||
$total['margin_ratio'] +=$data['margin_ratio'];
|
||||
|
||||
//CPC(Cost Per Click: 클릭당단가 (1회 클릭당 비용)) = 지출액/링크클릭
|
||||
if($total['click'] > 0){
|
||||
$total['avg_cpc'] = $total['spend'] / $total['click'];
|
||||
}else{
|
||||
$total['avg_cpc'] = 0;
|
||||
}
|
||||
|
||||
//CTR(Click Through Rate: 클릭율 (노출 대비 클릭한 비율)) = (링크클릭/노출수)*100
|
||||
$total['avg_ctr'] = ($total['click'] / $total['impressions']) * 100;
|
||||
|
||||
//CPA(Cost Per Action: 현재 DB단가(전환당 비용)) = 지출액/유효db
|
||||
if($total['unique_total'] > 0){
|
||||
$total['avg_cpa'] = $total['spend'] / $total['unique_total'];
|
||||
}else{
|
||||
$total['avg_cpa'] = 0;
|
||||
}
|
||||
|
||||
//CVR(Conversion Rate:전환율 = (유효db / 링크클릭)*100
|
||||
if ($total['click'] > 0) {
|
||||
$total['avg_cvr'] = ($total['unique_total'] / $total['click']) * 100;
|
||||
} else {
|
||||
$total['avg_cvr'] = 0;
|
||||
}
|
||||
|
||||
//수익률 = (수익/매출액)*100
|
||||
if ($total['sales'] > 0) {
|
||||
$total['avg_margin_ratio'] = ($total['margin'] / $total['sales']) * 100;
|
||||
} else {
|
||||
$total['avg_margin_ratio'] = 0;
|
||||
}
|
||||
|
||||
|
||||
if ($data['status'] == 'ON' && $data['unique_total']){
|
||||
$total['expect_db'] += round($data['budget'] / $data['cpa']);
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
private function array_remove_keys($array, $keys)
|
||||
{
|
||||
$assocKeys = array();
|
||||
foreach ($keys as $key) {
|
||||
$assocKeys[$key] = true;
|
||||
}
|
||||
|
||||
return array_diff_key($array, $assocKeys);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\AdvertisementManager;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Advertiser\AdvNaverManagerModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class AdvNaverManagerController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $naver;
|
||||
public function __construct()
|
||||
{
|
||||
$this->naver = model(AdvNaverManagerModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('advertisements/naver/naver');
|
||||
}
|
||||
|
||||
public function getAccounts()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
];
|
||||
|
||||
$accounts = $this->naver->getAccounts($arg);
|
||||
|
||||
return $this->respond($accounts);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'type' => $this->request->getGet('type'),
|
||||
'accounts' => $this->request->getGet('accounts'),
|
||||
'stx' => $this->request->getGet('stx'),
|
||||
];
|
||||
|
||||
if($arg['type'] == 'ads'){
|
||||
$result = $this->getAds($arg);
|
||||
}else if($arg['type'] == 'adsets'){
|
||||
$result = $this->getAdSets($arg);
|
||||
}else{
|
||||
$result = $this->getCampaigns($arg);
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getReport()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = [
|
||||
'dates' => [
|
||||
'sdate' => $this->request->getGet('sdate') ? $this->request->getGet('sdate') : date('Y-m-d'),
|
||||
'edate' => $this->request->getGet('edate') ? $this->request->getGet('edate') : date('Y-m-d'),
|
||||
],
|
||||
'accounts' => $this->request->getGet('accounts'),
|
||||
];
|
||||
|
||||
$res = $this->naver->getReport($arg);
|
||||
$columnIndex = 0;
|
||||
$data = [];
|
||||
foreach($res as $row) {
|
||||
$data[] = $row;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($val == NULL) $val = "0";
|
||||
$total[$col][$columnIndex] = $val;
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = $report['clicks_sum'] = $report['click_ratio_sum'] = $report['spend_sum'] = $report['unique_total_sum'] = $report['unique_one_price_sum'] = $report['conversion_ratio_sum'] = $report['profit_sum'] = $report['per_sum'] = 0;
|
||||
|
||||
if(!empty($res)){
|
||||
$report['impressions_sum'] = array_sum($total['impressions']); //총 노출수
|
||||
$report['clicks_sum'] = array_sum($total['click']); //총 클릭수
|
||||
if($report['clicks_sum'] != 0 && $report['impressions_sum'] != 0) {
|
||||
$report['click_ratio_sum'] = round(($report['clicks_sum'] / $report['impressions_sum']) * 100,2); //총 클릭률
|
||||
}
|
||||
$report['spend_sum'] = array_sum($total['spend']); //총 지출액
|
||||
$report['unique_total_sum'] = array_sum($total['unique_total']); //총 유효db수
|
||||
if($report['spend_sum'] != 0 && $report['unique_total_sum'] != 0) {
|
||||
$report['unique_one_price_sum'] = round($report['spend_sum'] / $report['unique_total_sum'],0); //총 db당 단가
|
||||
}
|
||||
if($report['unique_total_sum'] != 0 && $report['clicks_sum'] != 0) {
|
||||
$report['conversion_ratio_sum'] = round(($report['unique_total_sum'] / $report['clicks_sum']) * 100,2); //총 전환율
|
||||
}
|
||||
$report['price_sum'] = array_sum($total['price']); //총 매출액
|
||||
$report['profit_sum'] = array_sum($total['profit']); //총 수익
|
||||
if($report['profit_sum'] != 0 && $report['price_sum'] != 0) {
|
||||
$report['per_sum'] = round(($report['profit_sum'] / $report['price_sum']) * 100,2); //총 수익률
|
||||
}
|
||||
}
|
||||
return $this->respond($report);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
private function getCampaigns($arg)
|
||||
{
|
||||
$campaigns = $this->naver->getCampaigns($arg);
|
||||
$campaigns = $this->naver->getStatuses("campaigns", $campaigns, $arg['dates']);
|
||||
$total = $this->getTotal($campaigns);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $campaigns,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAdSets($arg)
|
||||
{
|
||||
$adsets = $this->naver->getAdSets($arg);
|
||||
$adsets = $this->naver->getStatuses("adsets", $adsets, $arg['dates']);
|
||||
$total = $this->getTotal($adsets);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $adsets
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAds($arg)
|
||||
{
|
||||
$ads = $this->naver->getAds($arg);
|
||||
$ads = $this->naver->getStatuses("ads", $ads, $arg['dates']);
|
||||
$total = $this->getTotal($ads);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $ads
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getTotal($datas)
|
||||
{
|
||||
$total = [];
|
||||
$total['impressions'] = 0;
|
||||
$total['click'] = 0;
|
||||
$total['spend'] = 0;
|
||||
$total['margin'] = 0;
|
||||
$total['unique_total'] = 0;
|
||||
$total['sales'] = 0;
|
||||
$total['dailyBudgetAmount'] = 0;
|
||||
$total['cpc'] = 0;
|
||||
$total['ctr'] = 0;
|
||||
$total['cpa'] = 0;
|
||||
$total['cvr'] = 0;
|
||||
$total['margin_ratio'] = 0;
|
||||
$total['expect_db'] = 0;
|
||||
foreach($datas as $data){
|
||||
$total['margin'] = $data['sales'] - $data['cost'];
|
||||
$total['impressions'] +=$data['impressions'];
|
||||
$total['click'] +=$data['click'];
|
||||
$total['spend'] +=$data['spend'];
|
||||
$total['margin'] +=$data['margin'];
|
||||
$total['unique_total'] +=$data['unique_total'];
|
||||
$total['sales'] +=$data['sales'];
|
||||
$total['cpc'] +=$data['cpc'];
|
||||
$total['ctr'] +=$data['ctr'];
|
||||
$total['cpa'] +=$data['cpa'];
|
||||
$total['cvr'] +=$data['cvr'];
|
||||
$total['margin_ratio'] +=$data['margin_ratio'];
|
||||
|
||||
//CPC(Cost Per Click: 클릭당단가 (1회 클릭당 비용)) = 지출액/링크클릭
|
||||
if($total['click'] > 0){
|
||||
$total['avg_cpc'] = $total['spend'] / $total['click'];
|
||||
}else{
|
||||
$total['avg_cpc'] = 0;
|
||||
}
|
||||
|
||||
//CTR(Click Through Rate: 클릭율 (노출 대비 클릭한 비율)) = (링크클릭/노출수)*100
|
||||
$total['avg_ctr'] = ($total['click'] / $total['impressions']) * 100;
|
||||
|
||||
//CPA(Cost Per Action: 현재 DB단가(전환당 비용)) = 지출액/유효db
|
||||
if($total['unique_total'] > 0){
|
||||
$total['avg_cpa'] = $total['spend'] / $total['unique_total'];
|
||||
}else{
|
||||
$total['avg_cpa'] = 0;
|
||||
}
|
||||
|
||||
//CVR(Conversion Rate:전환율 = (유효db / 링크클릭)*100
|
||||
if ($total['click'] > 0) {
|
||||
$total['avg_cvr'] = ($total['unique_total'] / $total['click']) * 100;
|
||||
} else {
|
||||
$total['avg_cvr'] = 0;
|
||||
}
|
||||
|
||||
//수익률 = (수익/매출액)*100
|
||||
if ($total['sales'] > 0) {
|
||||
$total['avg_margin_ratio'] = ($total['margin'] / $total['sales']) * 100;
|
||||
} else {
|
||||
$total['avg_margin_ratio'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Libraries\Calc;
|
||||
use App\Models\Advertiser\AdvFacebookManagerModel;
|
||||
use App\Models\Advertiser\AdvGoogleManagerModel;
|
||||
use App\Models\Advertiser\AdvKakaoManagerModel;
|
||||
use App\Models\Advertiser\AdvManagerModel;
|
||||
use App\Models\Api\CompanyModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class RestaController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $admanager, $facebook, $google, $kakao;
|
||||
private $advertiser = [
|
||||
'더스퀘어치과의원',
|
||||
'메이드영성형외과의원',
|
||||
'리프톤피부과의원',
|
||||
'모아만의원',
|
||||
'모우림의원',
|
||||
'열정치과의원',
|
||||
'우리들40플란트치과병원',
|
||||
'하루플란트치과의원광고주',
|
||||
'한나이브성형외과의원',
|
||||
'강남애프터치과의원',
|
||||
'참좋은치과의원',
|
||||
'보가치과의원'
|
||||
];
|
||||
public function __construct()
|
||||
{
|
||||
$this->admanager = model(AdvManagerModel::class);
|
||||
$this->facebook = model(AdvFacebookManagerModel::class);
|
||||
$this->google = model(AdvGoogleManagerModel::class);
|
||||
$this->kakao = model(AdvKakaoManagerModel::class);
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if(strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
if(empty($arg['external']) || $arg['external'] != 'resta'){
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
$company = model(CompanyModel::class);
|
||||
$companySeq = $company->getCompaniesByName($this->advertiser);
|
||||
$ids = array_column($companySeq, 'id');
|
||||
$ids = implode("|", $ids);
|
||||
$arg['searchData']['resta'] = $ids;
|
||||
switch ($arg['searchData']['type']) {
|
||||
case 'ads':
|
||||
$result = $this->getAds($arg);
|
||||
break;
|
||||
case 'adsets':
|
||||
$result = $this->getAdSets($arg);
|
||||
break;
|
||||
case 'campaigns':
|
||||
$result = $this->getCampaigns($arg);
|
||||
break;
|
||||
default:
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
$orderBy = [];
|
||||
if(!empty($arg['order'])) {
|
||||
foreach($arg['order'] as $row) {
|
||||
if($row['dir'] == 'desc'){
|
||||
$sort = SORT_DESC;
|
||||
}else{
|
||||
$sort = SORT_ASC;
|
||||
}
|
||||
$col = $arg['columns'][$row['column']]['data'];
|
||||
if($col) $orderBy[$col] = $sort;
|
||||
}
|
||||
array_sort_by_multiple_keys($result['data'], $orderBy);
|
||||
}
|
||||
|
||||
foreach ($result['data'] as &$value) {
|
||||
$value['bidamount'] = number_format($value['bidamount']);
|
||||
$value['budget'] = number_format($value['budget']);
|
||||
$value['impressions'] = number_format($value['impressions']);
|
||||
$value['click'] = number_format($value['click']);
|
||||
$value['spend'] = number_format($value['spend']);
|
||||
$value['sales'] = number_format($value['sales']);
|
||||
$value['unique_total'] = number_format($value['unique_total']);
|
||||
$value['margin'] = number_format($value['margin']);
|
||||
$value['margin_ratio'] = number_format($value['margin_ratio']);
|
||||
$value['cpa'] = number_format($value['cpa']);
|
||||
$value['cpc'] = number_format($value['cpc']);
|
||||
}
|
||||
if(isset($arg['noLimit'])) {
|
||||
return $this->respond($result['data']);
|
||||
}
|
||||
$result['accounts'] = $this->getAccounts($arg);
|
||||
$result['media_accounts'] = $this->getMediaAccounts($arg);
|
||||
$result['report'] = $this->getReport($arg);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
private function getAccounts($arg)
|
||||
{
|
||||
$result = [];
|
||||
$accounts = $this->admanager->getAccounts($arg);
|
||||
//$accounts = $this->setAccountData($accounts);
|
||||
$result = array_merge($result, $accounts);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getMediaAccounts($arg)
|
||||
{
|
||||
$result = $this->admanager->getMediaAccounts($arg);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getReport($arg)
|
||||
{
|
||||
$result = $this->admanager->getReport($arg);
|
||||
$columnIndex = 0;
|
||||
$data = [];
|
||||
|
||||
foreach($result as $row) {
|
||||
$data[] = $row;
|
||||
foreach ($row as $col => $val) {
|
||||
if ($val == NULL) $val = "0";
|
||||
$total[$col][$columnIndex] = $val;
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = $report['clicks_sum'] = $report['click_ratio_sum'] = $report['spend_sum'] = $report['unique_total_sum'] = $report['unique_one_price_sum'] = $report['conversion_ratio_sum'] = $report['profit_sum'] = $report['per_sum'] = $report['price_sum'] = $report['spend_ratio_sum'] =$report['cpc'] = 0;
|
||||
|
||||
if(!empty($result)){
|
||||
|
||||
$report['impressions_sum'] = array_sum($total['impressions']); //총 노출수
|
||||
$report['clicks_sum'] = array_sum($total['click']); //총 클릭수
|
||||
if ($report['clicks_sum'] != 0 && $report['impressions_sum'] != 0) {
|
||||
$report['click_ratio_sum'] = round(($report['clicks_sum'] / $report['impressions_sum']) * 100, 2); //총 클릭률
|
||||
}
|
||||
$report['spend_sum'] = array_sum($total['spend']); //총 지출액
|
||||
$report['spend_ratio_sum'] = floor(array_sum($total['spend']) * 0.85); //총 매체비
|
||||
if ($report['clicks_sum'] != 0) {
|
||||
$report['cpc'] = round($report['spend_sum'] / $report['clicks_sum'], 2);
|
||||
} else {
|
||||
$report['cpc'] = 0;
|
||||
}
|
||||
$report['unique_total_sum'] = array_sum($total['unique_total']); //총 유효db수
|
||||
if ($report['spend_sum'] != 0 && $report['unique_total_sum'] != 0) {
|
||||
$report['unique_one_price_sum'] = round($report['spend_sum'] / $report['unique_total_sum'], 0); //총 db당 단가
|
||||
}
|
||||
if ($report['unique_total_sum'] != 0 && $report['clicks_sum'] != 0) {
|
||||
$report['conversion_ratio_sum'] = round(($report['unique_total_sum'] / $report['clicks_sum']) * 100, 2); //총 전환율
|
||||
}
|
||||
$report['price_sum'] = array_sum($total['price']); //총 매출액
|
||||
$report['profit_sum'] = array_sum($total['profit']); //총 수익
|
||||
if ($report['profit_sum'] != 0 && $report['price_sum'] != 0) {
|
||||
$report['per_sum'] = round(($report['profit_sum'] / $report['price_sum']) * 100, 2); //총 수익률
|
||||
}
|
||||
|
||||
$report['impressions_sum'] = number_format($report['impressions_sum']);
|
||||
$report['clicks_sum'] = number_format($report['clicks_sum']);
|
||||
$report['spend_sum'] = number_format($report['spend_sum']);
|
||||
$report['unique_one_price_sum'] = number_format($report['unique_one_price_sum']);
|
||||
$report['spend_ratio_sum'] = number_format($report['spend_ratio_sum']);
|
||||
$report['price_sum'] = number_format($report['price_sum']);
|
||||
$report['profit_sum'] = number_format($report['profit_sum']);
|
||||
}
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
private function getCampaigns($arg)
|
||||
{
|
||||
$campaigns = $this->admanager->getCampaigns($arg);
|
||||
$campaigns = $this->setData($campaigns);
|
||||
|
||||
$total = $this->getTotal($campaigns);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $campaigns,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAdSets($arg)
|
||||
{
|
||||
$result = [];
|
||||
$campaigns = $this->admanager->getAdSets($arg);
|
||||
$campaigns = $this->setData($campaigns);
|
||||
$result = array_merge($result, $campaigns);
|
||||
|
||||
$total = $this->getTotal($result);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $result,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getAds($arg)
|
||||
{
|
||||
$result = [];
|
||||
$campaigns = $this->admanager->getAds($arg);
|
||||
$campaigns = $this->setData($campaigns);
|
||||
$result = array_merge($result, $campaigns);
|
||||
|
||||
$total = $this->getTotal($result);
|
||||
|
||||
$result = [
|
||||
'total' => $total,
|
||||
'data' => $result,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function setData($result)
|
||||
{
|
||||
foreach ($result as &$row) {
|
||||
$row['status'] = $this->setStatus($row['status']);
|
||||
|
||||
$row['margin_ratio'] = Calc::margin_ratio($row['margin'], $row['sales']); // 수익률
|
||||
|
||||
$row['cpc'] = Calc::cpc($row['spend'], $row['click']); // 클릭당단가 (1회 클릭당 비용)
|
||||
$row['ctr'] = Calc::ctr($row['click'], $row['impressions']); // 클릭율 (노출 대비 클릭한 비율)
|
||||
$row['cpa'] = Calc::cpa($row['unique_total'], $row['spend']); //DB단가(전환당 비용)
|
||||
$row['cvr'] = Calc::cvr($row['unique_total'], $row['click']); //전환율
|
||||
|
||||
if($row['bidamount_type'] == 'cpm' && $row['bidamount'] <= 1){
|
||||
$row['bidamount_type'] = '';
|
||||
$row['bidamount'] = 0;
|
||||
}
|
||||
|
||||
if(!empty($row['biddingStrategyType'])){
|
||||
switch($row['biddingStrategyType']) {
|
||||
case 'TARGET_CPA' :
|
||||
$row['biddingStrategyType'] = '타겟 CPA';
|
||||
break;
|
||||
case 'TARGET_ROAS' :
|
||||
$row['biddingStrategyType'] = '타겟 광고 투자수익(ROAS)';
|
||||
break;
|
||||
case 'TARGET_SPEND' :
|
||||
$row['biddingStrategyType'] = '클릭수 최대화';
|
||||
break;
|
||||
case 'MAXIMIZE_CONVERSIONS' :
|
||||
$row['biddingStrategyType'] = '전환수 최대화';
|
||||
break;
|
||||
/* //값이 뭔지 모름ㅠㅠ
|
||||
case '' :
|
||||
$row['biddingStrategyType'] = '검색 결과 위치 타겟';
|
||||
break;
|
||||
case '' :
|
||||
$row['biddingStrategyType'] = '경쟁 광고보다 내 광고가 높은 순위에 게재되는 비율 타겟';
|
||||
break;
|
||||
case '' :
|
||||
$row['biddingStrategyType'] = '타겟 노출 점유율';
|
||||
break;
|
||||
*/
|
||||
case 'PAGE_ONE_PROMOTED' :
|
||||
$row['biddingStrategyType'] = '향상된 CPC 입찰기능';
|
||||
break;
|
||||
case 'MANUAL_CPM' :
|
||||
$row['biddingStrategyType'] = '수동 입찰 전략';
|
||||
break;
|
||||
case 'MANUAL_CPC' :
|
||||
$row['biddingStrategyType'] = '수동 CPC';
|
||||
break;
|
||||
case 'UNKNOWN' :
|
||||
$row['biddingStrategyType'] = '알수없음';
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function setStatus($status)
|
||||
{
|
||||
/*
|
||||
ON = 인정,
|
||||
READY = 집행 예정,
|
||||
FINISHED = 집행 완료,
|
||||
STOPPED = 정지,
|
||||
ARCHIVED = 보관,
|
||||
DELETED = 삭제
|
||||
UNKNOWN = 알수 없음
|
||||
UNSPECIFIED = 명시되지 않음
|
||||
EXCEED_DAILY_BUDGET = 일 예산 초과
|
||||
NO_AVAILABLE_CREATIVE = 집행 가능한 소재가 없음
|
||||
CANCELED = 계약 해지
|
||||
SYSTEM_CONFIG_EXTERNAL_SERVICE_STOP = 연결 서비스 제한으로 운영불가인 상태
|
||||
ADACCOUNT_UNAVAILABLE = 광고계정 운영불가
|
||||
CAMPAIGN_UNAVAILABLE = 캠페인 운영불가
|
||||
ADGROUP_UNAVAILABLE = 광고 상위단위인 광고그룹이 운영불가인 상태
|
||||
SYSTEM_CONFIG_ADMIN_STOP = 관리자 정지
|
||||
OPERATING = 운영가능 상태
|
||||
UNAPPROVED = 심사승인이 아닌 상태(심사중, 심사보류를 모두 포함)
|
||||
INVALID_DATE = 집행기간이 도래하지 않았거나 이미 지난 상태
|
||||
MONITORING_REJECTED = 관리자정지 상태
|
||||
SYSTEM_CONFIG_VOID = 소재 콘텐츠 오류로 소재 운영불가인 상태
|
||||
*/
|
||||
if(!empty($status)){
|
||||
if(in_array($status, ['ENABLED', 'ACTIVE', 'LIVE', 'ON'])){$status = 'ON';}
|
||||
else if(in_array($status, ['READY'])){$status = 'READY';}
|
||||
else if(in_array($status, ['FINISHED'])){$status = 'FINISHED';}
|
||||
else if(in_array($status, ['OFF', 'PAUSED'])){$status = 'OFF';}
|
||||
else if(in_array($status, ['ARCHIVED'])){$status = 'ARCHIVED';}
|
||||
else if(in_array($status, ['DELETED', 'REMOVED'])){$status = 'DELETED';}
|
||||
else if(in_array($status, ['UNKNOWN'])){$status = 'UNKNOWN';}
|
||||
else if(in_array($status, ['UNSPECIFIED'])){$status = 'UNSPECIFIED';}
|
||||
else if(in_array($status, ['EXCEED_DAILY_BUDGET'])){$status = 'EXCEED_DAILY_BUDGET';}
|
||||
else if(in_array($status, ['NO_AVAILABLE_CREATIVE'])){$status = 'NO_AVAILABLE_CREATIVE';}
|
||||
else if(in_array($status, ['CANCELED'])){$status = 'CANCELED';}
|
||||
else if(in_array($status, ['SYSTEM_CONFIG_EXTERNAL_SERVICE_STOP'])){$status = 'SYSTEM_CONFIG_EXTERNAL_SERVICE_STOP';}
|
||||
else if(in_array($status, ['ADACCOUNT_UNAVAILABLE'])){$status = 'ADACCOUNT_UNAVAILABLE';}
|
||||
else if(in_array($status, ['CAMPAIGN_UNAVAILABLE'])){$status = 'CAMPAIGN_UNAVAILABLE';}
|
||||
else if(in_array($status, ['SYSTEM_CONFIG_ADMIN_STOP'])){$status = 'SYSTEM_CONFIG_ADMIN_STOP';}
|
||||
else if(in_array($status, ['OPERATING'])){$status = 'OPERATING';}
|
||||
else if(in_array($status, ['UNAPPROVED'])){$status = 'UNAPPROVED';}
|
||||
else if(in_array($status, ['INVALID_DATE'])){$status = 'INVALID_DATE';}
|
||||
else if(in_array($status, ['MONITORING_REJECTED'])){$status = 'MONITORING_REJECTED';}
|
||||
else if(in_array($status, ['ADGROUP_UNAVAILABLE'])){$status = 'ADGROUP_UNAVAILABLE';}
|
||||
else if(in_array($status, ['SYSTEM_CONFIG_VOID'])){$status = 'SYSTEM_CONFIG_VOID';}
|
||||
else{$status = 'ETC';};
|
||||
}else{
|
||||
$status = NULL;
|
||||
};
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
private function getTotal($datas)
|
||||
{
|
||||
$total = [];
|
||||
$total['impressions'] = 0;
|
||||
$total['click'] = 0;
|
||||
$total['spend'] = 0;
|
||||
$total['margin'] = 0;
|
||||
$total['unique_total'] = 0;
|
||||
$total['sales'] = 0;
|
||||
$total['budget'] = 0;
|
||||
$total['bidamount'] = 0;
|
||||
$total['cpc'] = 0;
|
||||
$total['ctr'] = 0;
|
||||
$total['cpa'] = 0;
|
||||
$total['cvr'] = 0;
|
||||
$total['margin_ratio'] = 0;
|
||||
$total['expect_db'] = 0;
|
||||
$total['avg_cpc'] = 0;
|
||||
$total['avg_cpa'] = 0;
|
||||
$total['avg_cvr'] = 0;
|
||||
$total['avg_ctr'] = 0;
|
||||
foreach($datas as $data){
|
||||
$total['impressions'] +=$data['impressions'];
|
||||
$total['click'] +=$data['click'];
|
||||
$total['spend'] +=$data['spend'];
|
||||
$total['margin'] +=$data['margin'];
|
||||
$total['unique_total'] +=$data['unique_total'];
|
||||
$total['sales'] +=$data['sales'];
|
||||
$total['bidamount'] +=$data['bidamount'];
|
||||
$total['budget'] +=$data['budget'];
|
||||
$total['cpc'] +=$data['cpc'];
|
||||
$total['ctr'] +=$data['ctr'];
|
||||
$total['cpa'] +=$data['cpa'];
|
||||
$total['cvr'] +=$data['cvr'];
|
||||
$total['margin_ratio'] +=$data['margin_ratio'];
|
||||
|
||||
//CPC(Cost Per Click: 클릭당단가 (1회 클릭당 비용)) = 지출액/링크클릭
|
||||
if($total['click'] > 0){
|
||||
$total['avg_cpc'] = $total['spend'] / $total['click'];
|
||||
}
|
||||
|
||||
//CTR(Click Through Rate: 클릭율 (노출 대비 클릭한 비율)) = (링크클릭/노출수)*100
|
||||
if($total['impressions'] > 0){
|
||||
$total['avg_ctr'] = ($total['click'] / $total['impressions']) * 100;
|
||||
}
|
||||
|
||||
//CPA(Cost Per Action: 현재 DB단가(전환당 비용)) = 지출액/유효db
|
||||
if($total['unique_total'] > 0){
|
||||
$total['avg_cpa'] = $total['spend'] / $total['unique_total'];
|
||||
}
|
||||
|
||||
//CVR(Conversion Rate:전환율 = (유효db / 링크클릭)*100
|
||||
if ($total['click'] > 0) {
|
||||
$total['avg_cvr'] = ($total['unique_total'] / $total['click']) * 100;
|
||||
}
|
||||
|
||||
//수익률 = (수익/매출액)*100
|
||||
if ($total['sales'] > 0) {
|
||||
$total['avg_margin_ratio'] = ($total['margin'] / $total['sales']) * 100;
|
||||
} else {
|
||||
$total['avg_margin_ratio'] = 0;
|
||||
}
|
||||
|
||||
if ($data['status'] == 'ON' && $data['unique_total'] && $data['cpa'] != 0){
|
||||
$total['expect_db'] += round($data['budget'] / $data['cpa']);
|
||||
}
|
||||
}
|
||||
|
||||
$total['impressions'] = number_format($total['impressions']);
|
||||
$total['bidamount'] = number_format($total['bidamount']);
|
||||
$total['budget'] = number_format($total['budget']);
|
||||
$total['click'] = number_format($total['click']);
|
||||
$total['spend'] = number_format($total['spend']);
|
||||
$total['avg_cpa'] = number_format($total['avg_cpa']);
|
||||
$total['margin'] = number_format($total['margin']);
|
||||
$total['sales'] = number_format($total['sales']);
|
||||
$total['avg_cpc'] = number_format($total['avg_cpc']);
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class TestController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
public function getInterlockData()
|
||||
{
|
||||
$data = $this->request->getVar();
|
||||
return $this->respond(['result'=> 200, 'msg' => 'success']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Auth;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Controllers\User\UserController;
|
||||
use CodeIgniter\Shield\Controllers\MagicLinkController as ShieldMagicLinkController;
|
||||
use CodeIgniter\Events\Events;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use CodeIgniter\Shield\Authentication\Authenticators\Session;
|
||||
use CodeIgniter\Shield\Config\Auth;
|
||||
use CodeIgniter\Shield\Models\LoginModel;
|
||||
use CodeIgniter\Shield\Models\UserIdentityModel;
|
||||
|
||||
class MagicLinkController extends ShieldMagicLinkController
|
||||
{
|
||||
public function verify(): RedirectResponse
|
||||
{
|
||||
$token = $this->request->getGet('token');
|
||||
|
||||
/** @var UserIdentityModel $identityModel */
|
||||
$identityModel = model(UserIdentityModel::class);
|
||||
|
||||
$identity = $identityModel->getIdentityBySecret(Session::ID_TYPE_MAGIC_LINK, $token);
|
||||
|
||||
$identifier = $token ?? '';
|
||||
|
||||
// No token found?
|
||||
if ($identity === null) {
|
||||
$this->recordLoginAttempt($identifier, false);
|
||||
|
||||
$credentials = ['magicLinkToken' => $token];
|
||||
Events::trigger('failedLogin', $credentials);
|
||||
|
||||
return redirect()->route('magic-link')->with('error', lang('Auth.magicTokenNotFound'));
|
||||
}
|
||||
|
||||
// Delete the db entry so it cannot be used again.
|
||||
$identityModel->delete($identity->id);
|
||||
|
||||
// Token expired?
|
||||
if (Time::now()->isAfter($identity->expires)) {
|
||||
$this->recordLoginAttempt($identifier, false);
|
||||
|
||||
$credentials = ['magicLinkToken' => $token];
|
||||
Events::trigger('failedLogin', $credentials);
|
||||
|
||||
return redirect()->route('magic-link')->with('error', lang('Auth.magicLinkExpired'));
|
||||
}
|
||||
|
||||
/** @var Session $authenticator */
|
||||
$authenticator = auth('session')->getAuthenticator();
|
||||
|
||||
// If an action has been defined
|
||||
if ($authenticator->hasAction($identity->user_id)) {
|
||||
return redirect()->route('auth-action-show')->with('error', lang('Auth.forcePasswordChange'));
|
||||
}
|
||||
|
||||
// Log the user in
|
||||
$authenticator->loginById($identity->user_id);
|
||||
|
||||
$user = $authenticator->getUser();
|
||||
|
||||
$this->recordLoginAttempt($identifier, true, $user->id);
|
||||
|
||||
// Give the developer a way to know the user
|
||||
// logged in via a magic link.
|
||||
session()->setTempdata('magicLogin', true);
|
||||
|
||||
Events::trigger('magicLogin');
|
||||
$user->forcePasswordReset();
|
||||
// Get our login redirect url
|
||||
return redirect()->to('/set-password');
|
||||
}
|
||||
|
||||
private function recordLoginAttempt(
|
||||
string $identifier,
|
||||
bool $success,
|
||||
$userId = null
|
||||
): void {
|
||||
/** @var LoginModel $loginModel */
|
||||
$loginModel = model(LoginModel::class);
|
||||
|
||||
$loginModel->recordLoginAttempt(
|
||||
Session::ID_TYPE_MAGIC_LINK,
|
||||
$identifier,
|
||||
$success,
|
||||
$this->request->getIPAddress(),
|
||||
(string) $this->request->getUserAgent(),
|
||||
$userId
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Auth;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Controllers\User\UserController;
|
||||
use App\Models\Api\UserModel;
|
||||
use CodeIgniter\Shield\Authentication\Passwords;
|
||||
|
||||
class PasswordChangeController extends BaseController
|
||||
{
|
||||
private $user, $userModel;
|
||||
protected $helpers = ['setting'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!auth()->loggedIn()) {
|
||||
return redirect()->to('/login');
|
||||
}
|
||||
$this->user = auth()->user();
|
||||
$this->userModel = model(UserModel::class);
|
||||
}
|
||||
|
||||
public function changePasswordView()
|
||||
{
|
||||
/* if (!session('magicLogin')) {
|
||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
||||
} */
|
||||
|
||||
return view(setting('Auth.views')['set-password']);
|
||||
}
|
||||
|
||||
public function changePasswordAction(){
|
||||
$data = $this->request->getPost();
|
||||
$rules = [
|
||||
'password' => [
|
||||
'label' => 'Auth.password',
|
||||
'rules' => 'required|' . Passwords::getMaxLengthRule() . '|strong_password[]',
|
||||
'errors' => [
|
||||
'max_byte' => 'Auth.errorPasswordTooLongBytes',
|
||||
],
|
||||
],
|
||||
'password_confirm' => [
|
||||
'label' => 'Auth.passwordConfirm',
|
||||
'rules' => 'required|matches[password]',
|
||||
],
|
||||
];
|
||||
|
||||
if (! $this->validateData($data, $rules, [], config('Auth')->DBGroup)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->user->fill($data);
|
||||
$result = $this->userModel->save($this->user);
|
||||
if($result == true){
|
||||
$this->user->undoForcePasswordReset();
|
||||
|
||||
$userController = new UserController;
|
||||
$userController->setPasswordChangedAt(true);
|
||||
session()->removeTempdata('magicLogin');
|
||||
}
|
||||
|
||||
return redirect()->to("/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\HTTP\CLIRequest;
|
||||
use CodeIgniter\HTTP\IncomingRequest;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*
|
||||
* BaseController provides a convenient place for loading components
|
||||
* and performing functions that are needed by all your controllers.
|
||||
* Extend this class in any new controllers:
|
||||
* class Home extends BaseController
|
||||
*
|
||||
* For security be sure to declare any new methods as protected or private.
|
||||
*/
|
||||
abstract class BaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Instance of the main Request object.
|
||||
*
|
||||
* @var CLIRequest|IncomingRequest
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* An array of helpers to be loaded automatically upon
|
||||
* class instantiation. These helpers will be available
|
||||
* to all other controllers that extend BaseController.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
* Be sure to declare properties for any property fetch you initialized.
|
||||
* The creation of dynamic property is deprecated in PHP 8.2.
|
||||
*/
|
||||
// protected $session;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
// Do Not Edit This Line
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
// Preload any models, libraries, etc, here.
|
||||
|
||||
// E.g.: $this->session = \Config\Services::session();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Calendar;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\ThirdParty\googleclient\GoogleCalendar;
|
||||
|
||||
class CalendarController extends BaseController
|
||||
{
|
||||
protected $googleCalender;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->googleCalender = new GoogleCalendar();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
//$list = $this->googleCalender->eventList();
|
||||
|
||||
/* $data['startDate'] = '2023-06-24';
|
||||
$data['endDate'] = '2023-06-30';
|
||||
$data['summary'] = 'test6';
|
||||
$this->googleCalender->createEvent($data); */
|
||||
|
||||
/* $data['startDate'] = '2023-06-20';
|
||||
$data['endDate'] = '2023-06-30';
|
||||
$data['summary'] = '테스트2';
|
||||
$event_id = '0iaudoh97jkqnp8vg1mbg5d4fg';
|
||||
$this->googleCalender->updateEvent($data, $event_id); */
|
||||
|
||||
/* $event_id = '3pp2lt2r5iuc9k4r13ampehhvt';
|
||||
$this->googleCalender->deleteEvent($event_id); */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Company;
|
||||
|
||||
use App\Models\Api\CompanyModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class CompanyController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $data, $zenith, $company, $validation;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
/* if(!auth()->user()->ingroup('superadmin', 'admin', 'developer')){
|
||||
return $this->failUnauthorized("권한이 없습니다.");
|
||||
} */
|
||||
$this->zenith = \Config\Database::connect();
|
||||
$this->company = model(CompanyModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('companies/company');
|
||||
}
|
||||
|
||||
public function getCompanies()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getCompanies($param);
|
||||
$result = [
|
||||
'data' => $result['data'],
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($param['draw']),
|
||||
];
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getCompany()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getCompany($param['id']);
|
||||
$result['username'] = explode(',', $result['username']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createCompany()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$param = $this->request->getRawInput();
|
||||
if (!empty($param)) {
|
||||
$validation = \Config\Services::validation();
|
||||
if(!empty($param['p_name'])){
|
||||
$agency = $this->company->getAgencyByName($param['p_name']);
|
||||
if(empty($agency)) {
|
||||
return $this->failValidationErrors(["p_name" => "존재하지 않는 대행사입니다."]);
|
||||
}
|
||||
}else{
|
||||
$agency = '';
|
||||
}
|
||||
|
||||
$validation->setRules($this->company->validationRules, $this->company->validationMessages);
|
||||
if (!$validation->run($param)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->company->createCompany($param, $agency);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setCompany()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put') {
|
||||
$param = $this->request->getRawInput();
|
||||
if (!empty($param)) {
|
||||
$validation = \Config\Services::validation();
|
||||
if(!empty($param['p_name'])){
|
||||
$agency = $this->company->getAgencyByName($param['p_name']);
|
||||
if(empty($agency)) {
|
||||
return $this->failValidationErrors(["p_name" => "존재하지 않는 대행사입니다."]);
|
||||
}
|
||||
}else{
|
||||
$agency = '';
|
||||
}
|
||||
$validation->setRules($this->company->validationRules, $this->company->validationMessages);
|
||||
if (!$validation->run($param)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->company->setCompany($param, $agency);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchCompanies()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getSearchCompanies($param['stx']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchAgencies()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getSearchAgencies($param['stx']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCompany()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'delete') {
|
||||
$param = $this->request->getRawInput();
|
||||
$result = $this->company->deleteCompany($param);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchAdAccounts()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getSearchAdAccounts($param['stx']);
|
||||
if(!empty($result)){
|
||||
foreach($result as &$row){
|
||||
if($row['status'] == 'ENABLED' || $row['status'] == 1 || $row['status'] == 'ON'){
|
||||
$row['status'] = '활성';
|
||||
}else{
|
||||
$row['status'] = '비활성';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getCompanyAdAccounts()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->company->getCompanyAdAccounts($param);
|
||||
if(!empty($result)){
|
||||
foreach($result as &$row){
|
||||
if($row['status'] == 'ENABLED' || $row['status'] == 1 || $row['status'] == 'ON'){
|
||||
$row['status'] = '활성';
|
||||
}else{
|
||||
$row['status'] = '비활성';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setCompanyAdAccount()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put') {
|
||||
$param = $this->request->getRawInput();
|
||||
$sliceId = explode("_", $param['ad_account_id']);
|
||||
$param['ad_account_id'] = $sliceId[1];
|
||||
$param['media'] = $sliceId[0];
|
||||
$adAccount = $this->company->getCompanyAdAccount($param);
|
||||
if(!empty($adAccount)){
|
||||
return $this->failValidationErrors(["username" => "이미 소속되어 있습니다."]);
|
||||
}
|
||||
$result = $this->company->setCompanyAdAccount($param);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function exceptCompanyAdAccount()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'delete') {
|
||||
$param = $this->request->getRawInput();
|
||||
$sliceId = explode("_", $param['ad_account_id']);
|
||||
$param['ad_account_id'] = $sliceId[1];
|
||||
$param['media'] = $sliceId[0];
|
||||
if (!empty($param)) {
|
||||
$result = $this->company->exceptCompanyAdAccount($param);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\AdvertiserModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class AdvertiserController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $advertiser;
|
||||
public function __construct()
|
||||
{
|
||||
$this->advertiser = model(AdvertiserModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('/events/advertiser/advertiser');
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->advertiser->getAdvertisers($arg);
|
||||
$list = $result['data'];
|
||||
for ($i = 0; $i < count($list); $i++) {
|
||||
if($list[$i]['is_stop']){
|
||||
$list[$i]['is_stop'] = '사용중지';
|
||||
}else{
|
||||
$list[$i]['is_stop'] = '사용중';
|
||||
}
|
||||
|
||||
if($list[$i]['interlock_url']){
|
||||
$list[$i]['interlock_url'] = 'O';
|
||||
}
|
||||
|
||||
if($list[$i]['agreement_url']){
|
||||
$list[$i]['agreement_url_exist'] = 'O';
|
||||
}
|
||||
|
||||
$list[$i]['remain_balance'] = ($list[$i]['sum_price'] == ($list[$i]['remain_balance'] * -1)) ? "" : $list[$i]['remain_balance'];
|
||||
|
||||
if($list[$i]['sum_price']){
|
||||
$list[$i]['sum_price'] = number_format($list[$i]['sum_price']);
|
||||
}
|
||||
|
||||
if($list[$i]['remain_balance']){
|
||||
$list[$i]['remain_balance'] = number_format($list[$i]['remain_balance']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result = [
|
||||
'data' => $list,
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($arg['draw']),
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdvertiser()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$adv = $this->advertiser->getAdvertiser($arg);
|
||||
$ow = $this->advertiser->getOverwatchByAdvertiser($arg);
|
||||
$wl = $this->advertiser->getMedia($arg);
|
||||
|
||||
$result = [
|
||||
'advertiser' => $adv,
|
||||
'ow' => $ow,
|
||||
'wl' => $wl
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getCompanies()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$stx = $this->request->getGet('stx');
|
||||
$result = $this->advertiser->getCompanies($stx);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createAdv()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = [
|
||||
'name' => $arg['name'],
|
||||
'agent' => $arg['agent'],
|
||||
'username' => auth()->user()->username,
|
||||
'homepage_url' => $arg['homepage_url'],
|
||||
'interlock_url' => $arg['interlock_url'],
|
||||
'agreement_url' => $arg['agreement_url'],
|
||||
'account_balance' => empty($arg['account_balance'])?0:$arg['account_balance'],
|
||||
'is_stop' => $arg['is_stop']
|
||||
];
|
||||
if(!empty($arg['company_id'])) {
|
||||
$data['company_seq'] = $arg['company_id'];
|
||||
}
|
||||
$data['ea_datetime'] = date('Y-m-d H:i:s');
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'name' => 'required|is_unique[event_advertiser.name]',
|
||||
// 'company_seq' => 'required|is_unique[event_advertiser.company_seq]',
|
||||
];
|
||||
$validationMessages = [
|
||||
/*
|
||||
'company_seq' => [
|
||||
'required' => '광고주 연결은 필수 입력 사항입니다.',
|
||||
'is_unique' => '이미 등록된 소속 광고주입니다.'
|
||||
],
|
||||
*/
|
||||
'name' => [
|
||||
'required' => '광고주명은 필수 입력 사항입니다.',
|
||||
'is_unique' => '이미 등록된 광고주입니다.'
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
/*
|
||||
$company = $this->advertiser->getCompanies($arg['name'])[0];
|
||||
if(empty($company['id']) || $company['id'] != $arg['company_id']) {
|
||||
$error = ['advertiser' => '소속 광고주와 입력한 광고주가 일치하지 않습니다.'];
|
||||
return $this->failValidationErrors($error);
|
||||
}
|
||||
|
||||
if(empty($arg['company_id'])){
|
||||
$advertiser = $this->advertiser->getAdvertiserByName($data);
|
||||
if(empty($advertiser)){
|
||||
$error = ['advertiser' => '광고주명에 해당하는 소속 광고주가 존재하지 않습니다.'];
|
||||
return $this->failValidationErrors($error);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$result = $this->advertiser->createAdv($data);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAdv()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
// 'name' => 'required',
|
||||
];
|
||||
|
||||
if($arg['sms_alert']){
|
||||
$validationRules['contact.0'] = 'required';
|
||||
}
|
||||
|
||||
$validationMessages = [
|
||||
'contact.0' => [
|
||||
'required' => '연락처는 필수 입력 사항입니다.'
|
||||
],
|
||||
];
|
||||
if(count($validationRules)) {
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($arg)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'agent' => $arg['agent'],
|
||||
'username' => auth()->user()->username,
|
||||
'homepage_url' => $arg['homepage_url'],
|
||||
'interlock_url' => $arg['interlock_url'],
|
||||
'agreement_url' => $arg['agreement_url'],
|
||||
'account_balance' => $arg['account_balance'],
|
||||
'is_stop' => $arg['is_stop'],
|
||||
];
|
||||
if(!empty($arg['company_id'])) {
|
||||
$data['company_seq'] = $arg['company_id'];
|
||||
}
|
||||
if(isset($arg['name'])) $data['name'] = $arg['name'];
|
||||
$data['ea_datetime'] = date('Y-m-d H:i:s');
|
||||
$result = $this->advertiser->updateAdv($data, $arg['seq']);
|
||||
|
||||
// OVERWATCH
|
||||
$db = \Config\Database::connect();
|
||||
$builder = $db->table('event_overwatch');
|
||||
$ow = $this->advertiser->getOverwatchByAdvertiser($arg['seq']);
|
||||
$contact = implode(';',$arg['contact']);
|
||||
// INSERT / UPDATE / DELETE
|
||||
if($arg['sms_alert'] && !$ow){
|
||||
$overwatch = [
|
||||
'advertiser' => $arg['seq'],
|
||||
'contact' => $contact,
|
||||
'watch_list' => $arg['watch_list'],
|
||||
'username' => auth()->user()->username
|
||||
];
|
||||
$overwatch['eo_datetime'] = date('Y-m-d H:i:s');
|
||||
$builder->insert($overwatch);
|
||||
}else if($arg['sms_alert'] && $ow){
|
||||
$builder->set('contact', $contact);
|
||||
$builder->set('watch_list', $arg['watch_list']);
|
||||
$builder->set('watch_all', $arg['watch_all']);
|
||||
$builder->where('seq', $ow['seq']);
|
||||
$builder->update();
|
||||
}else if(!$arg['sms_alert'] && $ow){
|
||||
$builder->where('seq', $ow['seq']);
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function evtOverwatch(){
|
||||
$result = $this->advertiser->evtOverwatch();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\BlackListModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use DateTime;
|
||||
|
||||
class BlackListController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $blacklist;
|
||||
public function __construct()
|
||||
{
|
||||
$this->blacklist = model(BlackListModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('/events/blacklist/blacklist');
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->blacklist->getBlackLists($arg);
|
||||
$list = $result['data'];
|
||||
|
||||
$result = [
|
||||
'data' => $list,
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($arg['draw']),
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getBlackList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$data = $this->request->getGet();
|
||||
$result = $this->blacklist->getBlacklist($data['seq']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createBlackList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getRawInput();
|
||||
|
||||
//유효성 검사 start
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'data' => 'required|is_unique[event_blacklist.data]',
|
||||
];
|
||||
$validationMessages = [
|
||||
'data' => [
|
||||
'required' => '전화번호/아이피를 입력해주세요.',
|
||||
'is_unique' => '이미 존재하는 전화번호/아이피입니다.'
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($arg)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
//유효성 검사 end
|
||||
|
||||
$data = [
|
||||
'data' => preg_replace("/[^0-9.]/", "", $arg['data']),
|
||||
'memo' => $arg['memo'],
|
||||
];
|
||||
|
||||
$result = $this->blacklist->createBlackList($data);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteBlackList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'delete'){
|
||||
$data = $this->request->getRawInput();
|
||||
$result = $this->blacklist->deleteBlackList($data['seq']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\ChangeModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class ChangeController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $change;
|
||||
public function __construct()
|
||||
{
|
||||
$this->change = model(ChangeModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('/events/change/change');
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->change->getChanges($arg);
|
||||
$list = $result['data'];
|
||||
|
||||
$result = [
|
||||
'data' => $list,
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($arg['draw']),
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getChange()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->change->getChange($arg['id']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createChange()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = [
|
||||
'id' => $arg['id'],
|
||||
'name' => $arg['name'],
|
||||
'token' => $arg['token'],
|
||||
];
|
||||
$data['ec_datetime'] = date('Y-m-d H:i:s');
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'id' => 'required|is_unique[event_conversion.id]',
|
||||
'token' => 'required'
|
||||
];
|
||||
$validationMessages = [
|
||||
'id' => [
|
||||
'required' => '전환ID는 필수 입력 사항입니다.',
|
||||
'is_unique' => '이미 등록된 아이디입니다.'
|
||||
],
|
||||
'token' => [
|
||||
'required' => 'Access Token은 필수 입력 사항입니다.',
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->change->createChange($data);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateChange()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = [
|
||||
'old_id' => $arg['old_id'],
|
||||
'id' => $arg['id'],
|
||||
'name' => $arg['name'],
|
||||
'token' => $arg['token'],
|
||||
];
|
||||
$data['ec_datetime'] = date('Y-m-d H:i:s');
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'id' => 'required',
|
||||
'token' => 'required'
|
||||
];
|
||||
if($data['old_id'] != $data['id']){
|
||||
$validationRules['id'] = 'required|is_unique[event_conversion.id]';
|
||||
}
|
||||
$validationMessages = [
|
||||
'id' => [
|
||||
'required' => '전환ID는 필수 입력 사항입니다.',
|
||||
'is_unique' => '이미 등록된 아이디입니다.'
|
||||
],
|
||||
'token' => [
|
||||
'required' => 'Access Token은 필수 입력 사항입니다.',
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->change->updateChange($data);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\AdvertiserModel;
|
||||
use App\Models\EventManage\EventModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class EventController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $event, $advertiser;
|
||||
public function __construct()
|
||||
{
|
||||
$this->event = model(EventModel::class);
|
||||
$this->advertiser = model(AdvertiserModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('events/event/event');
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->event->getInformation($arg);
|
||||
$ads = $this->event->getEnabledAds();
|
||||
if(empty($ads)){$ads = [];}
|
||||
foreach ($result['data'] as &$data) {
|
||||
if($data['is_stop']){
|
||||
$data['is_stop'] = 'X';
|
||||
}else{
|
||||
$data['is_stop'] = 'O';
|
||||
}
|
||||
|
||||
if($data['interlock']){
|
||||
$data['interlock'] = 'O';
|
||||
}else{
|
||||
$data['interlock'] = '';
|
||||
}
|
||||
|
||||
if($data['lead']){
|
||||
$lead_array = array("0" => $data['title'], "1" => "잠재고객", "2" => "엑셀업로드", "3" => "API 수신", "4" => "카카오 비즈폼");
|
||||
$data['title'] = $lead_array[$data['lead']];
|
||||
if($data['lead'] == 3)
|
||||
$data['title'] .= "<p class='desc'>[{$data['partner_event_seq']}]</p>";
|
||||
}
|
||||
|
||||
if(preg_match('/(카카오|GDN|페이스북|잠재|유튜브)/', $data['media_name'])) {
|
||||
$is_enabledAds = false;
|
||||
$data['config'] = 'disabled';
|
||||
if(in_array($data['seq'], $ads)){
|
||||
$is_enabledAds = true;
|
||||
}
|
||||
if($is_enabledAds) {
|
||||
$data['config'] = 'enabled';
|
||||
}
|
||||
}
|
||||
|
||||
if(!$data['impressions']){
|
||||
$data['impressions'] = 0;
|
||||
}
|
||||
|
||||
$data['hash_no'] = $this->makeHash($data['seq']);
|
||||
$url = env('app.eventURL');
|
||||
if($data['another_url'])
|
||||
$url = env('app.newEventURL');
|
||||
$data['event_url'] = $url.$data['hash_no'];
|
||||
$data['db_price'] = number_format($data['db_price']);
|
||||
}
|
||||
|
||||
$result = [
|
||||
'data' => $result['data'],
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($arg['draw']),
|
||||
];
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdv()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->event->getAdv($arg['stx']);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMedia()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->event->getMedia($arg['stx']);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createEvent()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = $this->setArg($arg);
|
||||
|
||||
$data['advertiser'] = $arg['advertiser'];
|
||||
$data['keyword'] = $arg['keyword'];
|
||||
$data['ei_datetime'] = date('Y-m-d H:i:s');
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'advertiser' => 'required',
|
||||
'media' => 'required',
|
||||
];
|
||||
$validationMessages = [
|
||||
'advertiser' => [
|
||||
'required' => '광고주가 입력되지 않았습니다.',
|
||||
],
|
||||
'media' => [
|
||||
'required' => '매체가 입력되지 않았습니다.',
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$adData = [
|
||||
'seq' => $arg['advertiser']
|
||||
];
|
||||
$advertiser = $this->advertiser->getAdvertiser($adData);
|
||||
if(empty($advertiser['company_seq']) || $advertiser['company_seq'] == 0){
|
||||
$error = ['advertiser' => '소속이 지정되지 않은 광고주입니다.'];
|
||||
return $this->failValidationErrors($error);
|
||||
}
|
||||
|
||||
$result = $this->event->createEvent($data);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateEvent()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = $this->setArg($arg);
|
||||
$data['keyword'] = $arg['keyword'];
|
||||
$data['ei_updatetime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'media' => 'required',
|
||||
];
|
||||
$validationMessages = [
|
||||
'media' => [
|
||||
'required' => '매체가 입력되지 않았습니다.',
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->event->updateEvent($data, $arg['seq']);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function copyEvent()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$data = $this->request->getRawInput();
|
||||
if(empty($data['seq'])){
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
$result = $this->event->copyEvent($data['seq']);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteEvent()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'delete'){
|
||||
$data = $this->request->getRawInput();
|
||||
if(empty($data['seq'])){
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
$url = "https://event.hotblood.co.kr/filecheck/".$data['seq'];
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if (!$response) {
|
||||
$result = $this->event->deleteEvent($data['seq']);
|
||||
return $this->respond($result);
|
||||
} else {
|
||||
$result = $this->event->deleteEvent($data['seq']);
|
||||
return $this->respond($result);
|
||||
return $this->fail("삭제할 수 없는 이벤트입니다.");
|
||||
}
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getEvent()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$seq = $this->request->getGet('seq');
|
||||
$result = $this->event->getEvent($seq);
|
||||
$result['keywords'] = explode(',', $result['keywords']);
|
||||
$result['hash_no'] = $this->makeHash($result['seq']);
|
||||
$url = env('app.eventURL');
|
||||
if($result['another_url'])
|
||||
$url = env('app.newEventURL');
|
||||
$result['event_url'] = $url.$result['hash_no'];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getEventImpressions()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$seq = $this->request->getGet('seq');
|
||||
$result = $this->event->getEventImpressions($seq);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
private function setArg($arg){
|
||||
$data = [
|
||||
'media' => $arg['media'],
|
||||
'description' => $arg['description'],
|
||||
'db_price' => (integer)$arg['db_price'] ?? 0,
|
||||
'interlock' => (integer)$arg['interlock'] ?? 0,
|
||||
'partner_id' => $arg['partner_id'],
|
||||
'partner_name' => $arg['partner_name'],
|
||||
'paper_code' => $arg['paper_code'],
|
||||
'paper_name' => $arg['paper_name'],
|
||||
'lead' => (integer)$arg['lead'],
|
||||
'creative_id' => (integer)$arg['creative_id'] ?? 0,
|
||||
'bizform_apikey' => $arg['bizform_apikey'],
|
||||
'is_stop' => (integer)$arg['is_stop'] ?? 0,
|
||||
'custom' => $arg['custom'],
|
||||
'title' => $arg['title'],
|
||||
'subtitle' => $arg['subtitle'],
|
||||
'object' => $arg['object'],
|
||||
'object_items' => $arg['object_items'],
|
||||
'pixel_id' => trim($arg['pixel_id']),
|
||||
'view_script' => $arg['view_script'],
|
||||
'done_script' => $arg['done_script'],
|
||||
'check_gender' => $arg['check_gender'],
|
||||
'check_age_min' => (integer)$arg['check_age_min'] ?? 0,
|
||||
'check_age_max' => (integer)$arg['check_age_max'] ?? 0,
|
||||
'duplicate_term' => (integer)$arg['duplicate_term'] ?? 0,
|
||||
'check_phone' => $arg['check_phone'],
|
||||
'check_name' => $arg['check_name'],
|
||||
'duplicate_precheck' => (integer)$arg['duplicate_precheck'] ?? 0,
|
||||
'no_hash' => isset($arg['no_hash']) ? (integer)$arg['no_hash'] : 0,
|
||||
'another_url' => isset($arg['another_url']) ? (integer)$arg['another_url'] : 0,
|
||||
'username' => auth()->user()->nickname ?? '',
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function makeHash($uid) {
|
||||
$ab = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$s_id = str_split($uid);
|
||||
$make_hash = [0,0];
|
||||
for($i=0; $i<count($s_id); $i++) $make_hash[0] += $s_id[$i]*($i+$s_id[count($s_id)-1]);
|
||||
for($i=0; $i<count($s_id); $i++) $make_hash[1] += $s_id[$i]*($i+$s_id[0]);
|
||||
$make_hash = array_map(function($v) use($ab){$chksum = ($v % 26); return $ab[$chksum];}, $make_hash);
|
||||
$hash = implode("", $make_hash);
|
||||
$result = $hash.$uid;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\ExcelModel;
|
||||
use Config\Services;
|
||||
|
||||
class ExcelController extends BaseController
|
||||
{
|
||||
protected $excel;
|
||||
public function __construct()
|
||||
{
|
||||
$this->excel = model(ExcelModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('events/excelUpload/excel', [
|
||||
'validation' => Services::validation(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
if(strtolower($this->request->getMethod()) === 'post'){
|
||||
$validated = $this->validate([
|
||||
'upload_file' => [
|
||||
'uploaded[upload_file]',
|
||||
'ext_in[upload_file,csv]',
|
||||
'max_size[upload_file, 4096]',
|
||||
],
|
||||
],
|
||||
[
|
||||
'upload_file' => [
|
||||
'uploaded' => '업로드 오류가 발생하였습니다.',
|
||||
'ext_in' => 'csv 파일만 업로드 가능합니다.',
|
||||
'max_size' => '파일 크기는 4MB를 초과할 수 없습니다.'
|
||||
]
|
||||
|
||||
]);
|
||||
|
||||
if (!$validated) {
|
||||
return view('events/excelUpload/excel', [
|
||||
'validation' => $this->validator
|
||||
]);
|
||||
}
|
||||
|
||||
$file = $this->request->getFile('upload_file');
|
||||
$filePath = $file->getPathname();
|
||||
$row = 1; //줄수 초기화
|
||||
$idx = 0; //배열 인덱스
|
||||
$fp = fopen($filePath, "r");
|
||||
while (($data = fgetcsv($fp, 1000, ",")) !== false) { //csv파일열기
|
||||
if ($row == 1) {
|
||||
$row += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
$excel[$idx]['reg_date'] = iconv("EUC-KR", "UTF-8", $data[1]);
|
||||
$excel[$idx]['name'] = preg_replace("/[#\&\+%@=\/\\\:;,\.'\"\^`~\_|\!\?\*$#<>\[\]\{\}]/i", "", iconv("EUC-KR", "UTF-8", $data[2]));
|
||||
$excel[$idx]['phone'] = strtr(iconv("EUC-KR", "UTF-8", $data[3]), array("+82 " => "0", "-" => "")); // 전화번호에서 국제번호 및 하이픈 제거
|
||||
$excel[$idx]['add1'] = iconv("EUC-KR", "UTF-8", $data[4]); //나이 또는 생년월일
|
||||
$excel[$idx]['add2'] = iconv("EUC-KR", "UTF-8", $data[5]);
|
||||
$excel[$idx]['add3'] = iconv("EUC-KR", "UTF-8", $data[6]);
|
||||
$excel[$idx]['add4'] = iconv("EUC-KR", "UTF-8", $data[7]);
|
||||
$excel[$idx]['add5'] = iconv("EUC-KR", "UTF-8", $data[8]);
|
||||
$excel[$idx]['branch'] = iconv("EUC-KR", "UTF-8", $data[9]);
|
||||
$excel[$idx]['age'] = iconv("EUC-KR", "UTF-8", $data[10]);
|
||||
$excel[$idx]['partner_name'] = iconv("EUC-KR", "UTF-8", $data[11]); //파트너명
|
||||
$excel[$idx]['partner_id'] = iconv("EUC-KR", "UTF-8", $data[12]); //파트너아이디
|
||||
$excel[$idx]['hospital_name'] = iconv("EUC-KR", "UTF-8", $data[13]); //코드명
|
||||
$excel[$idx]['counsel_memo'] = iconv("EUC-KR", "UTF-8", $data[14]); //지면명
|
||||
$excel[$idx]['paper_code'] = iconv("EUC-KR", "UTF-8", $data[13]); //코드명
|
||||
$excel[$idx]['paper_name'] = iconv("EUC-KR", "UTF-8", $data[14]); //지면명
|
||||
$excel[$idx]['event_seq'] = iconv("EUC-KR", "UTF-8", $data[15]); //랜딩번호
|
||||
$excel[$idx]['site'] = iconv("EUC-KR", "UTF-8", $data[16]); //사이트
|
||||
|
||||
if ($excel[$idx]['name'] && $excel[$idx]['phone']) {
|
||||
$status_check = $this->excel->status_check($excel[$idx]['name'], $excel[$idx]['phone'], $excel[$idx]['event_seq']);
|
||||
$excel[$idx]['status'] = $status_check['status'];
|
||||
$excel[$idx]['status_memo'] = $status_check['status_memo'];
|
||||
}
|
||||
|
||||
$idx++;
|
||||
}
|
||||
session()->setFlashdata('success', 'Success! image uploaded.');
|
||||
return redirect()->to(site_url('/events/exelUpload/exel'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\EventManage;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\EventManage\MediaModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class MediaController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $media;
|
||||
public function __construct()
|
||||
{
|
||||
$this->media = model(MediaModel::class);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('/events/media/media');
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->media->getMedias($arg);
|
||||
$list = $result['data'];
|
||||
|
||||
$result = [
|
||||
'data' => $list,
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($arg['draw']),
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMedia()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->media->getMedia($arg);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function createMedia()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = [
|
||||
'media' => $arg['media'],
|
||||
'target' => $arg['target'],
|
||||
];
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'media' => 'required|is_unique[event_media.media]',
|
||||
];
|
||||
$validationMessages = [
|
||||
'media' => [
|
||||
'required' => '매체명은 필수 입력 사항입니다.',
|
||||
'is_unique' => '이미 등록된 매체입니다.'
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->media->createMedia($data);
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateMedia()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put'){
|
||||
$arg = $this->request->getRawInput();
|
||||
$data = [
|
||||
'media' => $arg['media'],
|
||||
'target' => $arg['target'],
|
||||
];
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
$validationRules = [
|
||||
'media' => 'required',
|
||||
];
|
||||
$validationMessages = [
|
||||
'media' => [
|
||||
'required' => '매체명은 필수 입력 사항입니다.',
|
||||
],
|
||||
];
|
||||
$validation->setRules($validationRules, $validationMessages);
|
||||
if (!$validation->run($data)) {
|
||||
$errors = $validation->getErrors();
|
||||
return $this->failValidationErrors($errors);
|
||||
}
|
||||
|
||||
$result = $this->media->updateMedia($data, $arg['seq']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class ExampleController extends BaseController
|
||||
{
|
||||
public function view($page = 'test')
|
||||
{
|
||||
if(!is_file(APPPATH . 'Views/example/' . $page . '.php')) {
|
||||
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
|
||||
}
|
||||
|
||||
return view('example/'.$page);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class GuestController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('guest/guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Controllers\AdvertisementManager\AdvFacebookManagerController;
|
||||
use App\Controllers\AdvertisementManager\AdvGoogleManagerController;
|
||||
use App\Controllers\AdvertisementManager\AdvKakaoManagerController;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [];
|
||||
$data['password_check'] = false;
|
||||
$password_check = auth()->user()->getEmailIdentity()->password_changed_at;
|
||||
|
||||
if(!empty($password_check) && (strtotime($password_check) < strtotime('-90 days'))){
|
||||
$data['password_check'] = true;
|
||||
}
|
||||
|
||||
return view('pages/home', $data);
|
||||
}
|
||||
|
||||
public function getReports()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$facebookDB = \Config\Database::connect('facebook');
|
||||
$googleDB = \Config\Database::connect('google');
|
||||
$kakaoDB = \Config\Database::connect('kakao');
|
||||
|
||||
$result = [];
|
||||
$facebook = new AdvFacebookManagerController;
|
||||
$result['facebookReport'] = $facebook->getReport();
|
||||
|
||||
$google = new AdvGoogleManagerController;
|
||||
$result['googleReport'] = $google->getReport();
|
||||
|
||||
$kakao = new AdvKakaoManagerController;
|
||||
$result['kakaoReport'] = $kakao->getReport();
|
||||
|
||||
return $this->respond($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\HumanResource;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\HumanResource\HumanResourceModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Libraries\Douzone\Douzone;
|
||||
use App\Libraries\Douzone\DouzoneModel;
|
||||
|
||||
class HumanResourceController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $hr;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->hr = model(HumanResourceModel::class);
|
||||
}
|
||||
|
||||
public function humanResource()
|
||||
{
|
||||
return view('humanResource/humanresource');
|
||||
}
|
||||
|
||||
private function getDayOff()
|
||||
{ //연차
|
||||
$douzone = new Douzone();
|
||||
$list = $douzone->getDayOff();
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getMemberList()
|
||||
{
|
||||
$lists = $this->hr->getMemberList();
|
||||
foreach($lists as $row) $data[] = [$row['nickname'],$row['division'],$row['secret']];
|
||||
foreach ($lists as $row) $data[] = [$row['nickname'], $row['division'], $row['secret']];
|
||||
dd($data);
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public function updateUsersByDouzone()
|
||||
{
|
||||
$douzone = new Douzone();
|
||||
$list = $douzone->getMemberList();
|
||||
$total = count($list);
|
||||
if (!$total) return null;
|
||||
if (!$total) return null;
|
||||
$i = 1;
|
||||
foreach ($list as $row) {
|
||||
foreach ($list as $row) {
|
||||
$result = $this->hr->updateUserByEmail($row);
|
||||
if ($result) $i++;
|
||||
if ($result) $i++;
|
||||
}
|
||||
if ($result == $i) return true;
|
||||
if ($result == $i) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getHourTicketUse()
|
||||
{
|
||||
$hourticket = $this->hr->getHourTicketUse();
|
||||
|
||||
return $hourticket;
|
||||
}
|
||||
|
||||
public function getTodayDayOff($date = null)
|
||||
{
|
||||
$date = $date ? date('Y-m-d', strtotime($date)) : date('Y-m-d');
|
||||
$list = $this->getDayOff();
|
||||
$data = [];
|
||||
foreach ($list as $row) {
|
||||
if (isset($row['start']) && date('Y-m-d', strtotime($row['start'])) >= $date) {
|
||||
$data['day'][] = $row;
|
||||
}
|
||||
}
|
||||
$list = $this->getHourTicketUse($date);
|
||||
foreach ($list as $row) {
|
||||
if (isset($row['date']) && date('Y-m-d', strtotime($row['date'])) >= $date) {
|
||||
$data['hour'][] = $row;
|
||||
}
|
||||
}
|
||||
$result = $this->setMessageData($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function gwData(){
|
||||
$result = $this->hr->gwData();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getGwData(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->getGwData($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function issueProc()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$data = $this->request->getRawInput();
|
||||
$result = $this->hr->issueProc($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function hourTicketConfirm()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->hourTicketConfirm($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function hourTicketReg()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->HourTicketReg($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getHourTicketAll()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->getHourTicketAll($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getHourTicketIssue()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->getHourTicketIssue($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getHourTicketUseNew()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post') {
|
||||
$input = $this->request->getBody();
|
||||
$data = json_decode($input, true);
|
||||
$result = $this->hr->getHourTicketUseNew($data);
|
||||
|
||||
return json_encode($result);
|
||||
} else {
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function setMessageData($lists)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($lists as $type => $list) {
|
||||
foreach ($list as $row) {
|
||||
$user = $this->hr->getUserByEmail($row['email']);
|
||||
if (empty($user)) continue;
|
||||
$type = isset($row['type']) ? $row['type'] : '시차';
|
||||
$start = isset($row['start']) ? date('Y-m-d', strtotime($row['start'])) : date('Y-m-d H:m', strtotime($row['date'] . " " . $row['time']));
|
||||
$end = isset($row['end']) ? date('Y-m-d', strtotime($row['end'])) : date('Y-m-d H:m', strtotime($row['date'] . " " . $row['time'] . " +{$row['hour_ticket']} hours"));
|
||||
$term = isset($row['used']) ? $row['used'] : $row['hour_ticket'];
|
||||
$total_remain = isset($row['total']['remain']) ? $row['total']['remain'] : $row['remain'];
|
||||
$total_used = isset($row['total']['used']) ? $row['total']['used'] : '';
|
||||
$datetime = isset($row['reg_datetime']) ? $row['reg_datetime'] : $row['rep_dt'];
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'name' => $user['nickname'],
|
||||
'division' => $user['division'],
|
||||
'team' => $user['team'],
|
||||
'position' => $user['position'],
|
||||
'term' => $term,
|
||||
'total_used' => $total_used,
|
||||
'total_remain' => $total_remain,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'datetime' => $datetime
|
||||
];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Integrate;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\Integrate\IntegrateModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
use Mpdf\Mpdf;
|
||||
class IntegrateController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $integrate;
|
||||
protected $is_pravate_perm = false;
|
||||
private $leads_status = [
|
||||
0 => "미확인", 1 => "인정", 2 => "중복", 3 => "성별불량", 4 => "나이불량", 5 => "콜불량", 6 => "번호불량", 7 => "테스트",
|
||||
8 => "이름불량", 9 => "지역불량", 10 => "업체불량", 11 => "미성년자", 12 => "본인아님", 13 => "쿠키중복", 99 => "확인"
|
||||
];
|
||||
public function __construct()
|
||||
{
|
||||
$this->integrate = model(IntegrateModel::class);
|
||||
if(auth()->user()->inGroup('superadmin','admin','developer', 'agency', 'advertiser')) {
|
||||
$this->is_pravate_perm = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$_get = $this->request->getGet();
|
||||
return view('integrate/DBintegrated', $_get);
|
||||
}
|
||||
public function download()
|
||||
{
|
||||
$_get = $this->request->getGet();
|
||||
return view('integrate/DBdownload', $_get);
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
$date = $this->request->getPost('date') ?? ['sdate' => date('Y-m-d'), 'edate' => date('Y-m-d')];
|
||||
$sdate = (new \DateTime($date['sdate']))->format('Y-m-d') . ' 00:00:00';
|
||||
$edate = (new \DateTime($date['edate']))->format('Y-m-d') . ' 23:59:59';
|
||||
|
||||
//list
|
||||
$list = $this->integrate->getEventLead(['sdate' => $sdate, 'edate' => $edate]);
|
||||
foreach($list['data'] as &$d){
|
||||
// Trim all data
|
||||
$d = array_map('trim', $d);
|
||||
$d['hash_no'] = makeHash($d['info_seq']);
|
||||
$event_url = env('app.eventURL');
|
||||
if($d['another_url'])
|
||||
$event_url = env('app.newEventURL');
|
||||
$d['event_url'] = $event_url.$d['hash_no'];
|
||||
$etc = [];
|
||||
if(!empty($d['email'])) {
|
||||
$etc[] = $d['email'];
|
||||
}
|
||||
$d['dec_phone'] = preg_replace("/([0-9]{3})([0-9]{4})([0-9]{4})/", "$1-$2-$3", $d['dec_phone']);
|
||||
$d['age'] = $d['age'] == 0 ? '' : $d['age'];
|
||||
if(!$this->is_pravate_perm) {
|
||||
if(!preg_match('/test|테스트/i', $d['name']) && $d['status'] != 7) {
|
||||
$d['dec_phone'] = substr($d['dec_phone'],0,3).'<i class="masking">▒▒</i>'.substr($d['dec_phone'],-4);
|
||||
$d['dec_phone'] = html_entity_decode($d['dec_phone']);
|
||||
$name = trim($d['name']);
|
||||
$d['name'] = '';
|
||||
for($ii=0; $ii<mb_strlen($name); $ii++) {
|
||||
if(mb_strlen($name) >= 4 && $ii > 2 && mb_strlen($name)-1 != $ii)
|
||||
continue;
|
||||
else
|
||||
$d['name'] .= (($ii>0&&$ii<mb_strlen($name)-1)||$ii==1)?'<i class="masking">▒</i>':mb_substr($name, $ii, 1);
|
||||
$d['name'] = html_entity_decode($d['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
for($i2=1;$i2<7;$i2++){
|
||||
if(!empty($d['add'.$i2])){
|
||||
if(strpos($d['add'.$i2], "uploads")){
|
||||
$href = "<a href='".str_replace("./","{$event_url}uploads/",$d['add'.$i2])."' target='_blank'>[파일보기]</a>";
|
||||
$etc[] = $href;
|
||||
}else if(strpos($d['add'.$i2], "/v_")){
|
||||
$href = "<a href='{$event_url}img_viewer.php?data={$d['add'.$i2]}' target='_blank'>[파일보기]</a>";
|
||||
$etc[] = $href;
|
||||
}
|
||||
else{
|
||||
$etc[] = $d['add'.$i2];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($d['memo'])){
|
||||
$etc[] = $d['memo'];
|
||||
}
|
||||
if(!empty($d['addr'])){
|
||||
$etc[] = $d['addr'];
|
||||
}
|
||||
if(!empty($d['branch'])){
|
||||
$etc[] = $d['branch'];
|
||||
}
|
||||
$add = implode('/', $etc);
|
||||
$d['add'][] = $add;
|
||||
}
|
||||
|
||||
$result = $list;
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
private function getColumns()
|
||||
{
|
||||
$columns = [
|
||||
'event_seq' => '이벤트', 'site' => '사이트',
|
||||
'name' => '이름', 'phone' => '연락처',
|
||||
'age' => '나이', 'gender' => '성별', 'branch' => '지점', 'addr' => '주소',
|
||||
'email' => 'Email', 'add1' => '설문1', 'add2' => '설문2', 'add3' => '설문3',
|
||||
'add4' => '설문4', 'add5' => '설문5', 'add6' => '설문6', 'status' => '상태',
|
||||
'memos' => '메모', 'ip' => 'IP', 'reg_date' => '등록일시'
|
||||
];
|
||||
if(auth()->user()->hasPermission('integrate.description')
|
||||
|| auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
$columns = array_merge(
|
||||
array_slice($columns, 0, 2, true),
|
||||
['description' => '구분'],
|
||||
array_slice($columns, 2, null, true)
|
||||
);
|
||||
}
|
||||
if(auth()->user()->hasPermission('integrate.media')
|
||||
|| auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
$columns = array_merge(
|
||||
array_slice($columns, 0, 2, true),
|
||||
['media' => '매체'],
|
||||
array_slice($columns, 2, null, true)
|
||||
);
|
||||
}
|
||||
if(auth()->user()->hasPermission('integrate.advertiser')
|
||||
|| auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
$columns = array_merge(
|
||||
array_slice($columns, 0, 2, true),
|
||||
['advertiser' => '광고주'],
|
||||
array_slice($columns, 2, null, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (getenv('MY_SERVER_NAME') === 'resta' && auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')) {
|
||||
$columns = array_merge(['company' => '회사명'], $columns);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
private function transformData($data, $columns)
|
||||
{
|
||||
$transformedData = [];
|
||||
foreach ($data as $row) {
|
||||
$transformedRow = [];
|
||||
$isTestOrStatus7 = preg_match('/test|테스트/i', $row['name']) || $row['status'] == 7;
|
||||
|
||||
foreach ($columns as $key => $header) {
|
||||
$value = $row[$key];
|
||||
if ($key === 'phone') {
|
||||
if (!$this->is_pravate_perm && !$isTestOrStatus7) {
|
||||
$value = substr($value, 0, 3) . '▒▒' . substr($value, -4);
|
||||
$value = html_entity_decode($value);
|
||||
} else {
|
||||
$value = preg_replace("/([0-9]{3})([0-9]{4})([0-9]{4})/", "$1-$2-$3", $value);
|
||||
}
|
||||
} elseif ($key === 'status') {
|
||||
$value = $this->leads_status[$row[$key]];
|
||||
} elseif ($key === 'age') {
|
||||
$value = $value == 0 ? "" : $value;
|
||||
} elseif ($key === 'name' && !$this->is_pravate_perm && !$isTestOrStatus7) {
|
||||
$name = trim($value);
|
||||
$value = '';
|
||||
for ($ii = 0; $ii < mb_strlen($name); $ii++) {
|
||||
if (mb_strlen($name) >= 4 && $ii > 2 && mb_strlen($name) - 1 != $ii) {
|
||||
continue;
|
||||
} else {
|
||||
$value .= (($ii > 0 && $ii < mb_strlen($name) - 1) || $ii == 1) ? '▒' : mb_substr($name, $ii, 1);
|
||||
$value = html_entity_decode($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$transformedRow[$key] = $value;
|
||||
}
|
||||
$transformedData[] = $transformedRow;
|
||||
}
|
||||
return $transformedData;
|
||||
}
|
||||
|
||||
public function downloadData()
|
||||
{
|
||||
$sdate = $this->request->getPost('sdate');
|
||||
$edate = $this->request->getPost('edate');
|
||||
$advertiser = $this->request->getPost('advertiser');
|
||||
$media = $this->request->getPost('media');
|
||||
$description = $this->request->getPost('description');
|
||||
$message = $this->request->getPost('message');
|
||||
$fileFormat = $this->request->getPost('file_format'); // 파일 형식 추가
|
||||
$user = auth()->user();
|
||||
|
||||
$data = [
|
||||
'sdate' => $sdate,
|
||||
'edate' => $edate,
|
||||
'advertiser' => $advertiser,
|
||||
'media' => $media,
|
||||
'description' => $description,
|
||||
'message' => $message,
|
||||
'username' => $user->username,
|
||||
'reg_date' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$this->integrate->saveDownloadData($data);
|
||||
|
||||
$row = $this->integrate->getEventLeadRow($data);
|
||||
if (!$row) {
|
||||
return $this->response->setJSON(['status' => 'error', 'message' => '데이터를 찾을 수 없습니다.']);
|
||||
}
|
||||
|
||||
$columns = $this->getColumns();
|
||||
$transformedData = $this->transformData($row, $columns);
|
||||
|
||||
switch ($fileFormat) {
|
||||
case 'csv':
|
||||
$fileData = $this->createCSVFile($transformedData, $columns);
|
||||
$contentType = 'text/csv';
|
||||
$fileExtension = 'csv';
|
||||
break;
|
||||
case 'pdf':
|
||||
$fileData = $this->createPDFFile($transformedData, $columns);
|
||||
$contentType = 'application/pdf';
|
||||
$fileExtension = 'pdf';
|
||||
break;
|
||||
case 'xlsx':
|
||||
default:
|
||||
$fileData = $this->createExcelFile($transformedData, $columns);
|
||||
$contentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||
$fileExtension = 'xlsx';
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->response
|
||||
->setHeader('Content-Type', $contentType)
|
||||
->setHeader('Content-Disposition', 'attachment; filename="event_lead_' . date('YmdHis') . '.' . $fileExtension . '"')
|
||||
->setBody($fileData);
|
||||
}
|
||||
|
||||
private function createCSVFile($data, $columns)
|
||||
{
|
||||
$output = fopen('php://temp', 'r+');
|
||||
// UTF-8 BOM 추가
|
||||
fputs($output, "\xEF\xBB\xBF");
|
||||
fputcsv($output, array_values($columns));
|
||||
|
||||
foreach ($data as $row) {
|
||||
$rowData = [];
|
||||
foreach ($columns as $key => $header) {
|
||||
$rowData[] = $row[$key] ?? ''; // 키가 존재하지 않으면 빈 문자열로 대체
|
||||
}
|
||||
fputcsv($output, $rowData);
|
||||
}
|
||||
|
||||
rewind($output);
|
||||
$csvData = stream_get_contents($output);
|
||||
fclose($output);
|
||||
|
||||
return $csvData;
|
||||
}
|
||||
private function createPDFFile($data, $columns)
|
||||
{
|
||||
$html = '<table border="1" style="border-collapse: collapse; width: 100%;"><thead><tr>';
|
||||
foreach ($columns as $header) {
|
||||
$html .= "<th style='padding: 5px;'>{$header}</th>";
|
||||
}
|
||||
$html .= '</tr></thead><tbody>';
|
||||
|
||||
foreach ($data as $row) {
|
||||
$html .= '<tr>';
|
||||
foreach ($columns as $key => $header) {
|
||||
$value = $row[$key] ?? ''; // 키가 존재하지 않으면 빈 문자열로 대체
|
||||
$html .= "<td style='padding: 5px;'>{$value}</td>";
|
||||
}
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</tbody></table>';
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'default_font' => 'nanumgothic', // 기본 폰트를 나눔고딕으로 설정
|
||||
'orientation' => 'L', // 가로 방향 설정
|
||||
'margin_left' => 5,
|
||||
'margin_right' => 5,
|
||||
'margin_top' => 5,
|
||||
'margin_bottom' => 5,
|
||||
'tempDir' => WRITEPATH . 'tmp', // CodeIgniter 4 writable 디렉토리 설정
|
||||
'fontDir' => array_merge((new \Mpdf\Config\ConfigVariables())->getDefaults()['fontDir'], [
|
||||
FCPATH . 'fonts', // 폰트 파일 경로
|
||||
]),
|
||||
'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [
|
||||
'nanumgothic' => [
|
||||
'R' => 'NanumGothic-Regular.ttf',
|
||||
'B' => 'NanumGothic-Bold.ttf',
|
||||
]
|
||||
],
|
||||
'default_font_size' => 12, // 기본 폰트 크기 설정
|
||||
]);
|
||||
|
||||
$mpdf->WriteHTML($html);
|
||||
return $mpdf->Output('', 'S');
|
||||
}
|
||||
private function createExcelFile($data, $columns)
|
||||
{
|
||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// 헤더 설정
|
||||
$columnIndex = 'A';
|
||||
$sheet->setCellValue($columnIndex . '1', '#');
|
||||
$columnIndex++;
|
||||
foreach ($columns as $key => $header) {
|
||||
$sheet->setCellValue($columnIndex . '1', $header);
|
||||
if (in_array($key, ['addr', 'email', 'add1', 'add2', 'add3', 'add4', 'add5', 'add6'])) {
|
||||
$sheet->getColumnDimension($columnIndex)->setAutoSize(true);
|
||||
$sheet->getColumnDimension($columnIndex)->setWidth(200 / 7); // 최대 200픽셀로 제한
|
||||
} else if ($key === 'name') {
|
||||
$sheet->getColumnDimension($columnIndex)->setWidth(100 / 7); // 100픽셀로 설정 (엑셀의 너비 단위는 약 1/7인치)
|
||||
} else {
|
||||
$sheet->getColumnDimension($columnIndex)->setAutoSize(true); // 자동 너비 조정
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
// 필터 설정
|
||||
$sheet->setAutoFilter($sheet->calculateWorksheetDimension());
|
||||
|
||||
// 데이터 삽입
|
||||
$rowIndex = 2; // 데이터는 2번째 행부터 시작
|
||||
$totalRows = count($data);
|
||||
foreach ($data as $row) {
|
||||
$columnIndex = 'A';
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $totalRows); // 역순 카운트
|
||||
$columnIndex++;
|
||||
|
||||
foreach ($columns as $key => $header) {
|
||||
$value = $row[$key];
|
||||
if ($key === 'phone') {
|
||||
$value = preg_replace("/([0-9]{3})([0-9]{4})([0-9]{4})/", "$1-$2-$3", $value);
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
} elseif($key === 'age') {
|
||||
$value = $value == 0 ? "" : $value;
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
} elseif ($key === 'site') {
|
||||
$sheet->getCell($columnIndex . $rowIndex)->setValueExplicit($value, \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
|
||||
} else {
|
||||
$sheet->setCellValue($columnIndex . $rowIndex, $value);
|
||||
}
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$rowIndex++;
|
||||
$totalRows--;
|
||||
}
|
||||
|
||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
|
||||
ob_start();
|
||||
$writer->save('php://output');
|
||||
$excelData = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $excelData;
|
||||
}
|
||||
|
||||
public function getButtons()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getPost();
|
||||
$arg['sdate'] = (new \DateTime($arg['sdate']))->format('Y-m-d') . ' 00:00:00';
|
||||
$arg['edate'] = (new \DateTime($arg['edate']))->format('Y-m-d') . ' 23:59:59';
|
||||
$leadsAll = $this->integrate->getEventLeadCount($arg);
|
||||
|
||||
$filters = [];
|
||||
$filters['data'] = $leadsAll['filteredResult'];
|
||||
$buttons['filtered'] = $this->setCount($leadsAll['filteredResult'], 'count');
|
||||
$buttons['noFiltered'] = $this->setCount($leadsAll['noFilteredResult'], 'total');
|
||||
foreach($buttons['noFiltered'] as $type => $row){
|
||||
foreach($row as $k => $v) {
|
||||
if(!isset($buttons['filtered'][$type][$k]))
|
||||
$buttons['filtered'][$type][$k] = ['count' => 0];
|
||||
$filter_lists[$type][$k] = array_merge($buttons['filtered'][$type][$k], $v);
|
||||
}
|
||||
}
|
||||
if(!empty($filter_lists)){
|
||||
foreach($filter_lists as $type => $row) {
|
||||
$sortedRow = array();
|
||||
|
||||
foreach ($row as $name => $v) {
|
||||
$sortedRow[$name] = array_merge(['label' => $name], $v);
|
||||
}
|
||||
|
||||
asort($sortedRow);
|
||||
$sortedRow = array_values($sortedRow);
|
||||
|
||||
$filters[$type] = $sortedRow;
|
||||
}
|
||||
}
|
||||
$status = $this->integrate->getStatusCount($arg);
|
||||
$filters['status'] = $status;
|
||||
|
||||
return $this->respond($filters);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getEventLeadCount()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
if(!isset($arg['searchData'])) {
|
||||
$arg['searchData'] = [
|
||||
'sdate'=> date('Y-m-d'),
|
||||
'edate'=> date('Y-m-d')
|
||||
];
|
||||
}
|
||||
$data = $this->integrate->getEventLeadCount($arg);
|
||||
|
||||
$adv_counts = array();
|
||||
$med_counts = array();
|
||||
$event_counts = array();
|
||||
foreach ($data as $row) {
|
||||
if (!array_key_exists($row['adv_name'], $adv_counts)) {
|
||||
$adv_counts[$row['adv_name']] = array(
|
||||
'countAll' => 0
|
||||
);
|
||||
}
|
||||
|
||||
if (!array_key_exists($row['med_name'], $med_counts)) {
|
||||
$med_counts[$row['med_name']] = array(
|
||||
'countAll' => 0
|
||||
);
|
||||
}
|
||||
|
||||
$event_counts[$row['description']] = array(
|
||||
'countAll' => $row['countAll'],
|
||||
);
|
||||
|
||||
$adv_counts[$row['adv_name']]['countAll'] += $row['countAll'];
|
||||
$med_counts[$row['med_name']]['countAll'] += $row['countAll'];
|
||||
}
|
||||
|
||||
$result = [
|
||||
'advertiser' => $adv_counts,
|
||||
'media' => $med_counts,
|
||||
'description' => $event_counts,
|
||||
];
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getStatusCount()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
if(!isset($arg['searchData'])) {
|
||||
$arg['searchData'] = [
|
||||
'sdate'=> date('Y-m-d'),
|
||||
'edate'=> date('Y-m-d')
|
||||
];
|
||||
}
|
||||
$result = $this->integrate->getStatusCount($arg);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getMemo()
|
||||
{
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get'){
|
||||
$arg = $this->request->getGet();
|
||||
$result = $this->integrate->getMemo($arg);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function addMemo() {
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
$arg = $this->request->getPost();
|
||||
$result = $this->integrate->addMemo($arg);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setStatus() {
|
||||
if($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'post'){
|
||||
if(!auth()->user()->hasPermission('integrate.status') && !auth()->user()->inGroup('superadmin', 'admin')){
|
||||
return $this->fail("권한이 없습니다.");
|
||||
}
|
||||
$arg = $this->request->getPost();
|
||||
$result = $this->integrate->setStatus($arg);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
private function setCount($leads, $type)
|
||||
{
|
||||
$data = [
|
||||
'advertiser' => [],
|
||||
'media' => [],
|
||||
'description' => [],
|
||||
];
|
||||
if(getenv('MY_SERVER_NAME') === 'resta' && auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
$data['company'] = [];
|
||||
}
|
||||
foreach($leads as $row) {
|
||||
if(getenv('MY_SERVER_NAME') === 'resta' && auth()->user()->inGroup('superadmin', 'admin', 'developer', 'user')){
|
||||
//분류 기준
|
||||
if (!isset($data['company']['리스타'])) {
|
||||
$data['company']['리스타'][$type] = 0;
|
||||
}
|
||||
if($row['status'] == 1 && ($row['company'] != '케어랩스' && $row['company'] != '테크랩스')){
|
||||
$data['company']['리스타'][$type]++;
|
||||
}
|
||||
|
||||
if (isset($row['company'])) {
|
||||
if (!isset($data['company']['케어랩스'])) {
|
||||
$data['company']['케어랩스'][$type] = 0;
|
||||
}
|
||||
|
||||
if (!isset($data['company']['테크랩스'])) {
|
||||
$data['company']['테크랩스'][$type] = 0;
|
||||
}
|
||||
|
||||
if($row['status'] == 1 && $row['company'] == '케어랩스'){
|
||||
$data['company']['케어랩스'][$type]++;
|
||||
}
|
||||
|
||||
if($row['status'] == 1 && $row['company'] == '테크랩스'){
|
||||
$data['company']['테크랩스'][$type]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//광고주 기준
|
||||
if (!empty($row['advertiser'])) {
|
||||
if (!isset($data['advertiser'][$row['advertiser']])) {
|
||||
$data['advertiser'][$row['advertiser']][$type] = 0;
|
||||
}
|
||||
|
||||
if($row['status'] == 1){
|
||||
$data['advertiser'][$row['advertiser']][$type]++;
|
||||
}
|
||||
}
|
||||
|
||||
//매체 기준
|
||||
if (!empty($row['media'])) {
|
||||
if (!isset($data['media'][$row['media']])) {
|
||||
$data['media'][$row['media']][$type] = 0;
|
||||
}
|
||||
|
||||
if($row['status'] == 1){
|
||||
$data['media'][$row['media']][$type]++;
|
||||
}
|
||||
}
|
||||
|
||||
//이벤트 기준
|
||||
if (!empty($row['description'])) {
|
||||
if (!isset($data['description'][$row['description']])) {
|
||||
$data['description'][$row['description']][$type] = 0;
|
||||
}
|
||||
|
||||
if($row['status'] == 1){
|
||||
$data['description'][$row['description']][$type]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
class PageController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$page = new PageController();
|
||||
return $page->view();
|
||||
}
|
||||
|
||||
public function view($page = 'home')
|
||||
{
|
||||
if(!is_file(APPPATH . 'Views/pages/' . $page . '.php')) {
|
||||
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
|
||||
}
|
||||
|
||||
$data['title'] = ucfirst($page);
|
||||
|
||||
return view('pages/'.$page, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
<?php
|
||||
namespace App\Controllers\User;
|
||||
|
||||
use App\Models\Api\CompanyModel;
|
||||
use App\Models\Api\IdentityModel;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\Api\UserModel;
|
||||
use CodeIgniter\Shield\Authentication\Passwords;
|
||||
use CodeIgniter\Shield\Entities\User;
|
||||
|
||||
class UserController extends \CodeIgniter\Controller
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $user;
|
||||
protected $company;
|
||||
protected $data;
|
||||
protected $logginedUser;
|
||||
protected $validation;
|
||||
|
||||
public function __construct() {
|
||||
$this->user = model(UserModel::class);
|
||||
$this->company = model(CompanyModel::class);
|
||||
$this->logginedUser = auth()->user();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('users/user');
|
||||
}
|
||||
|
||||
public function myPage()
|
||||
{
|
||||
return view('users/mypage', ['user'=>$this->logginedUser]);
|
||||
}
|
||||
|
||||
public function myPageUpdate()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$credentials = [
|
||||
'email' => $this->logginedUser->getEmail(),
|
||||
'password' => $data['old_password'],
|
||||
];
|
||||
|
||||
$validCreds = auth()->check($credentials);
|
||||
if (! $validCreds->isOK()) {
|
||||
return redirect()->back()->with('error', '기존 비밀번호가 일치하지 않습니다.');
|
||||
}
|
||||
|
||||
$rules = [
|
||||
'password' => [
|
||||
'label' => 'Auth.password',
|
||||
'rules' => 'required|' . Passwords::getMaxLengthRule() . '|strong_password[]',
|
||||
'errors' => [
|
||||
'max_byte' => 'Auth.errorPasswordTooLongBytes',
|
||||
],
|
||||
],
|
||||
'password_confirm' => [
|
||||
'label' => 'Auth.passwordConfirm',
|
||||
'rules' => 'required|matches[password]',
|
||||
],
|
||||
];
|
||||
|
||||
if (! $this->validateData($data, $rules, [], config('Auth')->DBGroup)) {
|
||||
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
$cuser = auth()->user();
|
||||
$cuser->fill($data);
|
||||
$this->user->save($cuser);
|
||||
$this->setPasswordChangedAt(true);
|
||||
return redirect()->back()->with('message', '비밀번호가 변경되었습니다.');
|
||||
}
|
||||
|
||||
public function getUsers(){
|
||||
if (/* $this->request->isAJAX() && */strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->user->getUsers($param);
|
||||
foreach ($result['data'] as &$row) {
|
||||
$groups = explode(",", $row['groups']);
|
||||
$groupsMapping = [
|
||||
'superadmin' => '최고관리자',
|
||||
'admin' => '관리자',
|
||||
'developer' => '개발자',
|
||||
'user' => '직원',
|
||||
'agency' => '광고대행사',
|
||||
'advertiser' => '광고주',
|
||||
'guest' => '게스트',
|
||||
];
|
||||
|
||||
foreach ($groups as &$group) {
|
||||
$group = $groupsMapping[$group] ?? '';
|
||||
}
|
||||
|
||||
usort($groups, function ($a, $b) {
|
||||
return strcmp($a, $b);
|
||||
});
|
||||
|
||||
$row['groups'] = implode(',', $groups);
|
||||
|
||||
if($row['active']){
|
||||
$row['active'] = '활성';
|
||||
}else{
|
||||
$row['active'] = '비활성';
|
||||
}
|
||||
};
|
||||
|
||||
$result = [
|
||||
'data' => $result['data'],
|
||||
'recordsTotal' => $result['allCount'],
|
||||
'recordsFiltered' => $result['allCount'],
|
||||
'draw' => intval($param['draw']),
|
||||
];
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getUser(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->user->getUser($param);
|
||||
$result['groups'] = explode(",", $result['groups']);
|
||||
$result['permissions'] = explode(",", $result['permissions']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getSearchUsers(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->user->getSearchUsers($param);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function getBelongUsers(){
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'get') {
|
||||
$param = $this->request->getGet();
|
||||
$result = $this->user->getBelongUsers($param['company_id']);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setUser()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put') {
|
||||
$param = $this->request->getRawInput();
|
||||
if (!empty($param)) {
|
||||
$company = $this->company->getCompanyByName($param['company_name']);
|
||||
if(!empty($param['company_name'])){
|
||||
if(empty($company)) {
|
||||
return $this->failValidationErrors(["company" => "존재하지 않는 광고주/광고대행사입니다."]);
|
||||
}else{
|
||||
$param['company_id'] = $company['id'];
|
||||
}
|
||||
}
|
||||
if(empty($param['group']) || !$this->checkPermission($this->logginedUser, $param['user_id'], $param['group'])){
|
||||
return $this->failValidationErrors(["groups" => "수정 권한이 없습니다."]);
|
||||
}
|
||||
$result = $this->user->setUser($param);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setBelongUser()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'put') {
|
||||
$param = $this->request->getRawInput();
|
||||
if (!empty($param)) {
|
||||
$belongUser = $this->user->getBelongUser($param);
|
||||
if(!empty($belongUser)){
|
||||
return $this->failValidationErrors(["username" => "이미 소속되어 있습니다."]);
|
||||
}
|
||||
$result = $this->user->setBelongUser($param);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function exceptBelongUser()
|
||||
{
|
||||
if ($this->request->isAJAX() && strtolower($this->request->getMethod()) === 'delete') {
|
||||
$param = $this->request->getRawInput();
|
||||
if (!empty($param)) {
|
||||
$result = $this->user->exceptBelongUser($param);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setPasswordChangedAtAjax()
|
||||
{
|
||||
if (/* $this->request->isAJAX() && */strtolower($this->request->getMethod()) === 'get') {
|
||||
$result = $this->setPasswordChangedAt(false);
|
||||
|
||||
return $this->respond($result);
|
||||
}else{
|
||||
return $this->fail("잘못된 요청");
|
||||
}
|
||||
}
|
||||
|
||||
public function setPasswordChangedAt($type = false)
|
||||
{
|
||||
$user = $this->logginedUser;
|
||||
|
||||
if($type === true){
|
||||
$date = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "+90 days"));
|
||||
}else{
|
||||
$date = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "-76 days"));
|
||||
}
|
||||
|
||||
$identityModel = model(IdentityModel::class);
|
||||
$result = $identityModel->setPasswordChangedAt($user->id, $date);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function checkPermission($logginedUser, $updateId, $postGroups)
|
||||
{
|
||||
$updateUser = $this->user->find($updateId);
|
||||
$logginedUserGroups = $logginedUser->getGroups();
|
||||
$updateUserGroups = $updateUser->getGroups();
|
||||
|
||||
// 그룹 순서 정의
|
||||
$groupOrder = array_keys(config('AuthGroups')->groups);
|
||||
foreach ($postGroups as $postGroup) {
|
||||
foreach ($logginedUserGroups as $logginedUserGroup) {
|
||||
$currentGroupIndex = array_search($logginedUserGroup, $groupOrder);
|
||||
$targetGroupIndex = array_search($postGroup, $groupOrder);
|
||||
// superadmin, admin, developer, user 그룹만 수정 가능
|
||||
$editableGroups = ['superadmin', 'admin', 'developer', 'user'];
|
||||
if (in_array($logginedUserGroup, $editableGroups)) {
|
||||
// 자신의 그룹과 상위 그룹은 수정 불가
|
||||
if ($currentGroupIndex >= $targetGroupIndex) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 수정할 대상 사용자의 그룹이 자신보다 높은지 체크
|
||||
foreach ($updateUserGroups as $updateUserGroup) {
|
||||
foreach ($logginedUserGroups as $logginedUserGroup) {
|
||||
$currentGroupIndex = array_search($logginedUserGroup, $groupOrder);
|
||||
$updateGroupIndex = array_search($updateUserGroup, $groupOrder);
|
||||
|
||||
if ($currentGroupIndex >= $updateGroupIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user