Changeset 18609 for tmp/version-2_5-test/data/class/helper/SC_Helper_DB.php
- Timestamp:
- 2010/03/11 10:35:11 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tmp/version-2_5-test/data/class/helper/SC_Helper_DB.php
r18562 r18609 96 96 * @param bool $add カラムの作成も行う場合 true 97 97 * @return bool カラムが存在する場合とカラムの生成に成功した場合 true, 98 * 99 * 98 * テーブルが存在しない場合 false, 99 * 引数 $add == false でカラムが存在しない場合 false 100 100 */ 101 101 function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) { … … 142 142 * @param bool $add インデックスの生成もする場合 true 143 143 * @return bool インデックスが存在する場合とインデックスの生成に成功した場合 true, 144 * 145 * 144 * テーブルが存在しない場合 false, 145 * 引数 $add == false でインデックスが存在しない場合 false 146 146 */ 147 147 function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) { … … 201 201 * 店舗基本情報を取得する. 202 202 * 203 * @param boolean $force 強制的にDB取得するか 203 204 * @return array 店舗基本情報の配列 204 205 */ 205 function sf_getBasisData() { 206 $objQuery = new SC_Query(); 207 $arrRet = $objQuery->select('*', 'dtb_baseinfo'); 208 209 if (isset($arrRet[0])) return $arrRet[0]; 210 211 return array(); 206 function sf_getBasisData($force = false) { 207 static $data; 208 209 if ($force || !isset($data)) { 210 $objQuery = new SC_Query(); 211 $arrRet = $objQuery->select('*', 'dtb_baseinfo'); 212 213 if (isset($arrRet[0])) { 214 $data = $arrRet[0]; 215 } else { 216 $data = array(); 217 } 218 } 219 220 return $data; 212 221 } 213 222 … … 215 224 function sfGetRootId() { 216 225 217 if(!$this->g_root_on) 226 if(!$this->g_root_on) { 218 227 $this->g_root_on = true; 219 228 $objQuery = new SC_Query(); … … 241 250 * 242 251 * @param array $arrID 規格ID 252 * @param boolean $includePrivateProducts 非公開商品を含むか 243 253 * @return array 規格情報の配列 244 254 */ 245 function sfGetProductsClass($arrID ) {255 function sfGetProductsClass($arrID, $includePrivateProducts = false) { 246 256 list($product_id, $classcategory_id1, $classcategory_id2) = $arrID; 247 257 248 if ($classcategory_id1 == "") {258 if (strlen($classcategory_id1) == 0) { 249 259 $classcategory_id1 = '0'; 250 260 } 251 if ($classcategory_id2 == "") {261 if (strlen($classcategory_id2) == 0) { 252 262 $classcategory_id2 = '0'; 253 263 } … … 255 265 // 商品規格取得 256 266 $objQuery = new SC_Query(); 257 $col = "product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit, sale_unlimited"; 258 $table = "vw_product_class AS prdcls"; 259 $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ? AND status = 1"; 260 $objQuery->setorder("rank1 DESC, rank2 DESC"); 267 $col = 'product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit'; 268 $table = 'vw_product_class AS prdcls'; 269 $where = 'product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?'; 270 if (!$includePrivateProducts) { 271 $where .= ' AND status = 1'; 272 } 261 273 $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2)); 262 274 return $arrRet[0]; … … 280 292 * カート内商品の集計処理を行う. 281 293 * 294 * 管理機能での利用は想定していないので注意。(非公開商品は除外される。) 295 * 282 296 * @param LC_Page $objPage ページクラスのインスタンス 283 297 * @param SC_CartSession $objCartSess カートセッションのインスタンス 284 * @param array $arrInfo 商品情報の配列298 * @param null $dummy1 互換性確保用(決済モジュール互換のため) 285 299 * @return LC_Page 集計処理後のページクラスインスタンス 286 300 */ 287 function sfTotalCart(&$objPage, $objCartSess, $ arrInfo) {301 function sfTotalCart(&$objPage, $objCartSess, $dummy1 = null) { 288 302 289 303 // 規格名一覧 … … 292 306 $arrClassCatName = $this->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 293 307 294 $objPage->tpl_total_pretax = 0; // 費用合計(税込み) 295 $objPage->tpl_total_tax = 0; // 消費税合計 296 if (USE_POINT === true) { 297 $objPage->tpl_total_point = 0; // ポイント合計 298 } 308 $objPage->tpl_total_pretax = 0; // 費用合計(税込み) 309 $objPage->tpl_total_tax = 0; // 消費税合計 310 $objPage->tpl_total_point = 0; // ポイント合計 299 311 300 312 // カート内情報の取得 301 $arrCart = $objCartSess->getCartList(); 302 $max = count($arrCart); 313 $arrQuantityInfo_by_product = array(); 303 314 $cnt = 0; 304 305 for ($i = 0; $i < $max; $i++) { 315 foreach ($objCartSess->getCartList() as $arrCart) { 306 316 // 商品規格情報の取得 307 $arrData = $this->sfGetProductsClass($arrCart[ $i]['id']);308 $limit = "";317 $arrData = $this->sfGetProductsClass($arrCart['id']); 318 $limit = null; 309 319 // DBに存在する商品 310 320 if (count($arrData) > 0) { 311 321 312 322 // 購入制限数を求める。 313 if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') { 314 if($arrData['sale_limit'] < $arrData['stock']) { 315 $limit = $arrData['sale_limit']; 323 if ($arrData['stock_unlimited'] != '1' && SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { 324 $limit = min($arrData['sale_limit'], $arrData['stock']); 325 } elseif (SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { 326 $limit = $arrData['sale_limit']; 327 } elseif ($arrData['stock_unlimited'] != '1') { 328 $limit = $arrData['stock']; 329 } 330 331 if (!is_null($limit) && $arrCart['quantity'] > $limit) { 332 if ($limit > 0) { 333 // カート内商品数を制限に合わせる 334 $objCartSess->setProductValue($arrCart['id'], 'quantity', $limit); 335 $quantity = $limit; 336 $objPage->tpl_message .= "※「" . $arrData['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n"; 316 337 } else { 317 // 購入制限数を在庫数に318 #$limit = $arrData['stock'];319 // 購入制限数をSALE_LIMIT_MAXに320 $limit = SALE_LIMIT_MAX;338 // 売り切れ商品をカートから削除する 339 $objCartSess->delProduct($arrCart['cart_no']); 340 $objPage->tpl_message .= "※「" . $arrData['name'] . "」は売り切れました。\n"; 341 break; 321 342 } 322 343 } else { 323 if ($arrData['sale_unlimited'] != '1') { 324 $limit = $arrData['sale_limit']; 325 } 326 if ($arrData['stock_unlimited'] != '1') { 327 // 購入制限数を在庫数に 328 #$limit = $arrData['stock']; 329 // 購入制限数をSALE_LIMIT_MAXに 330 $limit = SALE_LIMIT_MAX; 331 } 344 $quantity = $arrCart['quantity']; 332 345 } 333 346 334 if($limit != "" && $limit < $arrCart[$i]['quantity']) { 335 // カート内商品数を制限に合わせる 336 $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit); 337 $quantity = $limit; 338 $objPage->tpl_message = "※「" . $arrData['name'] . "」は販売制限しております、一度にこれ以上の購入はできません。"; 339 } else { 340 $quantity = $arrCart[$i]['quantity']; 341 } 347 // (商品規格単位でなく)商品単位での評価のための準備 348 $product_id = $arrCart['id'][0]; 349 $arrQuantityInfo_by_product[$product_id]['quantity'] += $quantity; 350 $arrQuantityInfo_by_product[$product_id]['sale_limit'] = $arrData['sale_limit']; 351 $arrQuantityInfo_by_product[$product_id]['name'] = $arrData['name']; 342 352 343 353 $objPage->arrProductsClass[$cnt] = $arrData; 344 354 $objPage->arrProductsClass[$cnt]['quantity'] = $quantity; 345 $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[ $i]['cart_no'];355 $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart['cart_no']; 346 356 $objPage->arrProductsClass[$cnt]['class_name1'] = 347 357 isset($arrClassName[$arrData['class_id1']]) … … 358 368 $arrClassCatName[$arrData['classcategory_id2']]; 359 369 360 // 画像サイズ361 $main_image_path = IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]);362 if(file_exists($main_image_path)) {363 list($image_width, $image_height) = getimagesize($main_image_path);364 } else {365 $image_width = 0;366 $image_height = 0;367 }368 369 $objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;370 $objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;371 370 // 価格の登録 372 371 if ($arrData['price02'] != "") { 373 $objCartSess->setProductValue($arrCart[ $i]['id'], 'price', $arrData['price02']);372 $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price02']); 374 373 $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02']; 375 374 } else { 376 $objCartSess->setProductValue($arrCart[ $i]['id'], 'price', $arrData['price01']);375 $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price01']); 377 376 $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01']; 378 377 } 379 378 // ポイント付与率の登録 380 if (USE_POINT === true) {381 $objCartSess->setProductValue($arrCart[ $i]['id'], 'point_rate', $arrData['point_rate']);379 if (USE_POINT !== false) { 380 $objCartSess->setProductValue($arrCart['id'], 'point_rate', $arrData['point_rate']); 382 381 } 383 382 // 商品ごとの合計金額 384 $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arr Info, $arrCart[$i]['id']);383 $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrCart['id']); 385 384 // 送料の合計を計算する 386 $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[ $i]['quantity']);385 $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart['quantity']); 387 386 $cnt++; 388 } else { // DBに商品が見つからない場合 はカート商品の削除389 $objPage->tpl_message .= "※ 申し訳ございませんが、ご購入の直前で売り切れた商品があります。該当商品をカートから削除いたしました。\n";387 } else { // DBに商品が見つからない場合、 388 $objPage->tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n"; 390 389 // カート商品の削除 391 $objCartSess->delProductKey('id', $arrCart[$i]['id']); 390 $objCartSess->delProduct($arrCart['cart_no']); 391 } 392 } 393 394 foreach ($arrQuantityInfo_by_product as $product_id => $quantityInfo) { 395 if (SC_Utils_Ex::sfIsInt($quantityInfo['sale_limit']) && $quantityInfo['quantity'] > $quantityInfo['sale_limit']) { 396 $objPage->tpl_error = "※「{$quantityInfo['name']}」は数量「{$quantityInfo['sale_limit']}」以下に販売制限しております。一度にこれ以上の購入はできません。\n"; 397 // 販売制限に引っかかった商品をマークする 398 foreach (array_keys($objPage->arrProductsClass) as $key) { 399 $ProductsClass =& $objPage->arrProductsClass[$key]; 400 if ($ProductsClass['product_id'] == $product_id) { 401 $ProductsClass['error'] = true; 402 } 403 } 392 404 } 393 405 } 394 406 395 407 // 全商品合計金額(税込み) 396 $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal( $arrInfo);408 $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal(); 397 409 // 全商品合計消費税 398 $objPage->tpl_total_tax = $objCartSess->getAllProductsTax( $arrInfo);410 $objPage->tpl_total_tax = $objCartSess->getAllProductsTax(); 399 411 // 全商品合計ポイント 400 if (USE_POINT === true) {412 if (USE_POINT !== false) { 401 413 $objPage->tpl_total_point = $objCartSess->getAllProductsPoint(); 402 414 } … … 427 439 $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); 428 440 } 441 442 // 受注_Tempテーブルの名称列を更新 443 // ・決済モジュールに対応するため、static メソッドとして扱う 444 SC_Helper_DB_Ex::sfUpdateOrderNameCol($uniqid, true); 429 445 } 430 446 } … … 504 520 505 521 //-- 編集登録実行 506 $objQuery->begin();507 522 $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); 508 $objQuery->commit();509 523 } 510 524 … … 521 535 $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); 522 536 $customer_id = $arrRet[0]['customer_id']; 523 if ($customer_id != "" && $customer_id >= 1) {524 if (USE_POINT === true) {537 if ($customer_id != "" && $customer_id >= 1) { 538 if (USE_POINT !== false) { 525 539 $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); 526 540 $point = $arrRet[0]['point']; 527 541 $total_point = $arrRet[0]['point'] - $use_point + $add_point; 528 542 } else { 529 $total_point = "";530 $point = "";543 $total_point = 0; 544 $point = 0; 531 545 } 532 546 } else { 533 $total_point = 0;534 $point = 0;547 $total_point = ""; 548 $point = ""; 535 549 } 536 550 return array($point, $total_point); … … 547 561 function sfGetCustomerPointFromCid($customer_id, $use_point, $add_point) { 548 562 $objQuery = new SC_Query(); 549 if (USE_POINT === true) {550 551 552 563 if (USE_POINT !== false) { 564 $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); 565 $point = $arrRet[0]['point']; 566 $total_point = $arrRet[0]['point'] - $use_point + $add_point; 553 567 } else { 554 568 $total_point = 0; … … 676 690 677 691 /** 692 * 指定したカテゴリーIDのカテゴリーを取得する. 693 * 694 * @param integer $category_id カテゴリID 695 * @return array 指定したカテゴリーIDのカテゴリー 696 */ 697 function sfGetCat($category_id){ 698 $objQuery = new SC_Query(); 699 700 // カテゴリーを取得する 701 $arrVal = array($category_id); 702 $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal); 703 704 return $res[0]; 705 } 706 707 /** 678 708 * 指定したカテゴリーIDの大カテゴリーを取得する. 679 709 * … … 746 776 function sfGetLevelCatList($parent_zero = true) { 747 777 $objQuery = new SC_Query(); 778 779 // カテゴリ名リストを取得 780 $col = "category_id, parent_category_id, category_name"; 781 $where = "del_flg = 0"; 782 $objQuery->setoption("ORDER BY level"); 783 $arrRet = $objQuery->select($col, "dtb_category", $where); 784 $arrCatName = array(); 785 foreach ($arrRet as $arrTmp) { 786 $arrCatName[$arrTmp['category_id']] = 787 (($arrTmp['parent_category_id'] > 0)? 788 $arrCatName[$arrTmp['parent_category_id']] : "") 789 . CATEGORY_HEAD . $arrTmp['category_name']; 790 } 791 748 792 $col = "category_id, parent_category_id, category_name, level"; 749 793 $where = "del_flg = 0"; … … 763 807 } 764 808 765 $arrOutput[$cnt] = ""; 766 767 // 子カテゴリから親カテゴリを検索 768 $parent_category_id = $arrRet[$cnt]['parent_category_id']; 769 for($cat_cnt = $arrRet[$cnt]['level']; $cat_cnt > 1; $cat_cnt--) { 770 771 foreach ($arrRet as $arrCat) { 772 // 親が見つかったら順番に代入 773 if ($arrCat['category_id'] == $parent_category_id) { 774 775 $arrOutput[$cnt] = CATEGORY_HEAD 776 . $arrCat['category_name'] . $arrOutput[$cnt]; 777 $parent_category_id = $arrCat['parent_category_id']; 778 } 779 } 780 } 781 $arrOutput[$cnt].= CATEGORY_HEAD . $arrRet[$cnt]['category_name']; 809 $arrOutput[$cnt] = $arrCatName[$arrRet[$cnt]['category_id']]; 782 810 } 783 811 … … 804 832 $category_id = (int) $category_id; 805 833 $product_id = (int) $product_id; 806 if (SC_Utils_Ex::sfIsInt($category_id)&& $this->sfIsRecord("dtb_category","category_id", $category_id)) {834 if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && $this->sfIsRecord("dtb_category","category_id", $category_id)) { 807 835 $this->g_category_id = array($category_id); 808 } else if (SC_Utils_Ex::sfIsInt($product_id) && $ this->sfIsRecord("dtb_products","product_id", $product_id, $status)) {836 } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { 809 837 $objQuery = new SC_Query(); 810 838 $where = "product_id = ?"; … … 937 965 */ 938 966 function sfCategory_Count($objQuery){ 939 $sql = "";940 967 941 968 //テーブル内容の削除 … … 943 970 $objQuery->query("DELETE FROM dtb_category_total_count"); 944 971 972 $sql_where .= 'alldtl.del_flg = 0 AND alldtl.status = 1'; 973 // 在庫無し商品の非表示 974 if (NOSTOCK_HIDDEN === true) { 975 $sql_where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; 976 } 977 945 978 //各カテゴリ内の商品数を数えて格納 946 $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) "; 947 $sql .= " SELECT T1.category_id, count(T2.category_id), now() "; 948 $sql .= " FROM dtb_category AS T1 LEFT JOIN dtb_product_categories AS T2"; 949 $sql .= " ON T1.category_id = T2.category_id "; 950 $sql .= " LEFT JOIN dtb_products AS T3"; 951 $sql .= " ON T2.product_id = T3.product_id"; 952 $sql .= " WHERE T3.del_flg = 0 AND T3.status = 1 "; 953 $sql .= " GROUP BY T1.category_id, T2.category_id "; 979 $sql = <<< __EOS__ 980 INSERT INTO dtb_category_count(category_id, product_count, create_date) 981 SELECT T1.category_id, count(T2.category_id), now() 982 FROM dtb_category AS T1 983 LEFT JOIN dtb_product_categories AS T2 984 ON T1.category_id = T2.category_id 985 LEFT JOIN vw_products_allclass_detail AS alldtl 986 ON T2.product_id = alldtl.product_id 987 WHERE $sql_where 988 GROUP BY T1.category_id, T2.category_id 989 __EOS__; 990 954 991 $objQuery->query($sql); 955 992 956 993 //子カテゴリ内の商品数を集計する 957 $arrCat = $objQuery->getAll("SELECT * FROM dtb_category"); 958 959 $sql = ""; 960 foreach($arrCat as $key => $val){ 961 962 // 子ID一覧を取得 963 $arrRet = $this->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']); 964 $line = SC_Utils_Ex::sfGetCommaList($arrRet); 965 966 $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) "; 967 $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count "; 968 $sql .= " WHERE category_id IN (" . $line . ")"; 969 970 $objQuery->query($sql, array($val['category_id'])); 994 995 // カテゴリ情報を取得 996 $arrCat = $objQuery->select('category_id', 'dtb_category'); 997 998 foreach ($arrCat as $row) { 999 $category_id = $row['category_id']; 1000 $arrval = array(); 1001 1002 $arrval[] = $category_id; 1003 1004 list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id); 1005 if ($tmp_where != "") { 1006 $sql_where_product_ids = "alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 1007 $arrval = array_merge((array)$arrval, (array)$tmp_arrval); 1008 } else { 1009 $sql_where_product_ids = '0<>0'; // 一致させない 1010 } 1011 1012 $sql = <<< __EOS__ 1013 INSERT INTO dtb_category_total_count (category_id, product_count, create_date) 1014 SELECT 1015 ? 1016 ,count(*) 1017 ,now() 1018 FROM vw_products_allclass_detail AS alldtl 1019 WHERE ($sql_where) AND ($sql_where_product_ids) 1020 __EOS__; 1021 1022 $objQuery->query($sql, $arrval); 971 1023 } 972 1024 } … … 1097 1149 foreach ($arrRet as $val) { 1098 1150 if($tmp_where == "") { 1099 $tmp_where.= " 1151 $tmp_where.= "category_id IN ( ?"; 1100 1152 } else { 1101 1153 $tmp_where.= ",? "; … … 1245 1297 1246 1298 $max = $objQuery->max($tableName, "rank", $where); 1299 1247 1300 // 値の調整(逆順) 1248 1301 if($pos > $max) { … … 1268 1321 $sql.= " AND $where"; 1269 1322 } 1270 if( $position > $rank ) $objQuery->exec( $sql, array($rank, $position)); 1271 if( $position < $rank ) $objQuery->exec( $sql, array($position, $rank)); 1272 // 指定した順位へrankを書き換える。 1323 1324 if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position )); 1325 if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 )); 1326 1327 // 指定した順位へrankを書き換える。 1273 1328 $sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; 1274 1329 if($where != "") { 1275 1330 $sql.= " AND $where"; 1276 1331 } 1332 1277 1333 $objQuery->exec( $sql, array( $position, $keyId ) ); 1278 1334 $objQuery->commit(); … … 1413 1469 * 都道府県、支払い方法から配送料金を取得する. 1414 1470 * 1415 * @param integer $pref 都道府県ID 1416 * @param integer $payment_id 支払い方法ID 1471 * @param array $arrData 各種情報 1417 1472 * @return string 指定の都道府県, 支払い方法の配送料金 1418 1473 */ … … 1460 1515 * @param LC_Page $objPage LC_Page インスタンス 1461 1516 * @param SC_CartSession $objCartSess SC_CartSession インスタンス 1462 * @param array $arrInfo 店舗情報の配列1517 * @param null $dummy1 互換性確保用(決済モジュール互換のため) 1463 1518 * @param SC_Customer $objCustomer SC_Customer インスタンス 1464 1519 * @return array 最終計算後の配列 1465 1520 */ 1466 function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $arrInfo, $objCustomer = "") { 1521 function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $dummy1 = null, $objCustomer = "") { 1522 // 店舗基本情報を取得する 1523 $arrInfo = SC_Helper_DB_Ex::sf_getBasisData(); 1524 1467 1525 // 未定義変数を定義 1468 1526 if (!isset($arrData['deliv_pref'])) $arrData['deliv_pref'] = ""; … … 1470 1528 if (!isset($arrData['charge'])) $arrData['charge'] = ""; 1471 1529 if (!isset($arrData['use_point'])) $arrData['use_point'] = ""; 1472 1473 // 商品の合計個数 1474 $total_quantity = $objCartSess->getTotalQuantity(true); 1530 if (!isset($arrData['add_point'])) $arrData['add_point'] = 0; 1475 1531 1476 1532 // 税金の取得 … … 1484 1540 // 商品ごとの送料が有効の場合 1485 1541 if (OPTION_PRODUCT_DELIV_FEE == 1) { 1486 $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee(); 1542 // 全商品の合計送料を加算する 1543 $this->lfAddAllProductsDelivFee($arrData, $objPage, $objCartSess); 1487 1544 } 1488 1545 1489 1546 // 配送業者の送料が有効の場合 1490 1547 if (OPTION_DELIV_FEE == 1) { 1491 // 送料の合計を計算する1492 $ arrData['deliv_fee'] += $this->sfGetDelivFee($arrData);1548 // 都道府県、支払い方法から配送料金を加算する 1549 $this->lfAddDelivFee($arrData); 1493 1550 } 1494 1551 1495 1552 // 送料無料の購入数が設定されている場合 1496 if(DELIV_FREE_AMOUNT > 0) { 1553 if (DELIV_FREE_AMOUNT > 0) { 1554 // 商品の合計数量 1555 $total_quantity = $objCartSess->getTotalQuantity(true); 1556 1497 1557 if($total_quantity >= DELIV_FREE_AMOUNT) { 1498 1558 $arrData['deliv_fee'] = 0; … … 1509 1569 1510 1570 // 合計の計算 1511 $arrData['total'] = $objPage->tpl_total_pretax; 1512 $arrData['total']+= $arrData['deliv_fee']; 1513 $arrData['total']+= $arrData['charge']; 1571 $arrData['total'] = $objPage->tpl_total_pretax; // 商品合計 1572 $arrData['total']+= $arrData['deliv_fee']; // 送料 1573 $arrData['total']+= $arrData['charge']; // 手数料 1514 1574 // お支払い合計 1515 1575 $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE); 1516 1576 // 加算ポイントの計算 1517 if (USE_POINT === false) { 1518 $arrData['add_point'] = 0; 1519 } else { 1520 $arrData['add_point'] = SC_Utils::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo); 1577 if (USE_POINT !== false) { 1578 $arrData['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point']); 1521 1579 1522 1580 if($objCustomer != "") { … … 1571 1629 } 1572 1630 1631 /** 1632 * メーカー商品数数の登録を行う. 1633 * 1634 * @param SC_Query $objQuery SC_Query インスタンス 1635 * @return void 1636 */ 1637 function sfMaker_Count($objQuery){ 1638 $sql = ""; 1639 1640 //テーブル内容の削除 1641 $objQuery->query("DELETE FROM dtb_maker_count"); 1642 1643 //各メーカーの商品数を数えて格納 1644 $sql = " INSERT INTO dtb_maker_count(maker_id, product_count, create_date) "; 1645 $sql .= " SELECT T1.maker_id, count(T2.maker_id), now() "; 1646 $sql .= " FROM dtb_maker AS T1 LEFT JOIN dtb_products AS T2"; 1647 $sql .= " ON T1.maker_id = T2.maker_id "; 1648 $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 "; 1649 $sql .= " GROUP BY T1.maker_id, T2.maker_id "; 1650 $objQuery->query($sql); 1651 } 1652 1653 /** 1654 * 選択中の商品のメーカーを取得する. 1655 * 1656 * @param integer $product_id プロダクトID 1657 * @param integer $maker_id メーカーID 1658 * @return array 選択中の商品のメーカーIDの配列 1659 * 1660 */ 1661 function sfGetMakerId($product_id, $maker_id = 0, $closed = false) { 1662 if ($closed) { 1663 $status = ""; 1664 } else { 1665 $status = "status = 1"; 1666 } 1667 1668 if (!$this->g_maker_on) { 1669 $this->g_maker_on = true; 1670 $maker_id = (int) $maker_id; 1671 $product_id = (int) $product_id; 1672 if (SC_Utils_Ex::sfIsInt($maker_id) && $maker_id != 0 && $this->sfIsRecord("dtb_maker","maker_id", $maker_id)) { 1673 $this->g_maker_id = array($maker_id); 1674 } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { 1675 $objQuery = new SC_Query(); 1676 $where = "product_id = ?"; 1677 $maker_id = $objQuery->getCol("dtb_products", "maker_id", "product_id = ?", array($product_id)); 1678 $this->g_maker_id = $maker_id; 1679 } else { 1680 // 不正な場合は、空の配列を返す。 1681 $this->g_maker_id = array(); 1682 } 1683 } 1684 return $this->g_maker_id; 1685 } 1686 1687 /** 1688 * メーカーの取得を行う. 1689 * 1690 * $products_check:true商品登録済みのものだけ取得する 1691 * 1692 * @param string $addwhere 追加する WHERE 句 1693 * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true 1694 * @return array カテゴリツリーの配列 1695 */ 1696 function sfGetMakerList($addwhere = "", $products_check = false) { 1697 $objQuery = new SC_Query(); 1698 $where = "del_flg = 0"; 1699 1700 if($addwhere != "") { 1701 $where.= " AND $addwhere"; 1702 } 1703 1704 $objQuery->setoption("ORDER BY rank DESC"); 1705 1706 if($products_check) { 1707 $col = "T1.maker_id, name"; 1708 $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id"; 1709 $where .= " AND product_count > 0"; 1710 } else { 1711 $col = "maker_id, name"; 1712 $from = "dtb_maker"; 1713 } 1714 1715 $arrRet = $objQuery->select($col, $from, $where); 1716 1717 $max = count($arrRet); 1718 for($cnt = 0; $cnt < $max; $cnt++) { 1719 $id = $arrRet[$cnt]['maker_id']; 1720 $name = $arrRet[$cnt]['name']; 1721 $arrList[$id].= $name; 1722 } 1723 return $arrList; 1724 } 1725 1726 /** 1727 * 全商品の合計送料を加算する 1728 */ 1729 function lfAddAllProductsDelivFee(&$arrData, &$objPage, &$objCartSess) { 1730 $arrData['deliv_fee'] += $this->lfCalcAllProductsDelivFee($arrData, $objCartSess); 1731 } 1732 1733 /** 1734 * 全商品の合計送料を計算する 1735 */ 1736 function lfCalcAllProductsDelivFee(&$arrData, &$objCartSess) { 1737 $objQuery = new SC_Query(); 1738 $deliv_fee_total = 0; 1739 $max = $objCartSess->getMax(); 1740 for ($i = 0; $i <= $max; $i++) { 1741 // 商品送料 1742 $deliv_fee = $objQuery->getOne('SELECT deliv_fee FROM dtb_products WHERE product_id = ?', array($_SESSION[$objCartSess->key][$i]['id'][0])); 1743 // 数量 1744 $quantity = $_SESSION[$objCartSess->key][$i]['quantity']; 1745 // 累積 1746 $deliv_fee_total += $deliv_fee * $quantity; 1747 } 1748 return $deliv_fee_total; 1749 } 1750 1751 /** 1752 * 都道府県、支払い方法から配送料金を加算する. 1753 * 1754 * @param array $arrData 各種情報 1755 */ 1756 function lfAddDelivFee(&$arrData) { 1757 $arrData['deliv_fee'] += $this->sfGetDelivFee($arrData); 1758 } 1759 1760 /** 1761 * 受注の名称列を更新する 1762 * 1763 * @param integer $order_id 更新対象の注文番号 1764 * @param boolean $temp_table 更新対象は「受注_Temp」か 1765 * @static 1766 */ 1767 function sfUpdateOrderNameCol($order_id, $temp_table = false) { 1768 $objQuery = new SC_Query(); 1769 1770 if ($temp_table) { 1771 $tgt_table = 'dtb_order_temp'; 1772 $sql_where = 'WHERE order_temp_id = ?'; 1773 } else { 1774 $tgt_table = 'dtb_order'; 1775 $sql_where = 'WHERE order_id = ?'; 1776 } 1777 1778 $sql = <<< __EOS__ 1779 UPDATE 1780 {$tgt_table} 1781 SET 1782 payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = {$tgt_table}.payment_id) 1783 ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = {$tgt_table}.deliv_time_id AND deliv_id = {$tgt_table}.deliv_id) 1784 $sql_where 1785 __EOS__; 1786 1787 $objQuery->query($sql, array($order_id)); 1788 } 1789 1790 /** 1791 * 店舗基本情報に基づいて税金額を返す 1792 * 1793 * @param integer $price 計算対象の金額 1794 * @return integer 税金額 1795 */ 1796 function sfTax($price) { 1797 // 店舗基本情報を取得 1798 $CONF = SC_Helper_DB_Ex::sf_getBasisData(); 1799 1800 return SC_Utils_Ex::sfTax($price, $CONF['tax'], $CONF['tax_rule']); 1801 } 1802 1803 /** 1804 * 店舗基本情報に基づいて税金付与した金額を返す 1805 * 1806 * @param integer $price 計算対象の金額 1807 * @return integer 税金付与した金額 1808 */ 1809 function sfPreTax($price, $tax = null, $tax_rule = null) { 1810 // 店舗基本情報を取得 1811 $CONF = SC_Helper_DB_Ex::sf_getBasisData(); 1812 1813 return SC_Utils_Ex::sfPreTax($price, $CONF['tax'], $CONF['tax_rule']); 1814 } 1815 1816 /** 1817 * 店舗基本情報に基づいて加算ポイントを返す 1818 * 1819 * @param integer $totalpoint 1820 * @param integer $use_point 1821 * @return integer 加算ポイント 1822 */ 1823 function sfGetAddPoint($totalpoint, $use_point) { 1824 // 店舗基本情報を取得 1825 $CONF = SC_Helper_DB_Ex::sf_getBasisData(); 1826 1827 return SC_Utils_Ex::sfGetAddPoint($totalpoint, $use_point, $CONF['point_rate']); 1828 } 1829 1830 /** 1831 * 受注.対応状況の更新 1832 * 1833 * ・必ず呼び出し元でトランザクションブロックを開いておくこと。 1834 * 1835 * @param integer $orderId 注文番号 1836 * @param integer|null $newStatus 対応状況 (null=変更無し) 1837 * @param integer|null $newAddPoint 加算ポイント (null=変更無し) 1838 * @param integer|null $newUsePoint 使用ポイント (null=変更無し) 1839 * @return void 1840 */ 1841 function sfUpdateOrderStatus($orderId, $newStatus = null, $newAddPoint = null, $newUsePoint = null) { 1842 $objQuery = new SC_Query(); 1843 1844 $arrOrderOld = $objQuery->getRow('dtb_order', 'status, add_point, use_point, customer_id', 'order_id = ?', array($orderId)); 1845 1846 // 対応状況が変更無しの場合、DB値を引き継ぐ 1847 if (is_null($newStatus)) { 1848 $newStatus = $arrOrderOld['status']; 1849 } 1850 1851 // 使用ポイント、DB値を引き継ぐ 1852 if (is_null($newUsePoint)) { 1853 $newUsePoint = $arrOrderOld['use_point']; 1854 } 1855 1856 // 加算ポイント、DB値を引き継ぐ 1857 if (is_null($newAddPoint)) { 1858 $newAddPoint = $arrOrderOld['add_point']; 1859 } 1860 1861 if (USE_POINT !== false) { 1862 // 顧客.ポイントの加減値 1863 $addCustomerPoint = 0; 1864 1865 // ▼使用ポイント 1866 // 変更前の対応状況が利用対象の場合、変更前の使用ポイント分を戻す 1867 if (SC_Utils_Ex::sfIsUsePoint($arrOrderOld['status'])) { 1868 $addCustomerPoint += $arrOrderOld['use_point']; 1869 } 1870 1871 // 変更後の対応状況が利用対象の場合、変更後の使用ポイント分を引く 1872 if (SC_Utils_Ex::sfIsUsePoint($newStatus)) { 1873 $addCustomerPoint -= $newUsePoint; 1874 } 1875 // ▲使用ポイント 1876 1877 // ▼加算ポイント 1878 // 変更前の対応状況が加算対象の場合、変更前の加算ポイント分を戻す 1879 if (SC_Utils_Ex::sfIsAddPoint($arrOrderOld['status'])) { 1880 $addCustomerPoint -= $arrOrderOld['add_point']; 1881 } 1882 1883 // 変更後の対応状況が加算対象の場合、変更後の加算ポイント分を足す 1884 if (SC_Utils_Ex::sfIsAddPoint($newStatus)) { 1885 $addCustomerPoint += $newAddPoint; 1886 } 1887 // ▲加算ポイント 1888 1889 if ($addCustomerPoint != 0) { 1890 // ▼顧客テーブルの更新 1891 $sqlval = array(); 1892 $where = ''; 1893 $arrVal = array(); 1894 $arrRawSql = array(); 1895 $arrRawSqlVal = array(); 1896 1897 $sqlval['update_date'] = 'Now()'; 1898 $arrRawSql['point'] = 'point + ?'; 1899 $arrRawSqlVal[] = $addCustomerPoint; 1900 $where .= 'customer_id = ?'; 1901 $arrVal[] = $arrOrderOld['customer_id']; 1902 1903 $objQuery->update('dtb_customer', $sqlval, $where, $arrVal, $arrRawSql, $arrRawSqlVal); 1904 // ▲顧客テーブルの更新 1905 1906 // 顧客.ポイントをマイナスした場合、 1907 if ($addCustomerPoint < 0) { 1908 $sql = 'SELECT point FROM dtb_customer WHERE customer_id = ?'; 1909 $point = $objQuery->getone($sql, array($arrOrderOld['customer_id'])); 1910 // 変更後の顧客.ポイントがマイナスの場合、 1911 if ($point < 0) { 1912 // ロールバック 1913 $objQuery->rollback(); 1914 // エラー 1915 SC_Utils_Ex::sfDispSiteError(LACK_POINT); 1916 } 1917 } 1918 } 1919 } 1920 1921 // ▼受注テーブルの更新 1922 $sqlval = array(); 1923 if (USE_POINT !== false) { 1924 $sqlval['add_point'] = $newAddPoint; 1925 $sqlval['use_point'] = $newUsePoint; 1926 } 1927 // ステータスが発送済みに変更の場合、発送日を更新 1928 if ($arrOrderOld['status'] != ORDER_DELIV && $newStatus == ORDER_DELIV) { 1929 $sqlval['commit_date'] = 'Now()'; 1930 } 1931 $sqlval['status'] = $newStatus; 1932 $sqlval['update_date'] = 'Now()'; 1933 1934 $objQuery->update('dtb_order', $sqlval, 'order_id = ?', array($orderId)); 1935 // ▲受注テーブルの更新 1936 } 1937 1938 /** 1939 * 指定ファイルが存在する場合 SQL として実行 1940 * 1941 * ・MySQL の場合、文字「;」を区切りとして、分割実行。 1942 * XXX プラグイン用に追加。将来消すかも。 1943 * 1944 * @param string $sqlFilePath SQL ファイルのパス 1945 * @return void 1946 */ 1947 function sfExecSqlByFile($sqlFilePath) { 1948 if (file_exists($sqlFilePath)) { 1949 $objQuery = new SC_Query(); 1950 1951 $sqls = file_get_contents($sqlFilePath); 1952 if ($sqls === false) SC_Utils_Ex::sfDispException('ファイルは存在するが読み込めない'); 1953 1954 if (DB_TYPE == 'mysql') { 1955 foreach (explode(';', $sqls) as $sql) { 1956 $sql = trim($sql); 1957 if (strlen($sql) == 0) continue; 1958 $objQuery->query($sql); 1959 } 1960 } else { 1961 $objQuery->query($sqls); 1962 } 1963 } 1964 } 1965 1966 /** 1967 * 商品規格を設定しているか 1968 * 1969 * @param integer $product_id 商品ID 1970 * @return bool 商品規格が存在する場合:true, それ以外:false 1971 */ 1972 function sfHasProductClass($product_id) { 1973 if (!SC_Utils_Ex::sfIsInt($product_id)) return false; 1974 1975 $objQuery = new SC_Query(); 1976 $where = 'product_id = ? AND (classcategory_id1 <> 0 OR classcategory_id2 <> 0)'; 1977 $count = $objQuery->count('dtb_products_class', $where, array($product_id)); 1978 1979 return $count >= 1; 1980 } 1573 1981 } 1574 1982 ?>
Note: See TracChangeset
for help on using the changeset viewer.