123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\facade\Validate;
- use think\Request;
- //系统设置
- class System extends BaseController
- {
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $post =$this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc =VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- $condition = [];
- isset($post['startTime'])&& $post['startTime']!="" ? $condition[] = ["addtime",">=",$post["startTime"]]:"";
- isset($post['endTime'])&& $post['endTime']!="" ? $condition[] = ["addtime","<=",$post["endTime"]]:"";
- isset($post['event'])&& $post['event']!="" ? $condition[] = ["url","like","%".$post['event']."%"]:"";
- isset($post['name'])&& $post['name']!="" ? $condition[] = ["name","like","%".$post['name']."%"]:"";
- isset($post['action'])&& $post['action']!="" ? $condition[] = ["info","=",$post["action"]]:"";
- isset($post['role'])&& $post['role']!="" ? $condition[] = ["rolename","like","%".$post['role']."%"]:"";
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
- $count = Db::name("system_log")->where($condition)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("system_log")->where($condition)->page($page,$size)->order("addtime desc")->field("id,info,url,param,rolename,name,addtime")->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function version()
- {
- $post =$this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc =VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- $condition = " 1=1 ";
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
- $count = Db::name("system_version")->where($condition)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("system_version")->where($condition)->page($page,$size)->order("addtime desc")->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function LastVersion()
- {
- $post =$this->request->post();
- $type = isset($post['type'])&& $post['type']!="" ? $post['type'] : "";
- if($type=="" || !in_array($type,["VER","MSG"])){
- $where="1=1";
- }else{
- $where="sys_type='{$type}'";
- }
- $version=Db::name("system_version")->where($where)->order("addtime desc")->find();
- if(!$version){
- return error_show(1004,'未找到数据');
- }
- return app_show(0,"获取成功",$version);
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function upload()
- {
- // $post =$this->request->post();
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if($token==""){
- // return error_show(101,'token不能为空');
- // }
- // $effetc = VerifyTokens($token);
- // if(!empty($effetc) && $effetc['code']!=0){
- // return error_show($effetc['code'],$effetc['message']);
- // }
- $files = $this->request->file('image');
- $list = "";
- if ($files != "") $list = UploadImg($files);
- if (is_array($list) && !empty($list)) return json_show(0, "上传成功!", $list);
- else return json_show(1005, "上传失败!" . $list);
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function upload_file()
- {
- $post =$this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- $files = $this->request->file('files');
- $list="";
- if($files!=""){
- $list=UploadFile($files);
- }
- if(is_array($list)&&!empty($list)){
- return app_show(0, "上传成功!",$list);
- }else{
- return error_show(1005, "上传失败!".$list);
- }
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function upload_video()
- {
- $post =$this->request->post();
- // $token = isset($post['token']) ? trim($post['token']) : "";
- // if($token==""){
- // return error_show(101,'token不能为空');
- // }
- // $effetc = VerifyTokens($token);
- // if(!empty($effetc) && $effetc['code']!=0){
- // return error_show($effetc['code'],$effetc['message']);
- // }
- $files = $this->request->file('video');
- $list="";
- if($files!=""){
- $list=UploadVideo($files);
- }
- if(is_array($list)&&!empty($list)){
- return app_show(0, "上传成功!",$list);
- }else{
- return error_show(1005, "上传失败!".$list);
- }
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- //
- }
- //添加版本信息
- public function add()
- {
- $param = $this->request->only(['module', 'system', 'sys_type', 'version', 'addtime'], 'post');
- $val = Validate::rule([
- 'module' => 'require|max:255',
- 'system' => 'require',
- 'sys_type' => 'require|upper|in:MSG,VER',
- 'version' => 'require|max:255',
- 'addtime' => 'require|date',
- ]);
- if (!$val->check($param)) return error_show(1004, $val->getError());
- $rs = Db::name('system_version')
- ->insert($param);
- return $rs ? app_show(0, '添加版本信息成功') : error_show(1004, '添加版本信息失败');
- }
- }
|