GoodValidate.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\validate;
  3. use app\model\GoodModel;
  4. use think\facade\Db;
  5. use think\Validate;
  6. //商品模块验证器
  7. class GoodValidate extends Validate
  8. {
  9. //验证规则
  10. protected $rule = [
  11. 'good_cover_img|商品封面图' => 'require|max:255',
  12. 'good_name|商品名称' => 'require|max:255',
  13. 'moq|销售起订量' => 'require|number|min:1|max:999999999',
  14. 'step|销售步长' => 'require|number|min:1|max:999999999',
  15. 'good_banner_img|商品轮播图' => 'require|array|min:1|max:100',
  16. 'good_img|商品详情图' => 'require|array|min:1|max:100',
  17. 'good_param|商品参数' => 'require|array|min:1|max:100',
  18. 'unit_id|单位id' => 'require|number|gt:0',
  19. 'good_remark|商品备注' => 'require|max:255',
  20. 'type|商品类型' => 'require|number|in:1,2',
  21. 'price|售价' => 'requireIf:type,2|float|max:99999999.99',
  22. 'id|主键' => 'require|number|gt:0',
  23. ];
  24. //创建商品
  25. public function sceneAdd()
  26. {
  27. return $this
  28. ->only([
  29. 'good_cover_img',
  30. 'good_name',
  31. 'moq',
  32. 'step',
  33. 'good_banner_img',
  34. 'good_img',
  35. 'good_param',
  36. 'unit_id',
  37. 'good_remark',
  38. 'type',
  39. 'price'
  40. ]);
  41. }
  42. //修改商品信息
  43. public function sceneEdit()
  44. {
  45. return $this->remove('type', true);
  46. }
  47. //获取商品详情
  48. public function sceneRead()
  49. {
  50. return $this->only(['id']);
  51. }
  52. }