From 0398e5bd804ceaf089d219adee34ecbd8adc8314 Mon Sep 17 00:00:00 2001 From: molong Date: Fri, 1 Jul 2016 18:04:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E6=A0=B8=E6=9B=B4=E6=96=B0=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E6=96=87=E4=BB=B6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- application/admin/view/content/book.html | 124 ------ application/admin/view/user/index.html | 6 + application/common/behavior/InitHook.php | 2 +- application/common/controller/Fornt.php | 4 +- application/common/model/MemberExtend.php | 20 + application/common/model/User.php | 51 ++- application/common/validate/Member.php | 10 +- .../common/view/default/public/close.html | 16 + application/config.php | 9 +- application/database.php | 2 +- application/index/controller/Book.php | 70 ---- application/index/controller/Cart.php | 53 --- application/user/controller/Order.php | 27 +- application/user/controller/Profile.php | 7 +- application/user/static/css/member_login.css | 2 +- application/user/view/login/index.html | 2 +- core/base.php | 6 +- core/convention.php | 4 +- core/helper.php | 374 ++++++++++-------- core/library/think/App.php | 12 +- core/library/think/Debug.php | 50 ++- core/library/think/db/Query.php | 2 +- core/library/think/db/builder/Mysql.php | 1 + core/library/think/db/connector/Oracle.php | 17 +- .../think/debug/{trace => }/Console.php | 12 +- core/library/think/debug/{trace => }/Html.php | 8 +- .../think/{log/driver => debug}/Socket.php | 10 +- core/library/think/debug/Trace.php | 63 --- core/library/think/log/driver/File.php | 4 +- core/library/think/log/driver/Sae.php | 4 +- 31 files changed, 426 insertions(+), 551 deletions(-) delete mode 100644 application/admin/view/content/book.html create mode 100644 application/common/model/MemberExtend.php create mode 100644 application/common/view/default/public/close.html delete mode 100644 application/index/controller/Book.php delete mode 100644 application/index/controller/Cart.php rename core/library/think/debug/{trace => }/Console.php (95%) rename core/library/think/debug/{trace => }/Html.php (95%) rename core/library/think/{log/driver => debug}/Socket.php (97%) delete mode 100644 core/library/think/debug/Trace.php diff --git a/README.md b/README.md index 7a1baf85..5e233fd8 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,8 @@ * 第一步、修改数据库配置文件 application/database.php * 第二步、通过数据库导入工具,比如phpmyadmin导入数据,数据sql文件data/sql.sql +* 第三步、登录后台,后台地址 http://域名/admin -初始账号:admin,密码:admin888 \ No newline at end of file +> 系统必须开启伪静态 + +初始账号:admin,密码:admin888 \ No newline at end of file diff --git a/application/admin/view/content/book.html b/application/admin/view/content/book.html deleted file mode 100644 index c604855b..00000000 --- a/application/admin/view/content/book.html +++ /dev/null @@ -1,124 +0,0 @@ -{extend name="public/base"/} -{block name="style"} - - - - - -{/block} -{block name="body"} -
-
-
-

{$meta_title}

-
-
- 新 增 - -
-
-
-
-
-
-
-
书名:
- -
-
-
-
-
发布时间:
-
- -
-
- -
-
-
-
-
-
标准类型:
- -
-
-
-
-
编号:
- -
-
-
- -
-
-
-
- -
- - - - - {volist name="grid['grids']" id="item"} - - {/volist} - - - - - {if condition="empty($list)"} - {php} - $cow = count($grid['grids'])+2; - {/php} - - - - {else/} - {volist name="list" id="item"} - - - {volist name="grid['grids']" id="vo"} - {if isset($vo['format'])} - - {else/} - - {/if} - {/volist} - - - {/volist} - {/if} - -
{$item['title']}操作
暂无数据!
{$item[$vo['field'][0]]|$vo['format']}{$item[$vo['field'][0]]} - {if isset($item['status'])} - {if $item['status']} - 取消审核 - {else/} - 审核 - {/if} - {/if} - 编辑 - 删除 -
-
- {$page} -
-
-
-{/block} -{block name="script"} - -{/block} \ No newline at end of file diff --git a/application/admin/view/user/index.html b/application/admin/view/user/index.html index 19da79ff..868f8658 100644 --- a/application/admin/view/user/index.html +++ b/application/admin/view/user/index.html @@ -20,6 +20,9 @@ Email + + 手机号码 + 创建时间 @@ -40,6 +43,9 @@ {$item['email']} + + {$item['mobile']} + {$item['reg_time']|date='Y-m-d',###} {if condition="$item['status']"} diff --git a/application/common/behavior/InitHook.php b/application/common/behavior/InitHook.php index e0a9f190..2dd2ee0e 100644 --- a/application/common/behavior/InitHook.php +++ b/application/common/behavior/InitHook.php @@ -3,7 +3,7 @@ namespace app\common\behavior; class InitHook { - public function run(&$content){ + public function run(&$request){ //初始化某些配置信息 if (cache('db_config_data')) { diff --git a/application/common/controller/Fornt.php b/application/common/controller/Fornt.php index 3aaba06f..18f45505 100644 --- a/application/common/controller/Fornt.php +++ b/application/common/controller/Fornt.php @@ -16,8 +16,10 @@ class Fornt extends Base{ //判读是否为关闭网站 if (\think\Config::get('web_site_close')) { - return $this->fetch('common@default/public/close');exit(); + header("Content-type:text/html;charset=utf-8"); + echo $this->fetch('common@default/public/close');exit(); } + //设置SEO $this->setSeo(); diff --git a/application/common/model/MemberExtend.php b/application/common/model/MemberExtend.php new file mode 100644 index 00000000..39851077 --- /dev/null +++ b/application/common/model/MemberExtend.php @@ -0,0 +1,20 @@ + +// +---------------------------------------------------------------------- + +namespace app\common\model; + +/** +* 用户模型 +*/ +class MemberExtend extends Base{ + + protected $type = array( + 'uid' => 'integer', + ); +} \ No newline at end of file diff --git a/application/common/model/User.php b/application/common/model/User.php index 3bc0f18e..c1e1400c 100644 --- a/application/common/model/User.php +++ b/application/common/model/User.php @@ -12,19 +12,14 @@ namespace app\common\model; /** * 用户模型 */ -class User extends \think\model\Merge{ +class User extends Base{ protected $name = "Member"; - protected static $relationModel = array('MemberExtend'); protected $createTime = 'reg_time'; protected $updateTime = 'last_login_time'; - protected $fk = 'user_id'; - protected $mapFields = array( - 'uid' => 'Member.uid', - 'user_id' => 'MemberExtend.uid', - ); + protected $type = array( - 'id' => 'integer', + 'uid' => 'integer', ); protected $insert = array('salt', 'password', 'status', 'reg_time'); protected $update = array(); @@ -54,11 +49,21 @@ class User extends \think\model\Merge{ array('name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''), array('name'=>'sex','title'=>'性别','type'=>'select','option'=>array('0'=>'保密','1'=>'男','2'=>'女'),'help'=>''), array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'), + array('name'=>'mobile','title'=>'联系电话','type'=>'text','help'=>''), array('name'=>'qq','title'=>'QQ','type'=>'text','help'=>''), - array('name'=>'score','title'=>'用户积分','type'=>'text','help'=>''), array('name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''), ); + public $userextend = array( + array('name'=>'company','title'=>'单位名称','type'=>'text','help'=>''), + array('name'=>'company_addr','title'=>'单位地址','type'=>'text','help'=>''), + array('name'=>'company_contact','title'=>'单位联系人','type'=>'text','help'=>''), + array('name'=>'company_zip','title'=>'单位邮编','type'=>'text','help'=>''), + array('name'=>'company_depart','title'=>'所属部门','type'=>'text','help'=>''), + array('name'=>'company_post','title'=>'所属职务','type'=>'text','help'=>''), + array('name'=>'company_type','title'=>'单位类型','type'=>'select', 'option'=>'', 'help'=>''), + ); + protected function setStatusAttr($value){ return 1; } @@ -72,6 +77,11 @@ class User extends \think\model\Merge{ */ public function login($username = '', $password = '', $type = 1){ $map = array(); + if (\think\Validate::is($username,'email')) { + $type = 2; + }elseif (preg_match("/^1[34578]{1}\d{9}$/",$username)) { + $type = 3; + } switch ($type) { case 1: $map['username'] = $username; @@ -111,11 +121,6 @@ class User extends \think\model\Merge{ * @param integer $user 用户信息数组 */ function register($username, $password, $repassword, $email, $isautologin = true){ - if ($password !== $repassword) { - $this->error = "密码和确认密码不相同"; - return false; - } - $data['username'] = $username; $data['salt'] = rand_string(6); $data['password'] = $password; @@ -123,6 +128,7 @@ class User extends \think\model\Merge{ $result = $this->validate(true)->save($data); if ($result) { $this->data['uid'] = $result; + $this->extend()->save($data); if ($isautologin) { $this->autoLogin($this->data); } @@ -147,8 +153,8 @@ class User extends \think\model\Merge{ 'last_login_time' => time(), 'last_login_ip' => get_client_ip(1), ); - $this->db()->where(array('uid'=>$user['uid']))->update($data); - $user = $this->db()->where(array('uid'=>$user['uid']))->find(); + $this->where(array('uid'=>$user['uid']))->update($data); + $user = $this->where(array('uid'=>$user['uid']))->find(); /* 记录登录SESSION和COOKIES */ $auth = array( @@ -167,7 +173,7 @@ class User extends \think\model\Merge{ } public function getInfo($uid){ - $data = $this->db()->where(array('uid'=>$uid))->find(); + $data = $this->where(array('uid'=>$uid))->find(); if ($data) { return $data->toArray(); }else{ @@ -178,7 +184,12 @@ class User extends \think\model\Merge{ public function change(){ $data = input('post.'); if ($data['uid']) { - return $this->save($data, array('uid'=>$data['uid'])); + $result = $this->validate('member.edit')->save($data, array('uid'=>$data['uid'])); + if ($result) { + $result = $this->extend->save($data, array('uid'=>$data['uid'])); + }else{ + return false; + } }else{ $this->error = "非法操作!"; return false; @@ -211,6 +222,10 @@ class User extends \think\model\Merge{ return $this->db()->where(array('uid'=>$uid))->update($data); } + public function extend(){ + return $this->hasOne('MemberExtend', 'uid'); + } + protected function checkPassword($username,$password){ if (!$username || !$password) { return false; diff --git a/application/common/validate/Member.php b/application/common/validate/Member.php index 6067ce17..c0e8bf4c 100644 --- a/application/common/validate/Member.php +++ b/application/common/validate/Member.php @@ -15,17 +15,21 @@ namespace app\common\validate; class Member extends \think\Validate{ protected $rule = array( - 'username' => 'require|unique:member|/^[a-zA-Z]\w{0,39}$/', - 'email' => 'require|unique:member|email', + 'username' => 'require|unique:member|/^[a-zA-Z]\w{0,39}$/', + 'email' => 'require|unique:member|email', + 'mobile' => 'unique:member', + 'repassword'=>'require|confirm:password' ); protected $message = array( 'username.require' => '用户名必须', 'username.unique' => '用户名已存在', 'email.require' => '邮箱必须', 'email.unique' => '邮箱已存在', + 'mobile.unique' => '手机号已存在', + 'repassword.require' => '确认密码和密码必须一致', ); protected $scene = array( - //'add' => 'username,email', + 'edit' => 'email,mobile', ); } \ No newline at end of file diff --git a/application/common/view/default/public/close.html b/application/common/view/default/public/close.html new file mode 100644 index 00000000..e328c2c1 --- /dev/null +++ b/application/common/view/default/public/close.html @@ -0,0 +1,16 @@ + + + + +SentCMS网站管理系统 - PowerBy TenSent + + + +
+ 本站已关闭! +
+ + \ No newline at end of file diff --git a/application/config.php b/application/config.php index 46764f2d..a31664e5 100644 --- a/application/config.php +++ b/application/config.php @@ -92,9 +92,14 @@ return array( ), 'log' => array( - // 日志记录方式,支持 file socket trace sae + // 日志记录方式,支持 file sae 'type' => 'file', // 日志保存目录 'path' => LOG_PATH, - ) + ), + // 页面Trace信息 + // 'trace' =>array( + // //支持Html,Console 设为false则不显示 + // 'type' => false, + // ) ); \ No newline at end of file diff --git a/application/database.php b/application/database.php index ef2a84d1..08744d7c 100644 --- a/application/database.php +++ b/application/database.php @@ -15,7 +15,7 @@ return array( // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 - 'database' => 'nmg_www', + 'database' => 'sentcms_www', // 数据库用户名 'username' => 'root', // 数据库密码 diff --git a/application/index/controller/Book.php b/application/index/controller/Book.php deleted file mode 100644 index e0af7d2b..00000000 --- a/application/index/controller/Book.php +++ /dev/null @@ -1,70 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace app\index\controller; -use app\common\controller\Fornt; - -class Book extends Fornt{ - - public function _initialize(){ - parent::_initialize(); - $this->book = model('Book'); - } - - public function index(){ - $map = $this->search(); - $order = 'id desc'; - $list = $this->book->where($map)->order($order)->paginate(10); - - $data = array( - 'list' => $list, - 'page' => $list->render() - ); - $this->assign($data); - return $this->fetch(); - } - - //图书详情 - public function detail($id = 0){ - $map['id'] = $id; - - $info = $this->book->where($map)->find(); - - $data = array( - 'info' => $info, - ); - $this->assign($data); - return $this->fetch(); - } - - //图书搜索条件组织 - protected function search(){ - $map = array(); - $data = $this->request->post(); - $data['is_show_height'] = 0; - if (isset($data['book_name']) && $data['book_name']) { - $map['book_name'] = array("LIKE", "%" . $data['book_name'] . "%"); - } - if (isset($data['book_no']) && $data['book_no']) { - $map['book_no'] = array("LIKE", "%" . $data['book_no'] . "%"); - $data['is_show_height'] = 1; - } - if (isset($data['stand_class']) && $data['stand_class']) { - $map['stand_class'] = $data['stand_class']; - $data['is_show_height'] = 1; - } - if (isset($data['create_time'][0]) && isset($data['create_time'][1]) && $data['create_time'][0] && $data['create_time'][1]) { - $map['create_time'] = array('BETWEEN',$data['create_time']); - $data['is_show_height'] = 1; - } - - $this->assign($data); - return $map; - } -} \ No newline at end of file diff --git a/application/index/controller/Cart.php b/application/index/controller/Cart.php deleted file mode 100644 index a4e78b5d..00000000 --- a/application/index/controller/Cart.php +++ /dev/null @@ -1,53 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace app\index\controller; -use app\common\controller\Fornt; - -class Cart extends Fornt{ - - public function _initialize(){ - $this->cart = new \com\Cart(); - } - - //购物车 - public function index(){ - $list = $this->cart->all(); - - $data = array( - 'list' => $list, - ); - $this->assign($data); - return $this->fetch(); - } - - //加入购物车 - public function add($id, $num){ - if ($num > 0) { - $this->cart->addItem($id, $num); - } - $info['code'] = 1; - $info['num'] = $this->cart->getCount(); - return $info; - } - - //加入购物车 - public function del($id){ - $this->cart->delItem($id); - $info['code'] = 1; - $info['data'] = array('num'=>$this->cart->getCount()); - return $info; - } - - //购物车统计 - public function count(){ - $data = array('info'=>$this->cart->getCount()); - echo json_encode($data); - } -} \ No newline at end of file diff --git a/application/user/controller/Order.php b/application/user/controller/Order.php index 8dfa3a2a..df0fcd2d 100644 --- a/application/user/controller/Order.php +++ b/application/user/controller/Order.php @@ -51,20 +51,27 @@ class Order extends User{ if (!$order_id) { $price_count = '0.00'; $list = $this->cart->all(); - foreach ($list as $key => $value) { - $price_count += $value['price_count']; + if ($list) { + foreach ($list as $key => $value) { + $price_count += $value['price_count']; + } + + $data = array( + 'list' => $list, + 'price_count' => $price_count + ); + + //生成订单 + $map['id'] = $this->order->createOrder($data); } - - $data = array( - 'list' => $list, - 'price_count' => $price_count - ); - - //生成订单 - $map['id'] = $this->order->createOrder($data); }else{ $map['id'] = $order_id; } + + if (!isset($map['id'])) { + return $this->error('非法操作!'); + } + $order = $this->order->where($map)->find(); $data = array( diff --git a/application/user/controller/Profile.php b/application/user/controller/Profile.php index f2f88c5c..a5ef42ea 100644 --- a/application/user/controller/Profile.php +++ b/application/user/controller/Profile.php @@ -24,8 +24,13 @@ class Profile extends User{ } }else{ $group['基础资料'] = $user->useredit; + $group['扩展信息'] = $user->userextend; - $info = $user->getInfo(session('user_auth.uid')); + $info = $user->where(array('uid'=>session('user_auth.uid')))->find(); + + if ($info->extend) { + $info = array_merge($info->toArray(), $info->extend->toArray()); + } $data = array( 'fieldGroup' => $group, 'info' => $info diff --git a/application/user/static/css/member_login.css b/application/user/static/css/member_login.css index f040519d..2ccc62cd 100644 --- a/application/user/static/css/member_login.css +++ b/application/user/static/css/member_login.css @@ -79,7 +79,7 @@ time { color: #777;} .nc-login-form dl { background-color: #FFF; width: 398px; height: 52px; margin-top: -1px; border: solid 1px #E6E6E6; position: relative; z-index: 1; overflow: hidden;} .nc-login-form dl.focus { border-color: #7ABD54; z-index: 3;} .nc-login-form dl.error { border-color: #F87622 !important; z-index: 2;} -.nc-login-form dl dt { font-size: 14px; line-height: 20px; color: #666; width: 72px; padding: 16px 0 16px 20px; float: left;} +.nc-login-form dl dt { font-size: 14px; line-height: 20px; color: #333333; width: 72px; padding: 16px 0 16px 20px; float: left;} .nc-login-form dl dd { height: 28px; float: left; padding: 12px 0;} .nc-login-form dl dd .text { font-family: "microsoft yahei"; font-size: 14px; line-height: 28px; width: 290px; height: 28px; padding: 0; border: none 0;} diff --git a/application/user/view/login/index.html b/application/user/view/login/index.html index bf196a1a..396c27d2 100644 --- a/application/user/view/login/index.html +++ b/application/user/view/login/index.html @@ -39,7 +39,7 @@
账   号:
- +
diff --git a/core/base.php b/core/base.php index 78b3f920..66d53e9f 100644 --- a/core/base.php +++ b/core/base.php @@ -9,9 +9,9 @@ // | Author: liu21st // +---------------------------------------------------------------------- -define('THINK_VERSION', '5.0.0 RC3'); -define('START_TIME', number_format(microtime(true), 8, '.', '')); -define('START_MEM', memory_get_usage()); +define('THINK_VERSION', '5.0.0 RC4'); +define('THINK_START_TIME', number_format(microtime(true), 8, '.', '')); +define('THINK_START_MEM', memory_get_usage()); define('EXT', '.php'); define('DS', DIRECTORY_SEPARATOR); defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS); diff --git a/core/convention.php b/core/convention.php index 3ad29bb5..efcf27fc 100644 --- a/core/convention.php +++ b/core/convention.php @@ -140,7 +140,7 @@ return [ // +---------------------------------------------------------------------- 'log' => [ - // 日志记录方式,支持 file socket sae + // 日志记录方式,支持 file sae 'type' => 'File', // 日志保存目录 'path' => LOG_PATH, @@ -150,7 +150,7 @@ return [ // | Trace设置 // +---------------------------------------------------------------------- 'trace' => [ - //支持Html,Console 设为false则不显示 + // 支持Html Socket Console 设为false则不显示 'type' => false, ], diff --git a/core/helper.php b/core/helper.php index adaa31c1..6f630a72 100644 --- a/core/helper.php +++ b/core/helper.php @@ -33,9 +33,11 @@ use think\View; * @param string $ext 类库后缀 * @return boolean */ -function load_trait($class, $ext = EXT) -{ - return Loader::import($class, TRAIT_PATH, $ext); +if (!function_exists('load_trait')) { + function load_trait($class, $ext = EXT) + { + return Loader::import($class, TRAIT_PATH, $ext); + } } /** @@ -47,10 +49,12 @@ function load_trait($class, $ext = EXT) * * @throws Exception */ -function exception($msg, $code = 0, $exception = '') -{ - $e = $exception ?: '\think\Exception'; - throw new $e($msg, $code); +if (!function_exists('exception')) { + function exception($msg, $code = 0, $exception = '') + { + $e = $exception ?: '\think\Exception'; + throw new $e($msg, $code); + } } /** @@ -60,12 +64,14 @@ function exception($msg, $code = 0, $exception = '') * @param integer|string $dec 小数位 如果是m 表示统计内存占用 * @return mixed */ -function debug($start, $end = '', $dec = 6) -{ - if ('' == $end) { - Debug::remark($start); - } else { - return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec); +if (!function_exists('debug')) { + function debug($start, $end = '', $dec = 6) + { + if ('' == $end) { + Debug::remark($start); + } else { + return 'm' == $dec ? Debug::getRangeMem($start, $end) : Debug::getRangeTime($start, $end, $dec); + } } } @@ -76,9 +82,11 @@ function debug($start, $end = '', $dec = 6) * @param string $lang 语言 * @return mixed */ -function lang($name, $vars = [], $lang = '') -{ - return Lang::get($name, $vars, $lang); +if (!function_exists('lang')) { + function lang($name, $vars = [], $lang = '') + { + return Lang::get($name, $vars, $lang); + } } /** @@ -88,12 +96,14 @@ function lang($name, $vars = [], $lang = '') * @param string $range 作用域 * @return mixed */ -function config($name = '', $value = null, $range = '') -{ - if (is_null($value) && is_string($name)) { - return Config::get($name, $range); - } else { - return Config::set($name, $value, $range); +if (!function_exists('config')) { + function config($name = '', $value = null, $range = '') + { + if (is_null($value) && is_string($name)) { + return Config::get($name, $range); + } else { + return Config::set($name, $value, $range); + } } } @@ -104,28 +114,30 @@ function config($name = '', $value = null, $range = '') * @param string $filter 过滤方法 * @return mixed */ -function input($key, $default = null, $filter = null) -{ - if (0 === strpos($key, '?')) { - $key = substr($key, 1); - $has = true; - } - if ($pos = strpos($key, '.')) { - // 指定参数来源 - $method = substr($key, 0, $pos); - if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) { - $key = substr($key, $pos + 1); +if (!function_exists('input')) { + function input($key, $default = null, $filter = null) + { + if (0 === strpos($key, '?')) { + $key = substr($key, 1); + $has = true; + } + if ($pos = strpos($key, '.')) { + // 指定参数来源 + $method = substr($key, 0, $pos); + if (in_array($method, ['get', 'post', 'put', 'delete', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) { + $key = substr($key, $pos + 1); + } else { + $method = 'param'; + } } else { + // 默认为自动判断 $method = 'param'; } - } else { - // 默认为自动判断 - $method = 'param'; - } - if (isset($has)) { - return request()->has($key, $method, $default); - } else { - return request()->$method($key, $default, $filter); + if (isset($has)) { + return request()->has($key, $method, $default); + } else { + return request()->$method($key, $default, $filter); + } } } @@ -135,9 +147,11 @@ function input($key, $default = null, $filter = null) * @param array $data 传人的参数 * @return mixed */ -function widget($name, $data = []) -{ - return Loader::action($name, $data, 'widget'); +if (!function_exists('widget')) { + function widget($name, $data = []) + { + return Loader::action($name, $data, 'widget'); + } } /** @@ -147,9 +161,11 @@ function widget($name, $data = []) * @param bool $appendSuffix 是否添加类名后缀 * @return \think\Model */ -function model($name = '', $layer = 'model', $appendSuffix = false) -{ - return Loader::model($name, $layer, $appendSuffix); +if (!function_exists('model')) { + function model($name = '', $layer = 'model', $appendSuffix = false) + { + return Loader::model($name, $layer, $appendSuffix); + } } /** @@ -159,9 +175,11 @@ function model($name = '', $layer = 'model', $appendSuffix = false) * @param bool $appendSuffix 是否添加类名后缀 * @return \think\Validate */ -function validate($name = '', $layer = 'validate', $appendSuffix = false) -{ - return Loader::validate($name, $layer, $appendSuffix); +if (!function_exists('validate')) { + function validate($name = '', $layer = 'validate', $appendSuffix = false) + { + return Loader::validate($name, $layer, $appendSuffix); + } } /** @@ -170,9 +188,11 @@ function validate($name = '', $layer = 'validate', $appendSuffix = false) * @param array|string $config 数据库配置参数 * @return \think\db\Query */ -function db($name = '', $config = []) -{ - return Db::connect($config)->name($name); +if (!function_exists('db')) { + function db($name = '', $config = []) + { + return Db::connect($config)->name($name); + } } /** @@ -182,9 +202,11 @@ function db($name = '', $config = []) * @param bool $appendSuffix 是否添加类名后缀 * @return \think\Controller */ -function controller($name, $layer = 'controller', $appendSuffix = false) -{ - return Loader::controller($name, $layer, $appendSuffix); +if (!function_exists('controller')) { + function controller($name, $layer = 'controller', $appendSuffix = false) + { + return Loader::controller($name, $layer, $appendSuffix); + } } /** @@ -195,9 +217,11 @@ function controller($name, $layer = 'controller', $appendSuffix = false) * @param bool $appendSuffix 是否添加类名后缀 * @return mixed */ -function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) -{ - return Loader::action($url, $vars, $layer, $appendSuffix); +if (!function_exists('action')) { + function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) + { + return Loader::action($url, $vars, $layer, $appendSuffix); + } } /** @@ -207,9 +231,11 @@ function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) * @param string $ext 导入的文件扩展名 * @return boolean */ -function import($class, $baseUrl = '', $ext = EXT) -{ - return Loader::import($class, $baseUrl, $ext); +if (!function_exists('import')) { + function import($class, $baseUrl = '', $ext = EXT) + { + return Loader::import($class, $baseUrl, $ext); + } } /** @@ -218,9 +244,11 @@ function import($class, $baseUrl = '', $ext = EXT) * @param string $ext 类库后缀 * @return boolean */ -function vendor($class, $ext = EXT) -{ - return Loader::import($class, VENDOR_PATH, $ext); +if (!function_exists('vendor')) { + function vendor($class, $ext = EXT) + { + return Loader::import($class, VENDOR_PATH, $ext); + } } /** @@ -230,9 +258,11 @@ function vendor($class, $ext = EXT) * @param string $label 标签 默认为空 * @return void|string */ -function dump($var, $echo = true, $label = null) -{ - return Debug::dump($var, $echo, $label); +if (!function_exists('dump')) { + function dump($var, $echo = true, $label = null) + { + return Debug::dump($var, $echo, $label); + } } /** @@ -243,9 +273,11 @@ function dump($var, $echo = true, $label = null) * @param bool|string $domain 域名 * @return string */ -function url($url = '', $vars = '', $suffix = true, $domain = false) -{ - return Url::build($url, $vars, $suffix, $domain); +if (!function_exists('url')) { + function url($url = '', $vars = '', $suffix = true, $domain = false) + { + return Url::build($url, $vars, $suffix, $domain); + } } /** @@ -255,23 +287,25 @@ function url($url = '', $vars = '', $suffix = true, $domain = false) * @param string $prefix 前缀 * @return mixed */ -function session($name, $value = '', $prefix = null) -{ - if (is_array($name)) { - // 初始化 - Session::init($name); - } elseif (is_null($name)) { - // 清除 - Session::clear($value); - } elseif ('' === $value) { - // 判断或获取 - return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); - } elseif (is_null($value)) { - // 删除 - return Session::delete($name, $prefix); - } else { - // 设置 - return Session::set($name, $value, $prefix); +if (!function_exists('session')) { + function session($name, $value = '', $prefix = null) + { + if (is_array($name)) { + // 初始化 + Session::init($name); + } elseif (is_null($name)) { + // 清除 + Session::clear($value); + } elseif ('' === $value) { + // 判断或获取 + return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); + } elseif (is_null($value)) { + // 删除 + return Session::delete($name, $prefix); + } else { + // 设置 + return Session::set($name, $value, $prefix); + } } } @@ -282,23 +316,25 @@ function session($name, $value = '', $prefix = null) * @param mixed $option 参数 * @return mixed */ -function cookie($name, $value = '', $option = null) -{ - if (is_array($name)) { - // 初始化 - Cookie::init($name); - } elseif (is_null($name)) { - // 清除 - Cookie::clear($value); - } elseif ('' === $value) { - // 获取 - return Cookie::get($name); - } elseif (is_null($value)) { - // 删除 - return Cookie::delete($name); - } else { - // 设置 - return Cookie::set($name, $value, $option); +if (!function_exists('cookie')) { + function cookie($name, $value = '', $option = null) + { + if (is_array($name)) { + // 初始化 + Cookie::init($name); + } elseif (is_null($name)) { + // 清除 + Cookie::clear($value); + } elseif ('' === $value) { + // 获取 + return Cookie::get($name); + } elseif (is_null($value)) { + // 删除 + return Cookie::delete($name); + } else { + // 设置 + return Cookie::set($name, $value, $option); + } } } @@ -309,29 +345,31 @@ function cookie($name, $value = '', $option = null) * @param mixed $options 缓存参数 * @return mixed */ -function cache($name, $value = '', $options = null) -{ - if (is_array($options)) { - // 缓存操作的同时初始化 - Cache::connect($options); - } elseif (is_array($name)) { - // 缓存初始化 - return Cache::connect($name); - } - if ('' === $value) { - // 获取缓存 - return Cache::get($name); - } elseif (is_null($value)) { - // 删除缓存 - return Cache::rm($name); - } else { - // 缓存数据 +if (!function_exists('cache')) { + function cache($name, $value = '', $options = null) + { if (is_array($options)) { - $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 - } else { - $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 + // 缓存操作的同时初始化 + Cache::connect($options); + } elseif (is_array($name)) { + // 缓存初始化 + return Cache::connect($name); + } + if ('' === $value) { + // 获取缓存 + return Cache::get($name); + } elseif (is_null($value)) { + // 删除缓存 + return Cache::rm($name); + } else { + // 缓存数据 + if (is_array($options)) { + $expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间 + } else { + $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 + } + return Cache::set($name, $value, $expire); } - return Cache::set($name, $value, $expire); } } @@ -341,12 +379,14 @@ function cache($name, $value = '', $options = null) * @param string $level 日志级别 * @return void|array */ -function trace($log = '[think]', $level = 'log') -{ - if ('[think]' === $log) { - return Log::getLog(); - } else { - Log::record($log, $level); +if (!function_exists('trace')) { + function trace($log = '[think]', $level = 'log') + { + if ('[think]' === $log) { + return Log::getLog(); + } else { + Log::record($log, $level); + } } } @@ -354,9 +394,11 @@ function trace($log = '[think]', $level = 'log') * 获取当前Request对象实例 * @return Request */ -function request() -{ - return Request::instance(); +if (!function_exists('request')) { + function request() + { + return Request::instance(); + } } /** @@ -367,9 +409,11 @@ function request() * @param string $type * @return Response */ -function response($data = [], $code = 200, $header = [], $type = 'html') -{ - return Response::create($data, $type, $code, $header); +if (!function_exists('response')) { + function response($data = [], $code = 200, $header = [], $type = 'html') + { + return Response::create($data, $type, $code, $header); + } } /** @@ -379,9 +423,11 @@ function response($data = [], $code = 200, $header = [], $type = 'html') * @param integer $code 状态码 * @return \think\response\View */ -function view($template = '', $vars = [], $code = 200) -{ - return Response::create($template, 'view', $code)->vars($vars); +if (!function_exists('view')) { + function view($template = '', $vars = [], $code = 200) + { + return Response::create($template, 'view', $code)->vars($vars); + } } /** @@ -392,9 +438,11 @@ function view($template = '', $vars = [], $code = 200) * @param array $options 参数 * @return \think\response\Json */ -function json($data = [], $code = 200, $header = [], $options = []) -{ - return Response::create($data, 'json', $code, $header, $options); +if (!function_exists('json')) { + function json($data = [], $code = 200, $header = [], $options = []) + { + return Response::create($data, 'json', $code, $header, $options); + } } /** @@ -405,9 +453,11 @@ function json($data = [], $code = 200, $header = [], $options = []) * @param array $options 参数 * @return \think\response\Jsonp */ -function jsonp($data = [], $code = 200, $header = [], $options = []) -{ - return Response::create($data, 'jsonp', $code, $header, $options); +if (!function_exists('jsonp')) { + function jsonp($data = [], $code = 200, $header = [], $options = []) + { + return Response::create($data, 'jsonp', $code, $header, $options); + } } /** @@ -418,9 +468,11 @@ function jsonp($data = [], $code = 200, $header = [], $options = []) * @param array $options 参数 * @return \think\response\Xml */ -function xml($data = [], $code = 200, $header = [], $options = []) -{ - return Response::create($data, 'xml', $code, $header, $options); +if (!function_exists('xml')) { + function xml($data = [], $code = 200, $header = [], $options = []) + { + return Response::create($data, 'xml', $code, $header, $options); + } } /** @@ -430,13 +482,15 @@ function xml($data = [], $code = 200, $header = [], $options = []) * @param integer $code 状态码 * @return \think\response\Redirect */ -function redirect($url = [], $params = [], $code = 302) -{ - if (is_integer($params)) { - $code = $params; - $params = []; +if (!function_exists('redirect')) { + function redirect($url = [], $params = [], $code = 302) + { + if (is_integer($params)) { + $code = $params; + $params = []; + } + return Response::create($url, 'redirect', $code)->params($params); } - return Response::create($url, 'redirect', $code)->params($params); } /** @@ -445,7 +499,9 @@ function redirect($url = [], $params = [], $code = 302) * @param string $message 错误信息 * @param array $header 参数 */ -function abort($code, $message = null, $header = []) -{ - throw new \think\exception\HttpException($code, $message, null, $header); +if (!function_exists('abort')) { + function abort($code, $message = null, $header = []) + { + throw new \think\exception\HttpException($code, $message, null, $header); + } } diff --git a/core/library/think/App.php b/core/library/think/App.php index b881f921..b6438d04 100644 --- a/core/library/think/App.php +++ b/core/library/think/App.php @@ -12,7 +12,6 @@ namespace think; use think\Config; -use think\debug\Trace; use think\Exception; use think\exception\HttpException; use think\exception\HttpResponseException; @@ -145,19 +144,18 @@ class App $response = $data; } elseif (!is_null($data)) { // 默认自动识别响应输出类型 - $isAjax = $request->isAjax(); - $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); + $isAjax = $request->isAjax(); + $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type); } else { $response = Response::create(); } - // 监听app_end Hook::listen('app_end', $response); - - //注入Trace - self::$debug && Trace::inject($response); + + // Trace调试注入 + Debug::inject($response); return $response; } diff --git a/core/library/think/Debug.php b/core/library/think/Debug.php index 133d1d66..05695400 100644 --- a/core/library/think/Debug.php +++ b/core/library/think/Debug.php @@ -11,6 +11,13 @@ namespace think; +use think\Config; +use think\exception\ClassNotFoundException; +use think\Log; +use think\Request; +use think\Response; +use think\response\Redirect; + class Debug { // 区间时间信息 @@ -56,7 +63,7 @@ class Debug */ public static function getUseTime($dec = 6) { - return number_format((microtime(true) - START_TIME), $dec); + return number_format((microtime(true) - THINK_START_TIME), $dec); } /** @@ -97,7 +104,7 @@ class Debug */ public static function getUseMem($dec = 2) { - $size = memory_get_usage() - START_MEM; + $size = memory_get_usage() - THINK_START_MEM; $a = ['B', 'KB', 'MB', 'GB', 'TB']; $pos = 0; while ($size >= 1024) { @@ -177,4 +184,43 @@ class Debug } } + public static function inject(Response $response) + { + $config = Config::get('trace'); + $type = isset($config['type']) ? $config['type'] : 'Html'; + + if (false !== $type) { + $request = Request::instance(); + $accept = $request->header('accept'); + $contentType = $response->getHeader('Content-Type'); + $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type); + unset($config['type']); + if (class_exists($class)) { + $trace = new $class($config); + } else { + throw new ClassNotFoundException('class not exists:' . $class, $class); + } + + if ($response instanceof Redirect) { + //TODO 记录 + } elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + //TODO 记录 + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + //TODO 记录 + } else { + $output = $trace->output(Log::getLog()); + if (is_string($output)) { + // trace调试信息注入 + $content = $response->getContent(); + $pos = strripos($content, ''); + if (false !== $pos) { + $content = substr($content, 0, $pos) . $output . substr($content, $pos); + } else { + $content = $content . $output; + } + $response->content($content); + } + } + } + } } diff --git a/core/library/think/db/Query.php b/core/library/think/db/Query.php index 49604ac0..39943d6b 100644 --- a/core/library/think/db/Query.php +++ b/core/library/think/db/Query.php @@ -1820,7 +1820,7 @@ class Query if (empty($options['fetch_sql']) && !empty($options['cache'])) { // 判断查询缓存 $cache = $options['cache']; - if (true === $cache['key'] && !is_array($data)) { + if (true === $cache['key'] && !is_null($data) && !is_array($data)) { $key = 'think:' . $options['table'] . '|' . $data; } else { $key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options)); diff --git a/core/library/think/db/builder/Mysql.php b/core/library/think/db/builder/Mysql.php index 3f98adbe..d7427af7 100644 --- a/core/library/think/db/builder/Mysql.php +++ b/core/library/think/db/builder/Mysql.php @@ -18,6 +18,7 @@ use think\db\Builder; */ class Mysql extends Builder { + protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%'; /** * 字段和表名处理 diff --git a/core/library/think/db/connector/Oracle.php b/core/library/think/db/connector/Oracle.php index f50ec5f1..840ed44d 100644 --- a/core/library/think/db/connector/Oracle.php +++ b/core/library/think/db/connector/Oracle.php @@ -47,7 +47,7 @@ class Oracle extends Connection * @param string $sql sql指令 * @param array $bind 参数绑定 * @param boolean $getLastInsID 是否获取自增ID - * @param string $sequence 序列名 + * @param string $sequence 序列名 * @return integer * @throws \Exception * @throws \think\Exception @@ -60,16 +60,16 @@ class Oracle extends Connection } // 根据参数绑定组装最终的SQL语句 - $this->queryStr = $this->getBindSql($sql, $bind); + $this->queryStr = $this->getRealSql($sql, $bind); $flag = false; if (preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $sql, $match)) { - if(is_null($sequence)){ + if (is_null($sequence)) { $sequence = Config::get("db_sequence_prefix") . str_ireplace(Config::get("database.prefix"), "", $match[2]); } - $flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'"); + $flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'"); } - + //释放前次的查询结果 if (!empty($this->PDOStatement)) { $this->free(); @@ -89,7 +89,7 @@ class Oracle extends Connection $this->lastInsID = $this->linkID->lastInsertId(); if ($getLastInsID) { return $this->lastInsID; - } + } } return $this->numRows; } catch (\PDOException $e) { @@ -130,7 +130,7 @@ class Oracle extends Connection /** * 取得数据库的表信息(暂时实现取得用户表信息) * @access public - * @param string $dbName + * @param string $dbName * @return array */ public function getTables($dbName = '') @@ -155,7 +155,8 @@ class Oracle extends Connection return []; } - protected function supportSavepoint(){ + protected function supportSavepoint() + { return true; } } diff --git a/core/library/think/debug/trace/Console.php b/core/library/think/debug/Console.php similarity index 95% rename from core/library/think/debug/trace/Console.php rename to core/library/think/debug/Console.php index 0cbe12e6..6eacf23c 100644 --- a/core/library/think/debug/trace/Console.php +++ b/core/library/think/debug/Console.php @@ -9,7 +9,7 @@ // | Author: yangweijie // +---------------------------------------------------------------------- -namespace think\debug\trace; +namespace think\debug; use think\Cache; use think\Config; @@ -34,7 +34,7 @@ class Console } /** - * 日志写入接口 + * 调试输出接口 * @access public * @param array $log 日志信息 * @return bool @@ -42,9 +42,9 @@ class Console public function output(array $log = []) { // 获取基本信息 - $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); - $mem = number_format((memory_get_usage() - START_MEM) / 1024, 2); + $mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); if (isset($_SERVER['HTTP_HOST'])) { $uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; @@ -126,12 +126,12 @@ JS; } break; case '错误': - $msg = str_replace(PHP_EOL, '\n', $m); + $msg = str_replace("\n", '\n', $m); $style = 'color:#F4006B;font-size:14px;'; $line[] = "console.error(\"%c{$msg}\", \"{$style}\");"; break; case 'sql': - $msg = str_replace(PHP_EOL, '\n', $m); + $msg = str_replace("\n", '\n', $m); $style = "color:#009bb4;"; $line[] = "console.log(\"%c{$msg}\", \"{$style}\");"; break; diff --git a/core/library/think/debug/trace/Html.php b/core/library/think/debug/Html.php similarity index 95% rename from core/library/think/debug/trace/Html.php rename to core/library/think/debug/Html.php index 8e002567..7f16dc0e 100644 --- a/core/library/think/debug/trace/Html.php +++ b/core/library/think/debug/Html.php @@ -9,7 +9,7 @@ // | Author: liu21st // +---------------------------------------------------------------------- -namespace think\debug\trace; +namespace think\debug; use think\Cache; use think\Config; @@ -34,7 +34,7 @@ class Html } /** - * 日志写入接口 + * 调试输出接口 * @access public * @param array $log 日志信息 * @return bool @@ -43,9 +43,9 @@ class Html { // 获取基本信息 - $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); - $mem = number_format((memory_get_usage() - START_MEM) / 1024, 2); + $mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); // 页面Trace信息 if (isset($_SERVER['HTTP_HOST'])) { diff --git a/core/library/think/log/driver/Socket.php b/core/library/think/debug/Socket.php similarity index 97% rename from core/library/think/log/driver/Socket.php rename to core/library/think/debug/Socket.php index 2d423a5d..ae018a04 100644 --- a/core/library/think/log/driver/Socket.php +++ b/core/library/think/debug/Socket.php @@ -9,7 +9,7 @@ // | Author: luofei614 // +---------------------------------------------------------------------- -namespace think\log\driver; +namespace think\debug; /** * github: https://github.com/luofei614/SocketLog @@ -55,20 +55,20 @@ class Socket } /** - * 日志写入接口 + * 调试输出接口 * @access public * @param array $logs 日志信息 * @return bool */ - public function save(array $logs = []) + public function output(array $logs = []) { if (!$this->check()) { return false; } - $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / number_format($runtime, 8), 2); $time_str = " [运行时间:{$runtime}s][吞吐率:{$reqs}req/s]"; - $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); + $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); $memory_str = " [内存消耗:{$memory_use}kb]"; $file_load = " [文件加载:" . count(get_included_files()) . "]"; diff --git a/core/library/think/debug/Trace.php b/core/library/think/debug/Trace.php deleted file mode 100644 index f44b0b4f..00000000 --- a/core/library/think/debug/Trace.php +++ /dev/null @@ -1,63 +0,0 @@ - -// +---------------------------------------------------------------------- -namespace think\debug; - -use think\Config; -use think\exception\ClassNotFoundException; -use think\Log; -use think\Request; -use think\Response; -use think\response\Redirect; - -class Trace -{ - public static function inject(Response $response) - { - $config = Config::get('trace'); - - $type = isset($config['type']) ? $config['type'] : 'Html'; - - if ($type !== false) { - $request = Request::instance(); - $accept = $request->header('accept'); - $contentType = $response->getHeader('Content-Type'); - - $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\trace\\' . ucwords($type); - unset($config['type']); - if(class_exists($class)) { - $trace = new $class($config); - } else { - throw new ClassNotFoundException('class not exists:' . $class, $class); - } - - if ($response instanceof Redirect) { - //TODO 记录 - } elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) { - //TODO 记录 - } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { - //TODO 记录 - } else { - $output = $trace->output(Log::getLog()); - - $content = $response->getContent(); - - $pos = strripos($content, ''); - if (false !== $pos) { - $content = substr($content, 0, $pos) . $output . substr($content, $pos); - } else { - $content = $content . $output; - } - - $response->content($content); - } - } - } -} \ No newline at end of file diff --git a/core/library/think/log/driver/File.php b/core/library/think/log/driver/File.php index 76ade7ee..b3a077b2 100644 --- a/core/library/think/log/driver/File.php +++ b/core/library/think/log/driver/File.php @@ -54,10 +54,10 @@ class File } else { $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } - $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; - $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); + $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); $memory_str = " [内存消耗:{$memory_use}kb]"; $file_load = " [文件加载:" . count(get_included_files()) . "]"; diff --git a/core/library/think/log/driver/Sae.php b/core/library/think/log/driver/Sae.php index a45f3a62..c593c09e 100644 --- a/core/library/think/log/driver/Sae.php +++ b/core/library/think/log/driver/Sae.php @@ -33,10 +33,10 @@ class Sae } else { $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } - $runtime = number_format(microtime(true), 8, '.', '') - START_TIME; + $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; - $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); + $memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2); $memory_str = " [内存消耗:{$memory_use}kb]"; $file_load = " [文件加载:" . count(get_included_files()) . "]";