<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
 * 회원글관련 스케쥴
 */
class cron02 extends CI_Controller {
    #---------------------------------------------------------------------------
    # PURPOSE :	좋아요수 셋팅해놓은 갯수 이상이면 배댓
    # CREATE  :	2018-05-14
    #---------------------------------------------------------------------------
    function best_comment_update() {

        if (!is_dir('./logs/cron02/'.date("Ym")))   mkdir('./logs/cron02/'.date("Ym"), 0777, TRUE);

        # file helper
        $this->load->helper('file');
        $contents = '['.date("Y-m-d H:i:s").'] best_comment_update start'.chr(10);


        # model
        $this->load->model('admin/comm/m_comment');
        $this->m_comment->comment_is_best_all_update();

        $this->load->model('admin/setting/m_comment_setting');
        $arr_comment_setting    = $this->m_comment_setting->comment_setting_list();
        foreach ($arr_comment_setting as $val) {
            $req_data = array();
            $req_data['content_type']   = $val['setting_type'];
            $req_data['like_count']     = $val['best_comment_like_count'];
            $req_data['limit']          = $val['max_best_comment_count'];

            $this->m_comment->comment_is_best_update($req_data);

        }

        $contents.= '['.date("Y-m-d H:i:s").'] best_comment_update end'.chr(10);
        $contents.= '-------------------------------------------------------------------------------------'.chr(10);
        write_file('./logs/cron02/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');


	}

	#---------------------------------------------------------------------------
    # PURPOSE :	블라인드 처리
    # CREATE  :	2018-05-14
    #---------------------------------------------------------------------------
	function blind_update() {

	    if (!is_dir('./logs/cron02/'.date("Ym")))   mkdir('./logs/cron02/'.date("Ym"), 0777, TRUE);

        # file helper
        $this->load->helper('file');
        $contents = '['.date("Y-m-d H:i:s").'] blind_update start'.chr(10);

	    $now_date = date("Y-m-d H:i:s");
	    $this->load->model('admin/setting/m_comment_setting');
	    $this->load->model('admin/setting/m_blind');
	    $this->load->model('admin/comm/m_comment');
	    $this->load->model('admin/comm/m_spam');
        $arr_comment_setting    = $this->m_comment_setting->comment_setting_list();
        foreach ($arr_comment_setting as $val) {

            if($val['block_call_type']=='1'){   // 블라인드
                $blind_comment = $val['block_blind_conent'];
                $blind_code ='2';
            } else if($val['block_call_type']=='2'){    // 자동삭제
                $blind_comment = $val['block_del_conent'];
                $blind_code ='3';
            }

            $req_data = array();
            $req_data['content_type']       = $val['setting_type'];
            $req_data['block_call_count']   = $val['block_call_count'];

            $arr_blind_list = $this->m_spam->spam_where_block_list($req_data);

            if(count($arr_blind_list) > 0) {
                foreach ($arr_blind_list as $val2) {

                    $arr_comment = $this->m_comment->comment_select($val2['comment_idx']);

                    if($arr_comment['comment_status']!='1')    continue;

                    $req_data = array();
                    $req_data['comment_status']     = $blind_code;
                    $req_data['comment']            = $blind_comment;
                    $req_data['comment_org']        = $arr_comment['comment'];
                    $req_data['update_id']          = 'system';
                    $req_data['update_date']        = $now_date;
                    $req_data['del_date']           = $now_date;
                    $req_data['idx']                = $val2['comment_idx'];

                    $this->m_comment->comment_update($req_data);

                    $req_data = array();
                    $req_data['blind_type']         = '1';
                    $req_data['content_type']       = $val['setting_type'];
                    $req_data['content_idx']        = $arr_comment['content_idx'];
                    $req_data['comment_idx']        = $val2['comment_idx'];
                    $req_data['blind_id']           = $arr_comment['write_id'];
                    $req_data['blind_name']         = $arr_comment['write_name'];
                    $req_data['blind_comment']      = $arr_comment['comment'];
                    $req_data['blind_status']       = '1';
                    $req_data['reg_id']             = 'system';
                    $req_data['reg_date']           = $now_date;
                    $req_data['update_id']          = 'system';
                    $req_data['update_date']        = $now_date;

                    $this->m_blind->blind_insert($req_data);
                    $this->m_spam->spam_is_blind_where_comment_idx_update($val2['comment_idx']);


                }
            }


        }

        $contents.= '['.date("Y-m-d H:i:s").'] blind_update end'.chr(10);
        $contents.= '-------------------------------------------------------------------------------------'.chr(10);
        write_file('./logs/cron02/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');



	}

	#---------------------------------------------------------------------------
    # PURPOSE :	블라인드 제재처리
    # CREATE  :	2018-05-14
    #---------------------------------------------------------------------------
	function blind_limit_update() {

	    if (!is_dir('./logs/cron02/'.date("Ym")))   mkdir('./logs/cron02/'.date("Ym"), 0777, TRUE);

        # file helper
        $this->load->helper('file');
        $contents = '['.date("Y-m-d H:i:s").'] blind_limit_update start'.chr(10);

	    $this->load->model('admin/setting/m_blind');
	    $this->load->model('admin/member/m_member');
	    $this->load->model('admin/setting/m_blind_setting');
	    $this->load->model('admin/setting/m_blind_limit');
        $arr_blind_setting    = $this->m_blind_setting->blind_setting_list();


        foreach ($arr_blind_setting as $val) {

            if($val['limit_count']==0)  continue;

            $req_data = array();
            $req_data['cnt']                = $val['limit_count'];

            $arr_blind_list    = $this->m_blind->blind_group_by_count_list($req_data);

            if(count($arr_blind_list)>0) {
                foreach ($arr_blind_list as $val2){
                    $arr_member    = $this->m_member->member_where_member_id_select($val2['blind_id']);
                    $member_name = ''; $member_email = '';
                    if(isset($arr_member['member_name'])==true) {
                        $member_name    = $arr_member['member_name'];
                        $member_email   = $arr_member['member_email'];
                    }

                    $now_date = date("Y-m-d H:i:s");
                    if($val['limit_status'] == '2') {
                        $end_date = $now_date;
                    } else {
                        $end_date = date("Y-m-d H:i:s", strtotime("+".$val['limit_day']." days"));
                    }

                    $req_data = array();
                    $req_data['member_id']              = $val2['blind_id'];
                    $req_data['member_name']            = $member_name;
                    $req_data['limit_type']             = $val['limit_type'];
                    $req_data['limit_status']           = $val['limit_status'];
                    $req_data['limit_day']              = $val['limit_day'];
                    $req_data['start_date']             = $now_date;
                    $req_data['end_date']               = $end_date;
                    $req_data['reg_id']                 = 'system';
                    $req_data['reg_date']               = $now_date;
                    $req_data['update_id']              = 'system';
                    $req_data['update_date']            = $now_date;
                    $req_data['blind_setting_idx']      = $val['idx'];

                    $this->m_blind_limit->blind_limit_insert($req_data);

                    // 제제 완료 처리 update
                    $req_data = array();
                    $req_data['member_id']          = $val2['blind_id'];
                    $req_data['cnt']                = $val['limit_count'];

                    $this->m_blind->blind_group_by_count_update($req_data);

                    $req_data = array();
                    $req_data['limit_content']          = $val['limit_content'];
                    $req_data['limit_count']            = $val['limit_count'];
                    $req_data['member_email']           = $member_email;
                    $req_data['member_id']              = $val2['blind_id'];
                    $req_data['limit_type']             = $val['limit_type'];
                    $req_data['end_date']               = $end_date;
                    $req_data['member_name']            = $member_name;

                    $this->load->library('comm_admin');
                    $this->comm_admin->fn_blind_limit_proc($req_data);



                }

            }

        }

        $contents.= '['.date("Y-m-d H:i:s").'] blind_limit_update end'.chr(10);
        $contents.= '-------------------------------------------------------------------------------------'.chr(10);
        write_file('./logs/cron02/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');



	}
    
}

?>