WorkSubscr.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\bug\model;
  3. use think\Exception;use think\model\concern\SoftDelete;class WorkSubscr extends Base
  4. {
  5. //设置字段信息
  6. use SoftDelete;
  7. protected $schema = [
  8. 'id' =>'int',//
  9. 'belong' =>'tinyint',//系统归属
  10. 'role_id' =>'int',//角色id
  11. 'action' =>'text',//选中的岗位功能
  12. 'role_action' =>'text',//选中的岗位功能
  13. 'apply_id' =>'int',//申请人id
  14. 'apply_name' =>'varchar',//申请人名称
  15. 'check_id' =>'int',//审核人
  16. 'check_name' =>'varchar',//审核人
  17. 'status' =>'tinyint',//状态
  18. 'is_check' =>'tinyint',//是否有待审核数据
  19. 'createTime' =>'datetime',//
  20. 'updateTime' =>'datetime',//
  21. 'delete_time' =>'datetime',//
  22. ];
  23. protected $updateTime='updateTime';
  24. protected $createTime='createTime';
  25. protected $deleteTime = 'delete_time';
  26. public static $statusCn=['无状态',"待审批","部分通过", "全部通过" ,"全部驳回","废弃"];
  27. public function RoleInfo(){
  28. return $this->belongsTo(WorkRole::class,"role_id","id")->bind(["role_name","work_id","work_name","companyNo",'companyName']);
  29. }
  30. public function subInfo(){
  31. return $this->hasMany(WorkSubinfo::class,'sub_id','id');
  32. }
  33. public function GetActionAttr($v){
  34. return json_decode($v,true);
  35. }
  36. public function SetActionAttr($v){
  37. return json_encode($v,JSON_UNESCAPED_UNICODE);
  38. }
  39. public function GetRoleActionAttr($v){
  40. return json_decode($v,true);
  41. }
  42. public function SetRoleActionAttr($v){
  43. return json_encode($v,JSON_UNESCAPED_UNICODE);
  44. }
  45. public static function GetActionById($id){
  46. $info = self::findOrEmpty($id);
  47. if($info->is_check==1) throw new \Exception("功能权限申请存在数据未审核",1004);
  48. $list = WorkSubinfo::where(["sub_id"=>$id,"status"=>1])->column("action_id,type");
  49. $result = $info->role_action;
  50. $tempAdd=[];
  51. $tempRemove=[];
  52. if(!empty($list)){
  53. foreach ($list as $item){
  54. if($item['type']==1) $tempAdd[]=$item['action_id'];
  55. if($item['type']==2)$tempRemove[]=$item['action_id'];
  56. }
  57. }
  58. return array_diff(array_merge($result,$tempAdd),$tempRemove);
  59. }
  60. }