TenantValidate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\adminapi\validate\tenant;
  15. use app\common\model\tenant\Tenant;
  16. use app\common\validate\BaseValidate;
  17. /**
  18. * 用户验证
  19. * Class TenantValidate
  20. * @package app\adminapi\validate\user
  21. */
  22. class TenantValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|checkUser',
  26. 'name' => 'require',
  27. 'domain_alias' => 'checkDomainAlias'
  28. ];
  29. protected $message = [
  30. 'id.require' => '请选择用户',
  31. 'name.require' => '请输入用户名',
  32. ];
  33. /**
  34. * @notes 详情场景
  35. * @return TenantValidate
  36. * @author 段誉
  37. * @date 2022/9/22 16:35
  38. */
  39. public function sceneDetail()
  40. {
  41. return $this->only(['id']);
  42. }
  43. /**
  44. * @notes 租户信息校验
  45. * @param $value
  46. * @param $rule
  47. * @param $data
  48. * @return bool|string
  49. * @author 段誉
  50. * @date 2022/9/22 17:03
  51. */
  52. public function checkUser($value, $rule, $data)
  53. {
  54. $userIds = Tenant::findOrEmpty($value);
  55. if ($userIds->isEmpty()) {
  56. return '租户不存在';
  57. }
  58. return true;
  59. }
  60. /**
  61. * @notes 域名校验
  62. * @param $value
  63. * @param $rule
  64. * @param $data
  65. * @return string|true
  66. * @author JXDN
  67. * @date 2024/09/11 15:30
  68. */
  69. public function checkDomainAlias($value, $rule, $data)
  70. {
  71. $tenant = Tenant::where(['domain_alias' => $value])->findOrEmpty();
  72. if (!$tenant->isEmpty()) {
  73. return '租户别名已存在';
  74. }
  75. return true;
  76. }
  77. /**
  78. * @notes 域名校验
  79. * @param $value
  80. * @param $rule
  81. * @param $data
  82. * @return string|true
  83. * @author JXDN
  84. * @date 2024/09/11 15:30
  85. */
  86. public function checkDomainAliasEdit($value, $rule, $data)
  87. {
  88. $tenant = Tenant::where('domain_alias', $value)
  89. ->where('id', '<>', $data['id']) // 排除当前租户
  90. ->findOrEmpty();
  91. if (!$tenant->isEmpty()) {
  92. return '租户别名已存在';
  93. }
  94. return true;
  95. }
  96. /**
  97. * @notes 添加场景
  98. * @return TenantValidate
  99. * @author 段誉
  100. * @date 2022/5/25 18:16
  101. */
  102. public function sceneAdd()
  103. {
  104. return $this->remove('id', true);
  105. }
  106. /**
  107. * @notes 编辑场景
  108. * @return TenantValidate
  109. * @author JXDN
  110. * @date 2024/09/11 15:31
  111. */
  112. public function sceneEdit()
  113. {
  114. return $this->only(['id', 'name'])->append('domain_alias', 'checkDomainAliasEdit');
  115. }
  116. /**
  117. * @notes 删除场景
  118. * @return TenantValidate
  119. * @author 段誉
  120. * @date 2022/5/25 18:16
  121. */
  122. public function sceneDelete()
  123. {
  124. return $this->only(['id']);
  125. }
  126. }