Result.php 6.6 KB

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