IntegralGoodsValidate.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\shopapi\validate;
  3. use app\common\enum\IntegralGoodsEnum;
  4. use app\common\model\IntegralGoods;
  5. use app\common\validate\BaseValidate;
  6. /**
  7. * 积分商品验证
  8. * Class IntegralOrderValidate
  9. * @package app\api\validate
  10. */
  11. class IntegralGoodsValidate extends BaseValidate
  12. {
  13. protected $rule = [
  14. 'id' => 'require|number|checkGoods',
  15. ];
  16. protected $message = [
  17. 'id.require' => '参数缺失',
  18. 'id.number' => '参数类型错误',
  19. ];
  20. /**
  21. * @notes 验证商品
  22. * @param $value
  23. * @param $rule
  24. * @param $data
  25. * @return bool|string
  26. * @author 段誉
  27. * @date 2022/3/31 9:47
  28. */
  29. protected function checkGoods($value, $rule, $data)
  30. {
  31. $goods = IntegralGoods::findOrEmpty($value);
  32. if ($goods->isEmpty()) {
  33. return '积分商品不存在';
  34. }
  35. if ($goods['status'] != IntegralGoodsEnum::STATUS_SHELVES) {
  36. return '商品已下架';
  37. }
  38. return true;
  39. }
  40. }