Memberaddress.php 1.7 KB

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