MasterWokerValidate.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\workerapi\validate;
  3. use app\common\enum\notice\NoticeEnum;
  4. use app\common\service\sms\SmsDriver;
  5. use app\common\validate\BaseValidate;
  6. /**
  7. * @author 林海涛
  8. * @date 2024/7/10 下午1:42
  9. */
  10. class MasterWokerValidate extends BaseValidate
  11. {
  12. protected $rule = [
  13. 'mobile' => 'require|mobile',
  14. 'code' => 'require|checkCode',
  15. 'password' => 'require|length:6,20|alphaNum',
  16. 'password_confirm' => 'require|confirm',
  17. 'field' => 'require|checkField',
  18. 'value' => 'require',
  19. ];
  20. protected $message = [
  21. 'mobile.require' => '请输入手机号',
  22. 'mobile.mobile' => '请输入正确手机号',
  23. 'code.require' => '请填写验证码',
  24. 'password.require' => '请输入密码',
  25. 'password.length' => '密码须在6-25位之间',
  26. 'password.alphaNum' => '密码须为字母数字组合',
  27. 'password_confirm.require' => '请确认密码',
  28. 'password_confirm.confirm' => '两次输入的密码不一致',
  29. 'field.require' => '参数缺失',
  30. 'value.require' => '值不存在',
  31. ];
  32. protected function checkField($value, $rule, $data)
  33. {
  34. $allowField = [
  35. 'nickname', 'sex', 'real_avatar','avatar', 'real_name','accept_order_status',
  36. ];
  37. if (!in_array($value, $allowField)) {
  38. return '参数错误';
  39. }
  40. return true;
  41. }
  42. public function checkCode($code, $rule, $data)
  43. {
  44. $smsDriver = new SmsDriver();
  45. $result = $smsDriver->verify($data['mobile'], $code, NoticeEnum::CHANGE_MOBILE_CAPTCHA);
  46. if ($result) {
  47. return true;
  48. }
  49. return true;
  50. //return '验证码错误';
  51. }
  52. public function sceneChangeMobile(){
  53. return $this->only(['mobile', 'code']);
  54. }
  55. public function sceneChangePassword()
  56. {
  57. return $this->only(['password', 'password_confirm']);
  58. }
  59. public function sceneSetInfo()
  60. {
  61. return $this->only(['field', 'value']);
  62. }
  63. public function sceneInterview()
  64. {
  65. return $this->only(['sys_uuid', 'worker_id','nickname','status','start_answer','answer','answer1','answer2','answer3','answer4','answer5','answer6','answer7','answer8','answer9','answer10','class','class1','class2','question','question_answer']);
  66. }
  67. public function sceneQuestion()
  68. {
  69. return $this->only(['category']);
  70. }
  71. }