/** * Page のプロセス. * * @return void */ function process() { $conn = new SC_DBConn(); $objView = new SC_AdminView(); $objSess = new SC_Session(); $objDb = new SC_Helper_DB_Ex(); // 認証可否の判定 SC_Utils_Ex::sfIsSuccess($objSess); // ファイル管理クラス $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR); // ファイル情報の初期化 $this->lfInitFile(); // パラメータ管理クラス $this->objFormParam = new SC_FormParam(); // パラメータ情報の初期化 $this->lfInitParam(); $colmax = $this->objFormParam->getCount(); $this->objFormParam->setHtmlDispNameArray(); $this->arrTitle = $this->objFormParam->getHtmlDispNameArray(); if (!isset($_POST['mode'])) { $_POST['mode'] = ""; } switch ($_POST['mode']) { case 'csv_upload': $err = false; // エラーチェック $arrErr['csv_file'] = $this->objUpFile->makeTempFile('csv_file'); if ($arrErr['css_file'] == "") { $arrErr = $this->objUpFile->checkEXISTS(); } // 実行時間を制限しない set_time_limit(0); // 出力をバッファリングしない(==日本語自動変換もしない) ob_end_clean(); // IEのために256バイト空文字出力 echo str_pad('', 256); if (empty($arrErr['csv_file'])) { // 一時ファイル名の取得 $filepath = $this->objUpFile->getTempFilePath('csv_file'); // エンコード $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_DIR); // レコード数を得る $rec_count = $this->lfCSVRecordCount($enc_filepath); $fp = fopen($enc_filepath, "r"); $line = 0; // 行数 $regist = 0; // 登録数 $objQuery = new SC_Query(); $objQuery->begin(); echo "■ CSV登録進捗状況 <br/><br/>\n"; while (!feof($fp) && !$err) { $arrCSV = fgetcsv($fp, CSV_LINE_MAX); // 行カウント $line++; if ($line <= 1) { continue; } // 項目数カウント $max = count($arrCSV); // 項目数が1以下の場合は無視する if ($max <= 1) { continue; } // 項目数チェック if ($max != $colmax) { echo "※ 項目数が" . $max . "個検出されました。項目数は" . $colmax . "個になります。</br>\n"; $err = true; } else { // シーケンス配列を格納する。 $this->objFormParam->setParam($arrCSV, true); $arrRet = $this->objFormParam->getHashArray(); $this->objFormParam->setParam($arrRet); // 入力値の変換 $this->objFormParam->convParam(); // <br>なしでエラー取得する。 $arrCSVErr = $this->lfCheckError(); } // 入力エラーチェック if (count($arrCSVErr) > 0) { echo "<font color=\"red\">■" . $line . "行目でエラーが発生しました。</font></br>\n"; foreach ($arrCSVErr as $val) { $this->printError($val); } $err = true; } if (!$err) { $this->lfRegistProduct($objQuery, $line); $regist++; } $arrParam = $this->objFormParam->getHashArray(); if (!$err) { echo $line . " / " . $rec_count . "行目 (カテゴリID:" . $arrParam['category_id'] . " / カテゴリ名:" . $arrParam['category_name'] . ")\n<br />"; } flush(); } fclose($fp); if (!$err) { $objQuery->commit(); echo "■" . $regist . "件のレコードを登録しました。"; // カテゴリ件数カウント関数の実行 $objDb->sfCategory_Count($objQuery); } else { $objQuery->rollback(); } } else { foreach ($arrErr as $val) { $this->printError($val); } } echo "<br/><a href=\"javascript:window.close()\">→閉じる</a>"; flush(); exit; break; default: break; } $objView->assignobj($this); $objView->display(MAIN_FRAME); }
/** * CSVアップロードを実行します. * * @return void */ public function doUploadCsv(&$objFormParam, &$objUpFile) { // ファイルアップロードのチェック $this->arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file'); if (strlen($this->arrErr['csv_file']) >= 1) { return; } $arrErr = $objUpFile->checkExists(); if (count($arrErr) > 0) { $this->arrErr = $arrErr; return; } // 一時ファイル名の取得 $filepath = $objUpFile->getTempFilePath('csv_file'); // CSVファイルの文字コード変換 $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); // CSVファイルのオープン $fp = fopen($enc_filepath, 'r'); // 失敗した場合はエラー表示 if (!$fp) { SC_Utils_Ex::sfDispError(''); } // 登録先テーブル カラム情報の初期化 $this->lfInitTableInfo(); // 登録フォーム カラム情報 $this->arrFormKeyList = $objFormParam->getKeyList(); $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); // CSVからの読み込み、入力エラーチェック $errFlag = $this->lfReadCSVFile($objFormParam, $fp); if (!$errFlag) { rewind($fp); // CSVからの読み込み、保存 $errFlag = $this->lfReadCSVFile($objFormParam, $fp, $objQuery); } // 実行結果画面を表示 $this->tpl_mainpage = 'basis/device_android_edit_csv_complete.tpl'; fclose($fp); if ($errFlag) { $objQuery->rollback(); return; } $objQuery->commit(); // 商品件数カウント関数の実行 $this->objDb->sfCountCategory($objQuery); $this->objDb->sfCountMaker($objQuery); }
/** * CSVアップロードを実行します. * * @return void */ function doUploadCsv(&$objFormParam, &$objUpFile) { // ファイルアップロードのチェック $this->arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file'); if (strlen($this->arrErr['csv_file']) >= 1) { return; } $arrErr = $objUpFile->checkExists(); if (count($arrErr) > 0) { $this->arrErr = $arrErr; return; } // 一時ファイル名の取得 $filepath = $objUpFile->getTempFilePath('csv_file'); // CSVファイルの文字コード変換 $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); // CSVファイルのオープン $fp = fopen($enc_filepath, 'r'); // 失敗した場合はエラー表示 if (!$fp) { SC_Utils_Ex::sfDispError(''); } // 登録先テーブル カラム情報の初期化 $this->lfInitTableInfo(); // 登録フォーム カラム情報 $this->arrFormKeyList = $objFormParam->getKeyList(); // 登録対象の列数 $col_max_count = $objFormParam->getCount(); // 行数 $line_count = 0; $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $errFlag = false; $all_line_checked = false; while (!feof($fp)) { $arrCSV = fgetcsv($fp, CSV_LINE_MAX); // 全行入力チェック後に、ファイルポインターを先頭に戻す if (feof($fp) && !$all_line_checked) { rewind($fp); $line_count = 0; $all_line_checked = true; continue; } // 行カウント $line_count++; // ヘッダ行はスキップ if ($line_count == 1) { continue; } // 空行はスキップ if (empty($arrCSV)) { continue; } // 列数が異なる場合はエラー $col_count = count($arrCSV); if ($col_max_count != $col_count) { $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。'); $errFlag = true; break; } // シーケンス配列を格納する。 $objFormParam->setParam($arrCSV, true); $arrRet = $objFormParam->getHashArray(); $objFormParam->setParam($arrRet); // 入力値の変換 $objFormParam->convParam(); // <br>なしでエラー取得する。 $arrCSVErr = $this->lfCheckError($objFormParam); // 入力エラーチェック if (count($arrCSVErr) > 0) { foreach ($arrCSVErr as $err) { $this->addRowErr($line_count, $err); } $errFlag = true; break; } if ($all_line_checked) { $this->lfRegistProduct($objQuery, $line_count, $objFormParam); $arrParam = $objFormParam->getHashArray(); $this->addRowResult($line_count, '商品ID:' . $arrParam['product_id'] . ' / 商品名:' . $arrParam['name']); } SC_Utils_Ex::extendTimeOut(); } // 実行結果画面を表示 $this->tpl_mainpage = 'products/upload_csv_complete.tpl'; fclose($fp); if ($errFlag) { $objQuery->rollback(); return; } $objQuery->commit(); // 商品件数カウント関数の実行 $this->objDb->sfCountCategory($objQuery); $this->objDb->sfCountMaker($objQuery); }
/** * * @deprecated 重複決済される * @param unknown $accountDay */ function doContBillResult($accountDay) { if ($accountDay == null) { $accountDay = $this->getAccountDay(); } $objQuery = SC_Query_Ex::getSingletonInstance(); $curl = $this->curl_init(); do { $zip_file = CSV_TEMP_REALDIR . "auone/" . date("Y/m/d/His") . ".zip"; if (file_exists($zip_file)) { sleep(5); } } while (file_exists($zip_file)); SC_Utils_Ex::recursiveMkdir(dirname($zip_file)); $fp = fopen($zip_file, "w"); // FIXME 決済認可 $curl = $this->curl_init(false, true); // $post_history = array (); $post = $this->getPost("ContBillResult", $this->config, compact("accountDay")); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($curl, CURLOPT_HEADER, FALSE); curl_setopt($curl, CURLOPT_FILE, $fp); curl_exec($curl); $zip = new ZipArchive(); if (!$zip->open($zip_file)) { SC_Utils_Ex::sfDispSiteError(PAGE_ERROR); } $extr = dirname($zip_file) . "/" . basename($zip_file, ".zip") . "/"; SC_Utils_Ex::recursiveMkdir($extr); if (!$zip->extractTo($extr)) { SC_Utils_Ex::sfDispSiteError(PAGE_ERROR); } $files = glob($extr . "*.csv"); foreach ($files as $file) { $enc_filepath = SC_Utils_Ex::sfEncodeFile($file, CHAR_CODE, dirname($file) . DIRECTORY_SEPARATOR); $fp2 = fopen($enc_filepath, "r"); fgetcsv($fp2); while ($arrCsv = fgetcsv($fp2)) { if (count($arrCsv) == 0) { // 空の列 continue; } if ($arrCsv[4] != $this->config["serviceId"]) { // 別サービス・チェック continue; } if ($arrCsv[8] != 'MPL01000') { // 取消レコード continue; } $pay_info_no = $arrCsv[1]; $amount_in_tax = $arrCsv[2]; $service_id = $arrCsv[4]; $au_open_id = $arrCsv[5]; $member_manage_no = $arrCsv[6]; $process_day = $arrCsv[11]; $cont_bill_regst_day = $arrCsv[13]; $continue_account_id = $arrCsv[19]; $amount = $amount_in_tax - $amount_in_tax % 100; $add_point = $amount; $where = "au_open_id =? AND status = 2 AND del_flg = 0"; $arrWhereVal = (array) $au_open_id; $customer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId(null, $where, $arrWhereVal); if (SC_Utils_Ex::isBlank($customer)) { // ユーザー復旧は手動の方がいいかもしれない。 continue; } $name = "継続(" . $amount_in_tax . "円)"; $customer_id = $customer["customer_id"]; if ($add_point) { $lost_point = 0; // 更新後ポイント $updatePoint = array("point" => min($customer["point"] + $add_point, AU_MAXPOINT)); // 最大ポイントへ変更している場合は失効ポイントを計算 if ($updatePoint["point"] == AU_MAXPOINT) { $lost_point = max($customer["point"] + $add_point, AU_MAXPOINT) - AU_MAXPOINT; } SC_Helper_Customer_Ex::sfEditCustomerData($updatePoint, $customer_id); $objQuery->insert("cp_dtb_point_history", array("id" => $objQuery->nextVal("cp_dtb_point_history_id"), "customer_id" => $customer_id, "add_point" => $add_point, "use_point" => 0, "lost_point" => $lost_point, "order_id" => 0, "name" => $name, "create_date" => "NOW()", "update_date" => "NOW()")); $arrWhereVal[] = $continue_account_id; if ($objQuery->exists("cp_dtb_customer_transaction", "au_open_id=? AND del_flg=0 AND continue_account_id =?", $arrWhereVal)) { // 何かしらの影響で削除された場合後続処理を行う continue; } $objQuery->insert("cp_dtb_customer_transaction", array("id" => $objQuery->nextVal("cp_dtb_customer_transaction_id"), "customer_id" => $customer_id, "au_open_id" => $au_open_id, "transaction_id" => "", "transaction_status" => "40", "pay_info_no" => $pay_info_no, "pay_status" => 20, "continue_account_id" => $continue_account_id, "member_manage_no" => $member_manage_no, "process_day" => $process_day, "process_time" => "000000", "cont_bill_regst_day" => $cont_bill_regst_day, "cont_bill_regst_time" => "000000", "ammount" => $amount, "ammount_in_tax" => $amount_in_tax, "del_flg" => 0, "contents_id" => sprintf("%05d%09d", $service_id, $add_point), "status" => 0)); } } } }
/** * CSVアップロードを実行する * * @param SC_FormParam $objFormParam * @param SC_UploadFile $objUpFile * @param SC_Helper_DB $objDb * @return void */ function doUploadCsv(&$objFormParam, &$objUpFile) { // ファイルアップロードのチェック $objUpFile->makeTempFile('csv_file'); $arrErr = $objUpFile->checkExists(); if (count($arrErr) > 0) { $this->arrErr = $arrErr; return; } // 一時ファイル名の取得 $filepath = $objUpFile->getTempFilePath('csv_file'); // CSVファイルの文字コード変換 $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); // CSVファイルのオープン $fp = fopen($enc_filepath, 'r'); // 失敗した場合はエラー表示 if (!$fp) { SC_Utils_Ex::sfDispError(''); } // 登録先テーブル カラム情報の初期化 $this->lfInitTableInfo(); // 登録フォーム カラム情報 $this->arrFormKeyList = $objFormParam->getKeyList(); // 登録対象の列数 $col_max_count = $objFormParam->getCount(); // 行数 $line_count = 0; $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $errFlag = false; while (!feof($fp)) { $arrCSV = fgetcsv($fp, CSV_LINE_MAX); // 行カウント $line_count++; // ヘッダ行はスキップ if ($line_count == 1) { continue; } // 空行はスキップ if (empty($arrCSV)) { continue; } // 列数が異なる場合はエラー $col_count = count($arrCSV); if ($col_max_count != $col_count) { $this->addRowErr($line_count, t('c_* T_ARG1 was detected for the item quantity. The item quantity is T_ARG2._01', array('T_ARG1' => $col_count, 'T_ARG2' => $col_max_count))); $errFlag = true; break; } // シーケンス配列を格納する。 $objFormParam->setParam($arrCSV, true); $arrRet = $objFormParam->getHashArray(); $objFormParam->setParam($arrRet); // 入力値の変換 $objFormParam->convParam(); // <br>なしでエラー取得する。 $arrCSVErr = $this->lfCheckError($objFormParam); // 入力エラーチェック if (count($arrCSVErr) > 0) { foreach ($arrCSVErr as $err) { $this->addRowErr($line_count, $err); } $errFlag = true; break; } $category_id = $this->lfRegistCategory($objQuery, $line_count, $objFormParam); $this->addRowResult($line_count, t('c_Category ID: T_ARG1 /Category name: T_ARG2_01', array('T_ARG1' => $category_id, 'T_ARG2' => $objFormParam->getValue('category_name')))); } // 実行結果画面を表示 $this->tpl_mainpage = 'products/upload_csv_category_complete.tpl'; fclose($fp); if ($errFlag) { $objQuery->rollback(); return; } $objQuery->commit(); // カテゴリ件数を更新 SC_Helper_DB_EX::sfCountCategory($objQuery); return; }