GoodsSupplierCategoryValidate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\validate\goods;
  20. use app\common\model\GoodsSupplierCategory;
  21. use app\common\validate\BaseValidate;
  22. class GoodsSupplierCategoryValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|checkId|checkDel',
  26. 'name' => 'require|checkName',
  27. 'sort' => 'number|max:5'
  28. ];
  29. protected $message = [
  30. 'id.require' => 'id不能为空',
  31. 'name.require' => '供应商分类名称不能为空',
  32. 'sort.number' => '排序必须为数字',
  33. 'sort.max' => '排序最大不能超过五位数',
  34. ];
  35. public function sceneAdd()
  36. {
  37. return $this->only(['name','sort']);
  38. }
  39. public function sceneDel()
  40. {
  41. return $this->only(['id']);
  42. }
  43. public function sceneEdit()
  44. {
  45. return $this->only(['id','name','sort'])
  46. ->append('sort','require')
  47. ->remove('id','checkDel');
  48. }
  49. public function sceneDetail()
  50. {
  51. return $this->only(['id'])
  52. ->remove('id','checkDel');
  53. }
  54. /**
  55. * @notes 检查供应商分类名称是否已存在
  56. * @param $value
  57. * @param $rule
  58. * @param $data
  59. * @return bool|string
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @author ljj
  64. * @date 2021/7/16 5:25
  65. */
  66. public function checkName($value,$rule,$data)
  67. {
  68. $where[] = ['name', '=', $value];
  69. // 编辑的情况,要排除自身ID
  70. if (isset($data['id'])) {
  71. $where[] = ['id', '<>', $data['id']];
  72. }
  73. $result = GoodsSupplierCategory::where($where)->select()->toArray();
  74. if ($result) {
  75. return '该供应商分类已存在';
  76. }
  77. return true;
  78. }
  79. /**
  80. * @notes 检查供应商分类ID是否存在
  81. * @param $value
  82. * @param $rule
  83. * @param $data
  84. * @return bool|string
  85. * @author ljj
  86. * @date 2021/7/16 6:22
  87. */
  88. public function checkId($value,$rule,$data)
  89. {
  90. $result = GoodsSupplierCategory::findOrEmpty($value);
  91. if ($result->isEmpty()) {
  92. return '供应商分类不存在';
  93. }
  94. return true;
  95. }
  96. /**
  97. * @notes 检查供应商分类能否删除
  98. * @param $value
  99. * @param $rule
  100. * @param $data
  101. * @return bool|string
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\DbException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @throws \think\exception\DbException
  106. * @author ljj
  107. * @date 2021/7/16 6:57
  108. */
  109. public function checkDel($value,$rule,$data)
  110. {
  111. $result = GoodsSupplierCategory::hasWhere('goodsSupplier',['supplier_category_id'=>$value])->select()->toArray();
  112. if (!empty($result)) {
  113. return '该供应商分类正在使用中,无法删除';
  114. }
  115. return true;
  116. }
  117. }