From 6460d64ceb8738cfd9867ce5dc24ba3c5776afdc Mon Sep 17 00:00:00 2001 From: molong Date: Mon, 11 Jul 2016 12:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=89=B9=E9=87=8F=E6=93=8D?= =?UTF-8?q?=E4=BD=9Cbug=E4=BF=AE=E5=A4=8D=20=E5=86=85=E6=A0=B8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Action.php | 44 +++++++----------- application/admin/controller/Ad.php | 8 ++-- application/admin/controller/Channel.php | 2 +- application/admin/controller/Content.php | 8 ++-- application/admin/controller/Group.php | 8 ++-- application/admin/controller/Link.php | 6 ++- application/admin/controller/Menu.php | 4 +- application/admin/controller/Seo.php | 6 +-- application/admin/view/action/index.html | 2 +- application/admin/view/action/log.html | 2 +- application/admin/view/group/access.html | 2 + application/common/controller/Base.php | 2 + application/common/controller/Upload.php | 50 +++++++++++++-------- application/config.php | 2 +- application/pay.php | 18 -------- core/library/think/Collection.php | 17 ++++--- core/library/think/Model.php | 46 ++++++++++++------- core/library/think/Url.php | 14 +----- core/library/think/paginator/Collection.php | 6 +-- 19 files changed, 119 insertions(+), 128 deletions(-) delete mode 100644 application/pay.php diff --git a/application/admin/controller/Action.php b/application/admin/controller/Action.php index 1ca70355..6cd2b553 100644 --- a/application/admin/controller/Action.php +++ b/application/admin/controller/Action.php @@ -103,23 +103,17 @@ class Action extends Admin { * @author colin */ public function del(){ - if (IS_POST) { - $ids = input('ids/a',array()); - $id = input('id',''); - array_push($ids, $id); - if(empty($ids)){ - return $this->error("非法操作!",''); - } - $map['id'] = array('IN',$ids); - $result = db('Action')->where($map)->delete(); - if ($result) { - action_log('delete_action', 'Action', $id, session('user_auth.uid')); - return $this->success('删除成功!'); - }else{ - return $this->error('删除失败!'); - } + $id = array_unique((array)$this->param['id']); + if(empty($id)){ + return $this->error("非法操作!",''); + } + $map['id'] = array('IN',$id); + $result = db('Action')->where($map)->delete(); + if ($result) { + action_log('delete_action', 'Action', $id, session('user_auth.uid')); + return $this->success('删除成功!'); }else{ - return $this->error("非法操作!"); + return $this->error('删除失败!'); } } @@ -128,15 +122,13 @@ class Action extends Admin { * @author colin */ public function setstatus(){ - $ids = input('ids/a',array()); - $id = input('id',''); - array_push($ids, $id); - if(empty($ids)){ + $id = array_unique((array)$this->param['id']); + if(empty($id)){ return $this->error("非法操作!",''); } $status = input('get.status','','trim,intval'); $message = !$status ? '禁用' : '启用'; - $map['id'] = array('IN',$ids); + $map['id'] = array('IN',$id); $result = db('Action')->where($map)->setField('status',$status); if ($result !== false) { action_log('setstatus_action', 'Action', $id, session('user_auth.uid')); @@ -193,17 +185,15 @@ class Action extends Admin { } /** * 删除日志 - * @param mixed $ids + * @param mixed $id * @author huajie */ public function dellog() { - $ids = input('ids/a',array()); - $id = input('id',''); - array_push($ids, $id); - if(empty($ids)){ + $id = array_unique((array)$this->param['id']); + if(empty($id)){ return $this->error("非法操作!",''); } - $map['id'] = array('IN',$ids); + $map['id'] = array('IN',$id); $res = db('ActionLog')->where($map)->delete(); if ($res !== false) { action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid')); diff --git a/application/admin/controller/Ad.php b/application/admin/controller/Ad.php index 37267573..cad47f8b 100644 --- a/application/admin/controller/Ad.php +++ b/application/admin/controller/Ad.php @@ -90,9 +90,9 @@ class Ad extends Admin { } public function del(){ - $id = input('id',''); + $id = array_unique((array)$this->param['id']); - if (!$id) { + if (empty($id)) { return $this->error("非法操作!"); } $map['id'] = array('IN',$id); @@ -175,9 +175,9 @@ class Ad extends Admin { } public function delad(){ - $id = input('id',''); + $id = array_unique((array)$this->param['id']); - if (!$id) { + if (empty($id)) { return $this->error("非法操作!"); } $map['id'] = array('IN',$id); diff --git a/application/admin/controller/Channel.php b/application/admin/controller/Channel.php index 375e7e28..86b68679 100644 --- a/application/admin/controller/Channel.php +++ b/application/admin/controller/Channel.php @@ -127,7 +127,7 @@ class Channel extends Admin{ * @author 麦当苗儿 */ public function del() { - $id = array_unique((array)input('id', 0)); + $id = array_unique((array)$this->param['id']); if (empty($id)) { return $this->error('请选择要操作的数据!'); diff --git a/application/admin/controller/Content.php b/application/admin/controller/Content.php index 421802e1..1d2234d7 100644 --- a/application/admin/controller/Content.php +++ b/application/admin/controller/Content.php @@ -145,14 +145,12 @@ class Content extends Admin{ * @author molong */ public function del(){ - $id = input('id','','trim'); - $ids = input('post.ids',array()); - array_push($ids, $id); - if (empty($ids)) { + $id = array_unique((array)$this->param['id']); + if (empty($id)) { return $this->error("非法操作!"); } - $map['id'] = array('IN',$ids); + $map['id'] = array('IN',$id); $result = $this->model->del($map); if ($result) { diff --git a/application/admin/controller/Group.php b/application/admin/controller/Group.php index 8218e53f..ee92c61f 100644 --- a/application/admin/controller/Group.php +++ b/application/admin/controller/Group.php @@ -97,11 +97,11 @@ class Group extends Admin { //会员分组删除控制器 public function del(){ - $id = input('id','','trim,intval'); - if (!$id) { + $id = array_unique((array)$this->param['id']); + if (empty($id)) { return $this->error("非法操作!"); } - $result = $this->group->where(array('id'=>$id))->delete(); + $result = $this->group->where(array('id'=>array('IN', $id)))->delete(); if ($result) { return $this->success("删除成功!"); }else{ @@ -113,7 +113,7 @@ class Group extends Admin { public function access($type = 'admin'){ $map['module'] = $type; - $list = db('AuthRule')->where($map)->order('id desc')->paginate(10); + $list = db('AuthRule')->where($map)->order('id desc')->paginate(15); $data = array( 'list' => $list, diff --git a/application/admin/controller/Link.php b/application/admin/controller/Link.php index a2ed8e18..b6fc4a82 100644 --- a/application/admin/controller/Link.php +++ b/application/admin/controller/Link.php @@ -84,7 +84,11 @@ class Link extends Admin{ } //删除 - public function delete($id){ + public function delete(){ + $id = array_unique((array)$this->param['id']); + if (empty($id)) { + return $this->error('非法操作!'); + } $link = db('Link'); $map = array('id'=>array('IN',$id)); diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index bae50802..7e947665 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -123,7 +123,7 @@ class Menu extends Admin{ * @author yangweijie */ public function del(){ - $id = array_unique((array)input('id',0)); + $id = array_unique((array)$this->param['id']); if ( empty($id) ) { return $this->error('请选择要操作的数据!'); @@ -133,7 +133,7 @@ class Menu extends Admin{ if(db('Menu')->where($map)->delete()){ session('admin_menu_list',null); //记录行为 - action_log('update_menu', 'Menu', $id, UID); + action_log('update_menu', 'Menu', $id, session('user_auth.uid')); return $this->success('删除成功'); } else { return $this->error('删除失败!'); diff --git a/application/admin/controller/Seo.php b/application/admin/controller/Seo.php index 99c67caf..1f1ae831 100644 --- a/application/admin/controller/Seo.php +++ b/application/admin/controller/Seo.php @@ -97,11 +97,11 @@ class Seo extends Admin{ } public function del(){ - $id = input('id','','trim,intval'); - if (!$id) { + $id = array_unique((array)$this->param['id']); + if (empty($id)) { return $this->error("非法操作!"); } - $result = db('SeoRule')->where(array('id'=>$id))->delete(); + $result = db('SeoRule')->where(array('id'=>array('IN',$id)))->delete(); if ($result) { return $this->success("删除成功!"); }else{ diff --git a/application/admin/view/action/index.html b/application/admin/view/action/index.html index 5b7f37aa..27475554 100644 --- a/application/admin/view/action/index.html +++ b/application/admin/view/action/index.html @@ -34,7 +34,7 @@ {volist name="list" id="vo"} - + {$vo.id} {$vo.name} diff --git a/application/admin/view/action/log.html b/application/admin/view/action/log.html index a4dfcad0..e4cbd832 100644 --- a/application/admin/view/action/log.html +++ b/application/admin/view/action/log.html @@ -29,7 +29,7 @@ {volist name="list" id="vo"} - + {$vo['id']} {:get_action($vo['action_id'],'title')} {:get_nickname($vo['user_id'])} diff --git a/application/admin/view/group/access.html b/application/admin/view/group/access.html index 8665fac1..a31a2a78 100644 --- a/application/admin/view/group/access.html +++ b/application/admin/view/group/access.html @@ -34,6 +34,7 @@ + @@ -45,6 +46,7 @@ {volist name="list" id="item"} + diff --git a/application/common/controller/Base.php b/application/common/controller/Base.php index 5f62fe1e..4ad9b259 100644 --- a/application/common/controller/Base.php +++ b/application/common/controller/Base.php @@ -138,6 +138,7 @@ class Base extends \think\Controller{ //request信息 protected function requestInfo(){ $this->request = \think\Request::instance(); + $this->param = $this->request->param(); defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module()); defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller()); defined('ACTION_NAME') or define('ACTION_NAME', $this->request->action()); @@ -145,5 +146,6 @@ class Base extends \think\Controller{ defined('IS_GET') or define('IS_GET', $this->request->isGet()); $this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action(); $this->assign('request',$this->request); + $this->assign('param',$this->param); } } diff --git a/application/common/controller/Upload.php b/application/common/controller/Upload.php index d08b4469..cf7802ee 100644 --- a/application/common/controller/Upload.php +++ b/application/common/controller/Upload.php @@ -14,14 +14,16 @@ class Upload { public function upload(){ $upload_type = input('get.filename','images','trim'); $config = $this->$upload_type(); - $upload = new \org\Upload($config, $config['driver']); - $info = $upload->upload($_FILES); - if (false !== $info) { - $fileinfo = $this->save($config, $upload_type, $info['file']); - $return['info'] = $fileinfo; + // 获取表单上传文件 例如上传了001.jpg + $file = request()->file('file'); + $info = $file->move($config['rootPath'], true, false); + + if($info){ + $return['status'] = 1; + $return['info'] = $this->save($config, $upload_type, $info); }else{ $return['status'] = 0; - $return['info'] = $upload->getError(); + $return['info'] = $file->getError(); } echo json_encode($return); @@ -68,20 +70,10 @@ class Upload { * @access public */ public function save($config, $type, $file){ + $file = $this->parse_file($file); $file['status'] = 1; - if ($type == 'images') { - $dbname = 'picture'; - $file['path'] = substr($config['rootPath'], 1).$file['savepath'].$file['savename']; // - }else{ - $dbname = 'file'; - $file['url'] = substr($config['rootPath'], 1).$file['savepath'].$file['savename']; - } - $data = db($dbname)->where(array('md5'=>$file['md5']))->find(); - if (!empty($data)) { - return $data; - }else{ - $id = db($dbname)->insertGetId($file); - } + $dbname = ($type == 'images') ? 'picture' : 'file'; + $id = db($dbname)->insertGetId($file); if ($id) { $data = db($dbname)->where(array('id'=>$id))->find(); @@ -119,4 +111,24 @@ class Upload { return false; } } + + protected function parse_file($info){ + $data['create_time'] = $info->getATime(); //最后访问时间 + $data['savename'] = $info->getBasename(); //获取无路径的basename + $data['c_time'] = $info->getCTime(); //获取inode修改时间 + $data['ext'] = $info->getExtension(); //文件扩展名 + $data['name'] = $info->getFilename(); //获取文件名 + $data['m_time'] = $info->getMTime(); //获取最后修改时间 + $data['owner'] = $info->getOwner(); //文件拥有者 + $data['savepath'] = $info->getPath(); //不带文件名的文件路径 + $data['url'] = $data['path'] = substr($info->getPathname(), 1); //全路径 + $data['size'] = $info->getSize(); //文件大小,单位字节 + $data['is_file'] = $info->isFile(); //是否是文件 + $data['is_execut'] = $info->isExecutable(); //是否可执行 + $data['is_readable'] = $info->isReadable(); //是否可读 + $data['is_writable'] = $info->isWritable(); //是否可写 + $data['md5'] = md5_file($info->getPathname()); + $data['sha1'] = sha1_file($info->getPathname()); + return $data; + } } \ No newline at end of file diff --git a/application/config.php b/application/config.php index da04c13c..3ef09916 100644 --- a/application/config.php +++ b/application/config.php @@ -10,7 +10,7 @@ return array( // 调试模式 - 'app_debug' => false, + 'app_debug' => true, 'charset' => 'UTF-8', 'lang_switch_on' => true, // 开启语言包功能 diff --git a/application/pay.php b/application/pay.php deleted file mode 100644 index ebe6f8d5..00000000 --- a/application/pay.php +++ /dev/null @@ -1,18 +0,0 @@ - -// +---------------------------------------------------------------------- - -return array( - - 'alipay' => array( - 'email' => 'ycgpp@126.com', - 'partner' => '2088002040431424', - 'key' => '49ee6pf892uc5p8py4hdfbi2wurnpk0x' - ), - 'wechat' => array() -); \ No newline at end of file diff --git a/core/library/think/Collection.php b/core/library/think/Collection.php index 68097131..8315268a 100644 --- a/core/library/think/Collection.php +++ b/core/library/think/Collection.php @@ -40,10 +40,10 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria return empty($this->items); } - public function toArray($allow = []) + public function toArray() { return array_map(function ($value) { - return ($value instanceof Model || $value instanceof self) ? $value->toArray($allow) : $value; + return ($value instanceof Model || $value instanceof self) ? $value->toArray() : $value; }, $this->items); } @@ -225,11 +225,11 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria $result = []; foreach ($this->items as $row) { - $key = $value = null; + $key = $value = null; $keySet = $valueSet = false; if (null !== $index_key && array_key_exists($index_key, $row)) { $keySet = true; - $key = (string) $row[$index_key]; + $key = (string)$row[$index_key]; } if (null === $column_key) { $valueSet = true; @@ -344,13 +344,12 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria /** * 转换当前数据集为JSON字符串 * @access public - * @param array $allow 允许输出的属性列表 - * @param integer $options json参数 + * @param integer $options json参数 * @return string */ - public function toJson($allow = [], $options = JSON_UNESCAPED_UNICODE) + public function toJson($options = JSON_UNESCAPED_UNICODE) { - return json_encode($this->toArray($allow), $options); + return json_encode($this->toArray(), $options); } public function __toString() @@ -369,6 +368,6 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria if ($items instanceof self) { return $items->all(); } - return (array) $items; + return (array)$items; } } diff --git a/core/library/think/Model.php b/core/library/think/Model.php index b3fc26ad..47d422e5 100644 --- a/core/library/think/Model.php +++ b/core/library/think/Model.php @@ -62,6 +62,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 字段属性 protected $field = []; + // 显示属性 + protected $visible = []; // 隐藏属性 protected $hidden = []; // 追加属性 @@ -469,35 +471,46 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return $this; } + /** + * 设置需要输出的属性 + * @param array $visible + * @return $this + */ + public function visible($visible = []) + { + $this->visible = $visible; + return $this; + } + /** * 转换当前模型对象为数组 * @access public - * @param array $allow 允许输出的属性列表 * @return array */ - public function toArray($allow = []) + public function toArray() { $item = []; - if (empty($allow)) { - $allow = array_keys($this->data); - } - $allow = array_diff($allow, $this->hidden); - foreach ($this->data as $key => $val) { - // 属性过滤输出 - if (!in_array($key, $allow)) { - continue; - } + //过滤属性 + if (!empty($this->visible)) { + $data = array_intersect_key($this->data, array_flip($this->visible)); + } elseif (!empty($this->hidden)) { + $data = array_diff_key($this->data, array_flip($this->hidden)); + } else { + $data = $this->data; + } + + foreach ($data as $key => $val) { if ($val instanceof Model || $val instanceof Collection) { // 关联模型对象 $item[$key] = $val->toArray(); } elseif (is_array($val) && reset($val) instanceof Model) { // 关联模型数据集 - $data = []; + $arr = []; foreach ($val as $k => $value) { - $data[$k] = $value->toArray(); + $arr[$k] = $value->toArray(); } - $item[$key] = $data; + $item[$key] = $arr; } else { // 模型属性 $item[$key] = $this->getAttr($key); @@ -515,13 +528,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 转换当前模型对象为JSON字符串 * @access public - * @param array $allow 允许输出的属性列表 * @param integer $options json参数 * @return string */ - public function toJson($allow = [], $options = JSON_UNESCAPED_UNICODE) + public function toJson($options = JSON_UNESCAPED_UNICODE) { - return json_encode($this->toArray($allow), $options); + return json_encode($this->toArray(), $options); } /** diff --git a/core/library/think/Url.php b/core/library/think/Url.php index cf570af0..a5190d7b 100644 --- a/core/library/think/Url.php +++ b/core/library/think/Url.php @@ -19,9 +19,6 @@ use think\Route; class Url { - // 生成URL地址的root - protected static $root; - /** * URL生成 支持路由反射 * @param string $url URL表达式, @@ -116,7 +113,7 @@ class Url // 检测域名 $domain = self::parseDomain($url, $domain); // URL组装 - $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); + $url = $domain . Request::instance()->root() . '/' . ltrim($url, '/'); return $url; } @@ -319,11 +316,4 @@ class Url { Cache::rm('think_route_map'); } - - // 指定当前生成URL地址的root - public static function root($root) - { - self::$root = $root; - Request::instance()->root($root); - } -} +} \ No newline at end of file diff --git a/core/library/think/paginator/Collection.php b/core/library/think/paginator/Collection.php index ddea7d5a..64fbb93b 100644 --- a/core/library/think/paginator/Collection.php +++ b/core/library/think/paginator/Collection.php @@ -51,7 +51,7 @@ class Collection extends \think\Collection return $this->paginator; } - public function toArray($allow = []) + public function toArray() { if ($this->paginator) { try { @@ -64,10 +64,10 @@ class Collection extends \think\Collection 'total' => $total, 'per_page' => $this->listRows(), 'current_page' => $this->currentPage(), - 'data' => parent::toArray($allow) + 'data' => parent::toArray() ]; } else { - return parent::toArray($allow); + return parent::toArray(); } }
ID 组名 标识
{$item['id']} {$item['title']} {$item['name']}