Exec.php 6.3 KB

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