Conf.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Conf extends BaseController
  7. {
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $post =$this->request->post();
  12. $token = isset($post['token']) ? trim($post['token']) : "";
  13. // if($token==""){
  14. // return error_show(101,'token不能为空');
  15. //
  16. // }
  17. // $effetc = VerifyTokens($token);
  18. // if(!empty($effetc) && $effetc['code']!=0){
  19. // return error_show($effetc['code'],$effetc['message']);
  20. //
  21. // }
  22. }
  23. public function list(){
  24. $post = $this->request->post();
  25. $condition = [['is_del'=>0]];
  26. $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
  27. $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
  28. $count = Db::name("config")->where($condition)->count();
  29. $page>=ceil($count/$size) ? $page = ceil($count/$size): '';
  30. $list = Db::name("config")->where($condition)->page($page,$size)->order("addtime desc")->select();
  31. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  32. }
  33. public function info(){
  34. $post = $this->request->post();
  35. $id = isset($post['id']) && $post['id']!==''? intval($post['id']): '';
  36. if($id==''){
  37. return error_show(1004,'参数id 不能为空');
  38. }
  39. $condition = [['is_del'=>0],['id'=>$id]];
  40. $info = Db::name("config")->where($condition)->find();
  41. if(empty($info)){
  42. return error_show(1004,'未找到数据');
  43. }
  44. return app_show(0,"获取成功",$info);
  45. }
  46. public function add(){
  47. $post = $this->request->post();
  48. $name = isset($post['name'])&& $post['name']!='' ? trim($post['name']) :"";
  49. if($name==""){
  50. return error_show(1004,"参数name 不能为空");
  51. }
  52. $ist = Db::name("config")->where(["name"=>$name,"is_del"=>0])->find();
  53. if(!empty($ist)){
  54. return error_show(1004,"配置名称已存在");
  55. }
  56. $setv = isset($post['setv'])&& $post['setv']!='' ? trim($post['setv']) :"";
  57. if($setv==""){
  58. return error_show(1004,"参数setv 不能为空");
  59. }
  60. $start= isset($post['start'])&& $post['start']!='' ? $post['start'] :date("Y-m-d H:i:s");
  61. $end= isset($post['end'])&& $post['end']!='' ? $post['end'] :null;
  62. $status= isset($post['status'])&& $post['status']!='' ? intval($post['satus']) :"1";
  63. $data= [
  64. "name"=>$name,
  65. "setv"=>$setv,
  66. 'status'=>$status,
  67. "starttime"=>$start,
  68. "endtime"=>$end,
  69. "addtime"=>date("Y-m-d H:i:s"),
  70. "updatetime"=>date("Y-m-d H:i:s")
  71. ];
  72. $iser=Db::name("config")->insert($data);
  73. return $iser ? app_show(0,"新建成功"):error_show(1008,"新建失败");
  74. }
  75. public function edit(){
  76. $post = $this->request->post();
  77. $id = isset($post['id'])&& $post['id']!='' ? intval($post['id']) :"";
  78. if($id==""){
  79. return error_show(1004,"参数id 不能为空");
  80. }
  81. $data = Db::name("config")->where(['id'=>$id,"is_del"=>0])->find();
  82. if(empty($data)){
  83. return error_show(1005,"未找到数据");
  84. }
  85. $name = isset($post['name'])&& $post['name']!='' ? trim($post['name']) :"";
  86. if($name==""){
  87. return error_show(1004,"参数name 不能为空");
  88. }
  89. $ist = Db::name("config")->where(["name"=>$name,"is_del"=>0])->find();
  90. if(!empty($ist)&&$ist['id']!=$id){
  91. return error_show(1004,"配置名称已存在");
  92. }
  93. $setv = isset($post['setv'])&& $post['setv']!='' ? trim($post['setv']) :"";
  94. if($setv==""){
  95. return error_show(1004,"参数setv 不能为空");
  96. }
  97. $start= isset($post['start'])&& $post['start']!='' ? $post['start'] :date("Y-m-d H:i:s");
  98. $end= isset($post['end'])&& $post['end']!='' ? $post['end'] :null;
  99. $status= isset($post['status'])&& $post['status']!='' ? intval($post['satus']) :"1";
  100. $data= [
  101. "id"=>$id,
  102. "name"=>$name,
  103. "setv"=>$setv,
  104. 'status'=>$status,
  105. "starttime"=>$start,
  106. "endtime"=>$end,
  107. "updatetime"=>date("Y-m-d H:i:s")
  108. ];
  109. $iser=Db::name("config")->save($data);
  110. return $iser ? app_show(0,"新建成功"):error_show(1008,"新建失败");
  111. }
  112. public function delete(){
  113. $post = $this->request->post();
  114. $id = isset($post['id'])&& $post['id']!='' ? intval($post['id']) :"";
  115. if($id==""){
  116. return error_show(1004,"参数id 不能为空");
  117. }
  118. $data = Db::name("config")->where(['id'=>$id,"is_del"=>0])->find();
  119. if(empty($data)){
  120. return error_show(1005,"未找到数据");
  121. }
  122. $data['is_del']=1;
  123. $data['updatetime']=date("Y-m-d H:i:s");
  124. $iser=Db::name("config")->save($data);
  125. return $iser ? app_show(0,"删除成功"):error_show(1008,"删除失败");
  126. }
  127. }