public function __construct($array, $mode = '')
 {
     $pmode = $mode;
     if ($mode == "delete_in_customer") {
         $pmode = "customer";
     }
     parent::__construct($array, $pmode);
     if ($mode == "delete_in_customer") {
         strpos($this->where, ' del_flg = 0 ');
         // 先頭の del_flg = 0 を全ての条件に変える
         $this->where = preg_replace('/^ del_flg = 0 /', ' del_flg IS NOT NULL ', $this->where);
     }
     $objDb = new SC_Helper_DB_Ex();
     // query 構築用
     $objQuery = SC_Query_Ex::getSingletonInstance();
     GC_Utils_Ex::gfPrintLog(print_r($this->arrSql, true), DB_LOG_REALFILE);
     $having = "";
     if (count($this->arrSql["search_status"]) == 1) {
         switch ($this->arrSql["search_status"][0]) {
             case 1:
                 $having = "MIN(del_flg) = 1";
                 break;
             case 2:
                 $having = "MIN(del_flg) = 0";
                 break;
         }
     }
     $dt = "cp_dtb_customer_docomo_mymenu";
     $at = "cp_dtb_customer_transaction";
     $d = $objDb->sfColumnExists($dt, "customer_id");
     $a = $objDb->sfColumnExists($at, "customer_id");
     $objQuery->setGroupBy("customer_id");
     if ($having) {
         $objQuery->setOption("HAVING {$having}");
     }
     $where = PHP_EOL;
     $where .= "CASE " . PHP_EOL;
     $where .= "   WHEN 1 = 0 THEN FALSE " . PHP_EOL;
     // 自動構築時に特定条件で使えなくなることを防ぐ
     if ($d) {
         $sub_where = " payment_type IN ( 'USER1','USER10','USER12','USER3')";
         // 都度課金を除く
         if ($this->strlen('search_docomo_site_id') > 0) {
             $sub_where .= " AND site_id = ?";
             $this->arrVal[] = $this->arrSql['search_docomo_site_id'];
         }
         if ($this->strlen('search_course') > 0) {
             $sub_where .= " AND price = ?";
             $this->arrVal[] = intval($this->arrSql['search_course']);
         }
         $where .= "WHEN carrier = 1 THEN " . PHP_EOL;
         // docomo
         $where .= sprintf("     customer_id IN (%s) " . PHP_EOL, $objQuery->getSql("customer_id", $dt, $sub_where));
     }
     if ($a) {
         $sub_where = "continue_account_id IS NOT NULL";
         if ($this->strlen('search_docomo_site_id') > 0) {
             // サイト ID を指定した場合は 検索対象から除外
             $sub_where .= " AND FALSE ";
         }
         if ($this->strlen('search_course') > 0) {
             $sub_where .= " AND amount = ?";
             $this->arrVal[] = intval($this->arrSql['search_course']);
         }
         $where .= "WHEN carrier = 2 THEN " . PHP_EOL;
         // au-kddi
         $where .= sprintf("     customer_id IN (%s) " . PHP_EOL, $objQuery->getSql("customer_id", $at, $sub_where));
     }
     $where .= "ELSE FALSE END" . PHP_EOL;
     $this->setWhere($where);
     unset($where);
     $objQuery->setGroupBy("");
     $objQuery->setOption("");
     // 有効なメルマガ会員か本登録ユーザー
     $where = "CASE WHEN email LIKE ? THEN TRUE ELSE mailmaga_flg <> 3 END " . PHP_EOL;
     $this->arrVal[] = $this->addSearchStr("@" . $_SERVER['SERVER_NAME']);
     $this->setWhere($where);
     if ($this->is_array("search_customer_type")) {
         switch ($this->sum("search_customer_type")) {
             case "1":
                 $this->setWhere('mailmaga_flg = 3');
                 break;
             case "2":
                 $this->setWhere('mailmaga_flg <> 3');
                 break;
         }
     }
     if ($this->strlen("search_point")) {
         $this->setWhere('point >= ? ' . PHP_EOL);
         $this->arrVal[] = intval($this->arrSql['search_point']);
     }
     // carrier
     if ($this->strlen("search_carrier")) {
         $this->setWhere(' carrier = ? ' . PHP_EOL);
         $this->arrVal[] = intval($this->arrSql['search_carrier']);
     } else {
     }
     if ($mode == 'customer') {
         // 登録日を示すカラム
         $regdate_col = 'dtb_customer.update_date DESC';
         $this->setOrder($regdate_col);
     } elseif ($mode == 'DuplicateSiteId') {
         if (SC_Helper_DB::sfColumnExists("cp_dtb_customer_docomo_mymenu", "customer_id")) {
             $arrPaymentType = array("USER1", "USER10", "USER12");
             $this->arrVal = array_merge($this->arrVal, $arrPaymentType);
             $objSql = new SC_SelectSql();
             $objSql->setWhere("del_flg = 0");
             $objSql->setItemTerm($arrPaymentType, "payment_type");
             $objSql->setSelect("SELECT customer_id FROM cp_dtb_customer_docomo_mymenu ");
             $objSql->setGroup("customer_id HAVING count(site_id) > 1");
             $inquery = $objSql->getSql(2);
             $this->setWhere("customer_id IN ({$inquery})");
         }
         $regdate_col = 'dtb_customer.customer_id DESC';
         $this->setOrder($regdate_col);
     }
 }
 /**
  * 開始行番号, 行数を指定して管理者データを取得する.
  *
  * @access private
  * @param integer $startno 開始行番号
  * @return array 管理者データの連想配列
  */
 function getMemberData($startno)
 {
     $objSql = new SC_SelectSql();
     $objSql->setSelect("SELECT member_id,name,department,login_id,authority,rank,work FROM dtb_member");
     $objSql->setOrder("rank DESC");
     $objSql->setWhere("del_flg <> 1 AND member_id <> " . ADMIN_ID);
     $objSql->setLimitOffset(MEMBER_PMAX, $startno);
     $objQuery = new SC_Query();
     $arrMemberData = $objQuery->getAll($objSql->getSql());
     return $arrMemberData;
 }
 /**
  * ポイント履歴集計
  */
 public function lfGetCustmoerPointHistory($type, $sdate, $edate)
 {
     $objQuery = SC_Query_Ex::getSingletonInstance();
     list($where, $arrWhereVal) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
     $objSql = new SC_SelectSql();
     $objSql->setWhere($where);
     if (is_numeric($_REQUEST["search_customer_id"])) {
         $arrWhereVal[] = intval($_REQUEST["search_customer_id"]);
         $objSql->setWhere("customer_id = ? ");
     }
     // いずれかのポイントが 0 出ない場合出力する
     $objSql->setWhereByOR(array(array("column" => "NOT add_point", "value" => 0), array("column" => "NOT use_point", "value" => 0), array("column" => "NOT lost_point", "value" => 0)));
     $where = $objSql->getWhere(false);
     switch ($type) {
         case 'month':
             $xtitle = '(月別)';
             $ytitle = '(ポイント)';
             $db_format = 'YYYY-MM';
             $db_format2 = 'YYYY-MM';
             break;
         case 'year':
             $xtitle = '(年別)';
             $ytitle = '(ポイント)';
             $db_format = 'YYYY';
             $db_format2 = 'YYYY';
             break;
         case 'wday':
             $xtitle = '(曜日別)';
             $ytitle = '(ポイント)';
             $db_format = 'Dy';
             $db_format2 = 'ID';
             break;
         case 'hour':
             $xtitle = '(時間別)';
             $ytitle = '(ポイント)';
             $db_format = 'HH24';
             $db_format2 = 'HH24';
             break;
         default:
             $xtitle = '(日別)';
             $ytitle = '(ポイント)';
             $db_format = 'YYYY-MM-DD';
             $db_format2 = 'YYYY-MM-DD';
             $xincline = true;
             break;
     }
     $col = "\n    TO_CHAR(create_date, '{$db_format}')        AS str_date,\n    TO_CHAR(create_date, '{$db_format2}')       AS str_date2,\n    COUNT(*)                                  AS total_history,\n    SUM(add_point)                            AS add_point,\n    SUM(use_point)                            AS use_point,\n    SUM(lost_point)                           AS lost_point,\n    SUM(use_point + lost_point)               AS minus_point,\n    SUM(add_point - (use_point + lost_point)) AS total\n";
     $objQuery->setGroupBy('str_date,str_date2');
     $objQuery->setOrder('str_date2');
     // 検索結果の取得
     $arrTotalResults = $objQuery->select($col, 'cp_dtb_point_history', $where, $arrWhereVal);
     $arrTotalResults = is_array($arrTotalResults) ? $arrTotalResults : array();
     $arrTotalResults = $this->lfAddBlankLine($arrTotalResults, $type, $sdate, $edate);
     // todo GDない場合の処理
     $tpl_image = $this->lfGetGraphLine($arrTotalResults, 'str_date', 'term_' . $type, $xtitle, $ytitle, $sdate, $edate, $xincline);
     GC_Utils_Ex::gfDebugLog($tpl_image);
     $this->xtitle = $xtitle;
     $arrCsvResults = $arrTotalResults;
     if ($this->getMode() != "csv") {
         $arrTotalResults[] = array("str_date" => "合計", "total_history" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'total_history')), "add_point" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'add_point')), "use_point" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'use_point')), "lost_point" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'lost_point')), "minus_point" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'minus_point')), "total" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'total')), "total_history_sum" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'total_history')), "total_sum" => array_sum(SC_Utils_Ex::sfArrKeyValue($arrTotalResults, "str_date", 'total')));
     }
     return array($arrTotalResults, $tpl_image, $arrCsvResults);
 }