UserSubsidies.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class UserSubsidies extends Validate{
  6. protected $rule = [
  7. 'title' => 'require|checkUnique',
  8. // 'name' => 'require|checkUniqueName',
  9. 'type' => 'require|in:1,2,3',
  10. 'cate|分类' => 'require|in:1,2',
  11. 'pay_type|类型' => 'require|in:1,2,3,4,5',
  12. ];
  13. protected $message = [
  14. 'title.require' => '名称不能为空',
  15. // 'name.require' => '标识不能为空',
  16. 'type.require' => '请选择范围',
  17. 'type.in' => '参数错误',
  18. 'cate.in' => '参数错误',
  19. 'pay_type.in' => '参数错误',
  20. ];
  21. protected $scene = [
  22. ];
  23. protected function checkUnique($value,$rule,$data=[])
  24. {
  25. $info = Db::name('user_subsidies')->where('pay_type',$data['pay_type'])->where('title',$value)->where('del',0)->find();
  26. if($data['id'] <= 0 && $info){
  27. return '名称已被占用';
  28. }
  29. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  30. return '名称已被占用';
  31. }
  32. return true;
  33. }
  34. protected function checkUniqueName($value,$rule,$data=[])
  35. {
  36. $info = Db::name('user_subsidies')->where('del',0)->where('name',$value)->find();
  37. if($data['id'] <= 0 && $info){
  38. return '标识已被占用';
  39. }
  40. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  41. return '标识已被占用';
  42. }
  43. return true;
  44. }
  45. }