Exec.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $userinfo = GetUserInfo($token);
  57. if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
  58. return error_show(101, '未能获取用户信息');
  59. }
  60. $start = isset($post['start']) && $post['start'] != "" ? $post['start'] . " 00:00:00" : '';
  61. $end = isset($post['end']) && $post['end'] != "" ? $post['end'] . " 23:59:59" : '';
  62. $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
  63. if ($id == "") {
  64. return error_show(1004, "参数id不能为空");
  65. }
  66. $info = Db::name("exec")->where(["id" => $id])->find();
  67. if (empty($info)) {
  68. return error_show(1004, "未找到下载数据");
  69. }
  70. if ($info['start'] == $start && $info['end'] == $end) {
  71. return error_show(1004, "数据已提交");
  72. }
  73. if ($start != "") {
  74. $info['start'] = $start;
  75. }
  76. if ($end != "") {
  77. $info['end'] = $end;
  78. }
  79. if (is_file(root_path() . 'public' . $info['down_url'])) {
  80. @unlink(root_path() . "public" . $info['down_url']);
  81. }
  82. $info['status'] = 1;
  83. $info['apply_id'] = $userinfo['data']['id'];
  84. $info['apply_name'] = $userinfo['data']['nickname'];
  85. $info['down_url'] = '';
  86. $info['remark'] = '';
  87. $info['updatetime'] = date("Y-m-d H:i:s");
  88. $info['addtime'] = date("Y-m-d H:i:s");
  89. $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
  90. $up = Db::name("exec")->save($info);
  91. $redis = Cache::store("redis")->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
  92. return $up ? app_show(0, "编辑成功") : error_show(1004, "编辑失败");
  93. }
  94. public function down()
  95. {
  96. $post = $this->post;
  97. $token = isset($post['token']) ? trim($post['token']) : "";
  98. if ($token == "") {
  99. return error_show(101, 'token不能为空');
  100. }
  101. $id = isset($post['id']) && $post['id'] !== '' ? intval($post['id']) : "";
  102. if ($id == "") {
  103. return error_show(1004, "参数id不能为空");
  104. }
  105. $info = Db::name("exec")->where(["id" => $id])->find();
  106. if (empty($info)) {
  107. return error_show(1004, "未找到下载数据");
  108. }
  109. // $effetc = VerifyTokens($token);
  110. // if(!empty($effetc) && $effetc['code']!=0){
  111. // return error_show($effetc['code'],$effetc['message']);
  112. // }
  113. $userinfo = GetUserInfo($token);
  114. if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
  115. return error_show(101, '未能获取用户信息');
  116. }
  117. $info['status'] = 1;
  118. $info['down_url'] = '';
  119. $info['remark'] = '';
  120. $info['apply_id'] = $userinfo['data']['id'];
  121. $info['apply_name'] = $userinfo['data']['nickname'];
  122. $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
  123. $info['updatetime'] = date("Y-m-d H:i:s");
  124. $info['addtime'] = date("Y-m-d H:i:s");
  125. $up = Db::name("exec")->save($info);
  126. $redis = Cache::store("redis")->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
  127. return $up ? app_show(0, "编辑成功") : error_show(1004, "编辑失败");
  128. }
  129. }