用户上传头像
This commit is contained in:
parent
90dd514693
commit
b6e57d0cf3
|
@ -218,39 +218,6 @@ class HomeIndex extends ApiController
|
|||
View::assign('TP_VERSION', \think\facade\App::version());
|
||||
return View();
|
||||
}
|
||||
|
||||
//通讯录
|
||||
public function mail_list()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['id|username|name|nickname|mobile|desc', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$where[] = ['status', '<', 2];
|
||||
if (isset($param['status']) && $param['status']!='') {
|
||||
$where[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (!empty($param['did'])) {
|
||||
$department_array = get_department_son($param['did']);
|
||||
$where[] = ['did', 'in', $department_array];
|
||||
}
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$admin = \app\user\model\Admin::where($where)
|
||||
->order('id desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
$item->department = Db::name('Department')->where(['id' => $item->did])->value('title');
|
||||
$item->position = Db::name('Position')->where(['id' => $item->position_id])->value('title');
|
||||
$item->entry_time = empty($item->entry_time) ? '-' : date('Y-m-d', $item->entry_time);
|
||||
});
|
||||
return table_assign(0, '', $admin);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//修改个人信息
|
||||
public function edit_personal()
|
||||
|
@ -289,4 +256,96 @@ class HomeIndex extends ApiController
|
|||
Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data);
|
||||
$this->apiSuccess('修改成功');
|
||||
}
|
||||
|
||||
//上传文件
|
||||
public function upload()
|
||||
{
|
||||
$uid = JWT_UID;
|
||||
$sourse = 'file';
|
||||
if(isset($param['sourse'])){
|
||||
$sourse = $param['sourse'];
|
||||
}
|
||||
if($sourse == 'file' || $sourse == 'tinymce'){
|
||||
if(request()->file('file')){
|
||||
$file = request()->file('file');
|
||||
}
|
||||
else{
|
||||
$this->apiError('没有选择上传文件');
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (request()->file('editormd-image-file')) {
|
||||
$file = request()->file('editormd-image-file');
|
||||
} else {
|
||||
$this->apiError('没有选择上传文件');
|
||||
}
|
||||
}
|
||||
// 获取上传文件的hash散列值
|
||||
$sha1 = $file->hash('sha1');
|
||||
$md5 = $file->hash('md5');
|
||||
$rule = [
|
||||
'image' => 'jpg,png,jpeg,gif',
|
||||
'doc' => 'txt,doc,docx,ppt,pptx,xls,xlsx,pdf',
|
||||
'file' => 'zip,gz,7z,rar,tar',
|
||||
'video' => 'mpg,mp4,mpeg,avi,wmv,mov,flv,m4v',
|
||||
];
|
||||
$fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file'] . ',' . $rule['video'];
|
||||
//1M=1024*1024=1048576字节
|
||||
$fileSize = 100 * 1024 * 1024;
|
||||
if (isset($param['type']) && $param['type']) {
|
||||
$fileExt = $rule[$param['type']];
|
||||
}
|
||||
if (isset($param['size']) && $param['size']) {
|
||||
$fileSize = $param['size'];
|
||||
}
|
||||
$validate = \think\facade\Validate::rule([
|
||||
'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt,
|
||||
]);
|
||||
$file_check['image'] = $file;
|
||||
if (!$validate->check($file_check)) {
|
||||
$this->apiError($validate->getError());
|
||||
}
|
||||
// 日期前綴
|
||||
$dataPath = date('Ym');
|
||||
$use = 'thumb';
|
||||
$filename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file, function () use ($md5) {
|
||||
return $md5;
|
||||
});
|
||||
if ($filename) {
|
||||
//写入到附件表
|
||||
$data = [];
|
||||
$path = get_config('filesystem.disks.public.url');
|
||||
$data['filepath'] = $path . '/' . $filename;
|
||||
$data['name'] = $file->getOriginalName();
|
||||
$data['mimetype'] = $file->getOriginalMime();
|
||||
$data['fileext'] = $file->extension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
$data['filename'] = $filename;
|
||||
$data['sha1'] = $sha1;
|
||||
$data['md5'] = $md5;
|
||||
$data['module'] = \think\facade\App::initialize()->http->getName();
|
||||
$data['action'] = app('request')->action();
|
||||
$data['uploadip'] = app('request')->ip();
|
||||
$data['create_time'] = time();
|
||||
$data['user_id'] = $uid;
|
||||
if ($data['module'] = 'admin') {
|
||||
//通过后台上传的文件直接审核通过
|
||||
$data['status'] = 1;
|
||||
$data['admin_id'] = $data['user_id'];
|
||||
$data['audit_time'] = time();
|
||||
}
|
||||
$data['use'] = request()->has('use') ? request()->param('use') : $use; //附件用处
|
||||
$res['id'] = Db::name('file')->insertGetId($data);
|
||||
$res['filepath'] = $data['filepath'];
|
||||
$res['name'] = $data['name'];
|
||||
$res['filename'] = $data['filename'];
|
||||
$res['filesize'] = $data['filesize'];
|
||||
$res['fileext'] = $data['fileext'];
|
||||
add_log('upload', $data['user_id'], $data,'文件');
|
||||
$this->apiSuccess('上传成功', $res);
|
||||
} else {
|
||||
$this->apiError('上传失败,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ class Index extends BaseController
|
|||
public function upload()
|
||||
{
|
||||
$param = get_params();
|
||||
//var_dump($param);exit;
|
||||
$sourse = 'file';
|
||||
if(isset($param['sourse'])){
|
||||
$sourse = $param['sourse'];
|
||||
|
|
|
@ -689,6 +689,9 @@ function add_log($type, $param_id = '', $param = [] ,$subject='')
|
|||
$title = '操作';
|
||||
$session_admin = get_config('app.session_admin');
|
||||
$uid = \think\facade\Session::get($session_admin);
|
||||
if (empty($uid)) {
|
||||
$uid = JWT_UID;
|
||||
}
|
||||
$type_action = get_config('log.type_action');
|
||||
if($type_action[$type]){
|
||||
$title = $type_action[$type];
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.5 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.9 MiB |
Loading…
Reference in New Issue