Exec.php 5.3 KB

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