- Timestamp:
- 2013/07/20 16:19:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/class/helper/SC_Helper_TaxRule.php
r22927 r22976 129 129 $pref_id = $pref_id > 0 ? $pref_id : 0; 130 130 $country_id = $country_id > 0 ? $country_id : 0; 131 132 $objCustomer = new SC_Customer_Ex(); 133 if ($objCustomer->isLoginSuccess(true)) { 134 if ($country_id == 0) { 135 $objCustomer->getValue('country_id'); 131 // ログイン済み会員で国と地域指定が無い場合は、会員情報をデフォルトで利用。管理画面では利用しない 132 if (!(defined('ADMIN_FUNCTION') && ADMIN_FUNCTION == true)) { 133 $objCustomer = new SC_Customer_Ex(); 134 if ($objCustomer->isLoginSuccess(true)) { 135 if ($country_id == 0) { 136 $country_id = $objCustomer->getValue('country_id'); 137 } 138 if ($pref_id == 0) { 139 $pref_id = $objCustomer->getValue('pref'); 140 } 136 141 } 137 if ($pref_id == 0) { 138 $objCustomer->getValue('pref'); 139 } 140 } 141 142 // リクエストの配列化 143 $arrRequest = array('product_id' => $product_id, 144 'product_class_id' => $product_class_id, 145 'pref_id' => $pref_id, 146 'country_id' => $country_id); 147 148 // 地域設定を優先するが、システムパラメーターなどに設定を持っていくか 149 // 後に書いてあるほど優先される、詳細後述MEMO参照 150 $arrPriorityKeys = array('product_id', 'product_class_id', 'pref_id', 'country_id'); // TODO: パラメーター設定に持っていく 151 $cache_key = "$product_id,$product_class_id,$pref_id,$country_id"; 142 } 143 144 // 一覧画面の速度向上のため商品単位税率設定がOFFの時はキャッシュキーを丸めてしまう 145 if (OPTION_PRODUCT_TAX_RULE == 1) { 146 $cache_key = "$product_id,$product_class_id,$pref_id,$country_id"; 147 } else { 148 $cache_key = "$pref_id,$country_id"; 149 } 152 150 153 151 // 複数回呼出があるのでキャッシュ化 … … 156 154 if (empty($data_c[$cache_key])) { 157 155 $arrRet = array(); 156 // リクエストの配列化 157 $arrRequest = array('product_id' => $product_id, 158 'product_class_id' => $product_class_id, 159 'pref_id' => $pref_id, 160 'country_id' => $country_id); 161 162 // 地域設定を優先するが、システムパラメーターなどに設定を持っていくか 163 // 後に書いてあるほど優先される、詳細後述MEMO参照 164 $arrPriorityKeys = explode(',', TAX_RULE_PRIORITY); 158 165 159 166 // 条件に基づいて税の設定情報を取得 160 167 $objQuery =& SC_Query_Ex::getSingletonInstance(); 161 168 $table = 'dtb_tax_rule'; 162 $cols = '* , CASE WHEN apply_date IS NULL THEN 1 ELSE 0 END as nullorder';169 $cols = '*'; 163 170 $where = '((product_id = 0 OR product_id = ?)' 164 171 . ' OR (product_class_id = 0 OR product_class_id = ?))' 165 172 . ' AND (pref_id = 0 OR pref_id = ?)' 166 173 . ' AND (country_id = 0 OR country_id = ?)' 167 . ' AND (apply_date < CURRENT_TIMESTAMP OR apply_date IS NULL)'174 . ' AND apply_date < CURRENT_TIMESTAMP' 168 175 . ' AND del_flg = 0'; 169 176 170 177 $arrVal = array($product_id, $product_class_id, $pref_id, $country_id); 171 $order = ' nullorder ASC,apply_date DESC';178 $order = 'apply_date DESC'; 172 179 $objQuery->setOrder($order); 173 180 $arrData = $objQuery->select($cols, $table, $where, $arrVal); … … 176 183 // キーの優先度により、利用する税設定を判断する 177 184 // 優先度が同等の場合、適用日付で判断する 178 179 // XXXX: ビット演算で優先順位を判断という雑な事してます。すいません180 185 foreach ($arrData as $data_key => $data) { 181 186 $res = 0; … … 197 202 } 198 203 } 204 // XXXX: 互換性のためtax_ruleにもcalc_ruleを設定 205 $arrRet['tax_rule'] = $arrRet['calc_rule']; 199 206 $data_c[$cache_key] = $arrRet; 200 207 } 201 208 209 GC_Utils_Ex::gfDebugLog('tax_key=' . $cache_key . ' result_tax=' . print_r($data_c[$cache_key],true)); 202 210 return $data_c[$cache_key]; 203 211 } … … 217 225 { 218 226 // 基本設定を取得 219 $arrRet = SC_Helper_taxRule_Ex::getTaxRule(); 227 $arrRet = SC_Helper_TaxRule_Ex::getTaxRule($product_id, $product_class_id); 228 220 229 // 基本設定の消費税率と一緒であれば設定しない 221 230 if( $arrRet['tax_rate'] != $tax_rate ) { 222 231 // 課税規則は基本設定のものを使用 223 232 $calc_rule = $arrRet['calc_rule']; 233 // 日付は登録時点を設定 234 $apply_date = date('Y/m/d H:i:s'); 224 235 // 税情報を設定 225 236 SC_Helper_TaxRule_Ex::setTaxRule($calc_rule, $tax_rate, $apply_date, $tax_rule_id=NULL, $tax_adjust=0, $product_id, $product_class_id, $pref_id, $country_id); … … 280 291 } 281 292 $table = 'dtb_tax_rule'; 282 // 適用日時順に更新293 // 適用日時順に更新 283 294 $objQuery->setOrder('apply_date DESC'); 284 295 $arrRet = $objQuery->select($col, $table, $where);
Note: See TracChangeset
for help on using the changeset viewer.
