AssetItems.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AssetItems extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require',
  8. 'price|原值' => 'require|egt:0',
  9. 'company_id' => 'require|gt:0',
  10. 'cate_id' => 'require|gt:0',
  11. 'class_id' => 'require|gt:0',
  12. 'unit_id' => 'require|gt:0',
  13. 'add_id' => 'require|gt:0',
  14. 'buy_time' => 'require|date',
  15. 'nums' => 'require|gt:0',
  16. 'sn' => 'checkSn'
  17. ];
  18. protected $message = [
  19. 'price.require' => '请填写物品单价',
  20. 'price.egt' => '单价不能小于0',
  21. 'nums.require' => '请输入数量',
  22. 'nums.gt' => '数量必须大于0',
  23. 'cate_id.require' => '请选择物品分类',
  24. 'cate_id.gt' => '请选择物品分类',
  25. 'unit_id.require' => '请选择物品单位',
  26. 'unit_id.gt' => '请选择物品单位',
  27. 'buy_time.require' => '请选择购买日期',
  28. 'buy_time.date' => '购买日期格式不正确',
  29. 'company_id.require' => '请选择所属公司',
  30. 'company_id.gt' => '请选择所属公司',
  31. 'class_id.require' => '请选择类别',
  32. 'class_id.gt' => '请选择类别',
  33. 'add_id.require' => '请选择增加方式',
  34. 'add_id.gt' => '请选择增加方式',
  35. ];
  36. protected $scene = [
  37. ];
  38. protected function checkSn($value,$rule,$data=[])
  39. {
  40. if($data['id'] > 0){
  41. $info = Db::name('asset_items')->where('sn',$value)->where('id','<>',$data['id'])->where('del',0)->where('org_id',$data['org_id'])->find();
  42. if($info){
  43. return '该编号已被占用';
  44. }
  45. }
  46. return true;
  47. }
  48. }