Comment.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. use app\common\Enum\CommentEnum;
  5. class Comment extends Validate
  6. {
  7. protected $rule = [
  8. 'goods_id' => 'integer|>=:0',
  9. 'pid' => 'integer|>=:0',
  10. 'page' => 'integer|>:0',
  11. 'page_size' => 'integer|between:1,50',
  12. 'order_by' => 'in:pid,id,createtime,updatetime,rand',
  13. 'order_way' => 'in:asc,desc',
  14. 'has_picture' => 'integer|in:0,1',
  15. 'order_id' => 'require|integer|>:0',
  16. 'remark' => 'require|array',
  17. 'remark.*.goods_id' => 'require|integer|>:0',
  18. 'remark.*.star' => 'require|integer|between:1,5',
  19. 'remark.*.content' => 'require|max:500',
  20. 'remark.*.images' => 'array',
  21. 'evaluate_status' => 'integer|in:1,2,3',
  22. 'comment_id' => 'require|integer|>:0',
  23. ];
  24. protected $message = [
  25. 'goods_id.integer' => '商品ID必须为整数',
  26. 'pid.integer' => '父评论ID必须为整数',
  27. 'page.integer' => '页码必须为正整数',
  28. 'page_size.between' => '每页显示条数必须在1-50之间',
  29. 'order_by.in' => '排序字段不正确',
  30. 'order_way.in' => '排序方式不正确',
  31. 'has_picture.in' => '是否有图片参数错误',
  32. 'order_id.require' => '订单ID不能为空',
  33. 'order_id.integer' => '订单ID必须为整数',
  34. 'remark.require' => '评论内容不能为空',
  35. 'remark.array' => '评论内容格式不正确',
  36. 'remark.*.goods_id.require' => '商品ID不能为空',
  37. 'remark.*.goods_id.integer' => '商品ID必须为整数',
  38. 'remark.*.star.require' => '评分不能为空',
  39. 'remark.*.star.between' => '评分必须在1-5之间',
  40. 'remark.*.content.require' => '评论内容不能为空',
  41. 'remark.*.content.max' => '评论内容不能超过500字',
  42. 'remark.*.images.array' => '图片格式不正确',
  43. 'evaluate_status.in' => '评价状态参数错误',
  44. 'comment_id.require' => '评论ID不能为空',
  45. 'comment_id.integer' => '评论ID必须为整数',
  46. ];
  47. protected $scene = [
  48. 'index' => ['goods_id', 'pid', 'page', 'page_size', 'order_by', 'order_way', 'has_picture'],
  49. 'add' => ['order_id', 'remark', 'pid'],
  50. 'myList' => ['page', 'page_size'],
  51. 'stats' => ['goods_id'],
  52. 'audit' => ['comment_id', 'evaluate_status'],
  53. ];
  54. /**
  55. * 验证评价状态
  56. * @param $value
  57. * @param $rule
  58. * @param $data
  59. * @return bool|string
  60. */
  61. public function checkEvaluateStatus($value, $rule, $data)
  62. {
  63. if (!CommentEnum::isValidEvaluateStatus($value)) {
  64. return '评价状态参数错误';
  65. }
  66. return true;
  67. }
  68. /**
  69. * 验证有图片状态
  70. * @param $value
  71. * @param $rule
  72. * @param $data
  73. * @return bool|string
  74. */
  75. public function checkHasPicture($value, $rule, $data)
  76. {
  77. if (!CommentEnum::isValidHasPicture($value)) {
  78. return '有图片状态参数错误';
  79. }
  80. return true;
  81. }
  82. }