完成上传组件的开发

This commit is contained in:
2020-04-10 21:19:03 +08:00
parent 5629daa722
commit a5a9c12ad0
18 changed files with 385 additions and 145 deletions

View File

@@ -51,6 +51,7 @@ class Upload extends Base {
public function server(){
$param = $this->request->get();
$map = [];
if (!isset($param['name'])) {
return $this->error('非法操作');
}
@@ -60,10 +61,11 @@ class Upload extends Base {
'query' => $this->request->param()
];
if($param['type'] == 'file'){
$list = Db::name('File')->paginate($pageConfig);
$map[] = ['ext', '<>', 'image'];
}else{
$list = Db::name('Picture')->paginate($pageConfig);
$map[] = ['ext', '=', 'image'];
}
$list = Db::name('Attach')->paginate($pageConfig);
$this->data = [
'from' => $this->request->param('from'),
@@ -79,15 +81,16 @@ class Upload extends Base {
}
public function upload(){
$upload_type = $this->request->get('filename', 'image', 'trim');
$type = $this->request->param('type');
$upload_type = (false !== strpos("image", $type)) ? "image" : 'file';
$config = $this->$upload_type();
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file');
$file = $this->request->file('file');
try {
validate(['file'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])
->check([$file]);
$data['code'] = 1;
$data['info'] = $this->save($file, $upload_type);
$data['info'] = $this->save($this->request, $upload_type);
} catch (think\exception\ValidateException $e) {
$data['code'] = 0;
$data['info'] = $e->getMessage();
@@ -99,6 +102,10 @@ class Upload extends Base {
return [];
}
protected function file(){
return [];
}
public function editor(){
$fileType = $this->request->get('fileType', 'image', 'trim');
$file = request()->file('imgFile');
@@ -130,27 +137,20 @@ class Upload extends Base {
return json($data);
}
protected function save($file, $upload_type){
protected function save($request, $upload_type){
$data = [];
$savename = Filesystem::disk('public')->putFile($upload_type, $file, 'md5');
$data['create_time'] = $file->getATime(); //最后访问时间
$data['savename'] = $file->getBasename(); //获取无路径的basename
$data['c_time'] = $file->getCTime(); //获取inode修改时间
$data['ext'] = $file->getExtension(); //文件扩展名
$data['name'] = $file->getFilename(); //获取文件名
$data['m_time'] = $file->getMTime(); //获取最后修改时间
$data['owner'] = $file->getOwner(); //文件拥有者
$data['savepath'] = $file->getPath(); //不带文件名的文件路径
$data['url'] = $data['path'] = '/uploads/' . $savename; //全路径
$file= $request->file('file');
$data['savename'] = $request->param('name');
$data['mime'] = $request->param('type');
$data['size'] = $file->getSize(); //文件大小,单位字节
$data['is_file'] = $file->isFile(); //是否是文件
$data['is_execut'] = $file->isExecutable(); //是否可执行
$data['is_readable'] = $file->isReadable(); //是否可读
$data['is_writable'] = $file->isWritable(); //是否可写
$data['md5'] = md5_file($file->getPathname());
$data['sha1'] = sha1_file($file->getPathname());
$data['id'] = time();
$data['ext'] = pathinfo($data['savename'], PATHINFO_EXTENSION); //文件扩展名
$data['savepath'] = Filesystem::disk('public')->putFile($upload_type, $file, 'md5');
$data['location'] = "/uploads/";
$data['url'] = $data['location'] . $data['savepath'];
$data['create_time'] = time();
$data['id'] = Db::name('Attach')->insertGetId($data);
return $data;
}
}

View File

@@ -10,6 +10,7 @@
namespace app\controller\admin;
use app\model\Wechat as WechatM;
use app\model\WechatPay;
/**
* @title 微信模块
@@ -19,14 +20,14 @@ class Wechat extends Base {
/**
* @title 微信列表
* @author huajie <banhuajie@163.com>
* @author molong <molong@tensent.cn>
*/
public function index() {
$map = [];
$order = "id desc";
//获取列表数据
$list = WechatM::where($map)->order($order)->paginate($this->request->pageConfig);
$list = WechatM::where($map)->order($order)->paginate($this->request->pageConfig)->append(['type_text']);
$this->data = array(
'list' => $list,
@@ -37,7 +38,7 @@ class Wechat extends Base {
/**
* @title 添加微信
* @author colin <colin@tensent.cn>
* @author molong <molong@tensent.cn>
*/
public function add() {
if ($this->request->isPost()) {
@@ -58,7 +59,7 @@ class Wechat extends Base {
/**
* @title 修改微信
* @author colin <colin@tensent.cn>
* @author molong <molong@tensent.cn>
*/
public function edit($id = null) {
if ($this->request->isPost()) {
@@ -83,108 +84,92 @@ class Wechat extends Base {
}
/**
* @title 删除用户行为
* @author colin <colin@tensent.cn>
* @title 删除微信
* @author molong <molong@tensent.cn>
*/
public function del() {
$id = $this->getArrayParam('id');
if (empty($id)) {
return $this->error("非法操作!", '');
public function delete() {
$id = $this->request->param('id', '');
$map = [];
if (!$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('删除成功!');
if (is_array($id)) {
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
$result = WechatM::where($map)->delete();
if (false !== $result) {
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
}
}
/**
* @title 修改用户行为状态
* @author colin <colin@tensent.cn>
*/
public function setstatus() {
$id = $this->getArrayParam('id');
if (empty($id)) {
return $this->error("非法操作!", '');
}
$status = input('get.status', '', 'trim,intval');
$message = !$status ? '禁用' : '启用';
$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'));
return $this->success('设置' . $message . '状态成功!');
} else {
return $this->error('设置' . $message . '状态失败!');
}
}
/**
* @title 小程序列表
* @author huajie <banhuajie@163.com>
* @title 微信支付
* @author molong <molong@tensent.cn>
*/
public function pay() {
return $this->fetch();
}
/**
* @title 查看行为日志
* @author huajie <banhuajie@163.com>
*/
public function detail($id = 0) {
$model = model('ActionLog');
if (empty($id)) {
return $this->error('参数错误!');
}
$map = [];
$info = $model::get($id);
$order = "id desc";
//获取列表数据
$list = WechatPay::where($map)->order($order)->paginate($this->request->pageConfig);
$info['title'] = get_action($info['action_id'], 'title');
$info['user_id'] = get_username($info['user_id']);
$info['action_ip'] = long2ip($info['action_ip']);
$info['create_time'] = date('Y-m-d H:i:s', $info['create_time']);
$data = array(
'info' => $info,
'keyList' => $model->keyList,
$this->data = array(
'list' => $list,
'page' => '',
);
$this->assign($data);
$this->setMeta('查看行为日志');
return $this->fetch();
}
/**
* @title 删除日志
* @param mixed $id
* @author huajie <banhuajie@163.com>
* @title 添加微信支付
* @author molong <molong@tensent.cn>
*/
public function dellog() {
$id = $this->getArrayParam('id');
if (empty($id)) {
return $this->error("非法操作!", '');
}
$map['id'] = array('IN', $id);
$res = db('ActionLog')->where($map)->delete();
if ($res !== false) {
action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('删除成功!');
public function addpay() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = WechatPay::create($data);
if (false != $result) {
return $this->success('添加成功!', url('/admin/wechat/index'));
} else {
return $this->error('添加失败!');
}
} else {
return $this->error('删除失败!');
$this->data = array(
'keyList' => WechatPay::$fieldlist
);
return $this->fetch('admin/public/edit');
}
}
/**
* @title 清空日志
* @title 修改微信支付
* @author molong <molong@tensent.cn>
*/
public function clear($id = '') {
$res = db('ActionLog')->where('1=1')->delete();
if ($res !== false) {
//记录行为
action_log('clear_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('日志清空成功!');
public function editpay($id = null) {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = WechatPay::update($data, ['id' => $data['id']]);
if ($result !== false) {
return $this->success('编辑成功!', url('/admin/wechat/index'));
} else {
return $this->error('修改失败!');
}
} else {
return $this->error('日志清空失败!');
$info = WechatPay::find($id);
if (!$info) {
return $this->error("非法操作!");
}
$this->data = array(
'info' => $info,
'keyList' => WechatPay::$fieldlist
);
return $this->fetch('admin/public/edit');
}
}
}