HouseTurnLessee.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use app\Request;
  5. use think\Db;
  6. use think\Exception;
  7. use think\Model;
  8. class HouseTurnLessee extends Model
  9. {
  10. public function add(){
  11. $data = [
  12. 'house_turn_id' => input('houseTurnId/d',0),
  13. 'lessee_id' => input('lesseeId/d',0),
  14. 'start_time' => input('startTime','','trim'),
  15. 'remark' => input('remark','','trim'),
  16. 'create_time' => date("Y-m-d H:i:s"),
  17. 'org_id' => input('orgId/d',0),
  18. ];
  19. $result = validate('HouseTurnLessee')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('HouseTurnLessee')->getError());
  22. }
  23. Db::startTrans();
  24. try{
  25. $ret = $this->allowField(true)->save($data);
  26. if(!$ret){
  27. \exception('操作失败');
  28. }
  29. $res = Db::name('house_turn')->where('id',$data['house_turn_id'])->setField('cur_lessee_id',$data['lessee_id']);
  30. if(!$res){
  31. \exception('操作失败');
  32. }
  33. Db::commit();
  34. }catch (Exception $e){
  35. Db::rollback();
  36. HelpHander::error($e->getMessage());
  37. }
  38. return true;
  39. }
  40. public function edit(){
  41. $data = [
  42. 'id' => input('id/d',0),
  43. 'end_time' => input('endTime','','trim'),
  44. 'remark2' => input('remark2','','trim'),
  45. 'update_time' => date("Y-m-d H:i:s"),
  46. 'status' => 1
  47. ];
  48. if($data['id'] <= 0){
  49. HelpHander::error('参数错误');
  50. }
  51. if(!$data['end_time']){
  52. HelpHander::error('未选择退房日期');
  53. }
  54. $info = Db::name('house_turn_lessee')->where('id',$data['id'])->find();
  55. if(!$info){
  56. HelpHander::error('参数错误');
  57. }
  58. if($info['status'] == 1){
  59. HelpHander::error('已退房,无需重复操作');
  60. }
  61. Db::startTrans();
  62. try{
  63. $ret = $this->allowField(true)->save($data,['id'=>$data['id']]);
  64. if(!$ret){
  65. \exception('操作失败');
  66. }
  67. $res = Db::name('house_turn')->where('id',$info['house_turn_id'])->setField('cur_lessee_id',0);
  68. if(!$res){
  69. \exception('操作失败');
  70. }
  71. Db::commit();
  72. }catch (Exception $e){
  73. Db::rollback();
  74. HelpHander::error($e->getMessage());
  75. }
  76. return true;
  77. }
  78. public function lists($page,$size,$title,$id,$orgId){
  79. $map[] = ['htl.org_id','=',$orgId];
  80. $map[] = ['htl.house_turn_id','=',$id];
  81. if($title != ''){
  82. $map[] = ['hl.title','like','%'.$title.'%'];
  83. }
  84. $lists = Db::name('house_turn_lessee')
  85. ->alias('htl')
  86. ->join('house_lessee hl','hl.id = htl.lessee_id')
  87. ->field('htl.*,hl.title as lesseeName, hl.phone as phone')
  88. ->where($map)
  89. ->page($page,$size)
  90. ->order('htl.id desc')
  91. ->select();
  92. $total = Db::name('house_turn_lessee')
  93. ->alias('htl')
  94. ->join('house_lessee hl','hl.id = htl.lessee_id')
  95. ->where($map)->count();
  96. $data = [
  97. 'total' => $total,
  98. 'list' => $lists?$lists:[]
  99. ];
  100. return $data;
  101. }
  102. public function del(){
  103. $id = input('id/d',0);
  104. $res = Db::name('house_turn_lessee')->where('id',$id)->delete();
  105. if(!$res){
  106. HelpHander::error('操作失败');
  107. }
  108. return true;
  109. }
  110. }