1
0

SetMasterWorkerInfoValidate.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | whitef快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/whitef
  8. // | github下载:https://github.com/likeshop-github/whitef
  9. // | 访问官网:https://www.whitef.cn
  10. // | whitef团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: whitefTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\workerapi\validate;
  15. use app\common\model\user\User;
  16. use app\common\validate\BaseValidate;
  17. /**
  18. * 设置师傅信息
  19. */
  20. class SetMasterWorkerInfoValidate extends BaseValidate
  21. {
  22. protected $rule = [
  23. 'field' => 'require|checkField',
  24. 'value' => 'require',
  25. ];
  26. protected $message = [
  27. 'field.require' => '参数缺失',
  28. 'value.require' => '值不存在',
  29. ];
  30. /**
  31. * @notes 校验字段内容
  32. * @param $value
  33. * @param $rule
  34. * @param $data
  35. * @return bool|string
  36. * @author 段誉
  37. * @date 2022/9/21 17:01
  38. */
  39. protected function checkField($value, $rule, $data)
  40. {
  41. $allowField = [
  42. 'nickname', 'account', 'sex', 'avatar', 'real_name',
  43. ];
  44. if (!in_array($value, $allowField)) {
  45. return '参数错误';
  46. }
  47. if ($value == 'account') {
  48. $user = User::where([
  49. ['account', '=', $data['value']],
  50. ['id', '<>', $data['id']]
  51. ])->findOrEmpty();
  52. if (!$user->isEmpty()) {
  53. return '账号已被使用!';
  54. }
  55. }
  56. return true;
  57. }
  58. }