Memberaddress.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 验证器
  10. */
  11. class Memberaddress extends Validate
  12. {
  13. protected $rule = [
  14. 'city_id' => 'gt:0',
  15. 'area_id' => 'gt:0',
  16. 'address_realname' => 'require',
  17. 'area_info' => 'require',
  18. 'address_detail' => 'require',
  19. 'address_mob_phone' => 'checkMemberAddressMobPhone:1' //
  20. ];
  21. protected $message = [
  22. 'city_id.gt' => '请选择地区',
  23. 'area_id.gt' => '地区至少两级',
  24. 'address_realname.require' => '姓名不能为空',
  25. 'area_info.require' => '地区不能为空',
  26. 'address_detail.require' => '地址不能为空',
  27. 'address_mob_phone.checkMemberAddressMobPhone' => '联系方式不能为空' //
  28. ];
  29. protected $scene = [
  30. 'add' => ['address_realname', 'city_id', 'area_id'],
  31. 'edit' => ['address_realname', 'city_id', 'area_id'],
  32. 'address_valid' => ['address_realname', 'area_info', 'address_detail', 'address_mob_phone'], //mobile
  33. ];
  34. protected function checkMemberAddressMobPhone($value)
  35. {
  36. if (empty(input('post.mob_phone')) && empty(input('post.tel_phone'))) {
  37. if (empty($value)) {
  38. return '联系方式不能为空';
  39. }
  40. }
  41. return true;
  42. }
  43. }