[15618] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15618] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[15618] | 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * メール関連 のヘルパークラス. |
---|
| 26 | * |
---|
| 27 | * @package Helper |
---|
| 28 | * @author LOCKON CO.,LTD. |
---|
| 29 | * @version $Id$ |
---|
| 30 | */ |
---|
[22567] | 31 | class SC_Helper_Mail |
---|
| 32 | { |
---|
[15618] | 33 | |
---|
| 34 | /** メールテンプレートのパス */ |
---|
| 35 | var $arrMAILTPLPATH; |
---|
| 36 | |
---|
| 37 | /** |
---|
[21820] | 38 | * LC_Pageオブジェクト. |
---|
| 39 | * |
---|
| 40 | * @var LC_Page |
---|
| 41 | */ |
---|
| 42 | protected $objPage; |
---|
| 43 | |
---|
| 44 | /** |
---|
[15618] | 45 | * コンストラクタ. |
---|
| 46 | */ |
---|
[22567] | 47 | function __construct() |
---|
| 48 | { |
---|
[15618] | 49 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[21481] | 50 | $this->arrMAILTPLPATH = $masterData->getMasterData('mtb_mail_tpl_path'); |
---|
[19773] | 51 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
[15618] | 52 | } |
---|
| 53 | |
---|
[21820] | 54 | /** |
---|
| 55 | * LC_Pageオブジェクトをセットします. |
---|
| 56 | * |
---|
| 57 | * @param LC_Page $objPage |
---|
| 58 | */ |
---|
[22567] | 59 | function setPage(LC_Page $objPage) |
---|
| 60 | { |
---|
[21820] | 61 | $this->objPage = $objPage; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | * LC_Pageオブジェクトを返します. |
---|
| 66 | * |
---|
| 67 | * @return LC_Page |
---|
| 68 | */ |
---|
[22567] | 69 | function getPage() |
---|
| 70 | { |
---|
[21820] | 71 | return $this->objPage; |
---|
| 72 | } |
---|
[21829] | 73 | |
---|
[15618] | 74 | /* DBに登録されたテンプレートメールの送信 */ |
---|
[22567] | 75 | function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = '', $from_name = '', $reply_to = '', $bcc = '') |
---|
| 76 | { |
---|
[15618] | 77 | |
---|
| 78 | // メールテンプレート情報の取得 |
---|
[22584] | 79 | $objMailtemplate = new SC_Helper_Mailtemplate_Ex(); |
---|
| 80 | $mailtemplate = $objMailtemplate->get($template_id); |
---|
| 81 | $objPage->tpl_header = $mailtemplate['header']; |
---|
| 82 | $objPage->tpl_footer = $mailtemplate['footer']; |
---|
| 83 | $tmp_subject = $mailtemplate['subject']; |
---|
[15618] | 84 | |
---|
[20459] | 85 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 86 | |
---|
[20306] | 87 | $objMailView = new SC_SiteView_Ex(); |
---|
[21820] | 88 | $objMailView->setPage($this->getPage()); |
---|
[15618] | 89 | // メール本文の取得 |
---|
| 90 | $objMailView->assignobj($objPage); |
---|
[15622] | 91 | $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]); |
---|
[15618] | 92 | |
---|
| 93 | // メール送信処理 |
---|
[16503] | 94 | $objSendMail = new SC_SendMail_Ex(); |
---|
[21514] | 95 | if ($from_address == '') $from_address = $arrInfo['email03']; |
---|
| 96 | if ($from_name == '') $from_name = $arrInfo['shop_name']; |
---|
| 97 | if ($reply_to == '') $reply_to = $arrInfo['email03']; |
---|
[15618] | 98 | $error = $arrInfo['email04']; |
---|
[20469] | 99 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[20540] | 100 | |
---|
[20962] | 101 | $objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error, $bcc); |
---|
[15618] | 102 | $objSendMail->setTo($to, $to_name); |
---|
[16181] | 103 | $objSendMail->sendMail(); // メール送信 |
---|
[15618] | 104 | } |
---|
| 105 | |
---|
| 106 | /* 受注完了メール送信 */ |
---|
[22567] | 107 | function sfSendOrderMail($order_id, $template_id, $subject = '', $header = '', $footer = '', $send = true) |
---|
| 108 | { |
---|
[15618] | 109 | |
---|
[19749] | 110 | $arrTplVar = new stdClass(); |
---|
[20459] | 111 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[19749] | 112 | $arrTplVar->arrInfo = $arrInfo; |
---|
[15618] | 113 | |
---|
[21750] | 114 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[15618] | 115 | |
---|
[21515] | 116 | if ($subject == '' && $header == '' && $footer == '') { |
---|
[15618] | 117 | // メールテンプレート情報の取得 |
---|
[22584] | 118 | $objMailtemplate = new SC_Helper_Mailtemplate_Ex(); |
---|
| 119 | $mailtemplate = $objMailtemplate->get($template_id); |
---|
| 120 | $arrTplVar->tpl_header = $mailtemplate['header']; |
---|
| 121 | $arrTplVar->tpl_footer = $mailtemplate['footer']; |
---|
| 122 | $tmp_subject = $mailtemplate['subject']; |
---|
[15618] | 123 | } else { |
---|
[19749] | 124 | $arrTplVar->tpl_header = $header; |
---|
| 125 | $arrTplVar->tpl_footer = $footer; |
---|
[15618] | 126 | $tmp_subject = $subject; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // 受注情報の取得 |
---|
[21833] | 130 | $where = 'order_id = ? AND del_flg = 0'; |
---|
| 131 | $arrOrder = $objQuery->getRow('*', 'dtb_order', $where, array($order_id)); |
---|
| 132 | |
---|
| 133 | if (empty($arrOrder)) { |
---|
| 134 | trigger_error("該当する受注が存在しない。(注文番号: $order_id)", E_USER_ERROR); |
---|
| 135 | } |
---|
| 136 | |
---|
[21514] | 137 | $where = 'order_id = ?'; |
---|
[20435] | 138 | $objQuery->setOrder('order_detail_id'); |
---|
[21514] | 139 | $arrTplVar->arrOrderDetail = $objQuery->select('*', 'dtb_order_detail', $where, array($order_id)); |
---|
[15618] | 140 | |
---|
[20487] | 141 | $objProduct = new SC_Product_Ex(); |
---|
[19978] | 142 | $objQuery->setOrder('shipping_id'); |
---|
[21515] | 143 | $arrRet = $objQuery->select('*', 'dtb_shipping', 'order_id = ?', array($order_id)); |
---|
[21935] | 144 | foreach ($arrRet as $key => $value) { |
---|
[19978] | 145 | $objQuery->setOrder('shipping_id'); |
---|
[21515] | 146 | $arrItems = $objQuery->select('*', 'dtb_shipment_item', 'order_id = ? AND shipping_id = ?', |
---|
[19978] | 147 | array($order_id, $arrRet[$key]['shipping_id'])); |
---|
[21927] | 148 | foreach ($arrItems as $arrDetail) { |
---|
[19978] | 149 | foreach ($arrDetail as $detailKey => $detailVal) { |
---|
| 150 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | $arrTplVar->arrShipping = $arrRet; |
---|
| 157 | |
---|
[19749] | 158 | $arrTplVar->Message_tmp = $arrOrder['message']; |
---|
[15618] | 159 | |
---|
[20953] | 160 | // 会員情報の取得 |
---|
[15618] | 161 | $customer_id = $arrOrder['customer_id']; |
---|
[19978] | 162 | $objQuery->setOrder('customer_id'); |
---|
[21515] | 163 | $arrRet = $objQuery->select('point', 'dtb_customer', 'customer_id = ?', array($customer_id)); |
---|
[21514] | 164 | $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : ''; |
---|
[15618] | 165 | |
---|
[19749] | 166 | $arrTplVar->arrCustomer = $arrCustomer; |
---|
| 167 | $arrTplVar->arrOrder = $arrOrder; |
---|
[15618] | 168 | |
---|
| 169 | //その他決済情報 |
---|
[21514] | 170 | if ($arrOrder['memo02'] != '') { |
---|
[15618] | 171 | $arrOther = unserialize($arrOrder['memo02']); |
---|
| 172 | |
---|
[21441] | 173 | foreach ($arrOther as $other_key => $other_val) { |
---|
[21514] | 174 | if (SC_Utils_Ex::sfTrim($other_val['value']) == '') { |
---|
| 175 | $arrOther[$other_key]['value'] = ''; |
---|
[15618] | 176 | } |
---|
| 177 | } |
---|
| 178 | |
---|
[19749] | 179 | $arrTplVar->arrOther = $arrOther; |
---|
[15618] | 180 | } |
---|
| 181 | |
---|
| 182 | // 都道府県変換 |
---|
[19978] | 183 | $arrTplVar->arrPref = $this->arrPref; |
---|
[15618] | 184 | |
---|
[20490] | 185 | $objCustomer = new SC_Customer_Ex(); |
---|
[19749] | 186 | $arrTplVar->tpl_user_point = $objCustomer->getValue('point'); |
---|
[15618] | 187 | |
---|
[21820] | 188 | $objMailView = null; |
---|
[21527] | 189 | if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { |
---|
[20306] | 190 | $objMailView = new SC_MobileView_Ex(); |
---|
[21527] | 191 | } else { |
---|
[20306] | 192 | $objMailView = new SC_SiteView_Ex(); |
---|
[21527] | 193 | } |
---|
[15618] | 194 | // メール本文の取得 |
---|
[21820] | 195 | $objMailView->setPage($this->getPage()); |
---|
[19749] | 196 | $objMailView->assignobj($arrTplVar); |
---|
[15622] | 197 | $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]); |
---|
[15618] | 198 | |
---|
| 199 | // メール送信処理 |
---|
[16503] | 200 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 201 | $bcc = $arrInfo['email01']; |
---|
| 202 | $from = $arrInfo['email03']; |
---|
| 203 | $error = $arrInfo['email04']; |
---|
[20469] | 204 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[15618] | 205 | |
---|
| 206 | $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
[21515] | 207 | $objSendMail->setTo($arrOrder['order_email'], $arrOrder['order_name01'] . ' '. $arrOrder['order_name02'] .' 様'); |
---|
[15618] | 208 | |
---|
| 209 | // 送信フラグ:trueの場合は、送信する。 |
---|
[21441] | 210 | if ($send) { |
---|
[15618] | 211 | if ($objSendMail->sendMail()) { |
---|
[15622] | 212 | $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body); |
---|
[15618] | 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | return $objSendMail; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | // テンプレートを使用したメールの送信 |
---|
[22567] | 220 | function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) |
---|
| 221 | { |
---|
[20306] | 222 | $objMailView = new SC_SiteView_Ex(); |
---|
[21820] | 223 | $objMailView->setPage($this->getPage()); |
---|
[20459] | 224 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 225 | // メール本文の取得 |
---|
| 226 | $objPage->tpl_shopname=$arrInfo['shop_name']; |
---|
| 227 | $objPage->tpl_infoemail = $arrInfo['email02']; |
---|
| 228 | $objMailView->assignobj($objPage); |
---|
| 229 | $body = $objMailView->fetch($tplpath); |
---|
| 230 | // メール送信処理 |
---|
[16503] | 231 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 232 | $bcc = $arrInfo['email01']; |
---|
| 233 | $from = $arrInfo['email03']; |
---|
| 234 | $error = $arrInfo['email04']; |
---|
[20469] | 235 | $tosubject = $this->sfMakeSubject($tmp_subject, $objMailView); |
---|
[20540] | 236 | |
---|
[17590] | 237 | $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
[15618] | 238 | $objSendMail->sendMail(); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | // 通常のメール送信 |
---|
[22567] | 242 | function sfSendMail($to, $tmp_subject, $body) |
---|
| 243 | { |
---|
[20459] | 244 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[15618] | 245 | // メール送信処理 |
---|
[16503] | 246 | $objSendMail = new SC_SendMail_Ex(); |
---|
[15618] | 247 | $bcc = $arrInfo['email01']; |
---|
| 248 | $from = $arrInfo['email03']; |
---|
| 249 | $error = $arrInfo['email04']; |
---|
[17590] | 250 | $tosubject = $this->sfMakeSubject($tmp_subject); |
---|
[20540] | 251 | |
---|
[17590] | 252 | $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc); |
---|
[15618] | 253 | $objSendMail->sendMail(); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | //件名にテンプレートを用いる |
---|
[22567] | 257 | function sfMakeSubject($subject, &$objMailView) |
---|
| 258 | { |
---|
[20469] | 259 | if (empty($objMailView)) { |
---|
| 260 | $objMailView = new SC_SiteView_Ex(); |
---|
[21820] | 261 | $objMailView->setPage($this->getPage()); |
---|
[20469] | 262 | } |
---|
[17590] | 263 | $objTplAssign = new stdClass; |
---|
[20540] | 264 | |
---|
[20469] | 265 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[17590] | 266 | $objTplAssign->tpl_shopname=$arrInfo['shop_name']; |
---|
| 267 | $objTplAssign->tpl_infoemail=$subject; // 従来互換 |
---|
| 268 | $objTplAssign->tpl_mailtitle=$subject; |
---|
| 269 | $objMailView->assignobj($objTplAssign); |
---|
| 270 | $subject = $objMailView->fetch('mail_templates/mail_title.tpl'); |
---|
[22029] | 271 | // #1940 (SC_Helper_Mail#sfMakeSubject 先頭に改行を含む値を返す) 対応 |
---|
| 272 | $subject = trim($subject); |
---|
[17590] | 273 | return $subject; |
---|
[15618] | 274 | } |
---|
| 275 | |
---|
| 276 | // メール配信履歴への登録 |
---|
[22567] | 277 | function sfSaveMailHistory($order_id, $template_id, $subject, $body) |
---|
| 278 | { |
---|
[21927] | 279 | $sqlval = array(); |
---|
[15618] | 280 | $sqlval['subject'] = $subject; |
---|
| 281 | $sqlval['order_id'] = $order_id; |
---|
| 282 | $sqlval['template_id'] = $template_id; |
---|
[21185] | 283 | $sqlval['send_date'] = 'CURRENT_TIMESTAMP'; |
---|
[21515] | 284 | if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = ''; |
---|
[21514] | 285 | if ($_SESSION['member_id'] != '') { |
---|
[15618] | 286 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
| 287 | } else { |
---|
| 288 | $sqlval['creator_id'] = '0'; |
---|
| 289 | } |
---|
| 290 | $sqlval['mail_body'] = $body; |
---|
| 291 | |
---|
[21750] | 292 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21481] | 293 | $sqlval['send_id'] = $objQuery->nextVal('dtb_mail_history_send_id'); |
---|
| 294 | $objQuery->insert('dtb_mail_history', $sqlval); |
---|
[15618] | 295 | } |
---|
| 296 | |
---|
[16588] | 297 | /* 会員登録があるかどうかのチェック(仮会員を含まない) */ |
---|
[22567] | 298 | function sfCheckCustomerMailMaga($email) |
---|
| 299 | { |
---|
[21514] | 300 | $col = 'email, mailmaga_flg, customer_id'; |
---|
[21481] | 301 | $from = 'dtb_customer'; |
---|
[21514] | 302 | $where = '(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0'; |
---|
[21750] | 303 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[15618] | 304 | $arrRet = $objQuery->select($col, $from, $where, array($email)); |
---|
| 305 | // 会員のメールアドレスが登録されている |
---|
[21441] | 306 | if (!empty($arrRet[0]['customer_id'])) { |
---|
[15618] | 307 | return true; |
---|
| 308 | } |
---|
| 309 | return false; |
---|
| 310 | } |
---|
[20160] | 311 | |
---|
| 312 | /** |
---|
| 313 | * 登録メールを送信する。 |
---|
| 314 | * |
---|
[20953] | 315 | * @param string $secret_key 会員固有キー |
---|
[21419] | 316 | * @param integer $customer_id 会員ID |
---|
[20642] | 317 | * @param boolean $is_mobile false(default):PCアドレスにメールを送る true:携帯アドレスにメールを送る |
---|
[20160] | 318 | * @return boolean true:成功 false:失敗 |
---|
| 319 | */ |
---|
[22567] | 320 | function sfSendRegistMail($secret_key, $customer_id = '', $is_mobile = false) |
---|
| 321 | { |
---|
[20953] | 322 | // 会員データの取得 |
---|
[21441] | 323 | if (SC_Utils_Ex::sfIsInt($customer_id)) { |
---|
[20160] | 324 | $arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
[21441] | 325 | } else { |
---|
[21514] | 326 | $arrCustomerData = SC_Helper_Customer_Ex::sfGetCustomerDataFromId('', 'secret_key = ?', array($secret_key)); |
---|
[20160] | 327 | } |
---|
[21441] | 328 | if (SC_Utils_Ex::isBlank($arrCustomerData)) { |
---|
[20160] | 329 | return false; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | $CONF = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
[20540] | 333 | |
---|
[20306] | 334 | $objMailText = new SC_SiteView_Ex(); |
---|
[21820] | 335 | $objMailText->setPage($this->getPage()); |
---|
[20538] | 336 | $objMailText->assign('CONF', $CONF); |
---|
[21481] | 337 | $objMailText->assign('name01', $arrCustomerData['name01']); |
---|
| 338 | $objMailText->assign('name02', $arrCustomerData['name02']); |
---|
[20538] | 339 | $objMailText->assign('uniqid', $arrCustomerData['secret_key']); |
---|
[20160] | 340 | $objMailText->assignobj($arrCustomerData); |
---|
| 341 | $objMailText->assignobj($this); |
---|
| 342 | |
---|
| 343 | $objHelperMail = new SC_Helper_Mail_Ex(); |
---|
| 344 | |
---|
| 345 | // 仮会員が有効の場合 |
---|
[21441] | 346 | if (CUSTOMER_CONFIRM_MAIL == true and $arrCustomerData['status'] == 1) { |
---|
[20469] | 347 | $subject = $objHelperMail->sfMakeSubject('会員登録のご確認', $objMailText); |
---|
[21514] | 348 | $toCustomerMail = $objMailText->fetch('mail_templates/customer_mail.tpl'); |
---|
[20160] | 349 | } else { |
---|
[20469] | 350 | $subject = $objHelperMail->sfMakeSubject('会員登録のご完了', $objMailText); |
---|
[21514] | 351 | $toCustomerMail = $objMailText->fetch('mail_templates/customer_regist_mail.tpl'); |
---|
[20160] | 352 | } |
---|
| 353 | |
---|
[21950] | 354 | $objMail = new SC_SendMail_Ex(); |
---|
[20160] | 355 | $objMail->setItem( |
---|
| 356 | '' // 宛先 |
---|
| 357 | , $subject // サブジェクト |
---|
| 358 | , $toCustomerMail // 本文 |
---|
[21481] | 359 | , $CONF['email03'] // 配送元アドレス |
---|
| 360 | , $CONF['shop_name'] // 配送元 名前 |
---|
| 361 | , $CONF['email03'] // reply_to |
---|
| 362 | , $CONF['email04'] // return_path |
---|
| 363 | , $CONF['email04'] // Errors_to |
---|
| 364 | , $CONF['email01'] // Bcc |
---|
[20160] | 365 | ); |
---|
| 366 | // 宛先の設定 |
---|
[21441] | 367 | if ($is_mobile) { |
---|
[21481] | 368 | $to_addr = $arrCustomerData['email_mobile']; |
---|
[21441] | 369 | } else { |
---|
[20538] | 370 | $to_addr = $arrCustomerData['email']; |
---|
[20160] | 371 | } |
---|
[21515] | 372 | $objMail->setTo($to_addr, $arrCustomerData['name01'] . $arrCustomerData['name02'] .' 様'); |
---|
[20160] | 373 | |
---|
| 374 | $objMail->sendMail(); |
---|
| 375 | return true; |
---|
| 376 | } |
---|
[20540] | 377 | |
---|
[20198] | 378 | /** |
---|
[20357] | 379 | * 保存されているメルマガテンプレートの取得 |
---|
[20203] | 380 | * @param integer 特定IDのテンプレートを取り出したい時はtemplate_idを指定。未指定時は全件取得 |
---|
[20198] | 381 | * @return array メールテンプレート情報を格納した配列 |
---|
| 382 | * @todo 表示順も引数で変更できるように |
---|
| 383 | */ |
---|
[22567] | 384 | function sfGetMailmagaTemplate($template_id = null) |
---|
| 385 | { |
---|
[20198] | 386 | // 初期化 |
---|
| 387 | $where = ''; |
---|
[20507] | 388 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20540] | 389 | |
---|
[20198] | 390 | // 条件文 |
---|
| 391 | $where = 'del_flg = ?'; |
---|
| 392 | $arrValues[] = 0; |
---|
| 393 | //template_id指定時 |
---|
[20203] | 394 | if (SC_Utils_Ex::sfIsInt($template_id) === true) { |
---|
[20642] | 395 | $where .= ' AND template_id = ?'; |
---|
[20203] | 396 | $arrValues[] = $template_id; |
---|
[20198] | 397 | } |
---|
[20540] | 398 | |
---|
[20198] | 399 | // 表示順 |
---|
[21514] | 400 | $objQuery->setOrder('create_date DESC'); |
---|
[20540] | 401 | |
---|
[20198] | 402 | $arrResults = $objQuery->select('*', 'dtb_mailmaga_template', $where, $arrValues); |
---|
| 403 | return $arrResults; |
---|
| 404 | } |
---|
[20540] | 405 | |
---|
[20205] | 406 | /** |
---|
[20357] | 407 | * 保存されているメルマガ送信履歴の取得 |
---|
[20205] | 408 | * @param integer 特定の送信履歴を取り出したい時はsend_idを指定。未指定時は全件取得 |
---|
| 409 | * @return array 送信履歴情報を格納した配列 |
---|
| 410 | */ |
---|
[22567] | 411 | function sfGetSendHistory($send_id = null) |
---|
| 412 | { |
---|
[20205] | 413 | // 初期化 |
---|
| 414 | $where = ''; |
---|
[20507] | 415 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20540] | 416 | |
---|
[20205] | 417 | // 条件文 |
---|
| 418 | $where = 'del_flg = ?'; |
---|
| 419 | $arrValues[] = 0; |
---|
[20540] | 420 | |
---|
[20205] | 421 | //send_id指定時 |
---|
| 422 | if (SC_Utils_Ex::sfIsInt($send_id) === true) { |
---|
[20642] | 423 | $where .= ' AND send_id = ?'; |
---|
[20205] | 424 | $arrValues[] = $send_id; |
---|
| 425 | } |
---|
[20540] | 426 | |
---|
[20205] | 427 | // 表示順 |
---|
[21514] | 428 | $objQuery->setOrder('create_date DESC'); |
---|
[20540] | 429 | |
---|
[20205] | 430 | $arrResults = $objQuery->select('*', 'dtb_send_history', $where, $arrValues); |
---|
| 431 | return $arrResults; |
---|
| 432 | } |
---|
[20357] | 433 | |
---|
| 434 | /** |
---|
| 435 | * 指定したIDのメルマガ配送を行う |
---|
[20642] | 436 | * |
---|
[20357] | 437 | * @param integer $send_id dtb_send_history の情報 |
---|
[20361] | 438 | * @return void |
---|
[20357] | 439 | */ |
---|
[22567] | 440 | function sfSendMailmagazine($send_id) |
---|
| 441 | { |
---|
[20507] | 442 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20357] | 443 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 444 | $objSite = $objDb->sfGetBasisData(); |
---|
| 445 | $objMail = new SC_SendMail_Ex(); |
---|
[20540] | 446 | |
---|
[20357] | 447 | $where = 'del_flg = 0 AND send_id = ?'; |
---|
| 448 | $arrMail = $objQuery->getRow('*', 'dtb_send_history', $where, array($send_id)); |
---|
| 449 | |
---|
| 450 | // 対象となる$send_idが見つからない |
---|
[20361] | 451 | if (SC_Utils_Ex::isBlank($arrMail)) return; |
---|
[20357] | 452 | |
---|
| 453 | // 送信先リストの取得 |
---|
| 454 | $arrDestinationList = $objQuery->select( |
---|
| 455 | '*', |
---|
| 456 | 'dtb_send_customer', |
---|
| 457 | 'send_id = ? AND (send_flag = 2 OR send_flag IS NULL)', |
---|
| 458 | array($send_id) |
---|
| 459 | ); |
---|
[20540] | 460 | |
---|
[20357] | 461 | // 現在の配信数 |
---|
| 462 | $complete_count = $arrMail['complete_count']; |
---|
[21684] | 463 | if (SC_Utils_Ex::isBlank($arrMail)) { |
---|
| 464 | $complete_count = 0; |
---|
| 465 | } |
---|
[20540] | 466 | |
---|
[20357] | 467 | foreach ($arrDestinationList as $arrDestination) { |
---|
| 468 | |
---|
[20953] | 469 | // お名前の変換 |
---|
[20538] | 470 | $customerName = trim($arrDestination['name']); |
---|
[21514] | 471 | $subjectBody = preg_replace('/{name}/', $customerName, $arrMail['subject']); |
---|
| 472 | $mailBody = preg_replace('/{name}/', $customerName, $arrMail['body']); |
---|
[20357] | 473 | |
---|
| 474 | $objMail->setItem( |
---|
[20538] | 475 | $arrDestination['email'], |
---|
[20357] | 476 | $subjectBody, |
---|
| 477 | $mailBody, |
---|
[21481] | 478 | $objSite['email03'], // 送信元メールアドレス |
---|
| 479 | $objSite['shop_name'], // 送信元名 |
---|
| 480 | $objSite['email03'], // reply_to |
---|
| 481 | $objSite['email04'], // return_path |
---|
| 482 | $objSite['email04'] // errors_to |
---|
[20357] | 483 | ); |
---|
[20540] | 484 | |
---|
[20357] | 485 | // テキストメール配信の場合 |
---|
[21481] | 486 | if ($arrMail['mail_method'] == 2) { |
---|
[20357] | 487 | $sendResut = $objMail->sendMail(); |
---|
| 488 | // HTMLメール配信の場合 |
---|
| 489 | } else { |
---|
| 490 | $sendResut = $objMail->sendHtmlMail(); |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | // 送信完了なら1、失敗なら2をメール送信結果フラグとしてDBに挿入 |
---|
| 494 | if (!$sendResut) { |
---|
| 495 | $sendFlag = '2'; |
---|
| 496 | } else { |
---|
| 497 | // 完了を 1 増やす |
---|
| 498 | $sendFlag = '1'; |
---|
| 499 | $complete_count++; |
---|
| 500 | } |
---|
[20540] | 501 | |
---|
[20357] | 502 | // 送信結果情報を更新 |
---|
| 503 | $objQuery->update('dtb_send_customer', |
---|
| 504 | array('send_flag'=>$sendFlag), |
---|
| 505 | 'send_id = ? AND customer_id = ?', |
---|
[21481] | 506 | array($send_id,$arrDestination['customer_id'])); |
---|
[20357] | 507 | } |
---|
| 508 | |
---|
| 509 | // メール全件送信完了後の処理 |
---|
[20361] | 510 | $objQuery->update('dtb_send_history', |
---|
[21185] | 511 | array('end_date'=>'CURRENT_TIMESTAMP', 'complete_count'=>$complete_count), |
---|
[20361] | 512 | 'send_id = ?', |
---|
| 513 | array($send_id)); |
---|
[20357] | 514 | |
---|
| 515 | // 送信完了 報告メール |
---|
[21514] | 516 | $compSubject = date('Y年m月d日H時i分') . ' 下記メールの配信が完了しました。'; |
---|
[20357] | 517 | // 管理者宛に変更 |
---|
[21481] | 518 | $objMail->setTo($objSite['email03']); |
---|
[20357] | 519 | $objMail->setSubject($compSubject); |
---|
| 520 | |
---|
| 521 | // テキストメール配信の場合 |
---|
[21481] | 522 | if ($arrMail['mail_method'] == 2) { |
---|
[20357] | 523 | $sendResut = $objMail->sendMail(); |
---|
| 524 | // HTMLメール配信の場合 |
---|
| 525 | } else { |
---|
| 526 | $sendResut = $objMail->sendHtmlMail(); |
---|
| 527 | } |
---|
[20361] | 528 | return; |
---|
[20357] | 529 | } |
---|
[15618] | 530 | } |
---|