Exec.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\Admin\controller;
  3. use app\BaseController;
  4. use think\facade\Db;
  5. use think\Request;
  6. use think\facade\Cache;
  7. class Exec extends BaseController
  8. {
  9. public function list(){
  10. $post = request()->post();
  11. $token = isset($post['token']) ? trim($post['token']) : "";
  12. if($token==""){
  13. return error_show(101,'token不能为空');
  14. }
  15. $effetc = VerifyTokens($token);
  16. if(!empty($effetc) && $effetc['code']!=0){
  17. return error_show($effetc['code'],$effetc['message']);
  18. }
  19. $where=['type'=>0];
  20. $page = isset($post['page']) ? intval($post['page']): 1;
  21. $size = isset($post['size']) ? intval($post['size']):10;
  22. $count =Db::name("exec")->where($where)->count();
  23. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  24. $page = $page>=$total?intval($total):$page;
  25. $list = Db::name("exec")->where($where)->page($page,$size)->select();
  26. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  27. }
  28. public function nowlist(){
  29. $post = request()->post();
  30. $token = isset($post['token']) ? trim($post['token']) : "";
  31. if($token==""){
  32. return error_show(101,'token不能为空');
  33. }
  34. $effetc = VerifyTokens($token);
  35. if(!empty($effetc) && $effetc['code']!=0){
  36. return error_show($effetc['code'],$effetc['message']);
  37. }
  38. $where=['type'=>1];
  39. $page = isset($post['page']) ? intval($post['page']): 1;
  40. $size = isset($post['size']) ? intval($post['size']):10;
  41. $count =Db::name("exec")->where($where)->count();
  42. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  43. $page = $page>=$total?intval($total):$page;
  44. $list = Db::name("exec")->where($where)->page($page,$size)->select();
  45. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  46. }
  47. public function save(){
  48. $post = request()->post();
  49. $token = isset($post['token']) ? trim($post['token']) : "";
  50. if($token==""){
  51. return error_show(101,'token不能为空');
  52. }
  53. $effetc = VerifyTokens($token);
  54. if(!empty($effetc) && $effetc['code']!=0){
  55. return error_show($effetc['code'],$effetc['message']);
  56. }
  57. $userinfo = GetUserInfo($token);
  58. if(!isset($userinfo['code'])|| $userinfo['code']!=0){
  59. return error_show(101,'未能获取用户信息');
  60. }
  61. $start = isset($post['start']) && $post['start'] != "" ? $post['start']." 00:00:00" : '';
  62. $end = isset($post['end']) && $post['end'] != "" ? $post['end']." 23:59:59" : '';
  63. $id = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
  64. if($id==""){
  65. return error_show(1004,"参数id不能为空");
  66. }
  67. $info=Db::name("exec")->where(["id"=>$id])->find();
  68. if(empty($info)){
  69. return error_show(1004,"未找到下载数据");
  70. }
  71. if( $info['start'] == $start &&$info['end'] == $end){
  72. return error_show(1004,"数据已提交");
  73. }
  74. if($start!=""){
  75. $info['start'] = $start;
  76. }
  77. if($end!=""){
  78. $info['end'] = $end;
  79. }
  80. if(is_file(root_path() . 'public'.$info['down_url'])){
  81. @unlink(root_path()."public".$info['down_url']);
  82. }
  83. $info['status']=1;
  84. $info['apply_id']=$userinfo['data']['id'];
  85. $info['apply_name']=$userinfo['data']['nickname'];
  86. $info['down_url']='';
  87. $info['remark']='';
  88. $info['updatetime'] = date("Y-m-d H:i:s");
  89. $info['addtime'] = date("Y-m-d H:i:s");
  90. $info['expiretime'] = date("Y-m-d H:i:s",time()+7*24*3600);
  91. $up = Db::name("exec")->save($info);
  92. $redis = Cache::store("redis");
  93. $isPushed = $redis->handler()->lPush($info['type']==1? "nowreport":"execreport", json_encode($info));
  94. return $up? app_show(0,"编辑成功"):error_show(1004,"编辑失败");
  95. }
  96. public function down(){
  97. $post = request()->post();
  98. $token = isset($post['token']) ? trim($post['token']) : "";
  99. if($token==""){
  100. return error_show(101,'token不能为空');
  101. }
  102. $id = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
  103. if($id==""){
  104. return error_show(1004,"参数id不能为空");
  105. }
  106. $info=Db::name("exec")->where(["id"=>$id])->find();
  107. if(empty($info)){
  108. return error_show(1004,"未找到下载数据");
  109. }
  110. $effetc = VerifyTokens($token);
  111. if(!empty($effetc) && $effetc['code']!=0){
  112. return error_show($effetc['code'],$effetc['message']);
  113. }
  114. $userinfo = GetUserInfo($token);
  115. if(!isset($userinfo['code'])|| $userinfo['code']!=0){
  116. return error_show(101,'未能获取用户信息');
  117. }
  118. $info['status']=1;
  119. $info['down_url']='';
  120. $info['remark']='';
  121. $info['apply_id']=$userinfo['data']['id'];
  122. $info['apply_name']=$userinfo['data']['nickname'];
  123. $info['expiretime'] = date("Y-m-d H:i:s",time()+7*24*3600);
  124. $info['updatetime'] = date("Y-m-d H:i:s");
  125. $info['addtime'] = date("Y-m-d H:i:s");
  126. $up = Db::name("exec")->save($info);
  127. $redis = Cache::store("redis");
  128. $isPushed = $redis->handler()->lPush($info['type']==1? "nowreport":"execreport", json_encode($info));
  129. return $up? app_show(0,"编辑成功"):error_show(1004,"编辑失败");
  130. }
  131. }