Result.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Result extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post = $this->request->post();
  13. $token = isset($this->post['token']) ? trim($this->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. }
  22. public function list()
  23. {
  24. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  25. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  26. $where = ['is_del' => 0];
  27. $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
  28. if ($type !== "") {
  29. $where['type'] = $type;
  30. }
  31. $count = Db::name("result_info")->where($where)->count();
  32. $total = ceil($count / $size);
  33. $page = $page >= $total ? $total : $page;
  34. $list = Db::name('result_info')->where($where)->page($page, $size)->select();
  35. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  36. }
  37. /*新建*/
  38. public function create()
  39. {
  40. $result = isset($this->post['result']) && $this->post['result'] !== "" ? trim($this->post['result']) : "";
  41. if ($result == "") {
  42. return error_show(1002, "异常原因不能为空");
  43. }
  44. $desc = isset($this->post['result_desc']) && $this->post['result_desc'] !== "" ? trim($this->post['result_desc']) : "";
  45. if ($desc == "") {
  46. return error_show(1002, "异常描述不能为空");
  47. }
  48. $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "1";
  49. //$result_code = isset($this->post['result_code']) && $this->post['result_code'] !=="" ? intval($this->post['result_code']):"";
  50. $count = Db::name('result_info')->count();
  51. $str = sprintf("%04d", $count);
  52. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  53. $data = [
  54. "result" => $result,
  55. "result_desc" => $desc,
  56. "result_code" => $str,
  57. "status" => $status,
  58. "type" => $type,
  59. "is_del" => 0,
  60. "updatetime" => date("Y-m-d H:i:s"),
  61. "addtime" => date("Y-m-d H:i:s")
  62. ];
  63. $cr = Db::name('result_info')->insert($data);
  64. return $cr ? error_show(0, "添加成功") : error_show(1002, "添加失败");
  65. }
  66. /*查询*/
  67. public function selec()
  68. {
  69. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  70. if ($id == "") {
  71. return error_show(1002, "异常原因不存在");
  72. }
  73. $su = Db::name('result_info')->where(['id' => $id, 'is_del' => 0])->find();
  74. return app_show(0, "获取成功", $su);
  75. }
  76. /*编辑*/
  77. public function edit()
  78. {
  79. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  80. $sid = Db::name('result_info')->where(['id' => $id, 'is_del' => 0])->find();
  81. if ($sid == "") {
  82. return error_show(1002, "异常信息不存在");
  83. }
  84. $result = isset($this->post['result']) && $this->post['result'] !== "" ? trim($this->post['result']) : "";
  85. if ($result == "") {
  86. return error_show(1002, "异常内容不能为空");
  87. }
  88. $result_desc = isset($this->post['result_desc']) && $this->post['result_desc'] !== "" ? trim($this->post['result_desc']) : "";
  89. if ($result_desc == "") {
  90. return error_show(1002, "异常描述不能为空");
  91. }
  92. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  93. $li = [
  94. "id" => $id,
  95. "result" => $result,
  96. "result_desc" => $result_desc,
  97. "is_del" => 0,
  98. "status" => $status,
  99. "updatetime" => date("Y-m-d H:i:s"),
  100. ];
  101. $stn = Db::name('result_info')->where(['is_del' => 0, 'id' => $id])->save($li);
  102. return $stn ? error_show(0, "编辑成功") : error_show(1002, "编辑失败");
  103. }
  104. public function del()
  105. {
  106. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  107. $kid = Db::name('result_info')->where(['is_del' => 0, 'id' => $id])->find();
  108. if ($kid == false) {
  109. return error_show(1002, "异常信息不存在");
  110. }
  111. $back = Db::name('result_info')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  112. if ($back) {
  113. return error_show(0, '删除成功');
  114. } else {
  115. return error_show(1002, '删除失败');
  116. }
  117. }
  118. public function statu()
  119. {
  120. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  121. if ($id == "") {
  122. return error_show(1004, "参数id 不能为空");
  123. }
  124. $pd = Db::name('result_info')->where(['id' => $id])->find();
  125. if (empty($pd)) {
  126. return error_show(1002, "未找到原因编码");
  127. }
  128. $dp = $pd['status'] == 0 ? "1" : "0";
  129. $pd['status'] = $dp;
  130. $pd ['updatetime'] = date('Y-m-d H:i:s');
  131. $tn = Db::name('result_info')->save($pd);
  132. if ($tn) {
  133. return error_show(0, "状态更新成功");
  134. } else {
  135. return error_show(1002, "状态更新失败");
  136. }
  137. }
  138. }