123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- //系统配置
- class Conf extends BaseController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $post =$this->request->post();
- $token = isset($post['token']) ? trim($post['token']) : "";
- // if($token==""){
- // return error_show(101,'token不能为空');
- //
- // }
- // $effetc = VerifyTokens($token);
- // if(!empty($effetc) && $effetc['code']!=0){
- // return error_show($effetc['code'],$effetc['message']);
- //
- // }
- }
- public function list(){
- $post = $this->request->post();
- $condition = [['is_del'=>0]];
- $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
- $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
- $count = Db::name("config")->where($condition)->count();
- $page>=ceil($count/$size) ? $page = ceil($count/$size): '';
- $list = Db::name("config")->where($condition)->page($page,$size)->order("addtime desc")->select();
- return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
- }
- public function info(){
- $post = $this->request->post();
- $id = isset($post['id']) && $post['id']!==''? intval($post['id']): '';
- if($id==''){
- return error_show(1004,'参数id 不能为空');
- }
- $condition = [['is_del'=>0],['id'=>$id]];
- $info = Db::name("config")->where($condition)->find();
- if(empty($info)){
- return error_show(1004,'未找到数据');
- }
- return app_show(0,"获取成功",$info);
- }
- public function add(){
- $post = $this->request->post();
- $name = isset($post['name'])&& $post['name']!='' ? trim($post['name']) :"";
- if($name==""){
- return error_show(1004,"参数name 不能为空");
- }
- $ist = Db::name("config")->where(["name"=>$name,"is_del"=>0])->find();
- if(!empty($ist)){
- return error_show(1004,"配置名称已存在");
- }
- $setv = isset($post['setv'])&& $post['setv']!='' ? trim($post['setv']) :"";
- if($setv==""){
- return error_show(1004,"参数setv 不能为空");
- }
- $start= isset($post['start'])&& $post['start']!='' ? $post['start'] :date("Y-m-d H:i:s");
- $end= isset($post['end'])&& $post['end']!='' ? $post['end'] :null;
- $status= isset($post['status'])&& $post['status']!='' ? intval($post['satus']) :"1";
- $data= [
- "name"=>$name,
- "setv"=>$setv,
- 'status'=>$status,
- "starttime"=>$start,
- "endtime"=>$end,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $iser=Db::name("config")->insert($data);
- return $iser ? app_show(0,"新建成功"):error_show(1008,"新建失败");
- }
- public function edit(){
- $post = $this->request->post();
- $id = isset($post['id'])&& $post['id']!='' ? intval($post['id']) :"";
- if($id==""){
- return error_show(1004,"参数id 不能为空");
- }
- $data = Db::name("config")->where(['id'=>$id,"is_del"=>0])->find();
- if(empty($data)){
- return error_show(1005,"未找到数据");
- }
- $name = isset($post['name'])&& $post['name']!='' ? trim($post['name']) :"";
- if($name==""){
- return error_show(1004,"参数name 不能为空");
- }
- $ist = Db::name("config")->where(["name"=>$name,"is_del"=>0])->find();
- if(!empty($ist)&&$ist['id']!=$id){
- return error_show(1004,"配置名称已存在");
- }
- $setv = isset($post['setv'])&& $post['setv']!='' ? trim($post['setv']) :"";
- if($setv==""){
- return error_show(1004,"参数setv 不能为空");
- }
- $start= isset($post['start'])&& $post['start']!='' ? $post['start'] :date("Y-m-d H:i:s");
- $end= isset($post['end'])&& $post['end']!='' ? $post['end'] :null;
- $status= isset($post['status'])&& $post['status']!='' ? intval($post['satus']) :"1";
- $data= [
- "id"=>$id,
- "name"=>$name,
- "setv"=>$setv,
- 'status'=>$status,
- "starttime"=>$start,
- "endtime"=>$end,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $iser=Db::name("config")->save($data);
- return $iser ? app_show(0,"新建成功"):error_show(1008,"新建失败");
- }
- public function delete(){
- $post = $this->request->post();
- $id = isset($post['id'])&& $post['id']!='' ? intval($post['id']) :"";
- if($id==""){
- return error_show(1004,"参数id 不能为空");
- }
- $data = Db::name("config")->where(['id'=>$id,"is_del"=>0])->find();
- if(empty($data)){
- return error_show(1005,"未找到数据");
- }
- $data['is_del']=1;
- $data['updatetime']=date("Y-m-d H:i:s");
- $iser=Db::name("config")->save($data);
- return $iser ? app_show(0,"删除成功"):error_show(1008,"删除失败");
- }
- }
|