Exec.php 5.7 KB

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