123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- class Action extends BaseController
- {
- /**
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index(){
- $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']);
- }
- $data = Db::name("admin_menu")->where(["pid"=>0,"status"=>1])->select();
- $result = [];
- if(empty($data)){
- return app_show(0,"获取成功",$result);
- }
- foreach ($data as $key=>$val){
- $val["child"]=[];
- $result[$val['id']] =$val;
- }
- $child =Db::name("admin_menu")->where("pid","<>",0)->where('status',"=",1)->select();
- foreach ($child as $k=>$value){
- // $act = PasAction::all(['menuid'=>$value['id'],"status"=>1]);
- $act =Db::name("action")->alias("a")->leftJoin("cfp_action_list l","a.action_code=l.action_code")->field
- ("a.*,action_name")->where(['a.menuid'=>$value['id'],"a.status"=>1])->select();
- $act_data = Db::name("action_field")->where(['menuid'=>$value['id'],"status"=>1])->select();
- $value['action'] = $act;
- $value['action_data'] = $act_data;
- if(array_key_exists($value['pid'],$result)){
- $result[$value['pid']]["child"][]=$value;
- }
- }
- return app_show(0,"获取成功",array_values($result));
- }
- /**
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function DataAction(){
- $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']);
- }
- $data = Db::name("data_action")->where(["status"=>1])->select();
- return app_show(0,"获取成功",$data);
- }
- public function ActionList(){
- $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']);
- }
- $condition = isset($post['contidion']) ? $post['contidion'] :"1";
- $page = isset($post['page']) ? intval($post['page']) : 1;
- $size = isset($post['size']) ? intval($post['size']) : 10;
- $count = Db::name("action_list")->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("action_list")->page($page,$size)->select();
- $data =['list'=>$list,"count"=>$count];
- return app_show(0,'获取成功',$data);
- }
- /**@param id 存在更新 /不存在新建
- /**@param action_name
- /**@param action_desc
- /**@param status
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function ActionSave(){
- $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']);
- }
- $actionid = isset($post['id']) ? intval($post['id']) : "";
- if($actionid!=""){
- $isf= Db::name("action_list")->where("id","=",$actionid)->find();
- if($isf==false){
- return error_show(1005,"未找到数据");
- }
- }
- $action = isset($post['action_name']) ? trim($post['action_name']) : "";
- if($action==""){
- return error_show(1003,'功能名称不能为空');
- }
- $desc = isset($post['action_desc']) ? trim($post['action_desc']) : "";
- $status = isset($post['status']) ? intval($post['status']) : 0;
- $data=[
- "action_name"=>$action,
- "action_desc"=>$desc,
- "action_code"=>"",
- ];
- $isTrue = Db::name("action_list")->where(["action_name"=>$action])->find();
- if($isTrue){
- if($isTrue['id']!=$actionid || $actionid==""){
- return error_show(1003,'功能名称不能重复');
- }
- }
- try{
- $message = "";
- if($actionid==""){
- $data['status']=$status;
- $data['is_show']=1;
- $message = "新建成功";
- }else{
- $data['status']=$status;
- $data['id']=$actionid;
- $message = "更新成功";
- }
- Db::name("action_list")->save($data);
- return app_show(0,$message);
- }catch (\Exception $e){
- return error_show(1005,$e->getMessage());
- }
- }
- /**@param id menu 主键id
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function ActionInfo(){
- $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']);
- }
- $id = isset($post['id'])? intval($post['id']) :"";
- if($id==""){
- return error_show(1002,'功能id不能为空');
- }
- $menu = Db::name("action_list")->where("id","=",$id)->find();
- if(empty($menu)){
- return error_show(1003,"未找到对应的数据");
- }
- return app_show(0,"获取成功!",$menu);
- }
- /**@param id menu 主键id
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function ActionStatus(){
- $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']);
- }
- $id = isset($post['id'])? intval($post['id']) :"";
- if($id==""){
- return error_show(1002,'功能id不能为空');
- }
- $status = isset($post['status'])? intval($post['status']) :"";
- if($status===""){
- return error_show(1002,'状态status不能为空');
- }
- $menu = Db::name("action_list")->where("id","=",$id)->save(['status'=>$status]);
- return $menu ? app_show(0,"更新成功!") : error_show(1004,"更新失败");
- }
- }
|