Purview.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\system;
  10. use app\admin\service\Service;
  11. use app\common\models\system\Manage as ManageModel;
  12. use app\common\models\system\Purview as PurviewModel;
  13. class Purview extends Service {
  14. /**
  15. * 列表
  16. * @param $data
  17. * @return array
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\DbException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. */
  22. public static function getList($data){
  23. $count = ManageModel::count();
  24. $list = ManageModel::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  25. return [ "count"=>$count,"data"=>$list ];
  26. }
  27. /**
  28. * 详情
  29. * @param $id
  30. * @return array
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public static function detail($id){
  36. $row = ManageModel::where("id",$id)->find();
  37. if(isset($row["lock"]) && $row["lock"] == 1) {
  38. throw new \Exception("该分组已被锁定,不允许修改",0);
  39. }
  40. $systemMenu = PurviewModel::where(['status'=>0,"pid"=>0])->select()->toArray();
  41. foreach($systemMenu as $key=>$item){
  42. $children = PurviewModel::where(['status'=>0,"pid"=>$item["id"]])->select()->toArray();
  43. foreach($children as $k=>$v){
  44. $children[$k]["children"] = PurviewModel::where(['status'=>0,"pid"=>$v["id"]])->select()->toArray();
  45. }
  46. $systemMenu[$key]["children"] = $children;
  47. }
  48. return [ "group"=>$systemMenu, "data"=>$row ];
  49. }
  50. /**
  51. * 保存数据
  52. * @param $data
  53. * @return bool
  54. */
  55. public static function save($data){
  56. $data["purview"] = isset($data["purview"]) && is_array($data["purview"]) ? json_encode($data["purview"],JSON_UNESCAPED_UNICODE) : $data["purview"];
  57. if(ManageModel::where("id",$data["id"])->count()){
  58. ManageModel::where("id",$data["id"])->save($data);
  59. }else{
  60. ManageModel::create($data);
  61. }
  62. return true;
  63. }
  64. /**
  65. * 删除
  66. * @param $id
  67. * @return bool
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public static function delete($id){
  73. $row = ManageModel::where('id',$id)->find();
  74. if(empty($row)){
  75. throw new \Exception("您要查找的数据不存在",0);
  76. }
  77. if($row["lock"] == 1){
  78. throw new \Exception("该权限为系统权限,不允许删除。",0);
  79. }
  80. return ManageModel::where('id',$id)->delete();
  81. }
  82. /**
  83. * 更新字段值
  84. * @return ManageModel
  85. */
  86. public static function setFields(){
  87. $data = self::getFields();
  88. $row = ManageModel::where('id',$data["id"])->find();
  89. if(empty($row)){
  90. throw new \Exception("您要查找的数据不存在!",0);
  91. }
  92. if($row["lock"] == 1){
  93. throw new \Exception("该权限为系统权限,不允许更改。",0);
  94. }
  95. return ManageModel::where("id",$data["id"])->update([$data["name"]=>$data["value"]]);
  96. }
  97. }