WorkAction.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\bug\model;
  3. use think\helper\Arr;use think\model\concern\SoftDelete;
  4. class WorkAction extends Base
  5. {
  6. //设置字段信息
  7. use SoftDelete;
  8. protected $schema = [
  9. 'id' =>'int',//
  10. 'action_name' =>'varchar',//功能名称
  11. 'menu_id' =>'int',//归属菜单页面id
  12. 'belong' =>'tinyint',//系统归属1采销2结算3数据统计
  13. 'belong_action' =>'text',//功能集合
  14. 'belong_process' =>'text',//功能集合
  15. 'belong_private' =>'text',//功能集合
  16. 'apply_id' =>'int',//申请人id
  17. 'apply_name' =>'varchar',//申请人名称
  18. 'createTime' =>'datetime',//
  19. 'updateTime' =>'datetime',//
  20. 'delete_time' =>'datetime',//
  21. ];
  22. protected $updateTime='updateTime';
  23. protected $createTime='createTime';
  24. protected $deleteTime = 'delete_time';
  25. public function GetBelongActionAttr($v){
  26. return json_decode($v,true);
  27. }
  28. public function SetBelongActionAttr($v){
  29. return json_encode($v,JSON_UNESCAPED_UNICODE);
  30. }
  31. public function GetBelongPrivateAttr($v){
  32. return json_decode($v,true);
  33. }
  34. public function SetBelongPrivateAttr($v){
  35. return json_encode($v,JSON_UNESCAPED_UNICODE);
  36. }
  37. public function GetBelongProcessAttr($v){
  38. return json_decode($v,true);
  39. }
  40. public function SetBelongProcessAttr($v){
  41. return json_encode($v,JSON_UNESCAPED_UNICODE);
  42. }
  43. public function GetTreeActionByIdArr($idArr,$belong=0){
  44. $list = $this->whereIn("id",$idArr)->field("id,action_name,menu_id,belong_action,belong_private,belong_process")->select();
  45. $temp=[];
  46. foreach ($list as $item){
  47. $meun = $this->GetMenuList($item->menu_id,$belong);
  48. $item->belong_action_info = $this->GetActionList($item->belong_action,$belong);
  49. $item->belong_private_info = $this->GetActionList($item->belong_private,$belong);
  50. $item->belong_process_info = $this->GetProcessList($item->belong_process,$belong);
  51. $temp[]=array_merge($item->toArray(),$meun);
  52. }
  53. return $temp;
  54. }
  55. public function GetMenuList($menuid,$belong){
  56. $menu=[];
  57. switch ($belong){
  58. case 1:
  59. $menu=\app\admin\model\AdminMenu::GetMenu($menuid);
  60. break;
  61. case 2:
  62. $menu=\app\cxinv\model\AdminMenu::GetMenu($menuid);
  63. break;
  64. case 3:
  65. $menu=\app\cxinv\model\AdminMenu::GetMenu($menuid);
  66. break;
  67. }
  68. return$menu;
  69. }
  70. public function GetActionList($action,$belong){
  71. $act=[];
  72. switch ($belong){
  73. case 1:
  74. $act=\app\admin\model\Action::GetAction($action);
  75. break;
  76. case 2:
  77. $act=\app\cxinv\model\Action::GetAction($action);
  78. break;
  79. case 3:
  80. $act=\app\cxinv\model\Action::GetAction($action);
  81. break;
  82. }
  83. return$act;
  84. }
  85. public function GetProcessList($action,$belong){
  86. $act=[];
  87. switch ($belong){
  88. case 1:
  89. $act=\app\admin\model\ActionProcess::GetProcess($action);
  90. break;
  91. case 2:
  92. $act=\app\admin\model\ActionProcess::GetProcess($action);
  93. break;
  94. case 3:
  95. $act=\app\admin\model\ActionProcess::GetProcess($action);
  96. break;
  97. }
  98. return$act;
  99. }
  100. public function GetInfoById($id,$belong=0){
  101. $list = $this->where('id',$id)->field('id,action_name,menu_id,belong_action')->findOrEmpty();
  102. $meun = $this->GetMenuList($list->menu_id,$belong);
  103. $list->belong_action_info = $this->GetActionList($list->belong_action,$belong);
  104. $temp=array_merge($list->toArray(),$meun);
  105. return $temp;
  106. }
  107. public function CreateByArray($array){
  108. $ave = $this->saveAll($array);
  109. if($ave->isEmpty())throw new \Exception("功能创建失败");
  110. return array_column($ave->toArray(),"id");
  111. }
  112. public function GetBelongActionByIdArrs($IdArrs){
  113. $list = $this->whereIn('id',$IdArrs)->field('belong_action,belong_private,belong_process')->select();
  114. if($list->isEmpty())return [];
  115. $action = array_column($list->toArray(),"belong_action");
  116. $private = array_column($list->toArray(),"belong_private");
  117. $process = array_column($list->toArray(),"belong_process");
  118. return ["action"=>array_values(array_unique(Arr::flatten($action))),"private"=>array_values(array_unique(Arr::flatten
  119. ($private))),"process"=>array_values(array_unique(Arr::flatten($process)))];
  120. }
  121. }