Activity.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 验证器
  10. */
  11. class Activity extends Validate
  12. {
  13. protected $rule = [
  14. 'activity_title' => 'require',
  15. 'activity_startdate' => 'require',
  16. 'activity_enddate' => 'require|checkEnddate:1',
  17. 'activity_type' => 'require',
  18. 'activity_banner' => 'require',
  19. 'activity_sort' => 'require'
  20. ];
  21. protected $message = [
  22. 'activity_title.require' => '活动标题不能为空',
  23. 'activity_startdate.require' => '开始时间不能为空',
  24. 'activity_enddate.require' => '结束时间不能为空',
  25. 'activity_enddate.checkEnddate' => '结束时间不能为空',
  26. 'activity_type.require' => '必须选择活动类别',
  27. 'activity_banner.require' => '横幅图片不能为空',
  28. 'activity_sort.require' => '排序为0~255的数字'
  29. ];
  30. protected $scene = [
  31. 'add' => ['activity_title', 'activity_startdate', 'activity_enddate', 'activity_type', 'activity_banner', 'activity_sort'],
  32. 'edit' => ['activity_title', 'activity_startdate', 'activity_enddate', 'activity_type', 'activity_sort'],
  33. ];
  34. protected function checkEnddate($value)
  35. {
  36. $activity_startdate = strtotime(input('post.activity_startdate'));
  37. if ($activity_startdate >= $value) {
  38. return '结束时间早于开始时间或相同时间';
  39. }
  40. return true;
  41. }
  42. }