123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class AssetReceive extends Validate{
- protected $rule = [
- 'receive_user_id' => 'require|gt:0',
- // 'receive_dep_id' => 'require|gt:0',
- 'items' => 'require|checkItems',
- ];
- protected $message = [
- 'receive_user_id.require' => '请选择所领用人',
- 'receive_user_id.gt' => '请选择所领用人',
- // 'receive_dep_id.require' => '请选择所领用部门',
- // 'receive_dep_id.gt' => '请选择所领用部门',
- 'items.require' => '请选择领用资产',
- ];
- protected $scene = [
- ];
- protected function checkItems($value,$rule,$data=[])
- {
- $items = $data['items'];
- if(!$items){
- return '请选择领用资产';
- }
- foreach ($items as $k=>$v){
- $ret = Db::name('asset_items')->where('id',$v['id'])->where('enable',1)->find();
- if(!$ret){
- return $ret['sn'].'资产已被使用';
- }
- }
- return true;
- }
- }
|