Conf.php 5.1 KB

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