Activity.php 1.8 KB

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