TenantAdminValidate.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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\auth\TenantAdmin;
  16. use app\common\model\tenant\Tenant;
  17. use app\common\validate\BaseValidate;
  18. /**
  19. * 用户验证
  20. * Class TenantValidate
  21. * @package app\adminapi\validate\user
  22. */
  23. class TenantAdminValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkUser',
  27. 'tenant_id' => 'require|checkTenant',
  28. 'account' => 'require|length:1,32|checkAccount',
  29. 'name' => 'require',
  30. 'password' => 'require|length:6,32|edit',
  31. 'password_confirm' => 'requireWith:password|confirm',
  32. ];
  33. protected $message = [
  34. 'id.require' => '请选择用户',
  35. 'name.require' => '请输入用户名',
  36. 'account.require' => '请输入账户',
  37. 'account.checkAccount' => '账号已存在',
  38. 'account.length' => '账号长度须在1-32位字符',
  39. 'tenant_id.require' => '请选择对应的租户',
  40. 'password.require' => '密码不能为空',
  41. 'password.length' => '密码长度须在6-32位字符',
  42. 'password_confirm.requireWith' => '确认密码不能为空',
  43. 'password_confirm.confirm' => '两次输入的密码不一致',
  44. ];
  45. /**
  46. * @notes 详情场景
  47. * @return TenantAdminValidate
  48. * @author yfdong
  49. * @date 2024/09/04 22:58
  50. */
  51. public function sceneDetail()
  52. {
  53. return $this->only(['id', 'tenant_id']);
  54. }
  55. /**
  56. * @notes 租户信息校验
  57. * @param $value
  58. * @param $rule
  59. * @param $data
  60. * @return string|true
  61. * @author yfdong
  62. * @date 2024/09/04 22:57
  63. */
  64. public function checkUser($value, $rule, $data)
  65. {
  66. $userIds = TenantAdmin::findOrEmpty($value);
  67. if ($userIds->isEmpty()) {
  68. return '租户管理员不存在';
  69. }
  70. return true;
  71. }
  72. public function checkAccount($value, $rule, $data)
  73. {
  74. $adminAccount = TenantAdmin::where(['account' => $value, 'tenant_id' => $data['tenant_id']])->findOrEmpty();
  75. if (!$adminAccount->isEmpty()) {
  76. return '账号已存在';
  77. }
  78. return true;
  79. }
  80. /**
  81. * @notes 检查对应租户号是否存在
  82. * @param $value
  83. * @return string|true
  84. * @author yfdong
  85. * @date 2024/09/04 22:16
  86. */
  87. public function checkTenant($value)
  88. {
  89. $adminTenant = Tenant::where(['id' => $value])->findOrEmpty();
  90. if ($adminTenant->isEmpty()) {
  91. return '对应租户账号不存在';
  92. }
  93. return true;
  94. }
  95. /**
  96. * @notes 添加场景
  97. * @return TenantAdminValidate
  98. * @author yfdong
  99. * @date 2024/09/04 22:57
  100. */
  101. public function sceneAdd()
  102. {
  103. return $this->remove('id', true);
  104. }
  105. /**
  106. * @notes 修改场景
  107. * @return TenantAdminValidate
  108. * @author yfdong
  109. * @date 2024/09/04 22:57
  110. */
  111. public function sceneEdit()
  112. {
  113. return $this->remove('password', true)->remove('account', true);
  114. }
  115. /**
  116. * @notes 删除场景
  117. * @return TenantAdminValidate
  118. * @author yfdong
  119. * @date 2024/09/04 22:57
  120. */
  121. public function sceneDelete()
  122. {
  123. return $this->only(['id']);
  124. }
  125. /**
  126. * @notes 重置密码情形
  127. * @return TenantAdminValidate
  128. * @author yfdong
  129. * @date 2024/09/04 23:29
  130. */
  131. public function sceneResetPassword()
  132. {
  133. return $this->only(['id']);
  134. }
  135. /**
  136. * @notes 编辑情况下,检查是否填密码
  137. * @param $value
  138. * @param $rule
  139. * @param $data
  140. * @return bool|string
  141. * @author 段誉
  142. * @date 2021/12/29 10:19
  143. */
  144. public function edit($value, $rule, $data)
  145. {
  146. if (empty($data['password']) && empty($data['password_confirm'])) {
  147. return true;
  148. }
  149. $len = strlen($value);
  150. if ($len < 6 || $len > 32) {
  151. return '密码长度须在6-32位字符';
  152. }
  153. return true;
  154. }
  155. }