24 changed files with 2456 additions and 16 deletions
-
38app/Common/Helper.php
-
209app/Common/Utils/Database.php
-
260app/Common/Utils/HttpDownload.php
-
48app/Common/Utils/Utils.php
-
502app/Common/Utils/Zip.php
-
29app/Common/function.php
-
113app/Http/Controllers/Admin/AdController.php
-
388app/Http/Controllers/Admin/DatabaseController.php
-
43app/Http/Controllers/Home/AdController.php
-
6app/Http/Controllers/Home/PageController.php
-
149app/Http/Logic/AdLogic.php
-
164app/Http/Model/Ad.php
-
102app/Http/Requests/AdRequest.php
-
2database_backup/.gitignore
-
43lqycms.sql
-
3public/index.php
-
74resources/views/admin/ad/add.blade.php
-
74resources/views/admin/ad/edit.blade.php
-
26resources/views/admin/ad/index.blade.php
-
86resources/views/admin/database/index.blade.php
-
86resources/views/admin/database/index.html
-
6resources/views/admin/menu/add.blade.php
-
6resources/views/admin/menu/edit.blade.php
-
15routes/web.php
@ -0,0 +1,209 @@ |
|||
<?php |
|||
|
|||
namespace App\Common\Utils; |
|||
|
|||
use DB; |
|||
|
|||
//数据导出模型
|
|||
class Database |
|||
{ |
|||
/** |
|||
* 文件指针 |
|||
* @var resource |
|||
*/ |
|||
private $fp; |
|||
|
|||
/** |
|||
* 备份文件信息 part - 卷号,name - 文件名 |
|||
* @var array |
|||
*/ |
|||
private $file; |
|||
|
|||
/** |
|||
* 当前打开文件大小 |
|||
* @var integer |
|||
*/ |
|||
private $size = 0; |
|||
|
|||
/** |
|||
* 备份配置 |
|||
* @var integer |
|||
*/ |
|||
private $config; |
|||
|
|||
/** |
|||
* 数据库备份构造方法 |
|||
* @param array $file 备份或还原的文件信息 |
|||
* @param array $config 备份配置信息 |
|||
* @param string $type 执行类型,export - 备份数据, import - 还原数据 |
|||
*/ |
|||
public function __construct($file, $config, $type = 'export') |
|||
{ |
|||
$this->file = $file; |
|||
$this->config = $config; |
|||
} |
|||
|
|||
/** |
|||
* 打开一个卷,用于写入数据 |
|||
* @param integer $size 写入数据的大小 |
|||
*/ |
|||
private function open($size) |
|||
{ |
|||
if ($this->fp) { |
|||
$this->size += $size; |
|||
if ($this->size > $this->config['part']) { |
|||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|||
$this->fp = null; |
|||
$this->file['part']++; |
|||
session('backup_file', $this->file); |
|||
$this->create(); |
|||
} |
|||
} else { |
|||
$backuppath = $this->config['path']; |
|||
$filename = "{$backuppath}{$this->file['name']}-{$this->file['part']}.sql"; |
|||
if ($this->config['compress']) { |
|||
$filename = "{$filename}.gz"; |
|||
$this->fp = @gzopen($filename, "a{$this->config['level']}"); |
|||
} else { |
|||
$this->fp = @fopen($filename, 'a'); |
|||
} |
|||
$this->size = filesize($filename) + $size; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 写入初始数据 |
|||
* @return boolean true - 写入成功,false - 写入失败 |
|||
*/ |
|||
public function create() |
|||
{ |
|||
$sql = "-- -----------------------------\n"; |
|||
$sql .= "-- Think MySQL Data Transfer \n"; |
|||
$sql .= "-- \n"; |
|||
$sql .= "-- Host : " . config('database.hostname') . "\n"; |
|||
$sql .= "-- Port : " . config('database.hostport') . "\n"; |
|||
$sql .= "-- Database : " . config('database.database') . "\n"; |
|||
$sql .= "-- \n"; |
|||
$sql .= "-- Part : #{$this->file['part']}\n"; |
|||
$sql .= "-- Date : " . date("Y-m-d H:i:s") . "\n"; |
|||
$sql .= "-- -----------------------------\n\n"; |
|||
$sql .= "SET FOREIGN_KEY_CHECKS = 0;\n\n"; |
|||
return $this->write($sql); |
|||
} |
|||
|
|||
/** |
|||
* 写入SQL语句 |
|||
* @param string $sql 要写入的SQL语句 |
|||
* @return boolean true - 写入成功,false - 写入失败 |
|||
*/ |
|||
private function write($sql) |
|||
{ |
|||
$size = strlen($sql); |
|||
|
|||
//由于压缩原因,无法计算出压缩后的长度,这里假设压缩率为50%,
|
|||
//一般情况压缩率都会高于50%;
|
|||
$size = $this->config['compress'] ? $size / 2 : $size; |
|||
|
|||
$this->open($size); |
|||
return $this->config['compress'] ? @gzwrite($this->fp, $sql) : @fwrite($this->fp, $sql); |
|||
} |
|||
|
|||
/** |
|||
* 备份表结构 |
|||
* @param string $table 表名 |
|||
* @param integer $start 起始行数 |
|||
* @return boolean false - 备份失败 |
|||
*/ |
|||
public function backup($table, $start) |
|||
{ |
|||
//备份表结构
|
|||
if (0 == $start) { |
|||
$result = Db::query("SHOW CREATE TABLE `{$table}`"); |
|||
$sql = "\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "-- Table structure for `{$table}`\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "DROP TABLE IF EXISTS `{$table}`;\n"; |
|||
//$sql .= trim($result[0]['Create Table']) . ";\n\n";
|
|||
$sql .= trim($result[0]['create table']) . ";\n\n"; |
|||
if (false === $this->write($sql)) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//数据总数
|
|||
$result = Db::query("SELECT COUNT(*) AS count FROM `{$table}`"); |
|||
$count = $result['0']['count']; |
|||
|
|||
//备份表数据
|
|||
if ($count) { |
|||
//写入数据注释
|
|||
if (0 == $start) { |
|||
$sql = "-- -----------------------------\n"; |
|||
$sql .= "-- Records of `{$table}`\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$this->write($sql); |
|||
} |
|||
|
|||
//备份数据记录
|
|||
$result = Db::query("SELECT * FROM `{$table}` LIMIT {$start}, 1000"); |
|||
foreach ($result as $row) { |
|||
//$row = array_map('mysql_real_escape_string', $row);
|
|||
$row = array_map('mysql_escape_string', $row); |
|||
$sql = "INSERT INTO `{$table}` VALUES ('" . implode("', '", $row) . "');\n"; |
|||
if (false === $this->write($sql)) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//还有更多数据
|
|||
if ($count > $start + 1000) { |
|||
return array($start + 1000, $count); |
|||
} |
|||
} |
|||
|
|||
//备份下一表
|
|||
return 0; |
|||
} |
|||
|
|||
public function import($start) |
|||
{ |
|||
if ($this->config['compress']) { |
|||
$gz = gzopen($this->file[1], 'r'); |
|||
$size = 0; |
|||
} else { |
|||
$size = filesize($this->file[1]); |
|||
$gz = fopen($this->file[1], 'r'); |
|||
} |
|||
|
|||
$sql = ''; |
|||
if ($start) { |
|||
$this->config['compress'] ? gzseek($gz, $start) : fseek($gz, $start); |
|||
} |
|||
|
|||
for ($i = 0; $i < 1000; $i++) { |
|||
$sql .= $this->config['compress'] ? gzgets($gz) : fgets($gz); |
|||
if (preg_match('/.*;$/', trim($sql))) { |
|||
//if(false !== $db->query($sql)){
|
|||
if (false !== Db::execute($sql)) { |
|||
$start += strlen($sql); |
|||
} else { |
|||
return false; |
|||
} |
|||
$sql = ''; |
|||
} elseif ($this->config['compress'] ? gzeof($gz) : feof($gz)) { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
return array($start, $size); |
|||
} |
|||
|
|||
/** |
|||
* 析构方法,用于关闭文件资源 |
|||
*/ |
|||
public function __destruct() |
|||
{ |
|||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|||
} |
|||
} |
@ -0,0 +1,260 @@ |
|||
<?php |
|||
|
|||
namespace App\Common\Utils; |
|||
|
|||
/** |
|||
* 下载远程文件类支持断点续传 |
|||
*/ |
|||
class HttpDownload |
|||
{ |
|||
private $m_url = ""; |
|||
private $m_urlpath = ""; |
|||
private $m_scheme = "http"; |
|||
private $m_host = ""; |
|||
private $m_port = "80"; |
|||
private $m_user = ""; |
|||
private $m_pass = ""; |
|||
private $m_path = "/"; |
|||
private $m_query = ""; |
|||
private $m_fp = ""; |
|||
private $m_error = ""; |
|||
private $m_httphead = ""; |
|||
private $m_html = ""; |
|||
|
|||
/** |
|||
* 初始化 |
|||
*/ |
|||
public function PrivateInit($url) |
|||
{ |
|||
$urls = ""; |
|||
$urls = @parse_url($url); |
|||
$this->m_url = $url; |
|||
if (is_array($urls)) { |
|||
$this->m_host = $urls["host"]; |
|||
if (!empty($urls["scheme"])) $this->m_scheme = $urls["scheme"]; |
|||
if (!empty($urls["user"])) $this->m_user = $urls["user"]; |
|||
if (!empty($urls["pass"])) $this->m_pass = $urls["pass"]; |
|||
if (!empty($urls["port"])) $this->m_port = $urls["port"]; |
|||
if (!empty($urls["path"])) $this->m_path = $urls["path"]; |
|||
$this->m_urlpath = $this->m_path; |
|||
if (!empty($urls["query"])) { |
|||
$this->m_query = $urls["query"]; |
|||
$this->m_urlpath .= "?" . $this->m_query; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 打开指定网址 |
|||
*/ |
|||
function OpenUrl($url) |
|||
{ |
|||
#重设各参数
|
|||
$this->m_url = ""; |
|||
$this->m_urlpath = ""; |
|||
$this->m_scheme = "http"; |
|||
$this->m_host = ""; |
|||
$this->m_port = "80"; |
|||
$this->m_user = ""; |
|||
$this->m_pass = ""; |
|||
$this->m_path = "/"; |
|||
$this->m_query = ""; |
|||
$this->m_error = ""; |
|||
$this->m_httphead = ""; |
|||
$this->m_html = ""; |
|||
$this->Close(); |
|||
#初始化系统
|
|||
$this->PrivateInit($url); |
|||
$this->PrivateStartSession(); |
|||
} |
|||
|
|||
/** |
|||
* 获得某操作错误的原因 |
|||
*/ |
|||
public function printError() |
|||
{ |
|||
echo "错误信息:" . $this->m_error; |
|||
echo "具体返回头:<br>"; |
|||
foreach ($this->m_httphead as $k => $v) { |
|||
echo "$k => $v <br>\r\n"; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判别用Get方法发送的头的应答结果是否正确 |
|||
*/ |
|||
public function IsGetOK() |
|||
{ |
|||
if (ereg("^2", $this->GetHead("http-state"))) { |
|||
return true; |
|||
} else { |
|||
$this->m_error .= $this->GetHead("http-state") . " - " . $this->GetHead("http-describe") . "<br>"; |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 看看返回的网页是否是text类型 |
|||
*/ |
|||
public function IsText() |
|||
{ |
|||
if (ereg("^2", $this->GetHead("http-state")) && eregi("^text", $this->GetHead("content-type"))) { |
|||
return true; |
|||
} else { |
|||
$this->m_error .= "内容为非文本类型<br>"; |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判断返回的网页是否是特定的类型 |
|||
*/ |
|||
public function IsContentType($ctype) |
|||
{ |
|||
if (ereg("^2", $this->GetHead("http-state")) && $this->GetHead("content-type") == strtolower($ctype)) { |
|||
return true; |
|||
} else { |
|||
$this->m_error .= "类型不对 " . $this->GetHead("content-type") . "<br>"; |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用 HTTP 协议下载文件 |
|||
*/ |
|||
public function SaveToBin($savefilename) |
|||
{ |
|||
if (!$this->IsGetOK()) return false; |
|||
if (@feof($this->m_fp)) { |
|||
$this->m_error = "连接已经关闭!"; |
|||
return false; |
|||
} |
|||
$fp = fopen($savefilename, "w") or die("写入文件 $savefilename 失败!"); |
|||
while (!feof($this->m_fp)) { |
|||
@fwrite($fp, fgets($this->m_fp, 256)); |
|||
} |
|||
@fclose($this->m_fp); |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 保存网页内容为 Text 文件 |
|||
*/ |
|||
public function SaveToText($savefilename) |
|||
{ |
|||
if ($this->IsText()) { |
|||
$this->SaveBinFile($savefilename); |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 用 HTTP 协议获得一个网页的内容 |
|||
*/ |
|||
public function GetHtml() |
|||
{ |
|||
if (!$this->IsText()) return ""; |
|||
if ($this->m_html != "") return $this->m_html; |
|||
if (!$this->m_fp || @feof($this->m_fp)) return ""; |
|||
while (!feof($this->m_fp)) { |
|||
$this->m_html .= fgets($this->m_fp, 256); |
|||
} |
|||
@fclose($this->m_fp); |
|||
return $this->m_html; |
|||
} |
|||
|
|||
/** |
|||
* 开始 HTTP 会话 |
|||
*/ |
|||
public function PrivateStartSession() |
|||
{ |
|||
if (!$this->PrivateOpenHost()) { |
|||
$this->m_error .= "打开远程主机出错!"; |
|||
return false; |
|||
} |
|||
if ($this->GetHead("http-edition") == "HTTP/1.1") { |
|||
$httpv = "HTTP/1.1"; |
|||
} else { |
|||
$httpv = "HTTP/1.0"; |
|||
} |
|||
fputs($this->m_fp, "GET " . $this->m_urlpath . " $httpv\r\n"); |
|||
fputs($this->m_fp, "Host: " . $this->m_host . "\r\n"); |
|||
fputs($this->m_fp, "Accept: */*\r\n"); |
|||
fputs($this->m_fp, "User-Agent: Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2)\r\n"); |
|||
#HTTP1.1协议必须指定文档结束后关闭链接,否则读取文档时无法使用feof判断结束
|
|||
if ($httpv == "HTTP/1.1") { |
|||
fputs($this->m_fp, "Connection: Close\r\n\r\n"); |
|||
} else { |
|||
fputs($this->m_fp, "\r\n"); |
|||
} |
|||
$httpstas = fgets($this->m_fp, 256); |
|||
$httpstas = split(" ", $httpstas); |
|||
$this->m_httphead["http-edition"] = trim($httpstas[0]); |
|||
$this->m_httphead["http-state"] = trim($httpstas[1]); |
|||
$this->m_httphead["http-describe"] = ""; |
|||
for ($i = 2; $i < count($httpstas); $i++) { |
|||
$this->m_httphead["http-describe"] .= " " . trim($httpstas[$i]); |
|||
} |
|||
while (!feof($this->m_fp)) { |
|||
$line = str_replace("\"", "", trim(fgets($this->m_fp, 256))); |
|||
if ($line == "") break; |
|||
if (ereg(":", $line)) { |
|||
$lines = split(":", $line); |
|||
$this->m_httphead[strtolower(trim($lines[0]))] = trim($lines[1]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获得一个Http头的值 |
|||
*/ |
|||
public function GetHead($headname) |
|||
{ |
|||
$headname = strtolower($headname); |
|||
if (isset($this->m_httphead[$headname])) { |
|||
return $this->m_httphead[$headname]; |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 打开连接 |
|||
*/ |
|||
public function PrivateOpenHost() |
|||
{ |
|||
if ($this->m_host == "") return false; |
|||
$this->m_fp = @fsockopen($this->m_host, $this->m_port, $errno, $errstr, 10); |
|||
if (!$this->m_fp) { |
|||
$this->m_error = $errstr; |
|||
return false; |
|||
} else { |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 关闭连接 |
|||
*/ |
|||
public function Close() |
|||
{ |
|||
@fclose($this->m_fp); |
|||
} |
|||
} |
|||
/* |
|||
#两种使用方法,分别如下:
|
|||
|
|||
#打开网页
|
|||
$httpdown = new HttpDownload(); |
|||
$httpdown->OpenUrl("http://www.google.com.hk"); |
|||
echo $httpdown->GetHtml(); |
|||
$httpdown->Close(); |
|||
|
|||
|
|||
#下载文件
|
|||
$file = new HttpDownload(); # 实例化类
|
|||
$file->OpenUrl("http://www.ti.com.cn/cn/lit/an/rust020/rust020.pdf"); # 远程文件地址
|
|||
$file->SaveToBin("rust020.pdf"); # 保存路径及文件名
|
|||
$file->Close(); |
|||
*/ |
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
namespace App\Common\Utils; |
|||
|
|||
class Utils |
|||
{ |
|||
/** |
|||
* 模拟发送PUT方式请求 |
|||
* @param $url |
|||
* @param $contentBase64Md5 |
|||
* @param $fileContent |
|||
* @return mixed|string |
|||
* @author Ayz |
|||
*/ |
|||
public static function sendHttpPUT($url, $contentBase64Md5, $fileContent) |
|||
{ |
|||
$header = [ |
|||
'Content-Type:application/octet-stream' |
|||
]; |
|||
|
|||
$status = ''; |
|||
$curl_handle = curl_init(); |
|||
curl_setopt($curl_handle, CURLOPT_URL, $url); |
|||
curl_setopt($curl_handle, CURLOPT_FILETIME, true); |
|||
curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false); |
|||
curl_setopt($curl_handle, CURLOPT_HEADER, true); // 输出HTTP头 true
|
|||
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5184000); |
|||
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120); |
|||
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false); |
|||
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false); |
|||
|
|||
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $header); |
|||
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|||
|
|||
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $fileContent); |
|||
$result = curl_exec($curl_handle); |
|||
$status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); |
|||
|
|||
if ($result === false) { |
|||
$status = curl_errno($curl_handle); |
|||
$result = 'put file to oss - curl error :' . curl_error($curl_handle); |
|||
} |
|||
curl_close($curl_handle); |
|||
//$this->debug($url, $fileContent, $header, $result);
|
|||
return $status; |
|||
} |
|||
} |
@ -0,0 +1,502 @@ |
|||
<?php |
|||
|
|||
namespace App\Common\Utils; |
|||
|
|||
class Zip |
|||
{ |
|||
private $ctrl_dir = array(); |
|||
private $datasec = array(); |
|||
/********************************************************** |
|||
* 压缩部分 |
|||
**********************************************************/ |
|||
// ------------------------------------------------------ //
|
|||
// #遍历指定文件夹
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// $filelist = $archive->visitFile(文件夹路径);
|
|||
// print "当前文件夹的文件:<p>\r\n";
|
|||
// foreach($filelist as $file)
|
|||
// printf("%s<br>\r\n", $file);
|
|||
// ------------------------------------------------------ //
|
|||
var $fileList = array(); |
|||
|
|||
public function visitFile($path) |
|||
{ |
|||
global $fileList; |
|||
$path = str_replace("\\", "/", $path); |
|||
$fdir = dir($path); |
|||
while (($file = $fdir->read()) !== false) { |
|||
if ($file == '.' || $file == '..') { |
|||
continue; |
|||
} |
|||
$pathSub = preg_replace("*/{2,}*", "/", $path . "/" . $file); // 替换多个反斜杠
|
|||
$fileList[] = is_dir($pathSub) ? $pathSub . "/" : $pathSub; |
|||
if (is_dir($pathSub)) { |
|||
$this->visitFile($pathSub); |
|||
} |
|||
} |
|||
$fdir->close(); |
|||
return $fileList; |
|||
} |
|||
|
|||
private function unix2DosTime($unixtime = 0) |
|||
{ |
|||
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); |
|||
if ($timearray['year'] < 1980) { |
|||
$timearray['year'] = 1980; |
|||
$timearray['mon'] = 1; |
|||
$timearray['mday'] = 1; |
|||
$timearray['hours'] = 0; |
|||
$timearray['minutes'] = 0; |
|||
$timearray['seconds'] = 0; |
|||
} |
|||
return (($timearray['year'] - 1980) << 25) |
|||
| ($timearray['mon'] << 21) |
|||
| ($timearray['mday'] << 16) |
|||
| ($timearray['hours'] << 11) |
|||
| ($timearray['minutes'] << 5) |
|||
| ($timearray['seconds'] >> 1); |
|||
} |
|||
|
|||
var $old_offset = 0; |
|||
|
|||
private function addFile($data, $filename, $time = 0) |
|||
{ |
|||
$filename = str_replace('\\', '/', $filename); |
|||
$dtime = dechex($this->unix2DosTime($time)); |
|||
$hexdtime = '\x' . $dtime[6] . $dtime[7] |
|||
. '\x' . $dtime[4] . $dtime[5] |
|||
. '\x' . $dtime[2] . $dtime[3] |
|||
. '\x' . $dtime[0] . $dtime[1]; |
|||
eval('$hexdtime = "' . $hexdtime . '";'); |
|||
$fr = "\x50\x4b\x03\x04"; |
|||
$fr .= "\x14\x00"; |
|||
$fr .= "\x00\x00"; |
|||
$fr .= "\x08\x00"; |
|||
$fr .= $hexdtime; |
|||
$unc_len = strlen($data); |
|||
$crc = crc32($data); |
|||
$zdata = gzcompress($data); |
|||
$c_len = strlen($zdata); |
|||
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); |
|||
$fr .= pack('V', $crc); |
|||
$fr .= pack('V', $c_len); |
|||
$fr .= pack('V', $unc_len); |
|||
$fr .= pack('v', strlen($filename)); |
|||
$fr .= pack('v', 0); |
|||
$fr .= $filename; |
|||
$fr .= $zdata; |
|||
$fr .= pack('V', $crc); |
|||
$fr .= pack('V', $c_len); |
|||
$fr .= pack('V', $unc_len); |
|||
$this->datasec[] = $fr; |
|||
$new_offset = strlen(implode('', $this->datasec)); |
|||
$cdrec = "\x50\x4b\x01\x02"; |
|||
$cdrec .= "\x00\x00"; |
|||
$cdrec .= "\x14\x00"; |
|||
$cdrec .= "\x00\x00"; |
|||
$cdrec .= "\x08\x00"; |
|||
$cdrec .= $hexdtime; |
|||
$cdrec .= pack('V', $crc); |
|||
$cdrec .= pack('V', $c_len); |
|||
$cdrec .= pack('V', $unc_len); |
|||
$cdrec .= pack('v', strlen($filename)); |
|||
$cdrec .= pack('v', 0); |
|||
$cdrec .= pack('v', 0); |
|||
$cdrec .= pack('v', 0); |
|||
$cdrec .= pack('v', 0); |
|||
$cdrec .= pack('V', 32); |
|||
$cdrec .= pack('V', $this->old_offset); |
|||
$this->old_offset = $new_offset; |
|||
$cdrec .= $filename; |
|||
$this->ctrl_dir[] = $cdrec; |
|||
} |
|||
|
|||
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; |
|||
|
|||
private function file() |
|||
{ |
|||
$data = implode('', $this->datasec); |
|||
$ctrldir = implode('', $this->ctrl_dir); |
|||
return $data |
|||
. $ctrldir |
|||
. $this->eof_ctrl_dir |
|||
. pack('v', sizeof($this->ctrl_dir)) |
|||
. pack('v', sizeof($this->ctrl_dir)) |
|||
. pack('V', strlen($ctrldir)) |
|||
. pack('V', strlen($data)) |
|||
. "\x00\x00"; |
|||
} |
|||
// ------------------------------------------------------ //
|
|||
// #压缩到服务器
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// $archive->Zip("需压缩的文件所在目录", "ZIP压缩文件名");
|
|||
// ------------------------------------------------------ //
|
|||
public function zip($dir, $saveName) |
|||
{ |
|||
if (@!function_exists('gzcompress')) { |
|||
return; |
|||
} |
|||
ob_end_clean(); |
|||
$filelist = $this->visitFile($dir); |
|||
if (count($filelist) == 0) { |
|||
return; |
|||
} |
|||
foreach ($filelist as $file) { |
|||
if (!file_exists($file) || !is_file($file)) { |
|||
continue; |
|||
} |
|||
$fd = fopen($file, "rb"); |
|||
$content = @fread($fd, filesize($file)); |
|||
fclose($fd); |
|||
// 1.删除$dir的字符(./folder/file.txt删除./folder/)
|
|||
// 2.如果存在/就删除(/file.txt删除/)
|
|||
$file = substr($file, strlen($dir)); |
|||
if (substr($file, 0, 1) == "\\" || substr($file, 0, 1) == "/") { |
|||
$file = substr($file, 1); |
|||
} |
|||
$this->addFile($content, $file); |
|||
} |
|||
$out = $this->file(); |
|||
$fp = fopen($saveName, "wb"); |
|||
fwrite($fp, $out, strlen($out)); |
|||
fclose($fp); |
|||
} |
|||
// ------------------------------------------------------ //
|
|||
// #压缩并直接下载
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// $archive->ZipAndDownload("需压缩的文件所在目录");
|
|||
// ------------------------------------------------------ //
|
|||
public function ZipAndDownload($dir) |
|||
{ |
|||
if (@!function_exists('gzcompress')) { |
|||
return; |
|||
} |
|||
ob_end_clean(); |
|||
$filelist = $this->visitFile($dir); |
|||
if (count($filelist) == 0) { |
|||
return; |
|||
} |
|||
foreach ($filelist as $file) { |
|||
if (!file_exists($file) || !is_file($file)) { |
|||
continue; |
|||
} |
|||
$fd = fopen($file, "rb"); |
|||
$content = @fread($fd, filesize($file)); |
|||
fclose($fd); |
|||
// 1.删除$dir的字符(./folder/file.txt删除./folder/)
|
|||
// 2.如果存在/就删除(/file.txt删除/)
|
|||
$file = substr($file, strlen($dir)); |
|||
if (substr($file, 0, 1) == "\\" || substr($file, 0, 1) == "/") { |
|||
$file = substr($file, 1); |
|||
} |
|||
$this->addFile($content, $file); |
|||
} |
|||
$out = $this->file(); |
|||
@header('Content-Encoding: none'); |
|||
@header('Content-Type: application/zip'); |
|||
@header('Content-Disposition: attachment ; filename=Farticle' . date("YmdHis", time()) . '.zip'); |
|||
@header('Pragma: no-cache'); |
|||
@header('Expires: 0'); |
|||
print($out); |
|||
} |
|||
/********************************************************** |
|||
* 解压部分 |
|||
**********************************************************/ |
|||
// ------------------------------------------------------ //
|
|||
// ReadCentralDir($zip, $zipfile)
|
|||
// $zip是经过@fopen($zipfile, 'rb')打开的
|
|||
// $zipfile是zip文件的路径
|
|||
// ------------------------------------------------------ //
|
|||
private function ReadCentralDir($zip, $zipfile) |
|||
{ |
|||
$size = filesize($zipfile); |
|||
$max_size = ($size < 277) ? $size : 277; |
|||
@fseek($zip, $size - $max_size); |
|||
$pos = ftell($zip); |
|||
$bytes = 0x00000000; |
|||
while ($pos < $size) { |
|||
$byte = @fread($zip, 1); |
|||
$bytes = ($bytes << 8) | Ord($byte); |
|||
$pos++; |
|||
// 如果不是windows服务器,则要以504b0506作为对比
|
|||
if (strrpos(strtolower(PHP_OS), "win") === FALSE && substr(dechex($bytes), -8, 8) == '504b0506') { |
|||
break; |
|||
} // 如果是windows服务器,则要以0x504b0506作为对比
|
|||
elseif ($bytes == 0x504b0506) { |
|||
break; |
|||
} |
|||
} |
|||
$data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($zip, 18)); |
|||
$centd['comment'] = ($data['comment_size'] != 0) ? fread($zip, $data['comment_size']) : ''; // 注释
|
|||
$centd['entries'] = $data['entries']; |
|||
$centd['disk_entries'] = $data['disk_entries']; |
|||
$centd['offset'] = $data['offset']; |
|||
$centd['disk_start'] = $data['disk_start']; |
|||
$centd['size'] = $data['size']; |
|||
$centd['disk'] = $data['disk']; |
|||
return $centd; |
|||
} |
|||
|
|||
private function ReadCentralFileHeaders($zip) |
|||
{ |
|||
$binary_data = fread($zip, 46); |
|||
$header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data); |
|||
$header['filename'] = ($header['filename_len'] != 0) ? fread($zip, $header['filename_len']) : ''; |
|||
$header['extra'] = ($header['extra_len'] != 0) ? fread($zip, $header['extra_len']) : ''; |
|||
$header['comment'] = ($header['comment_len'] != 0) ? fread($zip, $header['comment_len']) : ''; |
|||
if ($header['mdate'] && $header['mtime']) { |
|||
$hour = ($header['mtime'] & 0xF800) >> 11; |
|||
$minute = ($header['mtime'] & 0x07E0) >> 5; |
|||
$seconde = ($header['mtime'] & 0x001F) * 2; |
|||
$year = (($header['mdate'] & 0xFE00) >> 9) + 1980; |
|||
$month = ($header['mdate'] & 0x01E0) >> 5; |
|||
$day = $header['mdate'] & 0x001F; |
|||
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); |
|||
} else { |
|||
$header['mtime'] = time(); |
|||
} |
|||
$header['stored_filename'] = $header['filename']; |
|||
$header['status'] = 'ok'; |
|||
if (substr($header['filename'], -1) == '/') { |
|||
$header['external'] = 0x41FF0010; |
|||
} // 判断是否文件夹
|
|||
return $header; |
|||
} |
|||
|
|||
private function ReadFileHeader($zip) |
|||
{ |
|||
$binary_data = fread($zip, 30); |
|||
$data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data); |
|||
$header['filename'] = fread($zip, $data['filename_len']); |
|||
$header['extra'] = ($data['extra_len'] != 0) ? fread($zip, $data['extra_len']) : ''; |
|||
$header['compression'] = $data['compression']; |
|||
$header['size'] = $data['size']; |
|||
$header['compressed_size'] = $data['compressed_size']; |
|||
$header['crc'] = $data['crc']; |
|||
$header['flag'] = $data['flag']; |
|||
$header['mdate'] = $data['mdate']; |
|||
$header['mtime'] = $data['mtime']; |
|||
if ($header['mdate'] && $header['mtime']) { |
|||
$hour = ($header['mtime'] & 0xF800) >> 11; |
|||
$minute = ($header['mtime'] & 0x07E0) >> 5; |
|||
$seconde = ($header['mtime'] & 0x001F) * 2; |
|||
$year = (($header['mdate'] & 0xFE00) >> 9) + 1980; |
|||
$month = ($header['mdate'] & 0x01E0) >> 5; |
|||
$day = $header['mdate'] & 0x001F; |
|||
$header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); |
|||
} else { |
|||
$header['mtime'] = time(); |
|||
} |
|||
$header['stored_filename'] = $header['filename']; |
|||
$header['status'] = "ok"; |
|||
return $header; |
|||
} |
|||
|
|||
private function ExtractFile($header, $to, $zip) |
|||
{ |
|||
$header = $this->readfileheader($zip); |
|||
if (substr($to, -1) != "/") { |
|||
$to .= "/"; |
|||
} |
|||
if (!@is_dir($to)) { |
|||
@mkdir($to, 0777); |
|||
} |
|||
$pth = explode("/", dirname($header['filename'])); |
|||
$pthss = ''; |
|||
for ($i = 0; isset($pth[$i]); $i++) { |
|||
if (!$pth[$i]) { |
|||
continue; |
|||
} |
|||
$pthss .= $pth[$i] . "/"; |
|||
if (!is_dir($to . $pthss)) { |
|||
@mkdir($to . $pthss, 0777); |
|||
} |
|||
} |
|||
if (!isset($header['external']) || ($header['external'] != 0x41FF0010 && $header['external'] != 16)) { |
|||
if ($header['compression'] == 0) { |
|||
$fp = @fopen($to . $header['filename'], 'wb'); |
|||
if (!$fp) { |
|||
return (-1); |
|||
} |
|||
$size = $header['compressed_size']; |
|||
while ($size != 0) { |
|||
$read_size = ($size < 2048 ? $size : 2048); |
|||
$buffer = fread($zip, $read_size); |
|||
$binary_data = pack('a' . $read_size, $buffer); |
|||
@fwrite($fp, $binary_data, $read_size); |
|||
$size -= $read_size; |
|||
} |
|||
fclose($fp); |
|||
touch($to . $header['filename'], $header['mtime']); |
|||
} else { |
|||
$fp = @fopen($to . $header['filename'] . '.gz', 'wb'); |
|||
if (!$fp) { |
|||
return (-1); |
|||
} |
|||
$binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); |
|||
fwrite($fp, $binary_data, 10); |
|||
$size = $header['compressed_size']; |
|||
while ($size != 0) { |
|||
$read_size = ($size < 1024 ? $size : 1024); |
|||
$buffer = fread($zip, $read_size); |
|||
$binary_data = pack('a' . $read_size, $buffer); |
|||
@fwrite($fp, $binary_data, $read_size); |
|||
$size -= $read_size; |
|||
} |
|||
$binary_data = pack('VV', $header['crc'], $header['size']); |
|||
fwrite($fp, $binary_data, 8); |
|||
fclose($fp); |
|||
$gzp = @gzopen($to . $header['filename'] . '.gz', 'rb') or die("Cette archive est compress!"); |
|||
if (!$gzp) { |
|||
return (-2); |
|||
} |
|||
$fp = @fopen($to . $header['filename'], 'wb'); |
|||
if (!$fp) { |
|||
return (-1); |
|||
} |
|||
$size = $header['size']; |
|||
while ($size != 0) { |
|||
$read_size = ($size < 2048 ? $size : 2048); |
|||
$buffer = gzread($gzp, $read_size); |
|||
$binary_data = pack('a' . $read_size, $buffer); |
|||
@fwrite($fp, $binary_data, $read_size); |
|||
$size -= $read_size; |
|||
} |
|||
fclose($fp); |
|||
gzclose($gzp); |
|||
touch($to . $header['filename'], $header['mtime']); |
|||
@unlink($to . $header['filename'] . '.gz'); |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
// ------------------------------------------------------ //
|
|||
// #解压文件
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// $zipfile = "ZIP压缩文件名";
|
|||
// $savepath = "解压缩目录名";
|
|||
// $zipfile = $unzipfile;
|
|||
// $savepath = $unziptarget;
|
|||
// $array = $archive->GetZipInnerFilesInfo($zipfile);
|
|||
// $filecount = 0;
|
|||
// $dircount = 0;
|
|||
// $failfiles = array();
|
|||
// set_time_limit(0); // 修改为不限制超时时间(默认为30秒)
|
|||
//
|
|||
// for($i=0; $i<count($array); $i++) {
|
|||
// if($array[$i][folder] == 0){
|
|||
// if($archive->unZip($zipfile, $savepath, $i) > 0){
|
|||
// $filecount++;
|
|||
// }else{
|
|||
// $failfiles[] = $array[$i][filename];
|
|||
// }
|
|||
// }else{
|
|||
// $dircount++;
|
|||
// }
|
|||
// }
|
|||
// set_time_limit(30);
|
|||
//printf("文件夹:%d 解压文件:%d 失败:%d<br>\r\n", $dircount, $filecount, count($failfiles));
|
|||
//if(count($failfiles) > 0){
|
|||
// foreach($failfiles as $file){
|
|||
// printf("·%s<br>\r\n", $file);
|
|||
// }
|
|||
//}
|
|||
// ------------------------------------------------------ //
|
|||
public function unzip($zipfile, $to, $index = Array(-1)) |
|||
{ |
|||
$ok = 0; |
|||
$zip = @fopen($zipfile, 'rb'); |
|||
if (!$zip) { |
|||
return (-1); |
|||
} |
|||
$cdir = $this->ReadCentralDir($zip, $zipfile); |
|||
$pos_entry = $cdir['offset']; |
|||
if (!is_array($index)) { |
|||
$index = array($index); |
|||
} |
|||
for ($i = 0; isset($index[$i]) && $index[$i]; $i++) { |
|||
if (intval($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) { |
|||
return (-1); |
|||
} |
|||
} |
|||
for ($i = 0; $i < $cdir['entries']; $i++) { |
|||
@fseek($zip, $pos_entry); |
|||
$header = $this->ReadCentralFileHeaders($zip); |
|||
$header['index'] = $i; |
|||
$pos_entry = ftell($zip); |
|||
@rewind($zip); |
|||
fseek($zip, $header['offset']); |
|||
if (in_array("-1", $index) || in_array($i, $index)) { |
|||
$stat[$header['filename']] = $this->ExtractFile($header, $to, $zip); |
|||
} |
|||
} |
|||
fclose($zip); |
|||
return $stat; |
|||
} |
|||
/********************************************************** |
|||
* 其它部分 |
|||
**********************************************************/ |
|||
// ------------------------------------------------------ //
|
|||
// #获取被压缩文件的信息
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// $array = $archive->GetZipInnerFilesInfo(ZIP压缩文件名);
|
|||
// for($i=0; $i<count($array); $i++) {
|
|||
// printf("<b>·%s</b><br>\r\n", $array[$i][filename]);
|
|||
// foreach($array[$i] as $key => $value)
|
|||
// printf("%s => %s<br>\r\n", $key, $value);
|
|||
// print "\r\n<p>------------------------------------<p>\r\n\r\n";
|
|||
// }
|
|||
// ------------------------------------------------------ //
|
|||
public function GetZipInnerFilesInfo($zipfile) |
|||
{ |
|||
$zip = @fopen($zipfile, 'rb'); |
|||
if (!$zip) { |
|||
return (0); |
|||
} |
|||
$centd = $this->ReadCentralDir($zip, $zipfile); |
|||
@rewind($zip); |
|||
@fseek($zip, $centd['offset']); |
|||
$ret = array(); |
|||
for ($i = 0; $i < $centd['entries']; $i++) { |
|||
$header = $this->ReadCentralFileHeaders($zip); |
|||
$header['index'] = $i; |
|||
$info = array( |
|||
'filename' => $header['filename'], // 文件名
|
|||
'stored_filename' => $header['stored_filename'], // 压缩后文件名
|
|||
'size' => $header['size'], // 大小
|
|||
'compressed_size' => $header['compressed_size'], // 压缩后大小
|
|||
'crc' => strtoupper(dechex($header['crc'])), // CRC32
|
|||
'mtime' => date("Y-m-d H:i:s", $header['mtime']), // 文件修改时间
|
|||
'comment' => $header['comment'], // 注释
|
|||
'folder' => ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0, // 是否为文件夹
|
|||
'index' => $header['index'], // 文件索引
|
|||
'status' => $header['status'] // 状态
|
|||
); |
|||
$ret[] = $info; |
|||
unset($header); |
|||
} |
|||
fclose($zip); |
|||
return $ret; |
|||
} |
|||
// ------------------------------------------------------ //
|
|||
// #获取压缩文件的注释
|
|||
//
|
|||
// $archive = new PHPZip();
|
|||
// echo $archive->GetZipComment(ZIP压缩文件名);
|
|||
// ------------------------------------------------------ //
|
|||
public function GetZipComment($zipfile) |
|||
{ |
|||
$zip = @fopen($zipfile, 'rb'); |
|||
if (!$zip) { |
|||
return (0); |
|||
} |
|||
$centd = $this->ReadCentralDir($zip, $zipfile); |
|||
fclose($zip); |
|||
return $centd[comment]; |
|||
} |
|||
} |
@ -0,0 +1,113 @@ |
|||
<?php |
|||
namespace App\Http\Controllers\Admin; |
|||
use DB; |
|||
use App\Common\Helper; |
|||
use App\Common\ReturnData; |
|||
use Illuminate\Http\Request; |
|||
use App\Http\Logic\AdLogic; |
|||
use App\Http\Model\Ad; |
|||
|
|||
class AdController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
public function getLogic() |
|||
{ |
|||
return new AdLogic(); |
|||
} |
|||
|
|||
public function index(Request $request) |
|||
{ |
|||
$res = ''; |
|||
$where = function ($query) use ($res) { |
|||
if(isset($_REQUEST["keyword"])) |
|||
{ |
|||
$query->where('name', 'like', '%'.$_REQUEST['keyword'].'%'); |
|||
} |
|||
}; |
|||
|
|||
$list = $this->getLogic()->getPaginate($where, array('id', 'desc')); |
|||
$data['list'] = $list; |
|||
return view('admin.ad.index', $data); |
|||
} |
|||
|
|||
public function add(Request $request) |
|||
{ |
|||
if(Helper::isPostRequest()) |
|||
{ |
|||
if ($_POST['start_time'] && $_POST['end_time']) { |
|||
$_POST['start_time'] = strtotime($_POST['start_time']); |
|||
$_POST['end_time'] = strtotime($_POST['end_time']); |
|||
} |
|||
|
|||
$res = $this->getLogic()->add($_POST); |
|||
if($res['code'] == ReturnData::SUCCESS) |
|||
{ |
|||
success_jump($res['msg'], route('admin_ad')); |
|||
} |
|||
|
|||
error_jump($res['msg']); |
|||
} |
|||
|
|||
return view('admin.ad.add'); |
|||
} |
|||
|
|||
public function edit(Request $request) |
|||
{ |
|||
if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');} |
|||
$id = $request->input('id'); |
|||
|
|||
if(Helper::isPostRequest()) |
|||
{ |
|||
if ($_POST['start_time'] && $_POST['end_time']) { |
|||
$_POST['start_time'] = strtotime($_POST['start_time']); |
|||
$_POST['end_time'] = strtotime($_POST['end_time']); |
|||
} |
|||
|
|||
$where['id'] = $id; |
|||
$res = $this->getLogic()->edit($_POST, $where); |
|||
if($res['code'] == ReturnData::SUCCESS) |
|||
{ |
|||
success_jump($res['msg'], route('admin_ad')); |
|||
} |
|||
|
|||
error_jump($res['msg']); |
|||
} |
|||
|
|||
$data['id'] = $where['id'] = $id; |
|||
$post = $this->getLogic()->getOne($where); |
|||
|
|||
//时间戳转日期格式
|
|||
if ($post->start_time > 0) { |
|||
$post->start_time = date('Y-m-d H:i:s', $post->start_time); |
|||
} else { |
|||
$post['start_time'] = ''; |
|||
} |
|||
if ($post->end_time > 0) { |
|||
$post->end_time = date('Y-m-d H:i:s', $post->end_time); |
|||
} else { |
|||
$post->end_time = ''; |
|||
} |
|||
|
|||
$data['post'] = $post; |
|||
return view('admin.ad.edit', $data); |
|||
} |
|||
|
|||
public function del(Request $request) |
|||
{ |
|||
if(!checkIsNumber($request->input('id',null))){error_jump('参数错误');} |
|||
$id = $request->input('id'); |
|||
|
|||
$where['id'] = $id; |
|||
$res = $this->getLogic()->del($where); |
|||
if($res['code'] != ReturnData::SUCCESS) |
|||
{ |
|||
error_jump($res['msg']); |
|||
} |
|||
|
|||
success_jump($res['msg']); |
|||
} |
|||
} |
@ -0,0 +1,388 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Admin; |
|||
|
|||
use DB; |
|||
use App\Common\ReturnData; |
|||
use Illuminate\Http\Request; |
|||
use App\Common\Helper; |
|||
use App\Common\Utils\Database as DatabaseUtil; |
|||
|
|||
class DatabaseController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
public function index() |
|||
{ |
|||
$data['list'] = $this->get_all_table(); |
|||
return view('admin.database.index', $data); |
|||
} |
|||
|
|||
public function get_all_table() |
|||
{ |
|||
$list = DB::select('SHOW TABLE STATUS'); |
|||
$list = object_to_array($list); |
|||
$list = array_map('array_change_key_case', $list); |
|||
return $list; |
|||
} |
|||
|
|||
public function recovery() |
|||
{ |
|||
$path = base_path() . DIRECTORY_SEPARATOR . 'database_backup'; |
|||
//判断目录是否存在
|
|||
is_writeable($path) || mkdir('./' . C("DB_PATH_NAME") . '', 0777, true); |
|||
//列出备份文件列表
|
|||
$flag = \FilesystemIterator::KEY_AS_FILENAME; |
|||
$glob = new \FilesystemIterator($path, $flag); |
|||
|
|||
$list = array(); |
|||
foreach ($glob as $name => $file) { |
|||
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) { |
|||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d'); |
|||
|
|||
$date = "{$name[0]}-{$name[1]}-{$name[2]}"; |
|||
$time = "{$name[3]}:{$name[4]}:{$name[5]}"; |
|||
$part = $name[6]; |
|||
|
|||
if (isset($list["{$date} {$time}"])) { |
|||
$info = $list["{$date} {$time}"]; |
|||
$info['part'] = max($info['part'], $part); |
|||
$info['size'] = $info['size'] + $file->getSize(); |
|||
} else { |
|||
$info['part'] = $part; |
|||
$info['size'] = $file->getSize(); |
|||
} |
|||
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); |
|||
$info['compress'] = ($extension === 'SQL') ? '-' : $extension; |
|||
$info['time'] = strtotime("{$date} {$time}"); |
|||
|
|||
$list["{$date} {$time}"] = $info; |
|||
} |
|||
} |
|||
$this->assign('list', $list); |
|||
$this->display(); |
|||
} |
|||
|
|||
/** |
|||
* 优化表 |
|||
* @param String $tables 表名 |
|||
*/ |
|||
public function optimize($tables = null) |
|||
{ |
|||
if (!$tables) { |
|||
$tables = request('tables'); |
|||
} |
|||
if (!$tables) { |
|||
error_jump("请指定要优化的表"); |
|||
} |
|||
if (is_array($tables)) { |
|||
if (count($tables) > 5) { |
|||
$all_table = $this->get_all_table(); |
|||
foreach ($all_table as $k => $v) { |
|||
DB::statement("OPTIMIZE TABLE `" . $v['name'] . "`"); |
|||
} |
|||
success_jump("数据库优化完成"); |
|||
} |
|||
$tables = implode('`,`', $tables); |
|||
$list = DB::statement("OPTIMIZE TABLE `{$tables}`"); |
|||
if (!$list) { |
|||
error_jump("数据表优化出错请重试"); |
|||
} |
|||
success_jump("数据表优化完成"); |
|||
} |
|||
if (substr_count($tables, ',') > 5) { |
|||
$all_table = $this->get_all_table(); |
|||
foreach ($all_table as $k => $v) { |
|||
DB::statement("OPTIMIZE TABLE `" . $v['name'] . "`"); |
|||
} |
|||
success_jump("数据库优化完成"); |
|||
} |
|||
$list = DB::statement("OPTIMIZE TABLE `{$tables}`"); |
|||
if (!$list) { |
|||
error_jump("数据表'{$tables}'优化出错请重试"); |
|||
} |
|||
success_jump("数据表'{$tables}'优化完成"); |
|||
} |
|||
|
|||
/** |
|||
* 修复表 |
|||
* @param String $tables 表名 |
|||
*/ |
|||
public function repair($tables = null) |
|||
{ |
|||
if (!$tables) { |
|||
$tables = request('tables'); |
|||
} |
|||
if (!$tables) { |
|||
error_jump("请指定要修复的表"); |
|||
} |
|||
if (is_array($tables)) { |
|||
if (count($tables) > 5) { |
|||
$all_table = $this->get_all_table(); |
|||
foreach ($all_table as $k => $v) { |
|||
DB::statement("REPAIR TABLE `" . $v['name'] . "`"); |
|||
} |
|||
success_jump("数据库修复完成"); |
|||
} |
|||
$tables = implode('`,`', $tables); |
|||
$list = DB::statement("REPAIR TABLE `{$tables}`"); |
|||
if (!$list) { |
|||
error_jump("数据表修复出错请重试"); |
|||
} |
|||
success_jump("数据表修复完成"); |
|||
} |
|||
if (substr_count($tables, ',') > 5) { |
|||
$all_table = $this->get_all_table(); |
|||
foreach ($all_table as $k => $v) { |
|||
DB::statement("REPAIR TABLE `" . $v['name'] . "`"); |
|||
} |
|||
success_jump("数据库修复完成"); |
|||
} |
|||
$list = DB::statement("REPAIR TABLE `{$tables}`"); |
|||
if (!$list) { |
|||
error_jump("数据表'{$tables}'修复出错请重试"); |
|||
} |
|||
success_jump("数据表'{$tables}'修复完成"); |
|||
} |
|||
|
|||
/** |
|||
* 删除备份文件 |
|||
* @param Integer $time 备份时间 |
|||
*/ |
|||
public function del($time = 0) |
|||
{ |
|||
if (!$time) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$name = date('Ymd-His', $time) . '-*.sql*'; |
|||
$path = base_path() . DIRECTORY_SEPARATOR . 'database_backup' . DIRECTORY_SEPARATOR . $name; |
|||
array_map("unlink", glob($path)); |
|||
if (count(glob($path))) { |
|||
error_jump('备份文件删除失败,请检查权限'); |
|||
} |
|||
success_jump('备份文件删除成功'); |
|||
} |
|||
|
|||
/** |
|||
* 备份数据库 |
|||
* @param String $tables 表名 |
|||
* @param Integer $id 表ID |
|||
* @param Integer $start 起始行数 |
|||
*/ |
|||
public function tables_backup() |
|||
{ |
|||
$tables = request('tables'); |
|||
if (!$tables) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$tables = explode(',', $tables); |
|||
//初始化
|
|||
if (!(!empty($tables) && is_array($tables))) { |
|||
error_jump('参数错误'); |
|||
} |
|||
if (count($tables) > 5) { |
|||
$all_table = $this->get_all_table(); |
|||
$tables = array_column($all_table, 'name'); |
|||
} |
|||
|
|||
$backup_path = base_path() . DIRECTORY_SEPARATOR . 'database_backup' . DIRECTORY_SEPARATOR; |
|||
foreach ($tables as $table) { |
|||
$filename = "{$backup_path}{$table}.sql"; |
|||
//判断文件是否已经存在
|
|||
if (file_exists($filename)) { |
|||
unlink($filename); |
|||
} |
|||
$fp = @fopen($filename, 'a'); |
|||
//将每个表的表结构导出到文件
|
|||
$table_structure = DB::select("SHOW CREATE TABLE `{$table}`"); |
|||
$table_structure = object_to_array($table_structure); |
|||
$sql = "\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "-- Table structure for `{$table}`\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "\n"; |
|||
$sql .= "DROP TABLE IF EXISTS `{$table}`;\n"; |
|||
$sql .= "\n"; |
|||
//$sql .= trim($table_structure[0]['create table']) . ";\n";
|
|||
$sql .= trim($table_structure[0]['Create Table']) . ";\n"; |
|||
$sql .= "\n"; |
|||
|
|||
//将每个表的数据导出到文件
|
|||
$table_data = DB::select("select * from " . $table); |
|||
if ($table_data) { |
|||
$table_data = object_to_array($table_data); |
|||
//数据量5万条以下导出
|
|||
if (count($table_data) < 50000) { |
|||
$sqlStr = "INSERT INTO `" . $table . "` VALUES ("; |
|||
foreach ($table_data as $k => $v) { |
|||
$keys = array_keys($v); |
|||
foreach ($keys as $row) { |
|||
$sqlStr .= "'" . $v[$row] . "', "; |
|||
} |
|||
//去掉最后一个逗号和空格
|
|||
$sqlStr = substr($sqlStr, 0, strlen($sqlStr) - 2); |
|||
$sqlStr = $sqlStr . '), ('; |
|||
} |
|||
//去掉最后一个逗号和空格
|
|||
$sqlStr = substr($sqlStr, 0, strlen($sqlStr) - 3); |
|||
$sqlStr .= ";\n"; |
|||
$sql .= $sqlStr; |
|||
} |
|||
} |
|||
|
|||
if (false === @fwrite($fp, $sql)) { |
|||
error_jump($table . '备份失败'); |
|||
} |
|||
} |
|||
success_jump('备份完成'); |
|||
} |
|||
|
|||
/** |
|||
* 备份数据库 |
|||
* @param String $tables 表名 |
|||
* @param Integer $id 表ID |
|||
* @param Integer $start 起始行数 |
|||
*/ |
|||
public function backup() |
|||
{ |
|||
if (Helper::isPostRequest()) { |
|||
$tables = request('tables'); |
|||
if (!$tables) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$tables = explode(',', $tables); |
|||
//初始化
|
|||
if (!(!empty($tables) && is_array($tables))) { |
|||
error_jump('参数错误'); |
|||
} |
|||
//读取备份配置
|
|||
$config = array( |
|||
'path' => base_path() . DIRECTORY_SEPARATOR . 'database_backup' . DIRECTORY_SEPARATOR, //路径
|
|||
'part' => 20971520, // 该值用于限制压缩后的分卷最大长度。单位:B;建议设置20M
|
|||
'compress' => 1, // 压缩备份文件需要PHP环境支持gzopen,gzwrite函数 0:不压缩 1:启用压缩
|
|||
'level' => 9, // 压缩级别, 1:普通 4:一般 9:最高
|
|||
); |
|||
//检查是否有正在执行的任务
|
|||
$lock = "{$config['path']}backup_database.lock"; |
|||
if (is_file($lock)) { |
|||
error_jump('检测到有一个备份任务正在执行,请稍后再试'); |
|||
} |
|||
//创建锁文件
|
|||
file_put_contents($lock, time()); |
|||
|
|||
//检查备份目录是否可写 创建备份目录
|
|||
is_writeable($config['path']) || mkdir($config['path'], 0777, true); |
|||
session('backup_config', $config); |
|||
|
|||
//生成备份文件信息
|
|||
$file = array( |
|||
'name' => date('Ymd-His'), |
|||
'part' => 1, |
|||
); |
|||
session('backup_file', $file); |
|||
|
|||
//缓存要备份的表
|
|||
session('backup_tables', $tables); |
|||
|
|||
//创建备份文件
|
|||
$database = new DatabaseUtil($file, $config); |
|||
if (false !== $database->create()) { |
|||
$tab = array('id' => 0, 'start' => 0); |
|||
success_jump('初始化成功', '', array('tables' => $tables, 'tab' => $tab)); |
|||
} |
|||
error_jump('初始化失败,备份文件创建失败'); |
|||
} |
|||
$id = request('id'); |
|||
$start = request('start'); |
|||
//备份数据
|
|||
if (is_numeric($id) && is_numeric($start)) { |
|||
error_jump('参数错误'); |
|||
} |
|||
$tables = session('backup_tables'); |
|||
//备份指定表
|
|||
$database = new DatabaseUtil(session('backup_file'), session('backup_config')); |
|||
$start = $database->backup($tables[$id], $start); |
|||
if (false === $start) { //出错
|
|||
error_jump('备份出错'); |
|||
} elseif (0 === $start) { //下一表
|
|||
if (isset($tables[++$id])) { |
|||
$tab = array('id' => $id, 'start' => 0); |
|||
success_jump('备份完成', '', array('tab' => $tab)); |
|||
} else { //备份完成,清空缓存
|
|||
unlink(session('backup_config.path') . 'backup_database.lock'); |
|||
session('backup_tables', null); |
|||
session('backup_file', null); |
|||
session('backup_config', null); |
|||
success_jump('备份完成'); |
|||
} |
|||
} else { |
|||
$tab = array('id' => $id, 'start' => $start[0]); |
|||
$rate = floor(100 * ($start[0] / $start[1])); |
|||
success_jump("正在备份...({$rate}%)", '', array('tab' => $tab)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 还原数据库 |
|||
*/ |
|||
public function import($time = 0, $part = null, $start = null) |
|||
{ |
|||
if (is_numeric($time) && is_null($part) && is_null($start)) { //初始化
|
|||
//获取备份文件信息
|
|||
$name = date('Ymd-His', $time) . '-*.sql*'; |
|||
$path = realpath(C('DB_PATH')) . DIRECTORY_SEPARATOR . $name; |
|||
$files = glob($path); |
|||
$list = array(); |
|||
foreach ($files as $name) { |
|||
$basename = basename($name); |
|||
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d'); |
|||
$gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename); |
|||
$list[$match[6]] = array($match[6], $name, $gz); |
|||
} |
|||
ksort($list); |
|||
|
|||
//检测文件正确性
|
|||
$last = end($list); |
|||
if (count($list) === $last[0]) { |
|||
session('backup_list', $list); //缓存备份列表
|
|||
success_jump('初始化完成', '', array('part' => 1, 'start' => 0)); |
|||
} else { |
|||
error_jump('备份文件可能已经损坏,请检查'); |
|||
} |
|||
} elseif (is_numeric($part) && is_numeric($start)) { |
|||
$list = session('backup_list'); |
|||
$db = new DatabaseUtil($list[$part], array( |
|||
'path' => realpath(C('DB_PATH')) . DIRECTORY_SEPARATOR, |
|||
'compress' => $list[$part][2] |
|||
)); |
|||
|
|||
$start = $db->import($start); |
|||
|
|||
if (false === $start) { |
|||
error_jump('还原数据出错'); |
|||
} elseif (0 === $start) { //下一卷
|
|||
if (isset($list[++$part])) { |
|||
$data = array('part' => $part, 'start' => 0); |
|||
success_jump("正在还原...#{$part}", '', $data); |
|||
} else { |
|||
session('backup_list', null); |
|||
success_jump('还原完成'); |
|||
} |
|||
} else { |
|||
$data = array('part' => $part, 'start' => $start[0]); |
|||
if ($start[1]) { |
|||
$rate = floor(100 * ($start[0] / $start[1])); |
|||
success_jump("正在还原...#{$part} ({$rate}%)", '', $data); |
|||
} else { |
|||
$data['gz'] = 1; |
|||
success_jump("正在还原...#{$part}", '', $data); |
|||
} |
|||
} |
|||
} else { |
|||
error_jump('参数错误'); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Home; |
|||
|
|||
use App\Http\Controllers\Home\CommonController; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Http\Request; |
|||
use App\Common\Helper; |
|||
|
|||
class AdController extends BaseController |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
public function detail($id) |
|||
{ |
|||
$where = function ($query) use ($id) { |
|||
$query->where('id', '=', $id)->orWhere('flag', '=', $id); |
|||
}; |
|||
$post = cache("index_ad_detail_$id"); |
|||
if (!$post) { |
|||
$time = time(); |
|||
$post = DB::table('ad')->where($where)->first(); |
|||
if (!$post) { |
|||
exit('not found'); |
|||
} |
|||
if ($post->is_expire == 1 && $post->end_time < $time) { |
|||
exit('expired'); |
|||
} |
|||
cache("index_ad_detail_$id", $post, 2592000); |
|||
} |
|||
|
|||
if (Helper::is_mobile_access()) { |
|||
if ($post->content_wap) { |
|||
exit($post->content_wap); |
|||
} |
|||
} |
|||
exit($post->content); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,149 @@ |
|||
<?php |
|||
namespace App\Http\Logic; |
|||
use App\Common\ReturnData; |
|||
use App\Http\Model\Ad; |
|||
use App\Http\Requests\AdRequest; |
|||
use Validator; |
|||
|
|||
class AdLogic extends BaseLogic |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
public function getModel() |
|||
{ |
|||
return new Ad(); |
|||
} |
|||
|
|||
public function getValidate($data, $scene_name) |
|||
{ |
|||
//数据验证
|
|||
$validate = new AdRequest(); |
|||
return Validator::make($data, $validate->getSceneRules($scene_name), $validate->getSceneRulesMessages()); |
|||
} |
|||
|
|||
//列表
|
|||
public function getList($where = array(), $order = '', $field = '*', $offset = '', $limit = '') |
|||
{ |
|||
$res = $this->getModel()->getList($where, $order, $field, $offset, $limit); |
|||
|
|||
if($res['count'] > 0) |
|||
{ |
|||
foreach($res['list'] as $k=>$v) |
|||
{ |
|||
$res['list'][$k] = $this->getDataView($v); |
|||
} |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//分页html
|
|||
public function getPaginate($where = array(), $order = '', $field = '*', $limit = '') |
|||
{ |
|||
$res = $this->getModel()->getPaginate($where, $order, $field, $limit); |
|||
|
|||
if($res->count() > 0) |
|||
{ |
|||
foreach($res as $k=>$v) |
|||
{ |
|||
$res[$k] = $this->getDataView($v); |
|||
} |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//全部列表
|
|||
public function getAll($where = array(), $order = '', $field = '*', $limit = '') |
|||
{ |
|||
$res = $this->getModel()->getAll($where, $order, $field, $limit); |
|||
|
|||
if($res) |
|||
{ |
|||
foreach($res as $k=>$v) |
|||
{ |
|||
$res[$k] = $this->getDataView($v); |
|||
} |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//详情
|
|||
public function getOne($where = array(), $field = '*') |
|||
{ |
|||
$res = $this->getModel()->getOne($where, $field); |
|||
if(!$res){return false;} |
|||
|
|||
$res = $this->getDataView($res); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//添加
|
|||
public function add($data = array(), $type=0) |
|||
{ |
|||
if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} |
|||
|
|||
//添加时间
|
|||
$time = time(); |
|||
if (!(isset($data['add_time']) && !empty($data['add_time']))) { |
|||
$data['add_time'] = $time; |
|||
} |
|||
|
|||
$validator = $this->getValidate($data, 'add'); |
|||
if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} |
|||
|
|||
$res = $this->getModel()->add($data,$type); |
|||
if($res){return ReturnData::create(ReturnData::SUCCESS,$res);} |
|||
|
|||
return ReturnData::create(ReturnData::FAIL); |
|||
} |
|||
|
|||
//修改
|
|||
public function edit($data, $where = array()) |
|||
{ |
|||
if(empty($data)){return ReturnData::create(ReturnData::SUCCESS);} |
|||
|
|||
//更新时间
|
|||
$time = time(); |
|||
if (!(isset($data['add_time']) && !empty($data['add_time']))) { |
|||
$data['add_time'] = $time; |
|||
} |
|||
|
|||
$validator = $this->getValidate($data, 'edit'); |
|||
if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} |
|||
|
|||
$res = $this->getModel()->edit($data,$where); |
|||
if($res){return ReturnData::create(ReturnData::SUCCESS,$res);} |
|||
|
|||
return ReturnData::create(ReturnData::FAIL); |
|||
} |
|||
|
|||
//删除
|
|||
public function del($where) |
|||
{ |
|||
if(empty($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} |
|||
|
|||
$validator = $this->getValidate($where,'del'); |
|||
if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} |
|||
|
|||
$res = $this->getModel()->del($where); |
|||
if($res){return ReturnData::create(ReturnData::SUCCESS,$res);} |
|||
|
|||
return ReturnData::create(ReturnData::FAIL); |
|||
} |
|||
|
|||
/** |
|||
* 数据获取器 |
|||
* @param array $data 要转化的数据 |
|||
* @return array |
|||
*/ |
|||
private function getDataView($data = array()) |
|||
{ |
|||
return getDataAttr($this->getModel(),$data); |
|||
} |
|||
} |
@ -0,0 +1,164 @@ |
|||
<?php |
|||
namespace App\Http\Model; |
|||
use DB; |
|||
use Log; |
|||
|
|||
class Ad extends BaseModel |
|||
{ |
|||
//广告
|
|||
|
|||
protected $table = 'ad'; |
|||
public $timestamps = false; |
|||
protected $hidden = array(); |
|||
protected $guarded = array(); //$guarded包含你不想被赋值的字段数组。
|
|||
|
|||
public function getDb() |
|||
{ |
|||
return DB::table($this->table); |
|||
} |
|||
|
|||
/** |
|||
* 列表 |
|||
* @param array $where 查询条件 |
|||
* @param string $order 排序 |
|||
* @param string $field 字段 |
|||
* @param int $offset 偏移量 |
|||
* @param int $limit 取多少条 |
|||
* @return array |
|||
*/ |
|||
public function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 15) |
|||
{ |
|||
$model = $this->getDb(); |
|||
if($where){$model = $model->where($where);} |
|||
|
|||
$res['count'] = $model->count(); |
|||
$res['list'] = array(); |
|||
|
|||
if($res['count'] > 0) |
|||
{ |
|||
if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}} |
|||
if($order){$model = parent::getOrderByData($model, $order);} |
|||
if($offset){}else{$offset = 0;} |
|||
if($limit){}else{$limit = 15;} |
|||
|
|||
$res['list'] = $model->skip($offset)->take($limit)->get(); |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 分页,用于前端html输出 |
|||
* @param array $where 查询条件 |
|||
* @param string $order 排序 |
|||
* @param string $field 字段 |
|||
* @param int $limit 每页几条 |
|||
* @param int $page 当前第几页 |
|||
* @return array |
|||
*/ |
|||
public function getPaginate($where = array(), $order = '', $field = '*', $limit = 15) |
|||
{ |
|||
$res = $this->getDb(); |
|||
|
|||
if($where){$res = $res->where($where);} |
|||
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|||
if($order){$res = parent::getOrderByData($res, $order);} |
|||
if($limit){}else{$limit = 15;} |
|||
|
|||
return $res->paginate($limit); |
|||
} |
|||
|
|||
/** |
|||
* 查询全部 |
|||
* @param array $where 查询条件 |
|||
* @param string $order 排序 |
|||
* @param string $field 字段 |
|||
* @param int $limit 取多少条 |
|||
* @return array |
|||
*/ |
|||
public function getAll($where = array(), $order = '', $field = '*', $limit = '', $offset = '') |
|||
{ |
|||
$res = $this->getDb(); |
|||
|
|||
if($where){$res = $res->where($where);} |
|||
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|||
if($order){$res = parent::getOrderByData($res, $order);} |
|||
if($offset){$res = $res->skip($offset);} |
|||
if($limit){$res = $res->take($limit);} |
|||
|
|||
$res = $res->get(); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 获取一条 |
|||
* @param array $where 条件 |
|||
* @param string $field 字段 |
|||
* @return array |
|||
*/ |
|||
public function getOne($where, $field = '*') |
|||
{ |
|||
$res = $this->getDb(); |
|||
|
|||
if($where){$res = $res->where($where);} |
|||
if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} |
|||
|
|||
$res = $res->first(); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 添加 |
|||
* @param array $data 数据 |
|||
* @return int |
|||
*/ |
|||
public function add(array $data,$type = 0) |
|||
{ |
|||
if($type==0) |
|||
{ |
|||
// 新增单条数据并返回主键值
|
|||
return self::insertGetId(parent::filterTableColumn($data,$this->table)); |
|||
} |
|||
elseif($type==1) |
|||
{ |
|||
/** |
|||
* 添加单条数据 |
|||
* $data = ['foo' => 'bar', 'bar' => 'foo']; |
|||
* 添加多条数据 |
|||
* $data = [ |
|||
* ['foo' => 'bar', 'bar' => 'foo'], |
|||
* ['foo' => 'bar1', 'bar' => 'foo1'], |
|||
* ['foo' => 'bar2', 'bar' => 'foo2'] |
|||
* ]; |
|||
*/ |
|||
return self::insert($data); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 修改 |
|||
* @param array $data 数据 |
|||
* @param array $where 条件 |
|||
* @return int |
|||
*/ |
|||
public function edit($data, $where = array()) |
|||
{ |
|||
$res = $this->getDb(); |
|||
return $res->where($where)->update(parent::filterTableColumn($data, $this->table)); |
|||
} |
|||
|
|||
/** |
|||
* 删除 |
|||
* @param array $where 条件 |
|||
* @return bool |
|||
*/ |
|||
public function del($where) |
|||
{ |
|||
$res = $this->getDb(); |
|||
$res = $res->where($where)->delete(); |
|||
|
|||
return $res; |
|||
} |
|||
} |
@ -0,0 +1,102 @@ |
|||
<?php |
|||
namespace App\Http\Requests; |
|||
|
|||
class AdRequest extends BaseRequest |
|||
{ |
|||
//总的验证规则
|
|||
protected $rules = [ |
|||
'id' => 'required|integer', |
|||
'name' => 'required|max:60', |
|||
'description' => 'max:255', |
|||
'flag' => 'max:30', |
|||
'is_expire' => 'between:0,3', |
|||
'start_time' => 'integer', |
|||
'end_time' => 'integer|min:start_time', |
|||
'add_time' => 'required|integer', |
|||
]; |
|||
|
|||
//总的自定义错误信息
|
|||
protected $messages = [ |
|||
'id.required' => 'ID不能为空', |
|||
'id.integer' => 'ID必须是数字', |
|||
'id.gt' => 'ID格式不正确', |
|||
'name.required' => '名称不能为空', |
|||
'name.max' => '名称不能超过60个字符', |
|||
'description.max' => '描述不能超过255个字符', |
|||
'flag.max' => '标识不能超过30个字符', |
|||
'is_expire.between' => '0永不过期', |
|||
'start_time.integer' => '投放开始时间格式不正确', |
|||
'end_time.integer' => '投放结束时间格式不正确', |
|||
'end_time.min' => '投放结束时间格式不正确', |
|||
'add_time.required' => '添加时间不能为空', |
|||
'add_time.integer' => '添加时间格式不正确', |
|||
'add_time.gt' => '添加时间格式不正确', |
|||
]; |
|||
|
|||
//场景验证规则
|
|||
protected $scene = [ |
|||
'add' => ['name', 'description', 'flag', 'is_expire', 'start_time', 'end_time', 'add_time'], |
|||
'edit' => ['name', 'description', 'flag', 'is_expire', 'start_time', 'end_time', 'add_time'], |
|||
'del' => ['id'], |
|||
]; |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return true; //修改为true
|
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return $this->rules; |
|||
} |
|||
|
|||
/** |
|||
* 获取被定义验证规则的错误消息. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function messages() |
|||
{ |
|||
return $this->messages; |
|||
} |
|||
|
|||
//获取场景验证规则
|
|||
public function getSceneRules($name, $fields = null) |
|||
{ |
|||
$res = array(); |
|||
|
|||
if(!isset($this->scene[$name])) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
$scene = $this->scene[$name]; |
|||
if($fields != null && is_array($fields)) |
|||
{ |
|||
$scene = $fields; |
|||
} |
|||
|
|||
foreach($scene as $k=>$v) |
|||
{ |
|||
if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];} |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
//获取场景验证规则自定义错误信息
|
|||
public function getSceneRulesMessages() |
|||
{ |
|||
return $this->messages; |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
* |
|||
!.gitignore |
43
lqycms.sql
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,74 @@ |
|||
@extends('admin.layouts.app') |
|||
@section('title', '广告添加') |
|||
|
|||
@section('content') |
|||
<script language="javascript" type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script> |
|||
<h5 class="sub-header"><a href="/fladmin/ad">广告列表</a> > 添加广告</h5> |
|||
|
|||
<form id="addarc" method="post" action="/fladmin/ad/add" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }} |
|||
<table class="table table-striped table-bordered"> |
|||
<tbody> |
|||
<tr> |
|||
<td align="right"><font color="red">*</font>名称:</td> |
|||
<td><input name="name" type="text" id="name" value="" class="required" style="width:30%" placeholder="在此输入名称"></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;">描述:</td> |
|||
<td><textarea name="description" rows="3" id="description" style="width:60%;vertical-align:middle;"></textarea></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right">广告位标识:</td> |
|||
<td><input name="flag" type="text" id="flag" value="" style="width:185px" class=""></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right">时间限制:</td> |
|||
<td> |
|||
<input type="radio" value='0' name="is_expire" checked /> 永不过期 |
|||
<input type="radio" value='1' name="is_expire" /> 在设内时间内有效 |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right">投放开始时间:</td> |
|||
<td colspan="2"><input autocomplete="off" name="start_time" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" id="start_time" style="width:185px" value="<?php echo date('Y-m-d H:i:s'); ?>"> 投放结束时间:<input autocomplete="off" name="end_time" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" id="end_time" style="width:185px" value="<?php echo date('Y-m-d H:i:s'); ?>"></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;"><font color="red">*</font>广告内容:</td> |
|||
<td><textarea name="content" rows="5" id="content" style="width:60%;vertical-align:middle;"></textarea></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;">广告内容-移动端:</td> |
|||
<td><textarea name="content_wap" rows="5" id="content_wap" style="width:60%;vertical-align:middle;"></textarea></td> |
|||
</tr> |
|||
<tr> |
|||
<td colspan="2"><button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button> <button type="reset" class="btn btn-default" value="Reset">重置(Reset)</button></td> |
|||
</tr> |
|||
</tbody></table></form><!-- 表单结束 --> |
|||
<script> |
|||
$(function(){ |
|||
$(".required").blur(function(){ |
|||
var $parent = $(this).parent(); |
|||
$parent.find(".formtips").remove(); |
|||
if(this.value=="") |
|||
{ |
|||
$parent.append(' <small class="formtips onError"><font color="red">不能为空!</font></small>'); |
|||
} |
|||
else |
|||
{ |
|||
$parent.append(' <small class="formtips onSuccess"><font color="green">OK</font></small>'); |
|||
} |
|||
}); |
|||
|
|||
//重置
|
|||
$('#addarc input[type="reset"]').click(function(){ |
|||
$(".formtips").remove(); |
|||
}); |
|||
|
|||
$("#addarc").submit(function(){ |
|||
$(".required").trigger('blur'); |
|||
var numError = $('#addarc .onError').length; |
|||
|
|||
if(numError){return false;} |
|||
}); |
|||
}); |
|||
</script> |
|||
@endsection |
@ -0,0 +1,74 @@ |
|||
@extends('admin.layouts.app') |
|||
@section('title', '广告修改') |
|||
|
|||
@section('content') |
|||
<script language="javascript" type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script> |
|||
<h5 class="sub-header"><a href="/fladmin/ad">广告列表</a> > 广告修改</h5> |
|||
|
|||
<form id="addarc" method="post" action="/fladmin/ad/edit" role="form" enctype="multipart/form-data" class="table-responsive">{{ csrf_field() }} |
|||
<table class="table table-striped table-bordered"> |
|||
<tbody> |
|||
<tr> |
|||
<td align="right"><font color="red">*</font>名称:</td> |
|||
<td><input name="name" type="text" id="name" value="<?php echo $post->name; ?>" class="required" style="width:30%" placeholder="在此输入名称"><input style="display:none;" name="id" type="text" id="id" value="<?php echo $id; ?>"></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;">描述:</td> |
|||
<td><textarea name="description" rows="3" id="description" style="width:60%;vertical-align:middle;"><?php echo $post->description; ?></textarea></td>
|
|||
</tr> |
|||
<tr> |
|||
<td align="right">广告位标识:</td> |
|||
<td><input name="flag" type="text" id="flag" value="<?php echo $post->flag; ?>" style="width:185px" class=""></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right">时间限制:</td> |
|||
<td> |
|||
<input type="radio" value='0' name="is_expire" <?php if ($post->is_expire == 0) { echo 'checked'; } ?> /> 永不过期
|
|||
<input type="radio" value='1' name="is_expire" <?php if ($post->is_expire == 1) { echo 'checked'; } ?> /> 在设内时间内有效
|
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right">投放开始时间:</td> |
|||
<td colspan="2"><input autocomplete="off" name="start_time" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" id="start_time" style="width:185px" value="<?php echo $post->start_time; ?>"> 投放结束时间:<input autocomplete="off" name="end_time" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" id="end_time" style="width:185px" value="<?php echo $post->end_time; ?>"></td> |
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;"><font color="red">*</font>广告内容:</td> |
|||
<td><textarea name="content" rows="5" id="content" style="width:60%;vertical-align:middle;"><?php echo $post->content; ?></textarea></td>
|
|||
</tr> |
|||
<tr> |
|||
<td align="right" style="vertical-align:middle;">广告内容-移动端:</td> |
|||
<td><textarea name="content_wap" rows="5" id="content_wap" style="width:60%;vertical-align:middle;"><?php echo $post->content_wap; ?></textarea></td>
|
|||
</tr> |
|||
<tr> |
|||
<td colspan="2"><button type="submit" class="btn btn-success" value="Submit">保存(Submit)</button> <button type="reset" class="btn btn-default" value="Reset">重置(Reset)</button></td> |
|||
</tr> |
|||
</tbody></table></form><!-- 表单结束 --> |
|||
<script> |
|||
$(function(){ |
|||
$(".required").blur(function(){ |
|||
var $parent = $(this).parent(); |
|||
$parent.find(".formtips").remove(); |
|||
if(this.value=="") |
|||
{ |
|||
$parent.append(' <small class="formtips onError"><font color="red">不能为空!</font></small>'); |
|||
} |
|||
else |
|||
{ |
|||
$parent.append(' <small class="formtips onSuccess"><font color="green">OK</font></small>'); |
|||
} |
|||
}); |
|||
|
|||
//重置
|
|||
$('#addarc input[type="reset"]').click(function(){ |
|||
$(".formtips").remove(); |
|||
}); |
|||
|
|||
$("#addarc").submit(function(){ |
|||
$(".required").trigger('blur'); |
|||
var numError = $('#addarc .onError').length; |
|||
|
|||
if(numError){return false;} |
|||
}); |
|||
}); |
|||
</script> |
|||
@endsection |
@ -0,0 +1,26 @@ |
|||
@extends('admin.layouts.app') |
|||
@section('title', '广告列表') |
|||
|
|||
@section('content') |
|||
<h2 class="sub-header">广告管理</h2>[ <a href="/fladmin/ad/add">添加广告</a> ]<br><br> |
|||
|
|||
<form name="listarc"><div class="table-responsive"><table class="table table-striped table-hover"> |
|||
<thead><tr> |
|||
<th>ID</th> |
|||
<th>名称</th> |
|||
<th>是否限时</th> |
|||
<th>结束时间</th> |
|||
<th>管理</th> |
|||
</tr></thead> |
|||
<tbody> |
|||
<?php if ($list) { foreach ($list as $row) { ?><tr>
|
|||
<td><?php echo $row->id; ?></td>
|
|||
<td><?php echo $row->name; ?></td>
|
|||
<td><?php if ($row->is_expire == 0) { echo '不限时间'; } else { echo '限时标记'; } ?></td>
|
|||
<td><?php if ($row->end_time > 0) { echo date('Y-m-d', $row->end_time); } ?></td>
|
|||
<td><a href="/fladmin/ad/edit?id=<?php echo $row->id; ?>">修改</a> | <a onclick="delconfirm('/fladmin/ad/del?id=<?php echo $row->id; ?>')" href="javascript:;">删除</a></td> |
|||
</tr><?php } } ?>
|
|||
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 --> |
|||
|
|||
<nav aria-label="Page navigation">{{ $list->links() }}</nav> |
|||
@endsection |
@ -0,0 +1,86 @@ |
|||
@extends('admin.layouts.app') |
|||
@section('title', '数据库备份') |
|||
|
|||
@section('content') |
|||
<h2 class="sub-header">数据库备份 <small class="badge"><?php echo count($list); ?> 条</small></h2>
|
|||
|
|||
<form name="listarc"><div class="table-responsive"><table class="table table-striped table-hover"> |
|||
<thead><tr> |
|||
<th>选择</th> |
|||
<th>表名</th> |
|||
<th>数据量</th> |
|||
<th>数据大小</th> |
|||
<th>创建时间</th> |
|||
<th>备份状态</th> |
|||
<th>操作</th> |
|||
</tr></thead> |
|||
<tbody> |
|||
<?php $backup_path = base_path() . DIRECTORY_SEPARATOR . 'database_backup' . DIRECTORY_SEPARATOR; if ($list) { foreach ($list as $k=>$v) { ?><tr>
|
|||
<td><input name="arcID" type="checkbox" value="<?php echo $v["name"]; ?>" class="np"></td> |
|||
<td><?php echo $v["name"]; ?></td>
|
|||
<td><?php echo $v["rows"]; ?></td>
|
|||
<td><?php echo format_bytes($v["data_length"]); ?></td>
|
|||
<td><?php echo $v["create_time"]; ?></td>
|
|||
<td><?php $filename = $backup_path . $v["name"] . '.sql'; if (file_exists($filename)) { echo '<font color="green">已备份</font>'; } else { echo '<font color="red">未备份</font>'; } ?></td>
|
|||
<td><a href="/fladmin/database/optimize?tables=<?php echo $v["name"]; ?>">优化表</a> <a href="/fladmin/database/repair?tables=<?php echo $v["name"]; ?>">修复表</a> <a href="/fladmin/database/tables_backup?tables=<?php echo $v["name"]; ?>">备份</a> </td> |
|||
</tr><?php } } ?>
|
|||
<tr> |
|||
<td colspan="8"> |
|||
<a href="javascript:selAll('arcID')" class="coolbg">反选</a> |
|||
<a href="javascript:backup_database()" class="coolbg">立即备份</a> |
|||
<a href="javascript:optimize()" class="coolbg">优化表</a> |
|||
<a href="javascript:repair()" class="coolbg">修复表</a> |
|||
<!-- <a href="javascript:recovery()" class="coolbg">数据还原</a> --> |
|||
</td> |
|||
</tr> |
|||
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 --> |
|||
|
|||
<script> |
|||
//备份数据库
|
|||
function backup_database() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要备份的表'); |
|||
return; |
|||
} |
|||
|
|||
if (confirm("确定要执行此操作吗")) { |
|||
location = "/fladmin/database/tables_backup?tables=" + checkvalue; |
|||
} |
|||
} |
|||
//优化表
|
|||
function optimize() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要优化的表'); |
|||
return; |
|||
} |
|||
location = "/fladmin/database/optimize?tables=" + checkvalue; |
|||
} |
|||
//修复表
|
|||
function repair() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue == '') { |
|||
alert('请选择要修复的表'); |
|||
return; |
|||
} |
|||
location = "/fladmin/database/repair?tables=" + checkvalue; |
|||
} |
|||
//数据还原
|
|||
function recovery() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要还原的表'); |
|||
return; |
|||
} |
|||
|
|||
if (confirm("确定要执行此操作吗")) { |
|||
location = "/fladmin/database/export?tables=" + checkvalue; |
|||
} |
|||
} |
|||
</script> |
|||
@endsection |
@ -0,0 +1,86 @@ |
|||
{extend name="public/base" /} |
|||
{block name="title"}数据库备份{/block} |
|||
|
|||
{block name="content"} |
|||
<h2 class="sub-header">数据库备份 <small class="badge"><?php echo count($list); ?> 条</small></h2> |
|||
|
|||
<form name="listarc"><div class="table-responsive"><table class="table table-striped table-hover"> |
|||
<thead><tr> |
|||
<th>选择</th> |
|||
<th>表名</th> |
|||
<th>数据量</th> |
|||
<th>数据大小</th> |
|||
<th>创建时间</th> |
|||
<th>备份状态</th> |
|||
<th>操作</th> |
|||
</tr></thead> |
|||
<tbody> |
|||
<?php $backup_path = ROOT_PATH . 'database_backup' . DIRECTORY_SEPARATOR; if ($list) { foreach ($list as $k=>$v) { ?><tr> |
|||
<td><input name="arcID" type="checkbox" value="<?php echo $v["name"]; ?>" class="np"></td> |
|||
<td><?php echo $v["name"]; ?></td> |
|||
<td><?php echo $v["rows"]; ?></td> |
|||
<td>{$v.data_length|format_bytes}</td> |
|||
<td><?php echo $v["create_time"]; ?></td> |
|||
<td><?php $filename = $backup_path . $v["name"] . '.sql'; if (file_exists($filename)) { echo '<font color="green">已备份</font>'; } else { echo '<font color="red">未备份</font>'; } ?></td> |
|||
<td><a href="{:url('optimize')}?tables=<?php echo $v["name"]; ?>">优化表</a> <a href="{:url('repair')}?tables=<?php echo $v["name"]; ?>">修复表</a> <a href="{:url('tables_backup')}?tables=<?php echo $v["name"]; ?>">备份</a> </td> |
|||
</tr><?php } } ?> |
|||
<tr> |
|||
<td colspan="8"> |
|||
<a href="javascript:selAll('arcID')" class="coolbg">反选</a> |
|||
<a href="javascript:backup_database()" class="coolbg">立即备份</a> |
|||
<a href="javascript:optimize()" class="coolbg">优化表</a> |
|||
<a href="javascript:repair()" class="coolbg">修复表</a> |
|||
<!-- <a href="javascript:recovery()" class="coolbg">数据还原</a> --> |
|||
</td> |
|||
</tr> |
|||
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 --> |
|||
|
|||
<script> |
|||
//备份数据库 |
|||
function backup_database() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要备份的表'); |
|||
return; |
|||
} |
|||
|
|||
if (confirm("确定要执行此操作吗")) { |
|||
location = "{:url('tables_backup')}?tables=" + checkvalue; |
|||
} |
|||
} |
|||
//优化表 |
|||
function optimize() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要优化的表'); |
|||
return; |
|||
} |
|||
location = "{:url('optimize')}?tables=" + checkvalue; |
|||
} |
|||
//修复表 |
|||
function repair() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue == '') { |
|||
alert('请选择要修复的表'); |
|||
return; |
|||
} |
|||
location = "{:url('repair')}?tables=" + checkvalue; |
|||
} |
|||
//数据还原 |
|||
function recovery() |
|||
{ |
|||
var checkvalue = getItems(); |
|||
if (checkvalue=='') { |
|||
alert('请选择要还原的表'); |
|||
return; |
|||
} |
|||
|
|||
if (confirm("确定要执行此操作吗")) { |
|||
location = "{:url('export')}?tables=" + checkvalue; |
|||
} |
|||
} |
|||
</script> |
|||
{/block} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue