Activity.php 1.9 KB

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