HouseContract.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class HouseContract extends Validate{
  6. protected $rule = [
  7. 'sn|编号' => 'require|checkUnique',
  8. 'intro|说明' => 'require',
  9. 'lessee_id|承租人' => 'require',
  10. 'houses|承租房屋' => 'require|checkHouses',
  11. 'sign_date|合同签订日期' => 'require|date',
  12. // 'price|价格' => 'require|gt:0',
  13. // 'price_id|价格单位' => 'require',
  14. 'year_money|年租金' => 'require|gt:0',
  15. 'amount|合同金额' => 'require|gt:0',
  16. 'level_id|租赁方式' => 'require',
  17. 'pay_id|支付方式' => 'require',
  18. 'tenant_id|承租用途' => 'require',
  19. 'contract_id1|合同类型' => 'require',
  20. 'contract_id2|合同类型' => 'require',
  21. 'release' => 'checkRelease',
  22. ];
  23. protected $scene = [
  24. 'add' => ['sn','intro','lessee_id','houses','sign_date','year_money','amount','level_id','pay_id','tenant_id','contract_id1','contract_id2'],
  25. 'edit' => ['sn','intro','sign_date','year_money','amount','level_id','pay_id','tenant_id','contract_id1','contract_id2','release']
  26. ];
  27. protected function checkUnique($value,$rule,$data=[])
  28. {
  29. $info = Db::name('house_contract')->where('sn',$value)->where('del',0)->where('org_id',$data['org_id'])->find();
  30. if($data['id'] <= 0 && $info){
  31. return '编号已被使用';
  32. }
  33. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  34. return '编号已被使用';
  35. }
  36. return true;
  37. }
  38. protected function checkRelease($value,$rule,$data=[])
  39. {
  40. if($data['id'] > 0){
  41. $info = Db::name('house_contract')->where('id',$data['id'])->where('del',0)->find();
  42. if(!$info){
  43. return '合同不存在';
  44. }
  45. if($info['is_released'] == 1){
  46. return '房产已释放,不能修改合同';
  47. }
  48. }
  49. return true;
  50. }
  51. protected function checkHouses($value,$rule,$data=[])
  52. {
  53. $houses = explode(',',$data['houses']);
  54. $count = Db::name('house')
  55. ->where('del',0)
  56. ->where('enable',1)
  57. ->where('cur_lessee_id','>',0)
  58. ->where('id','in',$houses)
  59. ->count();
  60. if($count == count($houses)){
  61. return '有房屋被禁用或不存在或已出租';
  62. }
  63. // 检查时间段内是否有合同
  64. // $count = Db::name('house_contract_relation')
  65. // ->alias('hcr')
  66. // ->join('house_contract hc','hc.id = hcr.contract_id')
  67. // ->where('hc.del',0)
  68. // ->where('hc.status',1)
  69. // ->where('hcr.house_id','in',$houses)
  70. // ->where('hc.start_time','<',$data['end_time'])
  71. // ->where('hc.end_time','>',$data['start_time'])
  72. // ->count();
  73. // if($count){
  74. // return '有房屋此段时间被使用中';
  75. // }
  76. return true;
  77. }
  78. }