123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\Request;
- use think\facade\Cache;
- class Exec extends BaseController
- {
- public function list(){
- $post = 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']);
- }
- $where=['type'=>0];
- $page = isset($post['page']) ? intval($post['page']): 1;
- $size = isset($post['size']) ? intval($post['size']):10;
- $count =Db::name("exec")->where($where)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("exec")->where($where)->page($page,$size)->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function nowlist(){
- $post = 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']);
- }
- $where=['type'=>1];
- $page = isset($post['page']) ? intval($post['page']): 1;
- $size = isset($post['size']) ? intval($post['size']):10;
- $count =Db::name("exec")->where($where)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("exec")->where($where)->page($page,$size)->select();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function save(){
- $post = 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']);
- }
- $userinfo = GetUserInfo($token);
- if(!isset($userinfo['code'])|| $userinfo['code']!=0){
- return error_show(101,'未能获取用户信息');
- }
- $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
- $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
- $id = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
- if($id==""){
- return error_show(1004,"参数id不能为空");
- }
- $info=Db::name("exec")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"未找到下载数据");
- }
- if( $info['start'] == $start &&$info['end'] == $end){
- return error_show(1004,"数据已提交");
- }
- if($start!=""){
- $info['start'] = $start;
- }
- if($end!=""){
- $info['end'] = $end;
- }
- if(is_file(root_path() . 'public'.$info['down_url'])){
- @unlink(root_path()."public".$info['down_url']);
- }
- $info['status']=1;
- $info['apply_id']=$userinfo['data']['id'];
- $info['apply_name']=$userinfo['data']['nickname'];
- $info['down_url']='';
- $info['remark']='';
- $info['updatetime'] = date("Y-m-d H:i:s");
- $info['addtime'] = date("Y-m-d H:i:s");
- $info['expiretime'] = date("Y-m-d H:i:s",time()+7*24*3600);
- $up = Db::name("exec")->save($info);
- $redis = Cache::store("redis");
- $isPushed = $redis->handler()->lPush($info['type']==1? "nowreport":"execreport", json_encode($info));
- return $up? app_show(0,"编辑成功"):error_show(1004,"编辑失败");
- }
- public function down(){
- $post = request()->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $id = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
- if($id==""){
- return error_show(1004,"参数id不能为空");
- }
- $info=Db::name("exec")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"未找到下载数据");
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- $userinfo = GetUserInfo($token);
- if(!isset($userinfo['code'])|| $userinfo['code']!=0){
- return error_show(101,'未能获取用户信息');
- }
- $info['status']=1;
- $info['down_url']='';
- $info['remark']='';
- $info['apply_id']=$userinfo['data']['id'];
- $info['apply_name']=$userinfo['data']['nickname'];
- $info['expiretime'] = date("Y-m-d H:i:s",time()+7*24*3600);
- $info['updatetime'] = date("Y-m-d H:i:s");
- $info['addtime'] = date("Y-m-d H:i:s");
- $up = Db::name("exec")->save($info);
- $redis = Cache::store("redis");
- $isPushed = $redis->handler()->lPush($info['type']==1? "nowreport":"execreport", json_encode($info));
- return $up? app_show(0,"编辑成功"):error_show(1004,"编辑失败");
- }
- }
|