| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* [̾¾Î] SC_CustomerList |
|---|
| 4 | * [³µÍ×] ²ñ°÷¸¡º÷ÍÑ¥¯¥é¥¹ |
|---|
| 5 | */ |
|---|
| 6 | class SC_CustomerList extends SC_SelectSql { |
|---|
| 7 | |
|---|
| 8 | var $arrColumnCSV; |
|---|
| 9 | |
|---|
| 10 | function SC_CustomerList($array, $mode = '') { |
|---|
| 11 | parent::SC_SelectSql($array); |
|---|
| 12 | |
|---|
| 13 | if($mode == "") { |
|---|
| 14 | // ²ñ°÷ËÜÅÐÏ¿²ñ°÷¤Çºï½ü¤·¤Æ¤¤¤Ê¤¤²ñ°÷ |
|---|
| 15 | $this->setWhere("status = 2 AND delete = 0 "); |
|---|
| 16 | // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à |
|---|
| 17 | $regdate_col = 'dtb_customer.update_date'; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | if($mode == "customer") { |
|---|
| 21 | // ´ÉÍý¼Ô¥Ú¡¼¥¸¸ÜµÒ¸¡º÷¤Î¾ì¹ç²¾ÅÐÏ¿²ñ°÷¤â¸¡º÷ |
|---|
| 22 | $this->setWhere( "(status = 1 OR status = 2) AND delete = 0 "); |
|---|
| 23 | // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à |
|---|
| 24 | $regdate_col = 'dtb_customer.update_date'; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | // ¥á¡¼¥ë¥Þ¥¬¥¸¥ó¤Î¾ì¹ç |
|---|
| 28 | if($mode == "magazine") { |
|---|
| 29 | $this->setWhere("(delete = 0 OR delete IS NULL)"); |
|---|
| 30 | |
|---|
| 31 | if(is_array($this->arrSql['customer'])) { |
|---|
| 32 | $tmp_where = ""; |
|---|
| 33 | foreach($this->arrSql['customer'] as $val) { |
|---|
| 34 | if($tmp_where != "") { |
|---|
| 35 | $tmp_where.= " OR "; |
|---|
| 36 | } |
|---|
| 37 | switch($val) { |
|---|
| 38 | // ²ñ°÷ |
|---|
| 39 | case '1': |
|---|
| 40 | $tmp_where.= "status = 2"; |
|---|
| 41 | break; |
|---|
| 42 | // ¥á¥ë¥Þ¥¬ÅÐÏ¿ |
|---|
| 43 | case '2': |
|---|
| 44 | $tmp_where.= "customer_id IS NULL"; |
|---|
| 45 | break; |
|---|
| 46 | // CSVÅÐÏ¿ |
|---|
| 47 | case '3': |
|---|
| 48 | $tmp_where.= "customer_id IS NULL"; |
|---|
| 49 | break; |
|---|
| 50 | default: |
|---|
| 51 | $tmp_where = ""; |
|---|
| 52 | break; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | if($tmp_where != "") { |
|---|
| 56 | $tmp_where = "(" . $tmp_where . ")"; |
|---|
| 57 | } |
|---|
| 58 | $this->setWhere($tmp_where); |
|---|
| 59 | } |
|---|
| 60 | // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à |
|---|
| 61 | $regdate_col = 'dtb_customer_mail.create_date'; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | // ¸ÜµÒID |
|---|
| 65 | if ( strlen($this->arrSql['customer_id']) > 0 ) { |
|---|
| 66 | $this->setWhere( "customer_id = ?" ); |
|---|
| 67 | $this->arrVal[] = $this->arrSql['customer_id']; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | // ̾Á° |
|---|
| 71 | if ( strlen($this->arrSql['name']) > 0 ) { |
|---|
| 72 | $this->setWhere("(name01 || name02 LIKE ?)" ); |
|---|
| 73 | $searchName = $this->addSearchStr($this->arrSql['name']); |
|---|
| 74 | $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchName); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | //¡¡Ì¾Á°¡Ê¥«¥Ê¡Ë |
|---|
| 78 | if ( strlen($this->arrSql['kana']) > 0 ) { |
|---|
| 79 | $this->setWhere("(kana01 || kana02 LIKE ?)"); |
|---|
| 80 | $searchKana = $this->addSearchStr($this->arrSql['kana']); |
|---|
| 81 | $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchKana); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | //¡¡ÅÔÆ»Éܸ© |
|---|
| 85 | if ( strlen($this->arrSql['pref']) > 0 ) { |
|---|
| 86 | $this->setWhere( "pref = ?" ); |
|---|
| 87 | $this->arrVal[] = $this->arrSql['pref']; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | //¡¡ÅÅÏÃÈÖ¹æ |
|---|
| 91 | if ( is_numeric( $this->arrSql['tel'] ) ) { |
|---|
| 92 | $this->setWhere( "(tel01 || tel02 || tel03 LIKE ?)" ); |
|---|
| 93 | $searchTel = $this->addSearchStr($this->arrSql['tel']); |
|---|
| 94 | $this->arrVal[] = ereg_replace("-", "", $searchTel); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | //¡¡ÀÊÌ |
|---|
| 98 | if ( is_array( $this->arrSql['sex'] ) ){ |
|---|
| 99 | $arrSexVal = $this->setItemTerm( $this->arrSql['sex'] ,"sex" ); |
|---|
| 100 | foreach ($arrSexVal as $data) { |
|---|
| 101 | $this->arrVal[] = $data; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | //¡¡¿¦¶È |
|---|
| 106 | if ( is_array( $this->arrSql['job'] ) ){ |
|---|
| 107 | if ( in_array("ÉÔÌÀ", $this->arrSql['job'] ) ) { |
|---|
| 108 | $arrJobVal = $this->setItemTermWithNull( $this->arrSql['job'] ,"job" ); |
|---|
| 109 | } else { |
|---|
| 110 | $arrJobVal = $this->setItemTerm( $this->arrSql['job'] ,"job" ); |
|---|
| 111 | } |
|---|
| 112 | if (is_array($arrJobVal)) { |
|---|
| 113 | foreach ($arrJobVal as $data) { |
|---|
| 114 | $this->arrVal[] = $data; |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | //¡¡E-MAIL |
|---|
| 120 | if (strlen($this->arrSql['email']) > 0) { |
|---|
| 121 | //¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊ£¿ô¤Î¾ò·ï»ØÄê²Äǽ¤Ë |
|---|
| 122 | $this->arrSql['email'] = explode(",", $this->arrSql['email']); |
|---|
| 123 | $sql_where = ""; |
|---|
| 124 | foreach($this->arrSql['email'] as $val) { |
|---|
| 125 | $val = trim($val); |
|---|
| 126 | //¸¡º÷¾ò·ï¤ò´Þ¤Þ¤Ê¤¤ |
|---|
| 127 | if($this->arrSql['not_emailinc'] == '1') { |
|---|
| 128 | if($sql_where == "") { |
|---|
| 129 | $sql_where .= "email NOT ILIKE ? "; |
|---|
| 130 | } else { |
|---|
| 131 | $sql_where .= "AND email NOT ILIKE ? "; |
|---|
| 132 | } |
|---|
| 133 | } else { |
|---|
| 134 | if($sql_where == "") { |
|---|
| 135 | $sql_where .= "email ILIKE ? "; |
|---|
| 136 | } else { |
|---|
| 137 | $sql_where .= "OR email ILIKE ? "; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | $searchEmail = $this->addSearchStr($val); |
|---|
| 141 | $this->arrVal[] = $searchEmail; |
|---|
| 142 | } |
|---|
| 143 | $this->setWhere($sql_where); |
|---|
| 144 | } |
|---|
| 145 | //¡¡HTML-mail |
|---|
| 146 | if ( $mode == 'magazine' ){ |
|---|
| 147 | if ( strlen($this->arrSql['htmlmail']) > 0 ) { |
|---|
| 148 | $this->setWhere( " mail_flag = ? "); |
|---|
| 149 | $this->arrVal[] = $this->arrSql['htmlmail']; |
|---|
| 150 | } else { |
|---|
| 151 | $this->setWhere( " (mail_flag = 1 or mail_flag = 2) "); |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | // ¹ØÆþ¶â³Û»ØÄê |
|---|
| 156 | if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) { |
|---|
| 157 | $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total"); |
|---|
| 158 | foreach ($arrBuyTotal as $data1) { |
|---|
| 159 | $this->arrVal[] = $data1; |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | // ¹ØÆþ²ó¿ô»ØÄê |
|---|
| 164 | if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) { |
|---|
| 165 | $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times"); |
|---|
| 166 | foreach ($arrBuyTimes as $data2) { |
|---|
| 167 | $this->arrVal[] = $data2; |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | // ÃÂÀ¸Æü´ü´Ö»ØÄê |
|---|
| 172 | if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) || |
|---|
| 173 | strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) { |
|---|
| 174 | |
|---|
| 175 | $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day'] |
|---|
| 176 | , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth"); |
|---|
| 177 | if (is_array($arrBirth)) { |
|---|
| 178 | foreach ($arrBirth as $data3) { |
|---|
| 179 | $this->arrVal[] = $data3; |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | // ÃÂÀ¸·î¤Î¸¡º÷ |
|---|
| 185 | if (is_numeric($this->arrSql["birth_month"])) { |
|---|
| 186 | $this->setWhere(" EXTRACT(month from birth) = ?"); |
|---|
| 187 | $this->arrVal[] = $this->arrSql["birth_month"]; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | // ÅÐÏ¿´ü´Ö»ØÄê |
|---|
| 191 | if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) || |
|---|
| 192 | (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) { |
|---|
| 193 | |
|---|
| 194 | $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day'] |
|---|
| 195 | , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col); |
|---|
| 196 | if (is_array($arrRegistTime)) { |
|---|
| 197 | foreach ($arrRegistTime as $data4) { |
|---|
| 198 | $this->arrVal[] = $data4; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | // ºÇ½ª¹ØÆþÆü»ØÄê |
|---|
| 204 | if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) || |
|---|
| 205 | (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) { |
|---|
| 206 | $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day'] |
|---|
| 207 | , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date"); |
|---|
| 208 | if (is_array($arrRegistTime)) { |
|---|
| 209 | foreach ($arrRegistTime as $data4) { |
|---|
| 210 | $this->arrVal[] = $data4; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | //¹ØÆþ¾¦ÉÊ¥³¡¼¥É |
|---|
| 216 | if ( strlen($this->arrSql['buy_product_code']) > 0 ) { |
|---|
| 217 | $this->setWhere( "customer_id IN (SELECT customer_id FROM dtb_order WHERE order_id IN (SELECT order_id FROM dtb_order_detail WHERE product_code LIKE ? ))"); |
|---|
| 218 | $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']); |
|---|
| 219 | $this->arrVal[] = $search_buyproduct_code; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | //¹ØÆþ¾¦ÉÊ̾¾Î |
|---|
| 223 | if ( strlen($this->arrSql['buy_product_name']) > 0 ) { |
|---|
| 224 | $this->setWhere( "customer_id IN (SELECT customer_id FROM dtb_order WHERE order_id IN (SELECT order_id FROM dtb_order_detail WHERE product_name LIKE ? ))"); |
|---|
| 225 | $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']); |
|---|
| 226 | $this->arrVal[] = $search_buyproduct_name; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | //¥«¥Æ¥´¥ê¡¼¤òÁªÂò¤·¤Æ¤¤¤ë¾ì¹ç¤Î¤ß¹Ê¹þ¸¡º÷¤ò¹Ô¤¦ |
|---|
| 230 | if ( strlen($this->arrSql['category_id']) != ""){ |
|---|
| 231 | //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¸¡º÷¤ò¹Ô¤¦SQLʸÀ¸À® |
|---|
| 232 | list($tmp_where, $tmp_arrval) = sfGetCatWhere(sfManualEscape($this->arrSql['category_id'])); |
|---|
| 233 | |
|---|
| 234 | //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¤ß¤¬²Äǽ¤Î¾ì¹ç |
|---|
| 235 | if($tmp_where != "") { |
|---|
| 236 | $this->setWhere( " customer_id IN (SELECT distinct customer_id FROM dtb_order WHERE order_id IN (SELECT distinct order_id FROM dtb_order_detail WHERE product_id IN (SELECT product_id FROM dtb_products WHERE ".$tmp_where." ))) "); |
|---|
| 237 | $this->arrVal = array_merge($this->arrVal, $tmp_arrval); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | //¡¡·ÈÂÓÅÅÏÃÈÖ¹æ |
|---|
| 241 | if ( is_numeric( $this->arrSql['cell'] ) ) { |
|---|
| 242 | $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" ); |
|---|
| 243 | $searchTel = $this->addSearchStr($this->arrSql['cell']); |
|---|
| 244 | $this->arrVal[] = ereg_replace("-", "", $searchTel); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | $this->setOrder( "customer_id DESC" ); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | // ¸¡º÷ÍÑSQL |
|---|
| 251 | function getList() { |
|---|
| 252 | $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer "; |
|---|
| 253 | return $this->getSql(0); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | function getListMailMagazine() { |
|---|
| 257 | $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref, mail_flag FROM dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)"; |
|---|
| 258 | return $this->getSql(0); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | function getListMailMagazineCount() { |
|---|
| 262 | $this->select = "SELECT COUNT(*) FROM dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)"; |
|---|
| 263 | return $this->getSql(0); |
|---|
| 264 | } |
|---|
| 265 | //¹ØÆþ¾¦ÉÊ¥³¡¼¥É¸¡º÷ÍÑSQL |
|---|
| 266 | function getBuyList(){ |
|---|
| 267 | $this->select = "SELECT A.customer_id, A.name01, A.name02, A.kana01, A.kana02, A.sex, A.email, A.tel01, A.tel02, A.tel03, A.pref, A.mail_flag, B.order_email, B.order_id, C.product_code |
|---|
| 268 | FROM (dtb_customer LEFT OUTER JOIN dtb_customer_mail USING (email)) AS A LEFT OUTER JOIN dtb_order AS B ON |
|---|
| 269 | A.email=B.order_email LEFT OUTER JOIN dtb_order_detail AS C ON B.order_id = C.order_id"; |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | //¡¡¸¡º÷Áí¿ô¥«¥¦¥ó¥ÈÍÑSQL |
|---|
| 273 | function getListCount() { |
|---|
| 274 | $this->select = "SELECT COUNT (customer_id) FROM dtb_customer "; |
|---|
| 275 | return $this->getSql(1); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | //¡¡CSV¥À¥¦¥ó¥í¡¼¥ÉÍÑSQL |
|---|
| 279 | function getListCSV($arrColumnCSV) { |
|---|
| 280 | $this->arrColumnCSV = $arrColumnCSV; |
|---|
| 281 | $i = 0; |
|---|
| 282 | foreach ($this->arrColumnCSV as $val) { |
|---|
| 283 | if ($i != 0) $state .= ", "; |
|---|
| 284 | $state .= $val["sql"]; |
|---|
| 285 | $i ++; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | $this->select = "SELECT " .$state. " FROM dtb_customer "; |
|---|
| 289 | return $this->getSql(2); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | function getWhere() { |
|---|
| 293 | return array($this->where, $this->arrVal); |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | ?> |
|---|