BuyControllerValidate.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Validate\Buy;
  3. use App\Http\Validate\BaseValidate;
  4. use Illuminate\Support\Facades\Validator;
  5. class BuyControllerValidate extends BaseValidate
  6. {
  7. /**
  8. * 电商平台分类列表参数校验
  9. * @param $data
  10. * @return bool
  11. */
  12. public function getCateList($data)
  13. {
  14. $validate = Validator::make($data,
  15. [
  16. "source"=>"required",
  17. ]
  18. );
  19. if($validate->fails()){
  20. //验证错误
  21. $this->setError($validate->errors()->first());
  22. return false;
  23. }
  24. return true;
  25. }
  26. /**
  27. * 商品列表参数校验
  28. * @param $data
  29. */
  30. public function getGoodsList($data)
  31. {
  32. $validate = Validator::make($data,
  33. [
  34. "source"=>"required",
  35. "cat_id"=>"required|integer",
  36. "page"=>"required|integer",
  37. "page_size"=>"required|integer",
  38. ]
  39. );
  40. if($validate->fails()){
  41. //验证错误
  42. $this->setError($validate->errors()->first());
  43. return false;
  44. }
  45. return true;
  46. }
  47. /**
  48. * 商品详情页参数校验
  49. * @param $data
  50. */
  51. public function getGoodsDetail($data)
  52. {
  53. $validate = Validator::make($data,
  54. [
  55. "source"=>"required",
  56. "goods_id"=>"required",
  57. ]
  58. );
  59. if($validate->fails()){
  60. //验证错误
  61. $this->setError($validate->errors()->first());
  62. return false;
  63. }
  64. return true;
  65. }
  66. /**
  67. * 搜索商品参数校验
  68. * @param $data
  69. */
  70. public function getGoodsSearch($data)
  71. {
  72. $validate = Validator::make($data,
  73. [
  74. "source"=>"required",
  75. "keyword"=>"required",
  76. "page"=>"required",
  77. "page_size"=>"required",
  78. ]
  79. );
  80. if($validate->fails()){
  81. //验证错误
  82. $this->setError($validate->errors()->first());
  83. return false;
  84. }
  85. return true;
  86. }
  87. }