StoreProductAssistValidate.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\merchant;
  12. use think\Validate;
  13. class StoreProductAssistValidate extends Validate
  14. {
  15. protected $failException = true;
  16. protected $rule = [
  17. "image|主图" => 'require|max:128',
  18. "slider_image|轮播图" => 'require',
  19. "store_name|商品名称" => 'require|max:128',
  20. "store_info|商品简介" => 'require|max:128',
  21. "product_id|原商品ID" => 'require',
  22. "temp_id|运费模板" => 'require',
  23. "start_time|开始时间" => 'require|checkTime',
  24. "end_time|结束时间" => "require",
  25. "assist_user_count|单人助力次数" => "require",
  26. "assist_count|需助力总人数" => "require|>=:assist_user_count",
  27. "attrValue|商品属性" => "require|Array"
  28. ];
  29. public function isUpdate()
  30. {
  31. $this->rule['start_time|开始时间'] = 'require';
  32. return $this;
  33. }
  34. protected function checkTime($value,$rule,$data)
  35. {
  36. $start_time = strtotime($data['start_time']);
  37. $end_time = strtotime($data['end_time']);
  38. if($start_time > $end_time) return '活动开始时间必须小于结束时间';
  39. if($start_time < time()) return '活动开始时间必须大于当前时间';
  40. return true;
  41. }
  42. }