Result.php 6.5 KB

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