|
@@ -0,0 +1,174 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+use app\BaseController;
|
|
|
+use think\App;
|
|
|
+use think\facade\Db;
|
|
|
+
|
|
|
+class Platform extends BaseController
|
|
|
+{
|
|
|
+ public $post ="";
|
|
|
+ public function __construct(App $app)
|
|
|
+ {
|
|
|
+ parent::__construct($app);
|
|
|
+ $this->post=$this->request->post();
|
|
|
+ }
|
|
|
+ public function create(){
|
|
|
+ $platform_code = makeNo("PT");
|
|
|
+ $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):"";
|
|
|
+ if($platform_name==""){
|
|
|
+ return error_show(1003,"参数platform_name不能为空");
|
|
|
+
|
|
|
+ }
|
|
|
+ $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
+ if($token==''){
|
|
|
+ return error_show(1005,"参数token不能为空");
|
|
|
+ }
|
|
|
+ $user =GetUserInfo($token);
|
|
|
+ if(empty($user)||$user['code']!=0){
|
|
|
+ return error_show(1002,"创建人数据不存在");
|
|
|
+ }
|
|
|
+ $action_id= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
+ $action_name= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
+ $desc=isset($this->post['desc']) && $this->post['desc'] !=="" ? trim($this->post['desc']):"";
|
|
|
+ $status= isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"0";
|
|
|
+ $data=[
|
|
|
+ "platform_code"=>$platform_code,
|
|
|
+ "platform_name"=>$platform_name,
|
|
|
+ "createrid"=>$action_id,
|
|
|
+ "creater"=>$action_name,
|
|
|
+ "desc"=>$desc,
|
|
|
+ "status"=>$status,
|
|
|
+ "is_del"=>0,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $info = Db::name("platform")->insert($data);
|
|
|
+ if($info){
|
|
|
+ return error_show(0,"新建成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1003,"新建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function list(){
|
|
|
+ $page = isset($this->post['page']) && $this->post['page']!=="" ? intval($this->post['page']):"1";
|
|
|
+ $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
|
|
|
+ $where=[["is_del","=",0]];
|
|
|
+ $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):"";
|
|
|
+ if($platform_name!=""){
|
|
|
+ $where[]=['platform_name',"like","%$platform_name%"];
|
|
|
+ }
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
|
|
|
+ if($status!=""){
|
|
|
+ $where[]=['status',"=",$status];
|
|
|
+ }
|
|
|
+ $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
|
|
|
+ if($start!==""){
|
|
|
+ $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
|
|
|
+ }
|
|
|
+ $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
|
|
|
+ if($end!==""){
|
|
|
+ $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
|
|
|
+ }
|
|
|
+ $count = Db::name('platform')->where($where)->count();
|
|
|
+ $total = ceil($count / $size);
|
|
|
+ $page = $page >= $total ? $total : $page;
|
|
|
+ $list = Db::name('platform')->where($where)->page($page,$size)->order("addtime desc")->select();
|
|
|
+ return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
|
|
|
+ }
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
|
|
|
+ if ($id == "") {
|
|
|
+ return error_show(1002, "参数id不能为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("platform")->where(['id' => $id, "is_del" => 0])->find();
|
|
|
+ if ($info == "") {
|
|
|
+ return error_show(1002, "未找到数据");
|
|
|
+ }
|
|
|
+ $platform_code = makeNo("PT");
|
|
|
+ $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !== "" ? trim($this->post['platform_name']) : "";
|
|
|
+ if ($platform_name == "") {
|
|
|
+ return error_show(1002, "参数platform_name不能为空");
|
|
|
+ }
|
|
|
+ $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
|
|
|
+ if ($token == '') {
|
|
|
+ return error_show(1005, "参数token不能为空");
|
|
|
+ }
|
|
|
+ $user = GetUserInfo($token);
|
|
|
+ if (empty($user) || $user['code'] != 0) {
|
|
|
+ return error_show(1002, "创建人数据不存在");
|
|
|
+ }
|
|
|
+ $action_id = isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
+ $action_name = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
|
|
|
+ $desc = isset($this->post['desc']) && $this->post['desc'] !== "" ? trim($this->post['desc']) : "";
|
|
|
+ $data = [
|
|
|
+ "id" => $id,
|
|
|
+ "platform_code" => $platform_code,
|
|
|
+ "platform_name" => $platform_name,
|
|
|
+ "createrid" => $action_id,
|
|
|
+ "creater" => $action_name,
|
|
|
+ "desc" => $desc,
|
|
|
+ "status" => $status,
|
|
|
+ "is_del" => 0,
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $datainfo = Db::name('platform')->save($data);
|
|
|
+ if ($datainfo) {
|
|
|
+ return error_show(0, "更新成功");
|
|
|
+ } else {
|
|
|
+ return error_show(1002, "更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function info(){
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
|
|
|
+ if($id==""){
|
|
|
+ return error_show(1002,"参数id不能为空");
|
|
|
+ }
|
|
|
+ $info = Db::name('platform')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1004,'未找到数据');
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",$info);
|
|
|
+ }
|
|
|
+ public function del(){
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
|
|
|
+ if($id==""){
|
|
|
+ return error_show(1002,"参数id不能为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1002,"未找到数据");
|
|
|
+ }
|
|
|
+ $end = Db::name('platform')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
|
|
|
+ if($end){
|
|
|
+ return error_show(0,"删除成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1002,"删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function status(){
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
|
|
|
+ if($id==""){
|
|
|
+ return error_show(1002,"参数id不能为空");
|
|
|
+ }
|
|
|
+ $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
+ if(empty($info)){
|
|
|
+ return error_show(1002,"未找到数据");
|
|
|
+ }
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
|
|
|
+ if($status===""){
|
|
|
+ return error_show(1002,"参数status不能为空");
|
|
|
+ }
|
|
|
+ if(!in_array($status,[0,1])){
|
|
|
+ return error_show(1002,"参数status无效");
|
|
|
+ }
|
|
|
+ $info['status']=$status;
|
|
|
+ $info['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $msg = $status==0?"启用":"禁用";
|
|
|
+ $update = Db::name("platform")->save($info);
|
|
|
+ return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
|
|
|
+ }
|
|
|
+}
|