123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class HouseContract extends Validate{
- protected $rule = [
- 'sn|编号' => 'require|checkUnique',
- 'intro|说明' => 'require',
- 'lessee_id|承租人' => 'require',
- 'houses|承租房屋' => 'require|checkHouses',
- 'sign_date|合同签订日期' => 'require|date',
- // 'price|价格' => 'require|gt:0',
- // 'price_id|价格单位' => 'require',
- 'year_money|年租金' => 'require|gt:0',
- 'amount|合同金额' => 'require|gt:0',
- 'level_id|租赁方式' => 'require',
- 'pay_id|支付方式' => 'require',
- 'tenant_id|承租用途' => 'require',
- 'contract_id1|合同类型' => 'require',
- 'contract_id2|合同类型' => 'require',
- 'release' => 'checkRelease',
- ];
- protected $scene = [
- 'add' => ['sn','intro','lessee_id','houses','sign_date','year_money','amount','level_id','pay_id','tenant_id','contract_id1','contract_id2'],
- 'edit' => ['sn','intro','sign_date','year_money','amount','level_id','pay_id','tenant_id','contract_id1','contract_id2','release']
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('house_contract')->where('sn',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
- if($data['id'] <= 0 && $info){
- return '编号已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '编号已被使用';
- }
- return true;
- }
- protected function checkRelease($value,$rule,$data=[])
- {
- if($data['id'] > 0){
- $info = Db::name('house_contract')->where('id',$data['id'])->where('del',0)->find();
- if(!$info){
- return '合同不存在';
- }
- if($info['is_released'] == 1){
- return '房产已释放,不能修改合同';
- }
- }
- return true;
- }
- protected function checkHouses($value,$rule,$data=[])
- {
- $houses = explode(',',$data['houses']);
- $count = Db::name('house')
- ->where('del',0)
- ->where('enable',1)
- ->where('cur_lessee_id','>',0)
- ->where('id','in',$houses)
- ->count();
- if($count == count($houses)){
- return '有房屋被禁用或不存在或已出租';
- }
- // 检查时间段内是否有合同
- // $count = Db::name('house_contract_relation')
- // ->alias('hcr')
- // ->join('house_contract hc','hc.id = hcr.contract_id')
- // ->where('hc.del',0)
- // ->where('hc.status',1)
- // ->where('hcr.house_id','in',$houses)
- // ->where('hc.start_time','<',$data['end_time'])
- // ->where('hc.end_time','>',$data['start_time'])
- // ->count();
- // if($count){
- // return '有房屋此段时间被使用中';
- // }
- return true;
- }
- }
|