AssetWithdraw.php 1.2 KB

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