JobsValidate.php 3.2 KB

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