后台批量操作bug修复

内核更新
This commit is contained in:
2016-07-11 12:03:55 +08:00
parent 195ec9417c
commit 6460d64ceb
19 changed files with 119 additions and 128 deletions

View File

@@ -103,14 +103,11 @@ class Action extends Admin {
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function del(){ public function del(){
if (IS_POST) { $id = array_unique((array)$this->param['id']);
$ids = input('ids/a',array()); if(empty($id)){
$id = input('id','');
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",''); return $this->error("非法操作!",'');
} }
$map['id'] = array('IN',$ids); $map['id'] = array('IN',$id);
$result = db('Action')->where($map)->delete(); $result = db('Action')->where($map)->delete();
if ($result) { if ($result) {
action_log('delete_action', 'Action', $id, session('user_auth.uid')); action_log('delete_action', 'Action', $id, session('user_auth.uid'));
@@ -118,9 +115,6 @@ class Action extends Admin {
}else{ }else{
return $this->error('删除失败!'); return $this->error('删除失败!');
} }
}else{
return $this->error("非法操作!");
}
} }
/** /**
@@ -128,15 +122,13 @@ class Action extends Admin {
* @author colin <colin@tensent.cn> * @author colin <colin@tensent.cn>
*/ */
public function setstatus(){ public function setstatus(){
$ids = input('ids/a',array()); $id = array_unique((array)$this->param['id']);
$id = input('id',''); if(empty($id)){
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",''); return $this->error("非法操作!",'');
} }
$status = input('get.status','','trim,intval'); $status = input('get.status','','trim,intval');
$message = !$status ? '禁用' : '启用'; $message = !$status ? '禁用' : '启用';
$map['id'] = array('IN',$ids); $map['id'] = array('IN',$id);
$result = db('Action')->where($map)->setField('status',$status); $result = db('Action')->where($map)->setField('status',$status);
if ($result !== false) { if ($result !== false) {
action_log('setstatus_action', 'Action', $id, session('user_auth.uid')); 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 <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
public function dellog() { public function dellog() {
$ids = input('ids/a',array()); $id = array_unique((array)$this->param['id']);
$id = input('id',''); if(empty($id)){
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",''); return $this->error("非法操作!",'');
} }
$map['id'] = array('IN',$ids); $map['id'] = array('IN',$id);
$res = db('ActionLog')->where($map)->delete(); $res = db('ActionLog')->where($map)->delete();
if ($res !== false) { if ($res !== false) {
action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid')); action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid'));

View File

@@ -90,9 +90,9 @@ class Ad extends Admin {
} }
public function del(){ public function del(){
$id = input('id',''); $id = array_unique((array)$this->param['id']);
if (!$id) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN',$id);
@@ -175,9 +175,9 @@ class Ad extends Admin {
} }
public function delad(){ public function delad(){
$id = input('id',''); $id = array_unique((array)$this->param['id']);
if (!$id) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$id); $map['id'] = array('IN',$id);

View File

@@ -127,7 +127,7 @@ class Channel extends Admin{
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function del() { public function del() {
$id = array_unique((array)input('id', 0)); $id = array_unique((array)$this->param['id']);
if (empty($id)) { if (empty($id)) {
return $this->error('请选择要操作的数据!'); return $this->error('请选择要操作的数据!');

View File

@@ -145,14 +145,12 @@ class Content extends Admin{
* @author molong <ycgpp@126.com> * @author molong <ycgpp@126.com>
*/ */
public function del(){ public function del(){
$id = input('id','','trim'); $id = array_unique((array)$this->param['id']);
$ids = input('post.ids',array()); if (empty($id)) {
array_push($ids, $id);
if (empty($ids)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$map['id'] = array('IN',$ids); $map['id'] = array('IN',$id);
$result = $this->model->del($map); $result = $this->model->del($map);
if ($result) { if ($result) {

View File

@@ -97,11 +97,11 @@ class Group extends Admin {
//会员分组删除控制器 //会员分组删除控制器
public function del(){ public function del(){
$id = input('id','','trim,intval'); $id = array_unique((array)$this->param['id']);
if (!$id) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = $this->group->where(array('id'=>$id))->delete(); $result = $this->group->where(array('id'=>array('IN', $id)))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ }else{
@@ -113,7 +113,7 @@ class Group extends Admin {
public function access($type = 'admin'){ public function access($type = 'admin'){
$map['module'] = $type; $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( $data = array(
'list' => $list, 'list' => $list,

View File

@@ -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'); $link = db('Link');
$map = array('id'=>array('IN',$id)); $map = array('id'=>array('IN',$id));

View File

@@ -123,7 +123,7 @@ class Menu extends Admin{
* @author yangweijie <yangweijiester@gmail.com> * @author yangweijie <yangweijiester@gmail.com>
*/ */
public function del(){ public function del(){
$id = array_unique((array)input('id',0)); $id = array_unique((array)$this->param['id']);
if ( empty($id) ) { if ( empty($id) ) {
return $this->error('请选择要操作的数据!'); return $this->error('请选择要操作的数据!');
@@ -133,7 +133,7 @@ class Menu extends Admin{
if(db('Menu')->where($map)->delete()){ if(db('Menu')->where($map)->delete()){
session('admin_menu_list',null); 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('删除成功'); return $this->success('删除成功');
} else { } else {
return $this->error('删除失败!'); return $this->error('删除失败!');

View File

@@ -97,11 +97,11 @@ class Seo extends Admin{
} }
public function del(){ public function del(){
$id = input('id','','trim,intval'); $id = array_unique((array)$this->param['id']);
if (!$id) { if (empty($id)) {
return $this->error("非法操作!"); return $this->error("非法操作!");
} }
$result = db('SeoRule')->where(array('id'=>$id))->delete(); $result = db('SeoRule')->where(array('id'=>array('IN',$id)))->delete();
if ($result) { if ($result) {
return $this->success("删除成功!"); return $this->success("删除成功!");
}else{ }else{

View File

@@ -34,7 +34,7 @@
{volist name="list" id="vo"} {volist name="list" id="vo"}
<tr> <tr>
<td> <td>
<input class="ids" type="checkbox" name="ids[]" value="{$vo.id}" /> <input class="ids" type="checkbox" name="id[]" value="{$vo['id']}" />
</td> </td>
<td>{$vo.id}</td> <td>{$vo.id}</td>
<td>{$vo.name}</td> <td>{$vo.name}</td>

View File

@@ -29,7 +29,7 @@
<tbody> <tbody>
{volist name="list" id="vo"} {volist name="list" id="vo"}
<tr> <tr>
<td><input class="ids" type="checkbox" name="ids[]" value="{$vo['id']}" /></td> <td><input class="ids" type="checkbox" name="id[]" value="{$vo['id']}" /></td>
<td>{$vo['id']} </td> <td>{$vo['id']} </td>
<td>{:get_action($vo['action_id'],'title')}</td> <td>{:get_action($vo['action_id'],'title')}</td>
<td>{:get_nickname($vo['user_id'])}</td> <td>{:get_nickname($vo['user_id'])}</td>

View File

@@ -34,6 +34,7 @@
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
<th width="60">ID</th> <th width="60">ID</th>
<th>组名</th> <th>组名</th>
<th>标识</th> <th>标识</th>
@@ -45,6 +46,7 @@
<tbody> <tbody>
{volist name="list" id="item"} {volist name="list" id="item"}
<tr> <tr>
<th width="30"><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></th>
<td>{$item['id']}</td> <td>{$item['id']}</td>
<td>{$item['title']}</td> <td>{$item['title']}</td>
<td>{$item['name']}</td> <td>{$item['name']}</td>

View File

@@ -138,6 +138,7 @@ class Base extends \think\Controller{
//request信息 //request信息
protected function requestInfo(){ protected function requestInfo(){
$this->request = \think\Request::instance(); $this->request = \think\Request::instance();
$this->param = $this->request->param();
defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module()); defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module());
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller()); defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller());
defined('ACTION_NAME') or define('ACTION_NAME', $this->request->action()); 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()); defined('IS_GET') or define('IS_GET', $this->request->isGet());
$this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action(); $this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
$this->assign('request',$this->request); $this->assign('request',$this->request);
$this->assign('param',$this->param);
} }
} }

View File

@@ -14,14 +14,16 @@ class Upload {
public function upload(){ public function upload(){
$upload_type = input('get.filename','images','trim'); $upload_type = input('get.filename','images','trim');
$config = $this->$upload_type(); $config = $this->$upload_type();
$upload = new \org\Upload($config, $config['driver']); // 获取表单上传文件 例如上传了001.jpg
$info = $upload->upload($_FILES); $file = request()->file('file');
if (false !== $info) { $info = $file->move($config['rootPath'], true, false);
$fileinfo = $this->save($config, $upload_type, $info['file']);
$return['info'] = $fileinfo; if($info){
$return['status'] = 1;
$return['info'] = $this->save($config, $upload_type, $info);
}else{ }else{
$return['status'] = 0; $return['status'] = 0;
$return['info'] = $upload->getError(); $return['info'] = $file->getError();
} }
echo json_encode($return); echo json_encode($return);
@@ -68,20 +70,10 @@ class Upload {
* @access public * @access public
*/ */
public function save($config, $type, $file){ public function save($config, $type, $file){
$file = $this->parse_file($file);
$file['status'] = 1; $file['status'] = 1;
if ($type == 'images') { $dbname = ($type == 'images') ? 'picture' : 'file';
$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); $id = db($dbname)->insertGetId($file);
}
if ($id) { if ($id) {
$data = db($dbname)->where(array('id'=>$id))->find(); $data = db($dbname)->where(array('id'=>$id))->find();
@@ -119,4 +111,24 @@ class Upload {
return false; 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;
}
} }

View File

@@ -10,7 +10,7 @@
return array( return array(
// 调试模式 // 调试模式
'app_debug' => false, 'app_debug' => true,
'charset' => 'UTF-8', 'charset' => 'UTF-8',
'lang_switch_on' => true, // 开启语言包功能 'lang_switch_on' => true, // 开启语言包功能

View File

@@ -1,18 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
return array(
'alipay' => array(
'email' => 'ycgpp@126.com',
'partner' => '2088002040431424',
'key' => '49ee6pf892uc5p8py4hdfbi2wurnpk0x'
),
'wechat' => array()
);

View File

@@ -40,10 +40,10 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
return empty($this->items); return empty($this->items);
} }
public function toArray($allow = []) public function toArray()
{ {
return array_map(function ($value) { 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); }, $this->items);
} }
@@ -229,7 +229,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
$keySet = $valueSet = false; $keySet = $valueSet = false;
if (null !== $index_key && array_key_exists($index_key, $row)) { if (null !== $index_key && array_key_exists($index_key, $row)) {
$keySet = true; $keySet = true;
$key = (string) $row[$index_key]; $key = (string)$row[$index_key];
} }
if (null === $column_key) { if (null === $column_key) {
$valueSet = true; $valueSet = true;
@@ -344,13 +344,12 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
/** /**
* 转换当前数据集为JSON字符串 * 转换当前数据集为JSON字符串
* @access public * @access public
* @param array $allow 允许输出的属性列表
* @param integer $options json参数 * @param integer $options json参数
* @return string * @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() public function __toString()
@@ -369,6 +368,6 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
if ($items instanceof self) { if ($items instanceof self) {
return $items->all(); return $items->all();
} }
return (array) $items; return (array)$items;
} }
} }

View File

@@ -62,6 +62,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 字段属性 // 字段属性
protected $field = []; protected $field = [];
// 显示属性
protected $visible = [];
// 隐藏属性 // 隐藏属性
protected $hidden = []; protected $hidden = [];
// 追加属性 // 追加属性
@@ -470,34 +472,45 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} }
/** /**
* 转换当前模型对象为数组 * 设置需要输出的属性
* @access public * @param array $visible
* @param array $allow 允许输出的属性列表 * @return $this
* @return array
*/ */
public function toArray($allow = []) public function visible($visible = [])
{ {
$item = []; $this->visible = $visible;
if (empty($allow)) { return $this;
$allow = array_keys($this->data);
}
$allow = array_diff($allow, $this->hidden);
foreach ($this->data as $key => $val) {
// 属性过滤输出
if (!in_array($key, $allow)) {
continue;
} }
/**
* 转换当前模型对象为数组
* @access public
* @return array
*/
public function toArray()
{
$item = [];
//过滤属性
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) { if ($val instanceof Model || $val instanceof Collection) {
// 关联模型对象 // 关联模型对象
$item[$key] = $val->toArray(); $item[$key] = $val->toArray();
} elseif (is_array($val) && reset($val) instanceof Model) { } elseif (is_array($val) && reset($val) instanceof Model) {
// 关联模型数据集 // 关联模型数据集
$data = []; $arr = [];
foreach ($val as $k => $value) { foreach ($val as $k => $value) {
$data[$k] = $value->toArray(); $arr[$k] = $value->toArray();
} }
$item[$key] = $data; $item[$key] = $arr;
} else { } else {
// 模型属性 // 模型属性
$item[$key] = $this->getAttr($key); $item[$key] = $this->getAttr($key);
@@ -515,13 +528,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/** /**
* 转换当前模型对象为JSON字符串 * 转换当前模型对象为JSON字符串
* @access public * @access public
* @param array $allow 允许输出的属性列表
* @param integer $options json参数 * @param integer $options json参数
* @return string * @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);
} }
/** /**

View File

@@ -19,9 +19,6 @@ use think\Route;
class Url class Url
{ {
// 生成URL地址的root
protected static $root;
/** /**
* URL生成 支持路由反射 * URL生成 支持路由反射
* @param string $url URL表达式 * @param string $url URL表达式
@@ -116,7 +113,7 @@ class Url
// 检测域名 // 检测域名
$domain = self::parseDomain($url, $domain); $domain = self::parseDomain($url, $domain);
// URL组装 // URL组装
$url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); $url = $domain . Request::instance()->root() . '/' . ltrim($url, '/');
return $url; return $url;
} }
@@ -319,11 +316,4 @@ class Url
{ {
Cache::rm('think_route_map'); Cache::rm('think_route_map');
} }
// 指定当前生成URL地址的root
public static function root($root)
{
self::$root = $root;
Request::instance()->root($root);
}
} }

View File

@@ -51,7 +51,7 @@ class Collection extends \think\Collection
return $this->paginator; return $this->paginator;
} }
public function toArray($allow = []) public function toArray()
{ {
if ($this->paginator) { if ($this->paginator) {
try { try {
@@ -64,10 +64,10 @@ class Collection extends \think\Collection
'total' => $total, 'total' => $total,
'per_page' => $this->listRows(), 'per_page' => $this->listRows(),
'current_page' => $this->currentPage(), 'current_page' => $this->currentPage(),
'data' => parent::toArray($allow) 'data' => parent::toArray()
]; ];
} else { } else {
return parent::toArray($allow); return parent::toArray();
} }
} }