AssetRepair.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AssetRepair extends Validate{
  6. protected $rule = [
  7. 'agent_user_id' => 'require|gt:0',
  8. // 'agent_dep_id' => 'require|gt:0',
  9. 'items' => 'require|checkItems',
  10. ];
  11. protected $message = [
  12. 'agent_user_id.require' => '请选择经办人',
  13. 'agent_user_id.gt' => '请选择经办人',
  14. // 'agent_dep_id.require' => '请选择经办部门',
  15. // 'agent_dep_id.gt' => '请选择经办部门',
  16. 'items.require' => '请选择资产',
  17. ];
  18. protected $scene = [
  19. ];
  20. protected function checkItems($value,$rule,$data=[])
  21. {
  22. $items = $data['items'];
  23. if(!$items){
  24. return '请选择资产';
  25. }
  26. foreach ($items as $k=>$v){
  27. $ret = Db::name('asset_items')->where('id',$v['id'])->where('enable','in','1,2')->find();
  28. if(!$ret){
  29. return $ret['sn'].'资产不能维修';
  30. }
  31. }
  32. return true;
  33. }
  34. }