123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- declare (strict_types = 1);
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\Request;
- use think\App;
- class Action 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']);
- //
- // }
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function ActionList(){
- $post =$this->request->post();
- $pageid = isset($post['id']) ? intval($post['id']) : "";
- if($pageid==""){
- return error_show(1001,'页面id不能为空');
- }
- $condition = ['menuid'=>$pageid];
- $data=Db::name('action')->alias("a")->leftJoin("action_list l","a.action_code=l.action_code")->field
- ("a.*,action_name")->where($condition)->select();
- return app_show(0,"获取成功",$data);
- }
- public function ActionSave(){
- $post =$this->request->post();
- $actid = isset($post['id']) ? intval($post['id']) : "";
- if($actid==""){
- return error_show(1001,'功能id不能为空');
- }
- $menuid = isset($post['menuid']) ? intval($post['menuid']) : "";
- if($menuid==""){
- return error_show(1001,'页面menuid不能为空');
- }
- $code = isset($post['action_code']) ? trim($post['action_code']) : "";
- $status = isset($post['status']) ? intval($post['status']) : 1;
- if($code==""){
- return error_show(1002,'功能code不能为空');
- }
- $istrue =Db::name("action")->where(['menuid'=>$menuid,"action_code"=>$code])->find();
- if($istrue && $istrue['id']!=$actid){
- return error_show(1005,'此功能已存在');
- }
- try{
- $data = ['action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
- $result=Db::name("action")->where("id","=",$actid)->save($data);
- if($result){
- return app_show(0,"更新成功");
- }else{
- return error_show(1004,"更新失败");
- }
- }catch (\Exception $e){
- return error_show(1003,$e->getMessage());
- }
- }
- public function ActionStatus(){
- $post =$this->request->post();
- $actid = isset($post['id']) ? intval($post['id']) : "";
- if($actid==""){
- return error_show(1001,'功能id不能为空');
- }
- $status = isset($post['status']) ? intval($post['status']) : 1;
- try{
- $data = ['status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
- $result=Db::name("action")->where("id","=",$actid)->save($data);
- if($result){
- return app_show(0,"更新成功");
- }else{
- return error_show(1004,"更新失败");
- }
- }catch (\Exception $e){
- return error_show(1003,$e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\exception\DbException
- */
- public function ActionAdd(){
- $post =$this->request->post();
- $pageid = isset($post['menuid']) ? intval($post['menuid']) : "";
- if($pageid==""){
- return error_show(1001,'页面id不能为空');
- }
- $code = isset($post['action_code']) ? trim($post['action_code']) : "";
- $status = isset($post['status']) ? intval($post['status']) : 1;
- if($code==""){
- return error_show(1002,'功能code不能为空');
- }
- try{
- $where = ['menuid'=>$pageid,'action_code'=>$code];
- $true =Db::name("action")->where($where)->find();
- $data = ['menuid'=>$pageid,'action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s"),"addtime"=>date("Y-m-d H:i:s")];
- if($true){
- return error_show(1003,'此功能已存在');
- }else{
- Db::name("action")->insert($data);
- return app_show(0,"添加成功");
- }
- }catch (\Exception $e){
- return error_show(1005,$e->getMessage());
- }
- }
- }
|