Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
更新ThinkPHP版本为5.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan1994 committed Mar 8, 2017
1 parent 0a21599 commit 2c65112
Show file tree
Hide file tree
Showing 268 changed files with 3,493 additions and 2,015 deletions.
7 changes: 6 additions & 1 deletion application/admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ protected function filterId($filterData, $error = '该记录不能执行此操
* $map['_order_by'] 可强制设置排序字段(field asc|desc[,filed2 asc|desc...]或者false)
* $map['_paginate'] 是否开启分页传入false可以关闭分页
* $map['_model'] 可强制指定模型
* $map['_func'] 匿名函数可以给模型设置属性比如关联aliasfunction ($model) {$model->alias('table')->join(...)}
*
* @param Model|Db $model 数据对象
* @param array $map 过滤条件
Expand All @@ -300,13 +301,17 @@ protected function filterId($filterData, $error = '该记录不能执行此操
protected function datalist($model, $map, $field = null, $sortBy = '', $asc = false, $return = false, $paginate = true)
{
// 私有字段指定特殊条件查询时要删除
$protectField = ['_table', '_relation', '_field', '_order_by', '_paginate', '_model'];
$protectField = ['_table', '_relation', '_field', '_order_by', '_paginate', '_model', '_func'];

// 通过过滤器指定模型
if (isset($map['_model'])) {
$model = $map['_model'];
}

if (isset($map['_func']) && ($map['_func'] instanceof \Closure)) {
call_user_func_array($map['_func'], [$model]);
}

// 排序字段 默认为主键名
$order = $this->request->param('_order') ?: (empty($sortBy) ? $model->getPk() : $sortBy);

Expand Down
88 changes: 86 additions & 2 deletions application/admin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ function reset_by_key($arr, $key)

/**
* 节点遍历
* @param $list
*
* @param $list
* @param string $pk
* @param string $pid
* @param string $child
* @param int $root
* @param int $root
*
* @return array
*/
function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0)
Expand All @@ -255,10 +257,16 @@ function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root
// 创建基于主键的数组引用
$refer = [];
foreach ($list as $key => $data) {
if ($data instanceof \think\Model) {
$list[$key] = $data->toArray();
}
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
if (!isset($list[$key][$child])) {
$list[$key][$child] = [];
}
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
Expand Down Expand Up @@ -418,3 +426,79 @@ function format_bytes($size, $delimiter = '')

return round($size, 2) . $delimiter . $units[$i];
}

/**
* 生成一定长度的UUID
*
* @param int $length
*
* @return string
*/
function get_uuid($length = 16)
{
mt_srand((double)microtime()*10000);
$uuid = sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
$str = base64_encode($uuid);
return substr($str, mt_rand(0, strlen($str) - $length), $length);
}

/**
* 根据模型名称获取模型
*
* @param $modelName
*
* @return \think\Model|\think\db\Query
*/
function get_model($modelName)
{
if (false !== strpos($modelName, '\\')) {
// 指定模型类
$db = new $modelName;
} else {
try {
$db = \think\Loader::model($modelName);
} catch (\think\exception\ClassNotFoundException $e) {
$db = \think\Db::name($modelName);
}
}

return $db;
}

/**
* 验证规则扩展
*/
\think\Validate::extend([
// 验证字段是否在模型中存在
'checkExist' => function($value, $rule, $data, $field) {
if (is_string($rule)) {
$rule = explode(',', $rule);
}
$db = get_model($rule[0]);
$key = isset($rule[1]) ? $rule[1] : $field;

if (strpos($key, '^')) {
// 支持多个字段验证
$fields = explode('^', $key);
foreach ($fields as $key) {
$map[$key] = $data[$key];
}
} elseif (strpos($key, '=')) {
parse_str($key, $map);
} else {
$map[$key] = $data[$field];
}

$pk = strval(isset($rule[3]) ? $rule[3] : $db->getPk());
if (isset($rule[2])) {
$map[$pk] = ['neq', $rule[2]];
} elseif (isset($data[$pk])) {
$map[$pk] = ['neq', $data[$pk]];
}

if ($db->where($map)->field($pk)->find()) {
return true;
}
return false;
}
]);
6 changes: 3 additions & 3 deletions application/admin/controller/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ protected function filter(&$map)
$map['realname'] = ["like", "%" . $this->request->param('realname') . "%"];
}
if ($this->request->param('account')) {
$map['realname'] = ["like", "%" . $this->request->param('account') . "%"];
$map['account'] = ["like", "%" . $this->request->param('account') . "%"];
}
if ($this->request->param('email')) {
$map['realname'] = ["like", "%" . $this->request->param('email') . "%"];
$map['email'] = ["like", "%" . $this->request->param('email') . "%"];
}
if ($this->request->param('mobile')) {
$map['realname'] = ["like", "%" . $this->request->param('mobile') . "%"];
$map['mobile'] = ["like", "%" . $this->request->param('mobile') . "%"];
}
}

Expand Down
8 changes: 6 additions & 2 deletions application/admin/controller/LoginLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use app\common\model\LoginLog as ModelLoginLog;
use app\common\model\AdminUser as ModelAdminUser;

class LoginLog extends Controller
{
Expand All @@ -42,7 +44,9 @@ protected function filter(&$map)

// 设置属性
$map['_table'] = "login_log";
$map['_relation'] = "user";
$map['_order_by'] = "login_log.id desc";
$map['_func'] = function (ModelLoginLog $model) use ($map) {
$model->alias($map['_table'])->join(ModelAdminUser::getTable() . ' user', 'login_log.uid = user.id');
};
}
}
}
2 changes: 1 addition & 1 deletion application/admin/controller/NodeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NodeMap extends Controller
protected function filter(&$map)
{
if ($this->request->param("map")) {
$map['map'] = ["like", "%" . $this->request->param("map") . "%"];
$map['action|module|controller'] = ["like", "%" . $this->request->param("map") . "%"];
}
if ($this->request->param("comment")) {
$map['comment'] = ["like", "%" . $this->request->param("comment") . "%"];
Expand Down
2 changes: 1 addition & 1 deletion application/admin/view/admin_group/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="page-bootstrap">{$page}</div>
</div>
{/block}
{block name='script'}}
{block name='script'}
<script>

</script>
Expand Down
2 changes: 1 addition & 1 deletion application/admin/view/index/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li><a href="javascript:;" onclick="logout()">退出</a></li>
</ul>
</li>
<li id="Hui-msg"> <a href="javascript:;" onclick="layer.msg('这个功能自己做咯,反正不难')" title="消息"><span class="badge badge-danger">1</span><i class="Hui-iconfont" style="font-size:18px">&#xe68a;</i></a> </li>
<li id="Hui-msg"> <a href="javascript:;" onclick="layer.msg('这个功能自己做')" title="消息"><span class="badge badge-danger">1</span><i class="Hui-iconfont" style="font-size:18px">&#xe68a;</i></a> </li>
<li id="Hui-skin" class="dropDown right dropDown_hover"> <a href="javascript:;" class="dropDown_A" title="换肤"><i class="Hui-iconfont" style="font-size:18px">&#xe62a;</i></a>
<ul class="dropDown-menu menu radius box-shadow">
<li><a href="javascript:;" data-val="default" title="默认(黑色)">默认(黑色)</a></li>
Expand Down
2 changes: 1 addition & 1 deletion application/admin/view/node_map/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{volist name="list" id="vo"}
<tr class="text-c">
<td><input type="checkbox" name="id[]" value="{$vo.id}"></td>
<td>{$vo.module}</td>
<td>{$vo.module|high_light=$Request.param.map}</td>
<td>{$vo.controller|high_light=$Request.param.map}</td>
<td>{$vo.action|high_light=$Request.param.map}</td>
<td>{$vo.method}</td>
Expand Down
2 changes: 1 addition & 1 deletion application/admin/widget/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function menu($list)
$html = "";
$generate = function ($list, $controller = "") use (&$html, &$generate) {
$html .= "<li>";
if (isset($list['_child'])) {
if (isset($list['_child']) && $list['_child']) {
$controller .= $list['name'] . ".";
$html .= '<a class="sub-menu-title" data-title="' . $list['title'] . '" href="javascript:;"><b>+</b>' . $list['title'] . '</a>';
$html .= '<ul class="sub-menu-list">';
Expand Down
4 changes: 2 additions & 2 deletions application/common/model/LoginLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class LoginLog extends Model
{
public function user()
{
return $this->hasOne('AdminUser', "id", "uid")->setAlias(["id" => "uuid"]);
return $this->hasOne('AdminUser', "id", "uid", ["id" => "uuid"]);
}
}
}
2 changes: 2 additions & 0 deletions application/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
'auto_timestamp' => false,
// 是否需要进行SQL性能分析
'sql_explain' => false,
// 是否开启自动时间戳转换
'auto_datetime_format' => false,
];
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions extend/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,12 @@ private function parseCode()
case "checkbox":
if ($form['type'] == "radio") {
// radio类型的控件进行编辑状态赋值checkbox类型控件请自行根据情况赋值
$setChecked[] = tab(2) . '$("[name=\'' . $form['name'] . '\'][value=\'{$vo.' . $form['name'] . ' ?? \'' . $form['default'] . '\'}\']").attr("checked", true);';
$setChecked[] = tab(2) . '$("[name=\'' . $form['name'] . '\'][value=\'{$vo.' . $form['name'] . ' ?? \'' . $form['default'] . '\'}\']").prop("checked", true);';
} else {
$setChecked[] = tab(2) . 'var checks = \'' . $form['default'] . '\'.split(",");' . "\n"
. tab(2) . 'if (checks.length > 0){' . "\n"
. tab(3) . 'for (var i in checks){' . "\n"
. tab(4) . '$("[name=\'' . $form['name'] . '[]\'][value=\'"+checks[i]+"\']").attr("checked", true);' . "\n"
. tab(4) . '$("[name=\'' . $form['name'] . '[]\'][value=\'"+checks[i]+"\']").prop("checked", true);' . "\n"
. tab(3) . '}' . "\n"
. tab(2) . '}';
}
Expand Down
3 changes: 2 additions & 1 deletion public/static/admin/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ $(function () {
});

// 绑定刷新事件
var baseUrl = location.href;
$(document).on('click', '.btn-refresh', function () {
location.replace(location.href);
window.location.href = baseUrl;
})
});

Expand Down
2 changes: 0 additions & 2 deletions thinkphp/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ install:
script:
## LINT
- find . -path ./vendor -prune -o -type f -name \*.php -exec php -l {} \;
## PHP_CodeSniffer
- vendor/bin/phpcs --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --standard=PSR2 --ignore="vendor/*" ./
## PHP Copy/Paste Detector
- vendor/bin/phpcpd --verbose --exclude vendor ./ || true
## PHPLOC
Expand Down
4 changes: 3 additions & 1 deletion thinkphp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ThinkPHP 5.0
===============

[![StyleCI](https://styleci.io/repos/48530411/shield?style=flat&branch=master)](https://styleci.io/repos/48530411)
[![Build Status](https://travis-ci.org/top-think/framework.svg?branch=master)](https://travis-ci.org/top-think/framework)
[![codecov.io](http://codecov.io/github/top-think/framework/coverage.svg?branch=master)](http://codecov.io/github/github/top-think/framework?branch=master)
[![Total Downloads](https://poser.pugx.org/topthink/framework/downloads)](https://packagist.org/packages/topthink/framework)
Expand All @@ -27,10 +28,11 @@ ThinkPHP5在保持快速开发和大道至简的核心理念不变的同时,PH
+ 真正惰性加载
+ 分布式环境支持
+ 支持Composer
+ 支持MongoDb

> ThinkPHP5的运行环境要求PHP5.4以上。
详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5)
详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5) 以及[ThinkPHP5入门系列教程](http://www.kancloud.cn/special/thinkphp5_quickstart)

## 目录结构

Expand Down
4 changes: 2 additions & 2 deletions thinkphp/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

define('THINK_VERSION', '5.0.4');
define('THINK_VERSION', '5.0.7');
define('THINK_START_TIME', microtime(true));
define('THINK_START_MEM', memory_get_usage());
define('EXT', '.php');
Expand Down
Loading

0 comments on commit 2c65112

Please sign in to comment.