BroadcastRoomValidate.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/7/30
  7. *
  8. *
  9. */
  10. namespace app\validate\merchant;
  11. use think\Validate;
  12. class BroadcastRoomValidate extends Validate
  13. {
  14. protected $failException = true;
  15. protected $rule = [
  16. 'name|直播间名字' => 'require|min:4|max:17',
  17. 'cover_img|背景图' => 'require',
  18. 'share_img|分享图' => 'require',
  19. 'anchor_name|主播昵称' => 'require|min:4|max:15',
  20. 'anchor_wechat|主播微信号' => 'require',
  21. 'phone|联系电话' => 'require|mobile',
  22. 'start_time|直播时间' => 'require|array|length:2|checkTime',
  23. 'type|直播间类型' => 'require|in:0',
  24. 'screen_type|显示样式' => 'require|in:0,1',
  25. 'close_like|是否开启点赞' => 'require|in:0,1',
  26. 'close_goods|是否开启货架' => 'require|in:0,1',
  27. 'close_comment|是否开启评论' => 'require|in:0,1',
  28. 'replay_status|是否开启回放' => 'require|in:0,1',
  29. 'close_share|是否开启分享' => 'require|in:0,1',
  30. 'close_kf|是否开启客服' => 'require|in:0,1',
  31. ];
  32. protected function checkTime($value)
  33. {
  34. $start = strtotime($value[0]);
  35. $end = strtotime($value[1]);
  36. if ($end < $start) return '请选择正确的直播时间';
  37. if ($start < strtotime('+ 15 minutes')) return '开播时间必须大于当前时间15分钟';
  38. if ($start >= strtotime('+ 6 month')) return '开播时间不能在6个月后';
  39. if (($end - $start) < (60 * 30)) return '直播时间不得小于30分钟';
  40. if (($end - $start) > (60 * 60 * 24)) return '直播时间不得超过24小时';
  41. return true;
  42. }
  43. }