TenantDept.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\dept;
  15. use app\common\model\auth\TenantAdminDept;
  16. use app\common\model\BaseModel;
  17. use think\Exception;
  18. use think\model\concern\SoftDelete;
  19. /**
  20. * 部门模型
  21. * Class Dept
  22. * @package app\common\model\article
  23. */
  24. class TenantDept extends BaseModel
  25. {
  26. use SoftDelete;
  27. protected $deleteTime = 'delete_time';
  28. /**
  29. * @notes 初始化管理员部门信息
  30. * @param mixed $tenantId
  31. * @param mixed $managerId
  32. * @return void
  33. * @throws Exception
  34. * @author yfdong
  35. * @date 2024/09/12 21:43
  36. */
  37. public static function initialization(mixed $tenantId, mixed $managerId)
  38. {
  39. $field = "tenant_id,name,pid,sort,leader,mobile,status";
  40. $tenantDept = TenantDept::where(['tenant_id' => 0])->field($field)->findOrEmpty()->toArray();
  41. if($tenantDept){
  42. $tenantDept['tenant_id'] = $tenantId;
  43. $dept = TenantDept::create($tenantDept);
  44. //添加对应的部门关联关系
  45. $tenantAdminDept ['admin_id'] = $managerId;
  46. $tenantAdminDept ['dept_id'] = $dept['id'];
  47. TenantAdminDept::create($tenantAdminDept);
  48. }else{
  49. throw new Exception("部门模板缺失");
  50. }
  51. }
  52. /**
  53. * @notes 状态描述
  54. * @param $value
  55. * @param $data
  56. * @return string
  57. * @author 段誉
  58. * @date 2022/5/25 18:03
  59. */
  60. public function getStatusDescAttr($value, $data)
  61. {
  62. return $data['status'] ? '正常' : '停用';
  63. }
  64. }