JobsValidate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\tenantapi\validate\dept;
  15. use app\common\model\auth\TenantAdminJobs;
  16. use app\common\model\dept\TenantJobs;
  17. use app\common\validate\BaseValidate;
  18. /**
  19. * 岗位验证
  20. * Class JobsValidate
  21. * @package app\tenantapi\validate\dept
  22. */
  23. class JobsValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkJobs',
  27. 'name' => 'require|unique:'.TenantJobs::class.'|length:1,50',
  28. 'code' => 'require|unique:'.TenantJobs::class,
  29. 'status' => 'require|in:0,1',
  30. 'sort' => 'egt:0',
  31. ];
  32. protected $message = [
  33. 'id.require' => '参数缺失',
  34. 'name.require' => '请填写岗位名称',
  35. 'name.length' => '岗位名称长度须在1-50位字符',
  36. 'name.unique' => '岗位名称已存在',
  37. 'code.require' => '请填写岗位编码',
  38. 'code.unique' => '岗位编码已存在',
  39. 'sort.egt' => '排序值不正确',
  40. 'status.require' => '请选择岗位状态',
  41. 'status.in' => '岗位状态值错误',
  42. ];
  43. /**
  44. * @notes 添加场景
  45. * @return JobsValidate
  46. * @author 段誉
  47. * @date 2022/5/26 9:53
  48. */
  49. public function sceneAdd()
  50. {
  51. return $this->remove('id', true);
  52. }
  53. /**
  54. * @notes 详情场景
  55. * @return JobsValidate
  56. * @author 段誉
  57. * @date 2022/5/26 9:53
  58. */
  59. public function sceneDetail()
  60. {
  61. return $this->only(['id']);
  62. }
  63. public function sceneEdit()
  64. {
  65. }
  66. /**
  67. * @notes 删除场景
  68. * @return JobsValidate
  69. * @author 段誉
  70. * @date 2022/5/26 9:54
  71. */
  72. public function sceneDelete()
  73. {
  74. return $this->only(['id'])->append('id', 'checkAbleDetele');
  75. }
  76. /**
  77. * @notes 校验岗位
  78. * @param $value
  79. * @return bool|string
  80. * @author 段誉
  81. * @date 2022/5/26 9:55
  82. */
  83. public function checkJobs($value)
  84. {
  85. $jobs = TenantJobs::findOrEmpty($value);
  86. if ($jobs->isEmpty()) {
  87. return '岗位不存在';
  88. }
  89. return true;
  90. }
  91. /**
  92. * @notes 校验能否删除
  93. * @param $value
  94. * @return bool|string
  95. * @author 段誉
  96. * @date 2022/5/26 14:22
  97. */
  98. public function checkAbleDetele($value)
  99. {
  100. $check = TenantAdminJobs::where(['jobs_id' => $value])->findOrEmpty();
  101. if (!$check->isEmpty()) {
  102. return '已关联管理员,暂不可删除';
  103. }
  104. return true;
  105. }
  106. }