public function doWebImportingsave() { global $_GPC, $_W; $rid = intval($_GPC['rid']); $districtid = intval($_GPC['districtid']); if (!$rid) { message('系统出错', url('site/entry/branch', array('rid' => $rid, 'm' => 'stonefish_bigwheel')), 'error'); exit; } if (empty($_FILES["inputExcel"]["tmp_name"])) { message('系统出错', url('site/entry/branch', array('rid' => $rid, 'm' => 'stonefish_bigwheel')), 'error'); exit; } $inputFileName = '../addons/stonefish_bigwheel/template/moban/excel/' . $_FILES["inputExcel"]["name"]; if (file_exists($inputFileName)) { unlink($inputFileName); //如果服务器上存在同名文件,则删除 } move_uploaded_file($_FILES["inputExcel"]["tmp_name"], $inputFileName); require_once '../framework/library/phpexcel/PHPExcel.php'; require_once '../framework/library/phpexcel/PHPExcel/IOFactory.php'; require_once '../framework/library/phpexcel/PHPExcel/Reader/Excel5.php'; //设置php服务器可用内存,上传较大文件时可能会用到 ini_set('memory_limit', '1024M'); $objReader = PHPExcel_IOFactory::createReader('Excel5'); //use excel2007 for 2007 format $objPHPExcel = $objReader->load($inputFileName); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); //取得总行数 $highestColumn = $sheet->getHighestColumn(); //取得总列数 $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexfromString($highestColumn); //总列数 $headtitle = array(); for ($row = 2; $row <= $highestRow; $row++) { $strs = array(); //注意highestColumnIndex的列数索引从0开始 for ($col = 0; $col < $highestColumnIndex; $col++) { $strs[$col] = $objWorksheet->getCellByColumnandRow($col, $row)->getValue(); } //查询是否规定了区域商点 if (!empty($districtid)) { $strs[2] = $districtid; } //查询是否规定了区域商点 //插入数据 $chongfu = pdo_fetch("select id from " . tablename('stonefish_branch_doings') . " where mobile =:mobile and uniacid=:uniacid and districtid=:districtid", array(':mobile' => $strs[0], ':uniacid' => $_W['uniacid'], ':districtid' => $strs[2])); $data = array('uniacid' => $_W['uniacid'], 'rid' => $rid, 'module' => 'stonefish_bigwheel', 'mobile' => $strs[0], 'awardcount' => $strs[1], 'districtid' => $strs[2], 'status' => 2, 'createtime' => time()); if (!empty($chongfu)) { pdo_update('stonefish_branch_doings', $data, array('id' => $chongfu['id'])); } else { pdo_insert('stonefish_branch_doings', $data); } } unlink($inputFileName); //删除上传的excel文件 message('导入抽奖次数成功', url('site/entry/branch', array('rid' => $rid, 'm' => 'stonefish_bigwheel'))); exit; }