public function excel_update() { if ($this->user['group_type'] > MAX_ADMIN_TYPE) { $this->errorOutput('只有管理员可以操作'); } require_once CUR_CONF_PATH . 'lib/excel.class.php'; $excel = new excel(); //获取文件扩展名 $extend = pathinfo($_FILES["excel"]["name"]); $extend = strtolower($extend["extension"]); //获取文件扩展名结束 $time = date("Y-m-d-H-i-s"); //取当前上传的时间 $name = $time . '.' . $extend; //重新组装上传后的文件名 $uploadfile = CACHE_DIR . $name; //上传后的文件名地址 if ($extend == "xls" && $_FILES["file"]["size"] < 2000000) { $tmp_name = $_FILES["excel"]["tmp_name"]; if ($_FILES["excel"]["error"] > 0) { $this->errorOutput("Return Code: " . $_FILES["excel"]["error"] . "<br />"); } else { $excel_info = $excel->show($uploadfile, $tmp_name, $this->user); if ($excel_info && is_array($excel_info)) { //取影院信息 $sql = "SELECT id,title FROM " . DB_PREFIX . "cinema"; $query = $this->db->query($sql); while ($row = $this->db->fetch_array($query)) { $cinema_info[$row['title']] = $row['id']; } //取影片信息 $sql = "SELECT id,title FROM " . DB_PREFIX . "movie"; $query = $this->db->query($sql); while ($row = $this->db->fetch_array($query)) { $movie_info[$row['title']] = $row['id']; } //处理excel信息 foreach ($excel_info as $key => $val) { if ($cinema_info[$key]) { $this->input['cinema_id'] = $cinema_info[$key]; } else { $cinema_data = array('title' => trim($key), 'create_time' => TIMENOW, 'org_id' => $this->user['org_id'], 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'ip' => hg_getip()); $insert_id = $this->db->insert_data($cinema_data, 'cinema'); $this->input['cinema_id'] = $insert_id; $this->db->query("UPDATE " . DB_PREFIX . "cinema SET order_id = {$insert_id} WHERE id = {$insert_id}"); } foreach ((array) $val as $ke => $va) { if ($movie_info[$ke]) { $this->input['movie_id'] = $movie_info[$ke]; } else { $movie_data = array('title' => trim($ke), 'status' => 1, 'create_time' => TIMENOW, 'org_id' => $this->user['org_id'], 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'ip' => hg_getip()); $insert_id = $this->db->insert_data($movie_data, 'movie'); $this->input['movie_id'] = $insert_id; $this->db->query("UPDATE " . DB_PREFIX . "movie SET order_id = {$insert_id} WHERE id = {$insert_id}"); } $this->input['movie_name'] = trim($ke); foreach ((array) $va as $k => $v) { $this->input['dates'] = trim($k); $this->input['data'] = array(); foreach ((array) $v as $kk => $vv) { $tmp = array(); $tmp = explode('|', $vv); $this->input['data'][] = array('project_time' => trim($tmp[0]), 'hall' => trim($tmp[4]), 'ticket_price' => trim($tmp[3]), 'language' => trim($tmp[1]), 'dimension' => trim($tmp[2]), 'id' => '0'); } if ($this->input['data']) { $this->input['data'] = htmlentities(json_encode($this->input['data'])); } $this->input['is_excel'] = 1; $this->create(); } } } $this->addItem('success'); $this->output(); } else { $this->errorOutput('导入失败'); } } } else { $this->errorOutput('文件错误,仅支持xls,文件不能大于2M'); } }
public function excel_update() { $data_prms['_action'] = 'create'; $this->verify_content_prms($data_prms); if ($this->user['group_type'] > MAX_ADMIN_TYPE) { //$this->errorOutput('只有管理员可以操作'); } include CUR_CONF_PATH . 'lib/excel.class.php'; $excel = new excel(); //获取文件扩展名 $extend = pathinfo($_FILES["excel"]["name"]); $extend = strtolower($extend["extension"]); //获取文件扩展名结束 $time = date("Y-m-d-H-i-s"); //取当前上传的时间 $name = $time . '.' . $extend; //重新组装上传后的文件名 $uploadfile = CACHE_DIR . $name; //上传后的文件名地址 if ($extend == "xls" && $_FILES["file"]["size"] < 2000000) { $tmp_name = $_FILES["excel"]["tmp_name"]; $strtotimes = strtotime(date('Ymd')); $key = md5_file($tmp_name); $sql = " SELECT filekey FROM " . DB_PREFIX . "con_fileinfo WHERE filekey = '" . $key . "' AND create_time =" . $strtotimes; $re = $this->db->query_first($sql); if ($_FILES["excel"]["error"] > 0) { $this->errorOutput("Return Code: " . $_FILES["excel"]["error"] . "<br />"); } elseif ($re['filekey'] == $key) { $this->errorOutput('已经导入成功,无需重复导入'); } else { $sort_id = intval($this->input['sort_id']); $isupload = $excel->show($uploadfile, $tmp_name, $this->user, $sort_id); if ($isupload) { $sql = 'INSERT INTO ' . DB_PREFIX . 'con_fileinfo SET filekey = \'' . $key . '\',create_time =' . $strtotimes; $this->db->query($sql); // 删除除今天以外的文件MD5值. $sql = " DELETE FROM " . DB_PREFIX . "con_fileinfo WHERE 1 AND create_time NOT IN (" . $strtotimes . ")"; $this->db->query($sql); $this->addItem($isupload); $this->output(); } else { $this->errorOutput('导入失败'); } } } else { $this->errorOutput('文件错误,仅支持xls,文件不能大于2M'); } }